botsense  3.2.0
RoadNarrows Client-Server Proxied Services Framework
bsProxyThread.c File Reference

BotSense bsProxy service threads. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include "rnr/rnrconfig.h"
#include "rnr/log.h"
#include "rnr/new.h"
#include "rnr/hash.h"
#include "rnr/dlistvoid.h"
#include "rnr/path.h"
#include "botsense/BotSense.h"
#include "botsense/libBotSense.h"
#include "botsense/bsProxyMsgs.h"
#include "bsProxy.h"

Go to the source code of this file.

Macros

#define BSPROXY_TH_HASH_MIN   8
 minimum hash table size
 
#define BSPROXY_TH_HASH_MAX   256
 maximum hash table size
 
#define BSPROXY_TH_MAX_QUEUE_SIZE   8
 request queue maximum depth
 
#define BSPROXY_TH_SERVER_URI   "#SERVER"
 server "URI"
 
#define BSPROXY_TH_LOG_ERROR(devuri, ecode, efmt, ...)
 Log Proxy Server Thread Error. More...
 

Functions

static int ThQReqCmp (const void *pData1, const void *pData2)
 Queue callback to compare two queue entries. More...
 
static void ThQReqDelete (void *pData)
 Queue callback to delete queue entry. More...
 
static BsProxyThCtl_TThCtlBlkNew (const char *sDevUri)
 Allocate new service thread control block. More...
 
static void ThCtlBlkDelete (BsProxyThCtl_T *pThCtl)
 Delete service thread control block. More...
 
static void ThGlobalLock ()
 Lock global mutual exclusion.
 
static void ThGlobalUnlock ()
 Unlock global mutual exclusion.
 
static bool_t ThGlobalTryLock ()
 Try to lock global mutual exclusion. More...
 
static void ThSyncLock (BsProxyThCtl_T *pThCtl)
 Lock service thread's mutual exclusion. More...
 
static void ThSyncUnlock (BsProxyThCtl_T *pThCtl)
 Unlock service thread's mutual exclusion. More...
 
static void ThSyncSignal (BsProxyThCtl_T *pThCtl)
 Signal service thread's condition. More...
 
static void ThSyncWait (BsProxyThCtl_T *pThCtl)
 Wait on service thread's condition. More...
 
static void ThHashDeleteData (void *sDevUri, void *pThCtl)
 Delete hash node data callback. More...
 
static int ThHashAdd (const char *sDevUri, BsProxyThCtl_T *pThCtl)
 Add the module data to the i/f module hash table. More...
 
static void ThHashDelete (BsProxyThCtl_T *pThCtl)
 Remove and delete the module data from the i/f module hash table. More...
 
static BsProxyThCtl_TThHashGetCtl (const char *sDevUri)
 Get the interface module's i/f from the module hash table. More...
 
static void ThSyncRun (BsProxyThCtl_T *pThCtl)
 Command service thread to run. More...
 
static void ThSyncExit (BsProxyThCtl_T *pThCtl)
 Command service thread to exit. More...
 
static void ThSyncWaitForRun (BsProxyThCtl_T *pThCtl)
 Wait indefinitely until state change. More...
 
static int ThDevRequest (BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen)
 Device service thread request handler. More...
 
static void * ThServiceThread (void *pThArg)
 The service thread. More...
 
BsProxyThReq_TThReqNew (BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen)
 Allocate and initalized a new service thread request. More...
 
void ThReqDelete (BsProxyThReq_T *pThReq)
 Delete service thread request. More...
 
int ThQueue (BsProxyThCtl_T *pThCtl, BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen)
 Queue a request for the given service thread. More...
 
BsProxyThReq_TThDequeue (BsProxyThCtl_T *pThCtl)
 Dequeue a request for the given service thread. More...
 
void ThOneTimeInit ()
 The service thread one-time global initialization.
 
char * ThNewDevUri (const char *sDevName)
 Convert the device name to a quasi Uniform Resource Id. More...
 
BsProxyThCtl_TThCreateDevThread (const char *sDevUri)
 Create a device service thread. More...
 
BsProxyThCtl_TThCreateServerThread ()
 Create the special server service thread. More...
 
void ThDestroyThread (BsProxyThCtl_T *pThCtl)
 Destroy service thread. More...
 

Variables

static pthread_mutex_t BsThGlobalMutex
 bsProxy module operations mutex
 
static hash_t * BsThHashTbl
 proxied device hash table
 

Detailed Description

BotSense bsProxy service threads.

LastChangedDate
2010-08-20 11:36:38 -0600 (Fri, 20 Aug 2010)
Rev
568

A Sevice thread provides a separate execution context to service client request-response exchanges. There are two types of service threads:

Server Thread 1 thread to service server-terminated requests.
Device Thread N device threads, one attached to each URI unique, opened device.
Author
Robin Knight (robin.nosp@m..kni.nosp@m.ght@r.nosp@m.oadn.nosp@m.arrow.nosp@m.s.co.nosp@m.m)

Definition in file bsProxyThread.c.

Macro Definition Documentation

#define BSPROXY_TH_LOG_ERROR (   devuri,
  ecode,
  efmt,
  ... 
)
Value:
LOGERROR("%s: Service Thread \"%s\": %s(ecode=%d): " efmt, \
ServerHasName(), devuri, \
bsStrError(ecode), (ecode>=0? ecode: -ecode), \
##__VA_ARGS__)
INLINE_IN_H const char * ServerHasName()
Get the <b><i>BotSense</i></b> server&#39;s official name.
Definition: bsProxy.h:485

Log Proxy Server Thread Error.

Parameters
devuriDevice URI string.
ecode

Definition at line 101 of file bsProxyThread.c.

Referenced by ThCreateServerThread(), ThHashAdd(), ThQueue(), and ThServiceThread().

Function Documentation

BsProxyThCtl_T* ThCreateDevThread ( const char *  sDevUri)

Create a device service thread.

The actual thread is only created if it does not already exists. The internal reference count is incremented to keep track of the users of this thread.

Execution Context:
Calling thread.
Parameters
sDevUriDevice URI.
Returns
On success, returns the service thread control block. On failure, NULL is returned.

Definition at line 756 of file bsProxyThread.c.

References BsProxyThStateInit, _bsproxy_th_ctl::m_eState, _bsproxy_th_ctl::m_fnRequest, _bsproxy_th_ctl::m_sDevUri, _bsproxy_th_ctl::m_thread, _bsproxy_th_ctl::m_uRefCnt, ThCtlBlkDelete(), ThCtlBlkNew(), ThDevRequest(), ThGlobalLock(), ThGlobalUnlock(), ThHashAdd(), ThHashDelete(), ThHashGetCtl(), ThServiceThread(), and ThSyncRun().

Referenced by ClientSetTraceState(), and VConnOpenDev().

757 {
758  BsProxyThCtl_T *pThCtl;
759  int rc;
760 
761  // lock global mutex
762  ThGlobalLock();
763 
764  //
765  // Device thread already exists.
766  //
767  if( (pThCtl = ThHashGetCtl(sDevUri)) != NULL )
768  {
769  pThCtl->m_uRefCnt++;
770  LOGDIAG1("Service Thread \"%s\" attached (refcnt=%u).",
771  pThCtl->m_sDevUri, pThCtl->m_uRefCnt);
772  }
773 
774  //
775  // Create new device thread.
776  //
777  else
778  {
779  //
780  // Create a new thread control block.
781  //
782  pThCtl = ThCtlBlkNew(sDevUri);
783 
784  pThCtl->m_fnRequest = ThDevRequest; // device request handler
785  pThCtl->m_uRefCnt = 1; // thread reference count
786  pThCtl->m_eState = BsProxyThStateInit; // control is (mostly) initialized
787 
788  //
789  // Add thread control to thread hash table
790  //
791  if( (rc = ThHashAdd(sDevUri, pThCtl)) < 0 )
792  {
793  LOGERROR("\"%s\": Failed to add thread control to hash table.", sDevUri);
794  ThCtlBlkDelete(pThCtl);
795  pThCtl = NULL;
796  }
797 
798  //
799  // Start the device service thread. The thread will block until the run
800  // state is set this context.
801  //
802  else if( pthread_create(&pThCtl->m_thread, NULL, ThServiceThread,
803  (void *)pThCtl) )
804  {
805  LOGSYSERROR("pthread_create(\"%s\")", sDevUri);
806  ThHashDelete(pThCtl);
807  pThCtl = NULL;
808  }
809 
810  //
811  // Signal the thread to run.
812  //
813  else
814  {
815  ThSyncRun(pThCtl);
816  }
817  }
818 
819  // unlock thread mutex
820  ThGlobalUnlock();
821 
822  return pThCtl;
823 }
static void ThGlobalLock()
Lock global mutual exclusion.
static BsProxyThCtl_T * ThCtlBlkNew(const char *sDevUri)
Allocate new service thread control block.
uint_t m_uRefCnt
vconn reference count for this thread
Definition: bsProxy.h:151
static void ThCtlBlkDelete(BsProxyThCtl_T *pThCtl)
Delete service thread control block.
static void ThSyncRun(BsProxyThCtl_T *pThCtl)
Command service thread to run.
pthread_t m_thread
the service thread
Definition: bsProxy.h:156
static int ThDevRequest(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen)
Device service thread request handler.
static int ThHashAdd(const char *sDevUri, BsProxyThCtl_T *pThCtl)
Add the module data to the i/f module hash table.
thread is initialized
Definition: bsProxy.h:140
static void * ThServiceThread(void *pThArg)
The service thread.
int(* m_fnRequest)(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen)
Service thread request handler.
Definition: bsProxy.h:170
static void ThHashDelete(BsProxyThCtl_T *pThCtl)
Remove and delete the module data from the i/f module hash table.
static void ThGlobalUnlock()
Unlock global mutual exclusion.
static BsProxyThCtl_T * ThHashGetCtl(const char *sDevUri)
Get the interface module&#39;s i/f from the module hash table.
BsProxyThState_T m_eState
thread state
Definition: bsProxy.h:152
const char * m_sDevUri
proxied device URI or server
Definition: bsProxy.h:150
BsProxyThCtl_T* ThCreateServerThread ( )

Create the special server service thread.

There is only one server service thread per server. The server thread processes all server terminated requests.

Execution Context:
Calling thread.
Returns
On success, returns the service thread control block. On failure, NULL is returned.

Definition at line 837 of file bsProxyThread.c.

References BS_ECODE_INTERNAL, BSPROXY_TH_LOG_ERROR, BSPROXY_TH_SERVER_URI, BsProxyThStateInit, _bsproxy_th_ctl::m_eState, _bsproxy_th_ctl::m_fnRequest, _bsproxy_th_ctl::m_thread, _bsproxy_th_ctl::m_uRefCnt, ServerRequest(), ThCtlBlkDelete(), ThCtlBlkNew(), ThGlobalLock(), ThGlobalUnlock(), ThHashAdd(), ThHashDelete(), ThHashGetCtl(), ThServiceThread(), and ThSyncRun().

Referenced by ClientSetTraceState(), and VConnOpenServer().

838 {
839  char *sDevUri;
840  BsProxyThCtl_T *pThCtl;
841  int rc;
842 
843  // Server URI
844  sDevUri = new_strdup(BSPROXY_TH_SERVER_URI);
845 
846  // lock global mutex
847  ThGlobalLock();
848 
849  //
850  // There should only be one server thread.
851  //
852  if( (pThCtl = ThHashGetCtl(sDevUri)) != NULL )
853  {
855  "Server service thread already exists.");
856  }
857 
858  //
859  // Create new device thread.
860  //
861  else
862  {
863  //
864  // Create a new thread control block.
865  //
866  pThCtl = ThCtlBlkNew(sDevUri);
867 
868  pThCtl->m_fnRequest = ServerRequest; // server request handler
869  pThCtl->m_uRefCnt = 1; // thread reference count
870  pThCtl->m_eState = BsProxyThStateInit; // control is (mostly) initialized
871 
872  //
873  // Add thread control to thread hash table
874  //
875  if( (rc = ThHashAdd(sDevUri, pThCtl)) < 0 )
876  {
877  LOGERROR("\"%s\": Failed to add thread control to hash table.", sDevUri);
878  ThCtlBlkDelete(pThCtl);
879  pThCtl = NULL;
880  }
881 
882  //
883  // Start the device service thread. The thread will block until the run
884  // state is set this context.
885  //
886  else if( pthread_create(&pThCtl->m_thread, NULL, ThServiceThread,
887  (void *)pThCtl) )
888  {
889  LOGSYSERROR("pthread_create(\"%s\")", sDevUri);
890  ThHashDelete(pThCtl);
891  pThCtl = NULL;
892  }
893 
894  //
895  // Signal the thread to run.
896  //
897  else
898  {
899  ThSyncRun(pThCtl);
900  }
901  }
902 
903  // unlock global mutex
904  ThGlobalUnlock();
905 
906  return pThCtl;
907 }
static void ThGlobalLock()
Lock global mutual exclusion.
static BsProxyThCtl_T * ThCtlBlkNew(const char *sDevUri)
Allocate new service thread control block.
uint_t m_uRefCnt
vconn reference count for this thread
Definition: bsProxy.h:151
static void ThCtlBlkDelete(BsProxyThCtl_T *pThCtl)
Delete service thread control block.
static void ThSyncRun(BsProxyThCtl_T *pThCtl)
Command service thread to run.
#define BSPROXY_TH_LOG_ERROR(devuri, ecode, efmt,...)
Log Proxy Server Thread Error.
pthread_t m_thread
the service thread
Definition: bsProxy.h:156
static int ThHashAdd(const char *sDevUri, BsProxyThCtl_T *pThCtl)
Add the module data to the i/f module hash table.
thread is initialized
Definition: bsProxy.h:140
static void * ThServiceThread(void *pThArg)
The service thread.
int(* m_fnRequest)(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen)
Service thread request handler.
Definition: bsProxy.h:170
static void ThHashDelete(BsProxyThCtl_T *pThCtl)
Remove and delete the module data from the i/f module hash table.
static void ThGlobalUnlock()
Unlock global mutual exclusion.
#define BS_ECODE_INTERNAL
internal error (bug)
Definition: BotSense.h:93
static BsProxyThCtl_T * ThHashGetCtl(const char *sDevUri)
Get the interface module&#39;s i/f from the module hash table.
BsProxyThState_T m_eState
thread state
Definition: bsProxy.h:152
#define BSPROXY_TH_SERVER_URI
server "URI"
Definition: bsProxyThread.c:87
int ServerRequest(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen)
Server service thread request handler.
static void ThCtlBlkDelete ( BsProxyThCtl_T pThCtl)
static

Delete service thread control block.

Parameters
pThCtlPointer to thread control block.

Definition at line 173 of file bsProxyThread.c.

References _bsproxy_th_ctl::m_condSync, _bsproxy_th_ctl::m_mutexSync, _bsproxy_th_ctl::m_queue, and _bsproxy_th_ctl::m_sDevUri.

Referenced by ThCreateDevThread(), ThCreateServerThread(), and ThHashDeleteData().

174 {
175  if( pThCtl != NULL )
176  {
177  // delete uri
178  delete((char *)pThCtl->m_sDevUri);
179 
180  // delete request queue
181  DListVoidDelete(pThCtl->m_queue);
182 
183  // destroy condition
184  pthread_cond_destroy(&pThCtl->m_condSync);
185 
186  // destroy mutex
187  pthread_mutex_destroy(&pThCtl->m_mutexSync);
188 
189  // delete self
190  delete(pThCtl);
191  }
192 }
pthread_mutex_t m_mutexSync
synchronization mutex used by condition
Definition: bsProxy.h:153
pthread_cond_t m_condSync
synchronization condition
Definition: bsProxy.h:154
DListVoid_T * m_queue
thread request queue
Definition: bsProxy.h:155
const char * m_sDevUri
proxied device URI or server
Definition: bsProxy.h:150
static BsProxyThCtl_T* ThCtlBlkNew ( const char *  sDevUri)
static

Allocate new service thread control block.

Parameters
sDevUriDevice URI.
Returns
Pointer to allocated thread control block.

Definition at line 150 of file bsProxyThread.c.

References BsProxyThStateUninit, _bsproxy_th_ctl::m_condSync, _bsproxy_th_ctl::m_eState, _bsproxy_th_ctl::m_mutexSync, _bsproxy_th_ctl::m_queue, _bsproxy_th_ctl::m_sDevUri, _bsproxy_th_ctl::m_uRefCnt, ThQReqCmp(), and ThQReqDelete().

Referenced by ThCreateDevThread(), and ThCreateServerThread().

151 {
152  BsProxyThCtl_T *pThCtl = NEW(BsProxyThCtl_T);
153 
154  pThCtl->m_sDevUri = new_strdup(sDevUri);
155  pThCtl->m_uRefCnt = 0;
156  pThCtl->m_eState = BsProxyThStateUninit;
157  pThCtl->m_queue = DListVoidNew(ThQReqCmp, ThQReqDelete);
158 
159  // create mutex
160  pthread_mutex_init(&pThCtl->m_mutexSync, NULL);
161 
162  // create condition
163  pthread_cond_init(&pThCtl->m_condSync, NULL);
164 
165  return pThCtl;
166 }
uint_t m_uRefCnt
vconn reference count for this thread
Definition: bsProxy.h:151
static int ThQReqCmp(const void *pData1, const void *pData2)
Queue callback to compare two queue entries.
pthread_mutex_t m_mutexSync
synchronization mutex used by condition
Definition: bsProxy.h:153
pthread_cond_t m_condSync
synchronization condition
Definition: bsProxy.h:154
static void ThQReqDelete(void *pData)
Queue callback to delete queue entry.
DListVoid_T * m_queue
thread request queue
Definition: bsProxy.h:155
thread is not fully initialized
Definition: bsProxy.h:139
BsProxyThState_T m_eState
thread state
Definition: bsProxy.h:152
const char * m_sDevUri
proxied device URI or server
Definition: bsProxy.h:150
BsProxyThReq_T* ThDequeue ( BsProxyThCtl_T pThCtl)

Dequeue a request for the given service thread.

The service thread will block if no queued request is present.

Execution Context:
Service thread.
Returns
On success, returns removed request at the front of the queue.
On failure, NULL is returned.

Definition at line 675 of file bsProxyThread.c.

References BsProxyThStateRunning, _bsproxy_th_ctl::m_eState, _bsproxy_th_ctl::m_queue, ThSyncLock(), ThSyncUnlock(), and ThSyncWait().

Referenced by ClientSetTraceState(), and ThServiceThread().

676 {
677  BsProxyThReq_T *pThReq;
678 
679  // lock thread and queue
680  ThSyncLock(pThCtl);
681 
682  //
683  // Block waiting for queued request or state change event.
684  //
685  while( (pThCtl->m_eState == BsProxyThStateRunning) &&
686  (DListVoidCount(pThCtl->m_queue) == 0) )
687  {
688  // Release mutex, block on conditional variable, auto-lock mutex on return.
689  ThSyncWait(pThCtl);
690  }
691 
692  if( pThCtl->m_eState == BsProxyThStateRunning )
693  {
694  pThReq = (BsProxyThReq_T *)DListVoidDequeue(pThCtl->m_queue);
695  }
696  else
697  {
698  pThReq = NULL;
699  }
700 
701  // unlock thread and queue
702  ThSyncUnlock(pThCtl);
703 
704  return pThReq;
705 }
static void ThSyncUnlock(BsProxyThCtl_T *pThCtl)
Unlock service thread&#39;s mutual exclusion.
static void ThSyncWait(BsProxyThCtl_T *pThCtl)
Wait on service thread&#39;s condition.
static void ThSyncLock(BsProxyThCtl_T *pThCtl)
Lock service thread&#39;s mutual exclusion.
DListVoid_T * m_queue
thread request queue
Definition: bsProxy.h:155
thread is running (nominal state)
Definition: bsProxy.h:141
BsProxyThState_T m_eState
thread state
Definition: bsProxy.h:152
void ThDestroyThread ( BsProxyThCtl_T pThCtl)

Destroy service thread.

The thread's reference count is decremented. If the count is zero, then the thread is actually destroyed with all queued requests deleted. The calling thread is suspended until the target service thread terminates.

Execution Context:
Calling thread.
Parameters
pThCtlService thread control block.

Definition at line 921 of file bsProxyThread.c.

References _bsproxy_th_ctl::m_sDevUri, _bsproxy_th_ctl::m_thread, _bsproxy_th_ctl::m_uRefCnt, ThGlobalLock(), ThGlobalUnlock(), ThHashDelete(), and ThSyncExit().

Referenced by ClientSetTraceState(), VConnClose(), and VConnOpenDev().

922 {
923  if( pThCtl == NULL )
924  {
925  return;
926  }
927 
928  // lock global mutex
929  ThGlobalLock();
930 
931  // do not destroy the thread since there exists users of this thread
932  if( pThCtl->m_uRefCnt > 0 )
933  {
934  pThCtl->m_uRefCnt--;
935  }
936 
937  // thread is not being used anymore - destroy
938  if( pThCtl->m_uRefCnt == 0 )
939  {
940  // signal thread of exit state change
941  ThSyncExit(pThCtl);
942 
943  // wait for thread to terminate
944  pthread_join(pThCtl->m_thread, NULL);
945 
946  // delete the thread hash entry's control block (including its queue)
947  ThHashDelete(pThCtl);
948  }
949 
950  else
951  {
952  LOGDIAG1("Service Thread \"%s\" detached (refcnt=%u).",
953  pThCtl->m_sDevUri, pThCtl->m_uRefCnt);
954  }
955 
956  // unlock global mutex
957  ThGlobalUnlock();
958 }
static void ThSyncExit(BsProxyThCtl_T *pThCtl)
Command service thread to exit.
static void ThGlobalLock()
Lock global mutual exclusion.
uint_t m_uRefCnt
vconn reference count for this thread
Definition: bsProxy.h:151
pthread_t m_thread
the service thread
Definition: bsProxy.h:156
static void ThHashDelete(BsProxyThCtl_T *pThCtl)
Remove and delete the module data from the i/f module hash table.
static void ThGlobalUnlock()
Unlock global mutual exclusion.
const char * m_sDevUri
proxied device URI or server
Definition: bsProxy.h:150
static int ThDevRequest ( BsProxyClientHnd_T  hndClient,
BsVConnHnd_T  hndVConn,
BsTid_T  uTid,
BsMsgId_T  uMsgId,
byte_t  bufReq[],
size_t  uReqLen 
)
static

Device service thread request handler.

Execution Context:
Device service thread.
Parameters
hndClient

Definition at line 462 of file bsProxyThread.c.

References BS_ECODE_NO_VCONN, BSPROXY_LOG_ERROR, BSPROXY_SEND_ERROR_RSP, BsProxyModIF_T::m_fnModRequest, BsProxyVConn_T::m_pModIF, VConnAcquire(), and VConnRelease().

Referenced by ThCreateDevThread().

468 {
469  BsProxyVConn_T *pVConn;
470  int rc;
471 
472  //
473  // Acquire virtual connection.
474  //
475  if( (pVConn = VConnAcquire(hndVConn)) != NULL )
476  {
477  //
478  // Call the interface module' specific request handler.
479  // The module is responsible for sending a response back regardless if the
480  // request is a success or a failure.
481  //
482  rc = pVConn->m_pModIF->m_fnModRequest(hndVConn, uTid, uMsgId, bufReq,
483  uReqLen);
484 
485  // release virtual connection
486  VConnRelease(hndVConn);
487 
488  // error
489  if( rc < 0 )
490  {
491  BSPROXY_LOG_ERROR(hndClient, rc, "Request failed.");
492  }
493  }
494 
495  else
496  {
497  BSPROXY_SEND_ERROR_RSP(hndClient, hndVConn, uTid, BS_ECODE_NO_VCONN,
498  "VConn=%d", hndVConn);
499  rc = -BS_ECODE_NO_VCONN;
500  }
501 
502  return rc;
503 }
void VConnRelease(BsVConnHnd_T hndVConn)
Release the locked virtual client.
Definition: bsProxyVConn.c:585
BsProxyVConn_T * VConnAcquire(BsVConnHnd_T hndVConn)
Acquire virtual connection, locking it from other threads.
Definition: bsProxyVConn.c:552
#define BSPROXY_SEND_ERROR_RSP(hndClient, hndVConn, uTid, ecode, efmt,...)
Log <b><i>BotSense</i></b> Error and Send Error Response.
Definition: bsProxy.h:330
#define BSPROXY_LOG_ERROR(hndClient, ecode, efmt,...)
Log Proxy Server Error.
Definition: bsProxy.h:288
#define BS_ECODE_NO_VCONN
virtual connection not found
Definition: BotSense.h:80
BsProxyModIF_T * m_pModIF
interface module I/F
Definition: bsProxy.h:226
BsModRequestFunc_P m_fnModRequest
module request
Definition: bsProxy.h:129
static bool_t ThGlobalTryLock ( )
inlinestatic

Try to lock global mutual exclusion.

Returns
Returns true if lock is acquired. Otherwise returns false if mutex already locked.

Definition at line 234 of file bsProxyThread.c.

References BsThGlobalMutex.

235 {
236  return pthread_mutex_trylock(&BsThGlobalMutex) == 0? true: false;
237 }
static pthread_mutex_t BsThGlobalMutex
bsProxy module operations mutex
Definition: bsProxyThread.c:90
static int ThHashAdd ( const char *  sDevUri,
BsProxyThCtl_T pThCtl 
)
static

Add the module data to the i/f module hash table.

Parameters
sDevUriAllocated Proxied device hash table key.
pThCtlAllocated service thread control.
Returns
On success, BS_OK is returned.
On error, the appropriate < 0 negated BotSense Error Code is returned.

Definition at line 334 of file bsProxyThread.c.

References BS_ECODE_NO_RSRC, BS_OK, BSPROXY_TH_LOG_ERROR, BsThHashTbl, and ThHashDeleteData().

Referenced by ThCreateDevThread(), and ThCreateServerThread().

335 {
336  char *sKey = new_strdup(sDevUri);
337  int rc;
338 
339  // insert into hash table, automatically allocating hnode_t
340  if( !hash_insert(BsThHashTbl, sKey, pThCtl) )
341  {
342  rc = -BS_ECODE_NO_RSRC;
343  BSPROXY_TH_LOG_ERROR(sDevUri, rc, "hash_insert(%s,...) failed", sKey);
344  ThHashDeleteData(sKey, pThCtl);
345  return rc;
346  }
347 
348  return BS_OK;
349 }
static void ThHashDeleteData(void *sDevUri, void *pThCtl)
Delete hash node data callback.
#define BSPROXY_TH_LOG_ERROR(devuri, ecode, efmt,...)
Log Proxy Server Thread Error.
#define BS_OK
not an error, success
Definition: BotSense.h:66
#define BS_ECODE_NO_RSRC
no resource available
Definition: BotSense.h:85
static hash_t * BsThHashTbl
proxied device hash table
Definition: bsProxyThread.c:91
static void ThHashDelete ( BsProxyThCtl_T pThCtl)
static

Remove and delete the module data from the i/f module hash table.

Parameters
pThCtlAllocated service thread control.
Returns
On success, BS_OK is returned.
On error, the appropriate < 0 negated BotSense Error Code is returned.

Definition at line 358 of file bsProxyThread.c.

References BsThHashTbl, and _bsproxy_th_ctl::m_sDevUri.

Referenced by ThCreateDevThread(), ThCreateServerThread(), and ThDestroyThread().

359 {
360  hnode_t *pNode;
361 
362  if( (pThCtl != NULL) &&
363  ((pNode = hash_lookup(BsThHashTbl, pThCtl->m_sDevUri)) != NULL) )
364  {
365  hash_node_delete(BsThHashTbl, pNode);
366  }
367 }
static hash_t * BsThHashTbl
proxied device hash table
Definition: bsProxyThread.c:91
const char * m_sDevUri
proxied device URI or server
Definition: bsProxy.h:150
static void ThHashDeleteData ( void *  sDevUri,
void *  pThCtl 
)
static

Delete hash node data callback.

Both the key and value are dynamically allocated.

Parameters
sDevUriProxied device hash table key.
pThCtlService thread control.

Definition at line 320 of file bsProxyThread.c.

References ThCtlBlkDelete().

Referenced by ThHashAdd(), and ThOneTimeInit().

321 {
322  delete(sDevUri);
323  ThCtlBlkDelete(pThCtl);
324 }
static void ThCtlBlkDelete(BsProxyThCtl_T *pThCtl)
Delete service thread control block.
static BsProxyThCtl_T* ThHashGetCtl ( const char *  sDevUri)
static

Get the interface module's i/f from the module hash table.

Parameters
sDevUriProxied device hash table key.
Returns
On success, returns pointer to the associated thread control block. On failure, returns NULL.

Definition at line 378 of file bsProxyThread.c.

References BsThHashTbl.

Referenced by ThCreateDevThread(), and ThCreateServerThread().

379 {
380  hnode_t *pNode;
381 
382  if( (pNode = hash_lookup(BsThHashTbl, sDevUri)) == NULL )
383  {
384  return NULL;
385  }
386  else
387  {
388  return (BsProxyThCtl_T *)hnode_get(pNode);
389  }
390 }
static hash_t * BsThHashTbl
proxied device hash table
Definition: bsProxyThread.c:91
char* ThNewDevUri ( const char *  sDevName)

Convert the device name to a quasi Uniform Resource Id.

Parameters
sDevNameDevice path name.
Returns
On success, an allocated, canonical device path name is returned.
On failure, NULL is returned.

Definition at line 737 of file bsProxyThread.c.

Referenced by ClientSetTraceState(), and VConnOpenDev().

738 {
739  return NewSearchPathCanonicalized(sDevName);
740 }
static int ThQReqCmp ( const void *  pData1,
const void *  pData2 
)
static

Queue callback to compare two queue entries.

Parameters
pData1Pointer to queue entry 1.
pData2Pointer to queue entry 2.
Returns
Returns < 0, 0, or > 0 if data 1 is less than, equal to, or greater than data2, respectively.

Definition at line 121 of file bsProxyThread.c.

References BSPROXY_MAKE_MSGUID, _bsproxy_th_req::m_hndVConn, and _bsproxy_th_req::m_uMsgId.

Referenced by ThCtlBlkNew().

122 {
123  BsProxyThReq_T *pThReq1 = (BsProxyThReq_T *)pData1;
124  BsProxyThReq_T *pThReq2 = (BsProxyThReq_T *)pData2;
125  BsMsgUid_T uid1 = BSPROXY_MAKE_MSGUID(pThReq1->m_hndVConn,
126  pThReq1->m_uMsgId);
127  BsMsgUid_T uid2 = BSPROXY_MAKE_MSGUID(pThReq2->m_hndVConn,
128  pThReq2->m_uMsgId);
129 
130  return (int)uid1 - (int)uid2;
131 }
uint_t BsMsgUid_T
client message unique id
Definition: BotSense.h:245
#define BSPROXY_MAKE_MSGUID(hndVConn, msgid)
Make a MSGUID.
Definition: BotSense.h:218
BsVConnHnd_T m_hndVConn
virtual connection handle
Definition: bsProxy.h:236
BsMsgId_T m_uMsgId
message id
Definition: bsProxy.h:238
static void ThQReqDelete ( void *  pData)
static

Queue callback to delete queue entry.

Parameters
pDataPointer to queue entry.

Definition at line 138 of file bsProxyThread.c.

References ThReqDelete().

Referenced by ThCtlBlkNew().

139 {
140  ThReqDelete((BsProxyThReq_T *)pData);
141 }
void ThReqDelete(BsProxyThReq_T *pThReq)
Delete service thread request.
int ThQueue ( BsProxyThCtl_T pThCtl,
BsProxyClientHnd_T  hndClient,
BsVConnHnd_T  hndVConn,
BsTid_T  uTid,
BsMsgId_T  uMsgId,
byte_t  bufReq[],
size_t  uReqLen 
)

Queue a request for the given service thread.

Execution Context:
Calling thread.
Parameters
pThCtlService thread control block.
hndClientClient handle.
hndVConnVirtual connection handle.
uTidRequest-Response transaction id.
uMsgIdRequest message id.
bufReqAllocated packed request message body.
uReqLenLength of request in buffer (number of bytes).
Returns
On success, BS_OK is returned.
On error, the appropriate < 0 negated BotSense Error Code is returned.

Definition at line 626 of file bsProxyThread.c.

References BS_ECODE_NO_RSRC, BS_OK, BSPROXY_TH_LOG_ERROR, BSPROXY_TH_MAX_QUEUE_SIZE, _bsproxy_th_ctl::m_queue, _bsproxy_th_ctl::m_sDevUri, ServerHasName(), ThReqNew(), ThSyncLock(), ThSyncSignal(), and ThSyncUnlock().

Referenced by BsProxyDispatch(), and ClientSetTraceState().

633 {
634  BsProxyThReq_T *pThReq;
635  int rc;
636 
637  // lock thread and queue
638  ThSyncLock(pThCtl);
639 
640  //
641  // Queue request on thread's message queue.
642  //
643  if( DListVoidCount(pThCtl->m_queue) < BSPROXY_TH_MAX_QUEUE_SIZE )
644  {
645  pThReq = ThReqNew(hndClient, hndVConn, uTid, uMsgId, bufReq, uReqLen);
646  DListVoidQueue(pThCtl->m_queue, pThReq);
647  ThSyncSignal(pThCtl);
648  LOGDIAG3("%s: Service Thread \"%s\": queue depth=%u.",
649  ServerHasName(), pThCtl->m_sDevUri, DListVoidCount(pThCtl->m_queue));
650  rc = BS_OK;
651  }
652  else
653  {
654  rc = -BS_ECODE_NO_RSRC;
655  BSPROXY_TH_LOG_ERROR(pThCtl->m_sDevUri, rc, "Queue overflow.");
656  }
657 
658  // unlock thread and queue
659  ThSyncUnlock(pThCtl);
660 
661  return rc;
662 }
static void ThSyncUnlock(BsProxyThCtl_T *pThCtl)
Unlock service thread&#39;s mutual exclusion.
#define BSPROXY_TH_MAX_QUEUE_SIZE
request queue maximum depth
Definition: bsProxyThread.c:86
#define BSPROXY_TH_LOG_ERROR(devuri, ecode, efmt,...)
Log Proxy Server Thread Error.
INLINE_IN_H const char * ServerHasName()
Get the <b><i>BotSense</i></b> server&#39;s official name.
Definition: bsProxy.h:485
#define BS_OK
not an error, success
Definition: BotSense.h:66
static void ThSyncLock(BsProxyThCtl_T *pThCtl)
Lock service thread&#39;s mutual exclusion.
DListVoid_T * m_queue
thread request queue
Definition: bsProxy.h:155
BsProxyThReq_T * ThReqNew(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen)
Allocate and initalized a new service thread request.
#define BS_ECODE_NO_RSRC
no resource available
Definition: BotSense.h:85
static void ThSyncSignal(BsProxyThCtl_T *pThCtl)
Signal service thread&#39;s condition.
const char * m_sDevUri
proxied device URI or server
Definition: bsProxy.h:150
void ThReqDelete ( BsProxyThReq_T pThReq)

Delete service thread request.

Parameters
pThReqService thread request.

Definition at line 601 of file bsProxyThread.c.

References _bsproxy_th_req::m_bufReq.

Referenced by ClientSetTraceState(), ThQReqDelete(), and ThServiceThread().

602 {
603  if( pThReq != NULL )
604  {
605  delete(pThReq->m_bufReq);
606  delete(pThReq);
607  }
608 }
byte_t * m_bufReq
packed request message buffer
Definition: bsProxy.h:239
BsProxyThReq_T* ThReqNew ( BsProxyClientHnd_T  hndClient,
BsVConnHnd_T  hndVConn,
BsTid_T  uTid,
BsMsgId_T  uMsgId,
byte_t  bufReq[],
size_t  uReqLen 
)

Allocate and initalized a new service thread request.

Parameters
hndClientClient handle.
hndVConnVirtual connection handle.
uTidRequest-Response transaction id.
uMsgIdRequest message id.
bufReqAllocated packed request message body.
uReqLenLength of request in buffer (number of bytes).
Returns
Pointer to allocated request.

Definition at line 577 of file bsProxyThread.c.

References _bsproxy_th_req::m_bufReq, _bsproxy_th_req::m_hndClient, _bsproxy_th_req::m_hndVConn, _bsproxy_th_req::m_uMsgId, _bsproxy_th_req::m_uReqLen, and _bsproxy_th_req::m_uTid.

Referenced by ClientSetTraceState(), and ThQueue().

583 {
584  BsProxyThReq_T *pThReq = NEW(BsProxyThReq_T);
585 
586  pThReq->m_hndClient = hndClient;
587  pThReq->m_hndVConn = hndVConn;
588  pThReq->m_uTid = uTid;
589  pThReq->m_uMsgId = uMsgId;
590  pThReq->m_bufReq = bufReq;
591  pThReq->m_uReqLen = uReqLen;
592 
593  return pThReq;
594 }
byte_t * m_bufReq
packed request message buffer
Definition: bsProxy.h:239
size_t m_uReqLen
request buffer length
Definition: bsProxy.h:240
BsProxyClientHnd_T m_hndClient
proxied client handle
Definition: bsProxy.h:235
BsVConnHnd_T m_hndVConn
virtual connection handle
Definition: bsProxy.h:236
BsMsgId_T m_uMsgId
message id
Definition: bsProxy.h:238
BsTid_T m_uTid
request-response transaction id
Definition: bsProxy.h:237
static void* ThServiceThread ( void *  pThArg)
static

The service thread.

Parameters
pThArgThread argument.
Returns
Returns NULL on thread exit.

Definition at line 512 of file bsProxyThread.c.

References BS_ECODE_NO_EXEC, BSPROXY_TH_LOG_ERROR, BsProxyThStateExit, _bsproxy_th_req::m_bufReq, _bsproxy_th_ctl::m_eState, _bsproxy_th_ctl::m_fnRequest, _bsproxy_th_req::m_hndClient, _bsproxy_th_req::m_hndVConn, _bsproxy_th_ctl::m_sDevUri, _bsproxy_th_req::m_uMsgId, _bsproxy_th_req::m_uReqLen, _bsproxy_th_req::m_uTid, ThDequeue(), ThReqDelete(), and ThSyncWaitForRun().

Referenced by ThCreateDevThread(), and ThCreateServerThread().

513 {
514  BsProxyThCtl_T *pThCtl = (BsProxyThCtl_T *)pThArg;
515  BsProxyThReq_T *pThReq;
516  int rc;
517 
518  LOGDIAG1("Service Thread \"%s\" created.", pThCtl->m_sDevUri);
519 
520  ThSyncWaitForRun(pThCtl);
521 
522  //
523  // Wait for any queue message or thread state change.
524  //
525  while( (pThReq = ThDequeue(pThCtl)) )
526  {
527  // exit thread
528  if( pThCtl->m_eState == BsProxyThStateExit )
529  {
530  break;
531  }
532  // nothing on queue
533  else if( pThReq == NULL )
534  {
536  "No request on queue.");
537  }
538  // service request then destroy
539  else
540  {
541  rc = pThCtl->m_fnRequest(pThReq->m_hndClient,
542  pThReq->m_hndVConn,
543  pThReq->m_uTid,
544  pThReq->m_uMsgId,
545  pThReq->m_bufReq,
546  pThReq->m_uReqLen);
547  ThReqDelete(pThReq);
548  }
549  }
550 
551  LOGDIAG1("Service Thread \"%s\" destroyed.", pThCtl->m_sDevUri);
552 
553  return NULL;
554 }
byte_t * m_bufReq
packed request message buffer
Definition: bsProxy.h:239
thread is exiting
Definition: bsProxy.h:142
BsProxyThReq_T * ThDequeue(BsProxyThCtl_T *pThCtl)
Dequeue a request for the given service thread.
#define BSPROXY_TH_LOG_ERROR(devuri, ecode, efmt,...)
Log Proxy Server Thread Error.
size_t m_uReqLen
request buffer length
Definition: bsProxy.h:240
BsProxyClientHnd_T m_hndClient
proxied client handle
Definition: bsProxy.h:235
#define BS_ECODE_NO_EXEC
cannot execute
Definition: BotSense.h:88
void ThReqDelete(BsProxyThReq_T *pThReq)
Delete service thread request.
BsVConnHnd_T m_hndVConn
virtual connection handle
Definition: bsProxy.h:236
int(* m_fnRequest)(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen)
Service thread request handler.
Definition: bsProxy.h:170
BsProxyThState_T m_eState
thread state
Definition: bsProxy.h:152
BsMsgId_T m_uMsgId
message id
Definition: bsProxy.h:238
const char * m_sDevUri
proxied device URI or server
Definition: bsProxy.h:150
static void ThSyncWaitForRun(BsProxyThCtl_T *pThCtl)
Wait indefinitely until state change.
BsTid_T m_uTid
request-response transaction id
Definition: bsProxy.h:237
static void ThSyncExit ( BsProxyThCtl_T pThCtl)
static

Command service thread to exit.

Execution Context:
Calling thread.
Parameters
pThCtlService thread control block.

Definition at line 421 of file bsProxyThread.c.

References BsProxyThStateExit, _bsproxy_th_ctl::m_eState, ThSyncLock(), ThSyncSignal(), and ThSyncUnlock().

Referenced by ThDestroyThread().

422 {
423  ThSyncLock(pThCtl);
424  pThCtl->m_eState = BsProxyThStateExit;
425  ThSyncSignal(pThCtl);
426  ThSyncUnlock(pThCtl);
427 }
static void ThSyncUnlock(BsProxyThCtl_T *pThCtl)
Unlock service thread&#39;s mutual exclusion.
thread is exiting
Definition: bsProxy.h:142
static void ThSyncLock(BsProxyThCtl_T *pThCtl)
Lock service thread&#39;s mutual exclusion.
BsProxyThState_T m_eState
thread state
Definition: bsProxy.h:152
static void ThSyncSignal(BsProxyThCtl_T *pThCtl)
Signal service thread&#39;s condition.
static void ThSyncLock ( BsProxyThCtl_T pThCtl)
inlinestatic

Lock service thread's mutual exclusion.

Parameters
pThCtlService thread control.

Definition at line 244 of file bsProxyThread.c.

References _bsproxy_th_ctl::m_mutexSync, and _bsproxy_th_ctl::m_sDevUri.

Referenced by ThDequeue(), ThQueue(), ThSyncExit(), ThSyncRun(), and ThSyncWaitForRun().

245 {
246  int rc;
247 
248  if( (rc = pthread_mutex_lock(&pThCtl->m_mutexSync)) != 0 )
249  {
250  errno = rc;
251  LOGSYSERROR("Service Thread \"%s\": pthread_mutex_lock()",
252  pThCtl->m_sDevUri);
253  }
254 }
pthread_mutex_t m_mutexSync
synchronization mutex used by condition
Definition: bsProxy.h:153
const char * m_sDevUri
proxied device URI or server
Definition: bsProxy.h:150
static void ThSyncRun ( BsProxyThCtl_T pThCtl)
static

Command service thread to run.

Parameters
pThCtlService thread control block.
Execution Context:
Calling thread.

Definition at line 405 of file bsProxyThread.c.

References BsProxyThStateRunning, _bsproxy_th_ctl::m_eState, ThSyncLock(), ThSyncSignal(), and ThSyncUnlock().

Referenced by ThCreateDevThread(), and ThCreateServerThread().

406 {
407  ThSyncLock(pThCtl);
409  ThSyncSignal(pThCtl);
410  ThSyncUnlock(pThCtl);
411 }
static void ThSyncUnlock(BsProxyThCtl_T *pThCtl)
Unlock service thread&#39;s mutual exclusion.
static void ThSyncLock(BsProxyThCtl_T *pThCtl)
Lock service thread&#39;s mutual exclusion.
thread is running (nominal state)
Definition: bsProxy.h:141
BsProxyThState_T m_eState
thread state
Definition: bsProxy.h:152
static void ThSyncSignal(BsProxyThCtl_T *pThCtl)
Signal service thread&#39;s condition.
static void ThSyncSignal ( BsProxyThCtl_T pThCtl)
inlinestatic

Signal service thread's condition.

Parameters
pThCtlService thread control.

Definition at line 278 of file bsProxyThread.c.

References _bsproxy_th_ctl::m_condSync, and _bsproxy_th_ctl::m_sDevUri.

Referenced by ThQueue(), ThSyncExit(), and ThSyncRun().

279 {
280  int rc;
281 
282  if( (rc = pthread_cond_signal(&pThCtl->m_condSync)) != 0 )
283  {
284  errno = rc;
285  LOGSYSERROR("Service Thread \"%s\": pthread_cond_signal()",
286  pThCtl->m_sDevUri);
287  }
288 }
pthread_cond_t m_condSync
synchronization condition
Definition: bsProxy.h:154
const char * m_sDevUri
proxied device URI or server
Definition: bsProxy.h:150
static void ThSyncUnlock ( BsProxyThCtl_T pThCtl)
inlinestatic

Unlock service thread's mutual exclusion.

Parameters
pThCtlService thread control.

Definition at line 261 of file bsProxyThread.c.

References _bsproxy_th_ctl::m_mutexSync, and _bsproxy_th_ctl::m_sDevUri.

Referenced by ThDequeue(), ThQueue(), ThSyncExit(), ThSyncRun(), and ThSyncWaitForRun().

262 {
263  int rc;
264 
265  if( (rc = pthread_mutex_unlock(&pThCtl->m_mutexSync)) != 0 )
266  {
267  errno = rc;
268  LOGSYSERROR("Service Thread \"%s\": pthread_mutex_unlock()",
269  pThCtl->m_sDevUri);
270  }
271 }
pthread_mutex_t m_mutexSync
synchronization mutex used by condition
Definition: bsProxy.h:153
const char * m_sDevUri
proxied device URI or server
Definition: bsProxy.h:150
static void ThSyncWait ( BsProxyThCtl_T pThCtl)
inlinestatic

Wait on service thread's condition.

Parameters
pThCtlService thread control.

Definition at line 295 of file bsProxyThread.c.

References _bsproxy_th_ctl::m_condSync, _bsproxy_th_ctl::m_mutexSync, and _bsproxy_th_ctl::m_sDevUri.

Referenced by ThDequeue(), and ThSyncWaitForRun().

296 {
297  int rc;
298 
299  if( (rc = pthread_cond_wait(&pThCtl->m_condSync, &pThCtl->m_mutexSync)) != 0 )
300  {
301  errno = rc;
302  LOGSYSERROR("Service Thread \"%s\": pthread_cond_wait()",
303  pThCtl->m_sDevUri);
304  }
305 }
pthread_mutex_t m_mutexSync
synchronization mutex used by condition
Definition: bsProxy.h:153
pthread_cond_t m_condSync
synchronization condition
Definition: bsProxy.h:154
const char * m_sDevUri
proxied device URI or server
Definition: bsProxy.h:150
static void ThSyncWaitForRun ( BsProxyThCtl_T pThCtl)
static

Wait indefinitely until state change.

Execution Context:
Service thread.
Parameters
pThCtlService thread control block.

Definition at line 437 of file bsProxyThread.c.

References BsProxyThStateInit, _bsproxy_th_ctl::m_eState, ThSyncLock(), ThSyncUnlock(), and ThSyncWait().

Referenced by ThServiceThread().

438 {
439  ThSyncLock(pThCtl);
440  while( pThCtl->m_eState == BsProxyThStateInit )
441  {
442  ThSyncWait(pThCtl);
443  }
444  ThSyncUnlock(pThCtl);
445 }
static void ThSyncUnlock(BsProxyThCtl_T *pThCtl)
Unlock service thread&#39;s mutual exclusion.
static void ThSyncWait(BsProxyThCtl_T *pThCtl)
Wait on service thread&#39;s condition.
static void ThSyncLock(BsProxyThCtl_T *pThCtl)
Lock service thread&#39;s mutual exclusion.
thread is initialized
Definition: bsProxy.h:140
BsProxyThState_T m_eState
thread state
Definition: bsProxy.h:152