Skip to content

Commit 48a70ff

Browse files
committed
c: bubble up obx_opt_* funcs #41
Except obx_opt_log_callback
1 parent 84740e9 commit 48a70ff

1 file changed

Lines changed: 135 additions & 18 deletions

File tree

objectbox/c.py

Lines changed: 135 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,13 @@ def shlib_name(library: str) -> str:
7676
OBXPropertyFlags = ctypes.c_int
7777
OBXDebugFlags = ctypes.c_int
7878
OBXPutMode = ctypes.c_int
79+
OBXPutPaddingMode = ctypes.c_int
7980
OBXOrderFlags = ctypes.c_int
8081
OBXHnswFlags = ctypes.c_int
8182
OBXHnswDistanceType = ctypes.c_int
83+
OBXValidateOnOpenPagesFlags = ctypes.c_int
84+
OBXValidateOnOpenKvFlags = ctypes.c_int
85+
OBXBackupRestoreFlags = ctypes.c_int
8286

8387

8488
class OBX_model(ctypes.Structure):
@@ -292,6 +296,7 @@ def c_fn(name: str, restype: Optional[type], argtypes):
292296

293297
return func
294298

299+
295300
# creates a global function "name" with the given restype & argtypes, calling C function with the same name.
296301
# no error checking is done on restype as this is defered to higher-level functions.
297302
def c_fn_nocheck(name: str, restype: type, argtypes):
@@ -300,6 +305,7 @@ def c_fn_nocheck(name: str, restype: type, argtypes):
300305
func.restype = restype
301306
return func
302307

308+
303309
# like c_fn, but for functions returning obx_err
304310
def c_fn_rc(name: str, argtypes):
305311
""" Like c_fn, but for functions returning obx_err (checks obx_err validity). """
@@ -309,6 +315,7 @@ def c_fn_rc(name: str, argtypes):
309315
func.errcheck = check_obx_err
310316
return func
311317

318+
312319
def c_fn_qb_cond(name: str, argtypes):
313320
""" Like c_fn, but for functions returning obx_qb_cond (checks obx_qb_cond validity). """
314321
func = C.__getattr__(name)
@@ -417,28 +424,119 @@ def c_array_pointer(py_list: Union[List[Any], np.ndarray], c_type):
417424
# OBX_store_options* ();
418425
obx_opt = c_fn('obx_opt', OBX_store_options_p, [])
419426

420-
# obx_err (OBX_store_options* opt, const char* dir);
421-
obx_opt_directory = c_fn_rc('obx_opt_directory', [
422-
OBX_store_options_p, ctypes.c_char_p])
427+
# OBX_C_API obx_err obx_opt_directory(OBX_store_options* opt, const char* dir);
428+
obx_opt_directory = c_fn_rc('obx_opt_directory', [OBX_store_options_p, ctypes.c_char_p])
429+
430+
# OBX_C_API void obx_opt_max_db_size_in_kb(OBX_store_options* opt, uint64_t size_in_kb);
431+
obx_opt_max_db_size_in_kb = c_fn('obx_opt_max_db_size_in_kb', None, [OBX_store_options_p, ctypes.c_uint64])
432+
433+
# OBX_C_API void obx_opt_max_data_size_in_kb(OBX_store_options* opt, uint64_t size_in_kb);
434+
obx_opt_max_data_size_in_kb = c_fn('obx_opt_max_data_size_in_kb', None, [OBX_store_options_p, ctypes.c_uint64])
435+
436+
# OBX_C_API void obx_opt_file_mode(OBX_store_options* opt, unsigned int file_mode);
437+
obx_opt_file_mode = c_fn('obx_opt_file_mode', None, [OBX_store_options_p, ctypes.c_uint32])
438+
439+
# OBX_C_API void obx_opt_max_readers(OBX_store_options* opt, unsigned int max_readers);
440+
obx_opt_max_readers = c_fn('obx_opt_max_readers', None, [OBX_store_options_p, ctypes.c_uint32])
441+
442+
# OBX_C_API void obx_opt_no_reader_thread_locals(OBX_store_options* opt, bool flag);
443+
obx_opt_no_reader_thread_locals = c_fn('obx_opt_no_reader_thread_locals', None, [OBX_store_options_p, ctypes.c_bool])
444+
445+
# OBX_C_API obx_err obx_opt_model(OBX_store_options* opt, OBX_model* model);
446+
obx_opt_model = c_fn_rc('obx_opt_model', [OBX_store_options_p, OBX_model_p])
447+
448+
# OBX_C_API obx_err obx_opt_model_bytes(OBX_store_options* opt, const void* bytes, size_t size);
449+
obx_opt_model_bytes = c_fn_rc('obx_opt_model_bytes', [OBX_store_options_p, ctypes.c_void_p, ctypes.c_size_t])
450+
451+
# OBX_C_API obx_err obx_opt_model_bytes_direct(OBX_store_options* opt, const void* bytes, size_t size);
452+
obx_opt_model_bytes_direct = c_fn_rc('obx_opt_model_bytes_direct', [OBX_store_options_p, ctypes.c_void_p, ctypes.c_size_t])
453+
454+
# OBX_C_API void obx_opt_validate_on_open_pages(OBX_store_options* opt, size_t page_limit, uint32_t flags);
455+
obx_opt_validate_on_open_pages = c_fn('obx_opt_validate_on_open_pages', None, [OBX_store_options_p, ctypes.c_size_t, OBXValidateOnOpenPagesFlags])
456+
457+
# OBX_C_API void obx_opt_validate_on_open_kv(OBX_store_options* opt, uint32_t flags);
458+
obx_opt_validate_on_open_kv = c_fn('obx_opt_validate_on_open_kv', None, [OBX_store_options_p, OBXValidateOnOpenKvFlags])
459+
460+
# OBX_C_API void obx_opt_put_padding_mode(OBX_store_options* opt, OBXPutPaddingMode mode);
461+
obx_opt_put_padding_mode = c_fn('obx_opt_put_padding_mode', None, [OBX_store_options_p, OBXPutPaddingMode])
462+
463+
# OBX_C_API void obx_opt_read_schema(OBX_store_options* opt, bool value);
464+
obx_opt_read_schema = c_fn('obx_opt_read_schema', None, [OBX_store_options_p, ctypes.c_bool])
465+
466+
# OBX_C_API void obx_opt_use_previous_commit(OBX_store_options* opt, bool value);
467+
obx_opt_use_previous_commit = c_fn('obx_opt_use_previous_commit', None, [OBX_store_options_p, ctypes.c_bool])
468+
469+
# OBX_C_API void obx_opt_read_only(OBX_store_options* opt, bool value);
470+
obx_opt_read_only = c_fn('obx_opt_read_only', None, [OBX_store_options_p, ctypes.c_bool])
471+
472+
# OBX_C_API void obx_opt_debug_flags(OBX_store_options* opt, uint32_t flags);
473+
obx_opt_debug_flags = c_fn('obx_opt_debug_flags', None, [OBX_store_options_p, OBXDebugFlags])
474+
475+
# OBX_C_API void obx_opt_add_debug_flags(OBX_store_options* opt, uint32_t flags);
476+
obx_opt_add_debug_flags = c_fn('obx_opt_add_debug_flags', None, [OBX_store_options_p, ctypes.c_uint32])
477+
478+
# OBX_C_API void obx_opt_async_max_queue_length(OBX_store_options* opt, size_t value);
479+
obx_opt_async_max_queue_length = c_fn('obx_opt_async_max_queue_length', None, [OBX_store_options_p, ctypes.c_size_t])
423480

424-
# void (OBX_store_options* opt, size_t size_in_kb);
425-
obx_opt_max_db_size_in_kb = c_fn('obx_opt_max_db_size_in_kb', None, [
426-
OBX_store_options_p, ctypes.c_size_t])
481+
# OBX_C_API void obx_opt_async_throttle_at_queue_length(OBX_store_options* opt, size_t value);
482+
obx_opt_async_throttle_at_queue_length = c_fn('obx_opt_async_throttle_at_queue_length', None, [OBX_store_options_p, ctypes.c_size_t])
427483

428-
# void (OBX_store_options* opt, int file_mode);
429-
obx_opt_file_mode = c_fn('obx_opt_file_mode', None, [
430-
OBX_store_options_p, ctypes.c_uint])
484+
# OBX_C_API void obx_opt_async_throttle_micros(OBX_store_options* opt, uint32_t value);
485+
obx_opt_async_throttle_micros = c_fn('obx_opt_async_throttle_micros', None, [OBX_store_options_p, ctypes.c_uint32])
431486

432-
# void (OBX_store_options* opt, int max_readers);
433-
obx_opt_max_readers = c_fn('obx_opt_max_readers', None, [
434-
OBX_store_options_p, ctypes.c_uint])
487+
# OBX_C_API void obx_opt_async_max_in_tx_duration(OBX_store_options* opt, uint32_t micros);
488+
obx_opt_async_max_in_tx_duration = c_fn('obx_opt_async_max_in_tx_duration', None, [OBX_store_options_p, ctypes.c_uint32])
435489

436-
# obx_err (OBX_store_options* opt, OBX_model* model);
437-
obx_opt_model = c_fn_rc('obx_opt_model', [
438-
OBX_store_options_p, OBX_model_p])
490+
# OBX_C_API void obx_opt_async_max_in_tx_operations(OBX_store_options* opt, uint32_t value);
491+
obx_opt_async_max_in_tx_operations = c_fn('obx_opt_async_max_in_tx_operations', None, [OBX_store_options_p, ctypes.c_uint32])
439492

440-
# void (OBX_store_options* opt);
441-
obx_opt_free = c_fn('obx_opt_free', None, [OBX_store_options_p])
493+
# OBX_C_API void obx_opt_async_pre_txn_delay(OBX_store_options* opt, uint32_t delay_micros);
494+
obx_opt_async_pre_txn_delay = c_fn('obx_opt_async_pre_txn_delay', None, [OBX_store_options_p, ctypes.c_uint32])
495+
496+
# OBX_C_API void obx_opt_async_pre_txn_delay4(OBX_store_options* opt, uint32_t delay_micros, uint32_t delay2_micros, size_t min_queue_length_for_delay2);
497+
obx_opt_async_pre_txn_delay4 = c_fn('obx_opt_async_pre_txn_delay4', None, [OBX_store_options_p, ctypes.c_uint32, ctypes.c_uint32, ctypes.c_size_t])
498+
499+
# OBX_C_API void obx_opt_async_post_txn_delay(OBX_store_options* opt, uint32_t delay_micros);
500+
obx_opt_async_post_txn_delay = c_fn('obx_opt_async_post_txn_delay', None, [OBX_store_options_p, ctypes.c_uint32])
501+
502+
# OBX_C_API void obx_opt_async_post_txn_delay5(OBX_store_options* opt, uint32_t delay_micros, uint32_t delay2_micros, size_t min_queue_length_for_delay2, bool subtract_processing_time);
503+
obx_opt_async_post_txn_delay5 = c_fn('obx_opt_async_post_txn_delay5', None, [OBX_store_options_p, ctypes.c_uint32, ctypes.c_uint32, ctypes.c_size_t, ctypes.c_bool])
504+
505+
# OBX_C_API void obx_opt_async_minor_refill_threshold(OBX_store_options* opt, size_t queue_length);
506+
obx_opt_async_minor_refill_threshold = c_fn('obx_opt_async_minor_refill_threshold', None, [OBX_store_options_p, ctypes.c_size_t])
507+
508+
# OBX_C_API void obx_opt_async_minor_refill_max_count(OBX_store_options* opt, uint32_t value);
509+
obx_opt_async_minor_refill_max_count = c_fn('obx_opt_async_minor_refill_max_count', None, [OBX_store_options_p, ctypes.c_uint32])
510+
511+
# OBX_C_API void obx_opt_async_max_tx_pool_size(OBX_store_options* opt, size_t value);
512+
obx_opt_async_max_tx_pool_size = c_fn('obx_opt_async_max_tx_pool_size', None, [OBX_store_options_p, ctypes.c_size_t])
513+
514+
# OBX_C_API void obx_opt_async_object_bytes_max_cache_size(OBX_store_options* opt, uint64_t value);
515+
obx_opt_async_object_bytes_max_cache_size = c_fn('obx_opt_async_object_bytes_max_cache_size', None, [OBX_store_options_p, ctypes.c_uint64])
516+
517+
# OBX_C_API void obx_opt_async_object_bytes_max_size_to_cache(OBX_store_options* opt, uint64_t value);
518+
obx_opt_async_object_bytes_max_size_to_cache = c_fn('obx_opt_async_object_bytes_max_size_to_cache', None, [OBX_store_options_p, ctypes.c_uint64])
519+
520+
# OBX_C_API void obx_opt_log_callback(OBX_store_options* opt, obx_log_callback* callback, void* user_data);
521+
# obx_opt_log_callback = c_fn('obx_opt_log_callback', None, [OBX_store_options_p, ...]) TODO
522+
523+
# OBX_C_API void obx_opt_backup_restore(OBX_store_options* opt, const char* backup_file, uint32_t flags);
524+
obx_opt_backup_restore = c_fn('obx_opt_backup_restore', None, [OBX_store_options_p, ctypes.c_char_p, OBXBackupRestoreFlags])
525+
526+
# OBX_C_API const char* obx_opt_get_directory(OBX_store_options* opt);
527+
obx_opt_get_directory = c_fn('obx_opt_get_directory', ctypes.c_char_p, [OBX_store_options_p])
528+
529+
# OBX_C_API uint64_t obx_opt_get_max_db_size_in_kb(OBX_store_options* opt);
530+
obx_opt_get_max_db_size_in_kb = c_fn('obx_opt_get_max_db_size_in_kb', ctypes.c_uint64, [OBX_store_options_p])
531+
532+
# OBX_C_API uint64_t obx_opt_get_max_data_size_in_kb(OBX_store_options* opt);
533+
obx_opt_get_max_data_size_in_kb = c_fn('obx_opt_get_max_data_size_in_kb', ctypes.c_uint64, [OBX_store_options_p])
534+
535+
# OBX_C_API uint32_t obx_opt_get_debug_flags(OBX_store_options* opt);
536+
obx_opt_get_debug_flags = c_fn('obx_opt_get_debug_flags', ctypes.c_uint32, [OBX_store_options_p])
537+
538+
# OBX_C_API void obx_opt_free(OBX_store_options* opt);
539+
obx_opt_free = c_fn('obx_opt_free', None, [])
442540

443541
# OBX_store* (const OBX_store_options* options);
444542
obx_store_open = c_fn('obx_store_open', OBX_store_p, [OBX_store_options_p])
@@ -705,7 +803,9 @@ def c_array_pointer(py_list: Union[List[Any], np.ndarray], c_type):
705803
ctypes.c_size_t])
706804

707805
# OBX_C_API obx_err obx_query_param_alias_vector_float32(OBX_query* query, const char* alias, const float* value, size_t element_count);
708-
obx_query_param_alias_vector_float32 = c_fn_rc('obx_query_param_alias_vector_float32', [OBX_query_p, ctypes.c_char_p, ctypes.POINTER(ctypes.c_float), ctypes.c_size_t])
806+
obx_query_param_alias_vector_float32 = c_fn_rc('obx_query_param_alias_vector_float32',
807+
[OBX_query_p, ctypes.c_char_p, ctypes.POINTER(ctypes.c_float),
808+
ctypes.c_size_t])
709809

710810
# OBX_C_API obx_err obx_query_param_alias_string(OBX_query* query, const char* alias, const char* value);
711811
obx_query_param_alias_string = c_fn_rc('obx_query_param_alias_string', [OBX_query_p, ctypes.c_char_p, ctypes.c_char_p])
@@ -838,6 +938,11 @@ def c_array_pointer(py_list: Union[List[Any], np.ndarray], c_type):
838938
OBXDebugFlags_LOG_QUERIES = 4
839939
OBXDebugFlags_LOG_QUERY_PARAMETERS = 8
840940
OBXDebugFlags_LOG_ASYNC_QUEUE = 16
941+
OBXDebugFlags_LOG_CACHE_HITS = 32
942+
OBXDebugFlags_LOG_CACHE_ALL = 64
943+
OBXDebugFlags_LOG_TREE = 128
944+
OBXDebugFlags_LOG_EXCEPTION_STACK_TRACE = 256
945+
OBXDebugFlags_RUN_THREADING_SELF_TEST = 512
841946

842947
# Standard put ("insert or update")
843948
OBXPutMode_PUT = 1
@@ -880,3 +985,15 @@ def c_array_pointer(py_list: Union[List[Any], np.ndarray], c_type):
880985
OBXHnswDistanceType_COSINE = 2
881986
OBXHnswDistanceType_DOT_PRODUCT = 3
882987
OBXHnswDistanceType_DOT_PRODUCT_NON_NORMALIZED = 10
988+
989+
OBXPutPaddingMode_PaddingAutomatic = 1
990+
OBXPutPaddingMode_PaddingAllowedByBuffer = 2
991+
OBXPutPaddingMode_PaddingByCaller = 3
992+
993+
OBXValidateOnOpenPagesFlags_None = 0
994+
OBXValidateOnOpenPagesFlags_VisitLeafPages = 1
995+
996+
OBXValidateOnOpenKvFlags_None = 0
997+
998+
OBXBackupRestoreFlags_None = 0
999+
OBXBackupRestoreFlags_OverwriteExistingData = 1

0 commit comments

Comments
 (0)