Barst  2.0
A server that controls lab hardware.
base classses.h
1 
4 #ifndef _BASE_CLASSES_H_
5 #define _BASE_CLASSES_H_
6 
7 #include "cpl defs.h"
8 #include <vector>
9 #include "mem pool.h"
10 
11 
12 class CDevice;
13 class CLogBuffer;
14 class CMemPool;
15 
16 /* Struct with which devices send to data to be written to user (through a comm).
17  Data is enqueued using this struct.
18  */
19 typedef struct SData
20 {
21  void* pHead; // data to be sent
22  DWORD dwSize; // data size in bytes
23  CDevice* pDevice; // pointer to device that will be called after data has been sent (Result(...))
24 } SData;
25 
54 class CComm
55 {
56 public:
57  CComm(){};
58  virtual ~CComm() {};
61  virtual int SendData(const SData *pData, __int64 llId) =0;
64  virtual void Close() =0;
65 protected:
66  CDevice* m_pcDevice; // the device which gets notified with ProcessData() of user requests.
67  CLogBuffer* m_pcLogBuffer; // could hold a log
68  CMemPool* m_pcMemPool; // a memory pool used by this comm.
69 };
70 
77 class CDevice
78 {
79 public:
81  CDevice(const TCHAR szName[]) : m_csName(szName){};
82  virtual ~CDevice() {};
84  virtual void ProcessData(const void *pHead, DWORD dwSize, __int64 llId) =0;
88  virtual void Result(void *pHead, bool bPass) =0;
95  virtual DWORD GetInfo(void* pHead, DWORD dwSize)= 0;
96 
98  const std::tstring m_csName;
99 protected:
100  CComm* m_pcComm; // holds a communicator used by device
101  CLogBuffer* m_pcLogBuffer; // a log to which we can write
102  CMemPool* m_pcMemPool; // pooled memory used instead of malloc()
103  // if something went wrong and isn't fixable this is set to true so that all folowing calls to the object
104  // return immidiatly. Typically only the constuctor sets it to to true if initialization was bad so that
105  // all subsequent calls to the object don't do anything. But if the constructor returns an error (using a
106  // parameter you shouldn't call this object anyway).
107  bool m_bError;
108 };
109 
110 
119 class CMainManager : public CDevice
120 {
121 public:
122  CMainManager();
123  virtual ~CMainManager();
127  int Run(int argc, TCHAR* argv[]);
128  void ProcessData(const void *pHead, DWORD dwSize, __int64 llId);
129  void Result(void *pHead, bool bPass) {if (m_pcMemPool) m_pcMemPool->PoolRelease(pHead);}
130  DWORD GetInfo(void* pHead, DWORD dwSize){return 0;}
131 private:
132  std::vector<CDevice*> m_acManagers; // holds all the managers, their channels numbers are position in this array.
133  HANDLE m_hClose; // this event is set when we want to the exe to exit
134  std::tstring m_csPipe; // the main pipe name.
135 };
136 
137 
146 class CManager : public CDevice
147 {
148 public:
152  CManager(const TCHAR szName[], const std::tstring csPipeName, int nChan) : CDevice(szName),
153  m_csPipeName(csPipeName), m_nChan(nChan){};
154  virtual ~CManager(){};
155  virtual void ProcessData(const void *pHead, DWORD dwSize, __int64 llId)= 0;
156  virtual void Result(void *pHead, bool bPass)= 0;
157  virtual DWORD GetInfo(void* pHead, DWORD dwSize)= 0;
158 
159  const std::tstring m_csPipeName;
160  const int m_nChan;
161 protected:
162  // typically, a manager will load some dll, this dll is held here and is unloaded when the manager is closed.
163  HINSTANCE m_hLib;
164 };
165 
166 #endif
CDevice(const TCHAR szName[])
Definition: base classses.h:81
CManager(const TCHAR szName[], const std::tstring csPipeName, int nChan)
void Result(void *pHead, bool bPass)
DWORD GetInfo(void *pHead, DWORD dwSize)
const std::tstring m_csName
Definition: base classses.h:98