ArmNN
 21.02
CommandLineProcessor Class Reference

Use Boost program options to process the command line. More...

#include <CommandLineProcessor.hpp>

Public Member Functions

bool ProcessCommandLine (int argc, char *argv[])
 
bool IsEchoEnabled ()
 
std::string GetUdsNamespace ()
 
std::string GetCommandFile ()
 

Detailed Description

Use Boost program options to process the command line.

-h or –help to print the options. -n or –namespace to specify the UDS namespace that the server will be listening on. -e or –echo print all sent and received packets to stdout. -f or –file The path to the file that contains instructions for the mock gatord.

Definition at line 20 of file CommandLineProcessor.hpp.

Member Function Documentation

◆ GetCommandFile()

std::string GetCommandFile ( )
inline

Definition at line 33 of file CommandLineProcessor.hpp.

Referenced by main().

34  {
35  return m_File;
36  }

◆ GetUdsNamespace()

std::string GetUdsNamespace ( )
inline

Definition at line 29 of file CommandLineProcessor.hpp.

Referenced by main().

30  {
31  return m_UdsNamespace;
32  }

◆ IsEchoEnabled()

bool IsEchoEnabled ( )
inline

Definition at line 24 of file CommandLineProcessor.hpp.

25  {
26  return m_Echo;
27  }

◆ ProcessCommandLine()

bool ProcessCommandLine ( int  argc,
char *  argv[] 
)

Definition at line 16 of file CommandLineProcessor.cpp.

Referenced by main().

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 }

The documentation for this class was generated from the following files: