client-cpp  0.7.4
AbstractHttpChannel.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 
18 
19 #ifndef ABSTRACTHTTPCHANNEL_HPP_
20 #define ABSTRACTHTTPCHANNEL_HPP_
21 
22 #include "kaa/KaaDefaults.hpp"
23 
25 
26 #include <cstdint>
27 
28 #include "kaa/KaaThread.hpp"
29 #include "kaa/logging/Log.hpp"
30 #include "kaa/http/HttpClient.hpp"
44 
45 namespace kaa {
46 
48 public:
49  AbstractHttpChannel(IKaaChannelManager *channelManager, const KeyPair& clientKeys, IKaaClientStateStoragePtr clientState);
50  virtual ~AbstractHttpChannel() { }
51 
52  virtual void sync(TransportType type);
53  virtual void syncAll();
54  virtual void syncAck(TransportType type);
55  virtual void setMultiplexer(IKaaDataMultiplexer *multiplexer);
56  virtual void setDemultiplexer(IKaaDataDemultiplexer *demultiplexer);
57 
58  virtual void setServer(ITransportConnectionInfoPtr server);
59 
61  return std::dynamic_pointer_cast<ITransportConnectionInfo, IPTransportInfo>(currentServer_);
62  }
63 
66  }
67 
68  virtual void setFailoverStrategy(IFailoverStrategyPtr strategy) {}
70 
71 protected:
72  typedef std::shared_ptr<IPTransportInfo> IPTransportInfoPtr;
73 
74  HttpDataProcessor* getHttpDataProcessor() { return &httpDataProcessor_; }
75  virtual void processTypes(const std::map<TransportType, ChannelDirection>& types
76 #ifdef KAA_THREADSAFE
77  , KAA_MUTEX_UNIQUE& lock
78 #endif
79  );
80 
81  virtual std::string getURLSuffix() = 0;
82 
83 private:
84  virtual std::shared_ptr<IHttpRequest> createRequest(IPTransportInfoPtr server, const std::vector<std::uint8_t>& body) = 0;
85  virtual std::string retrieveResponse(const IHttpResponse& response) = 0;
86 
87  void onServerFailed();
88 
89 private:
90  KeyPair clientKeys_;
91 
92  bool lastConnectionFailed_;
93 
94  IKaaDataMultiplexer *multiplexer_;
95  IKaaDataDemultiplexer *demultiplexer_;
96  IKaaChannelManager *channelManager_;
97  IPTransportInfoPtr currentServer_;
98  HttpDataProcessor httpDataProcessor_;
99  HttpClient httpClient_;
100  KAA_MUTEX_DECLARE(channelGuard_);
101 
102  IKaaClientStateStoragePtr clientState_;
103 };
104 
105 }
106 
107 #endif /* ABSTRACTHTTPCHANNEL_HPP_ */
108 
virtual void setServer(ITransportConnectionInfoPtr server)
HttpDataProcessor * getHttpDataProcessor()
std::shared_ptr< IConnectivityChecker > ConnectivityCheckerPtr
std::shared_ptr< IFailoverStrategy > IFailoverStrategyPtr
#define KAA_MUTEX_UNIQUE
Definition: KaaThread.hpp:31
virtual std::string getURLSuffix()=0
virtual void setConnectivityChecker(ConnectivityCheckerPtr checker)
static const TransportProtocolId HTTP_TRANSPORT_ID
AbstractHttpChannel(IKaaChannelManager *channelManager, const KeyPair &clientKeys, IKaaClientStateStoragePtr clientState)
virtual void setDemultiplexer(IKaaDataDemultiplexer *demultiplexer)
virtual void syncAck(TransportType type)
std::shared_ptr< IKaaClientStateStorage > IKaaClientStateStoragePtr
virtual void sync(TransportType type)
virtual void setFailoverStrategy(IFailoverStrategyPtr strategy)
virtual ITransportConnectionInfoPtr getServer()
virtual void setMultiplexer(IKaaDataMultiplexer *multiplexer)
virtual void syncAll()
virtual TransportProtocolId getTransportProtocolId() const
std::shared_ptr< IPTransportInfo > IPTransportInfoPtr
virtual void processTypes(const std::map< TransportType, ChannelDirection > &types)
std::shared_ptr< ITransportConnectionInfo > ITransportConnectionInfoPtr