layer23: Not every application supports every option add enum
authorHolger Hans Peter Freyther <zecke@selfish.org>
Sun, 26 Dec 2010 20:29:51 +0000 (21:29 +0100)
committerHolger Hans Peter Freyther <zecke@selfish.org>
Mon, 27 Dec 2010 18:01:37 +0000 (19:01 +0100)
Allow each application to specify the options it is supporting.

src/host/layer23/include/osmocom/bb/common/l23_app.h
src/host/layer23/src/common/main.c
src/host/layer23/src/misc/app_cell_log.c

index 8a24884..46141e1 100644 (file)
@@ -1,6 +1,15 @@
 #ifndef _L23_APP_H
 #define _L23_APP_H
 
+/* Options supported by the l23 app */
+enum {
+       L23_OPT_SAP     = 1,
+       L23_OPT_ARFCN   = 2,
+       L23_OPT_TAP     = 4,
+       L23_OPT_VTY     = 8,
+       L23_OPT_DBG     = 16,
+};
+
 /* initialization, called once when starting the app, before entering
  * select loop */
 extern int l23_app_init(struct osmocom_ms *ms);
@@ -11,6 +20,8 @@ extern int (*l23_app_exit) (struct osmocom_ms *ms);
 struct l23_app_info {
        const char *copyright;
        const char *contribution;
+
+       int (*cfg_supported)();
 };
 
 extern struct l23_app_info *l23_app_info();
index 2bcb2f4..1f9afaf 100644 (file)
@@ -74,17 +74,33 @@ static void print_usage(const char *app)
 
 static void print_help()
 {
+       int options = 0xff;
+       struct l23_app_info *app = l23_app_info();
+
+       if (app && app->cfg_supported != 0)
+               options = app->cfg_supported();
+
        printf(" Some help...\n");
        printf("  -h --help             this text\n");
        printf("  -s --socket           /tmp/osmocom_l2. Path to the unix "
                "domain socket (l2)\n");
-       printf("  -S --sap              /tmp/osmocom_sap. Path to the unix "
-               "domain socket (BTSAP)\n");
-       printf("  -a --arfcn NR         The ARFCN to be used for layer2.\n");
-       printf("  -i --gsmtap-ip        The destination IP used for GSMTAP.\n");
-       printf("  -v --vty-port         The VTY port number to telnet to. "
-               "(default %u)\n", vty_port);
-       printf("  -d --debug            Change debug flags.\n");
+
+       if (options & L23_OPT_SAP)
+               printf("  -S --sap              /tmp/osmocom_sap. Path to the "
+                       "unix domain socket (BTSAP)\n");
+
+       if (options & L23_OPT_ARFCN)
+               printf("  -a --arfcn NR         The ARFCN to be used for layer2.\n");
+
+       if (options & L23_OPT_TAP)
+               printf("  -i --gsmtap-ip        The destination IP used for GSMTAP.\n");
+
+       if (options & L23_OPT_VTY)
+               printf("  -v --vty-port         The VTY port number to telnet "
+                       "to. (default %u)\n", vty_port);
+
+       if (options & L23_OPT_DBG)
+               printf("  -d --debug            Change debug flags.\n");
 }
 
 static void handle_options(int argc, char **argv)
index 1ab64f5..a72588f 100644 (file)
@@ -72,8 +72,14 @@ int l23_app_init(struct osmocom_ms *ms)
        return 0;
 }
 
+static int l23_cfg_supported()
+{
+       return L23_OPT_TAP | L23_OPT_DBG;
+}
+
 static struct l23_app_info info = {
        .copyright      = "Copyright (C) 2010 Andreas Eversberg\n",
+       .cfg_supported  = l23_cfg_supported,
 };
 
 struct l23_app_info *l23_app_info()