8 #include <common/include/Assert.hpp> 9 #include <common/include/CommandHandlerRegistry.hpp> 10 #include <common/include/CommonProfilingUtils.hpp> 11 #include <common/include/PacketVersionResolver.hpp> 12 #include <common/include/NetworkSockets.hpp> 28 std::cout <<
"Sending connection acknowledgement." << std::endl;
31 m_BasePipeServer.get()->SendPacket(0, 1,
nullptr, 0);
38 std::cout <<
"Sending connection acknowledgement." << std::endl;
41 m_BasePipeServer.get()->SendPacket(0, 3,
nullptr, 0);
48 std::cout <<
"Sending activate timeline packet." << std::endl;
51 m_BasePipeServer.get()->SendPacket(0, 6,
nullptr, 0);
58 std::cout <<
"Sending deactivate timeline packet." << std::endl;
61 m_BasePipeServer.get()->SendPacket(0, 7,
nullptr, 0);
68 std::cout <<
"Launching receiving thread." << std::endl;
71 if (!m_BasePipeServer.get()->SetNonBlocking())
73 m_BasePipeServer.get()->Close();
74 std::cerr <<
"Failed to set socket as non blocking: " << strerror(errno) << std::endl;
77 m_ListeningThread = std::thread(&GatordMockService::ReceiveLoop,
this);
84 if (m_CloseReceivingThread !=
true)
86 m_CloseReceivingThread.store(
true);
89 if (m_ListeningThread.joinable())
92 m_ListeningThread.join();
97 m_TimelineDecoder.print();
103 return m_BasePipeServer->WaitForStreamMetaData();
114 std::cout <<
"SendPeriodicCounterSelectionList: Period=" << std::dec << period <<
"uSec" << std::endl;
115 std::cout <<
"List length=" << counters.size() << std::endl;
118 uint32_t dataLength =
static_cast<uint32_t
>(4 + (counters.size() * 2));
120 std::unique_ptr<unsigned char[]> uniqueData = std::make_unique<unsigned char[]>(dataLength);
121 unsigned char* data =
reinterpret_cast<unsigned char*
>(uniqueData.get());
124 arm::pipe::WriteUint32(data, offset, period);
126 for (std::vector<uint16_t>::iterator it = counters.begin(); it != counters.end(); ++it)
128 arm::pipe::WriteUint16(data, offset, *it);
133 m_BasePipeServer.get()->SendPacket(0, 4, data, dataLength);
142 uint32_t iterations = timeout / 1000;
143 std::cout << std::dec <<
"Wait command with timeout of " << timeout <<
" iterations = " << iterations << std::endl;
147 std::this_thread::sleep_for(std::chrono::microseconds(1000));
152 std::cout << std::dec <<
"Wait command with timeout of " << timeout <<
" microseconds completed. " << std::endl;
156 void GatordMockService::ReceiveLoop()
158 m_CloseReceivingThread.store(
false);
159 while (!m_CloseReceivingThread.load())
163 arm::pipe::Packet packet = m_BasePipeServer.get()->WaitForPacket(500);
165 arm::pipe::PacketVersionResolver packetVersionResolver;
167 arm::pipe::Version version =
168 packetVersionResolver.ResolvePacketVersion(packet.GetPacketFamily(), packet.GetPacketId());
170 arm::pipe::CommandHandlerFunctor* commandHandlerFunctor = m_HandlerRegistry.GetFunctor(
171 packet.GetPacketFamily(),
172 packet.GetPacketId(),
173 version.GetEncodedValue());
177 ARM_PIPE_ASSERT(commandHandlerFunctor);
178 commandHandlerFunctor->operator()(packet);
180 catch (
const arm::pipe::TimeoutException&)
184 catch (
const arm::pipe::InvalidArgumentException& e)
187 std::cerr <<
"Packet received that could not be processed: " << e.what() << std::endl;
189 catch (
const arm::pipe::ProfilingException& e)
192 std::cerr <<
"Receive thread closing: " << e.what() << std::endl;
193 m_CloseReceivingThread.store(
true);
Copyright (c) 2021 ARM Limited and Contributors.
void SendDeactivateTimelinePacket()
Send a deactivate timeline packet back to the client.
void SendActivateTimelinePacket()
Send a activate timeline packet back to the client.
bool WaitForStreamMetaData()
Once the connection is open wait to receive the stream meta data packet from the client.
void SendRequestCounterDir()
Send a request counter directory packet back to the client.
bool ReceiveThreadRunning()
bool LaunchReceivingThread()
Start the thread that will receive all packets and print them nicely to stdout.
void WaitCommand(uint32_t timeout)
Execute the WAIT command from the comamnd file.
void SendPeriodicCounterSelectionList(uint32_t period, std::vector< uint16_t > counters)
Send the counter list to ArmNN.
void WaitForReceivingThread()
This is a placeholder method to prevent main exiting.
void SendConnectionAck()
Send a connection acknowledged packet back to the client.