client-cpp  0.9.0
AbstractHttpChannel.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2016 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"
45 
46 namespace kaa {
47 
49 public:
50  AbstractHttpChannel(IKaaChannelManager *channelManager, const KeyPair& clientKeys, IKaaClientContext &context);
51  virtual ~AbstractHttpChannel() { }
52 
53  virtual void sync(TransportType type);
54  virtual void syncAll();
55  virtual void syncAck(TransportType type);
56  virtual void setMultiplexer(IKaaDataMultiplexer *multiplexer);
57  virtual void setDemultiplexer(IKaaDataDemultiplexer *demultiplexer);
58 
59  virtual void setServer(ITransportConnectionInfoPtr server);
60 
62  return std::dynamic_pointer_cast<ITransportConnectionInfo, IPTransportInfo>(currentServer_);
63  }
64 
67  }
68 
69  virtual void setFailoverStrategy(IFailoverStrategyPtr strategy) {}
71 
72 protected:
73  typedef std::shared_ptr<IPTransportInfo> IPTransportInfoPtr;
74 
75  HttpDataProcessor* getHttpDataProcessor() { return &httpDataProcessor_; }
76  virtual void processTypes(const std::map<TransportType, ChannelDirection>& types
77 #ifdef KAA_THREADSAFE
78  , KAA_MUTEX_UNIQUE& lock
79 #endif
80  );
81 
82  virtual std::string getURLSuffix() = 0;
83 
84 private:
85  virtual std::shared_ptr<IHttpRequest> createRequest(IPTransportInfoPtr server, const std::vector<std::uint8_t>& body) = 0;
86  virtual std::string retrieveResponse(const IHttpResponse& response) = 0;
87 
88  void onServerFailed(KaaFailoverReason reason);
89 
90 private:
91  KeyPair clientKeys_;
92 
93  bool lastConnectionFailed_;
94 
95  IKaaDataMultiplexer *multiplexer_;
96  IKaaDataDemultiplexer *demultiplexer_;
97  IKaaChannelManager *channelManager_;
98  IPTransportInfoPtr currentServer_;
99  HttpDataProcessor httpDataProcessor_;
100  HttpClient httpClient_;
101  KAA_MUTEX_DECLARE(channelGuard_);
102 
103  IKaaClientContext &context_;
104 };
105 
106 }
107 
108 #endif /* ABSTRACTHTTPCHANNEL_HPP_ */
109 
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
virtual void setDemultiplexer(IKaaDataDemultiplexer *demultiplexer)
virtual void syncAck(TransportType type)
AbstractHttpChannel(IKaaChannelManager *channelManager, const KeyPair &clientKeys, IKaaClientContext &context)
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