hooks: Allow to remove hooking (and/or trace)
[src/app-framework-binder.git] / src / afb-apiset.c
index 994a9c7..468a364 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017, 2018 "IoT.bzh"
+ * Copyright (C) 2016-2019 "IoT.bzh"
  * Author José Bollo <jose.bollo@iot.bzh>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -427,17 +427,23 @@ struct afb_apiset *afb_apiset_subset_get(struct afb_apiset *set)
  * Set the subset of the set
  * @param set the api set
  * @param subset the subset to set
+ *
+ * @return 0 in case of success or -1 if it had created a loop
  */
-void afb_apiset_subset_set(struct afb_apiset *set, struct afb_apiset *subset)
+int afb_apiset_subset_set(struct afb_apiset *set, struct afb_apiset *subset)
 {
        struct afb_apiset *tmp;
-       if (subset == set) {
-               /* avoid infinite loop */
-               subset = NULL;
-       }
+
+       /* avoid infinite loop */
+       for (tmp = subset ; tmp ; tmp = tmp->subset)
+               if (tmp == set)
+                       return -1;
+
        tmp = set->subset;
        set->subset = afb_apiset_addref(subset);
        afb_apiset_unref(tmp);
+
+       return 0;
 }
 
 void afb_apiset_onlack_set(struct afb_apiset *set, int (*callback)(void*, struct afb_apiset*, const char*), void *closure, void (*cleanup)(void*))
@@ -495,7 +501,8 @@ int afb_apiset_add(struct afb_apiset *set, const char *name, struct afb_api_item
        desc->next = all_apis;
        all_apis = desc;
 
-       INFO("API %s added", name);
+       if (afb_api_is_public(name))
+               INFO("API %s added", name);
 
        return 0;
 
@@ -777,15 +784,15 @@ static int start_api(struct api_desc *api)
                return -1;
        }
 
-       INFO("API %s starting...", api->name);
+       NOTICE("API %s starting...", api->name);
        api->status = EBUSY;
        rc = start_array_classes(&api->require.classes);
        if (rc < 0)
-               ERROR("Can start classes needed by api %s", api->name);
+               ERROR("Cannot start classes needed by api %s", api->name);
        else {
                rc = start_array_depends(&api->require.apis);
                if (rc < 0)
-                       ERROR("Can start apis needed by api %s", api->name);
+                       ERROR("Cannot start apis needed by api %s", api->name);
                else if (api->api.itf->service_start) {
                        rc = api->api.itf->service_start(api->api.closure);
                        if (rc < 0)
@@ -796,7 +803,7 @@ static int start_api(struct api_desc *api)
                api->status = errno ?: ECANCELED;
                return -1;
        }
-       NOTICE("API %s started", api->name);
+       INFO("API %s started", api->name);
        api->status = 0;
        return 0;
 }
@@ -863,6 +870,7 @@ int afb_apiset_start_all_services(struct afb_apiset *set)
        return ret;
 }
 
+#if WITH_AFB_HOOK
 /**
  * Ask to update the hook flags of the 'api'
  * @param set the api set
@@ -886,6 +894,7 @@ void afb_apiset_update_hooks(struct afb_apiset *set, const char *name)
                        d->api.itf->update_hooks(d->api.closure);
        }
 }
+#endif
 
 /**
  * Set the logmask of the 'api' to 'mask'