mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-04 18:29:19 +02:00
quick try at adding DC_EVENT names and use them to deltachat bindings
This commit is contained in:
parent
eec2261cca
commit
0340dbe81c
3 changed files with 40 additions and 4 deletions
|
@ -2,6 +2,7 @@ from deltachat import capi
|
|||
|
||||
|
||||
_DC_CALLBACK_MAP = {}
|
||||
_DC_EVENTNAME_MAP = {}
|
||||
|
||||
|
||||
@capi.ffi.def_extern()
|
||||
|
@ -16,3 +17,11 @@ def py_dc_callback(ctx, evt, data1, data2):
|
|||
if ret is None:
|
||||
return 0
|
||||
return ret
|
||||
|
||||
|
||||
def get_dc_event_name(integer):
|
||||
if not _DC_EVENTNAME_MAP:
|
||||
for name, val in vars(capi.lib).items():
|
||||
if name.startswith("DC_EVENT_"):
|
||||
_DC_EVENTNAME_MAP[val] = name
|
||||
return _DC_EVENTNAME_MAP[integer]
|
||||
|
|
|
@ -1,9 +1,27 @@
|
|||
import distutils.ccompiler
|
||||
import distutils.sysconfig
|
||||
import tempfile
|
||||
from os.path import dirname, abspath
|
||||
from os.path import join as joinpath
|
||||
|
||||
import cffi
|
||||
|
||||
here = dirname(abspath(__file__))
|
||||
deltah = joinpath(dirname(dirname(dirname(here))), "src", "deltachat.h")
|
||||
|
||||
|
||||
def read_event_defines():
|
||||
for line in open(deltah):
|
||||
if line.startswith("#define"):
|
||||
parts = line.split()
|
||||
if len(parts) >= 3:
|
||||
if parts[1].startswith("DC_EVENT"):
|
||||
try:
|
||||
val = int(parts[2])
|
||||
except ValueError:
|
||||
continue
|
||||
yield line
|
||||
|
||||
|
||||
def ffibuilder():
|
||||
builder = cffi.FFI()
|
||||
|
@ -35,6 +53,8 @@ def ffibuilder():
|
|||
uintptr_t data1,
|
||||
uintptr_t data2);
|
||||
""")
|
||||
event_defines = "\n".join(read_event_defines())
|
||||
builder.cdef(event_defines)
|
||||
return builder
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import print_function
|
||||
import deltachat
|
||||
from deltachat import capi
|
||||
from deltachat import capi, get_dc_event_name
|
||||
from deltachat.capi import ffi
|
||||
import queue
|
||||
|
||||
|
||||
|
@ -9,6 +10,10 @@ def test_empty_context():
|
|||
capi.lib.dc_close(ctx)
|
||||
|
||||
|
||||
def test_event_defines():
|
||||
assert capi.lib.DC_EVENT_INFO == 100
|
||||
|
||||
|
||||
def test_cb(register_dc_callback):
|
||||
def cb(ctx, evt, data1, data2):
|
||||
return 0
|
||||
|
@ -34,7 +39,9 @@ def test_basic_events(dc_context, dc_threads, register_dc_callback, tmpdir, user
|
|||
|
||||
while 1:
|
||||
evt1, data1, data2 = q.get(timeout=1.0)
|
||||
if evt1 == 100:
|
||||
print ("info event", data2)
|
||||
if evt1 == capi.lib.DC_EVENT_INFO:
|
||||
s = ffi.string(ffi.cast('char*', data2))
|
||||
print ("info event", s)
|
||||
elif evt1:
|
||||
print ("other event", evt1, data1, data2)
|
||||
name = get_dc_event_name(evt1)
|
||||
print ("other event", name, data1, data2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue