41 #include <sys/types.h>
48 #include <qb/qbipcc.h>
58 qb_ipcc_connection_t *
c;
65 qb_ipcc_connection_t *
c;
69 static void cmap_inst_free (
void *inst);
94 error =
hdb_error_to_cs(hdb_handle_create(&cmap_handle_t_db,
sizeof(*cmap_inst), handle));
96 goto error_no_destroy;
99 error =
hdb_error_to_cs(hdb_handle_get(&cmap_handle_t_db, *handle, (
void *)&cmap_inst));
100 if (error !=
CS_OK) {
107 if (cmap_inst->
c == NULL) {
109 goto error_put_destroy;
112 (void)hdb_handle_put(&cmap_handle_t_db, *handle);
117 (void)hdb_handle_put(&cmap_handle_t_db, *handle);
119 (void)hdb_handle_destroy(&cmap_handle_t_db, *handle);
131 struct qb_ipc_response_header res_lib_cmap_set_current_map;
135 if (error ==
CS_OK) {
136 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, *handle, (
void *)&cmap_inst));
137 if (error !=
CS_OK) {
141 memset(&req_lib_cmap_set_current_map, 0,
sizeof(req_lib_cmap_set_current_map));
142 req_lib_cmap_set_current_map.header.size =
sizeof(req_lib_cmap_set_current_map);
144 req_lib_cmap_set_current_map.map = map;
146 iov[0].iov_base = (
char *)&req_lib_cmap_set_current_map;
147 iov[0].iov_len =
sizeof(req_lib_cmap_set_current_map);
153 &res_lib_cmap_set_current_map,
156 if (error ==
CS_OK) {
157 error = res_lib_cmap_set_current_map.error;
160 (void)hdb_handle_put (&cmap_handle_t_db, *handle);
167 static void cmap_inst_free (
void *inst)
170 qb_ipcc_disconnect(cmap_inst->
c);
180 error =
hdb_error_to_cs(hdb_handle_get(&cmap_handle_t_db, handle, (
void *)&cmap_inst));
181 if (error !=
CS_OK) {
186 (void)hdb_handle_put (&cmap_handle_t_db, handle);
194 hdb_iterator_reset(&cmap_track_handle_t_db);
195 while (hdb_iterator_next(&cmap_track_handle_t_db,
196 (
void*)&cmap_track_inst, &track_inst_handle) == 0) {
198 if (cmap_track_inst->
c == cmap_inst->
c) {
199 (void)hdb_handle_destroy(&cmap_track_handle_t_db, track_inst_handle);
202 (void)hdb_handle_put (&cmap_track_handle_t_db, track_inst_handle);
205 (void)hdb_handle_destroy(&cmap_handle_t_db, handle);
207 (void)hdb_handle_put(&cmap_handle_t_db, handle);
217 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
218 if (error !=
CS_OK) {
224 (void)hdb_handle_put (&cmap_handle_t_db, handle);
237 struct qb_ipc_response_header *dispatch_data;
244 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
245 if (error !=
CS_OK) {
257 dispatch_data = (
struct qb_ipc_response_header *)dispatch_buf;
284 if (error !=
CS_OK) {
291 switch (dispatch_data->id) {
293 res_lib_cmap_notify_callback = (
struct res_lib_cmap_notify_callback *)dispatch_data;
296 res_lib_cmap_notify_callback->track_inst_handle,
297 (
void *)&cmap_track_inst));
304 if (error !=
CS_OK) {
308 new_val.
type = res_lib_cmap_notify_callback->new_value_type;
309 old_val.
type = res_lib_cmap_notify_callback->old_value_type;
310 new_val.
len = res_lib_cmap_notify_callback->new_value_len;
311 old_val.
len = res_lib_cmap_notify_callback->old_value_len;
313 old_val.
data = (((
const char *)res_lib_cmap_notify_callback->
new_value) + new_val.
len);
317 res_lib_cmap_notify_callback->event,
318 (
char *)res_lib_cmap_notify_callback->key_name.value,
323 (void)hdb_handle_put(&cmap_track_handle_t_db, res_lib_cmap_notify_callback->track_inst_handle);
347 (void)hdb_handle_put (&cmap_handle_t_db, handle);
354 const void **context)
359 error =
hdb_error_to_cs(hdb_handle_get(&cmap_handle_t_db, handle, (
void *)&cmap_inst));
360 if (error !=
CS_OK) {
366 (void)hdb_handle_put (&cmap_handle_t_db, handle);
378 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
379 if (error !=
CS_OK) {
385 (void)hdb_handle_put (&cmap_handle_t_db, handle);
392 const char *key_name,
403 if (key_name == NULL || value == NULL) {
411 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
412 if (error !=
CS_OK) {
416 memset(&req_lib_cmap_set, 0,
sizeof(req_lib_cmap_set));
417 req_lib_cmap_set.header.size =
sizeof(req_lib_cmap_set) + value_len;
420 memcpy(req_lib_cmap_set.key_name.value, key_name, strlen(key_name));
421 req_lib_cmap_set.key_name.length = strlen(key_name);
423 req_lib_cmap_set.value_len = value_len;
424 req_lib_cmap_set.type =
type;
426 iov[0].iov_base = (
char *)&req_lib_cmap_set;
427 iov[0].iov_len =
sizeof(req_lib_cmap_set);
428 iov[1].iov_base = (
void *)value;
429 iov[1].iov_len = value_len;
438 if (error ==
CS_OK) {
439 error = res_lib_cmap_set.header.error;
442 (void)hdb_handle_put (&cmap_handle_t_db, handle);
515 if (key_name == NULL) {
522 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
523 if (error !=
CS_OK) {
527 memset(&req_lib_cmap_delete, 0,
sizeof(req_lib_cmap_delete));
528 req_lib_cmap_delete.header.size =
sizeof(req_lib_cmap_delete);
531 memcpy(req_lib_cmap_delete.key_name.value, key_name, strlen(key_name));
532 req_lib_cmap_delete.key_name.length = strlen(key_name);
534 iov.iov_base = (
char *)&req_lib_cmap_delete;
535 iov.iov_len =
sizeof(req_lib_cmap_delete);
541 &res_lib_cmap_delete,
544 if (error ==
CS_OK) {
545 error = res_lib_cmap_delete.header.error;
548 (void)hdb_handle_put (&cmap_handle_t_db, handle);
555 const char *key_name,
567 if (key_name == NULL) {
574 if (value != NULL && value_len == NULL) {
578 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
579 if (error !=
CS_OK) {
583 memset(&req_lib_cmap_get, 0,
sizeof(req_lib_cmap_get));
584 req_lib_cmap_get.header.size =
sizeof(req_lib_cmap_get);
587 memcpy(req_lib_cmap_get.key_name.value, key_name, strlen(key_name));
588 req_lib_cmap_get.key_name.length = strlen(key_name);
590 if (value != NULL && value_len != NULL) {
591 req_lib_cmap_get.value_len = *value_len;
593 req_lib_cmap_get.value_len = 0;
596 iov.iov_base = (
char *)&req_lib_cmap_get;
597 iov.iov_len =
sizeof(req_lib_cmap_get);
599 res_size =
sizeof(
struct res_lib_cmap_get) + req_lib_cmap_get.value_len;
601 res_lib_cmap_get = malloc(res_size);
602 if (res_lib_cmap_get == NULL) {
613 if (error ==
CS_OK) {
614 error = res_lib_cmap_get->header.error;
617 if (error ==
CS_OK) {
619 *type = res_lib_cmap_get->type;
622 if (value_len != NULL) {
623 *value_len = res_lib_cmap_get->value_len;
626 if (value != NULL && value_len != NULL) {
627 memcpy(value, res_lib_cmap_get->value, res_lib_cmap_get->value_len);
631 free(res_lib_cmap_get);
633 (void)hdb_handle_put (&cmap_handle_t_db, handle);
640 const char *key_name,
651 key_size =
sizeof(key_value);
652 memset(key_value, 0, key_size);
654 err =
cmap_get(handle, key_name, key_value, &key_size, &key_type);
658 if (key_type != type) {
662 memcpy(value, key_value, value_size);
733 res =
cmap_get(handle, key_name, NULL, &str_len, &type);
743 *str = malloc(str_len);
750 res =
cmap_get(handle, key_name, *str, &str_len, &type);
771 if (key_name == NULL) {
778 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
779 if (error !=
CS_OK) {
802 if (error ==
CS_OK) {
806 (void)hdb_handle_put (&cmap_handle_t_db, handle);
814 return (cmap_adjust_int(handle, key_name, 1));
820 return (cmap_adjust_int(handle, key_name, -1));
830 struct cmap_inst *cmap_inst;
834 if (cmap_iter_handle == NULL) {
838 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
839 if (error !=
CS_OK) {
843 memset(&req_lib_cmap_iter_init, 0,
sizeof(req_lib_cmap_iter_init));
844 req_lib_cmap_iter_init.header.size =
sizeof(req_lib_cmap_iter_init);
851 memcpy(req_lib_cmap_iter_init.prefix.value, prefix, strlen(prefix));
852 req_lib_cmap_iter_init.prefix.length = strlen(prefix);
855 iov.iov_base = (
char *)&req_lib_cmap_iter_init;
856 iov.iov_len =
sizeof(req_lib_cmap_iter_init);
862 &res_lib_cmap_iter_init,
865 if (error ==
CS_OK) {
866 error = res_lib_cmap_iter_init.header.error;
869 if (error ==
CS_OK) {
870 *cmap_iter_handle = res_lib_cmap_iter_init.iter_handle;
873 (void)hdb_handle_put (&cmap_handle_t_db, handle);
887 struct cmap_inst *cmap_inst;
891 if (key_name == NULL) {
895 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
896 if (error !=
CS_OK) {
900 memset(&req_lib_cmap_iter_next, 0,
sizeof(req_lib_cmap_iter_next));
901 req_lib_cmap_iter_next.header.size =
sizeof(req_lib_cmap_iter_next);
903 req_lib_cmap_iter_next.iter_handle = iter_handle;
905 iov.iov_base = (
char *)&req_lib_cmap_iter_next;
906 iov.iov_len =
sizeof(req_lib_cmap_iter_next);
912 &res_lib_cmap_iter_next,
915 if (error ==
CS_OK) {
916 error = res_lib_cmap_iter_next.header.error;
919 if (error ==
CS_OK) {
920 memcpy(key_name, (
const char *)res_lib_cmap_iter_next.key_name.value,
921 res_lib_cmap_iter_next.key_name.length);
922 key_name[res_lib_cmap_iter_next.key_name.length] =
'\0';
924 if (value_len != NULL) {
925 *value_len = res_lib_cmap_iter_next.value_len;
929 *type = res_lib_cmap_iter_next.type;
933 (void)hdb_handle_put (&cmap_handle_t_db, handle);
944 struct cmap_inst *cmap_inst;
948 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
949 if (error !=
CS_OK) {
953 memset(&req_lib_cmap_iter_finalize, 0,
sizeof(req_lib_cmap_iter_finalize));
954 req_lib_cmap_iter_finalize.header.size =
sizeof(req_lib_cmap_iter_finalize);
956 req_lib_cmap_iter_finalize.iter_handle = iter_handle;
958 iov.iov_base = (
char *)&req_lib_cmap_iter_finalize;
959 iov.iov_len =
sizeof(req_lib_cmap_iter_finalize);
965 &res_lib_cmap_iter_finalize,
968 if (error ==
CS_OK) {
969 error = res_lib_cmap_iter_finalize.header.error;
972 (void)hdb_handle_put (&cmap_handle_t_db, handle);
979 const char *key_name,
987 struct cmap_inst *cmap_inst;
993 if (cmap_track_handle == NULL || notify_fn == NULL) {
997 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
998 if (error !=
CS_OK) {
1003 sizeof(*cmap_track_inst), &cmap_track_inst_handle));
1004 if (error !=
CS_OK) {
1009 cmap_track_inst_handle, (
void *)&cmap_track_inst));
1010 if (error !=
CS_OK) {
1011 goto error_put_destroy;
1016 cmap_track_inst->
c = cmap_inst->
c;
1018 memset(&req_lib_cmap_track_add, 0,
sizeof(req_lib_cmap_track_add));
1019 req_lib_cmap_track_add.header.size =
sizeof(req_lib_cmap_track_add);
1026 memcpy(req_lib_cmap_track_add.key_name.value, key_name, strlen(key_name));
1027 req_lib_cmap_track_add.key_name.length = strlen(key_name);
1030 req_lib_cmap_track_add.track_type = track_type;
1031 req_lib_cmap_track_add.track_inst_handle = cmap_track_inst_handle;
1033 iov.iov_base = (
char *)&req_lib_cmap_track_add;
1034 iov.iov_len =
sizeof(req_lib_cmap_track_add);
1040 &res_lib_cmap_track_add,
1043 if (error ==
CS_OK) {
1044 error = res_lib_cmap_track_add.header.error;
1047 if (error ==
CS_OK) {
1048 *cmap_track_handle = res_lib_cmap_track_add.track_handle;
1052 (void)hdb_handle_put (&cmap_track_handle_t_db, cmap_track_inst_handle);
1054 (void)hdb_handle_put (&cmap_handle_t_db, handle);
1059 (void)hdb_handle_put (&cmap_track_handle_t_db, cmap_track_inst_handle);
1060 (void)hdb_handle_destroy (&cmap_track_handle_t_db, cmap_track_inst_handle);
1063 (void)hdb_handle_put (&cmap_handle_t_db, handle);
1074 struct cmap_inst *cmap_inst;
1079 error =
hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db, handle, (
void *)&cmap_inst));
1080 if (error !=
CS_OK) {
1084 memset(&req_lib_cmap_track_delete, 0,
sizeof(req_lib_cmap_track_delete));
1085 req_lib_cmap_track_delete.header.size =
sizeof(req_lib_cmap_track_delete);
1087 req_lib_cmap_track_delete.track_handle = track_handle;
1089 iov.iov_base = (
char *)&req_lib_cmap_track_delete;
1090 iov.iov_len =
sizeof(req_lib_cmap_track_delete);
1096 &res_lib_cmap_track_delete,
1099 if (error ==
CS_OK) {
1100 error = res_lib_cmap_track_delete.header.error;
1103 if (error ==
CS_OK) {
1105 res_lib_cmap_track_delete.track_inst_handle,
1106 (
void *)&cmap_track_inst));
1107 if (error !=
CS_OK) {
1111 (void)hdb_handle_put(&cmap_track_handle_t_db, res_lib_cmap_track_delete.track_inst_handle);
1112 (void)hdb_handle_destroy(&cmap_track_handle_t_db, res_lib_cmap_track_delete.track_inst_handle);
1116 (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)
cs_error_t cmap_initialize_map(cmap_handle_t *handle, cmap_map_t map)
Create a new cmap connection on a specified map.
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.
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)
The req_lib_cmap_set_current_map struct used by cmap_initialize_map()
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)