corosync  2.3.2
cmap.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 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 /*
82  * Whole prefix is tracked, instead of key only (so "totem." tracking means that
83  * "totem.nodeid", "totem.version", ... applies). This value is also never returned
84  * inside of callback and is used only in adding track
85  */
86 #define CMAP_TRACK_PREFIX 8
87 
88 /*
89  * Possible types of value. Binary is raw data without trailing zero with given length
90  */
91 typedef enum {
105 
106 /*
107  * Structure passed as new_value and old_value in change callback. It contains type of
108  * key, length of key and pointer to value of key
109  */
112  size_t len;
113  const void *data;
114 };
115 
116 /*
117  * Prototype for notify callback function. Even is one of CMAP_TRACK_* event, key_name is
118  * changed key, new and old_value contains values or are zeroed (in other words, type is non
119  * existing 0 type) if there were no old (creating of key) or new (deleting of key) value.
120  * user_data are passed when adding tracking.
121  */
122 typedef void (*cmap_notify_fn_t) (
123  cmap_handle_t cmap_handle,
124  cmap_track_handle_t cmap_track_handle,
125  int32_t event,
126  const char *key_name,
127  struct cmap_notify_value new_value,
128  struct cmap_notify_value old_value,
129  void *user_data);
130 
138  cmap_handle_t *handle);
139 
144 extern cs_error_t cmap_finalize (
145  cmap_handle_t handle);
146 
147 /*
148  * Get a file descriptor on which to poll. cmap_handle_t is NOT a
149  * file descriptor and may not be used directly.
150  * @param handle cmap handle initialized by cmap_initialize
151  * @param fd file descriptor for poll
152  */
153 extern cs_error_t cmap_fd_get (
154  cmap_handle_t handle,
155  int *fd);
156 
162 extern cs_error_t cmap_dispatch (
163  cmap_handle_t handle,
164  cs_dispatch_flags_t dispatch_types);
165 /*
166  * Get/set context variable
167  */
169  cmap_handle_t handle,
170  const void **context);
171 
173  cmap_handle_t handle,
174  const void *context);
175 
176 
185 extern cs_error_t cmap_set(
186  cmap_handle_t handle,
187  const char *key_name,
188  const void *value,
189  size_t value_len,
191 
192 /*
193  * Shortcuts for cmap_set with given type
194  */
195 extern cs_error_t cmap_set_int8(cmap_handle_t handle, const char *key_name, int8_t value);
196 extern cs_error_t cmap_set_uint8(cmap_handle_t handle, const char *key_name, uint8_t value);
197 extern cs_error_t cmap_set_int16(cmap_handle_t handle, const char *key_name, int16_t value);
198 extern cs_error_t cmap_set_uint16(cmap_handle_t handle, const char *key_name, uint16_t value);
199 extern cs_error_t cmap_set_int32(cmap_handle_t handle, const char *key_name, int32_t value);
200 extern cs_error_t cmap_set_uint32(cmap_handle_t handle, const char *key_name, uint32_t value);
201 extern cs_error_t cmap_set_int64(cmap_handle_t handle, const char *key_name, int64_t value);
202 extern cs_error_t cmap_set_uint64(cmap_handle_t handle, const char *key_name, uint64_t value);
203 extern cs_error_t cmap_set_float(cmap_handle_t handle, const char *key_name, float value);
204 extern cs_error_t cmap_set_double(cmap_handle_t handle, const char *key_name, double value);
205 extern cs_error_t cmap_set_string(cmap_handle_t handle, const char *key_name, const char *value);
206 
212 extern cs_error_t cmap_delete(cmap_handle_t handle, const char *key_name);
213 
229 extern cs_error_t cmap_get(
230  cmap_handle_t handle,
231  const char *key_name,
232  void *value,
233  size_t *value_len,
235 
236 /*
237  * Shortcuts for cmap_get.
238  */
239 extern cs_error_t cmap_get_int8(cmap_handle_t handle, const char *key_name, int8_t *i8);
240 extern cs_error_t cmap_get_uint8(cmap_handle_t handle, const char *key_name, uint8_t *u8);
241 extern cs_error_t cmap_get_int16(cmap_handle_t handle, const char *key_name, int16_t *i16);
242 extern cs_error_t cmap_get_uint16(cmap_handle_t handle, const char *key_name, uint16_t *u16);
243 extern cs_error_t cmap_get_int32(cmap_handle_t handle, const char *key_name, int32_t *i32);
244 extern cs_error_t cmap_get_uint32(cmap_handle_t handle, const char *key_name, uint32_t *u32);
245 extern cs_error_t cmap_get_int64(cmap_handle_t handle, const char *key_name, int64_t *i64);
246 extern cs_error_t cmap_get_uint64(cmap_handle_t handle, const char *key_name, uint64_t *u64);
247 extern cs_error_t cmap_get_float(cmap_handle_t handle, const char *key_name, float *flt);
248 extern cs_error_t cmap_get_double(cmap_handle_t handle, const char *key_name, double *dbl);
249 
257 extern cs_error_t cmap_get_string(cmap_handle_t handle, const char *key_name, char **str);
258 
264 extern cs_error_t cmap_inc(cmap_handle_t handle, const char *key_name);
265 
271 extern cs_error_t cmap_dec(cmap_handle_t handle, const char *key_name);
272 
279 extern cs_error_t cmap_iter_init(cmap_handle_t handle, const char *prefix, cmap_iter_handle_t *cmap_iter_handle);
280 
293  cmap_handle_t handle,
294  cmap_iter_handle_t iter_handle,
295  char key_name[],
296  size_t *value_len,
298 
302 extern cs_error_t cmap_iter_finalize(cmap_handle_t handle, cmap_iter_handle_t iter_handle);
303 
304 /*
305  * Add tracking function for given key_name. Tracked changes (add|modify|delete) depend on track_type,
306  * which is bitwise or of CMAP_TRACK_* values. notify_fn is called on change, where user_data pointer
307  * is passed (unchanged). Value which can be used to delete tracking is passed as cmap_track.
308  * @param handle cmap handle
309  * @param key_name name of key to track changes on
310  * @param track_type bitwise-or of CMAP_TRACK_* values
311  * @param notify_fn function to be called on change of key
312  * @param user_data given pointer is unchanged passed to notify_fn
313  * @param cmap_track_handle handle used for removing of newly created track
314  */
316  cmap_handle_t handle,
317  const char *key_name,
318  int32_t track_type,
319  cmap_notify_fn_t notify_fn,
320  void *user_data,
321  cmap_track_handle_t *cmap_track_handle);
322 
328 extern cs_error_t cmap_track_delete(cmap_handle_t handle, cmap_track_handle_t track_handle);
329 
330 #ifdef __cplusplus
331 }
332 #endif
333 
334 #endif /* COROSYNC_CMAP_H_DEFINED */