corosync  3.1.2
cmap.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2017 Red Hat, Inc.
3  *
4  * All rights reserved.
5  *
6  * Author: Jan Friesse (jfriesse@redhat.com)
7  *
8  * This software licensed under BSD license, the text of which follows:
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * - Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  * - Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  * - Neither the name of the Red Hat, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32  * THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef COROSYNC_CMAP_H_DEFINED
36 #define COROSYNC_CMAP_H_DEFINED
37 
38 #include <corosync/corotypes.h>
39 #include <corosync/hdb.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
51 /*
52  * Handle for cmap service connection
53  */
54 typedef uint64_t cmap_handle_t;
55 
56 /*
57  * Handle for cmap iterator
58  */
59 typedef uint64_t cmap_iter_handle_t;
60 
61 /*
62  * Handle for cmap tracking function
63  */
64 typedef uint64_t cmap_track_handle_t;
65 
66 /*
67  * Maximum length of key in cmap
68  */
69 #define CMAP_KEYNAME_MAXLEN 255
70 /*
71  * Minumum length of key in cmap
72  */
73 #define CMAP_KEYNAME_MINLEN 3
74 
75 /*
76  * Tracking values.
77  */
78 #define CMAP_TRACK_ADD 4
79 #define CMAP_TRACK_DELETE 1
80 #define CMAP_TRACK_MODIFY 2
81 
87 #define CMAP_TRACK_PREFIX 8
88 
92 typedef enum {
106 
107 typedef enum {
111 } cmap_map_t;
112 
119  size_t len;
120  const void *data;
121 };
122 
129 typedef void (*cmap_notify_fn_t) (
130  cmap_handle_t cmap_handle,
131  cmap_track_handle_t cmap_track_handle,
132  int32_t event,
133  const char *key_name,
134  struct cmap_notify_value new_value,
135  struct cmap_notify_value old_value,
136  void *user_data);
137 
145  cmap_handle_t *handle);
146 
155  cmap_handle_t *handle,
156  cmap_map_t map);
157 
162 extern cs_error_t cmap_finalize (
163  cmap_handle_t handle);
164 
171 extern cs_error_t cmap_fd_get (
172  cmap_handle_t handle,
173  int *fd);
174 
180 extern cs_error_t cmap_dispatch (
181  cmap_handle_t handle,
182  cs_dispatch_flags_t dispatch_types);
190  cmap_handle_t handle,
191  const void **context);
192 
200  cmap_handle_t handle,
201  const void *context);
202 
211 extern cs_error_t cmap_set(
212  cmap_handle_t handle,
213  const char *key_name,
214  const void *value,
215  size_t value_len,
217 
218 /*
219  * Shortcuts for cmap_set with given type
220  */
221 extern cs_error_t cmap_set_int8(cmap_handle_t handle, const char *key_name, int8_t value);
222 extern cs_error_t cmap_set_uint8(cmap_handle_t handle, const char *key_name, uint8_t value);
223 extern cs_error_t cmap_set_int16(cmap_handle_t handle, const char *key_name, int16_t value);
224 extern cs_error_t cmap_set_uint16(cmap_handle_t handle, const char *key_name, uint16_t value);
225 extern cs_error_t cmap_set_int32(cmap_handle_t handle, const char *key_name, int32_t value);
226 extern cs_error_t cmap_set_uint32(cmap_handle_t handle, const char *key_name, uint32_t value);
227 extern cs_error_t cmap_set_int64(cmap_handle_t handle, const char *key_name, int64_t value);
228 extern cs_error_t cmap_set_uint64(cmap_handle_t handle, const char *key_name, uint64_t value);
229 extern cs_error_t cmap_set_float(cmap_handle_t handle, const char *key_name, float value);
230 extern cs_error_t cmap_set_double(cmap_handle_t handle, const char *key_name, double value);
231 extern cs_error_t cmap_set_string(cmap_handle_t handle, const char *key_name, const char *value);
232 
238 extern cs_error_t cmap_delete(cmap_handle_t handle, const char *key_name);
239 
256 extern cs_error_t cmap_get(
257  cmap_handle_t handle,
258  const char *key_name,
259  void *value,
260  size_t *value_len,
262 
263 /*
264  * Shortcuts for cmap_get.
265  */
266 extern cs_error_t cmap_get_int8(cmap_handle_t handle, const char *key_name, int8_t *i8);
267 extern cs_error_t cmap_get_uint8(cmap_handle_t handle, const char *key_name, uint8_t *u8);
268 extern cs_error_t cmap_get_int16(cmap_handle_t handle, const char *key_name, int16_t *i16);
269 extern cs_error_t cmap_get_uint16(cmap_handle_t handle, const char *key_name, uint16_t *u16);
270 extern cs_error_t cmap_get_int32(cmap_handle_t handle, const char *key_name, int32_t *i32);
271 extern cs_error_t cmap_get_uint32(cmap_handle_t handle, const char *key_name, uint32_t *u32);
272 extern cs_error_t cmap_get_int64(cmap_handle_t handle, const char *key_name, int64_t *i64);
273 extern cs_error_t cmap_get_uint64(cmap_handle_t handle, const char *key_name, uint64_t *u64);
274 extern cs_error_t cmap_get_float(cmap_handle_t handle, const char *key_name, float *flt);
275 extern cs_error_t cmap_get_double(cmap_handle_t handle, const char *key_name, double *dbl);
276 
286 extern cs_error_t cmap_get_string(cmap_handle_t handle, const char *key_name, char **str);
287 
294 extern cs_error_t cmap_inc(cmap_handle_t handle, const char *key_name);
295 
302 extern cs_error_t cmap_dec(cmap_handle_t handle, const char *key_name);
303 
311 extern cs_error_t cmap_iter_init(cmap_handle_t handle, const char *prefix, cmap_iter_handle_t *cmap_iter_handle);
312 
329  cmap_handle_t handle,
330  cmap_iter_handle_t iter_handle,
331  char key_name[],
332  size_t *value_len,
334 
341 extern cs_error_t cmap_iter_finalize(cmap_handle_t handle, cmap_iter_handle_t iter_handle);
342 
358  cmap_handle_t handle,
359  const char *key_name,
360  int32_t track_type,
361  cmap_notify_fn_t notify_fn,
362  void *user_data,
363  cmap_track_handle_t *cmap_track_handle);
364 
370 extern cs_error_t cmap_track_delete(cmap_handle_t handle, cmap_track_handle_t track_handle);
371 
374 #ifdef __cplusplus
375 }
376 #endif
377 
378 #endif /* COROSYNC_CMAP_H_DEFINED */
cs_error_t cmap_set_uint64(cmap_handle_t handle, const char *key_name, uint64_t value)
Definition: lib/cmap.c:482
cs_error_t cmap_get_uint8(cmap_handle_t handle, const char *key_name, uint8_t *u8)
Definition: lib/cmap.c:673
cs_error_t cmap_set_uint32(cmap_handle_t handle, const char *key_name, uint32_t value)
Definition: lib/cmap.c:472
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
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
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
uint32_t value
cmap_value_types_t type
Definition: cmap.h:118
cmap_map_t
Definition: cmap.h:107
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_handle_t cmap_handle
Definition: sam.c:137
cs_error_t cmap_initialize(cmap_handle_t *handle)
Create a new cmap connection.
Definition: lib/cmap.c:89
cs_error_t cmap_get_uint16(cmap_handle_t handle, const char *key_name, uint16_t *u16)
Definition: lib/cmap.c:685
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
cs_error_t cmap_get_int64(cmap_handle_t handle, const char *key_name, int64_t *i64)
Definition: lib/cmap.c:703
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
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
Structure passed as new_value and old_value in change callback.
Definition: cmap.h:117
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
cs_error_t cmap_iter_finalize(cmap_handle_t handle, cmap_iter_handle_t iter_handle)
Finalize iterator.
Definition: lib/cmap.c:938
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
cs_error_t cmap_get_double(cmap_handle_t handle, const char *key_name, double *dbl)
Definition: lib/cmap.c:721
const void * data
Definition: cmap.h:120
void * user_data
Definition: sam.c:127
cs_error_t cmap_set_double(cmap_handle_t handle, const char *key_name, double value)
Definition: lib/cmap.c:492
cs_error_t cmap_get_uint32(cmap_handle_t handle, const char *key_name, uint32_t *u32)
Definition: lib/cmap.c:697
cs_error_t cmap_get_float(cmap_handle_t handle, const char *key_name, float *flt)
Definition: lib/cmap.c:715
cs_error_t cmap_get_uint64(cmap_handle_t handle, const char *key_name, uint64_t *u64)
Definition: lib/cmap.c:709
cs_error_t
The cs_error_t enum.
Definition: corotypes.h:97
uint64_t cmap_track_handle_t
Definition: cmap.h:64
cs_dispatch_flags_t
The cs_dispatch_flags_t enum.
Definition: corotypes.h:83
cs_error_t cmap_set_string(cmap_handle_t handle, const char *key_name, const char *value)
Definition: lib/cmap.c:497
size_t len
Definition: cmap.h:119
cs_error_t cmap_set_uint8(cmap_handle_t handle, const char *key_name, uint8_t value)
Definition: lib/cmap.c:452
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
cs_error_t cmap_delete(cmap_handle_t handle, const char *key_name)
Deletes key from cmap database.
Definition: lib/cmap.c:507
cs_error_t cmap_dispatch(cmap_handle_t handle, cs_dispatch_flags_t dispatch_types)
Dispatch data from service.
Definition: lib/cmap.c:229
uint64_t cmap_iter_handle_t
Definition: cmap.h:59
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
cs_error_t cmap_set_int64(cmap_handle_t handle, const char *key_name, int64_t value)
Definition: lib/cmap.c:477
cs_error_t cmap_get_int8(cmap_handle_t handle, const char *key_name, int8_t *i8)
Definition: lib/cmap.c:667
cmap_value_types_t
Possible types of value.
Definition: cmap.h:92
cs_error_t cmap_set_int32(cmap_handle_t handle, const char *key_name, int32_t value)
Definition: lib/cmap.c:467
cs_error_t cmap_context_set(cmap_handle_t handle, const void *context)
cmap_context_set
Definition: lib/cmap.c:371
cs_error_t cmap_finalize(cmap_handle_t handle)
Close the cmap handle.
Definition: lib/cmap.c:173
cs_error_t cmap_get_int32(cmap_handle_t handle, const char *key_name, int32_t *i32)
Definition: lib/cmap.c:691
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
cs_error_t cmap_set_uint16(cmap_handle_t handle, const char *key_name, uint16_t value)
Definition: lib/cmap.c:462
cs_error_t cmap_context_get(cmap_handle_t handle, const void **context)
cmap_context_get
Definition: lib/cmap.c:352
cs_error_t cmap_set_int8(cmap_handle_t handle, const char *key_name, int8_t value)
Definition: lib/cmap.c:447
uint64_t cmap_handle_t
Definition: cmap.h:54
cs_error_t cmap_get_int16(cmap_handle_t handle, const char *key_name, int16_t *i16)
Definition: lib/cmap.c:679
cs_error_t cmap_set_int16(cmap_handle_t handle, const char *key_name, int16_t value)
Definition: lib/cmap.c:457
cs_error_t cmap_set_float(cmap_handle_t handle, const char *key_name, float value)
Definition: lib/cmap.c:487