Linkexpress 利用者プログラム開発ガイド |
目次
索引
![]() ![]() |
付録A サンプル | > A.1 転送APIのサンプル |
このサンプルプログラムは、以下のファイルに格納されています。
PCサーバ : インストールディレクトリ\sample\api\reapapl4.c
UNIXサーバ : インストールディレクトリ/SAMPLE/api/respapl4.c
このサンプルプログラムは、相手システムからの要求に対する応答を行う応答監視型利用者プログラム(常駐型)です。プログラムの説明を以下に示します。
GETINFでファイル転送の通知を受信し、受信したサービス種別がファイル転送の場合かつ、通知種別が開始情報の場合は、FTRNRSPで応答します。
通知種別が完了情報の場合は、TRANCOMPでLinkexpressに通知します。
GETINFで受信したサービス種別がメッセージ転送の場合はLinkexpressに完了通知受信をTRANCOMPで応答します。
また、利用者プログラムの停止契機としてGETINFの情報よりエラーコード、エラー詳細エラーコードが、50-10、60-30、60-40の場合に停止します。
apiresp4.cの内容を以下に示します。
/* * * AllRights Reserved Copyright (c) FUJITSU LIMITED 2004-2005 * */ /* * API sample program (resp no.4) */ /* * include file */ #include <windows.h> #include <sys/types.h> #include <string.h> #include <stdio.h> #include <fcntl.h> #include <lxapi.h> int main() { unsigned char message_text[ _DTSAPI_MSGTEXT_LEN+4 ] = { 0 }; int rtn_code = 0; int count = 0; unsigned long req_ident; dts_getinf_dcb_t input_getinf_dcb; dts_get_information_t output_getinf_dcb; dts_trancomp_dcb_t input_trancomp_dcb; dts_ftrnrsp_dcb_t input_ftrnrsp_dcb; dts_diagnostic_t output_diagnostic_dcb; printf( "転送監視機能サービスを開始します.スレッドID=%d\n", GetCurrentThreadId() ); while( 1 ) { /* * initialize */ memset( &input_getinf_dcb, 0, sizeof(dts_getinf_dcb_t) ); memset( &output_getinf_dcb, 0, sizeof(dts_get_information_t) ); /* * call getinf() */ while( 1 ) { printf( "\tgetinf() start\n" ); input_getinf_dcb.appl_name = (unsigned char*) "@_USRAPL"; input_getinf_dcb.info_kind = DTS_API_BOTH_INFO; input_getinf_dcb.req_kind = DTS_API_RESP; input_getinf_dcb.timer = 0; input_getinf_dcb.path_name = 0; rtn_code = getinf( &input_getinf_dcb, &output_getinf_dcb ); switch( rtn_code ) { case 0 : break; case -1 : if( count == 10 ) { printf( "\tgetinf異常\n" ); printf( "\tcategory_code\t: %d\n", output_getinf_dcb.diagnostic.category_code ); printf( "\terror_code\t: %d\n", output_getinf_dcb.diagnostic.error_code ); return( -1 ); } count++; continue; case -2 : continue; } break; } /* * 異常チェック */ /* Linkexpressの停止を契機にアプリ停止 */ if( (output_getinf_dcb.diagnostic.category_code == 50 && output_getinf_dcb.diagnostic.error_code == 10) || (output_getinf_dcb.diagnostic.category_code == 60 && output_getinf_dcb.diagnostic.error_code == 30) ) { printf( "\tLinkexpress停止\n" ); break; } if( output_getinf_dcb.info_kind == DTS_API_START_INFO ){ printf( "\t相手側システム名\t: %s\n", output_getinf_dcb.getinf_data.tstart.system_name ); printf( "\t使用する通信パス名\t: %s\n", output_getinf_dcb.getinf_data.tstart.path_name ); req_ident = output_getinf_dcb.getinf_data.tstart.req_ident; }else{ req_ident = output_getinf_dcb.getinf_data.tcomp.req_ident; } if ( output_getinf_dcb.service_kind == DTS_API_MESSAGETRAN ) { strncpy( (char *)message_text, (const char *)output_getinf_dcb.getinf_data.message.message_text, output_getinf_dcb.getinf_data.message.message_len ); /* * メッセージ転送要求の受付 */ memset( &input_trancomp_dcb, 0, sizeof(dts_trancomp_dcb_t) ); memset( &output_diagnostic_dcb, 0, sizeof(dts_diagnostic_t) ); input_trancomp_dcb.req_ident = req_ident; input_trancomp_dcb.appl_name = (unsigned char*)"@_USRAPL"; input_trancomp_dcb.req_kind = DTS_API_RESP; input_trancomp_dcb.appl_cont = DTS_API_APLCUT; printf( "\ttrancomp() start\n" ); if ( trancomp( &input_trancomp_dcb, &output_diagnostic_dcb ) < 0 ) { printf( "\trancomp異常\n" ); printf( "\tcategory_code\t: %d\n", output_diagnostic_dcb.category_code ); printf( "\terror_code\t: %d\n", output_diagnostic_dcb.error_code ); } printf( "\tメッセージテキスト\t: %s\n", message_text ); continue; } else { if ( output_getinf_dcb.info_kind == DTS_API_START_INFO ) { memset( &input_ftrnrsp_dcb, 0, sizeof(dts_ftrnrsp_dcb_t) ); memset( &output_diagnostic_dcb, 0, sizeof(dts_diagnostic_t) ); /* * 転送開始要求の受付 */ input_ftrnrsp_dcb.req_ident = req_ident; input_ftrnrsp_dcb.appl_name = (unsigned char*)"@_USRAPL"; input_ftrnrsp_dcb.attest_code = DTS_API_OK; input_ftrnrsp_dcb.error_detail = 0; input_ftrnrsp_dcb.local_user = 0; input_ftrnrsp_dcb.file_name = 0; input_ftrnrsp_dcb.file_attr = 0; input_ftrnrsp_dcb.data_type = 0; input_ftrnrsp_dcb.speed = 0; input_ftrnrsp_dcb.ret_tid = 0; printf( "\tftrnrsp() start\n" ); if ( ftrnrsp( &input_ftrnrsp_dcb, &output_diagnostic_dcb ) < 0 ) { printf( "\ftrnrsp異常\n" ); printf( "\tcategory_code\t: %d\n", output_diagnostic_dcb.category_code ); printf( "\terror_code\t: %d\n", output_diagnostic_dcb.error_code ); } continue; } else { memset( &input_trancomp_dcb, 0, sizeof(dts_trancomp_dcb_t) ); memset( &output_diagnostic_dcb, 0, sizeof(dts_diagnostic_t) ); /* * 転送完了の受付 */ printf( "\ttrancomp() start\n" ); input_trancomp_dcb.req_ident = req_ident; input_trancomp_dcb.appl_name = (unsigned char*)"@_USRAPL"; input_trancomp_dcb.req_kind = DTS_API_RESP; input_trancomp_dcb.appl_cont = DTS_API_APLCUT; if ( trancomp( &input_trancomp_dcb, &output_diagnostic_dcb ) < 0 ) { printf( "\trancomp異常\n" ); printf( "\tcategory_code\t: %d\n", output_diagnostic_dcb.category_code ); printf( "\terror_code\t: %d\n", output_diagnostic_dcb.error_code ); } continue; } } } return( 0 ); } |
/* * * AllRights Reserved Copyright (c) FUJITSU LIMITED 2004-2005 * */ /* * API sample program (resp no.4) */ /* * include file */ #include <sys/types.h> #include <string.h> #include <stdio.h> #include <fcntl.h> #include <lxapi.h> #include <thread.h> int main() { unsigned char message_text[ _DTSAPI_MSGTEXT_LEN+4 ] = { 0 }; int rtn_code = 0; int count = 0; unsigned long req_ident; dts_getinf_dcb_t input_getinf_dcb; dts_get_information_t output_getinf_dcb; dts_trancomp_dcb_t input_trancomp_dcb; dts_ftrnrsp_dcb_t input_ftrnrsp_dcb; dts_diagnostic_t output_diagnostic_dcb; printf( "The service of the function to monitor transfering begins. Thread ID=%d\n", thr_self() ); while( 1 ) { /* * initialize */ memset( &input_getinf_dcb, 0, sizeof(dts_getinf_dcb_t) ); memset( &output_getinf_dcb, 0, sizeof(dts_get_information_t) ); /* * call getinf() */ while( 1 ) { printf( "\tgetinf() start\n" ); input_getinf_dcb.appl_name = (unsigned char*) "@_USRAPL"; input_getinf_dcb.info_kind = DTS_API_BOTH_INFO; input_getinf_dcb.req_kind = DTS_API_RESP; input_getinf_dcb.timer = 0; input_getinf_dcb.path_name = 0; rtn_code = getinf( &input_getinf_dcb, &output_getinf_dcb ); switch( rtn_code ) { case 0 : break; case -1 : if( count == 10 ) { printf( "\tgetinf abnormal\n" ); printf( "\tcategory_code\t: %d\n", output_getinf_dcb.diagnostic.category_code ); printf( "\terror_code\t: %d\n", output_getinf_dcb.diagnostic.error_code ); return( -1 ); } count++; continue; case -2 : continue; } break; } /* * Check abnormality */ /* Stop this application when Linkexpress stop or getinf() is collected by cancelgif(). */ if( (output_getinf_dcb.diagnostic.category_code == 50 && output_getinf_dcb.diagnostic.error_code == 10) || (output_getinf_dcb.diagnostic.category_code == 60 && output_getinf_dcb.diagnostic.error_code == 30) ||(output_getinf_dcb.diagnostic.category_code == 60 && output_getinf_dcb.diagnostic.error_code == 40) ) { printf( "\tLinkexpress Stop\n" ); break; } if( output_getinf_dcb.info_kind == DTS_API_START_INFO ){ printf( "\tRemote system name\t: %s\n", output_getinf_dcb.getinf_data.tstart.system_name ); printf( "\tCommunication path name used\t: %s\n", output_getinf_dcb.getinf_data.tstart.path_name ); req_ident = output_getinf_dcb.getinf_data.tstart.req_ident; }else{ req_ident = output_getinf_dcb.getinf_data.tcomp.req_ident; } if ( output_getinf_dcb.service_kind == DTS_API_MESSAGETRAN ) { strncpy( (char *)message_text, (const char *)output_getinf_dcb.getinf_data.message.message_text, output_getinf_dcb.getinf_data.message.message_len ); /* * Acceptance of message transfer request */ memset( &input_trancomp_dcb, 0, sizeof(dts_trancomp_dcb_t) ); memset( &output_diagnostic_dcb, 0, sizeof(dts_diagnostic_t) ); input_trancomp_dcb.req_ident = req_ident; input_trancomp_dcb.appl_name = (unsigned char*)"@_USRAPL"; input_trancomp_dcb.req_kind = DTS_API_RESP; input_trancomp_dcb.appl_cont = DTS_API_APLCUT; printf( "\ttrancomp() start\n" ); if ( trancomp( &input_trancomp_dcb, &output_diagnostic_dcb ) < 0 ) { printf( "\trancomp abnormal\n" ); printf( "\tcategory_code\t: %d\n", output_diagnostic_dcb.category_code ); printf( "\terror_code\t: %d\n", output_diagnostic_dcb.error_code ); } printf( "\tmessage text\t: %s\n", message_text ); continue; } else { if ( output_getinf_dcb.info_kind == DTS_API_START_INFO ) { memset( &input_ftrnrsp_dcb, 0, sizeof(dts_ftrnrsp_dcb_t) ); memset( &output_diagnostic_dcb, 0, sizeof(dts_diagnostic_t) ); /* * Acceptance of transfer request to begin */ input_ftrnrsp_dcb.req_ident = req_ident; input_ftrnrsp_dcb.appl_name = (unsigned char*)"@_USRAPL"; input_ftrnrsp_dcb.attest_code = DTS_API_OK; input_ftrnrsp_dcb.error_detail = 0; input_ftrnrsp_dcb.local_user = 0; input_ftrnrsp_dcb.file_name = 0; input_ftrnrsp_dcb.file_attr = 0; input_ftrnrsp_dcb.data_type = 0; input_ftrnrsp_dcb.speed = 0; input_ftrnrsp_dcb.ret_tid = 0; printf( "\tftrnrsp() start\n" ); if ( ftrnrsp( &input_ftrnrsp_dcb, &output_diagnostic_dcb ) < 0 ) { printf( "\ftrnrsp abnormal\n" ); printf( "\tcategory_code\t: %d\n", output_diagnostic_dcb.category_code ); printf( "\terror_code\t: %d\n", output_diagnostic_dcb.error_code ); } continue; } else { memset( &input_trancomp_dcb, 0, sizeof(dts_trancomp_dcb_t) ); memset( &output_diagnostic_dcb, 0, sizeof(dts_diagnostic_t) ); /* * Acceptance of transfering completion */ printf( "\ttrancomp() start\n" ); input_trancomp_dcb.req_ident = req_ident; input_trancomp_dcb.appl_name = (unsigned char*)"@_USRAPL"; input_trancomp_dcb.req_kind = DTS_API_RESP; input_trancomp_dcb.appl_cont = DTS_API_APLCUT; if ( trancomp( &input_trancomp_dcb, &output_diagnostic_dcb ) < 0 ) { printf( "\trancomp abnormal\n" ); printf( "\tcategory_code\t: %d\n", output_diagnostic_dcb.category_code ); printf( "\terror_code\t: %d\n", output_diagnostic_dcb.error_code ); } continue; } } } return( 0 ); } |
目次
索引
![]() ![]() |