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

Virtual connections management operations. More...

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include "rnr/rnrconfig.h"
#include "rnr/log.h"
#include "rnr/new.h"
#include "botsense/BotSense.h"
#include "botsense/bsProxyModIF.h"
#include "bsProxy.h"

Go to the source code of this file.

Functions

static void VConnLockBusy ()
 Lock virtual connection's global busy mutual exclusion.
 
static void VConnUnlockBusy ()
 Unlock virtual connection's global busy mutual exclusion.
 
static bool_t VConnBusyTryLock ()
 Try to lock virtual connection's global busy mutual exclusion. More...
 
static void VConnBroadcastNotBusy ()
 Broadcast that a virtual connection has been freed or deleted. More...
 
static void VConnWaitNotBusy ()
 Wait on a virtual connection to become's free.
 
void VConnOneTimeInit ()
 The bsProxy virtual connections one-time initialization.
 
BsProxyVConn_TVConnNew ()
 Create a new, allocated virtual connection entry. More...
 
void VConnDelete (BsProxyVConn_T *pVConn)
 Delete allocated virtual connection entry. More...
 
BsProxyVConn_TVConnGet (BsVConnHnd_T hndVConn)
 Get the virtual connection entry associated with the handle. More...
 
int VConnOpenServer ()
 Open special server virtual connection. More...
 
int VConnOpenDev (BsProxyClientHnd_T hndClient, const char *sDevName, const char *sModName, byte_t argbuf[], size_t uArgLen, bool_t bTrace)
 Open a virtual device connection. More...
 
int VConnClose (BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn)
 Close the virtual connection. More...
 
BsProxyVConn_TVConnAcquire (BsVConnHnd_T hndVConn)
 Acquire virtual connection, locking it from other threads. More...
 
void VConnRelease (BsVConnHnd_T hndVConn)
 Release the locked virtual client. More...
 

Variables

static pthread_mutex_t BsVConnBusyMutex
 operations mutex
 
static pthread_cond_t BsVConnBusyCond
 block condition
 
static BsProxyVConn_TBsVConnTbl [BSPROXY_VCONN_NUMOF] = {NULL, }
 table of virtual connections
 
static uint_t BsVConnActiveCnt
 Number of active v. connections.
 

Detailed Description

Virtual connections management operations.

LastChangedDate
2010-08-20 11:36:38 -0600 (Fri, 20 Aug 2010)
Rev
568
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 bsProxyVConn.c.

Function Documentation

BsProxyVConn_T* VConnAcquire ( BsVConnHnd_T  hndVConn)

Acquire virtual connection, locking it from other threads.

The calling thread is blocked until the virtual connection is availble or has been deleted.

Parameters
hndVConn

Definition at line 552 of file bsProxyVConn.c.

References BSPROXY_CHK_VCONN_HND, BsProxyVConn_T::m_bBusy, VConnLockBusy(), VConnUnlockBusy(), and VConnWaitNotBusy().

Referenced by BsProxyDispatch(), ClientSetTraceState(), ModCbGetDevUri(), ModCbIterNext(), ReqGetVConnInfo(), ReqGetVConnList(), ReqMsgTrace(), ThDevRequest(), and VConnClose().

553 {
554  BsProxyVConn_T *pVConn;
555 
556  if( !BSPROXY_CHK_VCONN_HND(hndVConn) )
557  {
558  return NULL;
559  }
560 
561  VConnLockBusy();
562 
563  while( (BsVConnTbl[hndVConn] != NULL) && BsVConnTbl[hndVConn]->m_bBusy )
564  {
566  }
567 
568  if( (pVConn = BsVConnTbl[hndVConn]) != NULL )
569  {
570  pVConn->m_bBusy = true;
571  }
572 
573  VConnUnlockBusy();
574 
575  return pVConn;
576 }
static void VConnUnlockBusy()
Unlock virtual connection&#39;s global busy mutual exclusion.
Definition: bsProxyVConn.c:101
static BsProxyVConn_T * BsVConnTbl[BSPROXY_VCONN_NUMOF]
table of virtual connections
Definition: bsProxyVConn.c:75
static void VConnWaitNotBusy()
Wait on a virtual connection to become&#39;s free.
Definition: bsProxyVConn.c:146
static void VConnLockBusy()
Lock virtual connection&#39;s global busy mutual exclusion.
Definition: bsProxyVConn.c:87
#define BSPROXY_CHK_VCONN_HND(hndVConn)
Definition: bsProxy.h:428
bool_t m_bBusy
virtual connection is [not] busy
Definition: bsProxy.h:222
static void VConnBroadcastNotBusy ( )
inlinestatic

Broadcast that a virtual connection has been freed or deleted.

A broadcast will unblock all threads currently blocked on the busy condition variable. Only those thread waiting on virtual connections whose condition has changed will run. If multiple threads are waiting on the same virtual connection, then only one is schedule to run.

Definition at line 132 of file bsProxyVConn.c.

References BsVConnBusyCond.

Referenced by VConnDelete(), and VConnRelease().

133 {
134  int rc;
135 
136  if( (rc = pthread_cond_broadcast(&BsVConnBusyCond)) != 0 )
137  {
138  errno = rc;
139  LOGSYSERROR("pthread_cond_broadcast()");
140  }
141 }
static pthread_cond_t BsVConnBusyCond
block condition
Definition: bsProxyVConn.c:74
static bool_t VConnBusyTryLock ( )
inlinestatic

Try to lock virtual connection's global busy mutual exclusion.

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

Definition at line 119 of file bsProxyVConn.c.

References BsVConnBusyMutex.

120 {
121  return pthread_mutex_trylock(&BsVConnBusyMutex) == 0? true: false;
122 }
static pthread_mutex_t BsVConnBusyMutex
operations mutex
Definition: bsProxyVConn.c:73
int VConnClose ( BsProxyClientHnd_T  hndClient,
BsVConnHnd_T  hndVConn 
)

Close the virtual connection.

Closing a virtual connections may close the resource (file) descriptor associated with the device, unload the interface module associated with the device, and terminate the device thread. These actions occur only when the reference counts are zero.

Parameters
hndClient

Definition at line 478 of file bsProxyVConn.c.

References BS_ECODE_BAD_VCONN_HND, BS_ECODE_NO_VCONN, BS_OK, BSPROXY_CHK_MOD_VCONN_HND, BSPROXY_LOG_ERROR, BsVConnActiveCnt, ClientHasName(), BsProxyModIF_T::m_fnModClose, BsProxyVConn_T::m_hndVConn, BsProxyVConn_T::m_pModIF, BsProxyVConn_T::m_pThCtl, ModUnload(), ServerHasName(), ThDestroyThread(), VConnAcquire(), and VConnDelete().

Referenced by BsProxyClientUnregister(), ClientSetTraceState(), and ReqDevClose().

479 {
480  BsProxyVConn_T *pVConn;
481  int rc;
482 
483  // Only virtual connections associated with devices can be closed.
484  if( !BSPROXY_CHK_MOD_VCONN_HND(hndVConn) )
485  {
487  }
488 
489  //
490  // Acquire virtual connection associated with handle. Aquiring a virtual
491  // connections locks out other thread access to the vConnection until it
492  // is released.
493  //
494  else if( (pVConn = VConnAcquire(hndVConn)) == NULL )
495  {
496  rc = -BS_ECODE_NO_VCONN;
497  BSPROXY_LOG_ERROR(hndClient, rc, "VConn=%d", hndVConn);
498  }
499 
500  else
501  {
502  //
503  // Destroy the device thread. The thread reference count is decremented and
504  // only when it drops to zero is the thread actually terminated.
505  //
506  ThDestroyThread(pVConn->m_pThCtl);
507 
508  //
509  // Close the device associated with virtual connection. The actual device
510  // may or may not be closed, depending on the device and module
511  // implementation. For example, for an \h_i2c Bus device, the device is
512  // only closed when the last reference to that device is closed.
513  //
514  pVConn->m_pModIF->m_fnModClose(pVConn->m_hndVConn);
515 
516  //
517  // Dynamically unload the interface module from the bsProxy application. The
518  // module's reference count is decremented and only when it drops to zero is
519  // the module actually unloaded.
520  //
521  ModUnload(pVConn->m_pModIF);
522 
523  LOGDIAG1("%s: %s: Virtual connection %d closed.",
524  ServerHasName(), ClientHasName(hndClient), pVConn->m_hndVConn);
525 
526  //
527  // Delete the virtual connection. The slot is now available for a new
528  // virtual connection.
529  //
530  VConnDelete(pVConn);
531 
532  LOGDIAG2("%s: %u active module virtual connections.",
534 
535  rc = BS_OK;
536  }
537 
538  return rc;
539 }
static uint_t BsVConnActiveCnt
Number of active v. connections.
Definition: bsProxyVConn.c:77
BsProxyThCtl_T * m_pThCtl
service thread
Definition: bsProxy.h:225
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
#define BS_ECODE_BAD_VCONN_HND
bad virtual connection handle
Definition: BotSense.h:79
BsModCloseFunc_P m_fnModClose
device close
Definition: bsProxy.h:128
void ThDestroyThread(BsProxyThCtl_T *pThCtl)
Destroy service thread.
#define BSPROXY_LOG_ERROR(hndClient, ecode, efmt,...)
Log Proxy Server Error.
Definition: bsProxy.h:288
BsProxyVConn_T * VConnAcquire(BsVConnHnd_T hndVConn)
Acquire virtual connection, locking it from other threads.
Definition: bsProxyVConn.c:552
BsVConnHnd_T m_hndVConn
self reference
Definition: bsProxy.h:223
void VConnDelete(BsProxyVConn_T *pVConn)
Delete allocated virtual connection entry.
Definition: bsProxyVConn.c:220
#define BSPROXY_CHK_MOD_VCONN_HND(hndVConn)
Definition: bsProxy.h:441
#define BS_ECODE_NO_VCONN
virtual connection not found
Definition: BotSense.h:80
INLINE_IN_H const char * ClientHasName(BsProxyClientHnd_T hndClient)
Get the <b><i>BotSense</i></b> client official name.
Definition: bsProxy.h:588
BsProxyModIF_T * m_pModIF
interface module I/F
Definition: bsProxy.h:226
void ModUnload(BsProxyModIF_T *pModIF)
Unload the interface module.
Definition: bsProxyMod.c:1191
void VConnDelete ( BsProxyVConn_T pVConn)

Delete allocated virtual connection entry.

The deletion event is broadcasted to all blocked threads waiting on this connection.

Definition at line 220 of file bsProxyVConn.c.

References BSPROXY_CHK_VCONN_HND, BsVConnActiveCnt, BsProxyVConn_T::m_hndVConn, VConnBroadcastNotBusy(), VConnLockBusy(), and VConnUnlockBusy().

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

221 {
222  VConnLockBusy();
223 
224  if( pVConn != NULL )
225  {
226  if( BSPROXY_CHK_VCONN_HND(pVConn->m_hndVConn) )
227  {
228  BsVConnTbl[pVConn->m_hndVConn] = NULL;
230  }
231  delete(pVConn);
232  }
233 
235 
236  VConnUnlockBusy();
237 }
static uint_t BsVConnActiveCnt
Number of active v. connections.
Definition: bsProxyVConn.c:77
static void VConnUnlockBusy()
Unlock virtual connection&#39;s global busy mutual exclusion.
Definition: bsProxyVConn.c:101
static BsProxyVConn_T * BsVConnTbl[BSPROXY_VCONN_NUMOF]
table of virtual connections
Definition: bsProxyVConn.c:75
static void VConnBroadcastNotBusy()
Broadcast that a virtual connection has been freed or deleted.
Definition: bsProxyVConn.c:132
static void VConnLockBusy()
Lock virtual connection&#39;s global busy mutual exclusion.
Definition: bsProxyVConn.c:87
#define BSPROXY_CHK_VCONN_HND(hndVConn)
Definition: bsProxy.h:428
BsVConnHnd_T m_hndVConn
self reference
Definition: bsProxy.h:223
BsProxyVConn_T* VConnGet ( BsVConnHnd_T  hndVConn)

Get the virtual connection entry associated with the handle.

Warning
The virtual connection is not locked.
Parameters
hndVConn

Definition at line 248 of file bsProxyVConn.c.

References BSPROXY_CHK_VCONN_HND.

Referenced by BsProxyClientUnregister(), ClientSetTraceState(), ModCbSendErrorRsp(), ModCbSendOkRsp(), and ModCbSendRsp().

249 {
250  if( !BSPROXY_CHK_VCONN_HND(hndVConn) )
251  {
252  return NULL;
253  }
254  else
255  {
256  return BsVConnTbl[hndVConn];
257  }
258 }
static BsProxyVConn_T * BsVConnTbl[BSPROXY_VCONN_NUMOF]
table of virtual connections
Definition: bsProxyVConn.c:75
#define BSPROXY_CHK_VCONN_HND(hndVConn)
Definition: bsProxy.h:428
BsProxyVConn_T* VConnNew ( )

Create a new, allocated virtual connection entry.

The new virtual connection is added to the virtual connection table. It is marked busy (i.e. locked). The caller must call VConnRelease() or VConnDelete() to free the entry.

Returns
Allocated virtual connection on success, NULL on failure.

Definition at line 183 of file bsProxyVConn.c.

References BSPROXY_VCONN_MOD_NUMOF, BSPROXY_VCONN_NUMOF, BsVConnActiveCnt, BsProxyVConn_T::m_bBusy, BsProxyVConn_T::m_hndVConn, VConnLockBusy(), and VConnUnlockBusy().

Referenced by ClientSetTraceState(), and VConnOpenDev().

184 {
185  BsProxyVConn_T *pVConn = NULL;
186  BsVConnHnd_T hndVConn;
187 
188  // lock virtual connection table
189  VConnLockBusy();
190 
191  // find an empty virtual connection table slot
193  {
194  for(hndVConn=0; hndVConn<BSPROXY_VCONN_MOD_NUMOF; ++hndVConn)
195  {
196  if( BsVConnTbl[hndVConn] == NULL )
197  {
198  pVConn = NEW(BsProxyVConn_T);
199  pVConn->m_bBusy = true;
200  pVConn->m_hndVConn = hndVConn;
201  BsVConnTbl[hndVConn] = pVConn;
203  break;
204  }
205  }
206  }
207 
208  // unlock virtual connection table
209  VConnUnlockBusy();
210 
211  return pVConn;
212 }
static uint_t BsVConnActiveCnt
Number of active v. connections.
Definition: bsProxyVConn.c:77
static void VConnUnlockBusy()
Unlock virtual connection&#39;s global busy mutual exclusion.
Definition: bsProxyVConn.c:101
static BsProxyVConn_T * BsVConnTbl[BSPROXY_VCONN_NUMOF]
table of virtual connections
Definition: bsProxyVConn.c:75
#define BSPROXY_VCONN_NUMOF
total number of module handles
Definition: BotSense.h:144
static void VConnLockBusy()
Lock virtual connection&#39;s global busy mutual exclusion.
Definition: bsProxyVConn.c:87
BsVConnHnd_T m_hndVConn
self reference
Definition: bsProxy.h:223
bool_t m_bBusy
virtual connection is [not] busy
Definition: bsProxy.h:222
#define BSPROXY_VCONN_MOD_NUMOF
number of module-specific handles
Definition: BotSense.h:143
int BsVConnHnd_T
virtual connection handle type
Definition: BotSense.h:151
int VConnOpenDev ( BsProxyClientHnd_T  hndClient,
const char *  sDevName,
const char *  sModName,
byte_t  argbuf[],
size_t  uArgLen,
bool_t  bTrace 
)

Open a virtual device connection.

To open a virtual connection:

  • A new entry is created.
  • The associated device thread is located or created.
  • The associated interface module is located or loaded.
  • The module's exported ModOpen() routine is called.
Parameters
hndClient

Definition at line 325 of file bsProxyVConn.c.

References BS_ECODE_BAD_VAL, BS_ECODE_NO_EXEC, BS_ECODE_NO_MOD, BS_ECODE_NO_RSRC, BSPROXY_LOG_ERROR, BsVConnActiveCnt, ClientHasName(), BsProxyModIF_T::m_fnModOpen, BsProxyVConn_T::m_hndClient, BsProxyVConn_T::m_hndVConn, BsProxyVConn_T::m_pModIF, BsProxyVConn_T::m_pThCtl, BsProxyVConn_T::m_rd, BsProxyModIF_T::m_sModUri, ModLoad(), ModNewModUri(), ModUnload(), ServerHasName(), ThCreateDevThread(), ThDestroyThread(), ThNewDevUri(), VConnDelete(), VConnNew(), and VConnRelease().

Referenced by ClientSetTraceState(), and ReqDevOpen().

331 {
332  BsProxyVConn_T *pVConn = NULL; // new virtual connection entry
333  char *sModUri = NULL; // module URI
334  char *sDevUri = NULL; // device URI
335  BsProxyModIF_T *pModIF = NULL; // interface module interface
336  BsProxyThCtl_T *pThCtl = NULL; // device thread control block
337  int rc; // return code
338  int rd; // resource descriptor
339 
340  //
341  // Allocate a new virtual connection. If no more virtual connections are
342  // available, NULL is returned. The return virtual connection is left in
343  // the acquired state which requires releasing prior to becoming available
344  // for normal operations.
345  //
346  if( (pVConn = VConnNew()) == NULL )
347  {
348  rc = -BS_ECODE_NO_RSRC;
349  BSPROXY_LOG_ERROR(hndClient, rc,
350  "No more virtual connections are available.");
351  }
352 
353  //
354  // Convert module path name to canonical uniform resource identifier.
355  //
356  else if( (sModUri = ModNewModUri(sModName)) == NULL )
357  {
358  rc = -BS_ECODE_BAD_VAL;
359  BSPROXY_LOG_ERROR(hndClient, rc, "\"%s\": Bad module name.", sModName);
360  }
361 
362  //
363  // Convert device path name to canonical uniform resource identifier.
364  //
365  else if( (sDevUri = ThNewDevUri(sDevName)) == NULL )
366  {
367  rc = -BS_ECODE_BAD_VAL;
368  BSPROXY_LOG_ERROR(hndClient, rc, "\"%s\": Bad device name.", sDevName);
369  }
370 
371  //
372  // Dynamically load and initialize library interface module and return the
373  // module's interface. If the module already exists, then the same interface
374  // is returned. The module interface maintains a reference count which is
375  // incremented.
376  //
377  else if( (pModIF = ModLoad(sModUri)) == NULL )
378  {
379  rc = -BS_ECODE_NO_MOD;
380  BSPROXY_LOG_ERROR(hndClient, rc,
381  "Could not load or attach to \"%s\" interface module.", sModUri);
382  }
383 
384  //
385  // Call the interface module's open() function to open the device and allocate
386  // any internal resources. The return resource descriptor is typically a
387  // file or socket descript, but may be any unique non-negative integer
388  // defined by the module.
389  //
390  else if( (rd = pModIF->m_fnModOpen(pVConn->m_hndVConn, bTrace,
391  sDevUri, argbuf, uArgLen)) < 0 )
392  {
393  rc = -BS_ECODE_NO_EXEC;
394  BSPROXY_LOG_ERROR(hndClient, rd,
395  "Could not open \"%s\" interface module.", pModIF->m_sModUri);
396  }
397 
398  //
399  // Create a device thread returning the thread's control. If the thread
400  // already exists, then the same thread control is returned. The thread
401  // control maintains a reference count which is incremented.
402  //
403  else if( (pThCtl = ThCreateDevThread(sDevUri)) == NULL )
404  {
405  rc = -BS_ECODE_NO_EXEC;
406  BSPROXY_LOG_ERROR(hndClient, rc,
407  "Could not create or attach to \"%s\" device service thread.",
408  sDevUri);
409  }
410 
411  //
412  // Success.
413  //
414  // Populate the virtual connection's data. All allocated data are not owned by
415  // the virtual connection. That is, any allocated data will not be deleted
416  // when the virtual connection is deleted.
417  //
418  else
419  {
420  pVConn->m_hndClient = hndClient;
421  pVConn->m_pThCtl = pThCtl;
422  pVConn->m_pModIF = pModIF;
423  pVConn->m_rd = rd;
424 
425  VConnRelease(pVConn->m_hndVConn);
426 
427  rc = (int)pVConn->m_hndVConn;
428 
429  LOGDIAG1("%s: %s: Virtual connection %d opened: %s('%s',rd=%d).",
430  ServerHasName(), ClientHasName(hndClient), pVConn->m_hndVConn,
431  sModUri, sDevUri, rd);
432 
433  LOGDIAG2("%s: %u active module virtual connections.",
435  }
436 
437  //
438  // Error occurred, so clean up before returning.
439  //
440  if( rc < 0 )
441  {
442  if( pThCtl != NULL )
443  {
444  ThDestroyThread(pThCtl);
445  }
446  if( pModIF != NULL )
447  {
448  ModUnload(pModIF);
449  }
450  if( pVConn != NULL )
451  {
452  VConnDelete(pVConn);
453  }
454  }
455 
456  //
457  // Fixed clean up.
458  //
459  delete(sModUri);
460  delete(sDevUri);
461 
462  return rc;
463 }
static uint_t BsVConnActiveCnt
Number of active v. connections.
Definition: bsProxyVConn.c:77
BsProxyVConn_T * VConnNew()
Create a new, allocated virtual connection entry.
Definition: bsProxyVConn.c:183
#define BS_ECODE_BAD_VAL
bad value
Definition: BotSense.h:77
int m_rd
module resource descriptor
Definition: bsProxy.h:227
char * ThNewDevUri(const char *sDevName)
Convert the device name to a quasi Uniform Resource Id.
BsProxyThCtl_T * ThCreateDevThread(const char *sDevUri)
Create a device service thread.
BsProxyThCtl_T * m_pThCtl
service thread
Definition: bsProxy.h:225
void VConnRelease(BsVConnHnd_T hndVConn)
Release the locked virtual client.
Definition: bsProxyVConn.c:585
INLINE_IN_H const char * ServerHasName()
Get the <b><i>BotSense</i></b> server&#39;s official name.
Definition: bsProxy.h:485
char * ModNewModUri(const char *sModName)
Convert the module name to a quasi Uniform Resource Id.
Definition: bsProxyMod.c:1042
#define BS_ECODE_NO_EXEC
cannot execute
Definition: BotSense.h:88
void ThDestroyThread(BsProxyThCtl_T *pThCtl)
Destroy service thread.
BsProxyClientHnd_T m_hndClient
proxied client handle
Definition: bsProxy.h:224
BsProxyModIF_T * ModLoad(const char *sModUri)
Load the interface module.
Definition: bsProxyMod.c:1089
#define BS_ECODE_NO_RSRC
no resource available
Definition: BotSense.h:85
#define BSPROXY_LOG_ERROR(hndClient, ecode, efmt,...)
Log Proxy Server Error.
Definition: bsProxy.h:288
#define BS_ECODE_NO_MOD
no interface module
Definition: BotSense.h:83
const char * m_sModUri
module Uniform Resource Id
Definition: bsProxy.h:122
BsVConnHnd_T m_hndVConn
self reference
Definition: bsProxy.h:223
void VConnDelete(BsProxyVConn_T *pVConn)
Delete allocated virtual connection entry.
Definition: bsProxyVConn.c:220
BsModOpenFunc_P m_fnModOpen
device open
Definition: bsProxy.h:127
INLINE_IN_H const char * ClientHasName(BsProxyClientHnd_T hndClient)
Get the <b><i>BotSense</i></b> client official name.
Definition: bsProxy.h:588
BsProxyModIF_T * m_pModIF
interface module I/F
Definition: bsProxy.h:226
void ModUnload(BsProxyModIF_T *pModIF)
Unload the interface module.
Definition: bsProxyMod.c:1191
int VConnOpenServer ( )

Open special server virtual connection.

Returns
On success, BS_OK is returned.
On error, the appropriate < 0 negated BotSense Error Code is returned.

Definition at line 265 of file bsProxyVConn.c.

References BS_ECODE_NO_EXEC, BS_OK, BSPROXY_VCONN_SERVER, BsVConnActiveCnt, BsProxyVConn_T::m_bBusy, BsProxyVConn_T::m_hndClient, BsProxyVConn_T::m_hndVConn, BsProxyVConn_T::m_pModIF, BsProxyVConn_T::m_pThCtl, BsProxyVConn_T::m_rd, ServerHasName(), and ThCreateServerThread().

Referenced by ClientSetTraceState(), and main().

266 {
267  BsProxyThCtl_T *pThCtl; // server service thread control
268  BsProxyVConn_T *pVConn; // new virtual connection entry
269  BsVConnHnd_T hndVConn = BSPROXY_VCONN_SERVER; // reserved server handle
270  int rc; // return code
271 
272  //
273  // Create the one server thread.
274  //
275  if( (pThCtl = ThCreateServerThread()) == NULL )
276  {
277  rc = -BS_ECODE_NO_EXEC;
278  LOGERROR("%s: Could not create server service thread.", ServerHasName());
279  }
280 
281  //
282  // Add this special virtual connection to the table. No mutual exclusion is
283  // done since the server should be started prior to servicing an client
284  // requests.
285  //
286  else
287  {
288  pVConn = NEW(BsProxyVConn_T);
289  pVConn->m_bBusy = false;
290  pVConn->m_hndClient = -1;
291  pVConn->m_hndVConn = hndVConn;
292  pVConn->m_pThCtl = pThCtl;
293  pVConn->m_pModIF = NULL;
294  pVConn->m_rd = -1;
295 
296  BsVConnTbl[hndVConn] = pVConn;
298 
299  rc = BS_OK;
300  }
301 
302  return rc;
303 }
static uint_t BsVConnActiveCnt
Number of active v. connections.
Definition: bsProxyVConn.c:77
int m_rd
module resource descriptor
Definition: bsProxy.h:227
BsProxyThCtl_T * ThCreateServerThread()
Create the special server service thread.
static BsProxyVConn_T * BsVConnTbl[BSPROXY_VCONN_NUMOF]
table of virtual connections
Definition: bsProxyVConn.c:75
#define BSPROXY_VCONN_SERVER
handle for server-terminated msgs
Definition: BotSense.h:140
BsProxyThCtl_T * m_pThCtl
service thread
Definition: bsProxy.h:225
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
#define BS_ECODE_NO_EXEC
cannot execute
Definition: BotSense.h:88
BsProxyClientHnd_T m_hndClient
proxied client handle
Definition: bsProxy.h:224
BsVConnHnd_T m_hndVConn
self reference
Definition: bsProxy.h:223
bool_t m_bBusy
virtual connection is [not] busy
Definition: bsProxy.h:222
BsProxyModIF_T * m_pModIF
interface module I/F
Definition: bsProxy.h:226
int BsVConnHnd_T
virtual connection handle type
Definition: BotSense.h:151
void VConnRelease ( BsVConnHnd_T  hndVConn)

Release the locked virtual client.

A broadcast is sent to all blocking threads on the freed event.

Parameters
hndVConn

Definition at line 585 of file bsProxyVConn.c.

References BSPROXY_CHK_VCONN_HND, BsProxyVConn_T::m_bBusy, VConnBroadcastNotBusy(), VConnLockBusy(), and VConnUnlockBusy().

Referenced by BsProxyDispatch(), ClientSetTraceState(), ModCbGetDevUri(), ModCbIterNext(), ReqGetVConnInfo(), ReqGetVConnList(), ReqMsgTrace(), ThDevRequest(), and VConnOpenDev().

586 {
587  if( !BSPROXY_CHK_VCONN_HND(hndVConn) )
588  {
589  return;
590  }
591 
592  VConnLockBusy();
593 
594  if( BsVConnTbl[hndVConn] != NULL )
595  {
596  BsVConnTbl[hndVConn]->m_bBusy = false;
597  }
598 
600 
601  VConnUnlockBusy();
602 }
static void VConnUnlockBusy()
Unlock virtual connection&#39;s global busy mutual exclusion.
Definition: bsProxyVConn.c:101
static BsProxyVConn_T * BsVConnTbl[BSPROXY_VCONN_NUMOF]
table of virtual connections
Definition: bsProxyVConn.c:75
static void VConnBroadcastNotBusy()
Broadcast that a virtual connection has been freed or deleted.
Definition: bsProxyVConn.c:132
static void VConnLockBusy()
Lock virtual connection&#39;s global busy mutual exclusion.
Definition: bsProxyVConn.c:87
#define BSPROXY_CHK_VCONN_HND(hndVConn)
Definition: bsProxy.h:428
bool_t m_bBusy
virtual connection is [not] busy
Definition: bsProxy.h:222