client-cpp  0.6.3
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 
24 #if defined(KAA_DEFAULT_BOOTSTRAP_HTTP_CHANNEL) || defined (KAA_DEFAULT_OPERATION_HTTP_CHANNEL)
25 
27 
28 #include <cstdint>
29 
30 #include "kaa/KaaThread.hpp"
31 #include "kaa/logging/Log.hpp"
32 #include "kaa/http/HttpClient.hpp"
45 
46 namespace kaa {
47 
48 class AbstractHttpChannel : public ImpermanentDataChannel {
49 public:
50  AbstractHttpChannel(IKaaChannelManager *channelManager, const KeyPair& clientKeys);
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  virtual void setServer(ITransportConnectionInfoPtr server);
59 
60  virtual TransportProtocolId getTransportProtocolId() const {
62  }
63 
64  virtual void setConnectivityChecker(ConnectivityCheckerPtr checker) {}
65 
66 protected:
67  typedef std::shared_ptr<IPTransportInfo> IPTransportInfoPtr;
68 
69  HttpDataProcessor* getHttpDataProcessor() { return &httpDataProcessor_; }
70  virtual void processTypes(const std::map<TransportType, ChannelDirection>& types
71 #ifdef KAA_THREADSAFE
72  , KAA_MUTEX_UNIQUE& lock
73 #endif
74  );
75 
76  virtual std::string getURLSuffix() = 0;
77 
78 private:
79  virtual std::shared_ptr<IHttpRequest> createRequest(IPTransportInfoPtr server, const std::vector<std::uint8_t>& body) = 0;
80  virtual std::string retrieveResponse(const IHttpResponse& response) = 0;
81 
82 private:
83  KeyPair clientKeys_;
84 
85  bool lastConnectionFailed_;
86 
87  IKaaDataMultiplexer *multiplexer_;
88  IKaaDataDemultiplexer *demultiplexer_;
89  IKaaChannelManager *channelManager_;
90  IPTransportInfoPtr currentServer_;
91  HttpDataProcessor httpDataProcessor_;
92  HttpClient httpClient_;
93  KAA_MUTEX_DECLARE(channelGuard_);
94 };
95 
96 }
97 
98 #endif
99 
100 #endif /* ABSTRACTHTTPCHANNEL_HPP_ */
101 
std::shared_ptr< IConnectivityChecker > ConnectivityCheckerPtr
#define KAA_MUTEX_UNIQUE
Definition: KaaThread.hpp:58
static const TransportProtocolId HTTP_TRANSPORT_ID
#define KAA_MUTEX_DECLARE(name)
Definition: KaaThread.hpp:71
std::shared_ptr< ITransportConnectionInfo > ITransportConnectionInfoPtr