/*! \file pipackedtcp.h * \ingroup IO-Utils * \~\brief * \~english Ethernet device * \~russian Устройство Ethernet */ /* PIP - Platform Independent Primitives Ethernet, UDP/TCP Broadcast/Multicast Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #ifndef pipackedtcp_H #define pipackedtcp_H #include "piiodevice.h" #include "pinetworkaddress.h" #include "pip_io_utils_export.h" #include "pistreampacker.h" class PIEthernet; class PIP_IO_UTILS_EXPORT PIPackedTCP: public PIIODevice { PIIODEVICE(PIPackedTCP, "ptcp"); public: //! \brief Role of %PIPackedTCP enum Role { Client /** TCP client */, Server /** TCP server for one client */ }; //! Contructs %PIPackedTCP with "role" and "addr" address explicit PIPackedTCP(Role role = Client, const PINetworkAddress & addr = {}); virtual ~PIPackedTCP(); //! Set server address for Server role or connect address for Client void setAddress(const PINetworkAddress & addr); bool isConnected() const; bool isConnecting() const; //! Returns read address in format "i.i.i.i:p" PINetworkAddress address() const { return m_addr; } //! Returns %PIEthernet type Role role() const { return m_role; } EVENT0(connected); EVENT0(disconnected); protected: void init(); DeviceInfoFlags deviceInfoFlags() const override; PIString constructFullPathDevice() const override; void configureFromFullPathDevice(const PIString & full_path) override; ssize_t readDevice(void * read_to, ssize_t max_size) override; ssize_t writeDevice(const void * data, ssize_t max_size) override; bool openDevice() override; bool closeDevice() override; mutable PINetworkAddress m_addr; Role m_role = Client; PIEthernet *eth = nullptr, *client = nullptr; PIStreamPacker packer; PIMutex rec_mutex; PIQueue rec_queue; private: }; REGISTER_DEVICE(PIPackedTCP) #endif