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

📄 sbtrdevent.cpp

📁 sloedgy open sip stack source code
💻 CPP
字号:
/* SBtrdEvent, utility class for managing events */

 /****************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.
  *
  ***********************************************************************/
 
#include <vxibuildopts.h>
#if P_VXI

 static const char *rcsid = 0 ? (char *) &rcsid :
 "$Id: SBtrdEvent.cpp,v 1.1 2007/06/04 16:11:29 joegenbaclor Exp $";
 
 // -----1=0-------2=0-------3=0-------4=0-------5=0-------6=0-------7=0-------8
 
 #define SBTRDUTIL_EXPORTS
 #include "SBtrdEvent.hpp"             // Header for this class
 
 #include <stdio.h>
 #include <limits.h>                   // For INT_MAX
 
 #include "vxi/VXIlog.h"                   // For logging
 

 // -----1=0-------2=0-------3=0-------4=0-------5=0-------6=0-------7=0-------8
 
 
 // Destructor
 SBtrdEvent::~SBtrdEvent( ) 
 { 
   Diag (0, L"SBtrdEvent::~SBtrdEvent", L"enter: this 0x%p", this);
   
   if ( _timer ) 
     VXItrdTimerDestroy (&_timer); 
   if ( _sleepMutex ) 
     VXItrdMutexDestroy (&_sleepMutex); 
 }
 
 
 // Creation method
 VXItrdResult SBtrdEvent::Create( )
 { 
   VXItrdResult rc;
   Diag (0, L"SBtrdEvent::Create", L"enter: this 0x%p", this);
 
   if ( _timer != NULL ) {
     rc = VXItrd_RESULT_FATAL_ERROR;
   } else {
     rc = VXItrdTimerCreate (&_timer);
     if ( rc == VXItrd_RESULT_SUCCESS )
       rc = VXItrdMutexCreate (&_sleepMutex);
   }
 
   return rc;
 }
 
 
 // Reset the event
 VXItrdResult SBtrdEvent::Reset( ) 
 { 
   Diag (0, L"SBtrdEvent::Reset", L"enter: this 0x%p", this);
   _alerted = FALSE; 
   return VXItrd_RESULT_SUCCESS; 
 }
 
 
 // Set the event
 VXItrdResult SBtrdEvent::Set( ) 
 { 
   Diag (0, L"SBtrdEvent::Set", L"enter: this 0x%p", this);
   _alerted = TRUE; 
   return VXItrdTimerWake (_timer); 
 }
 
 
 // Wait on the event
 VXItrdResult SBtrdEvent::Wait( ) 
 {
   VXItrdResult rc = VXItrd_RESULT_SUCCESS;
   Diag (0, L"SBtrdEvent::Wait", L"enter: this 0x%p", this);
 
   if (( ! _alerted ) &&
       ( (rc = VXItrdMutexLock (_sleepMutex)) == VXItrd_RESULT_SUCCESS )) {
     while (( ! _alerted ) && 
 	   ( (rc = VXItrdTimerSleep (_timer, INT_MAX, NULL)) ==
 	     VXItrd_RESULT_SUCCESS )) {
       // keep waiting
       Diag (0, L"SBtrdEvent::Wait", L"woke up: %d", _alerted);
     }
     
     if ( VXItrdMutexUnlock (_sleepMutex) != VXItrd_RESULT_SUCCESS )
       rc = VXItrd_RESULT_SYSTEM_ERROR;
   }
 
   Diag (0, L"SBtrdEvent::Wait", L"exit: %d", rc);
   return rc;
 }
 
 
 // Error logging
 SBTRDUTIL_API_CLASS void
 SBtrdEvent::Error (VXIunsigned errorID, const VXIchar *format, ...) const
 {
   if ( _log ) {
     if ( format ) {
       va_list arguments;
       va_start(arguments, format);
       (*_log->VError)(_log, COMPANY_DOMAIN L".SBtrdUtil", errorID, format,
 		      arguments);
       va_end(arguments);
     } else {
       (*_log->Error)(_log, COMPANY_DOMAIN L".SBtrdUtil", errorID, NULL);
     }
   }  
 }
 
 
 // Diagnostic logging
 SBTRDUTIL_API_CLASS void
 SBtrdEvent::Diag (VXIunsigned tag, const VXIchar *subtag, 
 		  const VXIchar *format, ...) const
 {
   if ( _log ) {
     if ( format ) {
       va_list arguments;
       va_start(arguments, format);
       (*_log->VDiagnostic)(_log, tag + _diagTagBase, subtag, format, 
 			   arguments);
       va_end(arguments);
     } else {
       (*_log->Diagnostic)(_log, tag + _diagTagBase, subtag, NULL);
     }
 #if 0
   } else {
     VXIchar temp[1024];
     va_list arguments;
     va_start(arguments, format);
     wcscpy (temp, subtag);
     wcscat (temp, L"|");
     wcscat (temp, format);
     wcscat (temp, L"\n");
     vfwprintf(stderr, temp, arguments);
     va_end(arguments);
 #endif
   }
 }

#endif


⌨️ 快捷键说明

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