blob: a532401cc61c3bb8b0723e68734dc6cff91435b7 [file] [log] [blame]
Colm Donelan366023f2019-09-05 10:03:56 +01001//
Jim Flynn357add22023-04-10 23:26:40 +01002// Copyright © 2019, 2023 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
Matthew Sloyanf7017cb2020-09-30 13:07:51 +01008#include <cxxopts/cxxopts.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{
Matthew Sloyanf7017cb2020-09-30 13:07:51 +010018 cxxopts::Options options("GatordMock",
19 "Simulate a Gatord server to interact with ArmNN external profiling.");
20
Colm Donelan366023f2019-09-05 10:03:56 +010021 try
22 {
Matthew Sloyanf7017cb2020-09-30 13:07:51 +010023 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"));
Colm Donelan366023f2019-09-05 10:03:56 +010036 }
37 catch (const std::exception& e)
38 {
39 std::cerr << "Fatal internal error: [" << e.what() << "]" << std::endl;
40 return false;
41 }
42
Colm Donelan366023f2019-09-05 10:03:56 +010043 try
44 {
Matthew Sloyanf7017cb2020-09-30 13:07:51 +010045 auto result = options.parse(argc, argv);
Colm Donelan366023f2019-09-05 10:03:56 +010046
Matthew Sloyanf7017cb2020-09-30 13:07:51 +010047 if (result.count("help"))
Colm Donelan366023f2019-09-05 10:03:56 +010048 {
Matthew Sloyanf7017cb2020-09-30 13:07:51 +010049 std::cout << options.help() << std::endl;
Colm Donelan366023f2019-09-05 10:03:56 +010050 return false;
51 }
Matthew Sloyanf7017cb2020-09-30 13:07:51 +010052
Colm Donelana21620d2019-10-11 13:09:49 +010053 // Currently the file parameter is mandatory.
Matthew Sloyanf7017cb2020-09-30 13:07:51 +010054 if (!result.count("file"))
Colm Donelana21620d2019-10-11 13:09:49 +010055 {
Matthew Sloyanf7017cb2020-09-30 13:07:51 +010056 std::cout << "-f/--file parameter is mandatory." << std::endl;
Colm Donelana21620d2019-10-11 13:09:49 +010057 return false;
58 }
Matthew Sloyanf7017cb2020-09-30 13:07:51 +010059
60 // Sets bool value correctly.
61 if (result.count("echo"))
62 {
63 m_Echo = true;
64 }
Colm Donelan366023f2019-09-05 10:03:56 +010065 }
Jim Flynn357add22023-04-10 23:26:40 +010066 catch (const cxxopts::exceptions::exception& e)
Colm Donelan366023f2019-09-05 10:03:56 +010067 {
Matthew Sloyanf7017cb2020-09-30 13:07:51 +010068 std::cerr << e.what() << std::endl;
Colm Donelan366023f2019-09-05 10:03:56 +010069 return false;
70 }
71
72 return true;
73}
74
75} // namespace gatordmock
76
Jim Flynn357add22023-04-10 23:26:40 +010077} // namespace armnn