11 #include <NetworkSockets.hpp> 32 std::cout <<
"Sending connection acknowledgement." << std::endl;
35 m_BasePipeServer.get()->SendPacket(0, 1,
nullptr, 0);
42 std::cout <<
"Sending connection acknowledgement." << std::endl;
45 m_BasePipeServer.get()->SendPacket(0, 3,
nullptr, 0);
52 std::cout <<
"Sending activate timeline packet." << std::endl;
55 m_BasePipeServer.get()->SendPacket(0, 6,
nullptr, 0);
62 std::cout <<
"Sending deactivate timeline packet." << std::endl;
65 m_BasePipeServer.get()->SendPacket(0, 7,
nullptr, 0);
72 std::cout <<
"Launching receiving thread." << std::endl;
75 if (!m_BasePipeServer.get()->SetNonBlocking())
77 m_BasePipeServer.get()->Close();
78 std::cerr <<
"Failed to set socket as non blocking: " << strerror(errno) << std::endl;
81 m_ListeningThread = std::thread(&GatordMockService::ReceiveLoop,
this);
88 if (m_CloseReceivingThread !=
true)
90 m_CloseReceivingThread.store(
true);
93 if (m_ListeningThread.joinable())
96 m_ListeningThread.join();
101 m_TimelineDecoder.
print();
107 return m_BasePipeServer->WaitForStreamMetaData();
118 std::cout <<
"SendPeriodicCounterSelectionList: Period=" << std::dec << period <<
"uSec" << std::endl;
119 std::cout <<
"List length=" << counters.size() << std::endl;
122 uint32_t dataLength =
static_cast<uint32_t
>(4 + (counters.size() * 2));
124 std::unique_ptr<unsigned char[]> uniqueData = std::make_unique<unsigned char[]>(dataLength);
125 unsigned char* data =
reinterpret_cast<unsigned char*
>(uniqueData.get());
130 for (std::vector<uint16_t>::iterator it = counters.begin(); it != counters.end(); ++it)
137 m_BasePipeServer.get()->SendPacket(0, 4, data, dataLength);
146 uint32_t iterations = timeout / 1000;
147 std::cout << std::dec <<
"Wait command with timeout of " << timeout <<
" iterations = " << iterations << std::endl;
151 std::this_thread::sleep_for(std::chrono::microseconds(1000));
156 std::cout << std::dec <<
"Wait command with timeout of " << timeout <<
" microseconds completed. " << std::endl;
160 void GatordMockService::ReceiveLoop()
162 m_CloseReceivingThread.store(
false);
163 while (!m_CloseReceivingThread.load())
167 profiling::Packet packet = m_BasePipeServer.get()->WaitForPacket(500);
175 packet.GetPacketFamily(),
176 packet.GetPacketId(),
182 commandHandlerFunctor->operator()(packet);
191 std::cerr <<
"Packet received that could not be processed: " << e.
what() << std::endl;
196 std::cerr <<
"Receive thread closing: " << e.
what() << std::endl;
197 m_CloseReceivingThread.store(
true);
uint32_t GetEncodedValue()
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)
Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const
virtual const char * what() const noexcept override
CommandHandlerFunctor * GetFunctor(uint32_t familyId, uint32_t packetId, uint32_t version) const
Copyright (c) 2020 ARM Limited.
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()
#define ARMNN_ASSERT(COND)
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.