![]() |
Barst
2.0
A server that controls lab hardware.
|
#include <base classses.h>
Public Member Functions | |
virtual int | SendData (const SData *pData, __int64 llId)=0 |
virtual void | Close ()=0 |
Protected Attributes | |
CDevice * | m_pcDevice |
CLogBuffer * | m_pcLogBuffer |
CMemPool * | m_pcMemPool |
This defines a general communicator which lets you send and recieve massages from user. Typically each device gets its own comm for private use. The rule is that every device which has access to a comm and might have enqueued data to the comm to be sent to the user cannot be deleted while that comm is not stopped. I.e. you have to stop the comm and only then can you delete any of the devices which might have had access to the comm. This ensures a comm doesn't try to call a deleted device to which it had a pointer but is now an invalid pointer. So you typically: call close on the comm, delete the device and delete the comm.
At the moment, the rule is that when a device writes something to the comm using SendData, the SData struct used will be replicated in the comm (i.e. it doesn't have to be valid after the SendData call is completed), while the device and pHead in SData have to be valid until the comm is done with the data. The comm is done with the data after Close is called on the comm or if the comm calls Result(pHead, ...) on the device. Then you can delete pHead.
In addition to accepting data to be sent to a user (in which case using the SData struct we include a pointer to a device so that the comm knows who to notify after the data was sent, or not sent) the comm also needs to be initialized with a device pointer which it will call when a user has written data to it. In this case, the rule is that the data that the comm gives to the device using the ProcessData() function is only valid during the call to the device, so if the device needs access to the data afterwards it should be copied.
A single comm can communicate with multiple users simultaneuosly. This allows multiple users to send data at the same time. Therefore, we need a way to identify which user sent data to a particular device so when we get a ProcessData() call the device knows who to respond to. This is achieved using the llId parameter in the ProcessData() and SendData() function. When a user sends data to a device, the device is notified with ProcessData() which includes the llId param to uniquefy the user that sent it. When the device responds with SendData() the device includes this llId value so that the comm can reply to the correct user. The llId is unique and is incremented with each user that connects until it overflows back to zero (it's a 64-bit int). This guerantees that an llId of -1 is practically never reached, so -1 can used to initialize as an invalid value.
Definition at line 54 of file base classses.h.
|
pure virtual |
Stops all communication with this comm, terminates all threads and returns it to its original state. Any data waiting to be sent is not sent but Result() is called on that data.
Implemented in CPipeServer.
|
pure virtual |
Sends data to a user identified by llId. Function returns TRUE if it failed and FALSE otherwise. At some point it could be extended to return an error code if needed.
Implemented in CPipeServer.