#include <mmsthreadserver.h>
Public Member Functions | |
MMSThreadServer (int queue_size=1000, string identity="MMSThreadServer", bool blocking=true) | |
constructor | |
~MMSThreadServer () | |
destructor | |
bool | start () |
Start the server thread. | |
virtual void | processData (void *in_data, int in_data_len, void **out_data, int *out_data_len) |
Process a new event from the client. | |
bool | trigger (void *in_data, int in_data_len, void **out_data=NULL, int *out_data_len=NULL) |
Trigger a new event to the server. | |
Public Attributes | |
sigc::signal< void, void *, int, void **, int * > | onProcessData |
Set one or more callbacks for the onProcessData event. | |
Private Member Functions | |
void | threadMain () |
server thread | |
Private Attributes | |
pthread_t | server_tid |
id of the server thread | |
MMSTS_QUEUE_ITEM ** | queue |
request queue (ring buffer) | |
int | queue_size |
number of items in the queue | |
int | queue_rp |
current item in the queue (read pointer) | |
int | queue_wp |
first free item in the queue (write pointer) | |
bool | buffer_full |
mark the ring buffer as full | |
pthread_cond_t | cond |
variable for conditional handling (server side) | |
pthread_mutex_t | mutex |
mutex for conditional handling (server side) | |
bool | blocking |
in non-blocking mode the caller of trigger() will get control directly after triggering and do not wait until server has finished processData() | |
Classes | |
struct | MMSTS_QUEUE_ITEM |
describes one item/request in the queue More... |
This class includes the base functionality e.g. the handshake between server and client threads. You can use the onProcessData() callback if you do not want to derive your own class from MMSThreadServer.
Definition at line 46 of file mmsthreadserver.h.
MMSThreadServer::MMSThreadServer | ( | int | queue_size = 1000 , |
|
string | identity = "MMSThreadServer" , |
|||
bool | blocking = true | |||
) |
constructor
queue_size | maximum items in the queue | |
identity | identity of the server thread used for logging etc. | |
blocking | blocking or non-blocking mode, see trigger() |
Definition at line 38 of file mmsthreadserver.cpp.
MMSThreadServer::~MMSThreadServer | ( | ) |
void MMSThreadServer::threadMain | ( | ) | [private, virtual] |
bool MMSThreadServer::start | ( | void | ) | [virtual] |
Start the server thread.
This method starts the server thread. This has to be done before the first trigger() call.
Reimplemented from MMSThread.
Definition at line 69 of file mmsthreadserver.cpp.
void MMSThreadServer::processData | ( | void * | in_data, | |
int | in_data_len, | |||
void ** | out_data, | |||
int * | out_data_len | |||
) | [virtual] |
Process a new event from the client.
Reimplemented in MMSFBBackEndInterface.
Definition at line 127 of file mmsthreadserver.cpp.
bool MMSThreadServer::trigger | ( | void * | in_data, | |
int | in_data_len, | |||
void ** | out_data = NULL , |
|||
int * | out_data_len = NULL | |||
) |
Trigger a new event to the server.
This method sends data (in_data) from the caller (client) thread to the server thread. If MMSThreadServer runs in blocking mode (see constructor), the caller of trigger() will be blocked and is waiting for the answer from the server. If MMSThreadServer runs in non-blocking mode, the caller of trigger() will get control immediately and do not wait until server has finished processData() of the previous trigger() call.
in_data | pointer to data to put to the server | |
in_data_len | length of in_data | |
out_data | address of a pointer to receive data from the server | |
out_data_len | address of a integer to get the length of out_data |
The handling of out_data and out_data_len is dependend on the implementation of the processData() method which is done in classes derived from MMSThreadServer.
If MMSThreadServer runs in non-blocking mode, out_data and out_data_len are not supported.
Definition at line 131 of file mmsthreadserver.cpp.
pthread_t MMSThreadServer::server_tid [private] |
MMSTS_QUEUE_ITEM** MMSThreadServer::queue [private] |
int MMSThreadServer::queue_size [private] |
int MMSThreadServer::queue_rp [private] |
int MMSThreadServer::queue_wp [private] |
bool MMSThreadServer::buffer_full [private] |
pthread_cond_t MMSThreadServer::cond [private] |
pthread_mutex_t MMSThreadServer::mutex [private] |
bool MMSThreadServer::blocking [private] |
in non-blocking mode the caller of trigger() will get control directly after triggering and do not wait until server has finished processData()
Definition at line 90 of file mmsthreadserver.h.
sigc::signal<void, void *, int, void **, int *> MMSThreadServer::onProcessData |
Set one or more callbacks for the onProcessData event.
The connected callbacks will be called from MMSThreadServer::processData() and will be run within the context of server thread.
A callback method must be defined like this:
void myclass::mycallbackmethod(void *in_data, int in_data_len, void **out_data, int *out_data_len);
in_data | pointer to data to put to the server | |
in_data_len | length of in_data | |
out_data | address of a pointer to receive data from the server | |
out_data_len | address of a integer to get the length of out_data |
sigc::connection connection; connection = mythreadserver->onProcessData.connect(sigc::mem_fun(myobject,&myclass::mycallbackmethod));
To disconnect your callback do this:
connection.disconnect();
Please note:
You HAVE TO disconnect myobject from onProcessData BEFORE myobject will be deleted!!! Else an abnormal program termination can occur. You HAVE TO call the disconnect() method of sigc::connection explicitly. The destructor will NOT do this!!!
Definition at line 178 of file mmsthreadserver.h.