summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
e0ee638)
Change-Id: I063329b23f4476e2570e99dfc639b11320df41d2
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
* Get from the 'set' the API of 'name' in 'api' with fallback to subset or default api
* @param set the set of API
* @param name the name of the API to get
* Get from the 'set' the API of 'name' in 'api' with fallback to subset or default api
* @param set the set of API
* @param name the name of the API to get
- * @param api the structure where to store data about the API of name
- * @return 0 in case of success or -1 in case of error
+ * @param rec if not zero look also recursively in subsets
+ * @return the api pointer in case of success or NULL in case of error
*/
static struct api_desc *lookup(struct afb_apiset *set, const char *name, int rec)
{
*/
static struct api_desc *lookup(struct afb_apiset *set, const char *name, int rec)
{
* @param set the set of API
* @param name the name of the API to get
* @param rec if not zero look also recursively in subsets
* @param set the set of API
* @param name the name of the API to get
* @param rec if not zero look also recursively in subsets
- * @return 0 in case of success or -1 in case of error
+ * @return the api pointer in case of success or NULL in case of error
*/
const struct afb_api *afb_apiset_lookup(struct afb_apiset *set, const char *name, int rec)
{
*/
const struct afb_api *afb_apiset_lookup(struct afb_apiset *set, const char *name, int rec)
{
-/**
- * Check whether the 'set' has the API of 'name'
- * @param set the set of API
- * @param name the name of the API to get
- * @param rec if not zero look also recursively in subsets
- * @return 1 if the api exist or 0 otherwise
- */
-int afb_apiset_has(struct afb_apiset *set, const char *name, int rec)
-{
- return !!afb_apiset_lookup(set, name, rec);
-}
-
/**
* Starts the service 'api'.
* @param api the api
/**
* Starts the service 'api'.
* @param api the api
* @param callback the function to call for each name
* @param closure the closure for the callback
*/
* @param callback the function to call for each name
* @param closure the closure for the callback
*/
-void afb_apiset_enum(struct afb_apiset *set, void (*callback)(struct afb_apiset *set, const char *name, void *closure), void *closure)
+void afb_apiset_enum(struct afb_apiset *set, int rec, void (*callback)(struct afb_apiset *set, const char *name, void *closure), void *closure)
+ struct afb_apiset *iset;
+ struct api_desc *i, *e;
- for (i = 0 ; i < set->count ; i++)
- callback(set, set->apis[i].name, closure);
+ iset = set;
+ while (iset) {
+ i = iset->apis;
+ e = &i[iset->count];
+ while (i != e) {
+ if (lookup(set, i->name, 1) == i)
+ callback(iset, i->name, closure);
+ i++;
+ }
+ iset = rec ? iset->subset : NULL;
+ }
extern struct afb_apiset *afb_apiset_subset_get(struct afb_apiset *set);
extern int afb_apiset_add(struct afb_apiset *set, const char *name, struct afb_api api);
extern int afb_apiset_del(struct afb_apiset *set, const char *name);
extern struct afb_apiset *afb_apiset_subset_get(struct afb_apiset *set);
extern int afb_apiset_add(struct afb_apiset *set, const char *name, struct afb_api api);
extern int afb_apiset_del(struct afb_apiset *set, const char *name);
-extern int afb_apiset_has(struct afb_apiset *set, const char *name, int rec);
extern const struct afb_api *afb_apiset_lookup(struct afb_apiset *set, const char *name, int rec);
extern const struct afb_api *afb_apiset_lookup_started(struct afb_apiset *set, const char *name, int rec);
extern int afb_apiset_start_service(struct afb_apiset *set, const char *name, int share_session, int onneed);
extern const struct afb_api *afb_apiset_lookup(struct afb_apiset *set, const char *name, int rec);
extern const struct afb_api *afb_apiset_lookup_started(struct afb_apiset *set, const char *name, int rec);
extern int afb_apiset_start_service(struct afb_apiset *set, const char *name, int share_session, int onneed);
extern int afb_apiset_get_verbosity(struct afb_apiset *set, const char *name);
extern struct json_object *afb_apiset_describe(struct afb_apiset *set, const char *name);
extern const char **afb_apiset_get_names(struct afb_apiset *set);
extern int afb_apiset_get_verbosity(struct afb_apiset *set, const char *name);
extern struct json_object *afb_apiset_describe(struct afb_apiset *set, const char *name);
extern const char **afb_apiset_get_names(struct afb_apiset *set);
-extern void afb_apiset_enum(struct afb_apiset *set, void (*callback)(struct afb_apiset *set, const char *name, void *closure), void *closure);
+extern void afb_apiset_enum(struct afb_apiset *set, int rec, void (*callback)(struct afb_apiset *set, const char *name, void *closure), void *closure);
if (!name || !name[0])
verbosity = level;
else if (name[0] == '*' && !name[1])
if (!name || !name[0])
verbosity = level;
else if (name[0] == '*' && !name[1])
- afb_apiset_enum(main_apiset, set_verbosity_to_all_cb, (void*)(intptr_t)level);
+ afb_apiset_enum(main_apiset, 1, set_verbosity_to_all_cb, (void*)(intptr_t)level);
else
afb_apiset_set_verbosity(main_apiset, name, level);
}
else
afb_apiset_set_verbosity(main_apiset, name, level);
}
if (!name || !name[0])
json_object_object_add(resu, "", encode_verbosity(verbosity));
else if (name[0] == '*' && !name[1])
if (!name || !name[0])
json_object_object_add(resu, "", encode_verbosity(verbosity));
else if (name[0] == '*' && !name[1])
- afb_apiset_enum(main_apiset, get_verbosity_of_all_cb, resu);
+ afb_apiset_enum(main_apiset, 1, get_verbosity_of_all_cb, resu);
else {
l = afb_apiset_get_verbosity(main_apiset, name);
if (l >= 0)
else {
l = afb_apiset_get_verbosity(main_apiset, name);
if (l >= 0)
struct json_object *o;
o = afb_apiset_describe(main_apiset, name);
struct json_object *o;
o = afb_apiset_describe(main_apiset, name);
- if (o || afb_apiset_has(main_apiset, name, 0))
+ if (o || afb_apiset_lookup(main_apiset, name, 1))
json_object_object_add(resu, name, o);
}
json_object_object_add(resu, name, o);
}
} else if (json_object_is_type(spec, json_type_string)) {
get_one_api(resu, json_object_get_string(spec), NULL);
} else if (json_object_get_boolean(spec)) {
} else if (json_object_is_type(spec, json_type_string)) {
get_one_api(resu, json_object_get_string(spec), NULL);
} else if (json_object_get_boolean(spec)) {
- afb_apiset_enum(main_apiset, get_apis_of_all_cb, resu);
+ afb_apiset_enum(main_apiset, 1, get_apis_of_all_cb, resu);