OpenTP1 Version 7 Programming Reference C Language

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

7.2 Coding samples for client/server configuration UAPs (SPP TAM access)

The figure below shows an example of a client/server configuration UAP. This section presents only an SPP coding sample. This example assumes that the same SUP as in 7.1 Coding samples for client/server configuration UAPs (SUP, SPP DAM access) requests this SPP for service.

Figure 7-2 Client/server configuration UAP sample (TAM access)

[Figure]

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

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

(1) SPP sample (main function)

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

  10  /*
  20   * spp01 main function
  30   */
  40  #include <stdio.h>
  50  #include <dcrpc.h>
  60  #include <dctam.h>
  70  #define  TAMTABLE    "tamtable30"
  80  
  90  long  tamfd ;      /* tamfile file-id  */
 100  
 110  main()
 120  {
 130  
 140  /*
 150   * Define a return code storage variable
 160   */
 170    int    rcd ;
 180  /*
 190   * RPC-OPEN (start the UAP)
 200   */
 210    rcd = dc_rpc_open(DCNOFLAGS) ;
 220    if(rcd != DC_OK) {
 230      printf("SPP01:dc_rpc_open failed. "
 235             "code = %d \n", rcd) ;
 240      goto PROG_END ;
 250    }
 260  /*
 270   * TAM-OPEN (open a TAM table)
 280   */
 290    rcd = dc_tam_open(TAMTABLE, DCTAM_REC_EXCLUSIVE) ;
 300    if(rcd <= 0) {
 310      printf("SVR01:dc_tam_open failed. "
 315             "code = %d \n", rcd) ;
 320      goto TAM_END ;
 330    }
 340    tamfd = (long)rcd ;
 350  /*
 360   * RPC-MAINLOOP (start the SPP service)
 370   */
 380    rcd = dc_rpc_mainloop(DCNOFLAGS) ;
 390    if(rcd != DC_OK) {
 400      printf("SPP01:dc_rpc_mainloop failed. "
 405             "code = %d \n", rcd) ;
 410    }
 420  /*
 430   * TAM-CLOSE (close the TAM table)
 440   */
 450    rcd = dc_tam_close(tamfd, DCNOFLAGS) ;
 460    if(rcd != DC_OK) {
 470      printf("SVR01:dc_tam_close failed. "
 475             "code = %d \n", rcd) ;
 480    }
 490  TAM_END :
 500  /*
 510   * RPC-CLOSE (terminate the UAP)
 520   */
 530    dc_rpc_close(DCNOFLAGS) ;
 540  PROG_END :
 550    printf("SPP01:The SPP service processing is "
 555           "terminated. \n") ;
 560    exit(0) ;
 570  }

(2) SPP sample (service function)

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

  10  /*
  20   * srv01 service function
  30   */
  40  #include <stdio.h>
  50  #include <string.h>
  60  #include <dctam.h>
  70  #define  TAM_REC_SIZE  128
  80  
  90  extern  long tamfd ;   /* tamfile file-id */
 100  
 110  void svr01(in_data, in_leng, out_data, out_leng)
 120    char *in_data ;
 130    long *in_leng ;
 140    char *out_data ;
 150    long *out_leng ;
 160  {
 170  
 180  /*
 190   * Define variables
 200   */
 210    static struct DC_TAMKEY keyptr ;
 220    static char   *tamc_buf ;
 230    static char   tam_cntl_buf[TAM_REC_SIZE] ;
 240    static char   write_buf[TAM_REC_SIZE] ;
 250    struct tam_cntl_p {
 260                       char keyname[10] ;
 270                       char filler[118] ;
 280                      } *tam_cntl_p ;
 290    int    rcd ;
 300    int    write_size ;
 310    int    tamc_buf_size ;
 320    static char keypar[4][10] = {
 330                       { 0x00, 0x00, 0x00, 0x00, 0x00,
 340                         0x00, 0x00, 0x00, 0x00, 0x01} ,
 350                       { 0x00, 0x00, 0x00, 0x00, 0x00,
 360                         0x00, 0x00, 0x00, 0x00, 0x02} ,
 370                       { 0x00, 0x00, 0x00, 0x00, 0x00,
 380                         0x00, 0x00, 0x00, 0x00, 0x03} ,
 390                       { 0x00, 0x00, 0x00, 0x00, 0x00,
 400                         0x00, 0x00, 0x00, 0x00, 0x04} ,
 410                                } ;
 420    printf("SVR01:Start of processing \n") ;
 430  /*
 440   * TAM_READ (read the first record from the TAM table)
 450   */
 460    keyptr.keyname = keypar[0] ;
 470    tamc_buf_size = TAM_REC_SIZE ;
 480    rcd = dc_tam_read(tamfd, &keyptr, 1, tam_cntl_buf,
 490                      tamc_buf_size, 
 495                      DCTAM_EQLSRC | DCTAM_MODIFY) ;
 500    if(rcd != DC_OK) {
 510      printf("SVR01:dc_tam_read failed. "
 515             "code = %d \n", rcd) ;
 520      strcpy(out_data, "SVR01:TAM READ FAILED") ;
 530      *out_leng = strlen(out_data) ;
 540      goto PROG_END ;
 550    }
 560  /*
 570   * TAM_REWRITE (update the first record of TAM table 
 575   *              on the assumption of search)
 580   */
 590    tam_cntl_p = (struct tam_cntl_p *)tam_cntl_buf ;
 600    memcpy(tam_cntl_p->filler, in_data, *in_leng) ;
 610    rcd = dc_tam_rewrite(tamfd, &keyptr, 1, tam_cntl_buf,
 620                         tamc_buf_size, DCNOFLAGS) ;
 630    if(rcd != DC_OK) {
 640      printf("SVR01:dc_tam_rewrite failed. "
 645             "code = %d \n", rcd) ;
 650      strcpy(out_data, "SVR01:TAM REWRITE FAILED") ;
 660      *out_leng = strlen(out_data) ;
 670      goto PROG_END ;
 680    }
 690  /*
 700   * TAM_WRITE (update the second record of TAM table)
 710   */
 720    keyptr.keyname = keypar[1] ;
 730    tam_cntl_p = (struct tam_cntl_p *)write_buf ;
 740    memcpy(tam_cntl_p->keyname, keypar[1], 10) ;
 750    memcpy(tam_cntl_p->filler, in_data, *in_leng) ;
 760    write_size = TAM_REC_SIZE ;
 770    rcd = dc_tam_write(tamfd, &keyptr, 1, tam_cntl_p,
 780                              write_size, DCTAM_WRITE) ;
 790    if(rcd != DC_OK) {
 800      printf("SVR01:dc_tam_write failed. "
 805             "code = %d \n", rcd) ;
 810      strcpy(out_data, "SVR01:TAM WRITE FAILED") ;
 820      *out_leng = strlen(out_data) ;
 830      goto PROG_END ;
 840    }
 850  /*
 860   * TAM_READ (read the third record from the TAM table)
 870   */
 880    keyptr.keyname = keypar[2] ;
 890    tamc_buf_size = TAM_REC_SIZE ;
 900    rcd = dc_tam_read(tamfd, &keyptr, 1, tam_cntl_buf,
 910                      tamc_buf_size, 
 905                      DCTAM_EQLSRC | DCTAM_MODIFY) ;
 920    if(rcd != DC_OK) {
 930      printf("SVR01:dc_tam_read failed. "
 935             "code = %d \n", rcd) ;
 940      strcpy(out_data, "SVR01:TAM READ FAILED") ;
 950      *out_leng = strlen(out_data) ;
 960      goto PROG_END ;
 970    }
 980  /*
 990   * TAM_READ_CANCEL (cancel the search for the third 
 995   * record of the TAM table)
1000   */
1010    rcd = dc_tam_read_cancel(tamfd, &keyptr, 
1015                             1, DCNOFLAGS) ;
1020    if(rcd != DC_OK) {
1030      printf("SVR01:dc_tam_read_cancel failed. "
1040             "code = %d \n",rcd) ;
1050      strcpy(out_data, "SVR01:TAM READ CANCEL FAILED") ;
1060      *out_leng = strlen(out_data) ;
1070      goto PROG_END ;
1080    }
1090  /*
1100   * TAM_delete (delete the fourth record of the 
1105   *             TAM table)
1110   */
1120    keyptr.keyname = keypar[3] ;
1130    rcd = dc_tam_delete(tamfd, &keyptr, 1,
1140                               NULL, 0, DCTAM_NOOUTREC) ;
1150    if(rcd != DC_OK) {
1160      printf("SVR01:dc_tam_delete failed. "
1165             "code = %d \n", rcd) ;
1170      strcpy(out_data, "SVR01:TAM DELETE FAILED") ;
1180      *out_leng = strlen(out_data) ;
1190      goto PROG_END ;
1200    }
1210    strcpy(out_data, "SVR01:PROCESS COMPLETE") ;
1220    *out_leng = strlen(out_data) ;
1230  PROG_END :
1240    printf("SVR01:Processing is terminated.\n") ;
1250    return ;
1260  }