diff options
author | Michał Klichowicz <emkael@tlen.pl> | 2023-09-30 12:40:40 +0200 |
---|---|---|
committer | Michał Klichowicz <emkael@tlen.pl> | 2023-09-30 12:40:40 +0200 |
commit | 518bdba985a913044e84e82713a8e76f5ddd3301 (patch) | |
tree | 6757ec4d785c07e2c3f34e70b5bd7326fe7c7a2c /src/bcdd/BCalcWrapper.py |
Initial import script
Diffstat (limited to 'src/bcdd/BCalcWrapper.py')
-rw-r--r-- | src/bcdd/BCalcWrapper.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/bcdd/BCalcWrapper.py b/src/bcdd/BCalcWrapper.py new file mode 100644 index 0000000..a6bed27 --- /dev/null +++ b/src/bcdd/BCalcWrapper.py @@ -0,0 +1,45 @@ +''' +Wrapper class for libbcalcDDS.dll +''' + +import os +from ctypes import cdll, c_char_p, c_void_p + +from .Exceptions import DllNotFoundException + + +class BCalcWrapper(object): + + DENOMINATIONS = [ 'C', 'D', 'H', 'S', 'N' ] + PLAYERS = [ 'N', 'E', 'S', 'W' ] + + def __init__(self): + dllPath = os.path.join( + os.path.dirname(__file__), + '..') + try: + self.libbcalcdds = cdll.LoadLibrary(os.path.join( + dllPath, 'libbcalcdds.dll')) + except OSError: + try: + self.libbcalcdds = cdll.LoadLibrary(os.path.join( + dllPath, 'libbcalcdds.so')) + except OSError: + self.libbcalcdds = None + if self.libbcalcdds is None: + raise DllNotFoundException() + + def __getattr__(self, attrname): + def _dynamic_method(*args): + function = getattr(self.libbcalcdds, 'bcalcDDS_' + attrname) + if attrname == 'new': + function.restype = c_void_p + else: + if attrname == 'getLastError': + function.restype = c_char_p + function.argtypes = [c_void_p] + return function(*args) + return _dynamic_method + + def declarerToLeader(self, player): + return (player + 1) % 4 |