aboutsummaryrefslogtreecommitdiffstats
path: root/ctrl/facemgr/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'ctrl/facemgr/src/main.c')
-rw-r--r--ctrl/facemgr/src/main.c255
1 files changed, 119 insertions, 136 deletions
diff --git a/ctrl/facemgr/src/main.c b/ctrl/facemgr/src/main.c
index 344b034ae..18d2f8f7c 100644
--- a/ctrl/facemgr/src/main.c
+++ b/ctrl/facemgr/src/main.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 Cisco and/or its affiliates.
* 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:
@@ -24,7 +24,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <unistd.h> // sleep
+#include <unistd.h> // sleep
#include <hicn/facemgr.h>
#include <hicn/facemgr/cfg.h>
@@ -41,7 +41,7 @@
#if 0
static struct event_base * loop;
#endif
-static loop_t * loop = NULL;
+static loop_t* loop = NULL;
#ifdef __linux__
#ifdef WITH_THREAD
@@ -49,210 +49,193 @@ static bool stop = false;
#endif /* WITH_THREAD */
#endif /* __linux__ */
-static struct option long_options[] =
-{
- {"config", required_argument, 0, 'c'},
- {0, 0, 0, 0}
-};
+static struct option long_options[] = {{"config", required_argument, 0, 'c'},
+ {0, 0, 0, 0}};
typedef struct {
- char * cfgfile;
+ char* cfgfile;
} facemgr_options_t;
-void usage(const char * progname)
-{
- printf("%s: Face manager daemon\n", progname);
- printf("\n");
- printf("Usage: %s [OPTIONS]\n", progname);
- printf("\n");
- printf("OPTIONS:\n");
- printf(" -c --config [FILE|none] Sets the configuration file (unless none, default: /etc/facemgr.conf, ~/facemgr.conf)\n");
- printf("\n");
+void usage(const char* progname) {
+ printf("%s: Face manager daemon\n", progname);
+ printf("\n");
+ printf("Usage: %s [OPTIONS]\n", progname);
+ printf("\n");
+ printf("OPTIONS:\n");
+ printf(
+ " -c --config [FILE|none] Sets the configuration file (unless none, "
+ "default: /etc/facemgr.conf, ~/facemgr.conf)\n");
+ printf("\n");
}
void facemgr_signal_handler(int signal) {
- fprintf(stderr, "Received ^C... quitting !\n");
- if (loop) {
- loop_break(loop);
+ fprintf(stderr, "Received ^C... quitting !\n");
+ if (loop) {
+ loop_break(loop);
#ifdef __linux__
#ifdef WITH_THREAD
stop = true;
#endif /* WITH_THREAD */
#endif /* __linux__ */
- }
+ }
}
-int parse_cmdline(int argc, char ** argv, facemgr_options_t * opts)
-{
- int c;
- while ((c = getopt_long(argc, argv, "c:", long_options, NULL)) != -1) {
- switch(c) {
- case 'c':
- opts->cfgfile = optarg;
- break;
- case ':':
- case '?':
- default:
- usage(argv[0]);
- exit(EXIT_FAILURE);
- }
-
+int parse_cmdline(int argc, char** argv, facemgr_options_t* opts) {
+ int c;
+ while ((c = getopt_long(argc, argv, "c:", long_options, NULL)) != -1) {
+ switch (c) {
+ case 'c':
+ opts->cfgfile = optarg;
+ break;
+ case ':':
+ case '?':
+ default:
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
}
- return 0;
+ }
+ return 0;
}
-#ifdef __linux__
-
-#endif /* __linux__ */
-
-int
-dump_facelet(const facemgr_t * facemgr, const facelet_t * facelet,
- void * user_data)
-{
- char facelet_s[MAXSZ_FACELET];
- facelet_snprintf(facelet_s, MAXSZ_FACELET, facelet);
- DEBUG("%s", facelet_s);
- return 0;
+int dump_facelet(const facemgr_t* facemgr, const facelet_t* facelet,
+ void* user_data) {
+ char facelet_s[MAXSZ_FACELET];
+ facelet_snprintf(facelet_s, MAXSZ_FACELET, facelet);
+ DEBUG("%s", facelet_s);
+ return 0;
}
-int main(int argc, char ** argv)
-{
- facemgr_cfg_t * cfg = NULL;
- facemgr_t * facemgr;
+int main(int argc, char** argv) {
+ facemgr_cfg_t* cfg = NULL;
+ facemgr_t* facemgr;
- struct sigaction sigIntHandler;
- sigIntHandler.sa_handler = facemgr_signal_handler;
- sigemptyset(&sigIntHandler.sa_mask);
- sigIntHandler.sa_flags = 0;
- sigaction(SIGINT, &sigIntHandler, NULL);
+ struct sigaction sigIntHandler;
+ sigIntHandler.sa_handler = facemgr_signal_handler;
+ sigemptyset(&sigIntHandler.sa_mask);
+ sigIntHandler.sa_flags = 0;
+ sigaction(SIGINT, &sigIntHandler, NULL);
- char cfgfile[PATH_MAX];
+ char cfgfile[PATH_MAX];
- // TODO: default < config < commandline on a per option basis
+ // TODO: default < config < commandline on a per option basis
- /* Commandline */
- facemgr_options_t cmdline_opts = {0};
- if (parse_cmdline(argc, argv, &cmdline_opts) < 0) {
- ERROR("Error parsing commandline");
- goto ERR_CMDLINE;
- }
+ /* Commandline */
+ facemgr_options_t cmdline_opts = {0};
+ if (parse_cmdline(argc, argv, &cmdline_opts) < 0) {
+ ERROR("Error parsing commandline");
+ goto ERR_CMDLINE;
+ }
- /* Configuration file */
- //facemgr_options_t cfgfile_opts;
+ /* Configuration file */
+ // facemgr_options_t cfgfile_opts;
- if (cmdline_opts.cfgfile) {
- if (strcasecmp(cmdline_opts.cfgfile, "none") == 0)
- goto NO_CFGFILE;
+ if (cmdline_opts.cfgfile) {
+ if (strcasecmp(cmdline_opts.cfgfile, "none") == 0) goto NO_CFGFILE;
- if (!realpath(cmdline_opts.cfgfile, (char*)&cfgfile))
- goto ERR_PATH;
+ if (!realpath(cmdline_opts.cfgfile, (char*)&cfgfile)) goto ERR_PATH;
- goto PARSE_CFGFILE;
- }
+ goto PARSE_CFGFILE;
+ }
- /* No commandline path specifed, probe default locations... */
+ /* No commandline path specifed, probe default locations... */
- if (probe_cfgfile(cfgfile) < 0)
- goto NO_CFGFILE;
+ if (probe_cfgfile(cfgfile) < 0) goto NO_CFGFILE;
PARSE_CFGFILE:
- DEBUG("Using configuration file %s", cfgfile);
- cfg = facemgr_cfg_create();
- if (!cfg)
- goto ERR_FACEMGR_CFG;
+ DEBUG("Using configuration file %s", cfgfile);
+ cfg = facemgr_cfg_create();
+ if (!cfg) goto ERR_FACEMGR_CFG;
- if (parse_config_file(cfgfile, cfg) < 0) {
- ERROR("Error parsing configuration file %s", cfgfile);
- goto ERR_PARSE;
- }
+ if (parse_config_file(cfgfile, cfg) < 0) {
+ ERROR("Error parsing configuration file %s", cfgfile);
+ goto ERR_PARSE;
+ }
- facemgr = facemgr_create_with_config(cfg);
- if (!facemgr)
- goto ERR_FACEMGR_CONFIG;
+ facemgr = facemgr_create_with_config(cfg);
+ if (!facemgr) goto ERR_FACEMGR_CONFIG;
- goto MAIN_LOOP;
+ goto MAIN_LOOP;
NO_CFGFILE:
- facemgr = facemgr_create();
- if (!facemgr)
- goto ERR_FACEMGR;
+ facemgr = facemgr_create();
+ if (!facemgr) goto ERR_FACEMGR;
MAIN_LOOP:
- /* Main loop */
- loop = loop_create();
- facemgr_set_callback(facemgr, loop, (void*)loop_callback);
+ /* Main loop */
+ loop = loop_create();
+ if (!loop) {
+ ERROR("Failed to create main loop");
+ goto ERR_LOOP;
+ }
+ facemgr_set_callback(facemgr, loop, (void*)loop_callback);
#ifdef __ANDROID__
- facemgr_set_jvm(facemgr, NULL);
+ facemgr_set_jvm(facemgr, NULL);
#endif /* __ ANDROID__ */
- DEBUG("Bootstrap...");
+ DEBUG("Bootstrap...");
- if (facemgr_bootstrap(facemgr) < 0 )
- goto ERR_BOOTSTRAP;
+ if (facemgr_bootstrap(facemgr) < 0) goto ERR_BOOTSTRAP;
- if (loop_dispatch(loop) < 0) {
- ERROR("Failed to run main loop");
- return EXIT_FAILURE;
- }
+ if (loop_dispatch(loop) < 0) {
+ ERROR("Failed to run main loop");
+ goto ERR_DISPATCH;
+ }
#ifdef __linux__
#ifdef WITH_THREAD
- unsigned cpt = 0;
- while(!stop) {
- if (cpt == 10) {
- DEBUG("<facelets>");
+ unsigned cpt = 0;
+ while (!stop) {
+ if (cpt == 10) {
+ DEBUG("<facelets>");
#if 1
- facemgr_list_facelets(facemgr, dump_facelet, NULL);
+ facemgr_list_facelets(facemgr, dump_facelet, NULL);
#else
- char * buffer;
- int n = facemgr_list_facelets_json(facemgr, &buffer);
- printf("%s\n", buffer);
- free(buffer);
+ char* buffer;
+ int n = facemgr_list_facelets_json(facemgr, &buffer);
+ printf("%s\n", buffer);
+ free(buffer);
#endif
- DEBUG("</facelets>");
- cpt = 0;
- }
- usleep(500000);
- cpt++;
+ DEBUG("</facelets>");
+ cpt = 0;
}
+ usleep(500000);
+ cpt++;
+ }
#endif /* WITH_THREAD */
#endif /* __linux__ */
- facemgr_stop(facemgr);
+ facemgr_stop(facemgr);
- if (loop_undispatch(loop) < 0) {
- ERROR("Failed to terminate main loop");
- return EXIT_FAILURE;
- }
+ if (loop_undispatch(loop) < 0) {
+ ERROR("Failed to terminate main loop");
+ }
- facemgr_free(facemgr);
+ facemgr_free(facemgr);
- if (cfg)
- facemgr_cfg_free(cfg);
+ if (cfg) facemgr_cfg_free(cfg);
- loop_free(loop);
+ loop_free(loop);
- return EXIT_SUCCESS;
+ return EXIT_SUCCESS;
ERR_BOOTSTRAP:
+ facemgr_free(facemgr);
+ERR_DISPATCH:
+ loop_free(loop);
+ERR_LOOP:
- facemgr_free(facemgr);
- loop_free(loop);
ERR_FACEMGR_CONFIG:
ERR_FACEMGR:
ERR_PARSE:
- if (cfg)
- facemgr_cfg_free(cfg);
+ if (cfg) facemgr_cfg_free(cfg);
ERR_FACEMGR_CFG:
ERR_PATH:
ERR_CMDLINE:
- return EXIT_FAILURE;
-
-
+ return EXIT_FAILURE;
}