client-cpp  0.7.0
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 
71 
73  return std::dynamic_pointer_cast<ITransportConnectionInfo, IPTransportInfo>(currentServer_);
74  }
75 
76 protected:
77  std::string getURLSuffix() {
78  return "/EP/LongSync";
79  }
80 
81 private:
82  void startPoll();
83  void stopPoll();
84  void postTask();
85  void executeTask();
86  void doShutdown();
87 
88 private:
89  static const std::string CHANNEL_ID;
90  static const std::map<TransportType, ChannelDirection> SUPPORTED_TYPES;
91 
92  KeyPair clientKeys_;
93 
94  boost::asio::io_service io_;
95  boost::asio::io_service::work work_;
96  std::thread pollThread_;
97  bool stopped_;
98  bool isShutdown_;
99  bool isPaused_;
100  bool connectionInProgress_;
101  bool taskPosted_;
102  bool firstStart_;
103  IKaaDataMultiplexer *multiplexer_;
104  IKaaDataDemultiplexer *demultiplexer_;
105  IKaaChannelManager *channelManager_;
106  std::shared_ptr<IPTransportInfo> currentServer_;
107  HttpDataProcessor httpDataProcessor_;
108  HttpClient httpClient_;
109  KAA_CONDITION_VARIABLE_DECLARE(waitCondition_);
110  KAA_MUTEX_DECLARE(conditionMutex_);
111  KAA_MUTEX_DECLARE(channelGuard_);
112 };
113 
114 }
115 
116 #endif /* DEFAULTOPERATIONLONGPOLLCHANNEL_HPP_ */
std::shared_ptr< IConnectivityChecker > ConnectivityCheckerPtr
virtual const std::map< TransportType, ChannelDirection > & getSupportedTransportTypes() const
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 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