📄 notifyslave.cpp
字号:
/************************************************************************
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
* KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
* PURPOSE.
************************************************************************/
/************************************************************************
*
* Module: NotifySlave.cpp
* Long name: CNotifySlave class implementation
* Description: Class that monitors a portion of the local nodes
* IEEE 1394 address space and notifies the caller
* on accesses to the address space.
*
* Runtime Env.: Win32
* Author(s): Frank Senf
* Company: Thesycon GmbH, Ilmenau
************************************************************************/
#include "NotifySlave.h"
// constructor implementation
CNotifySlave::CNotifySlave()
{
// init members
m_CurrentNotification = NULL;
m_NotifyEvt = NULL;
m_NotifyCompletedEvt = NULL;
m_ThreadExited = NULL;
m_BufferError = 0;
m_LastError = 0;
} // ctor
// destructor implementation
CNotifySlave::~CNotifySlave()
{
} // dtor
// overloaded CVhpdThread::TerminateThread() function
// NOTE 1: called in the context of the main thread
// NOTE 2: TerminateThread() is overloaded to ensure that the
// thread will exit. This is done by trying to terminate the
// thread until it really terminates. For future version of VHPDLib
// this will be implemented by the base class
void CNotifySlave::TerminateThread()
{
// cancel all pending notification buffers, this forces the worker thread
// to resume from a wait state and check for termination
AbortIoBuffers();
// now wait for the thread to terminate
if ( mThreadHandle != NULL ) {
// loop until thread has terminated
for (;;) {
// wait on thread handle, 40 ms timeout
DWORD err = WaitForSingleObject(mThreadHandle,40);
if ( err==WAIT_OBJECT_0 ) {
// handle is signaled, done
break;
}
if ( err==WAIT_TIMEOUT ) {
// wait timed out
// cancel all pending notification buffers again, should force the worker thread
// to resume from the wait state and check for termination
AbortIoBuffers();
// loop and wait again
continue;
}
// neither WAIT_OBJECT_0 nor WAIT_TIMEOUT returned -> error during wait
break;
} // for()
}
} // TerminateThread
// overloaded CVhpdThread::OnThreadExit() function
// NOTE: It is called in the context of the worker thread.
void CNotifySlave::OnThreadExit()
{
// store new thread state
m_ThreadExited = true;
} // OnThreadExit
// overloaded CVhpdNotifySlave::ProcessNotification() function
// function is only called if Buf->mStatus == VHPD_STATUS_SUCCESS
// NOTE: It is called in the context of the worker thread.
BOOL CNotifySlave::ProcessNotification(CVhpdBuf *Buf)
{
// init pointer to current address space access description
m_CurrentNotification = (VHPD_ADRRNG_NOTIFICATION*)Buf->Buffer();
if ( m_NotifyEvt != NULL ) {
// set event object to signaled state
::SetEvent(m_NotifyEvt);
}
if ( m_NotifyCompletedEvt != NULL ) {
// now wait until the caller signals completion of notification processing
::WaitForSingleObject(m_NotifyCompletedEvt, INFINITE);
}
// invalidate m_CurrentNotification pointer
m_CurrentNotification = NULL;
return true;
} // ProcessNotification
// overloaded CVhpdNotifySlave::BufErrorHandler() function
// function called if a buffer returns with error
// NOTE: It is called in the context of the worker thread.
void CNotifySlave::BufErrorHandler(CVhpdBuf *Buf)
{
if ( Buf->mStatus != VHPD_STATUS_SUCCESS ) {
// completed with error, store error and continue
m_BufferError++;
m_LastError = Buf->mStatus;
}
} // BufErrorHandler
/*************************** EOF **************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -