diff options
Diffstat (limited to 'xpa/python/PythonXPA/server')
-rw-r--r-- | xpa/python/PythonXPA/server/XPAServer.py | 125 | ||||
-rwxr-xr-x | xpa/python/PythonXPA/server/test_XPAS.py | 91 |
2 files changed, 216 insertions, 0 deletions
diff --git a/xpa/python/PythonXPA/server/XPAServer.py b/xpa/python/PythonXPA/server/XPAServer.py new file mode 100644 index 0000000..4c46ed3 --- /dev/null +++ b/xpa/python/PythonXPA/server/XPAServer.py @@ -0,0 +1,125 @@ + +from ctypes import * + +x=cdll.LoadLibrary("../libxpa.so.1.0") + + +c_byte_p = POINTER(c_byte) + + +## int XPAPoll(int msec, int maxreq); + +XPAPoll = x.XPAPoll +x.XPAPoll.restype = c_int +x.XPAPoll.argtypes = [c_int, c_int] + + + + +## typedef struct xparec{ +## /* xpa version */ +## char *version; +## /* status of this xpa */ +## int status; +## /* "g", "s", "i" are server types; "c" for client */ +## char *type; +## /* +## * THE SERVER SIDE +## */ +## struct xparec *next; +## char *xclass; +## char *name; +## char *help; + +## +## /* and so on */ +## +## } *XPA; + +# ctypes wrapper +class xparec(Structure): + _fields_ = [ ("version", c_char_p), \ + ("status", c_int), \ + ("type", c_char_p), \ + ("next", c_void_p), \ + ("xclass", c_char_p), \ + ("name", c_char_p), \ + ("help", c_char_p) \ + ] + +XPA = POINTER(xparec) + + + + + +## int XPAFree(XPA xpa); + +XPAFree = x.XPAFree +x.XPAFree.restype = c_void_p +x.XPAFree.argtypes = [XPA] + + + +## info callback: +## int info_cb(void *info_data, void *call_data, char *paramlist) + + + +INFOCBFUNC = CFUNCTYPE(c_int, c_char_p, XPA, c_char_p) + +### implement like this: +#def py_infocb_func(a, b, c): +# print "py_cmp_func", a, b +# return 0 +# +#infocb_func = INFOCBFUNC(py_infocb_func) + + + +## XPA XPAInfoNew(char *class, char *name, +## int (*info_callback)(), +## void *info_data, char *info_mode); + +XPAInfoNew = x.XPAInfoNew +x.XPAInfoNew.restype = XPA +x.XPAInfoNew.argtypes = [c_char_p, c_char_p, INFOCBFUNC, c_char_p, c_char_p] + + + + + +## int send_callback(void *send_data, void *call_data, +## char *paramlist, char **buf, int *len) + +SENDCBFUNC = CFUNCTYPE(c_int, c_char_p, XPA, c_char_p, POINTER(c_byte_p), POINTER(c_int)) + +### implement like this: +#def py_sendcb_func(a, data, call_data, param, buf, len): +# print "inside send_callback" +# return 0 +# +#sendcb_func = SENDCBFUNC(py_sendcb_func) + + +## int receive_callback(void *receive_data, void *call_data, +## char *paramlist, char *buf, int len) + +RCVCBFUNC = CFUNCTYPE(c_int, c_char_p, XPA, c_char_p, c_byte_p, c_int) + + + +## XPA XPANew(char *class, char *name, char *help, +## int (*send_callback)(), +## void *send_data, char *send_mode, +## int (*rec_callback)(), +## void *rec_data, char *rec_mode); + +XPANew = x.XPANew +x.XPANew.restype = XPA +x.XPANew.argtypes = [c_char_p, c_char_p, c_char_p, \ + SENDCBFUNC, \ + c_char_p, c_char_p, \ + RCVCBFUNC, \ + c_char_p, c_char_p \ + ] diff --git a/xpa/python/PythonXPA/server/test_XPAS.py b/xpa/python/PythonXPA/server/test_XPAS.py new file mode 100755 index 0000000..fe4f1a2 --- /dev/null +++ b/xpa/python/PythonXPA/server/test_XPAS.py @@ -0,0 +1,91 @@ +#!/usr/bin/python + +################################ +####### testing: # +################################ + +from XPAServer import * + +import time + +print "Poll" +n = x.XPAPoll(10000, 0) +print "got %d" % n + +EXIT_FLAG = False + + +############################## +# setting up Info Point # +############################## + +def py_infocb_func(a, b, c): + global EXIT_FLAG + print ">>> INFO:" + print "params:", c + print "info:", a + print "XPA.name", b[0].name + print "<<<" + if (c[0:4] == "exit"): + print "setting EXIT_FLAG" + EXIT_FLAG = True + return 0 + +infocb_func = INFOCBFUNC(py_infocb_func) + +xpa = XPAInfoNew("XPA", "i_test", infocb_func, "my info", "") + +############################## + + + + +####################################### +# setting up AccessPoint Get/Set # +####################################### + +def py_sendcb_func(data, call_data, param, buf, len): + print "inside send_callback" + print "param:", param + print "buf:", string_at(buf) + buf[0] = cast("this is test only\n", c_byte_p) + len[0] = 19 + return 0 + +sendcb_func = SENDCBFUNC(py_sendcb_func) + + +def py_rcvcb_func(data, call_data, param, buf, len): + print "inside rcv_callback" + print "param:", param + print "got %d bytes" % len + print "buf:", string_at(buf) + return 0 + +rcvcb_func = RCVCBFUNC(py_rcvcb_func) + + +xpa2 = XPANew("XPA", "myxpa", "this is great help", + sendcb_func, + "SEND_DATA", "freebuf=false", + rcvcb_func, + "", "") + + + + + +############################## +print "Entering loop" + +while EXIT_FLAG == False: + n = XPAPoll(1000, 1) + print "got:", n + +print "loop finished" +############################## + + +print "calling XPAFree" +XPAFree(xpa) +XPAFree(xpa2) |