ArmNN
 21.02
GatordMockMain.cpp File Reference
#include "CommandFileParser.hpp"
#include "CommandLineProcessor.hpp"
#include "GatordMockService.hpp"
#include <server/include/basePipeServer/ConnectionHandler.hpp>
#include <string>
#include <signal.h>

Go to the source code of this file.

Functions

void exit_capture (int signum)
 
bool CreateMockService (std::unique_ptr< arm::pipe::BasePipeServer > basePipeServer, std::string commandFile, bool isEchoEnabled)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ CreateMockService()

bool CreateMockService ( std::unique_ptr< arm::pipe::BasePipeServer >  basePipeServer,
std::string  commandFile,
bool  isEchoEnabled 
)

Definition at line 26 of file GatordMockMain.cpp.

References GatordMockService::LaunchReceivingThread(), CommandFileParser::ParseFile(), GatordMockService::SendConnectionAck(), GatordMockService::WaitForReceivingThread(), and GatordMockService::WaitForStreamMetaData().

29 {
30  GatordMockService mockService(std::move(basePipeServer), isEchoEnabled);
31 
32  // Send receive the stream metadata and send connection ack.
33  if (!mockService.WaitForStreamMetaData())
34  {
35  return EXIT_FAILURE;
36  }
37  mockService.SendConnectionAck();
38 
39  // Prepare to receive data.
40  mockService.LaunchReceivingThread();
41 
42  // Process the SET and WAIT command from the file.
43  CommandFileParser commandLineParser;
44  commandLineParser.ParseFile(commandFile, mockService);
45 
46  // Once we've finished processing the file wait for the receiving thread to close.
47  mockService.WaitForReceivingThread();
48 
49  return EXIT_SUCCESS;
50 }
void ParseFile(std::string CommandFile, GatordMockService &mockService)
A class that implements a Mock Gatord server.
This class parses a command file for the GatordMockService.

◆ exit_capture()

void exit_capture ( int  signum)

Definition at line 20 of file GatordMockMain.cpp.

References armnn::IgnoreUnused().

Referenced by main().

21 {
23  run = false;
24 }
void IgnoreUnused(Ts &&...)

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 52 of file GatordMockMain.cpp.

References exit_capture(), CommandLineProcessor::GetCommandFile(), CommandLineProcessor::GetUdsNamespace(), and CommandLineProcessor::ProcessCommandLine().

53 {
54  // We need to capture ctrl-c so we can close any remaining sockets before exit
55  signal(SIGINT, exit_capture);
56 
57  // Process command line arguments
58  CommandLineProcessor cmdLine;
59  if (!cmdLine.ProcessCommandLine(argc, argv))
60  {
61  return EXIT_FAILURE;
62  }
63 
64  std::vector<std::thread> threads;
65  std::string commandFile = cmdLine.GetCommandFile();
66 
67  // make the socket non-blocking so we can exit the loop
68  arm::pipe::ConnectionHandler connectionHandler(cmdLine.GetUdsNamespace(), true);
69 
70  while (run)
71  {
72  auto basePipeServer = connectionHandler.GetNewBasePipeServer(cmdLine.IsEchoEnabled());
73 
74  if (basePipeServer != nullptr)
75  {
76  threads.emplace_back(
77  std::thread(CreateMockService, std::move(basePipeServer), commandFile, cmdLine.IsEchoEnabled()));
78  }
79 
80  std::this_thread::sleep_for(std::chrono::milliseconds(100u));
81  }
82 
83  std::for_each(threads.begin(), threads.end(), [](std::thread& t){t.join();});
84 }
bool ProcessCommandLine(int argc, char *argv[])
void exit_capture(int signum)
bool CreateMockService(std::unique_ptr< arm::pipe::BasePipeServer > basePipeServer, std::string commandFile, bool isEchoEnabled)
Use Boost program options to process the command line.