botsense  3.2.0
RoadNarrows Client-Server Proxied Services Framework
bsNull.i
1 /******************************************************************************
2  *
3  * Package: BotSense
4  *
5  * File: bsNull.i
6  *
7  * $LastChangedDate$
8  * $Rev$
9  */
10 
11 /*!
12  * \file
13  *
14  * \brief BotSense /dev/null library python swig interface definitions file.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \par Copyright:
19  * (C) 2010. RoadNarrows LLC.
20  * (http://www.roadnarrows.com)
21  * All Rights Reserved
22  */
23 
24 /*
25  * Permission is hereby granted, without written agreement and without
26  * license or royalty fees, to use, copy, modify, and distribute this
27  * software and its documentation for any purpose, provided that
28  * (1) The above copyright notice and the following two paragraphs
29  * appear in all copies of the source code and (2) redistributions
30  * including binaries reproduces these notices in the supporting
31  * documentation. Substantial modifications to this software may be
32  * copyrighted by their authors and need not follow the licensing terms
33  * described here, provided that the new terms are clearly indicated in
34  * all files where they apply.
35  *
36  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
37  * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
38  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
39  * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
40  * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
41  * THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
44  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
45  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
46  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
47  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
48  *
49  ******************************************************************************/
50 
51 %module bsNull
52 %{
53 #include "botsense/BotSense.h"
54 #include "botsense/bsNull.h"
55 %}
56 
57 %begin
58 %{
59 /*! \file
60  * \brief Swig generated null wrapper c file.
61  */
62 %}
63 
64 /*
65  * Required RNR C Types
66  */
67 typedef unsigned char byte_t;
68 typedef unsigned short ushort_t;
69 typedef unsigned int uint_t;
70 typedef unsigned long ulong_t;
71 typedef int bool_t;
72 
73 /*
74  * Required BotSense C Types
75  */
76 typedef struct _bsClientStruct *BsClient_P;
77 typedef int BsVConnHnd_T;
78 
79 /* the swigged interface */
80 %include "botsense/bsNull.h"
81 
82 
83 /*
84  * Higher-level python interface to the BotSense Null C library.
85  */
86 %pythoncode
87 %{
88 
89 """
90 BotSense DevNull Python Inline Extensions and Wrappers.
91 """
92 
93 ## \file
94 ## \package BotSense.bsNull
95 ##
96 ## \brief BotSense Swigged Null Python Interface Module.
97 ##
98 ## \author Robin Knight (robin.knight@roadnarrows.com)
99 ##
100 ## \par Copyright:
101 ## (C) 2010. RoadNarrows LLC.\n
102 ## (http://www.roadnarrows.com)\n
103 ## All Rights Reserved
104 ##
105 
106 import BotSenseCore as bsCore
107 import BotSenseError as bsError
108 import BotSenseTypes as bsTypes
109 
110 
111 def NullGetMsgName(client, hndVConn, msgId):
112  """ Get the DevNull message name.
113 
114  For each (virtual connection, message id) 2-tuple, there can be a known
115  name string (provided the id is valid and an application provides the
116  information).
117 
118  Parameters:
119  client - BotSenseTypes.BsClient instance.
120  hndVConn - Virtual connection handle (ignored).
121  msgId - DevNull message id.
122 
123  Return:
124  Returns message name string if it can be determined.
125  Otherwise returns 'unknown'.
126  """
127  bsTypes.BsClient.ChkClient(client)
128  return bsNullGetMsgName(client.pClient, hndVConn, msgId)
129 
130 def NullReqOpen(client, trace=False):
131  """ Proxy server request to establish a virtual connection to the /dev/null
132  device.
133 
134  Raises a BotSenseError exception on failure.
135 
136  Parameters:
137  client - BotSenseTypes.BsClient instance.
138  trace - Initial message tracing enable(true)/disable(false) state.
139 
140  Return
141  New virtual connection handle.
142  """
143  bsTypes.BsClient.ChkClient(client)
144  hndVConn = bsNullReqOpen(client.pClient, trace)
145  bsError.ChkReturnIsNonNeg(hndVConn,
146  "Client %s: DevNull Open request failed." % (client.AttrGetName()))
147  return hndVConn
148 
149 def NullReqClose(client, hndVConn):
150  """ Proxy server request to close client's proxied /dev/null device virtual
151  connection.
152 
153  Raises a BotSenseError exception on failure.
154 
155  Parameters:
156  client - BotSenseTypes.BsClient instance.
157  hndVConn - Virtual connection handle.
158  """
159  bsTypes.BsClient.ChkClient(client)
160  rc = bsNullReqClose(client.pClient, hndVConn)
161  bsError.ChkReturnIsOk(rc,
162  "Client %s: DevNull Close request failed." % (client.AttrGetName()))
163 
164 def NullReqWrite(client, hndVConn, wbuf):
165  """ DevNull request to write /dev/null.
166 
167  Raises a BotSenseError exception on failure.
168 
169  Parameters:
170  client - BotSenseTypes.BsClient instance.
171  hndVConn - Virtual connection handle.
172  wbuf - Write buffer.
173 
174  Return:
175  Number of bytes written.
176  """
177  bsTypes.BsClient.ChkClient(client)
178  wbytebuf = bsTypes.ByteBuf.Clone(wbuf)
179  wbytebuf.copyToSwigObj(len(wbytebuf))
180  n = bsNullReqWrite(client.pClient, hndVConn, wbytebuf.getSwigObj(),
181  len(wbytebuf))
182  bsError.ChkReturnIsNonNeg(n,
183  "Client %s: DevNull Write request failed." % (client.AttrGetName()))
184  return n
185 
186 %}