Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*-coding:utf8-*-
- import win32com.client
- import ctypes
- import os
- class GtAlgoWrapper():
- # com spec
- _public_methods_ = ['solve','resultCallback', 'progressCallback',]
- _public_attrs_ = ['version',]
- _readonly_attr_ = []
- _reg_clsid_ = '{2234314F-F3F1-2341-5BA9-5FD1E58F1526}'
- _reg_progid_= 'GtAlgoWrapper'
- _reg_desc_ = 'COM Wrapper For GTAlgo'
- _dependencies = ['libwinpthread-1.dll',
- 'libgcc_s_dw2-1.dll',
- 'libstdc++-6.dll',
- 'libcrypto-1_1.dll',
- 'libssl-1_1.dll',
- 'Qt5Core.dll',
- 'Qt5Cored.dll',
- 'Qt5Gui.dll',
- 'Qt5Guid.dll',
- 'libcurl.dll',
- 'GtTools0-0-1.dll',
- 'GtRouting0-0-1.dll']
- def __init__(self):
- self.version = '0.0.1'
- self.progressOuterCb = None
- self.resultOuterCb = None
- def solve(self, data):
- prefix_path = 'C:/release'
- try:
- for dep in self._dependencies:
- ctypes.cdll.LoadLibrary(os.path.join(prefix_path, dep))
- lib = ctypes.cdll.LoadLibrary(os.path.join(prefix_path, 'GtAlgo0-0-1.dll'))
- except WindowsError:
- raise Exception('cant load' + dep)
- solve_func = getattr(lib, '_ZN6GtAlgo5solveEPKcPFviS1_ES3_')
- StatusCallback = ctypes.CFUNCTYPE(None, ctypes.c_int, ctypes.c_char_p)
- ResultCallback = ctypes.CFUNCTYPE(None, ctypes.c_int, ctypes.c_char_p)
- _scb_func = StatusCallback(self._libProgressCb)
- _rcb_func = ResultCallback(self._libResultCb)
- if self.resultOuterCb is None:
- raise Exception('resultCallback function is not Set')
- if self.progressOuterCb is None:
- raise Exception('progressCallback function is not Set')
- solve_func(ctypes.c_char_p(data), _scb_func, _rcb_func)
- return 'DONE'
- def _libProgressCb(self, *args):
- self.progressOuterCb(*args)
- def _libResultCb(self, *args):
- self.resultOuterCb(*args)
- def _callbackSetter(self, obj, outerCbName):
- if str(type(obj)) == "<type 'PyIDispatch'>":
- com_obj = win32com.client.Dispatch(obj)
- try:
- return getattr(com_obj, outerCbName)
- except AttributeError:
- raise Exception('"'+outerCbName + '" not found in "This"')
- else:
- raise Exception('"This" is necessary parameter')
- def resultCallback(self, obj):
- self.resultOuterCb = self._callbackSetter(obj, 'resultCallback')
- return obj
- def progressCallback(self, obj):
- self.progressOuterCb = self._callbackSetter(obj, 'progressCallback')
- return obj
- def main():
- import win32com.server.register
- win32com.server.register.UseCommandLine(GtAlgoWrapper)
- print('registred')
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment