41 #include <sys/types.h> 49 #include <qb/qbipcc.h> 59 qb_ipcc_connection_t *
c;
66 qb_ipcc_connection_t *
c;
70 static void cmap_inst_free (
void *inst);
95 error =
hdb_error_to_cs(hdb_handle_create(&cmap_handle_t_db,
sizeof(*cmap_inst), handle));
97 goto error_no_destroy;
100 error =
hdb_error_to_cs(hdb_handle_get(&cmap_handle_t_db, *handle, (
void *)&cmap_inst));
101 if (error !=
CS_OK) {
108 if (cmap_inst->
c == NULL) {
110 goto error_put_destroy;
113 (void)hdb_handle_put(&cmap_handle_t_db, *handle);
118 (void)hdb_handle_put(&cmap_handle_t_db, *handle);
120 (void)hdb_handle_destroy(&cmap_handle_t_db, *handle);
125 static void cmap_inst_free (
void *inst)
128 qb_ipcc_disconnect(cmap_inst->
c);
138 error =
hdb_error_to_cs(hdb_handle_get(&cmap_handle_t_db, handle, (
void *)&cmap_inst));
139 if (error !=
CS_OK) {
144 (void)hdb_handle_put (&cmap_handle_t_db, handle);
152 hdb_iterator_reset(&cmap_track_handle_t_db);
153 while (hdb_iterator_next(&cmap_track_handle_t_db,
154 (
void*)&cmap_track_inst, &track_inst_handle) == 0) {
156 if (cmap_track_inst->
c == cmap_inst->
c) {
157 (void)hdb_handle_destroy(&cmap_track_handle_t_db, track_inst_handle);
160 (void)hdb_handle_put (&cmap_track_handle_t_db, track_inst_handle);
163 (void)hdb_handle_destroy(&cmap_handle_t_db, handle);
165 (void)hdb_handle_put(&cmap_handle_t_db, handle);
175 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
176 if (error !=
CS_OK) {
182 (void)hdb_handle_put (&cmap_handle_t_db, handle);
195 struct qb_ipc_response_header *dispatch_data;
202 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
203 if (error !=
CS_OK) {
215 dispatch_data = (
struct qb_ipc_response_header *)dispatch_buf;
242 if (error !=
CS_OK) {
249 switch (dispatch_data->id) {
251 res_lib_cmap_notify_callback = (
struct res_lib_cmap_notify_callback *)dispatch_data;
254 res_lib_cmap_notify_callback->track_inst_handle,
255 (
void *)&cmap_track_inst));
262 if (error !=
CS_OK) {
266 new_val.
type = res_lib_cmap_notify_callback->new_value_type;
267 old_val.
type = res_lib_cmap_notify_callback->old_value_type;
268 new_val.
len = res_lib_cmap_notify_callback->new_value_len;
269 old_val.
len = res_lib_cmap_notify_callback->old_value_len;
271 old_val.
data = (((
const char *)res_lib_cmap_notify_callback->
new_value) + new_val.
len);
275 res_lib_cmap_notify_callback->event,
276 (
char *)res_lib_cmap_notify_callback->key_name.value,
281 (void)hdb_handle_put(&cmap_track_handle_t_db, res_lib_cmap_notify_callback->track_inst_handle);
305 (void)hdb_handle_put (&cmap_handle_t_db, handle);
317 error =
hdb_error_to_cs(hdb_handle_get(&cmap_handle_t_db, handle, (
void *)&cmap_inst));
318 if (error !=
CS_OK) {
324 (void)hdb_handle_put (&cmap_handle_t_db, handle);
336 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
337 if (error !=
CS_OK) {
343 (void)hdb_handle_put (&cmap_handle_t_db, handle);
350 const char *key_name,
361 if (key_name == NULL || value == NULL) {
369 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
370 if (error !=
CS_OK) {
374 memset(&req_lib_cmap_set, 0,
sizeof(req_lib_cmap_set));
375 req_lib_cmap_set.header.size =
sizeof(req_lib_cmap_set) + value_len;
378 memcpy(req_lib_cmap_set.key_name.value, key_name, strlen(key_name));
379 req_lib_cmap_set.key_name.length = strlen(key_name);
381 req_lib_cmap_set.value_len = value_len;
382 req_lib_cmap_set.type =
type;
384 iov[0].iov_base = (
char *)&req_lib_cmap_set;
385 iov[0].iov_len =
sizeof(req_lib_cmap_set);
386 iov[1].iov_base = (
void *)value;
387 iov[1].iov_len = value_len;
396 if (error ==
CS_OK) {
397 error = res_lib_cmap_set.header.error;
400 (void)hdb_handle_put (&cmap_handle_t_db, handle);
473 if (key_name == NULL) {
480 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
481 if (error !=
CS_OK) {
485 memset(&req_lib_cmap_delete, 0,
sizeof(req_lib_cmap_delete));
486 req_lib_cmap_delete.header.size =
sizeof(req_lib_cmap_delete);
489 memcpy(req_lib_cmap_delete.key_name.value, key_name, strlen(key_name));
490 req_lib_cmap_delete.key_name.length = strlen(key_name);
492 iov.iov_base = (
char *)&req_lib_cmap_delete;
493 iov.iov_len =
sizeof(req_lib_cmap_delete);
499 &res_lib_cmap_delete,
502 if (error ==
CS_OK) {
503 error = res_lib_cmap_delete.header.error;
506 (void)hdb_handle_put (&cmap_handle_t_db, handle);
513 const char *key_name,
525 if (key_name == NULL) {
532 if (value != NULL && value_len == NULL) {
536 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
537 if (error !=
CS_OK) {
541 memset(&req_lib_cmap_get, 0,
sizeof(req_lib_cmap_get));
542 req_lib_cmap_get.header.size =
sizeof(req_lib_cmap_get);
545 memcpy(req_lib_cmap_get.key_name.value, key_name, strlen(key_name));
546 req_lib_cmap_get.key_name.length = strlen(key_name);
548 if (value != NULL && value_len != NULL) {
549 req_lib_cmap_get.value_len = *value_len;
551 req_lib_cmap_get.value_len = 0;
554 iov.iov_base = (
char *)&req_lib_cmap_get;
555 iov.iov_len =
sizeof(req_lib_cmap_get);
557 res_size =
sizeof(
struct res_lib_cmap_get) + req_lib_cmap_get.value_len;
559 res_lib_cmap_get = malloc(res_size);
560 if (res_lib_cmap_get == NULL) {
571 if (error ==
CS_OK) {
572 error = res_lib_cmap_get->header.error;
575 if (error ==
CS_OK) {
577 *type = res_lib_cmap_get->type;
580 if (value_len != NULL) {
581 *value_len = res_lib_cmap_get->value_len;
584 if (value != NULL && value_len != NULL) {
585 memcpy(value, res_lib_cmap_get->value, res_lib_cmap_get->value_len);
589 free(res_lib_cmap_get);
591 (void)hdb_handle_put (&cmap_handle_t_db, handle);
598 const char *key_name,
609 key_size =
sizeof(key_value);
610 memset(key_value, 0, key_size);
612 err =
cmap_get(handle, key_name, key_value, &key_size, &key_type);
616 if (key_type != type) {
620 memcpy(
value, key_value, value_size);
691 res =
cmap_get(handle, key_name, NULL, &str_len, &type);
701 *str = malloc(str_len);
708 res =
cmap_get(handle, key_name, *str, &str_len, &type);
729 if (key_name == NULL) {
736 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
737 if (error !=
CS_OK) {
741 memset(&req_lib_cmap_adjust_int, 0,
sizeof(req_lib_cmap_adjust_int));
742 req_lib_cmap_adjust_int.header.size =
sizeof(req_lib_cmap_adjust_int);
745 memcpy(req_lib_cmap_adjust_int.key_name.value, key_name, strlen(key_name));
746 req_lib_cmap_adjust_int.key_name.length = strlen(key_name);
748 req_lib_cmap_adjust_int.step = step;
750 iov.iov_base = (
char *)&req_lib_cmap_adjust_int;
751 iov.iov_len =
sizeof(req_lib_cmap_adjust_int);
757 &res_lib_cmap_adjust_int,
760 if (error ==
CS_OK) {
761 error = res_lib_cmap_adjust_int.header.error;
764 (void)hdb_handle_put (&cmap_handle_t_db, handle);
772 return (cmap_adjust_int(handle, key_name, 1));
778 return (cmap_adjust_int(handle, key_name, -1));
792 if (cmap_iter_handle == NULL) {
796 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
797 if (error !=
CS_OK) {
801 memset(&req_lib_cmap_iter_init, 0,
sizeof(req_lib_cmap_iter_init));
802 req_lib_cmap_iter_init.header.size =
sizeof(req_lib_cmap_iter_init);
809 memcpy(req_lib_cmap_iter_init.prefix.value, prefix, strlen(prefix));
810 req_lib_cmap_iter_init.prefix.length = strlen(prefix);
813 iov.iov_base = (
char *)&req_lib_cmap_iter_init;
814 iov.iov_len =
sizeof(req_lib_cmap_iter_init);
820 &res_lib_cmap_iter_init,
823 if (error ==
CS_OK) {
824 error = res_lib_cmap_iter_init.header.error;
827 if (error ==
CS_OK) {
828 *cmap_iter_handle = res_lib_cmap_iter_init.iter_handle;
831 (void)hdb_handle_put (&cmap_handle_t_db, handle);
849 if (key_name == NULL) {
853 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
854 if (error !=
CS_OK) {
858 memset(&req_lib_cmap_iter_next, 0,
sizeof(req_lib_cmap_iter_next));
859 req_lib_cmap_iter_next.header.size =
sizeof(req_lib_cmap_iter_next);
861 req_lib_cmap_iter_next.iter_handle = iter_handle;
863 iov.iov_base = (
char *)&req_lib_cmap_iter_next;
864 iov.iov_len =
sizeof(req_lib_cmap_iter_next);
870 &res_lib_cmap_iter_next,
873 if (error ==
CS_OK) {
874 error = res_lib_cmap_iter_next.header.error;
877 if (error ==
CS_OK) {
878 strncpy(key_name, (
const char *)res_lib_cmap_iter_next.key_name.value,
CMAP_KEYNAME_MAXLEN);
880 if (value_len != NULL) {
881 *value_len = res_lib_cmap_iter_next.value_len;
885 *type = res_lib_cmap_iter_next.type;
889 (void)hdb_handle_put (&cmap_handle_t_db, handle);
904 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
905 if (error !=
CS_OK) {
909 memset(&req_lib_cmap_iter_finalize, 0,
sizeof(req_lib_cmap_iter_finalize));
910 req_lib_cmap_iter_finalize.header.size =
sizeof(req_lib_cmap_iter_finalize);
912 req_lib_cmap_iter_finalize.iter_handle = iter_handle;
914 iov.iov_base = (
char *)&req_lib_cmap_iter_finalize;
915 iov.iov_len =
sizeof(req_lib_cmap_iter_finalize);
921 &res_lib_cmap_iter_finalize,
924 if (error ==
CS_OK) {
925 error = res_lib_cmap_iter_finalize.header.error;
928 (void)hdb_handle_put (&cmap_handle_t_db, handle);
935 const char *key_name,
949 if (cmap_track_handle == NULL || notify_fn == NULL) {
953 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
954 if (error !=
CS_OK) {
959 sizeof(*cmap_track_inst), &cmap_track_inst_handle));
960 if (error !=
CS_OK) {
965 cmap_track_inst_handle, (
void *)&cmap_track_inst));
966 if (error !=
CS_OK) {
967 goto error_put_destroy;
972 cmap_track_inst->
c = cmap_inst->
c;
974 memset(&req_lib_cmap_track_add, 0,
sizeof(req_lib_cmap_track_add));
975 req_lib_cmap_track_add.header.size =
sizeof(req_lib_cmap_track_add);
982 memcpy(req_lib_cmap_track_add.key_name.value, key_name, strlen(key_name));
983 req_lib_cmap_track_add.key_name.length = strlen(key_name);
986 req_lib_cmap_track_add.track_type = track_type;
987 req_lib_cmap_track_add.track_inst_handle = cmap_track_inst_handle;
989 iov.iov_base = (
char *)&req_lib_cmap_track_add;
990 iov.iov_len =
sizeof(req_lib_cmap_track_add);
996 &res_lib_cmap_track_add,
999 if (error ==
CS_OK) {
1000 error = res_lib_cmap_track_add.header.error;
1003 if (error ==
CS_OK) {
1004 *cmap_track_handle = res_lib_cmap_track_add.track_handle;
1008 (void)hdb_handle_put (&cmap_track_handle_t_db, cmap_track_inst_handle);
1010 (void)hdb_handle_put (&cmap_handle_t_db, handle);
1015 (void)hdb_handle_put (&cmap_track_handle_t_db, cmap_track_inst_handle);
1016 (void)hdb_handle_destroy (&cmap_track_handle_t_db, cmap_track_inst_handle);
1019 (void)hdb_handle_put (&cmap_handle_t_db, handle);
1035 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
1036 if (error !=
CS_OK) {
1040 memset(&req_lib_cmap_track_delete, 0,
sizeof(req_lib_cmap_track_delete));
1041 req_lib_cmap_track_delete.header.size =
sizeof(req_lib_cmap_track_delete);
1043 req_lib_cmap_track_delete.track_handle = track_handle;
1045 iov.iov_base = (
char *)&req_lib_cmap_track_delete;
1046 iov.iov_len =
sizeof(req_lib_cmap_track_delete);
1052 &res_lib_cmap_track_delete,
1055 if (error ==
CS_OK) {
1056 error = res_lib_cmap_track_delete.header.error;
1059 if (error ==
CS_OK) {
1061 res_lib_cmap_track_delete.track_inst_handle,
1062 (
void *)&cmap_track_inst));
1063 if (error !=
CS_OK) {
1067 (void)hdb_handle_put(&cmap_track_handle_t_db, res_lib_cmap_track_delete.track_inst_handle);
1068 (void)hdb_handle_destroy(&cmap_track_handle_t_db, res_lib_cmap_track_delete.track_inst_handle);
1072 (void)hdb_handle_put (&cmap_handle_t_db, handle);
cs_error_t cmap_set_uint64(cmap_handle_t handle, const char *key_name, uint64_t value)
The res_lib_cmap_track_add struct.
cs_error_t cmap_get_uint8(cmap_handle_t handle, const char *key_name, uint8_t *u8)
cs_error_t cmap_set_uint32(cmap_handle_t handle, const char *key_name, uint32_t value)
cs_error_t cmap_set(cmap_handle_t handle, const char *key_name, const void *value, size_t value_len, cmap_value_types_t type)
Store value in cmap.
The res_lib_cmap_iter_finalize struct.
cs_error_t cmap_track_add(cmap_handle_t handle, const char *key_name, int32_t track_type, cmap_notify_fn_t notify_fn, void *user_data, cmap_track_handle_t *cmap_track_handle)
Add tracking function for given key_name.
cs_error_t hdb_error_to_cs(int res)
The res_lib_cmap_iter_next struct.
cs_error_t cmap_iter_next(cmap_handle_t handle, cmap_iter_handle_t iter_handle, char key_name[], size_t *value_len, cmap_value_types_t *type)
Return next item in iterator iter.
cs_error_t cmap_initialize(cmap_handle_t *handle)
Create a new cmap connection.
The res_lib_cmap_adjust_int struct.
The req_lib_cmap_iter_finalize struct.
#define CMAP_KEYNAME_MAXLEN
cs_error_t cmap_get_uint16(cmap_handle_t handle, const char *key_name, uint16_t *u16)
cs_error_t cmap_iter_init(cmap_handle_t handle, const char *prefix, cmap_iter_handle_t *cmap_iter_handle)
Initialize iterator with given prefix.
cs_error_t cmap_get_int64(cmap_handle_t handle, const char *key_name, int64_t *i64)
cs_error_t cmap_inc(cmap_handle_t handle, const char *key_name)
Increment value of key_name if it is [u]int* type.
The req_lib_cmap_iter_next struct.
cs_error_t cmap_track_delete(cmap_handle_t handle, cmap_track_handle_t track_handle)
Delete track created previously by cmap_track_add.
Structure passed as new_value and old_value in change callback.
void(* cmap_notify_fn_t)(cmap_handle_t cmap_handle, cmap_track_handle_t cmap_track_handle, int32_t event, const char *key_name, struct cmap_notify_value new_value, struct cmap_notify_value old_value, void *user_data)
Prototype for notify callback function.
cs_error_t cmap_iter_finalize(cmap_handle_t handle, cmap_iter_handle_t iter_handle)
Finalize iterator.
cs_error_t cmap_get(cmap_handle_t handle, const char *key_name, void *value, size_t *value_len, cmap_value_types_t *type)
Retrieve value of key key_name and store it in user preallocated value pointer.
#define IPC_DISPATCH_SIZE
cs_error_t cmap_get_double(cmap_handle_t handle, const char *key_name, double *dbl)
The res_lib_cmap_iter_init struct.
The req_lib_cmap_track_add struct.
The res_lib_cmap_notify_callback struct.
cs_error_t cmap_set_double(cmap_handle_t handle, const char *key_name, double value)
cs_error_t cmap_get_uint32(cmap_handle_t handle, const char *key_name, uint32_t *u32)
cs_error_t cmap_get_float(cmap_handle_t handle, const char *key_name, float *flt)
cs_error_t cmap_get_uint64(cmap_handle_t handle, const char *key_name, uint64_t *u64)
cs_error_t
The cs_error_t enum.
uint64_t cmap_track_handle_t
cs_dispatch_flags_t
The cs_dispatch_flags_t enum.
cs_error_t cmap_set_string(cmap_handle_t handle, const char *key_name, const char *value)
The res_lib_cmap_track_delete struct.
cs_error_t cmap_set_uint8(cmap_handle_t handle, const char *key_name, uint8_t value)
The res_lib_cmap_delete struct.
The req_lib_cmap_iter_init struct.
cs_error_t cmap_get_string(cmap_handle_t handle, const char *key_name, char **str)
Shortcut for cmap_get for string type.
The req_lib_cmap_track_delete struct.
cs_error_t cmap_delete(cmap_handle_t handle, const char *key_name)
Deletes key from cmap database.
cs_error_t cmap_dispatch(cmap_handle_t handle, cs_dispatch_flags_t dispatch_types)
Dispatch data from service.
cmap_notify_fn_t notify_fn
cmap_track_handle_t track_handle
DECLARE_HDB_DATABASE(cmap_handle_t_db, cmap_inst_free)
#define CS_MAX_NAME_LENGTH
uint64_t cmap_iter_handle_t
The req_lib_cmap_delete struct.
cs_error_t cmap_fd_get(cmap_handle_t handle, int *fd)
Get a file descriptor on which to poll.
cs_error_t cmap_set_int64(cmap_handle_t handle, const char *key_name, int64_t value)
The res_lib_cmap_set struct.
cs_error_t cmap_get_int8(cmap_handle_t handle, const char *key_name, int8_t *i8)
cmap_value_types_t
Possible types of value.
cs_error_t cmap_set_int32(cmap_handle_t handle, const char *key_name, int32_t value)
cs_error_t cmap_context_set(cmap_handle_t handle, const void *context)
cmap_context_set
cs_error_t cmap_finalize(cmap_handle_t handle)
Close the cmap handle.
cs_error_t cmap_get_int32(cmap_handle_t handle, const char *key_name, int32_t *i32)
cs_error_t cmap_dec(cmap_handle_t handle, const char *key_name)
Decrement value of key_name if it is [u]int* type.
The req_lib_cmap_adjust_int struct.
cs_error_t cmap_set_uint16(cmap_handle_t handle, const char *key_name, uint16_t value)
The res_lib_cmap_get struct.
cs_error_t cmap_context_get(cmap_handle_t handle, const void **context)
cmap_context_get
The req_lib_cmap_set struct.
#define CS_IPC_TIMEOUT_MS
cs_error_t qb_to_cs_error(int result)
qb_to_cs_error
cs_error_t cmap_set_int8(cmap_handle_t handle, const char *key_name, int8_t value)
The req_lib_cmap_get struct.
cs_error_t cmap_get_int16(cmap_handle_t handle, const char *key_name, int16_t *i16)
cs_error_t cmap_set_int16(cmap_handle_t handle, const char *key_name, int16_t value)
cs_error_t cmap_set_float(cmap_handle_t handle, const char *key_name, float value)