afs-supervisor: Add ws-server option 27/14327/1
authorJosé Bollo <jose.bollo@iot.bzh>
Fri, 6 Apr 2018 22:01:33 +0000 (00:01 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Wed, 13 Jun 2018 15:14:18 +0000 (17:14 +0200)
This allow exportation of the API of the supervisor.

Change-Id: I167ec94f00f40f8c3640377a46820e6a060b24f1
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afs-config.c
src/afs-config.h
src/afs-main.c

index eee4ccc..71d5ab7 100644 (file)
@@ -71,6 +71,7 @@
 #define SET_NAME           'n'
 #define SET_TCP_PORT       'p'
 #define SET_QUIET          'q'
+#define WS_SERVICE         's'
 #define SET_AUTH_TOKEN     't'
 #define SET_UPLOAD_DIR     'u'
 #define DISPLAY_VERSION    'V'
@@ -78,7 +79,7 @@
 #define SET_WORK_DIR       'w'
 
 const char shortopts[] =
-       "hn:p:qrt:u:Vvw:"
+       "hn:p:qrs:t:u:Vvw:"
 ;
 
 // Command line structure hold cli --command + help text
@@ -113,6 +114,7 @@ static AFB_options cliOptions[] = {
 
        {SET_AUTH_TOKEN,    1, "token",       "Initial Secret [default=" AFS_SUPERVISOR_TOKEN ", use --token="" to allow any token]"},
 
+       {WS_SERVICE,        1, "ws-server",   "Povide supervisor as websocket"},
        {DISPLAY_VERSION,   0, "version",     "Display version and copyright"},
        {DISPLAY_HELP,      0, "help",        "Display this help"},
 
@@ -324,6 +326,10 @@ static void parse_arguments(int argc, char **argv, struct afs_config *config)
                        config->name = argvalstr(optc);
                        break;
 
+               case WS_SERVICE:
+                       config->ws_server = argvalstr(optc);
+                       break;
+
                case DISPLAY_VERSION:
                        noarg(optc);
                        printVersion(stdout);
@@ -401,6 +407,7 @@ void afs_config_dump(struct afs_config *config)
        S(uploaddir)
        S(token)
        S(name)
+       S(ws_server)
 
        D(httpdPort)
        D(cacheTimeout)
index ca7dfc2..f374e81 100644 (file)
@@ -26,6 +26,7 @@ struct afs_config {
        char *uploaddir;        // where to store transient files
        char *token;            // initial authentication token [default NULL no session]
        char *name;             /* name to set to the daemon */
+       char *ws_server;        /* exported api */
 
        /* integers */
        int httpdPort;
index 980a1bc..93e4932 100644 (file)
@@ -30,6 +30,7 @@
 #include "afb-hswitch.h"
 #include "afb-hreq.h"
 #include "afb-apiset.h"
+#include "afb-api-ws.h"
 #include "afb-session.h"
 
 #include "afs-supervisor.h"
@@ -149,6 +150,15 @@ static void start(int signum, void *arg)
                goto error;
        }
 
+       /* export the service if required */
+       if (main_config->ws_server) {
+               rc = afb_api_ws_add_server(main_config->ws_server, main_apiset);
+               if (rc < 0) {
+                       ERROR("Can't export (ws-server) api %s: %m", main_config->ws_server);
+                       goto error;
+               }
+       }
+
        /* start the services */
        if (afb_apiset_start_all_services(main_apiset, 1) < 0)
                goto error;