botsense  3.2.0
RoadNarrows Client-Server Proxied Services Framework
BotSenseTypes.py
Go to the documentation of this file.
1 ###############################################################################
2 #
3 # Package: BotSense
4 #
5 # File: BotSenseTypes.py
6 #
7 
8 """
9 BotSense Type Classes.
10 """
11 
12 ## \file
13 ## \package BotSense.BotSenseTypes
14 ##
15 ## $LastChangedDate: 2012-12-11 14:28:19 -0700 (Tue, 11 Dec 2012) $
16 ## $Rev: 2573 $
17 ##
18 ## \brief BotSense Types
19 ##
20 ## \sa
21 ## \htmlonly
22 ## <a href="../pydoc/BotSense.BotSenseError.html">PyDoc Generated Documentation</a>
23 ## \endhtmlonly
24 ##
25 ## \author Robin Knight (robin.knight@roadnarrows.com)
26 ##
27 ## \copyright
28 ## \h_copy 2010-2017. RoadNarrows LLC.\n
29 ## http://www.roadnarrows.com\n
30 ## All Rights Reserved
31 ##
32 
33 # Permission is hereby granted, without written agreement and without
34 # license or royalty fees, to use, copy, modify, and distribute this
35 # software and its documentation for any purpose, provided that
36 # (1) The above copyright notice and the following two paragraphs
37 # appear in all copies of the source code and (2) redistributions
38 # including binaries reproduces these notices in the supporting
39 # documentation. Substantial modifications to this software may be
40 # copyrighted by their authors and need not follow the licensing terms
41 # described here, provided that the new terms are clearly indicated in
42 # all files where they apply.
43 #
44 # IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
45 # OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
46 # PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
47 # DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
48 # EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
49 # THE POSSIBILITY OF SUCH DAMAGE.
50 #
51 # THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
52 # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
53 # FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
54 # "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
55 # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
56 #
57 ###############################################################################
58 
59 import BotSenseCore as bsCore
60 import BotSenseError as bsError
61 
62 #--
63 def sizeof(bsObj):
64  """ Size of BotSense object in bytes. Size is contextual by object type. """
65  return bsObj.__sizeof__()
66 ##
67 
68 
69 #------------------------------------------------------------------------------
70 # CLASS: BsClient
71 #------------------------------------------------------------------------------
72 class BsClient:
73  """ BotSense Client Wrapper Class.
74 
75  The BsClient class provides a safe wrapper around the BsClient_T *
76  opaque object.
77  """
78 
79  #--
80  def __init__(self, clientName='bsclient'):
81  """
82  Create and initialize BotSense client instance.
83 
84  Parameters:
85  clientName - Proxied client name string.
86  """
87  ## Pointer to opaque object
88  self.pClient = None
89 
90  pClient = bsCore.bsClientNew(clientName)
91  if not pClient:
92  raise bsError.BotSenseError(BS_ECODE_NO_RSRC, "Failed to create client.")
93 
94  self.pClient = pClient
95  ##
96 
97  #--
98  def __del__(self):
99  """ Delete BotSense client instance. """
100  if self.pClient is not None:
101  bsCore.bsClientDelete(self.pClient)
102  self.pClient = None
103  ##
104 
105  #--
106  def __sizeof__(self):
107  """ x.__sizeof__() -- size of swig object, in bytes. """
108  if self.pClient is not None:
109  return 1 # opaque size
110  else:
111  return 0 # opaque size
112  ##
113 
114  #--
115  def AttrGetName(self):
116  """ Get the client's name.
117 
118  Return:
119  On success, returns client string name.
120  On parameter check failure, a BotSenseError exception is raised.
121  """
122  self._ChkSelf()
123  clientName = bsCore.bsClientAttrGetName(self.pClient)
124  if not clientName:
125  clientName = 'unknown'
126  return clientName
127  ##
128 
129  #--
130  def AttrGetTraceState(self, hndVConn):
131  """ Get a client's virtual connection trace state.
132 
133  Parameters:
134  hndVConn - Virtual connection handle.
135 
136  Return:
137  On success, returns True (enabled) or False (disabled).
138  On parameter check failure, a BotSenseError exception is raised.
139  """
140  self._ChkSelf()
141  state = bsCore.bsClientAttrGetTraceState(self.pClient, hndVConn)
142  if state:
143  return True
144  else:
145  return False
146  ##
147 
148  #--
149  def AttrGetVConnCount(self):
150  """ Get a client's virtual connection trace state.
151 
152  Return:
153  On success, returns client's virtual connection count.
154  On parameter check failure, a BotSenseError exception is raised.
155  """
156  self._ChkSelf()
157  cnt = bsCore.bsClientAttrGetVConnCount(self.pClient)
158  return cnt
159  ##
160 
161  #--
162  def AttrHasVConn(self, hndVConn):
163  """ Check if the client has a virtual connection associated with the
164  given handle.
165 
166  Parameters:
167  hndVConn - Virtual connection handle.
168 
169  Return:
170  On success, returns True or False.
171  On parameter check failure, a BotSenseError exception is raised.
172  """
173  self._ChkSelf()
174  tf = bsCore.bsClientAttrHasVConn(self.pClient, hndVConn)
175  if tf:
176  return True
177  else:
178  return False
179  ##
180 
181  #--
182  def AttrGetDevName(self, hndVConn):
183  """ Get the proxied device name associated with the given handle.
184 
185  Parameters:
186  hndVConn - Virtual connection handle.
187 
188  Return:
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.
192  """
193  self._ChkSelf()
194  devName = bsCore.bsClientAttrGetDevName(self.pClient, hndVConn)
195  if not devName:
196  devName = '#nodev#'
197  return devName
198  ##
199 
200  #--
201  def AttrGetModName(self, hndVConn):
202  """ Get the proxied interface module name associated with the given
203  handle.
204 
205  Parameters:
206  hndVConn - Virtual connection handle.
207 
208  Return:
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.
212  """
213  self._ChkSelf()
214  modName = bsCore.bsClientAttrGetModName(self.pClient, hndVConn)
215  if not modName:
216  modName = '#nomod#'
217  return modName
218  ##
219 
220  #--
221  def AttrSetLogging(self, nLevel):
222  """ Set the client's diagnostic logging threshold.
223 
224  Parameters:
225  nLevel - New logging threshold level.
226  """
227  self._ChkSelf()
228  bsCore.bsClientAttrSetLogging(self.pClient, nLevel)
229  ##
230 
231  #--
232  def AttrGetConnState(self):
233  """ Get the client's connection state.
234 
235  Return:
236  Dictionary specifying connection state.
237  """
238  self._ChkSelf()
239  connstate = bsCore.BsClientConnState_T()
240  bsCore.bsClientAttrGetConnState(self.pClient, connstate)
241  d = {}
242  if connstate.m_bIsConnected:
243  d['is_connected'] = True
244  else:
245  d['is_connected'] = False
246  d['server_hostname'] = connstate.m_sServerHostName
247  return d
248  ##
249 
250  #--
251  def AttrGetTimeouts(self):
252  """ Get the client's request and response timeouts in seconds.
253  """
254  self._ChkSelf()
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);
261  return ret
262  ##
263 
264  #--
265  def AttrSetTimeouts(self, reqTimeout, rspTimeout):
266  """ Set the client's request and response timeouts in seconds.
267 
268  Parameters:
269  reqTimeout - Request (write) timeout.
270  rspTimeout - Response (read) timeout.
271  """
272  self._ChkSelf()
273  bsCore.bsClientAttrSetTimeouts(self.pClient, reqTimeout, rspTimeout)
274  ##
275 
276  #--
277  def GetMsgName(self, hndVConn, msgId):
278  """ Get the message name string.
279 
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).
283 
284  Parameters:
285  hndVConn - Virtual connection handle.
286  msgId - Message id.
287 
288  Return:
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.
292  """
293  self._ChkSelf()
294  return bsCore.bsClientGetMsgName(self.pClient, hndVConn, msgId)
295  ##
296 
297  #--
298  def Trans(self, hndVConn, reqMsgId, reqBuf, rspMsgId,
299  rspMaxSize=bsCore.BSPROXY_MSG_BODY_MAX):
300  """ Execute a request - response transaction with the server.
301 
302  The request message header is automatically generated. The response
303  message header is stripped off from the received response.
304 
305  Raises a BotSenseError exception on failure.
306 
307  Parameters:
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.
313 
314  Return:
315  Packed response message body buffer.
316  """
317  self._ChkSelf()
318  reqByteBuf = ByteBuf.Clone(reqBuf)
319  # leave space in buffer to prepend request message header
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
329  ##
330 
331  #--
332  def _ChkSelf(self):
333  """ Check that the opaque 'real' client exists. """
334  if self.pClient is None:
335  raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL, "No client.")
336  ##
337 
338  #--
339  @staticmethod
340  def ChkClient(obj):
341  """ Static check if object is a valid BsClient object.
342 
343  Parameters:
344  obj - Object instance.
345  """
346  bsError.ChkType(obj, BsClient)
347  obj._ChkSelf()
348  ##
349 ##
350 
351 
352 #------------------------------------------------------------------------------
353 # CLASS: ByteBuf
354 #------------------------------------------------------------------------------
355 class ByteBuf:
356  """ BotSense Byte Buffer Class.
357 
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
361  client and server.
362 
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.
366  """
367 
368  #--
369  def __init__(self, size=bsCore.BSPROXY_MSG_BODY_MAX):
370  """ Initialize byte buffer instance.
371 
372  Parameters:
373  size - Number of bytes of the underlining fixed sized SWIG
374  object.
375  """
376  # add header length
377  size += bsCore.BSPROXY_MSG_HDR_LEN
378 
379  ## internal swig object
380  self._swigObj = bsCore.new_byteArray(size)
381 
382  ## internal swig object fixed buffer size
383  self._size = size
384 
385  ## python byte string
386  self.buf = ''
387  ##
388 
389  #--
390  def __del__(self):
391  """ Delete byte buffer instance. """
392  bsCore.delete_byteArray(self._swigObj)
393  ##
394 
395  #--
396  @staticmethod
397  def Constructor(seq):
398  """ Conversion constructor.
399 
400  Parameters:
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.
404 
405  Return:
406  New initialized ByteBuf().
407  """
408  buf = ByteBuf.bytestring(seq)
409  bytebuf = ByteBuf(size=len(buf))
410  bytebuf.buf = buf
411  return bytebuf
412 
413  #--
414  @staticmethod
415  def Clone(buf):
416  """ Smart clone constructor.
417 
418  If buf is a ByteBuf instance, then simply return buf.
419  Otherwise convert buf to a ByteBuf instance.
420 
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.
423 
424  Parameters:
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.
428 
429  Return:
430  Existing or new ByteBuf().
431  """
432  if isinstance(buf, ByteBuf):
433  return buf
434  else:
435  return ByteBuf.Constructor(buf)
436  ##
437 
438  #--
439  def __getitem__(self, i):
440  """ x.__getitem__(i) <==> x[i] """
441  return self.buf.__getitem__(i)
442  ##
443 
444  #--
445  def __getslice__(self, i, j):
446  """ x.__getslice__(i, j) <==> x[i:j] """
447  return self.buf.__getslice__(i, j)
448  ##
449 
450  #--
451  def __iadd__(self, y):
452  """ x.__iadd__(y) <==> x+=y """
453  z = ByteBuf.bytestring(y)
454  self.buf.__iadd__(z)
455  return self
456  ##
457 
458  #--
459  def __imul__(self, y):
460  """ x.__imul__(y) <==> x*=y """
461  self.buf.__imul__(y)
462  return self
463  ##
464 
465  #--
466  def __iter__(self):
467  """ x.__iter__() <==> iter(x) """
468  return self.buf.__iter__()
469  ##
470 
471  #--
472  def __len__(self):
473  """ x.__len__() <==> len(x)
474 
475  Number of bytes used in buffer.
476  """
477  return len(self.buf)
478  ##
479 
480  #--
481  def __str__(self):
482  """ x.__str__() <==> str(x) <==> print x """
483  return self.buf.__str__()
484  ##
485 
486  #--
487  def __setitem__(self, i, y):
488  """ x.__setitem__(i, y) <==> x[i]=y """
489  z = self.byte(y)
490  self.buf.__setitem__(i, z)
491  return self
492  ##
493 
494  #--
495  def __setslice__(self, i, j, y):
496  """ x.__setslice__(i, j, y) <==> x[i:j]=y """
497  z = ByteBuf.bytestring(y)
498  self.buf.__setslice__(i, j, z)
499  return self
500  ##
501 
502  #--
503  def __sizeof__(self):
504  """ x.__sizeof__() -- size of swig object byte buffer, in bytes. """
505  return self._size
506  ##
507 
508  #--
509  def avail(self):
510  """ Available bytes in fixed swig object buffer. """
511  return self._size - len(self.buf)
512  ##
513 
514  #--
515  def copyFromSwigObj(self, n, i=0, j=0):
516  """ Copy swig object buffer to python buffer.
517 
518  Parameters:
519  n - Number of bytes to copy.
520  i - Starting source index in swig object buffer.
521  j - Starting destination index in python buffer.
522  """
523  if i+n > self._size:
524  raise bsError.BotSenseError(bsCore.BS_ECODE_BUF_TOO_SMALL,
525  "copyFromSwigObj: swig object buffer size=%d < %d bytes" % \
526  (self._size, i+n))
527  l = len(self.buf)
528  if l < j+n:
529  self.buf += chr(0) * (j + n - l)
530  s = ''
531  for k in xrange(n):
532  s += chr(bsCore.byteArray_getitem(self._swigObj, i+k))
533  self.buf = self.buf[:j] + s
534  ##
535 
536  #--
537  def copyToSwigObj(self, n, i=0, j=0):
538  """ Copy python buffer to instance swig object buffer.
539 
540  Parameters:
541  n - Number of bytes to copy.
542  i - Starting source index in python buffer.
543  j - Starting destination index in swig object buffer.
544  """
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" % \
552  (self._size, j+n))
553  for k in xrange(n):
554  bsCore.byteArray_setitem(self._swigObj, j+k, ord(self.buf[i+k]))
555  ##
556 
557  #--
558  def getSwigObj(self):
559  """ Return raw swig object. """
560  return self._swigObj
561  ##
562 
563  #--
564  def getBuffer(self):
565  """ Return python buffer. """
566  return self.buf
567  ##
568 
569  #--
570  def sizeof(self):
571  """ Size of fixed swig object byte buffer, in bytes. """
572  return self.__sizeof__()
573  ##
574 
575  #--
576  @staticmethod
577  def byte(val):
578  """ Static method to convert a value into a byte.
579 
580  Parameters:
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.
584 
585  Return:
586  On success, returns converted byte value.
587  On failure, a BotSenseError exception is raised.
588  """
589  if type(val) == int:
590  if val > 255:
591  raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL, "%s" % str(val))
592  else:
593  return val
594  elif type(val) == str:
595  if len(val) != 1:
596  raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL, "%s" % str(val))
597  else:
598  return ord(val[0])
599  elif type(val) == list:
600  if len(val) != 1:
601  raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL, "%s" % str(val))
602  else:
603  return ByteBuf.byte(val[0])
604  else:
605  raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL, "%s" % str(val))
606  ##
607 
608  #--
609  @staticmethod
610  def bytelist(seq):
611  """ Static method to convert a value sequence into a byte list.
612 
613  Parameters:
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.
617 
618  Return:
619  On success, returns converted byte value list.
620  On failure, a BotSenseError exception is raised.
621  """
622  if seq is None:
623  return []
624  elif type(seq) == int:
625  outbuf = [ ByteBuf.byte(seq) ]
626  return outbuf
627  elif type(seq) == str or type(seq) == list:
628  outbuf = []
629  for val in seq:
630  outbuf += [ ByteBuf.byte(val) ]
631  return outbuf
632  else:
633  raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL, "%s" % str(val))
634  ##
635 
636  #--
637  @staticmethod
638  def bytec(val):
639  """ Static method to convert a value into a byte character string.
640 
641  Parameters:
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.
645 
646  Return:
647  On success, returns converted byte value.
648  On failure, a BotSenseError exception is raised.
649  """
650  if type(val) == int:
651  if val > 255:
652  raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL, "%s" % str(val))
653  else:
654  return chr(val)
655  elif type(val) == str:
656  if len(val) != 1:
657  raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL, "%s" % str(val))
658  else:
659  return val[0]
660  elif type(val) == list:
661  if len(val) != 1:
662  raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL, "%s" % str(val))
663  else:
664  return ByteBuf.bytec(val[0])
665  else:
666  raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL, "%s" % str(val))
667  ##
668 
669  #--
670  @staticmethod
671  def bytestring(seq):
672  """ Static method to convert a value sequence into a byte string.
673 
674  Parameters:
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.
678 
679  Return:
680  On success, returns converted byte value list.
681  On failure, a BotSenseError exception is raised.
682  """
683  if seq is None:
684  return ''
685  elif type(seq) == int:
686  return ByteBuf.bytec(seq)
687  elif type(seq) == str or type(seq) == list:
688  outbuf = ''
689  for val in seq:
690  outbuf += ByteBuf.bytec(val)
691  return outbuf
692  else:
693  raise bsError.BotSenseError(bsCore.BS_ECODE_BAD_VAL, "%s" % str(val))
694  ##
695 ##
696 
697 
698 #------------------------------------------------------------------------------
699 # CLASS: BsProxyMsgHdr
700 #------------------------------------------------------------------------------
701 class BsProxyMsgHdr(bsCore.BsProxyMsgHdr_T):
702  """ BotSense bsProxy Message Header Wrapper Class. """
703 
704  #--
705  def __init__(self, tid=0, vconn=bsCore.BSPROXY_VCONN_SERVER, msgid=0,
706  bodylen=0):
707  """ Initialize BotSense Proxy Message Header instance.
708 
709  Parameters:
710  tid - Transaction id.
711  vconn - Virtual connection handle.
712  msgid - Message id.
713  bodylen - Message body length, in bytes.
714  """
715  bsCore.BsProxyMsgHdr_T.__init__(self)
716  ## message header fixed magic number
717  self.m_hdrMagic = bsCore.BSPROXY_MSG_MAGIC
718  ## message header transaction id
719  self.m_hdrTid = tid
720  ## message header virtual connection handle
721  self.m_hdrVConn = vconn
722  ## message header message id
723  self.m_hdrMsgId = msgid
724  ## message header body length
725  self.m_hdrBodyLen = bodylen
726 
727  ## class attributes
728  self._attrlist = ['m_hdrMagic', 'm_hdrTid', 'm_hdrVConn', 'm_hdrMsgId',
729  'm_hdrBodyLen']
730  ##
731 
732  #--
733  def __sizeof__(self):
734  """ x.__sizeof__() -- size of header, in bytes. """
735  return bsCore.BSPROXY_MSG_HDR_LEN
736  ##
737 
738  #--
739  def __getitem__(self, y):
740  """ x.__getitem__(y) <==> x[y] """
741  return getattr(self, y)
742  ##
743 
744  #--
745  def __setitem__(self, y, v):
746  """ x.__setitem__(y, v) <==> x[y]=v """
747  if y in self._attrlist:
748  setattr(self, y, v)
749  else:
750  raise AttributeError(y)
751  ##
752 
753  #--
754  def __iter__(self):
755  """ x.__iter__() <==> iter(x) """
756  return self._attrlist.__iter__()
757  ##
758 
759  #--
760  def __str__(self):
761  """ x.__str__() <==> str(x) <==> print x """
762  d = {}
763  for attr in self._attrlist:
764  d[attr] = getattr(self, attr)
765  return str(d)
766  ##
767 
768  #--
769  def ListAttrs(self):
770  """ Return list of class variable attribute names. """
771  return self._attrlist
772  ##
773 
774  #--
775  def PackMsgHdr(self, buf):
776  """ Pack BotSense bsProxy message header
777 
778  Raises a BotSenseError exception on failure.
779 
780  Parameters:
781  buf [out] - BotSenseTypes.ByteBuf output buffer instance.
782 
783  Return:
784  On success, returns the number of bytes packed.
785  On failure, a BotSenseError exception is raised.
786  """
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)
791  return n
792  ##
793 
794  #--
795  def UnpackMsgHdr(self, buf):
796  """ Unpack BotSense bsProxy message header
797 
798  Raises a BotSenseError exception on failure.
799 
800  Parameters:
801  buf [in] - BotSenseTypes.ByteBuf input buffer instance.
802 
803  Return:
804  On success, returns the number of bytes unpacked.
805  On failure, a BotSenseError exception is raised.
806  """
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.")
811  return n
812  ##
813 ##
814 
815 
816 #------------------------------------------------------------------------------
817 # CLASS: BsVConnInfo
818 #------------------------------------------------------------------------------
819 class BsVConnInfo(bsCore.BsVConnInfo_T):
820  """ BotSense Virtual Connection Information Wrapper Class.
821  """
822 
823  #--
824  def __init__(self):
825  """ Initialize Virtual Connection Info instance. """
826  bsCore.BsVConnInfo_T.__init__(self)
827 
828  self._attrlist = ['m_vconn', 'm_rd', 'm_client', 'm_devuri', 'm_moduri',
829  'm_modver', 'm_moddate']
830  ##
831 
832  #--
833  def __sizeof__(self):
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)
837  ##
838 
839  #--
840  def __getitem__(self, y):
841  """ x.__getitem__(y) <==> x[y] """
842  return getattr(self, y)
843  ##
844 
845  #--
846  def __setitem__(self, y, v):
847  """ x.__setitem__(y, v) <==> x[y]=v """
848  if y in self._attrlist:
849  setattr(self, y, v)
850  else:
851  raise AttributeError(y)
852  ##
853 
854  #--
855  def __iter__(self):
856  """ x.__iter__() <==> iter(x) """
857  return self._attrlist.__iter__()
858  ##
859 
860  #--
861  def __str__(self):
862  """ x.__str__() <==> str(x) <==> print x """
863  d = {}
864  for attr in self._attrlist:
865  d[attr] = getattr(self, attr)
866  return str(d)
867  ##
868 
869  #--
870  def ListAttrs(self):
871  """ Return list of class variable attribute names. """
872  return self._attrlist
873  ##
874 ##
875 
876 
877 #------------------------------------------------------------------------------
878 # CLASS: BsClientAppInfo
879 #------------------------------------------------------------------------------
880 class BsClientAppInfo(bsCore.BsClientAppInfo_T):
881  """ BotSense Client Application Info and Callback Wrapper Class.
882 
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.
886 
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).
890  """
891 
892  #--
893  def __init__(self):
894  """ Initialize BotSense Proxy Message Header instance. """
895  bsCore.BsClientAppInfo_T.__init__(self)
896 
897  self._attrlist = ['app_name', 'brief', 'version', 'date', 'maintainer',
898  'license', 'fnGetMsgName']
899  ##
900 
901  #--
902  def __sizeof__(self):
903  """ x.__sizeof__() -- size of swig object, in bytes. """
904  return 8 * len(self._attrlist)
905  ##
906 
907  #--
908  def __getitem__(self, y):
909  """ x.__getitem__(y) <==> x[y] """
910  return getattr(self, y)
911  ##
912 
913  #--
914  def __setitem__(self, y, v):
915  """ x.__setitem__(y, v) <==> x[y]=v """
916  if y in self._attrlist:
917  setattr(self, y, v)
918  else:
919  raise AttributeError(y)
920  ##
921 
922  #--
923  def __iter__(self):
924  """ x.__iter__() <==> iter(x) """
925  return self._attrlist.__iter__()
926  ##
927 
928  #--
929  def __str__(self):
930  """ x.__str__() <==> str(x) <==> print x """
931  d = {}
932  for attr in self._attrlist:
933  d[attr] = getattr(self, attr)
934  return str(d)
935  ##
936 
937  #--
938  def ListAttrs(self):
939  """ Return list of class variable attribute names. """
940  return self._attrlist
941  ##
942 ##
pClient
Pointer to opaque object.
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)
m_hdrVConn
message header virtual connection handle
def AttrSetTimeouts(self, reqTimeout, rspTimeout)
m_hdrMagic
message header fixed magic number
def AttrSetLogging(self, nLevel)
def __setslice__(self, i, j, y)
def copyToSwigObj(self, n, i=0, j=0)
def Trans(self, hndVConn, reqMsgId, reqBuf, rspMsgId, rspMaxSize=bsCore.BSPROXY_MSG_BODY_MAX)
def __init__(self, tid=0, vconn=bsCore.BSPROXY_VCONN_SERVER, msgid=0, bodylen=0)
def AttrGetTraceState(self, hndVConn)
def AttrGetModName(self, hndVConn)
def GetMsgName(self, hndVConn, msgId)
def __init__(self, clientName='bsclient')
m_hdrBodyLen
message header body length
_size
internal swig object fixed buffer size
m_hdrMsgId
message header message id
m_hdrTid
message header transaction id
_swigObj
internal swig object