OpenTP1 Version 7 Programming Reference C Language

[Contents][Index][Back][Next]

7.3 Coding samples for message exchange configuration UAPs (MHP)

The figure below shows an example of a message exchange UAP.

Figure 7-3 Message exchange configuration UAP sample (MHP)

[Figure]

This section presents a coding example based on the configuration sample shown in the figure.

Organization of this section
(1) MHP sample (main function)
(2) MHP sample (service function)

(1) MHP sample (main function)

The following shows a coding example for the MHP main function.

  10  /*
  20   * MHP main function
  30   */
  40  #include <stdio.h>
  50  #include <dcrpc.h>
  60  #include <dcmcf.h>
  70  
  80  main()
  90  {
 100     int rtn_cod ;
 110  
 120     printf("******  RPC OPEN   *****\n") ;
 130  /*
 140   * RPC-OPEN (start the UAP)
 150   */
 160     rtn_cod = dc_rpc_open(DCNOFLAGS) ;
 170     if(rtn_cod != DC_OK) {
 180       printf("dc_rpc_open failed !! CODE = %d \n",
 185              rtn_cod) ;
 190       goto PROG_END ;
 200     }
 210  
 220     printf("******  MCF OPEN   *****\n") ;
 230  /*
 240   * MCF-OPEN (open the MCF environment)
 250   */
 260     rtn_cod = dc_mcf_open(DCNOFLAGS) ;
 270     if(rtn_cod != DC_OK) {
 280       printf("dc_mcf_open failed !! CODE = %d \n",
 285              rtn_cod) ;
 290       goto PROG_END ;
 300     }
 310  
 320     printf("******  MCF MAINLOOP   *****\n") ;
 330  /*
 340   * MCF-MAINLOOP (start the MHP service)
 350   */
 360     rtn_cod = dc_mcf_mainloop(DCNOFLAGS) ;
 370     if(rtn_cod != DC_OK) {
 380       printf("dc_mcf_mainloop failed !! CODE = %d \n",
 385              rtn_cod) ;
 390     }
 400  
 410     printf("******  MCF CLOSE   *****\n") ;
 420  /*
 430   * MCF-CLOSE (close the MCF environment)
 440   */
 450     dc_mcf_close(DCNOFLAGS) ;
 460  
 470  PROG_END :
 480     printf("******  RPC CLOSE   *****\n") ;
 490  /*
 500   * RPC-CLOSE (terminate the UAP) 
 510   */
 520     dc_rpc_close(DCNOFLAGS) ;
 530     exit(0) ;
 540  }

(2) MHP sample (service function)

The following shows a coding example for the MHP service function.

  10  /*
  20   * MHP service function
  30   */
  40  #include <stdio.h>
  50  #include <sys/types.h>
  60  #include <dcmcf.h>
  70  #include <dcrpc.h>
  80  
  90  void svrA() 
 100  {
 110       DCLONG action ;
 120       DCLONG commform ;
 130       DCLONG opcd ;
 140       DCLONG active ;
 150       char recvdata[1024] ;
 160       DCLONG rdataleng ;
 170       DCLONG time ;
 180       DCLONG inbufleng ;
 190       int  rtn_cod ;
 200       DCLONG cdataleng ;
 210       char termnam[10] ;
 220       static char execdata[32] = "  SVRA EXECAP DATA" ;
 230       static char senddata[32] = "  SVRA REPLY DATA1" ;
 240       static char resv01[9] = "\0" ;
 250       static char resv02[9] = "\0" ;
 260       static char resv03[9] = "\0" ;
 270       static char apnam[9] = "aprepB" ;
 280  
 290       printf("*****   UAP START   *****\n") ;
 300  
 310       printf("*****   MCF RECEIVE   *****\n") ;
 320  /*
 330   * MCF-RECEIVE (receive messages)
 340   */
 350       action = DCMCFFRST ; 
 360       commform = DCNOFLAGS ;
 370       inbufleng = sizeof(recvdata) ;
 380       rtn_cod = dc_mcf_receive(action, commform,
 385                        termnam, resv01, recvdata,
 390                        &rdataleng, inbufleng, &time) ;
 400       if(rtn_cod != DCMCFRTN_00000) {
 410  /*
 420   * MCF-ROLLBACK (error processing)
 430   */
 440       printf("dc_mcf_receive failed !! CODE = %d \n",
 445              rtn_cod) ;
 450       rtn_cod = dc_mcf_rollback(DCMCFNRTN) ;
 460       }
 470  
 480       printf("*****   MCF EXECAP   *****\n") ;
 490  /*
 500   * MCF-EXECAP (start the application program)
 510   */
 520       action = DCMCFEMI|DCMCFJUST ;
 530       commform = DCNOFLAGS ;
 540       active = 0 ;
 550       cdataleng = 16 ;
 560       rtn_cod = dc_mcf_execap(action, commform, resv01,
 570                 active, apnam, execdata, cdataleng) ;
 580       if(rtn_cod != DCMCFRTN_00000) {
 590  /*
 600   * MCF-ROLLBACK (error processing)
 610   */
 620       printf("dc_mcf_execap failed !! CODE = %d \n",
 625              rtn_cod) ;
 630       rtn_cod = dc_mcf_rollback(DCMCFNRTN) ;
 640       }
 650  
 660       printf("*****   MCF REPLY   *****\n") ;
 670  /*
 680   * MCF-REPLY (send a response message)
 690   */
 700       action = DCMCFEMI ;
 710       commform = DCNOFLAGS ;
 720       opcd = DCNOFLAGS ;
 730       cdataleng = 16 ;
 740       rtn_cod = dc_mcf_reply(action, commform,
 745                 resv01, resv02, senddata, 
 750                 cdataleng, resv03, opcd) ;
 760       if(rtn_cod != DCMCFRTN_00000) {
 770  /*
 780   * MCF-ROLLBACK (error processing)
 790   */
 800       printf("dc_mcf_reply failed !! CODE = %d \n",
 805              rtn_cod) ;
 810       rtn_cod = dc_mcf_rollback(DCMCFNRTN) ;
 820       }
 830  }