serialization: make input consistency between printer and serializer 31/203931/4
authorsanghyeok.oh <sanghyeok.oh@samsung.com>
Thu, 18 Apr 2019 07:00:22 +0000 (16:00 +0900)
committersanghyeok.oh <sanghyeok.oh@samsung.com>
Mon, 22 Apr 2019 02:50:38 +0000 (11:50 +0900)
Change-Id: I7ef136fde2a3b7cdd3cf117ccdc32fc5e0dce52c
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
src/dbuspolicy_printer.cpp
src/dbuspolicy_serializer.cpp

index 18ed6ce..8b5f2c8 100644 (file)
@@ -1,27 +1,68 @@
 #include "internal/print_content.hpp"
 #include "internal/storage_backend_serialized.hpp"
 #include <iostream>
+#include <getopt.h>
+#include "libdbuspolicy1-private.h"
 
 using namespace std;
 
+static const struct option options[] = {
+       {"system", no_argument, 0, 0 },
+       {"session", no_argument, 0, 0},
+       {0, 0, 0, 0}
+};
+
 static void print_help(const char *name) {
        cout << endl;
-       cout << "usage: " << name << " <input_filename.serialized>" << endl;
+       cout << "usage: " << name << " [-i input_filename]" << endl;
+       cout << "       " << name << " {--system|--session}" << endl;
        cout << endl;
 }
 
-int main(int argc, const char **argv) {
+int main(int argc, char *argv[]) {
+       std::string input_filename;
+       int c;
 
        if (argc < 2) {
                print_help(argv[0]);
                return 1;
        }
 
+       while (1) {
+               int option_index;
+               c = getopt_long(argc, argv, "i:", options, &option_index);
+               if (c == -1)
+                       break;
+
+               switch(c) {
+               case 0:
+                       if (option_index == 0)
+                               input_filename = system_bus_conf_file_primary();
+                       else
+                               input_filename = session_bus_conf_file_primary();
+                       input_filename.append(".serialized");
+                       break;
+               case 'i':
+                       input_filename = optarg;
+                       break;
+               case '?':
+                       break;
+               }
+               if (!input_filename.empty())
+                       break;
+       }
+
+       if (input_filename.empty()) {
+               cout << "No input filename" << endl;
+               print_help(argv[0]);
+               return 1;
+       }
+
        tslog::init(tslog::ldp_log_level::DEFAULT);
 
        ldp_serialized::StorageBackendSerialized storage;
 
-       if (!storage.init(argv[1], true))
+       if (!storage.init(input_filename.c_str(), true))
                return 1;
 
        storage.printContent();
index a08c6a1..90a4f55 100644 (file)
@@ -12,7 +12,8 @@ using namespace std;
 
 static const struct option options[] = {
        {"system", no_argument, 0, 0 },
-       {"session", no_argument, 0, 0}
+       {"session", no_argument, 0, 0},
+       {0, 0, 0, 0}
 };
 
 static void print_help(const char *name) {