ファイルの例を次に示します。ここでは,次に示す例を示します。
IDLファイルの例を次に示します。
10 /*
20 * (1)IDLファイルの例 sample.idl
30 */
40 [
50 uuid(f990a82a-10e5-11ce-9b02-0000870000ff),
60 version(1.0),
70 transaction_mandatory
80 ]
90 interface sample_ope
100 {
110 const long NAME_LENGTH = 20; /* size of name field in record */
120 const long AGE_LEN = 3; /* size of age field in record */
130 const long MAXRECORD = 10; /* max number of record in database */
140
150 /*struct info : record format of customer information database */
160 typedef struct info{
170 char name[NAME_LENGTH]; /* name (20 byte) */
180 char sex; /* sex (1 byte) */
190 char age[AGE_LEN]; /* age (3 byte) */
200 long sale; /* sale (4 byte) */
210 }info_t;
220
230 error_status_t getinfo
240 (
250 [in] unsigned char name[NAME_LENGTH], /* input parameter */
260 [out] info_t *ptr /* output parameter */
270 );
280 }
290 /* EOF */
クライアントプログラムの例を次に示します。
10 /*
20 * (2)クライアントプログラムの例
30 * 注意事項:ndceタイプの場合は dc_rpc_open(),dc_adm_complete(),
40 * dc_rpc_close()が必要です。
50 * wdceタイプの場合は dc_clt_cltin(),dc_rpc_open(),
60 * dc_rpc_close(),dc_clt_cltin()が必要です。インクルードする
70 * ヘッダファイルは,TP1/Clientのライブラリを使ってください。
80 * clt.c
90 * Functions = main()
100 */
110
120 #include <stdio.h>
130 #include <dcrpc.h>
140 #include <dctrp.h>
150 #include <dcadm.h>
160 #include <tx.h>
170 #include "sample.h"
180
190 /*
200 * Program Specification
210 * construct customer information database. allow actions noted the following.
220 * * reference processing
230 * refer the information using "name" as a key.
240 *
250 * customer information database
260 * *--------------------------------------------*
270 * | name | sex | age | sale |
280 * |--------------------------------------------|
290 * | Suzuki | Male | 30 | 1,000,000 |
300 * | Okada | Female | 23 | 1,500,000 |
310 * | Yoshida | Female | 26 | 800,000 |
320 * | Saitoh | Male | 24 | 1,000,000 |
330 * | Itoh | Male | 35 | 1,800,000 |
340 * | Nishikawa | Male | 20 | 300,000 |
350 * | Katoh | Female | 28 | 1,000,000 |
360 * | Satoh | Female | 27 | 2,100,000 |
370 * | Hasegawa | Male | 25 | 600,000 |
380 * | Tumura | Male | 24 | 1,100,000 |
390 * *--------------------------------------------*
400 *
410 * This program requires service.
420 * <refer> refer Tumura's information.
430 *
440 */
450 /*
460 * name = main()
470 * func = Client program for sample_ope interface
480 * (1)service requirement(reference)
490 * (2)output result of service requirement
500 * arg = nothing
510 * return = void
520 */
530
540 int main()
550 {
560 static unsigned char name[] = "Tumura"; /* input parameter */
570 info_t out_data; /* output parameter */
580 error_status_t status; /* return code for server */
590 int rc; /* return code */
600
610 /*
620 * Start UAP
630 */
640 rc = dc_rpc_open(DCNOFLAGS);
650 /* error processing */
660 if(rc != DC_OK){
670 fprintf(stderr,"client:dc_rpc_open failed. rc = %d¥n",rc);
680 goto END;
690 }
700
710 /*
720 ** Post the completion of user process start processing
730 */
740 rc = dc_adm_complete(DCNOFLAGS);
750 /* error processing */
760 if(rc != DC_OK){
770 fprintf(stderr,"client:dc_adm_complete failed. rc = %d¥n",rc);
780 goto END;
790 }
800
810 /*
820 * Begin transaction
830 */
840
850 rc = tx_begin();
860 /* error processing */
870 if(rc != DC_OK){
880 fprintf(stderr,"client:tx_begin failed. rc = %d¥n",rc);
890 goto END;
900 }
910
920 /*
930 * getinfo:
940 * get information for input parameter
950 */
960 status = getinfo(name,&out_data);
970 if(status != 0){
980 fprintf(stderr,"client:getinfo failed.rc = %d¥n",status);
990 }else{
1000 fprintf(stdout,"NAME: %s SEX: %c AGE: %s SALE:%ld¥n",
1010 out_data.name,
1020 out_data.sex,
1030 out_data.age,
1040 out_data.sale);
1050 }
1060 /*
1070 * commit transaction
1080 */
1090
1100 rc = tx_commit();
1110 /* error processing */
1120 if(rc != DC_OK){
1130 fprintf(stderr,"client:tx_commit failed. rc = %d¥n",rc);
1140 goto END;
1150 }
1160 /*
1170 * Termination processing
1180 */
1190 END:
1200 dc_rpc_close(DCNOFLAGS);
1210 return(0);
1220 }
マネジャプログラムの例を次に示します。
10 /*
20 *
30 * (3)マネジャプログラムの例
40 * sv.c
50 * Data Table = customers
60 * Functions = main()
70 * getinfo()
80 */
90
100 #include <stdio.h>
110 #include <string.h>
120 #include "sample.h"
130
140 /*
150 * name = customers
160 * func = customer information database
170 * field = name(20byte)
180 * sex(1byte)
190 * age(3byte)
200 * sale(4byte)
210 * record = 10 record(1 record = 28 byte)
220 */
230 static info_t customers[MAXRECORD] =
240 { {"Suzuki", 'M',"30",1000000},
250 {"Okada", 'F',"23",1500000},
260 {"Yoshida", 'F',"26", 800000},
270 {"Saitoh", 'M',"24",1000000},
280 {"Itoh", 'M',"35",1800000},
290 {"Nishikawa", 'M',"20", 300000},
300 {"Katoh", 'F',"28",1000000},
310 {"Satoh", 'F',"27",2100000},
320 {"Hasegawa", 'M',"25", 600000},
330 {"Tumura", 'M',"24",1100000}
340 };
350
360 /*
370 * name = getinfo()
380 * func = Manager routine for sample_ope interface
390 * (1)search suitable record.
400 * (2)set found record to output parameter.
410 * arg = name :i: name
420 * out_data:o: information for input parameter
430 * return = result
440 * 0 : success getinfo
450 */
460
470 error_status_t getinfo(name,out_data)
480 unsigned char *name;
490 info_t *out_data;
500 {
510 int i; /* counter of for loop */
520 info_t *ptr; /* pointer for search record */
530
540 /* point 1st record of database(customers) */
550 ptr = customers;
560
570 /* search until find record with same name or end of database */
580 for (i = 0; i < MAXRECORD; i++, ptr++) {
590 /* compare name */
600 if(strcmp(name,ptr->name) == 0) {
610 memcpy(out_data,ptr,sizeof(info_t));
620 return (0);
630 }
640 }
650 return(1);
660 }
ACFファイルの例を次に示します。
10 /*
20 *
30 * (4) ACFファイルの例 RPC TxRPCでだけ使えます。
40 * sample.acf
50 */
60
70 [auto_handle] interface sample_ope
80 {
90 [comm_status, fault_status] getinfo();
100 }
txidlコマンドの引数に指定する値によって,サーバプログラムのテンプレート例は異なります。-sptype ndceオプションを指定した場合の例を次に示します。
10 /*
20 *
30 * (5)サーバプログラムのテンプレート(名称 : serv.c)
40 * <-sptype ndceの場合>
50 */
60
70 #include <dctrp.h>
80
90 main()
100 {
110 idl_long_int rc;
120 rc = dc_rpc_open(DCNOFLAGS);
130 if(rc != DC_OK) {
140 printf("server : dc_rpc_open failed. rc=%d¥n", rc);
150 goto end_of_program;
160 }
170 rc=dc_rpc_mainloop(DCNOFLAGS);
180 if(rc != DC_OK) {
190 printf("server : dc_rpc_mainloop failed. rc=%d¥n", rc);
200 }
210 end_of_program:
220 dc_rpc_close(DCNOFLAGS);
230 exit(0);
240 }
txidlコマンドの引数に指定する値によって,ユーザサービス定義のテンプレート例は異なります。それぞれのオプションを指定した場合の例を次に示します。
10 /*
20 * (6)ユーザサービス定義 テンプレートの例
30 * <-cptype ndce の場合>
40 */
50
60 #Don't change the 2 definitions below.
70
80 set atomic_update = Y
90
100 set trn_expiration_time_suspend = Y
110
120 # If this program is SUP, set none. If other, set queue or socket.
130
140 set receive_from = none
150
160 #Set your modulename.
170
180 set module = "modulename"
190
200 #Set non-zero value.
210
220 set trn_expiration_time = 180
230
240 #Add any definition you need.
10 /*
20 * (6)ユーザサービス定義 テンプレートの例
30 * <-sptype ndce の場合>
40 */
50
60 #Don't change the 4 definitions below.
70
80
90 set atomic_update = Y
100
110 set trn_expiration_time_suspend = Y
120
130 set service_group = "sample_ope"
140
150 set service = "_getinfo=_getinfo"
160
170 #Set your modulename.
180
190 set module = "modulename"
200
210 #Set non-zero value.
220
230 set trn_expiration_time = 180
240
250 #Add any definition you need.
10 /*
20 * (6)ユーザサービス定義 テンプレートの例
30 * <-sptype wdce の場合>
40 */
50
60 #Don't change the 4 definitions below.
70
80 set atomic_update = N
90
100 set receive_from = queue
110
120 set service_group = "sample_ope"
130
140 set service = "_getinfo=_getinfo"
150
160 #Set your modulename.
170
180 set module = "modulename"
190
200 #Add any definition you need.
環境定義のテンプレートの例を次に示します。
10 /*
20 * (7)環境定義 テンプレートの例
30 * <-cptype wdce の場合>
40 */
50
60 #Set the 2 definition below
70
80 #DCNAMPORT =
90
100 #DCHOST =
110
120 #Add any definition you need.