blob: 2903dbbfe3959cb12d92c0d43af904811e21a528 [file] [log] [blame]
Colm Donelan366023f2019-09-05 10:03:56 +01001//
Jim Flynnbbfe6032020-07-20 16:57:44 +01002// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
Colm Donelan366023f2019-09-05 10:03:56 +01003// SPDX-License-Identifier: MIT
4//
5
6#include "CommandLineProcessor.hpp"
7
8#include <boost/program_options.hpp>
Colm Donelan366023f2019-09-05 10:03:56 +01009#include <iostream>
10
11namespace armnn
12{
13namespace gatordmock
14{
15
16bool CommandLineProcessor::ProcessCommandLine(int argc, char *argv[])
17{
18 namespace po = boost::program_options;
Colm Donelan366023f2019-09-05 10:03:56 +010019 po::options_description desc("Options");
20 try
21 {
Colm Donelana85e2152019-09-09 11:59:08 +010022 desc.add_options()
23 ("help,h", "Display help messages")
Colm Donelana21620d2019-10-11 13:09:49 +010024 ("file,f", po::value<std::string>(&m_File),
25 "The path to the file that contains instructions for the mock gatord")
Colm Donelana85e2152019-09-09 11:59:08 +010026 ("namespace,n", po::value<std::string>(&m_UdsNamespace)->default_value("gatord_namespace"),
27 "The Unix domain socket namespace this server will bind to.\n"
Colm Donelana21620d2019-10-11 13:09:49 +010028 "This will always be prepended with \\0 to use the abstract namespace")
29 ("echo,e", po::bool_switch(&m_Echo)->default_value(false),
30 "Echo packets sent and received to stdout. Disabled by default.\n");
Colm Donelan366023f2019-09-05 10:03:56 +010031 }
32 catch (const std::exception& e)
33 {
34 std::cerr << "Fatal internal error: [" << e.what() << "]" << std::endl;
35 return false;
36 }
37
38 po::variables_map vm;
39 try
40 {
41 po::store(po::parse_command_line(argc, argv, desc), vm);
42
Colm Donelana85e2152019-09-09 11:59:08 +010043 if (vm.count("help"))
Colm Donelan366023f2019-09-05 10:03:56 +010044 {
45 std::cout << "Simulate a Gatord server to interact with ArmNN external profiling." << std::endl;
46 std::cout << std::endl;
47 std::cout << desc << std::endl;
48 return false;
49 }
Colm Donelana21620d2019-10-11 13:09:49 +010050 // Currently the file parameter is mandatory.
51 if (!vm.count("file"))
52 {
53 std::cout << std::endl << "*** Expected --file or -f parameter." << std::endl;
54 std::cout << std::endl;
55 std::cout << desc << std::endl;
56 return false;
57 }
Colm Donelan366023f2019-09-05 10:03:56 +010058 po::notify(vm);
59 }
60 catch (const po::error& e)
61 {
62 std::cerr << e.what() << std::endl << std::endl;
63 std::cerr << desc << std::endl;
64 return false;
65 }
66
67 return true;
68}
69
70} // namespace gatordmock
71
72} // namespace armnn