Skip to content

Commit e9cdb3e

Browse files
author
Ivan Dlugos
committed
declare c-api types in python
1 parent bf6d54d commit e9cdb3e

1 file changed

Lines changed: 119 additions & 0 deletions

File tree

objectbox/c.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,122 @@
22

33
# initialize the C library
44
C = ctypes.CDLL(ctypes.util.find_library("objectbox"))
5+
6+
# define some basic types
7+
obx_err = ctypes.c_int
8+
obx_schema_id = ctypes.c_uint32
9+
obx_uid = ctypes.c_uint64
10+
obx_id = ctypes.c_uint64
11+
obx_qb_cond = ctypes.c_int
12+
13+
14+
class OBX_model(ctypes.Structure):
15+
pass
16+
17+
18+
OBX_model_p = ctypes.POINTER(OBX_model)
19+
20+
21+
class OBX_store(ctypes.Structure):
22+
pass
23+
24+
25+
OBX_store_p = ctypes.POINTER(OBX_store)
26+
27+
28+
class OBX_store_options(ctypes.Structure):
29+
_fields_ = [
30+
('directory', ctypes.c_char_p),
31+
('maxDbSizeInKByte', ctypes.c_uint64),
32+
('fileMode', ctypes.c_uint),
33+
('maxReaders', ctypes.c_uint)
34+
]
35+
36+
37+
OBX_store_options_p = ctypes.POINTER(OBX_store_options)
38+
39+
40+
class OBX_bytes(ctypes.Structure):
41+
_fields_ = [
42+
('data', ctypes.c_void_p),
43+
('size', ctypes.c_size_t),
44+
]
45+
46+
47+
OBX_bytes_p = ctypes.POINTER(OBX_bytes)
48+
49+
50+
class OBX_bytes_array(ctypes.Structure):
51+
_fields_ = [
52+
('data', ctypes.POINTER(OBX_bytes)),
53+
('count', ctypes.c_size_t),
54+
]
55+
56+
57+
OBX_bytes_array_p = ctypes.POINTER(OBX_bytes_array)
58+
59+
60+
class OBX_id_array(ctypes.Structure):
61+
_fields_ = [
62+
('ids', ctypes.POINTER(obx_id)),
63+
('count', ctypes.c_size_t),
64+
]
65+
66+
67+
OBX_id_array_p = ctypes.POINTER(OBX_id_array)
68+
69+
70+
class OBX_txn(ctypes.Structure):
71+
pass
72+
73+
74+
OBX_txn_p = ctypes.POINTER(OBX_txn)
75+
76+
77+
class OBX_box(ctypes.Structure):
78+
pass
79+
80+
81+
OBX_box_p = ctypes.POINTER(OBX_box)
82+
83+
84+
class OBX_async(ctypes.Structure):
85+
pass
86+
87+
88+
OBX_async_p = ctypes.POINTER(OBX_async)
89+
90+
91+
class OBX_query_builder(ctypes.Structure):
92+
pass
93+
94+
95+
OBX_query_builder_p = ctypes.POINTER(OBX_query_builder)
96+
97+
98+
class OBX_query(ctypes.Structure):
99+
pass
100+
101+
102+
OBX_query_p = ctypes.POINTER(OBX_query)
103+
104+
105+
# creates a global function "name" with the given restype & argtypes, calling C function with the same name
106+
def fn(name: str, restype: type, argtypes):
107+
func = C.__getattr__(name)
108+
109+
if restype == obx_err:
110+
# TODO func.errcheck
111+
pass
112+
else:
113+
func.restype = restype
114+
115+
func.argtypes = argtypes
116+
return func
117+
118+
119+
# OBX_model* obx_model_create(void);
120+
obx_model_create = fn('obx_model_create', OBX_model_p, [])
121+
122+
# obx_err obx_model_entity(OBX_model* model, const char* name, obx_schema_id entity_id, obx_uid entity_uid);
123+
obx_model_entity = fn('obx_model_entity', obx_err, [OBX_model_p, ctypes.c_char_p, obx_schema_id, obx_uid])

0 commit comments

Comments
 (0)