client-cpp  0.6.3
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 #ifdef KAA_DEFAULT_LONG_POLL_CHANNEL
23 
24 #include <cstdint>
25 #include <thread>
26 
27 #include <boost/asio.hpp>
28 
29 #include "kaa/KaaThread.hpp"
31 #include "kaa/http/HttpClient.hpp"
39 
40 namespace kaa {
41 
42 class DefaultOperationLongPollChannel : public IDataChannel {
43 public:
44  DefaultOperationLongPollChannel(IKaaChannelManager *channelManager, const KeyPair& clientKeys);
45  virtual ~DefaultOperationLongPollChannel();
46 
47  virtual void sync(TransportType type);
48  virtual void syncAll();
49  virtual void syncAck(TransportType type);
50  virtual const std::string& getId() const { return CHANNEL_ID; }
51 
52  virtual TransportProtocolId getTransportProtocolId() const {
54  }
55 
56  virtual ServerType getServerType() const {
58  }
59 
60  virtual void setMultiplexer(IKaaDataMultiplexer *multiplexer);
61  virtual void setDemultiplexer(IKaaDataDemultiplexer *demultiplexer);
62  virtual void setServer(ITransportConnectionInfoPtr server);
63 
64  virtual const std::map<TransportType, ChannelDirection>& getSupportedTransportTypes() const {
65  return SUPPORTED_TYPES;
66  }
67 
68  virtual void shutdown();
69  virtual void pause();
70  virtual void resume();
71 
72  virtual void setConnectivityChecker(ConnectivityCheckerPtr checker) {}
73 
74 protected:
75  std::string getURLSuffix() {
76  return "/EP/LongSync";
77  }
78 
79 private:
80  void startPoll();
81  void stopPoll();
82  void postTask();
83  void executeTask();
84  void doShutdown();
85 
86 private:
87  static const std::string CHANNEL_ID;
88  static const std::map<TransportType, ChannelDirection> SUPPORTED_TYPES;
89 
90  KeyPair clientKeys_;
91 
92  boost::asio::io_service io_;
93  boost::asio::io_service::work work_;
94  std::thread pollThread_;
95  bool stopped_;
96  bool isShutdown_;
97  bool isPaused_;
98  bool connectionInProgress_;
99  bool taskPosted_;
100  bool firstStart_;
101  IKaaDataMultiplexer *multiplexer_;
102  IKaaDataDemultiplexer *demultiplexer_;
103  IKaaChannelManager *channelManager_;
104  std::shared_ptr<IPTransportInfo> currentServer_;
105  HttpDataProcessor httpDataProcessor_;
106  HttpClient httpClient_;
107  KAA_CONDITION_VARIABLE_DECLARE(waitCondition_);
108  KAA_MUTEX_DECLARE(conditionMutex_);
109  KAA_MUTEX_DECLARE(channelGuard_);
110 };
111 
112 }
113 
114 #endif
115 
116 #endif /* DEFAULTOPERATIONLONGPOLLCHANNEL_HPP_ */
std::shared_ptr< IConnectivityChecker > ConnectivityCheckerPtr
static const TransportProtocolId HTTP_TRANSPORT_ID
ServerType
Definition: ServerType.hpp:22
#define KAA_MUTEX_DECLARE(name)
Definition: KaaThread.hpp:71
#define KAA_CONDITION_VARIABLE_DECLARE(name)
Definition: KaaThread.hpp:70
std::shared_ptr< ITransportConnectionInfo > ITransportConnectionInfoPtr