-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdk.py
34 lines (27 loc) · 1.07 KB
/
sdk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
_temp = __import__(os.environ["OUT_DIR"] + ".ext_module", globals(), locals(), ["ffi", "lib"])
ffi = _temp.ffi
lib = _temp.lib
class Client(object):
def __init__(self, **kwargs):
# Keep handle alive at least as long as Client instance
self.handle = ffi.new_handle(self)
print "Python: In Client.__init__", self.handle
# Configure logger, etc.
self.log = kwargs.get("logger", self.default_logger)
self.rust_client = lib.make_client(
self.handle,
lib.cb_logger_log,
)
print "Python: make_client returned", self.rust_client
def add(self, a, b):
print "Python: In Client.add; calling lib.add with rust_client", self.rust_client
return lib.add(self.rust_client, a, b)
def default_logger(self, message):
print "DefaultPrefix:", message
@ffi.def_extern()
def cb_logger_log(client_handle, message):
message = ffi.string(message)
print "Python: In static callback, msg: '%s'" % message
client = ffi.from_handle(client_handle)
client.log(message)