⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testclient.c

📁 Open VXI. This is a open source.
💻 C
字号:
/****************License************************************************ * * Copyright 2000-2001.  SpeechWorks International, Inc.   * * Use of this software is subject to notices and obligations set forth * in the SpeechWorks Public License - Software Version 1.1 which is * included with this software. * * SpeechWorks is a registered trademark, and SpeechWorks Here,  * DialogModules and the SpeechWorks logo are trademarks of SpeechWorks  * International, Inc. in the United States and other countries.  *  *********************************************************************** * * $Id: testClient.c,v 1.4.2.1.2.5 2001/10/03 16:33:54 dmeyer Exp $ * * Main test program. * ********************************************************************** */static const char *rcsid = 0 ? (char *) &rcsid :"$Id: testClient.c,v 1.4.2.1.2.5 2001/10/03 16:33:54 dmeyer Exp $";// -----1=0-------2=0-------3=0-------4=0-------5=0-------6=0-------7=0-------8#include <string.h>#include <stdio.h>#include <stdlib.h>#include "VXIlog.h"#include "VXItrd.h"#include "VXIplatform.h"#include "SBclientUtils.h"#include "ConfigFile.h"#define CHANNEL_CHECK_RESULT(_func, _res) \    if ((VXIint)(_res) != 0) { \        fprintf(stderr, "ERROR: %s failed, error code %i, file %s, line %i\n",\                (_func), (_res), __FILE__, __LINE__); \        return ((VXItrdThreadArg)_res); \    }#ifdef WIN32#define PATH_SEPARATOR '\\'#else#define PATH_SEPARATOR '/'#endif/* Defaults for command line arguments */#ifdef OPENVXI#define DEFAULT_CONFIG_FILENAME       "OSBclient.cfg"#else#define DEFAULT_CONFIG_FILENAME       "SBclient.cfg"#endif#define DEFAULT_NB_CHANNELS           1#define DEFAULT_MAX_CALLS             -1 /* loop forever *//* Configuration file parameters */#define TEST_CLIENT_VXML_URL          L"testClient.vxmlURL"/* Structure for controlling channel threads */typedef struct ChannelThreadArgs {  VXIunsigned    channelNum;  VXIunsigned    maxCalls;  const VXIMap  *configArgs;  const VXIchar *vxmlURL;  VXItrdThread  *threadHandle;} ChannelThreadArgs;static void ShowResult(const VXIValue *result_val, int ChanNum, VXIplatform *platform){  switch (VXIValueGetType(result_val)) {  case VALUE_INTEGER:    SBclientDiag(platform, 60001, L"testClient::ShowResult",		 L"VXIInteger\tResult Value: %d\n",		 VXIIntegerValue((const VXIInteger *) result_val));    break;  case VALUE_FLOAT:    SBclientDiag(platform, 60001, L"testClient::ShowResult",		 L"VXIFloat\tResult Value: %f\n", 		 VXIFloatValue((const VXIFloat *) result_val));    break;  case VALUE_STRING:    SBclientDiag(platform, 60001, L"testClient::ShowResult",		 L"VXIString\tResult Value: %s\n", 		 VXIStringCStr((const VXIString *) result_val));    break;  case VALUE_PTR:    SBclientDiag(platform, 60001, L"testClient::ShowResult",		 L"Result Type: VXIPtr: 0x%p\n",		 VXIPtrValue((const VXIPtr *) result_val));    break;      case VALUE_MAP:    SBclientDiag(platform, 60001, L"testClient::ShowResult",		 L"Result Type: VXIMap");    break;  case VALUE_VECTOR:    SBclientDiag(platform, 60001, L"testClient::ShowResult",		 L"Result Type: VXIVector");    break;  case VALUE_CONTENT:    SBclientDiag(platform, 60001, L"testClient::ShowResult",		 L"Result Type: VXIContent");    break;  default:    SBclientDiag(platform, 60001, L"testClient::ShowResult",		 L"Result Type: Unknown type");    break;  }}static VXITRD_DEFINE_THREAD_FUNC(ChannelThread, userData){    const ChannelThreadArgs *channelArgs = (const ChannelThreadArgs *)userData;    VXIunsigned numCalls = 0;    VXIplatformResult platformResult;    VXIplatform *platform;    VXIMap *channelConfig;    if ( channelArgs->configArgs )      channelConfig = VXIMapClone (channelArgs->configArgs);    else      channelConfig = NULL;    platformResult =         VXIplatformCreateResources(channelArgs->channelNum, channelConfig,				   &platform);    CHANNEL_CHECK_RESULT("VXIplatformCreateResources()", platformResult);    while ((channelArgs->maxCalls == -1) || 	   (numCalls < channelArgs->maxCalls)) {      numCalls++;      printf("Channel %d: Waiting for Call %d\n", channelArgs->channelNum,	     numCalls);      platformResult = VXIplatformEnableCall(platform);      CHANNEL_CHECK_RESULT("VXIplatformEnableCall()", platformResult);      SBclientDiag(platform, 60001, L"testClient::ChannelThread",		   L"About to call VXIplatformWaitForCall");      platformResult = VXIplatformWaitForCall(platform);      CHANNEL_CHECK_RESULT("VXIplatformWaitForCall()", platformResult);      printf("Channel %d: In a Call\n", channelArgs->channelNum);      SBclientDiag(platform, 60001, L"testClient::ChannelThread",L"In a Call");      {	VXIMap *sessionArgs = VXIMapCreate();	VXIValue *result = NULL ;	platformResult = VXIplatformProcessDocument(channelArgs->vxmlURL,						    sessionArgs, &result,						    platform);	if((VXIint) platformResult != 0){	  fprintf(stderr, "Error: ProcessDocument returned error code %i\n",		  platformResult);	}	else{	  if(result) {	    ShowResult(result, channelArgs->channelNum, platform);	    VXIValueDestroy(&result);	  }else{	    SBclientDiag(platform, 60001, L"testClient::ChannelThread",			 L"NULL result");	  }	}	VXIMapDestroy(&sessionArgs);      }      printf("Channel %d: Call Terminated\n", channelArgs->channelNum);      SBclientDiag(platform, 60001, L"testClient::ChannelThread",		   L"Call Terminated");    }    platformResult = VXIplatformDestroyResources(&platform);    CHANNEL_CHECK_RESULT("VXIplatformDestroyResources()", platformResult);        if (channelConfig)      VXIMapDestroy(&channelConfig);    VXItrdThreadExit(0);    return 0;}int main (int argc, char *argv[]){    char *configFile = NULL, *ptr = NULL;    VXIchar *vxmlURL = NULL;    VXIplatformResult platformResult;    VXItrdResult trdResult;    VXIMap *configArgs = NULL;    VXIunsigned nbChannels = DEFAULT_NB_CHANNELS;    VXIunsigned maxChannels, maxCalls = DEFAULT_MAX_CALLS;    long tempLong;    int i;    VXIunsigned j;    ChannelThreadArgs *channelArgs;    VXItrdThreadArg status;    printf("\nCommand-line arguments :\n"	   "  [-url vxmlDocURL] [-channels nbChannels] [-config configFile] "	   "[-calls maxCalls]\n"	   "To use all hardware channels, set nbChannels to 0\n"	   "To take unlimited calls, set maxCalls to -1\n\n");    if( ( argc % 2 ) != 1 )    {        printf("ERROR: Invalid number of command-line arguments\n");        return 1;    }    for( i = 1 ; i < argc ; i += 2 )    {        int j = i + 1;        /* Determine the URL of the initial document to be fetched */        if( strcmp( argv[i], "-url" ) == 0 )        {            VXIunsigned urlLen = strlen(argv[j]) + 1;            vxmlURL = (VXIchar *) calloc(urlLen, sizeof(VXIchar));            CLIENT_CHECK_MEMALLOC( vxmlURL, "URL buffer" );            mbstowcs(vxmlURL, argv[j], urlLen);        }        /* Determine the number of channels */        else if( strcmp( argv[i], "-channels" ) == 0 )        {            tempLong = strtol(argv[j], &ptr, 10);            if(( tempLong < 0 ) || ( *ptr != '\0' ))            {	        fprintf(stderr, "ERROR: Invalid number of channels '%s'\n",			argv[j]);                return 1;            }	    nbChannels = (VXIunsigned) tempLong;        }	/* Determine the maximum number of calls */        else if( strcmp( argv[i], "-calls" ) == 0 )        {            tempLong = strtol(argv[j], &ptr, 10);            if(( tempLong < -1 ) || ( *ptr != '\0' ))            {	        fprintf(stderr, "ERROR: Invalid number of calls '%s'\n",			argv[j]);                return 1;            }	    maxCalls = (VXIunsigned) tempLong;        }        /* Determine the location of the config file */        else if( strcmp( argv[i], "-config" ) == 0 )        {            configFile = (char *) calloc(strlen(argv[j]) + 1, sizeof(char));            CLIENT_CHECK_MEMALLOC( configFile, "config filename" );            strcpy( configFile, argv[j] );        }        else        {	    fprintf(stderr, "ERROR: Invalid command-line option '%s'\n",		    argv[i]);            return 1;        }    }    /* Use the default location for the config file */    if( configFile == NULL ) {        char *swiDir = getenv( "SWISBSDK" );        if(( swiDir == NULL ) || ( swiDir[0] == '\0' )) swiDir = ".";        configFile = (char *) calloc(strlen( swiDir ) + strlen( "config" ) +				     strlen( DEFAULT_CONFIG_FILENAME ) + 3,				     sizeof(char));        CLIENT_CHECK_MEMALLOC( configFile, "config filename" );        sprintf( configFile, "%s%c%s%c%s", swiDir, PATH_SEPARATOR,                 "config", PATH_SEPARATOR, DEFAULT_CONFIG_FILENAME );    }    printf("Using config file '%s'\n\n", configFile);    /* Parse the configuration file */    platformResult = ParseConfigFile(&configArgs, configFile);    CLIENT_CHECK_RESULT("ParseConfigFile()", platformResult);    /* Determine the URL if not specified on the command line */    if(vxmlURL == NULL) {        const VXIString *urlStr =             (const VXIString *)VXIMapGetProperty(configArgs,						 TEST_CLIENT_VXML_URL);        if(urlStr == NULL) {	    fprintf(stderr, "ERROR: No VXML document specified\n");            return 1;        } else if (VXIValueGetType((const VXIValue *)urlStr) != VALUE_STRING) {	    fprintf(stderr, "ERROR: %S must be set to a VXIString value\n",		    TEST_CLIENT_VXML_URL);	    return 1;	}        vxmlURL = (VXIchar *)VXIStringCStr(urlStr);    }    printf("Using VXML document '%S'\n\n", vxmlURL);    /* Initialize the platform */    platformResult = VXIplatformInit(configArgs, &maxChannels);    CLIENT_CHECK_RESULT("VXIplatformInit()", platformResult);    if(maxChannels < nbChannels) {        printf("WARNING: %d channels requested on the command line but only " 	       "%d available\n\n", nbChannels, maxChannels);        nbChannels = maxChannels;    } else if (nbChannels == 0) {        nbChannels = maxChannels;    }    printf("Using %d channel(s)\n\n", nbChannels);    /* Start the call processing threads */    if(nbChannels > 0) {        channelArgs = (ChannelThreadArgs *)	  calloc(nbChannels, sizeof(ChannelThreadArgs));        CLIENT_CHECK_MEMALLOC( channelArgs, "channel thread args array" );        for(j = 0; j < nbChannels ; j++) {	    channelArgs[j].channelNum = j;	    channelArgs[j].maxCalls = maxCalls;	    channelArgs[j].configArgs = configArgs;	    channelArgs[j].vxmlURL = vxmlURL;            trdResult = VXItrdThreadCreate(&channelArgs[j].threadHandle,					   ChannelThread,                                           (VXItrdThreadArg) &channelArgs[j]);            CLIENT_CHECK_RESULT("VXItrdThreadCreate()", trdResult);        }    }    else {        fprintf(stderr, "ERROR: No channels available, file %s, line %i\n",                __FILE__, __LINE__);    }    /* Wait for threads to finish */    for (j = 0; j < nbChannels; j++) {      trdResult = VXItrdThreadJoin (channelArgs[j].threadHandle, &status, -1);      CLIENT_CHECK_RESULT("VXItrdThreadJoin()", trdResult);      trdResult = VXItrdThreadDestroyHandle (&channelArgs[j].threadHandle);      CLIENT_CHECK_RESULT("VXItrdThreadDestroyHandle()", trdResult);      if ( status != 0 ) {	/* Need to cast this twice, some compilers won't allow going directly	   to VXIplatformResult */	platformResult = (VXIplatformResult) ((VXIint) status);      }    }        /* Shut down the platform */    platformResult = VXIplatformShutdown();    CLIENT_CHECK_RESULT("VXIplatformShutdown()", platformResult);    /* Clean up */    if ( vxmlURL )      free(vxmlURL);    if ( configArgs )      VXIMapDestroy(&configArgs);    if ( configFile )      free(configFile);    if ( channelArgs )      free(channelArgs);    if (platformResult == VXIplatform_RESULT_SUCCESS)      printf("Successfully exiting\n");    else      printf("Exiting with errors, rc = %d\n", platformResult);    return (VXIint) platformResult;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -