2 // Copyright © 2019 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include "CommandFileParser.hpp"
19 void CommandFileParser::ParseFile(std::string CommandFile, GatordMockService& mockService)
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);
30 std::vector<std::string> tokens;
32 std::copy(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>(),
33 std::back_inserter(tokens));
35 std::string command = tokens[0];
37 if (command == "LIST")
39 // Expected format for the SET command
44 mockService.SendRequestCounterDir();
48 // Expected format for the SET command
50 // SET 500000 1 2 5 10
52 // This breaks down to:
54 // 500000 polling period in micro seconds
55 // 1 2 5 10 counter list
57 uint period = static_cast<uint>(std::stoul(tokens[1]));
59 std::vector<uint16_t> counters;
61 std::transform(tokens.begin() + 2, tokens.end(), std::back_inserter(counters),
62 [](const std::string& str) { return static_cast<uint16_t>(std::stoul(str)); });
64 mockService.SendPeriodicCounterSelectionList(period, counters);
66 else if (command == "WAIT")
68 // Expected format for the SET command
72 // This breaks down to:
74 // 11000000 timeout period in micro seconds
76 uint timeout = static_cast<uint>(std::stoul(tokens[1]));
78 mockService.WaitCommand(timeout);
83 } // namespace gatordmock