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

📄 osbtel.cpp

📁 Open VXI. This is a open source.
💻 CPP
字号:
/****************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. *  *********************************************************************** * * An implementation of the OSBtelInterface object designed for scripted *   QA of VXI interpreter * ***********************************************************************/#define OSBTEL_EXPORTS#include "OSBtel.h"#include <cstdio>#include <string>#include <cstring>#define VXIstrcmp wcscmp#include "VXIvalue.h"typedef std::basic_string<VXIchar> vxistring;  // ------*---------*---------*---------*---------*---------*---------*---------// Global for the base diagnostic tag ID//static VXIunsigned gblDiagLogBase = 0;// Constants for diagnostic logging tags//static const VXIunsigned DIAG_TAG_SIGNALING = 0;// OSBtel implementation of the VXItel interface//extern "C" {struct OSBtelImpl {  // Base interface, must be first  OSBtelInterface osbIntf;  // Log interface for this resource  VXIlogInterface *log;};}// A few conversion functions...static inline OSBtelImpl * ToOSBtelImpl(VXItelInterface * i){ return reinterpret_cast<OSBtelImpl *>(i); }static inline OSBtelImpl * ToOSBtelImpl(OSBtelInterface * i){ return reinterpret_cast<OSBtelImpl *>(i); }/******************************************************* * * Utility functions * *******************************************************/ /** * Log an error */static VXIlogResult Error(OSBtelImpl *impl, VXIunsigned errorID,			  const VXIchar *format, ...){  VXIlogResult rc;  va_list arguments;  if ((! impl) || (! impl->log))    return VXIlog_RESULT_NON_FATAL_ERROR;    if (format) {    va_start(arguments, format);    rc = (*impl->log->VError)(impl->log, COMPANY_DOMAIN L".OSBtel", 			      errorID, format, arguments);    va_end(arguments);  } else {    rc = (*impl->log->Error)(impl->log, COMPANY_DOMAIN L".OSBtel",			     errorID, NULL);  }  return rc;}/** * Log a diagnostic message */static VXIlogResult Diag(OSBtelImpl *impl, VXIunsigned tag, 			 const VXIchar *subtag, const VXIchar *format, ...){  VXIlogResult rc;  va_list arguments;  if ((! impl) || (! impl->log))    return VXIlog_RESULT_NON_FATAL_ERROR;  if (format) {    va_start(arguments, format);    rc = (*impl->log->VDiagnostic)(impl->log, tag + gblDiagLogBase, subtag,				   format, arguments);    va_end(arguments);  } else {    rc = (*impl->log->Diagnostic)(impl->log, tag + gblDiagLogBase, subtag,				  NULL);  }  return rc;}/******************************************************* * * Method routines for OSBtelInterface structure * *******************************************************/ // Get the VXItel interface version supported//static VXIint32 OSBtelGetVersion(void){  return VXI_CURRENT_VERSION;}// Get the implementation name//static const VXIchar* OSBtelGetImplementationName(void){  static const VXIchar IMPLEMENTATION_NAME[] = COMPANY_DOMAIN L".OSBtel";  return IMPLEMENTATION_NAME;}// Begin a session//static VXItelResult OSBtelBeginSession(VXItelInterface * pThis, VXIMap *){  return VXItel_RESULT_SUCCESS;}// End a session//staticVXItelResult OSBtelEndSession(VXItelInterface *pThis, VXIMap *){  return VXItel_RESULT_SUCCESS;}staticVXItelResult OSBtelGetStatus(VXItelInterface * pThis, VXItelStatus *status){  *status = VXItel_STATUS_ACTIVE;  return VXItel_RESULT_SUCCESS;}/** * Disconnect caller (ie hang up). * * @param  ch   A handle to the channel resource manager */staticVXItelResult OSBtelDisconnect(VXItelInterface * vxip){  OSBtelImpl *impl = ToOSBtelImpl(vxip);  Diag(impl, DIAG_TAG_SIGNALING, NULL, L"Disconnect");  return VXItel_RESULT_SUCCESS;}/** * Blind Transfer. */staticVXItelResult OSBtelTransferBlind(VXItelInterface * vxip, 				 const VXIMap * prop,				 const VXIchar * transferDestination,				 const VXIMap * data,				 VXIMap ** resp){  OSBtelImpl *impl = ToOSBtelImpl(vxip);  Diag(impl, DIAG_TAG_SIGNALING, NULL, L"TransferBlind: %s",        transferDestination);  *resp = VXIMapCreate();  VXIMapSetProperty(*resp, L"status",		    (VXIValue *) VXIStringCreate(L"far_end_disconnect"));  VXIMapSetProperty(*resp, L"duration", (VXIValue *)VXIIntegerCreate(122));  return VXItel_RESULT_SUCCESS;}/** * Bridging Transfer. * */staticVXItelResult OSBtelTransferBridge(VXItelInterface * vxip, 				  const VXIMap * prop,				  const VXIchar * transferDestination,				  const VXIMap * data,				  VXIMap **resp){  OSBtelImpl *impl = ToOSBtelImpl(vxip);  Diag(impl, DIAG_TAG_SIGNALING, NULL, L"TransferBridge: %s",        transferDestination);  *resp = VXIMapCreate();  VXIMapSetProperty(*resp, L"status", 		    (VXIValue *) VXIStringCreate(L"noanswer"));  VXIMapSetProperty(*resp, L"duration", (VXIValue *) VXIIntegerCreate(0));  return VXItel_RESULT_SUCCESS;}/** * Enable calls on the channel * */static VXItelResultOSBtelEnableCall(struct OSBtelInterface  *pThis){  if (! pThis) return VXItel_RESULT_INVALID_ARGUMENT;  return VXItel_RESULT_SUCCESS;}/** * Wait for and answer a call on the channel * */static VXItelResultOSBtelWaitForCall(struct OSBtelInterface  *vxip,		  VXIMap                 **telephonyProps){  if ((! vxip) || (! telephonyProps))    return VXItel_RESULT_INVALID_ARGUMENT;  OSBtelImpl *impl = ToOSBtelImpl(vxip);  Diag(impl, DIAG_TAG_SIGNALING, NULL, L"New call");  *telephonyProps = VXIMapCreate();  if (! *telephonyProps) return VXItel_RESULT_OUT_OF_MEMORY;  VXIMapSetProperty(*telephonyProps, L"dnis",		    (VXIValue *)VXIStringCreate(L"6174284444"));  VXIMapSetProperty(*telephonyProps, L"ani", 		    (VXIValue *)VXIStringCreate(L"6508470000"));  return VXItel_RESULT_SUCCESS;}/******************************************************* * Factory and init routines *******************************************************/ /** * Global initialization of Telephony platform. */OSBTEL_API VXItelResult OSBtelInit (VXIlogInterface  *log,				    VXIunsigned       diagLogBase){  if (! log) return VXItel_RESULT_INVALID_ARGUMENT;  gblDiagLogBase = diagLogBase;  return VXItel_RESULT_SUCCESS;}/** * Global shutdown of Telephony platform. */OSBTEL_API VXItelResult OSBtelShutDown (VXIlogInterface  *log){  if (! log) return VXItel_RESULT_INVALID_ARGUMENT;  return VXItel_RESULT_SUCCESS;}/** * Creates an OSBtel implementation of the VXItel interface */OSBTEL_API VXItelResult OSBtelCreateResource(VXIlogInterface *log,					     VXItelInterface **tel){  if (! log) return VXItel_RESULT_INVALID_ARGUMENT;  OSBtelImpl* pp = new OSBtelImpl();  if (pp == NULL) return VXItel_RESULT_OUT_OF_MEMORY;  pp->log = log;  pp->osbIntf.intf.GetVersion     = OSBtelGetVersion;  pp->osbIntf.intf.GetImplementationName = OSBtelGetImplementationName;  pp->osbIntf.intf.BeginSession   = OSBtelBeginSession;  pp->osbIntf.intf.EndSession     = OSBtelEndSession;  pp->osbIntf.intf.GetStatus      = OSBtelGetStatus;  pp->osbIntf.intf.Disconnect     = OSBtelDisconnect;  pp->osbIntf.intf.TransferBlind  = OSBtelTransferBlind;  pp->osbIntf.intf.TransferBridge = OSBtelTransferBridge;  pp->osbIntf.EnableCall          = OSBtelEnableCall;  pp->osbIntf.WaitForCall         = OSBtelWaitForCall;  *tel = &pp->osbIntf.intf;  return VXItel_RESULT_SUCCESS;}/** * Destroys the specified OSBtel implementation */OSBTEL_API VXItelResult OSBtelDestroyResource(VXItelInterface **tel){  if (tel == NULL || *tel == NULL) return VXItel_RESULT_INVALID_ARGUMENT;  OSBtelImpl* telImpl = reinterpret_cast<OSBtelImpl*>(*tel);  delete telImpl;  *tel = NULL;  return VXItel_RESULT_SUCCESS;}

⌨️ 快捷键说明

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