17 #ifndef DEFAULTOPERATIONTCPCHANNEL_HPP_
18 #define DEFAULTOPERATIONTCPCHANNEL_HPP_
27 #include <boost/asio.hpp>
60 virtual const std::string&
getId()
const {
return CHANNEL_ID; }
79 return SUPPORTED_TYPES;
87 failoverStrategy_ = strategy;
91 connectivityChecker_= checker;
94 void onReadEvent(
const boost::system::error_code& err);
108 boost::system::error_code sendKaaSync(
const std::map<TransportType, ChannelDirection>& transportTypes);
109 boost::system::error_code sendConnect();
110 boost::system::error_code sendDisconnect();
111 boost::system::error_code sendPingRequest();
112 boost::system::error_code sendData(
const IKaaTcpRequest& request);
114 void readFromSocket();
116 void setConnAckTimer();
124 static const std::string CHANNEL_ID;
126 static const std::map<TransportType, ChannelDirection> SUPPORTED_TYPES;
128 static const std::uint16_t THREADPOOL_SIZE = 2;
129 static const std::uint32_t KAA_PLATFORM_PROTOCOL_AVRO_ID = 0xf291f2d4;
131 static const std::uint16_t CHANNEL_TIMEOUT = 200;
132 static const std::uint16_t PING_TIMEOUT = CHANNEL_TIMEOUT / 2;
133 static const std::uint16_t CONN_ACK_TIMEOUT = 20;
140 std::list<TransportType> ackTypes_;
142 boost::asio::io_service io_;
143 boost::asio::io_service::work work_;
144 std::unique_ptr<boost::asio::ip::tcp::socket> sock_;
145 boost::asio::deadline_timer pingTimer_;
146 boost::asio::deadline_timer connAckTimer_;
147 std::vector<std::thread> ioThreads_;
148 std::unique_ptr<boost::asio::streambuf> responseBuffer_;
152 bool isConnected_ =
false;
153 bool isFirstResponseReceived_ =
false;
154 bool isPendingSyncRequest_ =
false;
155 bool isShutdown_ =
false;
156 bool isPaused_ =
false;
157 bool isFailoverInProgress_ =
false;
165 std::shared_ptr<RsaEncoderDecoder> encDec_;
167 KAA_MUTEX_DECLARE(channelGuard_);
169 std::shared_ptr<IPTransportInfo> currentServer_;
void onConnack(const ConnackMessage &message)
std::shared_ptr< IConnectivityChecker > ConnectivityCheckerPtr
std::shared_ptr< IFailoverStrategy > IFailoverStrategyPtr
virtual void setMultiplexer(IKaaDataMultiplexer *multiplexer)
virtual void setServer(ITransportConnectionInfoPtr server)
virtual void syncAck(TransportType type)
static const TransportProtocolId TCP_TRANSPORT_ID
virtual void setConnectivityChecker(ConnectivityCheckerPtr checker)
virtual ServerType getServerType() const
virtual ITransportConnectionInfoPtr getServer()
virtual const std::string & getId() const
virtual void setDemultiplexer(IKaaDataDemultiplexer *demultiplexer)
virtual void setFailoverStrategy(IFailoverStrategyPtr strategy)
void onReadEvent(const boost::system::error_code &err)
virtual const std::map< TransportType, ChannelDirection > & getSupportedTransportTypes() const
void onPingTimeout(const boost::system::error_code &err)
virtual TransportProtocolId getTransportProtocolId() const
void onServerFailed(KaaFailoverReason failoverReason=KaaFailoverReason::CURRENT_OPERATIONS_SERVER_NA)
virtual void sync(TransportType type)
void onDisconnect(const DisconnectMessage &message)
void onConnAckTimeout(const boost::system::error_code &err)
void onKaaSync(const KaaSyncResponse &message)
~DefaultOperationTcpChannel()
DefaultOperationTcpChannel(IKaaChannelManager &channelManager, const KeyPair &clientKeys, IKaaClientContext &context)
std::shared_ptr< ITransportConnectionInfo > ITransportConnectionInfoPtr