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

📄 vxitel.cpp

📁 openvxi3.4是一个voicexml对话脚本语言的解释器源码.可用VC6.0编译.
💻 CPP
📖 第 1 页 / 共 2 页
字号:

/****************License************************************************
 * Vocalocity OpenVXI
 * Copyright (C) 2004-2005 by Vocalocity, Inc. All Rights Reserved.
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 * Vocalocity, the Vocalocity logo, and VocalOS are trademarks or 
 * registered trademarks of Vocalocity, Inc. 
 * OpenVXI is a trademark of Scansoft, Inc. and used under license 
 * by Vocalocity.
 ***********************************************************************/

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#define VXIstrcmp wcscmp

#include <VXIvalue.h>
#include <VXItrd.h>
#define VXITEL_EXPORTS
#include "VXItelAPI.h"
#include "SWIstring.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;

static inline VXItelTransferStatus GetXferStatus( const wchar_t* hupStrId )
{
  if( hupStrId )
  {
    if( wcscmp(hupStrId, L"far_end_disconnect") == 0 )
      return VXItel_TRANSFER_FAR_END_DISCONNECT;
    else if( wcscmp(hupStrId, L"near_end_disconnect") == 0 )
      return VXItel_TRANSFER_NEAR_END_DISCONNECT;
    else if( wcscmp(hupStrId, L"busy") == 0 )
      return VXItel_TRANSFER_BUSY;
    else if( wcscmp(hupStrId, L"noanswer") == 0 )
      return VXItel_TRANSFER_NOANSWER;
    else if( wcscmp(hupStrId, L"network_busy") == 0 )
      return VXItel_TRANSFER_NETWORK_BUSY;
    else if( wcscmp(hupStrId, L"network_disconnect") == 0 )
      return VXItel_TRANSFER_NETWORK_DISCONNECT;
    else if( wcscmp(hupStrId, L"maxtime_disconnect") == 0 )
      return VXItel_TRANSFER_MAXTIME_DISCONNECT;
    else if( wcscmp(hupStrId, L"caller_hangup") == 0 )
      return VXItel_TRANSFER_CALLER_HANGUP;
  }
  return VXItel_TRANSFER_UNKNOWN; 
}

// VXItel implementation of the VXItel interface
//
class VXItelImpl {
public:
  VXItelImpl()
  : statusMutex(NULL), status(VXItel_STATUS_INACTIVE)
  {
    VXItrdMutexCreate(&statusMutex);
  }  
  ~VXItelImpl()
  {
    VXItrdMutexDestroy(&statusMutex);
  }
  
  // Set Line Status
  void SetLineStatus(VXItelStatus st)
  {
    VXItrdMutexLock(statusMutex);
    status = st;
    VXItrdMutexUnlock(statusMutex);
  }

  // Get Line Status
  VXItelStatus GetLineStatus(void)
  {
    VXItelStatus st;
    VXItrdMutexLock(statusMutex);
    st = status;
    VXItrdMutexUnlock(statusMutex);
    return st;
  }
  
  // Base interface, must be first
  VXItelInterfaceEx telIntf;

  // Log interface for this resource
  VXIlogInterface *log;
  
  // Line status
  VXItelStatus status;
  
  // Mutex for line status
  VXItrdMutex *statusMutex;
};


// A few conversion functions...

static inline VXItelImpl * ToVXItelImpl(VXItelInterface * i)
{ return reinterpret_cast<VXItelImpl *>(i); }

static inline VXItelImpl * ToVXItelImpl(VXItelInterfaceEx * i)
{ return reinterpret_cast<VXItelImpl *>(i); }


/*******************************************************
 *
 * Utility functions
 *
 *******************************************************/ 

/**
 * Log an error
 */
static VXIlogResult Error(VXItelImpl *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".VXItel", 
                              errorID, format, arguments);
    va_end(arguments);
  } else {
    rc = (*impl->log->Error)(impl->log, COMPANY_DOMAIN L".VXItel",
                             errorID, NULL);
  }

  return rc;
}


/**
 * Log a diagnostic message
 */
static VXIlogResult Diag(VXItelImpl *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 VXItelInterface structure
 *
 *******************************************************/ 

// Get the VXItel interface version supported
//
static VXIint32 VXItelGetVersion(void)
{
  return VXI_CURRENT_VERSION;
}



// Get the implementation name
//
static const VXIchar* VXItelGetImplementationName(void)
{
  static const VXIchar IMPLEMENTATION_NAME[] = COMPANY_DOMAIN L".VXItel";
  return IMPLEMENTATION_NAME;
}


// Begin a session
//
static 
VXItelResult VXItelBeginSession(VXItelInterface * pThis, VXIMap *)
{
  if( !pThis ) return VXItel_RESULT_INVALID_ARGUMENT;
  VXItelImpl *impl = ToVXItelImpl(pThis);
  impl->SetLineStatus(VXItel_STATUS_ACTIVE);
  return VXItel_RESULT_SUCCESS;
}


// End a session
//
static
VXItelResult VXItelEndSession(VXItelInterface *pThis, VXIMap *)
{
  if( !pThis ) return VXItel_RESULT_INVALID_ARGUMENT;
  VXItelImpl *impl = ToVXItelImpl(pThis);
  impl->SetLineStatus(VXItel_STATUS_INACTIVE);
  return VXItel_RESULT_SUCCESS;
}


static
VXItelResult VXItelGetStatus(VXItelInterface * pThis, VXItelStatus *status)
{
  if( !pThis ) return VXItel_RESULT_INVALID_ARGUMENT;
  VXItelImpl *impl = ToVXItelImpl(pThis);
  *status = impl->GetLineStatus();
  return VXItel_RESULT_SUCCESS;
}

/**
 * Disconnect caller (ie hang up).
 *
 * @param  ch   A handle to the channel resource manager
 */
static
VXItelResult VXItelDisconnect(VXItelInterface * pThis,const VXIMap *namelist)
{
  if( !pThis ) return VXItel_RESULT_INVALID_ARGUMENT;
  VXItelImpl *impl = ToVXItelImpl(pThis);
  Diag(impl, DIAG_TAG_SIGNALING, NULL, L"Disconnect");
  impl->SetLineStatus(VXItel_STATUS_INACTIVE); 
  return VXItel_RESULT_SUCCESS;
}


static bool GetReturnCode(const VXIMap* props, VXItelResult& retcode)
{
  const VXIValue* val = VXIMapGetProperty(props, L"ReturnCode");

⌨️ 快捷键说明

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