/*! * \file TcpConnection.h * \author S. Eisenhauer * \date 27.10.2011 * \brief Header of CTcpConnection */ #ifndef CTCPCONNECTION_H_ #define CTCPCONNECTION_H_ #include #include #include #include #include #include #include "protocol.h" /// maximum number of network connections #define nMAX_CONNECTIONS (16) /// size of buffer for logged message to upload over network #define nUPLOAD_BUFFERSIZE (16) /// forward declaration of main application type class CPluginExecutor; /// type definition for buffer of logged messages to upload typedef boost::circular_buffer tUploadBuffer; /// network communication class CTcpConnection : public boost::intrusive::set_base_hook<> { public: /// type definition for object pointer typedef CTcpConnection* tConnectionPtr; static tConnectionPtr pxCreate(boost::asio::io_service& xIoService, CPluginExecutor* pxExecutor); void vUploadLogMessage(const tstLogMessage& stLogMsg); boost::asio::ip::tcp::socket& xGetSocket(); void vWaitForClientRequest(); /*! * \brief set the activation state of tcp connection object * \param[in] boActive activation state */ void vSetActive(bool boActive) { m_boActive = boActive; } /*! * \brief get the activation state of a tcp sonnection * \return TRUE if connection is active, FALSE if not. */ bool boIsActive() { return m_boActive; } /// operator less for connection objects, needed for ordering in the container friend bool operator<(const CTcpConnection& a, const CTcpConnection& b) { return &a < &b; } /// destructor ~CTcpConnection(void); private: tNetworkBuffer m_xRxBuff; //!< request buffer tNetworkBuffer m_xTxBuff; //!< response buffer CNetworkInStream m_xInStream; //!< instream for receive buffer CNetworkOutStream m_xOutStream; //!< outstream for transmit buffer CNetworkDatacontainer m_xNetworkDatacontainer; //!< datacontainer for data from and to network boost::asio::ip::tcp::socket m_xSocket; //!< socket of this connection CPluginExecutor* m_pxExecutor; //!< pointer to main application uint8_t m_u8ConNum; //!< number of this connection bool m_boActive; //!< activation state of this object tUploadBuffer m_xUploadBuffer; //!< buffer for logged messages, that should be uploaded over this conenction x2e::Mutex m_xUploadBufferMutex; //!< mutex to protect upload buffer from concurrent access int32_t m_i32UploadBufferUnread; //!< number of elements in upload buffer bool m_boUploadActive; //!< is an upload of logged messages active yet /// constructor CTcpConnection(boost::asio::io_service& io_service, CPluginExecutor* pxExecutor, uint8_t u8ConNum); void vWriteHandler(const boost::system::error_code& err, size_t bytesTransferred); void vReadHandler(const boost::system::error_code& err, size_t bytesTransferred); void vUploadNextMessage(); }; /// type definition for connection container typedef boost::intrusive::set tConnectionSet; /// type definition for connection container iterator typedef boost::intrusive::set::iterator tConIter; /// global connection container extern tConnectionSet g_astActiveConnections; #endif /*CTCPCONNECTION_H_*/