client-cpp  0.7.4
DefaultOperationLongPollChannel.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014 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"
37 
38 namespace kaa {
39 
41 public:
42  DefaultOperationLongPollChannel(IKaaChannelManager *channelManager, const KeyPair& clientKeys);
44 
45  virtual void sync(TransportType type);
46  virtual void syncAll();
47  virtual void syncAck(TransportType type);
48  virtual const std::string& getId() const { return CHANNEL_ID; }
49 
52  }
53 
54  virtual ServerType getServerType() const {
56  }
57 
58  virtual void setMultiplexer(IKaaDataMultiplexer *multiplexer);
59  virtual void setDemultiplexer(IKaaDataDemultiplexer *demultiplexer);
60  virtual void setServer(ITransportConnectionInfoPtr server);
61 
62  virtual const std::map<TransportType, ChannelDirection>& getSupportedTransportTypes() const {
63  return SUPPORTED_TYPES;
64  }
65 
66  virtual void shutdown();
67  virtual void pause();
68  virtual void resume();
69 
70  virtual void setFailoverStrategy(IFailoverStrategyPtr strategy) {}
72 
74  return std::dynamic_pointer_cast<ITransportConnectionInfo, IPTransportInfo>(currentServer_);
75  }
76 
77 protected:
78  std::string getURLSuffix() {
79  return "/EP/LongSync";
80  }
81 
82 private:
83  void startPoll();
84  void stopPoll();
85  void postTask();
86  void executeTask();
87  void doShutdown();
88 
89 private:
90  static const std::string CHANNEL_ID;
91  static const std::map<TransportType, ChannelDirection> SUPPORTED_TYPES;
92 
93  KeyPair clientKeys_;
94 
95  boost::asio::io_service io_;
96  boost::asio::io_service::work work_;
97  std::thread pollThread_;
98  bool stopped_;
99  bool isShutdown_;
100  bool isPaused_;
101  bool connectionInProgress_;
102  bool taskPosted_;
103  bool firstStart_;
104  IKaaDataMultiplexer *multiplexer_;
105  IKaaDataDemultiplexer *demultiplexer_;
106  IKaaChannelManager *channelManager_;
107  std::shared_ptr<IPTransportInfo> currentServer_;
108  HttpDataProcessor httpDataProcessor_;
109  HttpClient httpClient_;
110  KAA_CONDITION_VARIABLE_DECLARE(waitCondition_);
111  KAA_MUTEX_DECLARE(conditionMutex_);
112  KAA_MUTEX_DECLARE(channelGuard_);
113 };
114 
115 }
116 
117 #endif /* DEFAULTOPERATIONLONGPOLLCHANNEL_HPP_ */
std::shared_ptr< IConnectivityChecker > ConnectivityCheckerPtr
virtual const std::map< TransportType, ChannelDirection > & getSupportedTransportTypes() const
std::shared_ptr< IFailoverStrategy > IFailoverStrategyPtr
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)
DefaultOperationLongPollChannel(IKaaChannelManager *channelManager, const KeyPair &clientKeys)
virtual void syncAck(TransportType type)
std::shared_ptr< ITransportConnectionInfo > ITransportConnectionInfoPtr