client-cpp  0.9.0
DefaultOperationLongPollChannel.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2016 CyberVision, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef DEFAULTOPERATIONLONGPOLLCHANNEL_HPP_
18 #define DEFAULTOPERATIONLONGPOLLCHANNEL_HPP_
19 
20 #include "kaa/KaaDefaults.hpp"
21 
22 #include <cstdint>
23 #include <thread>
24 
25 #include <boost/asio.hpp>
26 
27 #include "kaa/KaaThread.hpp"
29 #include "kaa/http/HttpClient.hpp"
38 
39 namespace kaa {
40 
42 public:
43  DefaultOperationLongPollChannel(IKaaChannelManager *channelManager, const KeyPair& clientKeys, IKaaClientContext &context);
45 
46  virtual void sync(TransportType type);
47  virtual void syncAll();
48  virtual void syncAck(TransportType type);
49  virtual const std::string& getId() const { return CHANNEL_ID; }
50 
53  }
54 
55  virtual ServerType getServerType() const {
57  }
58 
59  virtual void setMultiplexer(IKaaDataMultiplexer *multiplexer);
60  virtual void setDemultiplexer(IKaaDataDemultiplexer *demultiplexer);
61  virtual void setServer(ITransportConnectionInfoPtr server);
62 
63  virtual const std::map<TransportType, ChannelDirection>& getSupportedTransportTypes() const {
64  return SUPPORTED_TYPES;
65  }
66 
67  virtual void shutdown();
68  virtual void pause();
69  virtual void resume();
70 
71  virtual void setFailoverStrategy(IFailoverStrategyPtr strategy) {}
73 
75  return std::dynamic_pointer_cast<ITransportConnectionInfo, IPTransportInfo>(currentServer_);
76  }
77 
78 protected:
79  std::string getURLSuffix() {
80  return "/EP/LongSync";
81  }
82 
83 private:
84  void startPoll();
85  void stopPoll();
86  void postTask();
87  void executeTask();
88  void doShutdown();
89 
90 private:
91  static const std::string CHANNEL_ID;
92  static const std::map<TransportType, ChannelDirection> SUPPORTED_TYPES;
93 
94  KeyPair clientKeys_;
95 
96  boost::asio::io_service io_;
97  boost::asio::io_service::work work_;
98  std::thread pollThread_;
99  bool stopped_;
100  bool isShutdown_;
101  bool isPaused_;
102  bool connectionInProgress_;
103  bool taskPosted_;
104  bool firstStart_;
105  IKaaDataMultiplexer *multiplexer_;
106  IKaaDataDemultiplexer *demultiplexer_;
107  IKaaChannelManager *channelManager_;
108  std::shared_ptr<IPTransportInfo> currentServer_;
109  HttpDataProcessor httpDataProcessor_;
110  HttpClient httpClient_;
111  KAA_CONDITION_VARIABLE_DECLARE(waitCondition_);
112  KAA_MUTEX_DECLARE(conditionMutex_);
113  KAA_MUTEX_DECLARE(channelGuard_);
114 
115 protected:
117 };
118 
119 }
120 
121 #endif /* DEFAULTOPERATIONLONGPOLLCHANNEL_HPP_ */
std::shared_ptr< IConnectivityChecker > ConnectivityCheckerPtr
virtual const std::map< TransportType, ChannelDirection > & getSupportedTransportTypes() const
std::shared_ptr< IFailoverStrategy > IFailoverStrategyPtr
DefaultOperationLongPollChannel(IKaaChannelManager *channelManager, const KeyPair &clientKeys, IKaaClientContext &context)
virtual void setDemultiplexer(IKaaDataDemultiplexer *demultiplexer)
static const TransportProtocolId HTTP_TRANSPORT_ID
virtual const std::string & getId() const
virtual TransportProtocolId getTransportProtocolId() const
ServerType
Definition: ServerType.hpp:22
virtual void setConnectivityChecker(ConnectivityCheckerPtr checker)
virtual void setFailoverStrategy(IFailoverStrategyPtr strategy)
virtual ITransportConnectionInfoPtr getServer()
virtual void setServer(ITransportConnectionInfoPtr server)
virtual void sync(TransportType type)
virtual void setMultiplexer(IKaaDataMultiplexer *multiplexer)
virtual void syncAck(TransportType type)
std::shared_ptr< ITransportConnectionInfo > ITransportConnectionInfoPtr