client-cpp  0.0.1-SNAPSHOT
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 
22 #include "kaa/http/HttpClient.hpp"
23 #include <boost/cstdint.hpp>
24 #include <boost/asio.hpp>
25 #include <boost/thread.hpp>
29 
30 namespace kaa {
31 
33 public:
34  DefaultOperationLongPollChannel(IKaaChannelManager *channelManager, const KeyPair& clientKeys);
36 
37  virtual void sync(TransportType type);
38  virtual void syncAll();
39  virtual void syncAck(TransportType type);
40  virtual const std::string& getId() const { return CHANNEL_ID; }
41  virtual ChannelType getChannelType() const { return ChannelType::HTTP_LP; }
42  virtual ServerType getServerType() const { return ServerType::OPERATIONS; }
43 
44  virtual void setMultiplexer(IKaaDataMultiplexer *multiplexer);
45  virtual void setDemultiplexer(IKaaDataDemultiplexer *demultiplexer);
46  virtual void setServer(IServerInfoPtr server);
47 
48  virtual const std::map<TransportType, ChannelDirection>& getSupportedTransportTypes() const { return SUPPORTED_TYPES; }
49 
51 
52  void executeTask();
53 
54 private:
55  void startPoll();
56  void stopPoll();
57  void postTask();
58 
59 private:
60  static const std::string CHANNEL_ID;
61  static const std::map<TransportType, ChannelDirection> SUPPORTED_TYPES;
62 
63  KeyPair clientKeys_;
64 
65  boost::asio::io_service io_;
66  boost::asio::io_service::work work_;
67  boost::thread pollThread_;
68  bool stopped_;
69  bool connectionInProgress_;
70  bool taskPosted_;
71  bool firstStart_;
72  IKaaDataMultiplexer *multiplexer_;
73  IKaaDataDemultiplexer *demultiplexer_;
74  IKaaChannelManager *channelManager_;
75  OperationServerLongPollInfoPtr currentServer_;
76  HttpDataProcessor httpDataProcessor_;
77  HttpClient httpClient_;
78  boost::condition_variable waitCondition_;
79  boost::mutex channelGuard_;
80 };
81 
82 }
83 
84 
85 
86 #endif /* DEFAULTOPERATIONLONGPOLLCHANNEL_HPP_ */
std::pair< Botan::MemoryVector< boost::uint8_t >, std::string > KeyPair
Definition: KeyUtils.hpp:28
virtual const std::map< TransportType, ChannelDirection > & getSupportedTransportTypes() const
virtual void setDemultiplexer(IKaaDataDemultiplexer *demultiplexer)
virtual const std::string & getId() const
ServerType
Definition: ServerType.hpp:22
virtual void setConnectivityChecker(ConnectivityCheckerPtr checker)
virtual void setServer(IServerInfoPtr server)
boost::shared_ptr< HttpLPServerInfo > OperationServerLongPollInfoPtr
boost::shared_ptr< IServerInfo > IServerInfoPtr
Definition: IServerInfo.hpp:55
virtual void sync(TransportType type)
virtual void setMultiplexer(IKaaDataMultiplexer *multiplexer)
DefaultOperationLongPollChannel(IKaaChannelManager *channelManager, const KeyPair &clientKeys)
virtual void syncAck(TransportType type)
boost::shared_ptr< IConnectivityChecker > ConnectivityCheckerPtr