📄 asyncwriter.h
字号:
/************************************************************************
* 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: AsyncWriter.h
* Long name: CAsyncWriter class definition
* Description: Simple class that continuously transmits data using
* asynchronous WRITE requests (based on CVhpdAsyncWriter).
*
* Runtime Env.: Win32
* Author(s): Frank Senf
* Company: Thesycon GmbH, Ilmenau
************************************************************************/
#if !defined(_ASYNCWRITER_h_)
#define _ASYNCWRITER_h_
// get base class definition
#include "CVhpdAsyncWriter.h"
//
// CAsyncWriter class
// The class is derived from the CVhpdAsyncWriter class contained in the
// VHPDLib C++ class library.
// Thus, it has an embeded worker thread that handles data transmission.
// The class mainly implements the ProcessBuffer function defined
// by the base class.
//
class CAsyncWriter : public CVhpdAsyncWriter {
public:
// Construction
CAsyncWriter();
// destructor
~CAsyncWriter();
// ----------------
// interface
// source file handling
// opens the specified file
// returns 0 for success, 1 if a file was already opened or an specific
// error code if opening the file failed
unsigned long
OpenFile(const char *Filename);
// closes the source file, no-op if no file is currently opened
void CloseFile();
// return current number of buffers completed with error
unsigned long
GetErrorCount() { return m_BufferError; }
// return status code of last buffer completed with error
unsigned long
GetLastError() { return m_LastError; }
// returns true if the thread is about to terminate
bool
ThreadExited() { return m_ThreadExited; }
// ----------------
// CVhpdThread overloaded functions
// This notification handler is called in the context of
// the worker thread before the thread terminates itself.
// NOTE: It is called in the context of the worker thread.
virtual
void OnThreadExit();
// 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
virtual
void
TerminateThread();
// implementation
protected:
// --------------
// CVhpdAsyncWriter overloaded functions
// function that fills the buffer with data
// returns FALSE if buffer processing should be stopped, TRUE to continue
virtual
BOOL ProcessBuffer(CVhpdBuf* Buf);
// function is called if a buffer was completed by the driver with error
virtual
void BufErrorHandler(CVhpdBuf* Buf);
// --------------
// member variables
// input file, NULL if not valid
HANDLE m_File;
// pattern will be filled to buffer before transferring, only used if m_File==NULL
unsigned char m_Pattern;
// flag is set to true if OnThreadExit is called
bool m_ThreadExited;
// error handling
// counter increases every time a buffer is completed with an error status
unsigned long m_BufferError;
// last error received from the Buf->mStatus member, only valid if
// m_BufferError != 0
unsigned long m_LastError;
};
#endif // !defined(_ASYNCWRITER_h_)
/*************************** EOF **************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -