]> Nishi Git Mirror - libw3.git/commitdiff
functions
authornishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Fri, 9 Feb 2024 05:58:03 +0000 (05:58 +0000)
committernishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Fri, 9 Feb 2024 05:58:03 +0000 (05:58 +0000)
git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@193 d27a3e52-49c5-7645-884c-6793ebffc270

Python/__init__.py

index 7f7ba455f803f65eb6d0196ad34877a37a3f9403..9c99b4d799e9cd9f51c84cc05694a5d2966c4963 100644 (file)
@@ -1,4 +1,4 @@
-" $Id$ "
+# $Id$
 import ctypes
 import ctypes.util
 
@@ -8,13 +8,60 @@ libpath = ctypes.util.find_library("w3")
 if not(libpath):
        raise Exception("LibW3 not found")
 
-class w3:
-       def __init__(self):
-               return
-
 libw3_loaded = ctypes.CDLL(libpath)
 
 libw3_loaded.W3_Do_Debug.argtypes = [ctypes.c_bool]
+libw3_loaded.W3_Do_Debug = None
+
+libw3_loaded.W3_Library_Init.argtypes = []
+libw3_loaded.W3_Library_Init.restype = None
+
+libw3_loaded.W3_Create.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int]
+libw3_loaded.W3_Create.restype = ctypes.c_void_p
+
+libw3_loaded.W3_Send_Request.argtypes = [ctypes.c_void_p]
+libw3_loaded.W3_Send_Request.restype = None
+
+libw3_loaded.W3_Set_Method.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
+libw3_loaded.W3_Set_Method.restype = None
+
+libw3_loaded.W3_Set_Path.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
+libw3_loaded.W3_Set_Path.restype = None
+
+libw3_loaded.W3_On.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p]
+libw3_loaded.W3_On.restype = None
+
+w3_list = []
+
+@ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_char_p, ctypes.c_size_t)
+def global_data_handler(cli, data, size):
+       for i in w3_list:
+               if cli == i._client:
+                       ba = bytearray(size)
+                       for j in range(size):
+                               ba[j] = data[j]
+                       if i._data_handler:
+                               i._data_handler(i, ba, size)
+
+
+class w3:
+       def __init__(self, protocol, hostname, port):
+               self._client = libw3_loaded.W3_Create(protocol.encode("utf-8"), hostname.encode("utf-8"), port);
+               self._data_handler = None
+               if not(self._client):
+                       raise Exception("Failed to conenct")
+               else:
+                       w3_list.append(self)
+                       libw3_loaded.W3_On(self._client, b"data", global_data_handler);
+               return
+       def set_path(self, path):
+               libw3_loaded.W3_Set_Path(self._client, path.encode("utf-8"))
+       def set_method(self, method):
+               libw3_loaded.W3_Set_Method(self._client, method.encode("utf-8"))
+       def set_data_handler(self, handler):
+               self._data_handler = handler
+       def send_request(self):
+               libw3_loaded.W3_Send_Request(self._client)
 
 class libw3:
        @staticmethod