afb-supervision: Remove dependency to external 43/15343/2
authorJosé Bollo <jose.bollo@iot.bzh>
Thu, 12 Jul 2018 09:22:14 +0000 (11:22 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Fri, 13 Jul 2018 10:19:11 +0000 (12:19 +0200)
Also some cleaning in use of extern to allow
accurate grep.

Removing extern is better for linking and for
structuration.

Change-Id: I8121c4b9b34fa2737bffd2ecbe170d04d1d60ad1
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afb-hreq.c
src/afb-hsrv.c
src/afb-hsrv.h
src/afb-session.c
src/afb-supervision.c
src/afb-supervision.h
src/afb-trace.c
src/main-afb-daemon.c

index fa16565..54c097e 100644 (file)
@@ -36,6 +36,7 @@
 #include "afb-msg-json.h"
 #include "afb-context.h"
 #include "afb-hreq.h"
+#include "afb-hsrv.h"
 #include "afb-session.h"
 #include "afb-cred.h"
 #include "verbose.h"
@@ -168,10 +169,9 @@ static void afb_hreq_reply_v(struct afb_hreq *hreq, unsigned status, struct MHD_
 
        hreq->replied = 1;
        if (hreq->suspended != 0) {
-               extern void run_micro_httpd(struct afb_hsrv *hsrv);
                MHD_resume_connection (hreq->connection);
                hreq->suspended = 0;
-               run_micro_httpd(hreq->hsrv);
+               afb_hsrv_run(hreq->hsrv);
        }
 }
 
index 3bca583..efa74f4 100644 (file)
@@ -263,7 +263,7 @@ static void do_run(int signum, void *arg)
        fdev_set_events(hsrv->fdev, EPOLLIN);
 }
 
-void run_micro_httpd(struct afb_hsrv *hsrv)
+void afb_hsrv_run(struct afb_hsrv *hsrv)
 {
        fdev_set_events(hsrv->fdev, 0);
        if (jobs_queue(hsrv, 0, do_run, hsrv) < 0)
@@ -272,7 +272,7 @@ void run_micro_httpd(struct afb_hsrv *hsrv)
 
 static void listen_callback(void *hsrv, uint32_t revents, struct fdev *fdev)
 {
-       run_micro_httpd(hsrv);
+       afb_hsrv_run(hsrv);
 }
 
 static int new_client_handler(void *cls, const struct sockaddr *addr, socklen_t addrlen)
index c03894a..f72fc3b 100644 (file)
@@ -32,3 +32,4 @@ extern int afb_hsrv_add_alias(struct afb_hsrv *hsrv, const char *prefix, int dir
 extern int afb_hsrv_add_alias_root(struct afb_hsrv *hsrv, const char *prefix, struct locale_root *root, int priority, int relax);
 extern int afb_hsrv_add_handler(struct afb_hsrv *hsrv, const char *prefix, int (*handler) (struct afb_hreq *, void *), void *data, int priority);
 
+extern void afb_hsrv_run(struct afb_hsrv *hsrv);
index 16fc69b..adfed2a 100644 (file)
@@ -59,7 +59,7 @@ struct cookie
 struct afb_session
 {
        struct afb_session *next; /**< link to the next */
-       unsigned refcount;      /**< external reference count of the session */
+       unsigned refcount;      /**< count of reference to the session */
        int timeout;            /**< timeout of the session */
        time_t expiration;      /**< expiration time of the token */
        pthread_mutex_t mutex;  /**< mutex of the session */
index 84c302f..2482a08 100644 (file)
@@ -51,8 +51,6 @@
 #include "wrap-json.h"
 #include "jobs.h"
 
-extern struct afb_config *main_config;
-
 /* api and apiset name */
 static const char supervision_apiname[] = AFS_SUPERVISION_APINAME;
 static const char supervisor_apiname[] = AFS_SUPERVISOR_APINAME;
@@ -64,7 +62,10 @@ static const char supervisor_socket_path[] = AFS_SUPERVISION_SOCKET;
 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 
 /* the standard apiset */
-extern struct afb_apiset *main_apiset;
+static struct {
+       struct afb_apiset *apiset;
+       struct afb_config *config;
+} global;
 
 /* the supervision apiset (not exported) */
 static struct afb_apiset *supervision_apiset;
@@ -237,7 +238,7 @@ static void on_sighup(int signum)
 /**
  * initialize the supervision
  */
-int afb_supervision_init()
+int afb_supervision_init(struct afb_apiset *apiset, struct afb_config *config)
 {
        int rc;
        struct sigaction sa;
@@ -263,6 +264,10 @@ int afb_supervision_init()
                return rc;
        }
 
+       /* init the globals */
+       global.apiset = apiset;
+       global.config = config;
+
        /* get SIGHUP */
        memset(&sa, 0, sizeof sa);
        sa.sa_handler = on_sighup;
@@ -346,7 +351,7 @@ static void on_supervision_call(void *closure, struct afb_xreq *xreq)
                afb_xreq_reply(xreq, list, NULL, NULL);
                break;
        case Config:
-               afb_xreq_reply(xreq, afb_config_json(main_config), NULL, NULL);
+               afb_xreq_reply(xreq, afb_config_json(global.config), NULL, NULL);
                break;
        case Trace:
                if (!trace)
@@ -372,7 +377,7 @@ static void on_supervision_call(void *closure, struct afb_xreq *xreq)
                if (wrap_json_unpack(args, "{ss ss s?o*}", "api", &api, "verb", &verb, "args", &sub))
                        afb_xreq_reply(xreq, NULL, "error", "bad request");
                else {
-                       xapi = afb_apiset_lookup_started(main_apiset, api, 1);
+                       xapi = afb_apiset_lookup_started(global.apiset, api, 1);
                        if (!xapi)
                                afb_xreq_reply_unknown_api(xreq);
                        else {
index 5ffd432..0acf7f6 100644 (file)
@@ -18,4 +18,7 @@
 
 #pragma once
 
-extern int afb_supervision_init();
+struct afb_apiset;
+struct afb_config;
+
+extern int afb_supervision_init(struct afb_apiset *apiset, struct afb_config *config);
index 0e285e1..dd6e863 100644 (file)
@@ -1739,7 +1739,7 @@ int afb_trace_add(afb_req_t req, struct json_object *args, struct afb_trace *tra
 }
 
 /* drop traces */
-extern int afb_trace_drop(afb_req_t req, struct json_object *args, struct afb_trace *trace)
+int afb_trace_drop(afb_req_t req, struct json_object *args, struct afb_trace *trace)
 {
        int rc;
        struct context context;
index 4be6cc5..75d5190 100644 (file)
@@ -580,7 +580,7 @@ static void start(int signum, void *arg)
                goto error;
        }
 #if defined(WITH_SUPERVISION)
-       if (afb_supervision_init() < 0) {
+       if (afb_supervision_init(main_apiset, main_config) < 0) {
                ERROR("failed to setup supervision");
                goto error;
        }