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

📄 sbobject.cpp

📁 Open VXI. This is a open source.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/****************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: SBobject.cpp,v 1.8.4.5 2001/10/03 16:33:54 dmeyer Exp $ * * Implementation of the SBobject functions defined in SBobject.h, see * that header for details * ************************************************************************ */static const char *rcsid = 0 ? (char *) &rcsid :"$Id: SBobject.cpp,v 1.8.4.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>                     // For memset( )#include "VXIlog.h"                     // For VXIlog interface#include "OSBobject.h"                  // Header for these functions#ifdef OPENVXI#define SBOBJECT_API extern "C"typedef OSBobjectResources SBobjectResources;#else#define SBOBJECT_EXPORTS#include "SBobject.h"                   // Second header for these functions#endif#ifndef MODULE_PREFIX#define MODULE_PREFIX  COMPANY_DOMAIN L"."#endif#ifdef OPENVXIstatic const VXIchar MODULE_SBOBJECT[] = MODULE_PREFIX L"OSBobject";static const VXIchar SBOBJECT_IMPLEMENTATION_NAME[] =                        COMPANY_DOMAIN L".OSBobject";#elsestatic const VXIchar MODULE_SBOBJECT[] = MODULE_PREFIX L"SBobject";static const VXIchar SBOBJECT_IMPLEMENTATION_NAME[] =                        COMPANY_DOMAIN L".SBobject";#endif// Global variable to track whether this is initializedstatic bool gblInitialized = false;// Global diagnostic logging basestatic VXIunsigned gblDiagLogBase;// Diagnostic logging tagsstatic const VXIunsigned LOG_API = 0;// SBobject interface, "inherits" from VXIobjectInterfacetypedef struct SBobjectInterface{  // Base interface, must be the first member  VXIobjectInterface  object;  // Resources for this channel  SBobjectResources  *resources;  // Diagnostic log base for this channel  VXIunsigned         diagLogBase;} SBobjectInterface;// Convenience macro#define GET_SBOBJECT(pThis, sbObject, log, rc) \  VXIobjResult rc = VXIobj_RESULT_SUCCESS; \  SBobjectInterface *sbObject = (SBobjectInterface *) pThis; \  if ( ! sbObject ) { rc = VXIobj_RESULT_INVALID_ARGUMENT; return rc; } \  VXIlogInterface *log = sbObject->resources->log;// Forward declarationsextern "C" {  VXIint32 SBobjectGetVersion(void);  const VXIchar* SBobjectGetImplementationName(void);  VXIobjResult SBobjectExecute(struct VXIobjectInterface *pThis,			       const VXIMap              *properties,			       const VXIMap              *parameters,			       VXIValue                 **result);  VXIobjResult SBobjectValidate(struct VXIobjectInterface *pThis,				const VXIMap              *properties,				const VXIMap              *parameters);};// -----1=0-------2=0-------3=0-------4=0-------5=0-------6=0-------7=0-------8/** * Sample diagnostic logging object * * @param parameters    [IN]  See description in SBobjectExecute()  *                            or SBobjectValidate() * @param execute       [IN]  Specifies whether the object should be *                            executed (true) or simply validated (false) * @param result        [OUT] See description in SBobjectExecute()  *                            or SBobjectValidate() * * @result VXIobj_RESULT_SUCCESS on success */static VXIobjResult ProcessComSpeechworksDiagObject (struct VXIobjectInterface *pThis,                                 const VXIMap    *parameters,                                 VXIbool          execute,			                     VXIValue       **result){  static const wchar_t func[] = L"ProcessComSpeechworksDiagObject";  GET_SBOBJECT (pThis, sbObject, log, rc);  VXIMap *resultObj;  if(execute) {    if(result == NULL) return VXIobj_RESULT_INVALID_ARGUMENT;    // Create the result object    resultObj = VXIMapCreate();    if(resultObj == NULL) return VXIobj_RESULT_OUT_OF_MEMORY;    *result = reinterpret_cast<VXIValue *>(resultObj);    // Add a status field to the result object, initialized to 'failure'    VXIMapSetProperty(resultObj, L"status",              reinterpret_cast<VXIValue *>(VXIStringCreate(L"failure")));  }  if(parameters == NULL) return VXIobj_RESULT_INVALID_ARGUMENT;  // Get the tag ID  const VXIValue *val = VXIMapGetProperty(parameters, L"tag");  if(val == NULL) return VXIobj_RESULT_INVALID_PROP_VALUE;  const VXIchar *tagStr = VXIStringCStr((VXIString *)val);  if((tagStr == NULL) || (tagStr[0] == L'\0'))    return VXIobj_RESULT_INVALID_PROP_VALUE;  VXIint tag = ::wcstol(tagStr, NULL, 10);  // Get the message string  const VXIchar *messageStr;  val = VXIMapGetProperty(parameters, L"message");  if(val == NULL) return VXIobj_RESULT_INVALID_PROP_VALUE;  // Check whether the message was sent in "data" or "ref" format.  // If it is "ref", we need to retrieve it in the embedded map.  if(VXIValueGetType(val) == VALUE_MAP) {    const VXIValue *val2 = VXIMapGetProperty((const VXIMap *)val,                                              OBJECT_VALUE);    messageStr = VXIStringCStr((VXIString *)val2);  }  else {    messageStr = VXIStringCStr((VXIString *)val);  }  if(execute) {    // Print a diagnostic message using the retrieved arguments.    // To see this message, you must enable client.log.diagTag.xxx    // in your SBclient configuration file, where 'xxx' is the     // value of client.object.diagLogBase defined in the same file.    VXIlogResult rc = log->Diagnostic (log, sbObject->diagLogBase + tag,                                       func, messageStr);    // Set the result object's status field to 'success' if needed    if(rc == VXIlog_RESULT_SUCCESS) {      VXIMapSetProperty(resultObj, L"status",               reinterpret_cast<VXIValue *>(VXIStringCreate(L"success")));    }  }  return VXIobj_RESULT_SUCCESS;}/** * Sample object echoing back all attributes * * @param properties    [IN]  See description in SBobjectExecute()  *                            or SBobjectValidate() * @param execute       [IN]  Specifies whether the object should be *                            executed (true) or simply validated (false) * @param result        [OUT] See description in SBobjectExecute()  *                            or SBobjectValidate() * * @result VXIobj_RESULT_SUCCESS on success */static VXIobjResult ProcessComSpeechworksEchoObject (struct VXIobjectInterface *pThis,                                 const VXIMap              *properties,                                 VXIbool                    execute,				 VXIValue                 **result){  static const wchar_t func[] = L"ProcessComSpeechworksEchoObject";  GET_SBOBJECT (pThis, sbObject, log, rc);  VXIMap *resultObj;  if(execute) {    if(result == NULL) return VXIobj_RESULT_INVALID_ARGUMENT;    // Create the result object    resultObj = VXIMapCreate();    if(resultObj == NULL) return VXIobj_RESULT_OUT_OF_MEMORY;    *result = reinterpret_cast<VXIValue *>(resultObj);  }    if(properties == NULL) return VXIobj_RESULT_INVALID_ARGUMENT;  if(execute) {    // Simply add the input properties to the result object    VXIMapSetProperty(resultObj, L"attributes", 		      VXIValueClone((VXIValue *)properties));  }  return VXIobj_RESULT_SUCCESS;}// -----1=0-------2=0-------3=0-------4=0-------5=0-------6=0-------7=0-------8/** * Global platform initialization of SBobject * * @param log            VXI Logging interface used for error/diagnostic  *                       logging, only used for the duration of this  *                       function call * @param  diagLogBase   Base tag number for diagnostic logging purposes. *                       All diagnostic tags for SBobject will start at this *                       ID and increase upwards. * * @result VXIobj_RESULT_SUCCESS on success */SBOBJECT_API VXIobjResult SBobjectInit (VXIlogInterface  *log,					VXIunsigned       diagLogBase){  static const wchar_t func[] = L"SBobjectInit";  if ( log )    log->Diagnostic (log, diagLogBase + LOG_API, func, 		     L"entering: 0x%p, %u", log, diagLogBase);  gblDiagLogBase = diagLogBase;  VXIobjResult rc = VXIobj_RESULT_SUCCESS;  if (gblInitialized == true) {    rc = VXIobj_RESULT_FATAL_ERROR;    if ( log )      log->Diagnostic (log, gblDiagLogBase + LOG_API, func,		       L"exiting: returned %d", rc);    return rc;  }  if ( ! log ) {    rc = VXIobj_RESULT_INVALID_ARGUMENT;    if ( log )      log->Diagnostic (log, gblDiagLogBase + LOG_API, func,		       L"exiting: returned %d", rc);    return rc;  }  // Return  gblInitialized = true;  log->Diagnostic (log, gblDiagLogBase + LOG_API, func,		   L"exiting: returned %d", rc);  return rc;}OSBOBJECT_API VXIobjResult OSBobjectInit (VXIlogInterface  *log,					  VXIunsigned       diagLogBase){  return SBobjectInit (log, diagLogBase);}/** * Global platform shutdown of SBobject * * @param log    VXI Logging interface used for error/diagnostic logging, *               only used for the duration of this function call * * @result VXIobj_RESULT_SUCCESS on success */SBOBJECT_API VXIobjResult SBobjectShutDown (VXIlogInterface  *log){  static const wchar_t func[] = L"SBobjectShutDown";  if ( log ) log->Diagnostic (log, gblDiagLogBase + LOG_API, func,			      L"entering: 0x%p", log);  VXIobjResult rc = VXIobj_RESULT_SUCCESS;  if (gblInitialized == false) {    rc = VXIobj_RESULT_FATAL_ERROR;    if ( log )      log->Diagnostic (log, gblDiagLogBase + LOG_API, func,		       L"exiting: returned %d", rc);    return rc;  }  if ( ! log )    return VXIobj_RESULT_INVALID_ARGUMENT;  gblInitialized = false;  log->Diagnostic (log, gblDiagLogBase + LOG_API, func,		   L"exiting: returned %d", rc);  return rc;}OSBOBJECT_API VXIobjResult OSBobjectShutDown (VXIlogInterface  *log)

⌨️ 快捷键说明

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