?? recvsm.cpp
字號:
/* Module: SMGP API File Name: RecvSM.cpp Class Name: Version: 1.3 Author: Eric Xu Create Date: 2002-6-4 12:04 Last Modify Date:2002-6-4 12:04 Description: Receive short message from SMGW.*/#include <stdio.h>#include <stdlib.h>#include <string.h>#ifdef _WIN32#include <io.h>#include <winsock2.h>#else#include <unistd.h>#include <ctype.h>#endif#include "smgpdef.h"#include "SMGPAPI.hpp"void Usage(char *sProgram);#if 0int MOProcess(DeliverResp *pDeliverResp);#endif// public variableschar sParamFile[100 +1] = {0}, sMsgFile[100+1] = {0};int nOutput = 1;int main(int argc, char ** argv){ int n; FILE *pFile; int nTimeout = 0, nFunType = 0; DeliverResp theDeliverResp; int nRepeat = 0; memset(&theDeliverResp, 0, sizeof(theDeliverResp)); // get argument for(n=1; n<argc; ++n) { if(strcmp(argv[n], "-n") == 0) { nOutput = 0; } else if(strcmp(argv[n], "-t") == 0) { n++; nTimeout = atoi(argv[n]); } else if(strcmp(argv[n], "-p") == 0) { n++; strncpy(sParamFile, argv[n], 100); sParamFile[100] ='\0'; } else if(strcmp(argv[n], "-m") == 0) { n++; strncpy(sMsgFile, argv[n], 100); sMsgFile[100]='\0'; } else if(strcmp(argv[n], "-f") == 0) { n++; nFunType = atoi(argv[n]); } else if(strcmp(argv[n], "-r") == 0) { n++; nRepeat = atoi(argv[n]); } else { if(nOutput == 1) { Usage(argv[0]); } exit(1); } } if(strlen(sMsgFile) == 0 || strlen(sParamFile) == 0) { if(nOutput == 1) { printf("No parameter file or message file!\n"); } exit(1); } // initiate API if(InitSMGPAPI() != 0) { if(nOutput == 1) { printf("Fail to call InitSMGPAPI!\n"); } exit(1); } for(int iTimes=0; iTimes<= nRepeat; iTimes++ )#if 0 if(nFunType == 1) { if(SMGPDeliverCallback(MOProcess) != 0) { if(nOutput == 1) { printf("Fail to call SMGPDeliverCallback!\n"); } exit(1); } } else {#endif if(nFunType == 0) { if(SMGPDeliver(nTimeout, &theDeliverResp) != 0) { if(nOutput == 1) { printf("Fail to call SMGPDeliver!\n"); } exit(1); } Sleep(1000); // write receiving short message into files pFile = fopen(sParamFile, "w"); if(pFile == NULL) { if(nOutput == 1) { printf("Fail to open file %s!\n", sParamFile); } exit(1); } fprintf(pFile, "%s\n", theDeliverResp.sMsgID); fprintf(pFile, "%d\n", theDeliverResp.nIsReport); fprintf(pFile, "%d\n", theDeliverResp.nMsgFormat); fprintf(pFile, "%s\n", theDeliverResp.sSrcTermID); fprintf(pFile, "%s\n", theDeliverResp.sDestTermID); fprintf(pFile, "%d\n", theDeliverResp.nMsgLen); fprintf(pFile, "%s\n", theDeliverResp.sReserved); fclose(pFile); pFile = fopen(sMsgFile, "wb"); if(pFile == NULL) { if(nOutput == 1) { printf("Fail to open file %s!\n", sMsgFile); } exit(1); } fwrite(theDeliverResp.sMsgContent, theDeliverResp.nMsgLen , 1, pFile); fclose(pFile); } else if(nFunType == 2) { while(1) { if(SMGPDeliver(nTimeout, &theDeliverResp) != 0) { if(nOutput == 1) { printf("Fail to call SMGPDeliver!\n"); } continue; } printf("\n"); printf("MsgID=%s\n", theDeliverResp.sMsgID); printf("IsReply=%d\n", theDeliverResp.nIsReport ); printf("MsgFormat=%d\n", theDeliverResp.nMsgFormat); printf("SrcTermID=%s\n", theDeliverResp.sSrcTermID); printf("DestTermID=%s\n", theDeliverResp.sDestTermID); printf("MsgLen=%d\n", theDeliverResp.nMsgLen ); printf("\n#%s#\n", theDeliverResp.sMsgContent); printf("%s\n", theDeliverResp.sReserved); } }#if 0 }#endif exit(0); return(0);}void Usage(char *sProgram){ printf("Usage: %s [-n] [-f function] <-t timeout> <-p parameter_file> <-m message_file>\n", sProgram); printf(" -n: no message output\n"); printf(" -t: waiting time, in second. 0 means wait forever.\n"); printf(" -p: receiving short message parameter file name.\n"); printf(" -m: receiving short message content file name.\n"); printf("e.g.: %s -t 10 -p sm.par -m sm.txt\n", sProgram);}#if 0int MOProcess(DeliverResp *pDeliverResp){ static int nCounter = 0; char sFileName[100]; FILE *pFile; sprintf(sFileName, "%s.%03d", sParamFile, nCounter); pFile = fopen(sFileName, "w"); if(pFile == NULL) { if(nOutput == 1) { printf("Fail to open file %s!\n", sFileName); } return(1); } fprintf(pFile, "%s\n", pDeliverResp->sMsgID ); fprintf(pFile, "%d\n", pDeliverResp->nIsReport ); fprintf(pFile, "%d\n", pDeliverResp->nMsgFormat ); fprintf(pFile, "%s\n", pDeliverResp->sSrcTermID ); fprintf(pFile, "%s\n", pDeliverResp->sDestTermID ); fprintf(pFile, "%d\n", pDeliverResp->nMsgLen ); fprintf(pFile, "%s\n", pDeliverResp->sReserved); fclose(pFile); sprintf(sFileName, "%s.%03d", sMsgFile, nCounter); pFile = fopen(sFileName, "wb"); if(pFile == NULL) { if(nOutput == 1) { printf("Fail to open file %s!\n", sFileName); } return(1); } fwrite(pDeliverResp->sMsgContent, pDeliverResp->nMsgLength , 1, pFile); fclose(pFile); nCounter++; return(0);}#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -