59 import BotSenseCore
as bsCore
60 import BotSenseError
as bsError
64 """ Size of BotSense object in bytes. Size is contextual by object type. """ 65 return bsObj.__sizeof__()
73 """ BotSense Client Wrapper Class. 75 The BsClient class provides a safe wrapper around the BsClient_T * 82 Create and initialize BotSense client instance. 85 clientName - Proxied client name string. 90 pClient = bsCore.bsClientNew(clientName)
92 raise bsError.BotSenseError(BS_ECODE_NO_RSRC,
"Failed to create client.")
99 """ Delete BotSense client instance. """ 101 bsCore.bsClientDelete(self.
pClient)
107 """ x.__sizeof__() -- size of swig object, in bytes. """ 116 """ Get the client's name. 119 On success, returns client string name. 120 On parameter check failure, a BotSenseError exception is raised. 123 clientName = bsCore.bsClientAttrGetName(self.
pClient)
125 clientName =
'unknown' 131 """ Get a client's virtual connection trace state. 134 hndVConn - Virtual connection handle. 137 On success, returns True (enabled) or False (disabled). 138 On parameter check failure, a BotSenseError exception is raised. 141 state = bsCore.bsClientAttrGetTraceState(self.
pClient, hndVConn)
150 """ Get a client's virtual connection trace state. 153 On success, returns client's virtual connection count. 154 On parameter check failure, a BotSenseError exception is raised. 157 cnt = bsCore.bsClientAttrGetVConnCount(self.
pClient)
163 """ Check if the client has a virtual connection associated with the 167 hndVConn - Virtual connection handle. 170 On success, returns True or False. 171 On parameter check failure, a BotSenseError exception is raised. 174 tf = bsCore.bsClientAttrHasVConn(self.
pClient, hndVConn)
183 """ Get the proxied device name associated with the given handle. 186 hndVConn - Virtual connection handle. 189 On success, returns the device URI string. If no device is found, 190 then '#nodev#' is returned. 191 On parameter check failure, a BotSenseError exception is raised. 194 devName = bsCore.bsClientAttrGetDevName(self.
pClient, hndVConn)
202 """ Get the proxied interface module name associated with the given 206 hndVConn - Virtual connection handle. 209 On success, returns the I/F module URI string. If no module is 210 found, then '#nomod#' is returned. 211 On parameter check failure, a BotSenseError exception is raised. 214 modName = bsCore.bsClientAttrGetModName(self.
pClient, hndVConn)
222 """ Set the client's diagnostic logging threshold. 225 nLevel - New logging threshold level. 228 bsCore.bsClientAttrSetLogging(self.
pClient, nLevel)
233 """ Get the client's connection state. 236 Dictionary specifying connection state. 239 connstate = bsCore.BsClientConnState_T()
240 bsCore.bsClientAttrGetConnState(self.
pClient, connstate)
242 if connstate.m_bIsConnected:
243 d[
'is_connected'] =
True 245 d[
'is_connected'] =
False 246 d[
'server_hostname'] = connstate.m_sServerHostName
252 """ Get the client's request and response timeouts in seconds. 255 reqTimeout = bsCore.new_uintp();
256 rspTimeout = bsCore.new_uintp();
257 bsCore.bsClientAttrGetTimeouts(self.
pClient, reqTimeout, rspTimeout)
258 ret = (bsCore.uintp_value(reqTimeout), bsCore.uintp_value(rspTimeout))
259 bsCore.delete_uintp(reqTimeout);
260 bsCore.delete_uintp(rspTimeout);
266 """ Set the client's request and response timeouts in seconds. 269 reqTimeout - Request (write) timeout. 270 rspTimeout - Response (read) timeout. 273 bsCore.bsClientAttrSetTimeouts(self.
pClient, reqTimeout, rspTimeout)
278 """ Get the message name string. 280 For each (virtual connection, message id) 2-tuple, the message 281 name can be determinied (provided the msgid is valid and an 282 application provides the information). 285 hndVConn - Virtual connection handle. 289 On success, returns the message name string. If the name cannot 290 be determined, then 'unknown' is returned. 291 On parameter check failure, a BotSenseError exception is raised. 294 return bsCore.bsClientGetMsgName(self.
pClient, hndVConn, msgId)
298 def Trans(self, hndVConn, reqMsgId, reqBuf, rspMsgId,
299 rspMaxSize=bsCore.BSPROXY_MSG_BODY_MAX):
300 """ Execute a request - response transaction with the server. 302 The request message header is automatically generated. The response 303 message header is stripped off from the received response. 305 Raises a BotSenseError exception on failure. 308 hndVConn - Virtual connection handle. 309 reqMsgId - Virtual connection unique request message id. 310 reqBuf - Packed request message body. 311 rspMsgId - Virtual connection expected response message id. 312 rspMaxSize - Maximum expected response body size. 315 Packed response message body buffer. 318 reqByteBuf = ByteBuf.Clone(reqBuf)
320 reqByteBuf.copyToSwigObj(len(reqByteBuf), i=0, j=bsCore.BSPROXY_MSG_HDR_LEN)
321 rspByteBuf =
ByteBuf(rspMaxSize)
322 n = bsCore.bsClientTrans(self.
pClient, hndVConn,
323 reqMsgId, reqByteBuf.getSwigObj(), len(reqByteBuf),
324 rspMsgId, rspByteBuf.getSwigObj(),
sizeof(rspByteBuf))
325 bsError.ChkReturnIsNonNeg(n,
326 "Client %s: Transaction request failed." % (self.
AttrGetName()))
327 rspByteBuf.copyFromSwigObj(n)
328 return rspByteBuf.buf
333 """ Check that the opaque 'real' client exists. """ 335 raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL,
"No client.")
341 """ Static check if object is a valid BsClient object. 344 obj - Object instance. 346 bsError.ChkType(obj, BsClient)
356 """ BotSense Byte Buffer Class. 358 The ByteBuf class provides a wrapper around the byte_t* SWIG object. 359 The byte_t is typedef'ed in C as an unsigned char. Byte buffers are used 360 in packing and unpacking messages and in communication between the 363 Note: There does not seem to be any way to advance the pointer of the 364 underlining byte_t* SWIG object, so a copy from/to a python byte 365 list (buffer) is required. 369 def __init__(self, size=bsCore.BSPROXY_MSG_BODY_MAX):
370 """ Initialize byte buffer instance. 373 size - Number of bytes of the underlining fixed sized SWIG 377 size += bsCore.BSPROXY_MSG_HDR_LEN
380 self.
_swigObj = bsCore.new_byteArray(size)
391 """ Delete byte buffer instance. """ 392 bsCore.delete_byteArray(self.
_swigObj)
398 """ Conversion constructor. 401 seq - Sequence of values to convert. Sequence type can be an 402 integer [0,255], a string, or a list of elements of 403 type integer, string, list. 406 New initialized ByteBuf(). 408 buf = ByteBuf.bytestring(seq)
409 bytebuf =
ByteBuf(size=len(buf))
416 """ Smart clone constructor. 418 If buf is a ByteBuf instance, then simply return buf. 419 Otherwise convert buf to a ByteBuf instance. 421 The underlining swig object contents are not touched, so swig copies 422 will need to be done prior to or after calling a byte_t* core routine. 425 buf - Either a ByteBuf instance or a sequence of values to convert. 426 Sequence type can be an integer [0,255], a string, or a list 427 of elements of type integer, string, list. 430 Existing or new ByteBuf(). 432 if isinstance(buf, ByteBuf):
435 return ByteBuf.Constructor(buf)
440 """ x.__getitem__(i) <==> x[i] """ 441 return self.buf.__getitem__(i)
446 """ x.__getslice__(i, j) <==> x[i:j] """ 447 return self.buf.__getslice__(i, j)
452 """ x.__iadd__(y) <==> x+=y """ 453 z = ByteBuf.bytestring(y)
460 """ x.__imul__(y) <==> x*=y """ 467 """ x.__iter__() <==> iter(x) """ 468 return self.buf.__iter__()
473 """ x.__len__() <==> len(x) 475 Number of bytes used in buffer. 482 """ x.__str__() <==> str(x) <==> print x """ 483 return self.buf.__str__()
488 """ x.__setitem__(i, y) <==> x[i]=y """ 490 self.buf.__setitem__(i, z)
496 """ x.__setslice__(i, j, y) <==> x[i:j]=y """ 497 z = ByteBuf.bytestring(y)
498 self.buf.__setslice__(i, j, z)
504 """ x.__sizeof__() -- size of swig object byte buffer, in bytes. """ 510 """ Available bytes in fixed swig object buffer. """ 516 """ Copy swig object buffer to python buffer. 519 n - Number of bytes to copy. 520 i - Starting source index in swig object buffer. 521 j - Starting destination index in python buffer. 524 raise bsError.BotSenseError(bsCore.BS_ECODE_BUF_TOO_SMALL,
525 "copyFromSwigObj: swig object buffer size=%d < %d bytes" % \
529 self.
buf += chr(0) * (j + n - l)
532 s += chr(bsCore.byteArray_getitem(self.
_swigObj, i+k))
533 self.
buf = self.
buf[:j] + s
538 """ Copy python buffer to instance swig object buffer. 541 n - Number of bytes to copy. 542 i - Starting source index in python buffer. 543 j - Starting destination index in swig object buffer. 545 if i+n > len(self.
buf):
546 raise bsError.BotSenseError(bsCore.BS_ECODE_BUF_TOO_SMALL,
547 "copyToSwigObj: python buffer size=%d < %d bytes" % \
548 (len(self.
buf), i+n))
549 elif j+n > self.
_size:
550 raise bsError.BotSenseError(bsCore.BS_ECODE_BUF_TOO_SMALL,
551 "copyToSwigObj: swig object buffer size=%d < %d bytes" % \
554 bsCore.byteArray_setitem(self.
_swigObj, j+k, ord(self.
buf[i+k]))
559 """ Return raw swig object. """ 565 """ Return python buffer. """ 571 """ Size of fixed swig object byte buffer, in bytes. """ 578 """ Static method to convert a value into a byte. 581 val - Value to convert. Value type can be an integer [0,255], 582 a string of length 1, or a list of length 1 of element 583 type of integer, string, list. 586 On success, returns converted byte value. 587 On failure, a BotSenseError exception is raised. 591 raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL,
"%s" % str(val))
594 elif type(val) == str:
596 raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL,
"%s" % str(val))
599 elif type(val) == list:
601 raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL,
"%s" % str(val))
603 return ByteBuf.byte(val[0])
605 raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL,
"%s" % str(val))
611 """ Static method to convert a value sequence into a byte list. 614 seq - Sequence of values to convert. Sequence type can be an 615 integer [0,255], a string, or a list of elements of 616 type integer, string, list. 619 On success, returns converted byte value list. 620 On failure, a BotSenseError exception is raised. 624 elif type(seq) == int:
625 outbuf = [ ByteBuf.byte(seq) ]
627 elif type(seq) == str
or type(seq) == list:
630 outbuf += [ ByteBuf.byte(val) ]
633 raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL,
"%s" % str(val))
639 """ Static method to convert a value into a byte character string. 642 val - Value to convert. Value type can be an integer [0,255], 643 a string of length 1, or a list of length 1 of element 644 type of integer, string, list. 647 On success, returns converted byte value. 648 On failure, a BotSenseError exception is raised. 652 raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL,
"%s" % str(val))
655 elif type(val) == str:
657 raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL,
"%s" % str(val))
660 elif type(val) == list:
662 raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL,
"%s" % str(val))
664 return ByteBuf.bytec(val[0])
666 raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL,
"%s" % str(val))
672 """ Static method to convert a value sequence into a byte string. 675 seq - Sequence of values to convert. Sequence type can be an 676 integer [0,255], a string, or a list of elements of 677 type integer, string, list. 680 On success, returns converted byte value list. 681 On failure, a BotSenseError exception is raised. 685 elif type(seq) == int:
686 return ByteBuf.bytec(seq)
687 elif type(seq) == str
or type(seq) == list:
690 outbuf += ByteBuf.bytec(val)
693 raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL,
"%s" % str(val))
702 """ BotSense bsProxy Message Header Wrapper Class. """ 705 def __init__(self, tid=0, vconn=bsCore.BSPROXY_VCONN_SERVER, msgid=0,
707 """ Initialize BotSense Proxy Message Header instance. 710 tid - Transaction id. 711 vconn - Virtual connection handle. 713 bodylen - Message body length, in bytes. 715 bsCore.BsProxyMsgHdr_T.__init__(self)
728 self.
_attrlist = [
'm_hdrMagic',
'm_hdrTid',
'm_hdrVConn',
'm_hdrMsgId',
734 """ x.__sizeof__() -- size of header, in bytes. """ 735 return bsCore.BSPROXY_MSG_HDR_LEN
740 """ x.__getitem__(y) <==> x[y] """ 741 return getattr(self, y)
746 """ x.__setitem__(y, v) <==> x[y]=v """ 750 raise AttributeError(y)
755 """ x.__iter__() <==> iter(x) """ 756 return self._attrlist.__iter__()
761 """ x.__str__() <==> str(x) <==> print x """ 764 d[attr] = getattr(self, attr)
770 """ Return list of class variable attribute names. """ 776 """ Pack BotSense bsProxy message header 778 Raises a BotSenseError exception on failure. 781 buf [out] - BotSenseTypes.ByteBuf output buffer instance. 784 On success, returns the number of bytes packed. 785 On failure, a BotSenseError exception is raised. 787 bsError.ChkType(buf, ByteBuf)
788 n = bsCore.bsPackMsgHdr(self, buf.getSwigObj(), buf.sizeof())
789 bsError.ChkReturnIsNonNeg(n,
"Failed to pack message header.")
790 buf.copyFromSwigObj(n)
796 """ Unpack BotSense bsProxy message header 798 Raises a BotSenseError exception on failure. 801 buf [in] - BotSenseTypes.ByteBuf input buffer instance. 804 On success, returns the number of bytes unpacked. 805 On failure, a BotSenseError exception is raised. 807 bsError.ChkType(buf, ByteBuf)
808 buf.copyToSwigObj(bsCore.BSPROXY_MSG_HDR_LEN)
809 n = bsCore.bsUnpackMsgHdr(buf.getSwigObj(), len(buf), self)
810 bsError.ChkReturnIsNonNeg(n,
"Failed to unpack message header.")
820 """ BotSense Virtual Connection Information Wrapper Class. 825 """ Initialize Virtual Connection Info instance. """ 826 bsCore.BsVConnInfo_T.__init__(self)
828 self.
_attrlist = [
'm_vconn',
'm_rd',
'm_client',
'm_devuri',
'm_moduri',
829 'm_modver',
'm_moddate']
834 """ x.__sizeof__() -- size of swig object, in bytes. """ 835 return 5 + len(self.m_client) + len(self.m_devuri) + len(self.m_moduri) + \
836 len(self.m_modver) + len(self.m_moddate)
841 """ x.__getitem__(y) <==> x[y] """ 842 return getattr(self, y)
847 """ x.__setitem__(y, v) <==> x[y]=v """ 851 raise AttributeError(y)
856 """ x.__iter__() <==> iter(x) """ 857 return self._attrlist.__iter__()
862 """ x.__str__() <==> str(x) <==> print x """ 865 d[attr] = getattr(self, attr)
871 """ Return list of class variable attribute names. """ 881 """ BotSense Client Application Info and Callback Wrapper Class. 883 When an application (library) establishes an application-specific 884 virtual connection, this static information and callbacks are passed 885 to the BotSense client library. 887 The information and callbacks are optional. The BotSense library will 888 ignore any member value that is set to None or if the class instance 889 is None (everything is ignored). 894 """ Initialize BotSense Proxy Message Header instance. """ 895 bsCore.BsClientAppInfo_T.__init__(self)
897 self.
_attrlist = [
'app_name',
'brief',
'version',
'date',
'maintainer',
898 'license',
'fnGetMsgName']
903 """ x.__sizeof__() -- size of swig object, in bytes. """ 909 """ x.__getitem__(y) <==> x[y] """ 910 return getattr(self, y)
915 """ x.__setitem__(y, v) <==> x[y]=v """ 919 raise AttributeError(y)
924 """ x.__iter__() <==> iter(x) """ 925 return self._attrlist.__iter__()
930 """ x.__str__() <==> str(x) <==> print x """ 933 d[attr] = getattr(self, attr)
939 """ Return list of class variable attribute names. """ pClient
Pointer to opaque object.
def AttrGetVConnCount(self)
def copyFromSwigObj(self, n, i=0, j=0)
def AttrHasVConn(self, hndVConn)
def __init__(self, size=bsCore.BSPROXY_MSG_BODY_MAX)
def AttrGetDevName(self, hndVConn)
def __getslice__(self, i, j)
m_hdrVConn
message header virtual connection handle
def AttrSetTimeouts(self, reqTimeout, rspTimeout)
def __setitem__(self, y, v)
def PackMsgHdr(self, buf)
m_hdrMagic
message header fixed magic number
def AttrSetLogging(self, nLevel)
def __setitem__(self, i, y)
def __setslice__(self, i, j, y)
def copyToSwigObj(self, n, i=0, j=0)
def AttrGetTimeouts(self)
def Trans(self, hndVConn, reqMsgId, reqBuf, rspMsgId, rspMaxSize=bsCore.BSPROXY_MSG_BODY_MAX)
def UnpackMsgHdr(self, buf)
_attrlist
class attributes
def __init__(self, tid=0, vconn=bsCore.BSPROXY_VCONN_SERVER, msgid=0, bodylen=0)
def AttrGetTraceState(self, hndVConn)
def AttrGetModName(self, hndVConn)
def __setitem__(self, y, v)
def GetMsgName(self, hndVConn, msgId)
def __setitem__(self, y, v)
def __init__(self, clientName='bsclient')
m_hdrBodyLen
message header body length
_size
internal swig object fixed buffer size
m_hdrMsgId
message header message id
def AttrGetConnState(self)
m_hdrTid
message header transaction id
_swigObj
internal swig object