summaryrefslogtreecommitdiffstats
path: root/xpa/python/PythonXPA/server/XPAServer.py
blob: 4c46ed3eba25a8ba122e6a9726b180ad264f03ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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 \
                     ]