diff options
author | Jim Flynn <jim.flynn@arm.com> | 2020-07-20 16:57:44 +0100 |
---|---|---|
committer | Jim Flynn <jim.flynn@arm.com> | 2020-07-29 15:35:15 +0100 |
commit | bbfe603e5ae42317a2b67d713d00882bea341c88 (patch) | |
tree | 8d8a78d6836384fb92fb9741c865443624dfec68 /profiling/server/include/basePipeServer/BasePipeServer.hpp | |
parent | a9c2ce123a6a5a68728d040a0323c482bbe46903 (diff) | |
download | armnn-bbfe603e5ae42317a2b67d713d00882bea341c88.tar.gz |
IVGCVSW-5166 Pull out the common and server side code into standalone libraries
Change-Id: I180f84c493a9b2be4b93b25d312ebdd9e71b1735
Signed-off-by: Jim Flynn <jim.flynn@arm.com>
Diffstat (limited to 'profiling/server/include/basePipeServer/BasePipeServer.hpp')
-rw-r--r-- | profiling/server/include/basePipeServer/BasePipeServer.hpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/profiling/server/include/basePipeServer/BasePipeServer.hpp b/profiling/server/include/basePipeServer/BasePipeServer.hpp new file mode 100644 index 0000000000..1b6dec54ff --- /dev/null +++ b/profiling/server/include/basePipeServer/BasePipeServer.hpp @@ -0,0 +1,120 @@ +// +// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include <common/include/NetworkSockets.hpp> +#include <common/include/Packet.hpp> +#include <common/include/SocketConnectionException.hpp> + +#include <string> +#include <atomic> + +namespace arm +{ + +namespace pipe +{ + +enum class TargetEndianness +{ + BeWire, + LeWire +}; + +enum class PacketDirection +{ + Sending, + ReceivedHeader, + ReceivedData +}; +class ConnectionHandler; + +class BasePipeServer +{ + +public: + + BasePipeServer(arm::pipe::Socket clientConnection, bool echoPackets) + : m_ClientConnection(clientConnection) + , m_EchoPackets(echoPackets) + {} + + ~BasePipeServer() + { + // We have set SOCK_CLOEXEC on this socket but we'll close it to be good citizens. + arm::pipe::Close(m_ClientConnection); + } + + BasePipeServer(const BasePipeServer&) = delete; + BasePipeServer& operator=(const BasePipeServer&) = delete; + + BasePipeServer(BasePipeServer&&) = delete; + BasePipeServer& operator=(BasePipeServer&&) = delete; + + /// Close the client connection + /// @return 0 if successful + int Close() + { + return arm::pipe::Close(m_ClientConnection); + } + + /// Send a packet to the client + /// @return true if a valid packet has been sent. + bool SendPacket(uint32_t packetFamily, uint32_t packetId, const uint8_t* data, uint32_t dataLength); + + /// Set the client socket to nonblocking + /// @return true if successful. + bool SetNonBlocking() + { + return arm::pipe::SetNonBlocking(m_ClientConnection); + } + + /// Block on the client connection until a complete packet has been received. + /// @return true if a valid packet has been received. + arm::pipe::Packet WaitForPacket(uint32_t timeoutMs); + + /// Once the connection is open wait to receive the stream meta data packet from the client. Reading this + /// packet differs from others as we need to determine endianness. + /// @return true only if a valid stream meta data packet has been received. + bool WaitForStreamMetaData(); + + uint32_t GetStreamMetadataVersion() + { + return m_StreamMetaDataVersion; + } + + uint32_t GetStreamMetadataMaxDataLen() + { + return m_StreamMetaDataMaxDataLen; + } + + uint32_t GetStreamMetadataPid() + { + return m_StreamMetaDataPid; + } + +private: + + void EchoPacket(PacketDirection direction, uint8_t* packet, size_t lengthInBytes); + bool ReadFromSocket(uint8_t* packetData, uint32_t expectedLength); + bool ReadHeader(uint32_t headerAsWords[2]); + + arm::pipe::Packet ReceivePacket(); + + uint32_t ToUint32(uint8_t* data, TargetEndianness endianness); + void InsertU32(uint32_t value, uint8_t* data, TargetEndianness endianness); + + arm::pipe::Socket m_ClientConnection; + bool m_EchoPackets; + TargetEndianness m_Endianness; + + uint32_t m_StreamMetaDataVersion; + uint32_t m_StreamMetaDataMaxDataLen; + uint32_t m_StreamMetaDataPid; +}; + +} // namespace pipe +} // namespace arm |