client-cpp  0.10.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:
51  const KeyPair& clientKeys,
52  IKaaClientContext& context);
53 
54  virtual void sync(TransportType type);
55  virtual void syncAll();
56  virtual void syncAck(TransportType type);
57  virtual void setMultiplexer(IKaaDataMultiplexer *multiplexer);
58  virtual void setDemultiplexer(IKaaDataDemultiplexer *demultiplexer);
59 
60  virtual void setServer(ITransportConnectionInfoPtr server);
61 
63  return std::dynamic_pointer_cast<ITransportConnectionInfo, IPTransportInfo>(currentServer_);
64  }
65 
68  }
69 
70  virtual void setFailoverStrategy(IFailoverStrategyPtr strategy) {}
72  connectivityChecker_ = checker;
73  }
74 
75 protected:
76  typedef std::shared_ptr<IPTransportInfo> IPTransportInfoPtr;
77 
78  HttpDataProcessor* getHttpDataProcessor() { return &httpDataProcessor_; }
79 
80  virtual void processTypes(const std::map<TransportType, ChannelDirection>& types
81 #ifdef KAA_THREADSAFE
82  , KAA_MUTEX_UNIQUE& lock
83 #endif
84  );
85 
86  virtual std::string getURLSuffix() = 0;
87 
88 private:
89  virtual std::shared_ptr<IHttpRequest> createRequest(IPTransportInfoPtr server, const std::vector<std::uint8_t>& body) = 0;
90  virtual std::string retrieveResponse(const IHttpResponse& response) = 0;
91 
92  void onServerFailed(KaaFailoverReason reason);
93 
94 private:
95  IKaaChannelManager& channelManager_;
96  IKaaClientContext& context_;
97  KeyPair clientKeys_;
98  IPTransportInfoPtr currentServer_;
99  HttpDataProcessor httpDataProcessor_;
100  HttpClient httpClient_;
101 
102  KAA_MUTEX_DECLARE(channelGuard_);
103 
104  IKaaDataMultiplexer *multiplexer_ = nullptr;
105  IKaaDataDemultiplexer *demultiplexer_ = nullptr;
106  ConnectivityCheckerPtr connectivityChecker_;
107 };
108 
109 }
110 
111 #endif /* ABSTRACTHTTPCHANNEL_HPP_ */
112 
AbstractHttpChannel(IKaaChannelManager &channelManager, const KeyPair &clientKeys, IKaaClientContext &context)
virtual void setServer(ITransportConnectionInfoPtr server)
HttpDataProcessor * getHttpDataProcessor()
KaaFailoverReason
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)
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