From 7d0ecfe5b820941c0199af044fd3a756e6a94890 Mon Sep 17 00:00:00 2001 From: doomchild Date: Mon, 3 May 2010 15:54:13 -0500 Subject: [PATCH] first commit, attaching/detaching/suspending/resuming works --- dfhack/python/dfhack_api_ctypes.py | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 dfhack/python/dfhack_api_ctypes.py diff --git a/dfhack/python/dfhack_api_ctypes.py b/dfhack/python/dfhack_api_ctypes.py new file mode 100644 index 000000000..d9f460ba8 --- /dev/null +++ b/dfhack/python/dfhack_api_ctypes.py @@ -0,0 +1,41 @@ +from ctypes import * + +int_ptr = POINTER(c_int) +uint_ptr = POINTER(c_uint) + +libdfhack = cdll.libdfhack +libdfhack.API_Alloc.restype = c_void_p +libdfhack.API_Free.argtypes = [ c_void_p ] + +class API(object): + def __init__(self, memory_path): + self._api_ptr = libdfhack.API_Alloc(create_string_buffer(memory_path)) + + def __del__(self): + libdfhack.API_Free(self._api_ptr) + + def Attach(self): + return libdfhack.API_Attach(self._api_ptr) > 0 + + def Detach(self): + return libdfhack.API_Detach(self._api_ptr) > 0 + + def Suspend(self): + return libdfhack.API_Suspend(self._api_ptr) > 0 + + def Resume(self): + return libdfhack.API_Resume(self._api_ptr) > 0 + + def Force_Resume(self): + return libdfhack.API_ForceResume(self._api_ptr) > 0 + + def Async_Suspend(self): + return libdfhack.API_AsyncSuspend(self._api_ptr) > 0 + + @property + def is_attached(self): + return libdfhack.API_isAttached(self._api_ptr) > 0 + + @property + def is_suspended(self): + return libdfhack.API_isSuspended(self._api_ptr) > 0