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

📄 sbjsifuncs.cpp

📁 sloedgy open sip stack source code
💻 CPP
📖 第 1 页 / 共 2 页
字号:


 /****************License************************************************
  *
  * Copyright 2000-2003.  ScanSoft, Inc.    
  *
  * Use of this software is subject to notices and obligations set forth 
  * in the SpeechWorks Public License - Software Version 1.2 which is 
  * included with this software. 
  *
  * ScanSoft is a registered trademark of ScanSoft, Inc., and OpenSpeech, 
  * SpeechWorks and the SpeechWorks logo are registered trademarks or 
  * trademarks of SpeechWorks International, Inc. in the United States 
  * and other countries.
  *
  ***********************************************************************/
 

 /*****************************************************************************
  *****************************************************************************
  *
  * Implementation of the SBjsi functions defined in SBjsiAPI.h,
  * see that header for details. These implementations are just a thin
  * C wrapper around the real implementation.
  *
  *****************************************************************************
  ****************************************************************************/
 
 
 // -----1=0-------2=0-------3=0-------4=0-------5=0-------6=0-------7=0-------8
 
#include <vxibuildopts.h>
#if P_VXI
 
 #include "SBjsiInternal.h"
 
 
 #include "SBjsiLog.h"                // For logging
 #include "JsiRuntime.hpp"            // For JsiRuntime class
 #include "JsiContext.hpp"            // For JsiContext class
 #include "SBjsiInterface.h"          // For SBjsiInterface
 
 #include "SBjsiAPI.h"                // Header for these functions
 
 
 // Real VXIjsiContext API object
 extern "C" {
 typedef struct VXIjsiContext
 {
   // JavaScript context object
   JsiContext *jsiContext;
 
 } VXIjsiContext;
 }
 
 // Convenience macro
 #define GET_SBJSI(pThis, context, rc) \
   VXIjsiResult rc = VXIjsi_RESULT_SUCCESS; \
   SBjsiInterface *sbJsi = (SBjsiInterface *) pThis; \
   if (( ! sbJsi ) || ( ! context )) { \
     if ( sbJsi ) SBjsiLogger::Error (sbJsi->log, MODULE_SBJSI, \
                                       JSI_ERROR_NULL_INTERFACE_PTR, NULL); \
     rc = VXIjsi_RESULT_INVALID_ARGUMENT; \
     return rc; \
   }
 
 
 // -----1=0-------2=0-------3=0-------4=0-------5=0-------6=0-------7=0-------8
 
 
 /**
  * Return the version
  */
 extern "C" 
 VXIint32 SBjsiGetVersion (void)
 {
   return VXI_CURRENT_VERSION;
 }
 
 
 /**
  * Return the implementation name
  */
 extern "C" 
 const VXIchar* SBjsiGetImplementationName (void)
 {
   return SBJSI_IMPLEMENTATION_NAME;
 }
 
 
 /**
  * Create and initialize a new script context
  *
  * This creates a new environment using a model, usually the global
  * environment created by VXIjsiInit( ). Currently one context is
  * created per thread, but the implementation must support the ability
  * to have multiple contexts per thread.
  *
  * @param model    [IN]  Pointer to the model context that will be the
  *                       basis for the new context, pass NULL to use the
  *                       default environment
  * @param context  [OUT] Newly created context
  *
  * @result VXIjsiResult 0 on success 
  */
 extern "C"
 VXIjsiResult SBjsiCreateContext(VXIjsiInterface        *pThis,
 				VXIjsiContext         **context)
 {
   static const wchar_t func[] = L"SBjsiCreateContext";
   GET_SBJSI (pThis, context, rc);
   sbJsi->log->Diagnostic (sbJsi->log, sbJsi->diagTagBase + SBJSI_LOG_API,
 			  func, L"entering: 0x%p", context);
 
   // Allocate the wrapper object and the new context
   *context = NULL;
   VXIjsiContext *newContext = new VXIjsiContext;
   if ( newContext == NULL ) {
     SBjsiLogger::Error (sbJsi->log, MODULE_SBJSI, JSI_ERROR_OUT_OF_MEMORY,
 			 NULL);
     rc = VXIjsi_RESULT_OUT_OF_MEMORY;
   } else if ( (newContext->jsiContext = new JsiContext) == NULL ) {
     delete newContext;
     SBjsiLogger::Error (sbJsi->log, MODULE_SBJSI, JSI_ERROR_OUT_OF_MEMORY,
 			 NULL);
     rc = VXIjsi_RESULT_OUT_OF_MEMORY;
     sbJsi->log->Diagnostic (sbJsi->log, sbJsi->diagTagBase + SBJSI_LOG_API, 
 			    func, L"exiting: returned %d", rc);
     return rc;
   }
 
   // Now do the low-level creation
   rc = newContext->jsiContext->Create (sbJsi->jsiRuntime, sbJsi->contextSize,
 				       sbJsi->maxBranches, sbJsi->log,
 				       sbJsi->diagTagBase);
   if ( rc == VXIjsi_RESULT_SUCCESS ) {
     *context = newContext;
   } else {
     delete newContext->jsiContext;
     delete newContext;
   }
 
   sbJsi->log->Diagnostic (sbJsi->log, sbJsi->diagTagBase + SBJSI_LOG_API,
 			  func, L"exiting: returned %d, 0x%p", rc, *context);
   return rc;
 }
 
 
 /**
  * Destroy a script context, clean up storage if required
  *
  * @param context  [IN] Context to destroy
  *
  * @result VXIjsiResult 0 on success
  */
 extern "C"
 VXIjsiResult SBjsiDestroyContext(VXIjsiInterface        *pThis,
 				 VXIjsiContext         **context)
 {
   static const wchar_t func[] = L"SBjsiDestroyContext";
   GET_SBJSI (pThis, context, rc);
   sbJsi->log->Diagnostic (sbJsi->log, sbJsi->diagTagBase + SBJSI_LOG_API, 
 			  func, L"entering: 0x%p (0x%p)", 
 			  context, (context ? *context : NULL));
 
   if ( *context == NULL ) {
     SBjsiLogger::Error (sbJsi->log, MODULE_SBJSI, JSI_ERROR_INVALID_ARG,
 			 NULL);
     rc = VXIjsi_RESULT_INVALID_ARGUMENT;
   } else {
     delete (*context)->jsiContext;
     delete *context;
     *context = NULL;
   }
 
   sbJsi->log->Diagnostic (sbJsi->log, sbJsi->diagTagBase + SBJSI_LOG_API, func,
 			  L"exiting: returned %d", rc);
   return rc;
 }
 
 
 /**
  * Create a script variable relative to the current scope, initialized
  *  to an expression
  *
  * NOTE: When there is an expression, the expression is evaluated,
  *  then the value of the evaluated expression (the final
  *  sub-expression) assigned. Thus an expression of "1; 2;" actually
  *  assigns 2 to the variable.
  *
  * @param context  [IN] JavaScript context to create the variable within
  * @param name     [IN] Name of the variable to create
  * @param expr     [IN] Expression to set the initial value of the variable 
  *                      (if NULL or empty the variable is set to JavaScript 
  *                      Undefined as required for VoiceXML 1.0 <var>)
  *
  * @result VXIjsiResult 0 on success 
  */
 extern "C"
 VXIjsiResult SBjsiCreateVarExpr(VXIjsiInterface        *pThis,
 				VXIjsiContext          *context, 
 				const VXIchar          *name, 
 				const VXIchar          *expr)
 {
   static const wchar_t func[] = L"SBjsiCreateVarExpr";
   GET_SBJSI (pThis, context, rc);
   context->jsiContext->Diag (SBJSI_LOG_API, func, 
 			     L"entering: 0x%p, '%s', '%s'", 
 			     context, name, expr);
 
   rc = context->jsiContext->CreateVar (name, expr);
 
   context->jsiContext->Diag (SBJSI_LOG_API, func, L"exiting: returned %d", rc);
   return rc;
 }
 
   
 /**
  * Create a script variable relative to the current scope, initialized
  *  to a VXIValue based value
  *
  * @param context  [IN] JavaScript context to create the variable within
  * @param name     [IN] Name of the variable to create
  * @param value    [IN] VXIValue based value to set the initial value of 
  *                      the variable (if NULL the variable is set to 
  *                      JavaScript Undefined as required for VoiceXML 1.0
  *                      <var>). VXIMap is used to pass JavaScript objects.
  *
  * @result VXIjsiResult 0 on success 
  */
 extern "C"
 VXIjsiResult SBjsiCreateVarValue(VXIjsiInterface        *pThis,
 				 VXIjsiContext          *context, 
 				 const VXIchar          *name, 
 				 const VXIValue         *value)
 {
   static const wchar_t func[] = L"SBjsiCreateVarValue";
   GET_SBJSI (pThis, context, rc);
   context->jsiContext->Diag (SBJSI_LOG_API, func, 
 			     L"entering: 0x%p, '%s', 0x%p", 
 			     context, name, value);
 
   rc = context->jsiContext->CreateVar (name, value);
 
   context->jsiContext->Diag (SBJSI_LOG_API, func, L"exiting: returned %d", rc);
   return rc;
 }
 
   
 /**
  * Set a script variable to an expression relative to the current scope
  *
  * NOTE: The expression is evaluated, then the value of the
  *  evaluated expression (the final sub-expression) assigned. Thus
  *  an expression of "1; 2;" actually assigns 2 to the variable.
  *
  * @param context  [IN] JavaScript context to set the variable within
  * @param name     [IN] Name of the variable to set
  * @param expr     [IN] Expression to be assigned

⌨️ 快捷键说明

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