From: nishi Date: Fri, 9 Feb 2024 05:58:03 +0000 (+0000) Subject: functions X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=33d6fff3c179d48fc94a8195ded748a8c1f2235b;p=libw3.git functions git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@193 d27a3e52-49c5-7645-884c-6793ebffc270 --- diff --git a/Python/__init__.py b/Python/__init__.py index 7f7ba45..9c99b4d 100644 --- a/Python/__init__.py +++ b/Python/__init__.py @@ -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