client-cpp  0.7.0
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"
43 
44 namespace kaa {
45 
47 public:
48  AbstractHttpChannel(IKaaChannelManager *channelManager, const KeyPair& clientKeys);
49  virtual ~AbstractHttpChannel() { }
50 
51  virtual void sync(TransportType type);
52  virtual void syncAll();
53  virtual void syncAck(TransportType type);
54  virtual void setMultiplexer(IKaaDataMultiplexer *multiplexer);
55  virtual void setDemultiplexer(IKaaDataDemultiplexer *demultiplexer);
56 
57  virtual void setServer(ITransportConnectionInfoPtr server);
58 
60  return std::dynamic_pointer_cast<ITransportConnectionInfo, IPTransportInfo>(currentServer_);
61  }
62 
65  }
66 
68 
69 protected:
70  typedef std::shared_ptr<IPTransportInfo> IPTransportInfoPtr;
71 
72  HttpDataProcessor* getHttpDataProcessor() { return &httpDataProcessor_; }
73  virtual void processTypes(const std::map<TransportType, ChannelDirection>& types
74 #ifdef KAA_THREADSAFE
75  , KAA_MUTEX_UNIQUE& lock
76 #endif
77  );
78 
79  virtual std::string getURLSuffix() = 0;
80 
81 private:
82  virtual std::shared_ptr<IHttpRequest> createRequest(IPTransportInfoPtr server, const std::vector<std::uint8_t>& body) = 0;
83  virtual std::string retrieveResponse(const IHttpResponse& response) = 0;
84 
85 private:
86  KeyPair clientKeys_;
87 
88  bool lastConnectionFailed_;
89 
90  IKaaDataMultiplexer *multiplexer_;
91  IKaaDataDemultiplexer *demultiplexer_;
92  IKaaChannelManager *channelManager_;
93  IPTransportInfoPtr currentServer_;
94  HttpDataProcessor httpDataProcessor_;
95  HttpClient httpClient_;
96  KAA_MUTEX_DECLARE(channelGuard_);
97 };
98 
99 }
100 
101 #endif /* ABSTRACTHTTPCHANNEL_HPP_ */
102 
virtual void setServer(ITransportConnectionInfoPtr server)
HttpDataProcessor * getHttpDataProcessor()
std::shared_ptr< IConnectivityChecker > ConnectivityCheckerPtr
#define KAA_MUTEX_UNIQUE
Definition: KaaThread.hpp:61
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 ITransportConnectionInfoPtr getServer()
AbstractHttpChannel(IKaaChannelManager *channelManager, const KeyPair &clientKeys)
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