This class parses a command file for the GatordMockService.
The file contains one command per line. Valid commands are: SET and WAIT.
SET: Will construct and send a PeriodicCounterSelection packet to enable a set of counters. WAIT: Will pause for a set period of time to allow for data to be received.
Definition at line 22 of file CommandFileParser.hpp.
Definition at line 19 of file CommandFileParser.cpp.
References GatordMockService::ReceiveThreadRunning(), GatordMockService::SendActivateTimelinePacket(), GatordMockService::SendDeactivateTimelinePacket(), GatordMockService::SendPeriodicCounterSelectionList(), GatordMockService::SendRequestCounterDir(), and GatordMockService::WaitCommand().
Referenced by CreateMockService().
21 std::ifstream infile(CommandFile);
24 std::cout <<
"Parsing command file: " << CommandFile << std::endl;
26 while (mockService.ReceiveThreadRunning() && std::getline(infile, line))
28 std::istringstream iss(line);
29 std::vector<std::string> tokens;
31 std::copy(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>(),
32 std::back_inserter(tokens));
33 if (tokens.size() > 0)
35 std::string command = tokens[0];
36 if (command ==
"DISABLE")
43 mockService.SendDeactivateTimelinePacket();
45 else if (command ==
"ENABLE")
52 mockService.SendActivateTimelinePacket();
54 else if (command ==
"LIST")
62 mockService.SendRequestCounterDir();
76 if (tokens.size() > 2)
78 uint32_t period =
static_cast<uint32_t
>(std::stoul(tokens[1]));
80 std::vector<uint16_t> counters;
82 std::transform(tokens.begin() + 2, tokens.end(), std::back_inserter(counters),
83 [](
const std::string& str)
84 {
return static_cast<uint16_t
>(std::stoul(str)); });
86 mockService.SendPeriodicCounterSelectionList(period, counters);
90 std::cerr <<
"Invalid SET command. Format is: SET <polling period> <id list>" << std::endl;
93 else if (command ==
"WAIT")
103 if (tokens.size() > 1)
105 uint32_t timeout =
static_cast<uint32_t
>(std::stoul(tokens[1]));
106 mockService.WaitCommand(timeout);
110 std::cerr <<
"Invalid WAIT command. Format is: WAIT <interval>" << std::endl;