summaryrefslogtreecommitdiff
path: root/lib/include/buxton2.h
blob: 6a8f17b2450320da239ce515615e5894a68d5b1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/*
 * Buxton
 *
 * Copyright (C) 2015 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __BUXTON_H__
#define __BUXTON_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>

/*
 *
 */
struct buxton_client;

enum buxton_status {
	BUXTON_STATUS_UNINITIALIZED = 0,
	BUXTON_STATUS_CONNECTED,
	BUXTON_STATUS_DISCONNECTED,
	BUXTON_STATUS_MAX /* sentinel value */
};

/*
 *
 */
typedef void (*buxton_status_callback)(enum buxton_status status,
		void *user_data);

/*
 *
 */
int buxton_open(struct buxton_client **client,
		buxton_status_callback callback, void *user_data);

/*
 *
 */
int buxton_close(struct buxton_client *client);


/*
 *
 */
enum buxton_key_type {
	BUXTON_TYPE_UNKNOWN = 0,
	BUXTON_TYPE_STRING,
	BUXTON_TYPE_INT32,
	BUXTON_TYPE_UINT32,
	BUXTON_TYPE_INT64,
	BUXTON_TYPE_UINT64,
	BUXTON_TYPE_DOUBLE,
	BUXTON_TYPE_BOOLEAN,
	BUXTON_TYPE_MAX /* sentinel value */
};
#define BUXTON_TYPE_PRIVILEGE BUXTON_TYPE_STRING

/*
 *
 */
struct buxton_value;

/*
 *
 */
struct buxton_value *buxton_value_create_string(const char *s);
struct buxton_value *buxton_value_create_int32(int32_t i);
struct buxton_value *buxton_value_create_uint32(uint32_t u);
struct buxton_value *buxton_value_create_int64(int64_t i64);
struct buxton_value *buxton_value_create_uint64(uint64_t u64);
struct buxton_value *buxton_value_create_double(double d);
struct buxton_value *buxton_value_create_boolean(int32_t b);

int buxton_value_get_type(const struct buxton_value *val,
		enum buxton_key_type *type);
int buxton_value_get_string(const struct buxton_value *val, const char **s);
int buxton_value_get_int32(const struct buxton_value *val, int32_t *i);
int buxton_value_get_uint32(const struct buxton_value *val, uint32_t *u);
int buxton_value_get_int64(const struct buxton_value *val, int64_t *i64);
int buxton_value_get_uint64(const struct buxton_value *val, uint64_t *u64);
int buxton_value_get_double(const struct buxton_value *val, double *d);
int buxton_value_get_boolean(const struct buxton_value *val, int32_t *b);

struct buxton_value *buxton_value_duplicate(const struct buxton_value *val);
void buxton_value_free(struct buxton_value *val);


/*
 *
 */
struct buxton_layer;

/*
 *
 */
typedef void (*buxton_response_callback)(int status,
		const struct buxton_layer *layer, const char *key,
		const struct buxton_value *val, void *user_data);

/*
 *
 */
struct buxton_layer *buxton_create_layer(const char *layer_name);

/*
 *
 */
const char *buxton_layer_get_name(const struct buxton_layer *layer);

/*
 *
 */
void buxton_free_layer(struct buxton_layer *layer);

/*
 *
 */
int buxton_set_value(struct buxton_client *client,
		const struct buxton_layer *layer, const char *key,
		const struct buxton_value *val,
		buxton_response_callback callback, void *user_data);

/*
 *
 */
int buxton_set_value_sync(struct buxton_client *client,
		const struct buxton_layer *layer, const char *key,
		const struct buxton_value *val);

/*
 *
 */
int buxton_get_value(struct buxton_client *client,
		const struct buxton_layer *layer, const char *key,
		buxton_response_callback callback, void *user_data);

/*
 *
 */
int buxton_get_value_sync(struct buxton_client *client,
		const struct buxton_layer *layer, const char *key,
		struct buxton_value **val);


/*
 *
 */
typedef void (*buxton_list_callback)(int status,
		const struct buxton_layer *layer,
		char * const *names, unsigned int len,
		void *user_data);

/*
 *
 */
int buxton_list_keys(struct buxton_client *client,
		const struct buxton_layer *layer,
		buxton_list_callback callback, void *user_data);

/*
 *
 */
int buxton_list_keys_sync(struct buxton_client *client,
		const struct buxton_layer *layer,
		char ***names, unsigned int *len);

/*
 *
 */
static inline void buxton_free_keys(char **names)
{
	char **k;

	if (!names)
		return;

	k = names;
	while (*k) {
		free(*k);
		k++;
	}

	free(names);
}

/*
 *
 */
typedef void (*buxton_notify_callback)(const struct buxton_layer *layer,
		const char *key, const struct buxton_value *val,
		void *user_data);

/*
 *
 */
int buxton_register_notification(struct buxton_client *client,
		const struct buxton_layer *layer, const char *key,
		buxton_notify_callback notify, void *notify_data,
		buxton_response_callback callback, void *user_data);

/*
 *
 */
int buxton_register_notification_sync(struct buxton_client *client,
		const struct buxton_layer *layer, const char *key,
		buxton_notify_callback notify, void *notify_data);

/*
 *
 */
int buxton_unregister_notification(struct buxton_client *client,
		const struct buxton_layer *layer, const char *key,
		buxton_notify_callback notify,
		buxton_response_callback callback, void *user_data);

/*
 *
 */
int buxton_unregister_notification_sync(struct buxton_client *client,
		const struct buxton_layer *layer, const char *key,
		buxton_notify_callback notify);

/* Wrapper APIs ------------------ */

/* Admin APIs  ------------------- */

/*
 *
 */
void buxton_layer_set_uid(struct buxton_layer *layer, uid_t uid);

enum buxton_layer_type {
	BUXTON_LAYER_NORMAL = 0,
	BUXTON_LAYER_BASE,
	BUXTON_LAYER_MAX /* sentinel value */
};

/*
 *
 */
void buxton_layer_set_type(struct buxton_layer *layer,
		enum buxton_layer_type type);

/*
 *
 */
int buxton_create_value(struct buxton_client *client,
		const struct buxton_layer *layer, const char *key,
		const char *read_privilege, const char *write_privilege,
		const struct buxton_value *val,
		buxton_response_callback callback, void *user_data);

/*
 *
 */
int buxton_create_value_sync(struct buxton_client *client,
		const struct buxton_layer *layer, const char *key,
		const char *read_privilege, const char *write_privilege,
		const struct buxton_value *val);

/*
 *
 */
int buxton_unset_value(struct buxton_client *client,
		const struct buxton_layer *layer, const char *key,
		buxton_response_callback callback, void *user_data);

/*
 *
 */
int buxton_unset_value_sync(struct buxton_client *client,
		const struct buxton_layer *layer, const char *key);

/*
 *
 */
enum buxton_priv_type {
	BUXTON_PRIV_UNKNOWN = 0,
	BUXTON_PRIV_READ,
	BUXTON_PRIV_WRITE,
	BUXTON_PRIV_MAX /* sentinel value */
};

/*
 *
 */
int buxton_set_privilege(struct buxton_client *client,
		const struct buxton_layer *layer, const char *key,
		enum buxton_priv_type type,
		const char *privilege,
		buxton_response_callback callback, void *user_data);

/*
 *
 */
int buxton_set_privilege_sync(struct buxton_client *client,
		const struct buxton_layer *layer, const char *key,
		enum buxton_priv_type type,
		const char *privilege);

/*
 *
 */
int buxton_get_privilege(struct buxton_client *client,
		const struct buxton_layer *layer, const char *key,
		enum buxton_priv_type type,
		buxton_response_callback callback, void *user_data);

/*
 *
 */
int buxton_get_privilege_sync(struct buxton_client *client,
		const struct buxton_layer *layer, const char *key,
		enum buxton_priv_type type,
		char **privilege);

#ifdef __cplusplus
}
#endif
#endif /* __BUXTON_H__ */