waf buildable daemon
[ladish.git] / lash_compat / lash / config.h
blob0cd852792873862181cea2619f2bb87a9ab5f112
1 /*
2 * LASH
4 * Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
5 * Copyright (C) 2002 Robert Ham <rah@bash.sh>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22 #ifndef __LASH_CONFIG_H__
23 #define __LASH_CONFIG_H__
25 #include <stdbool.h>
27 #include <lash/types.h>
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
33 /**
34 * Append a key-value pair of typed data to a config message.
36 * @param handle An opaque config message handle passed
37 * to the callback function by liblash.
38 * @param key The key string pointer.
39 * @param value The value pointer.
40 * @param type The value type. Must be one out of \ref LASH_TYPE_DOUBLE,
41 * \ref LASH_TYPE_INTEGER, and \ref LASH_TYPE_STRING.
42 * @return True if writing succeeded, false otherwise.
44 bool
45 lash_config_write(lash_config_handle_t *handle,
46 const char *key,
47 const void *value,
48 int type);
50 /**
51 * Append a key-value pair of raw data to a config message.
53 * @param handle An opaque config message handle passed
54 * to the callback function by liblash.
55 * @param key The key string pointer.
56 * @param buf The data buffer pointer.
57 * @param size The size of the data buffer in bytes.
58 * @return True if writing succeeded, false otherwise.
60 bool
61 lash_config_write_raw(lash_config_handle_t *handle,
62 const char *key,
63 const void *buf,
64 int size);
66 /**
67 * Read a key-value pair of data from a config message.
69 * @param handle An opaque config message handle passed
70 * to the callback function by liblash.
71 * @param key_ptr A pointer to the memory location in which to
72 * save the key pointer.
73 * @param value_ptr A pointer to the memory location in which to
74 * save the value pointer.
75 * @param type_ptr A pointer to the memory location in which to
76 * save the value type.
77 * @return If reading succeeds the return value will be equal to the
78 * config value's size in bytes (for strings this includes the
79 * terminating NUL). If no data remains in the message the return
80 * value will 0, and -1 if an error occurred during reading.
82 int
83 lash_config_read(lash_config_handle_t *handle,
84 const char **key_ptr,
85 void *value_ptr,
86 int *type_ptr);
88 /* Begin old API */
90 #include <stdint.h>
91 #include <stddef.h>
93 lash_config_t *
94 lash_config_new(void);
96 void
97 lash_config_destroy(lash_config_t *config);
99 lash_config_t *
100 lash_config_dup(const lash_config_t *config);
102 lash_config_t *
103 lash_config_new_with_key(const char *key);
105 const char *
106 lash_config_get_key(const lash_config_t *config);
108 const void *
109 lash_config_get_value(const lash_config_t *config);
111 size_t
112 lash_config_get_value_size(const lash_config_t *config);
114 void
115 lash_config_set_key(lash_config_t *config,
116 const char *key);
118 void
119 lash_config_set_value(lash_config_t *config,
120 const void *value,
121 size_t value_size);
124 * With these functions, no type checking is done; you can do
125 * lash_config_get_value_int on a config that was set with
126 * lash_config_set_value_float.
129 uint32_t
130 lash_config_get_value_int(const lash_config_t *config);
132 float
133 lash_config_get_value_float(const lash_config_t *config);
135 double
136 lash_config_get_value_double(const lash_config_t *config);
138 const char *
139 lash_config_get_value_string(const lash_config_t *config);
141 void
142 lash_config_set_value_int(lash_config_t *config,
143 uint32_t value);
145 void
146 lash_config_set_value_float(lash_config_t *config,
147 float value);
148 void
149 lash_config_set_value_double(lash_config_t *config,
150 double value);
152 void
153 lash_config_set_value_string(lash_config_t *config,
154 const char *value);
156 /* End old API */
158 #ifdef __cplusplus
160 #endif
162 #endif /* __LASH_CONFIG_H__ */