cmap.h
Go to the documentation of this file.
/*
* Copyright (c) 2011-2017 Red Hat, Inc.
*
* All rights reserved.
*
* Author: Jan Friesse (jfriesse@redhat.com)
*
* This software licensed under BSD license, the text of which follows:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the Red Hat, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef COROSYNC_CMAP_H_DEFINED
#define COROSYNC_CMAP_H_DEFINED
#include <corosync/corotypes.h>
#include <corosync/hdb.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Handle for cmap service connection
*/
typedef uint64_t cmap_handle_t;
/*
* Handle for cmap iterator
*/
typedef uint64_t cmap_iter_handle_t;
/*
* Handle for cmap tracking function
*/
typedef uint64_t cmap_track_handle_t;
/*
* Maximum length of key in cmap
*/
#define CMAP_KEYNAME_MAXLEN 255
/*
* Minumum length of key in cmap
*/
#define CMAP_KEYNAME_MINLEN 3
/*
* Tracking values.
*/
#define CMAP_TRACK_ADD 4
#define CMAP_TRACK_DELETE 1
#define CMAP_TRACK_MODIFY 2
#define CMAP_TRACK_PREFIX 8
typedef enum {
CMAP_VALUETYPE_INT8 = 1,
CMAP_VALUETYPE_UINT8 = 2,
CMAP_VALUETYPE_INT16 = 3,
CMAP_VALUETYPE_UINT16 = 4,
CMAP_VALUETYPE_INT32 = 5,
CMAP_VALUETYPE_UINT32 = 6,
CMAP_VALUETYPE_INT64 = 7,
CMAP_VALUETYPE_UINT64 = 8,
CMAP_VALUETYPE_FLOAT = 9,
CMAP_VALUETYPE_DOUBLE = 10,
CMAP_VALUETYPE_STRING = 11,
CMAP_VALUETYPE_BINARY = 12,
} cmap_value_types_t;
typedef enum {
CMAP_MAP_DEFAULT = 0,
CMAP_MAP_ICMAP = 0,
CMAP_MAP_STATS = 1,
} cmap_map_t;
struct cmap_notify_value {
cmap_value_types_t type;
size_t len;
const void *data;
};
typedef 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);
extern cs_error_t cmap_initialize (
cmap_handle_t *handle);
extern cs_error_t cmap_initialize_map (
cmap_handle_t *handle,
cmap_map_t map);
extern cs_error_t cmap_finalize (
cmap_handle_t handle);
extern cs_error_t cmap_fd_get (
cmap_handle_t handle,
int *fd);
extern cs_error_t cmap_dispatch (
cmap_handle_t handle,
cs_dispatch_flags_t dispatch_types);
extern cs_error_t cmap_context_get (
cmap_handle_t handle,
const void **context);
extern cs_error_t cmap_context_set (
cmap_handle_t handle,
const void *context);
extern 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);
/*
* Shortcuts for cmap_set with given type
*/
extern cs_error_t cmap_set_int8(cmap_handle_t handle, const char *key_name, int8_t value);
extern cs_error_t cmap_set_uint8(cmap_handle_t handle, const char *key_name, uint8_t value);
extern cs_error_t cmap_set_int16(cmap_handle_t handle, const char *key_name, int16_t value);
extern cs_error_t cmap_set_uint16(cmap_handle_t handle, const char *key_name, uint16_t value);
extern cs_error_t cmap_set_int32(cmap_handle_t handle, const char *key_name, int32_t value);
extern cs_error_t cmap_set_uint32(cmap_handle_t handle, const char *key_name, uint32_t value);
extern cs_error_t cmap_set_int64(cmap_handle_t handle, const char *key_name, int64_t value);
extern cs_error_t cmap_set_uint64(cmap_handle_t handle, const char *key_name, uint64_t value);
extern cs_error_t cmap_set_float(cmap_handle_t handle, const char *key_name, float value);
extern cs_error_t cmap_set_double(cmap_handle_t handle, const char *key_name, double value);
extern cs_error_t cmap_set_string(cmap_handle_t handle, const char *key_name, const char *value);
extern cs_error_t cmap_delete(cmap_handle_t handle, const char *key_name);
extern cs_error_t cmap_get(
cmap_handle_t handle,
const char *key_name,
void *value,
size_t *value_len,
cmap_value_types_t *type);
/*
* Shortcuts for cmap_get.
*/
extern cs_error_t cmap_get_int8(cmap_handle_t handle, const char *key_name, int8_t *i8);
extern cs_error_t cmap_get_uint8(cmap_handle_t handle, const char *key_name, uint8_t *u8);
extern cs_error_t cmap_get_int16(cmap_handle_t handle, const char *key_name, int16_t *i16);
extern cs_error_t cmap_get_uint16(cmap_handle_t handle, const char *key_name, uint16_t *u16);
extern cs_error_t cmap_get_int32(cmap_handle_t handle, const char *key_name, int32_t *i32);
extern cs_error_t cmap_get_uint32(cmap_handle_t handle, const char *key_name, uint32_t *u32);
extern cs_error_t cmap_get_int64(cmap_handle_t handle, const char *key_name, int64_t *i64);
extern cs_error_t cmap_get_uint64(cmap_handle_t handle, const char *key_name, uint64_t *u64);
extern cs_error_t cmap_get_float(cmap_handle_t handle, const char *key_name, float *flt);
extern cs_error_t cmap_get_double(cmap_handle_t handle, const char *key_name, double *dbl);
extern cs_error_t cmap_get_string(cmap_handle_t handle, const char *key_name, char **str);
extern cs_error_t cmap_inc(cmap_handle_t handle, const char *key_name);
extern cs_error_t cmap_dec(cmap_handle_t handle, const char *key_name);
extern cs_error_t cmap_iter_init(cmap_handle_t handle, const char *prefix, cmap_iter_handle_t *cmap_iter_handle);
extern 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);
extern cs_error_t cmap_iter_finalize(cmap_handle_t handle, cmap_iter_handle_t iter_handle);
extern 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);
extern cs_error_t cmap_track_delete(cmap_handle_t handle, cmap_track_handle_t track_handle);
#ifdef __cplusplus
}
#endif
#endif /* COROSYNC_CMAP_H_DEFINED */
nodeid
unsigned int nodeid
Definition coroapi.h:0
corotypes.h
cs_dispatch_flags_t
cs_dispatch_flags_t
The cs_dispatch_flags_t enum.
Definition corotypes.h:84
cs_error_t
cs_error_t
The cs_error_t enum.
Definition corotypes.h:98
value
uint32_t value
Definition exec/votequorum.c:2
cmap_map_t
cmap_map_t
Definition cmap.h:107
cmap_context_set
cs_error_t cmap_context_set(cmap_handle_t handle, const void *context)
cmap_context_set
Definition lib/cmap.c:371
cmap_value_types_t
cmap_value_types_t
Possible types of value.
Definition cmap.h:92
cmap_iter_handle_t
uint64_t cmap_iter_handle_t
Definition cmap.h:59
cmap_set_int8
cs_error_t cmap_set_int8(cmap_handle_t handle, const char *key_name, int8_t value)
Definition lib/cmap.c:447
cmap_get_double
cs_error_t cmap_get_double(cmap_handle_t handle, const char *key_name, double *dbl)
Definition lib/cmap.c:721
cmap_get_int64
cs_error_t cmap_get_int64(cmap_handle_t handle, const char *key_name, int64_t *i64)
Definition lib/cmap.c:703
cmap_finalize
cs_error_t cmap_finalize(cmap_handle_t handle)
Close the cmap handle.
Definition lib/cmap.c:173
cmap_set_uint32
cs_error_t cmap_set_uint32(cmap_handle_t handle, const char *key_name, uint32_t value)
Definition lib/cmap.c:472
cmap_iter_next
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.
Definition lib/cmap.c:878
cmap_inc
cs_error_t cmap_inc(cmap_handle_t handle, const char *key_name)
Increment value of key_name if it is [u]int* type.
Definition lib/cmap.c:811
cmap_set_uint8
cs_error_t cmap_set_uint8(cmap_handle_t handle, const char *key_name, uint8_t value)
Definition lib/cmap.c:452
cmap_get_float
cs_error_t cmap_get_float(cmap_handle_t handle, const char *key_name, float *flt)
Definition lib/cmap.c:715
cmap_track_add
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.
Definition lib/cmap.c:977
cmap_handle_t
uint64_t cmap_handle_t
Definition cmap.h:54
cmap_track_handle_t
uint64_t cmap_track_handle_t
Definition cmap.h:64
cmap_context_get
cs_error_t cmap_context_get(cmap_handle_t handle, const void **context)
cmap_context_get
Definition lib/cmap.c:352
cmap_dec
cs_error_t cmap_dec(cmap_handle_t handle, const char *key_name)
Decrement value of key_name if it is [u]int* type.
Definition lib/cmap.c:817
cmap_get_uint64
cs_error_t cmap_get_uint64(cmap_handle_t handle, const char *key_name, uint64_t *u64)
Definition lib/cmap.c:709
cmap_delete
cs_error_t cmap_delete(cmap_handle_t handle, const char *key_name)
Deletes key from cmap database.
Definition lib/cmap.c:507
cmap_get_int16
cs_error_t cmap_get_int16(cmap_handle_t handle, const char *key_name, int16_t *i16)
Definition lib/cmap.c:679
cmap_get
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.
Definition lib/cmap.c:553
cmap_fd_get
cs_error_t cmap_fd_get(cmap_handle_t handle, int *fd)
Get a file descriptor on which to poll.
Definition lib/cmap.c:212
cmap_initialize
cs_error_t cmap_initialize(cmap_handle_t *handle)
Create a new cmap connection.
Definition lib/cmap.c:89
cmap_set_int32
cs_error_t cmap_set_int32(cmap_handle_t handle, const char *key_name, int32_t value)
Definition lib/cmap.c:467
cmap_get_uint32
cs_error_t cmap_get_uint32(cmap_handle_t handle, const char *key_name, uint32_t *u32)
Definition lib/cmap.c:697
cmap_get_uint8
cs_error_t cmap_get_uint8(cmap_handle_t handle, const char *key_name, uint8_t *u8)
Definition lib/cmap.c:673
cmap_dispatch
cs_error_t cmap_dispatch(cmap_handle_t handle, cs_dispatch_flags_t dispatch_types)
Dispatch data from service.
Definition lib/cmap.c:229
cmap_set_uint16
cs_error_t cmap_set_uint16(cmap_handle_t handle, const char *key_name, uint16_t value)
Definition lib/cmap.c:462
cmap_set_int16
cs_error_t cmap_set_int16(cmap_handle_t handle, const char *key_name, int16_t value)
Definition lib/cmap.c:457
cmap_track_delete
cs_error_t cmap_track_delete(cmap_handle_t handle, cmap_track_handle_t track_handle)
Delete track created previously by cmap_track_add.
Definition lib/cmap.c:1068
cmap_get_string
cs_error_t cmap_get_string(cmap_handle_t handle, const char *key_name, char **str)
Shortcut for cmap_get for string type.
Definition lib/cmap.c:727
cmap_iter_finalize
cs_error_t cmap_iter_finalize(cmap_handle_t handle, cmap_iter_handle_t iter_handle)
Finalize iterator.
Definition lib/cmap.c:938
cmap_initialize_map
cs_error_t cmap_initialize_map(cmap_handle_t *handle, cmap_map_t map)
Create a new cmap connection on a specified map.
Definition lib/cmap.c:124
cmap_iter_init
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.
Definition lib/cmap.c:823
cmap_notify_fn_t
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.
Definition cmap.h:129
cmap_set
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.
Definition lib/cmap.c:390
cmap_set_string
cs_error_t cmap_set_string(cmap_handle_t handle, const char *key_name, const char *value)
Definition lib/cmap.c:497
cmap_get_uint16
cs_error_t cmap_get_uint16(cmap_handle_t handle, const char *key_name, uint16_t *u16)
Definition lib/cmap.c:685
cmap_get_int8
cs_error_t cmap_get_int8(cmap_handle_t handle, const char *key_name, int8_t *i8)
Definition lib/cmap.c:667
cmap_set_int64
cs_error_t cmap_set_int64(cmap_handle_t handle, const char *key_name, int64_t value)
Definition lib/cmap.c:477
cmap_set_double
cs_error_t cmap_set_double(cmap_handle_t handle, const char *key_name, double value)
Definition lib/cmap.c:492
cmap_set_float
cs_error_t cmap_set_float(cmap_handle_t handle, const char *key_name, float value)
Definition lib/cmap.c:487
cmap_get_int32
cs_error_t cmap_get_int32(cmap_handle_t handle, const char *key_name, int32_t *i32)
Definition lib/cmap.c:691
cmap_set_uint64
cs_error_t cmap_set_uint64(cmap_handle_t handle, const char *key_name, uint64_t value)
Definition lib/cmap.c:482
CMAP_MAP_DEFAULT
@ CMAP_MAP_DEFAULT
Definition cmap.h:108
CMAP_MAP_ICMAP
@ CMAP_MAP_ICMAP
Definition cmap.h:109
CMAP_MAP_STATS
@ CMAP_MAP_STATS
Definition cmap.h:110
CMAP_VALUETYPE_UINT8
@ CMAP_VALUETYPE_UINT8
Definition cmap.h:94
CMAP_VALUETYPE_UINT32
@ CMAP_VALUETYPE_UINT32
Definition cmap.h:98
CMAP_VALUETYPE_INT8
@ CMAP_VALUETYPE_INT8
Definition cmap.h:93
CMAP_VALUETYPE_FLOAT
@ CMAP_VALUETYPE_FLOAT
Definition cmap.h:101
CMAP_VALUETYPE_UINT16
@ CMAP_VALUETYPE_UINT16
Definition cmap.h:96
CMAP_VALUETYPE_UINT64
@ CMAP_VALUETYPE_UINT64
Definition cmap.h:100
CMAP_VALUETYPE_STRING
@ CMAP_VALUETYPE_STRING
Definition cmap.h:103
CMAP_VALUETYPE_DOUBLE
@ CMAP_VALUETYPE_DOUBLE
Definition cmap.h:102
CMAP_VALUETYPE_BINARY
@ CMAP_VALUETYPE_BINARY
Definition cmap.h:104
CMAP_VALUETYPE_INT16
@ CMAP_VALUETYPE_INT16
Definition cmap.h:95
CMAP_VALUETYPE_INT32
@ CMAP_VALUETYPE_INT32
Definition cmap.h:97
CMAP_VALUETYPE_INT64
@ CMAP_VALUETYPE_INT64
Definition cmap.h:99
hdb.h
user_data
void * user_data
Definition sam.c:127
cmap_handle
cmap_handle_t cmap_handle
Definition sam.c:137
cmap_notify_value
Structure passed as new_value and old_value in change callback.
Definition cmap.h:117
cmap_notify_value::type
cmap_value_types_t type
Definition cmap.h:118
cmap_notify_value::data
const void * data
Definition cmap.h:120
cmap_notify_value::len
size_t len
Definition cmap.h:119
type
char type
Definition totem.h:2