Colm Donelan | 366023f | 2019-09-05 10:03:56 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "CommandLineProcessor.hpp" |
| 7 | |
| 8 | #include <boost/program_options.hpp> |
Colm Donelan | 366023f | 2019-09-05 10:03:56 +0100 | [diff] [blame] | 9 | #include <iostream> |
| 10 | |
| 11 | namespace armnn |
| 12 | { |
| 13 | namespace gatordmock |
| 14 | { |
| 15 | |
| 16 | bool CommandLineProcessor::ProcessCommandLine(int argc, char *argv[]) |
| 17 | { |
| 18 | namespace po = boost::program_options; |
Colm Donelan | 366023f | 2019-09-05 10:03:56 +0100 | [diff] [blame] | 19 | po::options_description desc("Options"); |
| 20 | try |
| 21 | { |
Colm Donelan | a85e215 | 2019-09-09 11:59:08 +0100 | [diff] [blame] | 22 | desc.add_options() |
| 23 | ("help,h", "Display help messages") |
Colm Donelan | a21620d | 2019-10-11 13:09:49 +0100 | [diff] [blame] | 24 | ("file,f", po::value<std::string>(&m_File), |
| 25 | "The path to the file that contains instructions for the mock gatord") |
Colm Donelan | a85e215 | 2019-09-09 11:59:08 +0100 | [diff] [blame] | 26 | ("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 Donelan | a21620d | 2019-10-11 13:09:49 +0100 | [diff] [blame] | 28 | "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 Donelan | 366023f | 2019-09-05 10:03:56 +0100 | [diff] [blame] | 31 | } |
| 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 Donelan | a85e215 | 2019-09-09 11:59:08 +0100 | [diff] [blame] | 43 | if (vm.count("help")) |
Colm Donelan | 366023f | 2019-09-05 10:03:56 +0100 | [diff] [blame] | 44 | { |
| 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 Donelan | a21620d | 2019-10-11 13:09:49 +0100 | [diff] [blame] | 50 | // 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 Donelan | 366023f | 2019-09-05 10:03:56 +0100 | [diff] [blame] | 58 | 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 |