• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "CommandLineProcessor.hpp"
7 
8 #include <cxxopts/cxxopts.hpp>
9 #include <iostream>
10 
11 namespace armnn
12 {
13 namespace gatordmock
14 {
15 
ProcessCommandLine(int argc,char * argv[])16 bool CommandLineProcessor::ProcessCommandLine(int argc, char *argv[])
17 {
18     cxxopts::Options options("GatordMock",
19                              "Simulate a Gatord server to interact with ArmNN external profiling.");
20 
21     try
22     {
23         options.add_options()
24             ("h,help", "Display help messages")
25             ("f,file",
26                 "The path to the file that contains instructions for the mock gatord.",
27                 cxxopts::value<std::string>(m_File))
28             ("n,namespace",
29                 "The Unix domain socket namespace this server will bind to.\n"
30                 "This will always be prepended with \\0 to use the abstract namespace",
31                 cxxopts::value<std::string>(m_UdsNamespace)->default_value("gatord_namespace"))
32             ("e,echo",
33                 "Echo packets sent and received to stdout. Disabled by default. "
34                 "Default value = false.",
35                 cxxopts::value<bool>(m_Echo)->default_value("false"));
36     }
37     catch (const std::exception& e)
38     {
39         std::cerr << "Fatal internal error: [" << e.what() << "]" << std::endl;
40         return false;
41     }
42 
43     try
44     {
45         auto result = options.parse(argc, argv);
46 
47         if (result.count("help"))
48         {
49             std::cout << options.help() << std::endl;
50             return false;
51         }
52 
53         // Currently the file parameter is mandatory.
54         if (!result.count("file"))
55         {
56             std::cout << "-f/--file parameter is mandatory." << std::endl;
57             return false;
58         }
59 
60         // Sets bool value correctly.
61         if (result.count("echo"))
62         {
63             m_Echo = true;
64         }
65     }
66     catch (const cxxopts::OptionException& e)
67     {
68         std::cerr << e.what() << std::endl;
69         return false;
70     }
71 
72     return true;
73 }
74 
75 } // namespace gatordmock
76 
77 } // namespace armnn