📄 loopmain.c
字号:
/////////////////////////////////////////////////////////////////////// loopmain.c//// IP phone loopback app main //// Copyright Netergy Microelectronics 2000, 2001//////////////////////////////////////////////////////////////////////#include <NNstyle.h>#include <syslog.h>#include <sys/types.h> /* for socket() */#include <sys/socket.h> /* for socket() */#include <unistd.h> /* for fcntl() */#include <fcntl.h> /* for fcntl() */#include <netinet/in.h>#include <arpa/inet.h>#include <unistd.h>#include <sys/ioctl.h>#include <net/if_arp.h>#include <netdb.h>#include <pthread.h>#include "stdlib.h"#include <string.h>#include <stdio.h>#include "dllist.h"#include "rtpapi.h"#include "ntpapi.h"#include "h323ccapi.h"#include "protocol.h"#include "h4507ccapi.h"#include "common.h"#include "endpoint.h"#include "stack.h"int g_iCmd = 0;BOOL g_bDirectCall = FALSE;char g_chNumber[30];LONG g_iEndPoint = 1;//FILE *fpLog, *fpMsg;char *g_pchCfgFile;void* _StdinThread(void* pArg);void _ProcessMWIActivate();void _ProcessMWIDeactivate();extern void InterceptDumpMemory();////////////////////////////////////////////////////////////////////// Main entry point////////////////////////////////////////////////////////////////////int main(int argc, char **argv) { pthread_t tid; /* create the main processing thread */ pthread_attr_t thrAttr; int i = 0; int error; if (argc < 2) { printf("You can use config file as an argument: %s <config file>\n",argv[0]); g_pchCfgFile=NULL; } else { g_pchCfgFile = argv[1]; } /* initialize drivers, stacks, etc. */ _Initialization(); for (i = 0; i < END_POINT_NUM; i++) { /* Create instance */ CreateInstance(&xEndPoint[i]); } // Create call service thread error = pthread_attr_init(&thrAttr); if (error) { ASSERT(0); } error = pthread_create(&tid,&thrAttr,_StdinThread,NULL); if (error) { ASSERT(0); } else { printf("pthread_create():: %d\n", (SHORT)tid); } // main processing loop while (!g_bQuit) { msleep(10000000); for (i = 0; i < END_POINT_NUM; i++) { EndPointProcess(&xEndPoint[i]); EndPointProcessRtp(&xEndPoint[i]); }#if 0 if (g_bDirectCall) { END_POINT *pEndPoint = &xEndPoint[g_iEndPoint-1]; g_bDirectCall = FALSE; pthread_mutex_lock(&pEndPoint->mMutex); strcpy(pEndPoint->szDialString, g_chNumber); pEndPoint->bDirectCall = TRUE; pEndPoint->fpHandler(EVENT_DIAL_MATCH, pEndPoint, 0, NULL); pEndPoint->bDirectCall = FALSE; pthread_mutex_unlock(&pEndPoint->mMutex); }#endif //AudioProcess(); } APPLOG(LOG_INFO,"Unregisterring from gatekeeper...\n"); for (i = 0; i < END_POINT_NUM; i++) { // unregister from gatekeeper StackUnregister(&xEndPoint[i]); } // shutdown H323 _ShutdownH323(); // shutdown RTP _ShutdownRTP(); // give time for shutdown to complete msleep(500);// fclose(fpLog);// fclose(fpMsg); APPLOG(LOG_INFO,"*** Exiting H323 loopback app ***\n"); return 0;}//////////////////////////////////////////////////////////////////////// _StdinThread//// Thread for reading command line input////////////////////////////////////////////////////////////////////void* _StdinThread(void* pArg){ char chInput[100]; while (!g_bQuit) { msleep(100); fgets(chInput, 100, stdin); printf("_StdinThread() %d\n", chInput[0]); switch(chInput[0]) { case 'e': { int nNewEndpoint = atol(&chInput[1]); if (nNewEndpoint <= END_POINT_NUM && nNewEndpoint != g_iEndPoint) { g_iEndPoint = nNewEndpoint; } } break; case 'p': g_iCmd = HANDSET_OFF_HOOK_EVENT; g_bOffHook=TRUE; break; case 'o': g_iCmd = HANDSET_ON_HOOK_EVENT; g_bOffHook=FALSE; break; case 'c': strcpy(g_chNumber,chInput+1); g_iCmd = HANDSET_KEY_DOWN_EVENT; break; case 'C': strcpy(g_chNumber,chInput+1); g_bDirectCall = TRUE; break; case 'f': strcpy(g_chNumber,chInput+1); g_iCmd = HANDSET_FLASH_HOOK_EVENT; break;#if 0 case 'm': InterceptDumpMemory(); break;#endif /* 0 */ case 'q': g_bQuit=TRUE; break; case 'H': // hold g_chNumber[0] = '1'; // f1 g_iCmd = HANDSET_FLASH_HOOK_EVENT; break; case 'T': // transfer strcpy(g_chNumber+1,chInput+1); g_chNumber[0] = '4'; // f4 g_iCmd = HANDSET_FLASH_HOOK_EVENT; break; case 'V': // voice mail strcpy(g_chNumber+2,chInput+1); g_chNumber[0] = '*'; // *4 g_chNumber[1] = '4'; g_iCmd = HANDSET_KEY_DOWN_EVENT; break; case 'v': // cancel voice mail g_chNumber[0] = '*'; // *5 g_chNumber[1] = '5'; g_iCmd = HANDSET_KEY_DOWN_EVENT; break; case 'L': // flash (switch line) g_chNumber[0] = '*'; // f* g_iCmd = HANDSET_FLASH_HOOK_EVENT; break; case 'D': // forwarding on strcpy(g_chNumber+2,chInput+1); g_chNumber[0] = '*'; // *2 g_chNumber[1] = '2'; g_iCmd = HANDSET_KEY_DOWN_EVENT; break; case 'd': // forwarding off g_chNumber[0] = '*'; // *3 g_chNumber[1] = '3'; g_iCmd = HANDSET_KEY_DOWN_EVENT; break; case 'M': strcpy(g_chNumber,chInput+1); _ProcessMWIActivate(); break; case 'm': strcpy(g_chNumber,chInput+1); _ProcessMWIDeactivate(); break; case '#': strcpy(g_chNumber,chInput); g_iCmd = HANDSET_KEY_DOWN_EVENT; break; case '?': case 'h': printf("p => Pickup; o => Hangup; c<n> => Call; q => Quit\n"); printf("f => Flash; H => Hold; L => Line; T<n> => Transfer\n"); printf("V<n> => Voice mail number: v => Voice mail cancel\n"); printf("D<n> => Forwarding number: d => Forwarding cancel\n"); printf("M<n> => Activate MWI: m<n> => Deactivate MWI\n"); printf("#329 => FAX_TONE_DETECT\n"); printf("#42<n> => Group member add: #47<n> => Group member remove\n"); printf("#72[<n>] => Call park: #74[<n>] => Call pickup\n"); printf("#78 => Inquire parked entry: #96 => Recall(Call Completion)\n"); printf("#8673447832 => Unregister )\n"); break; default: // printf("Unknown command type h for help\n"); break; } } return NULL;}//////////////////////////////////////////////////////////////////////// HandsetProcess//// Process command line input and return event and data to endpoint process////////////////////////////////////////////////////////////////////E_HANDSET_RETURN_VALUES HandsetProcess(OCTET oLineNumber, unsigned char *chKeyPressed){ E_HANDSET_RETURN_VALUES eEvent = HANDSET_NO_EVENT;#if 0 if (g_iCmd != HANDSET_NO_EVENT) printf("\n");#endif if (oLineNumber == g_iEndPoint) { eEvent = g_iCmd; switch (g_iCmd) { case HANDSET_KEY_DOWN_EVENT: *chKeyPressed = g_chNumber[0]; if (strlen(g_chNumber) > 1) { strcpy(g_chNumber, g_chNumber+1); } else { g_iCmd = HANDSET_NO_EVENT; } break; case HANDSET_FLASH_HOOK_EVENT: if (strlen(g_chNumber) > 0) { g_iCmd = HANDSET_KEY_DOWN_EVENT; } else { g_iCmd = HANDSET_NO_EVENT; } break; default: g_iCmd = HANDSET_NO_EVENT; break; } } return eEvent;}//////////////////////////////////////////////////////////////////////// _ProcessMWIActivate// activate the message waiting indication on the remote endpoint//////////////////////////////////////////////////////////////////////void _ProcessMWIActivate(){ char *pchCalleeAddress=NULL; H_CALL hCall; ASSERT(strlen(g_chNumber)>0); pchCalleeAddress=(char *)calloc(1,strlen(g_chNumber)+7); ASSERT(pchCalleeAddress!=NULL); printf("Sending MWI_Acitvate.Inv\n"); strcpy(pchCalleeAddress,"E164:"); strcat(pchCalleeAddress,g_chNumber); /* allways handle at endpoint 0 */ H4507MWIActivate(xEndPoint->hInstance, &hCall, pchCalleeAddress, NULL, 1, // oBasicSvc 0, // MSC id, addr xEndPoint->szPhoneNumber, // MSC E164 alias xEndPoint->szCallerIDName, // MSC H323 Id NULL, // MSC string 3, // Number of messages TRUE, NULL, NULL, // originating number NULL, // time stamp 0, FALSE); // priority printf("Activating MWI at %s\n",pchCalleeAddress); free(pchCalleeAddress);}//////////////////////////////////////////////////////////////////////// _ProcessMWIDeactivate// deactivate the message waiting indication on the remote endpoint//////////////////////////////////////////////////////////////////////void _ProcessMWIDeactivate(){ char *pchCalleeAddress=NULL; H_CALL hCall; ASSERT(strlen(g_chNumber)>0); pchCalleeAddress=(char *)calloc(1,strlen(g_chNumber)+7); ASSERT(pchCalleeAddress!=NULL); printf("Sending MWI_Deacitvate.Inv\n"); strcpy(pchCalleeAddress,"E164:"); strcat(pchCalleeAddress,g_chNumber); /* allways handle at endpoint 0 */ H4507MWIDeactivate(xEndPoint->hInstance, &hCall, pchCalleeAddress, NULL, 1, // oBasicSvc 0, // MSC id, addr xEndPoint->szPhoneNumber, // MSC E164 alias xEndPoint->szCallerIDName, // MSC H323 Id NULL, // MSC string FALSE, FALSE); // Callback printf("Deactivating MWI at %s\n",pchCalleeAddress); free(pchCalleeAddress);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -