The figure below shows an example of a client/server configuration UAP.
Figure 7-1 Client/Server configuration UAP sample (DAM access)
This section presents a coding example based on the configuration sample shown in the figure.
The following shows a coding example for an SUP.
10 /*
20 * SUP01
30 */
40 #include <stdio.h>
50 #include <string.h>
60 #include <dcrpc.h>
70 #include <dctrn.h>
80
90 main()
100 {
110 /*
120 * Define variables
130 */
140 static char in_buf[1024];
150 static DCLONG in_buf_len;
160 static char out_buf[1024];
170 static DCLONG out_buf_len;
180 int rc;
190 /*
200 * RPC-OPEN (start the UAP)
210 */
220 rc = dc_rpc_open(DCNOFLAGS);
230 /* Prepare to use various OpenTP1 functions */
235 /* (initialize each function) */
240 if(rc != DC_OK) {
250 printf("SUP01:dc_rpc_open failed. CODE = %d \n",rc);
260 goto PROG_END;
270 }
280 /*
290 * ADM-COMPLETE (report completion
295 * of user server start processing)
300 */
310 rc = dc_adm_complete(DCNOFLAGS);
320 if(rc != DC_OK){
330 printf("SUP01:dc_adm_complete failed."
335 "CODE = %d \n",rc);
340 goto PROG_END;
350 }
360 /*
370 * TRN_BEGIN (start the transaction)
380 */
390 rc = dc_trn_begin();
400 if(rc != DC_OK) {
410 printf("SUP01:dc_trn_begin failed. CODE = %d \n",rc);
420 goto TRAN_END;
430 }
440 /*
450 * RPC-CALL (request a remote service)
460 */
470 strcpy(in_buf,"SUP01:DATA OpenTP1!!");
480 in_buf_len = strlen(in_buf) + 1;
490 out_buf_len = 1024;
500 rc = dc_rpc_call("spp01grp","svr01",
505 in_buf,&in_buf_len,
510 out_buf,&out_buf_len,DCNOFLAGS);
520 if(rc != DC_OK) {
530 printf("SUP01:Service request failed. "
535 "CODE = %d \n",rc);
540 goto TRAN_END;
550 }
560 printf("SUP01:SERVICE FUNCTION RETURN = %s\n",
565 out_buf);
570 /*
580 * TRN-UNCHAINED-COMMIT (commit in unchained mode)
590 */
600 TRAN_END:
610 rc = dc_trn_unchained_commit();
620 if(rc != DC_OK) {
630 printf("SUP01:dc_trn_unchained_commit failed. "
635 "CODE = %d \n",rc);
640 }
650 /*
660 * RPC-CLOSE (terminate the UAP)
670 */
680 PROG_END:
690 dc_rpc_close(DCNOFLAGS);
700 printf("SUP01:Processing is finished.\n");
710 exit(0);
720 }
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 <dcdam.h>
70 #define DAMFILE "damfile0"
80
90 int damfd; /* damfile file-id */
100
110 main()
120 {
130 /*
140 * Define area for storing return value
150 */
160 int rc;
170 /*
180 * RPC-OPEN (start the UAP)
190 */
200 rc = dc_rpc_open(DCNOFLAGS);
210 if(rc != DC_OK) {
220 printf("SPP01:dc_rpc_open failed. CODE = %d \n",rc);
230 goto PROG_END;
240 }
250 /*
260 * DAM-OPEN (open a logical file)
270 */
280 rc = dc_dam_open(DAMFILE,DCDAM_BLOCK_EXCLUSIVE);
290 if(rc < DC_OK) {
300 printf("SVR01:dc_dam_open failed. CODE = %d \n",rc);
310 goto DAM_END;
320 }
330 damfd = rc;
340 /*
350 * RPC-MAINLOOP (start the SPP service)
360 */
370 printf("SPP01:mainloop begins.\n");
380 rc = dc_rpc_mainloop(DCNOFLAGS);
390 if(rc != DC_OK) {
400 printf("SPP01:dc_rpc_mainloop \
410 failed. CODE = %d \n",rc);
420 }
430 /*
440 * DAM-CLOSE (close the logical file)
450 */
460 DAM_END:
470 rc = dc_dam_close(damfd,DCNOFLAGS);
480 if(rc != DC_OK) {
490 printf("SVR01:dc_dam_close failed. CODE = %d\n",rc);
500 }
510 /*
520 * RPC-CLOSE (terminate the UAP)
530 */
540 PROG_END:
550 dc_rpc_close(DCNOFLAGS);
560 printf("SPP01:The SPP service processing is "
565 "terminated. \n");
570 exit(0);
580 }
The following shows a coding example for the SPP service function.
10 /*
20 * SVR01 service function
30 */
40 #include <stdio.h>
50 #include <string.h>
60 #include <dcrpc.h>
70 #include <dcdam.h>
80 #define DAMFILE "damfile0"
90 #define DAM_BLK_SIZE 504
100 #define REWRITE_LEN 19
110 extern int damfd;
120
130 void svr01(in_data,in_leng,out_data,out_leng)
140 char *in_data;
150 DCLONG *in_leng;
160 char *out_data;
170 DCLONG *out_leng;
180 {
190 /*
200 * Define variables
210 */
220 static struct DC_DAMKEY keyptr;
230 static char *damc_buf;
240 static char dam_cntl_buf[DAM_BLK_SIZE];
250 static char write_buf[DAM_BLK_SIZE];
260 struct dam_cntl_p {
270 int w_point;
280 char rewrite_data[REWRITE_LEN];
290 } *dam_cntl_p;
300 int rc;
310 int write_size;
320 int rewrite_size;
330 int damc_buf_size;
340
350 keyptr.fstblkno = 0;
360 keyptr.endblkno = 0;
370 damc_buf_size = DAM_BLK_SIZE;
380 printf("SVR01:Start of processing\n");
390 /*
400 * DAM_READ(read logical file blocks)
410 */
420 rc = dc_dam_read(damfd,&keyptr,1,dam_cntl_buf,
430 damc_buf_size,DCDAM_MODIFY);
440 if(rc != DC_OK) {
450 printf("SVR01:dc_dam_read failed. CODE = %d \n",rc);
460 strcpy(out_data,"SVR01:DAM READ FAILED");
470 *out_leng = strlen(out_data);
480 goto PROG_END;
490 }
500 /*
510 * DAM_WRITE (write to logical file blocks)
520 * DAM_REWRITE (update logical file blocks)
530 */
540 DAM_WRITE:
550 dam_cntl_p = (struct dam_cntl_p *)dam_cntl_buf;
560 write_size = DAM_BLK_SIZE;
570 memcpy(write_buf,in_data,*in_leng);
580 dam_cntl_p->w_point = dam_cntl_p->w_point + 1;
590 keyptr.fstblkno = dam_cntl_p->w_point;
600 keyptr.endblkno = 0;
610 rc = dc_dam_write(damfd,&keyptr,1,write_buf,
620 write_size,DCNOFLAGS);
630 if(rc != DC_OK) {
640 if(rc == DCDAMER_BNOER) {
650 dam_cntl_p->w_point = 0;
660 goto DAM_WRITE;
670 }
680 printf("SVR01:dc_dam_write failed. "
685 "CODE = %d \n",rc);
690 strcpy(out_data,"SVR01;DAM WRITE FAILED");
700 *out_leng = strlen(out_data);
710 goto PROG_END;
720 }
730 keyptr.fstblkno = 0;
740 keyptr.endblkno = 0;
750 damc_buf_size = DAM_BLK_SIZE;
760 sprintf(dam_cntl_p->rewrite_data,
765 "REWRITE COMPLETE\n");
770 rc = dc_dam_rewrite(damfd,&keyptr,1,dam_cntl_buf,
780 damc_buf_size,DCDAM_UPDATE);
790 if(rc != DC_OK) {
800 printf("SVR01:dc_dam_rewrite failed. "
805 "CODE = %d\n",rc);
810 strcpy(out_data,"SVR01:DAM REWRITE FAILED");
820 *out_leng = strlen(out_data);
830 }
840 strcpy(out_data,"SVR01:PROCESS COMPLETE");
850 *out_leng = strlen(out_data);
860 PROG_END:
870 printf("SVR01:Processing is terminated.\n");
880 return;
890 }