client-cpp  0.10.0
DefaultOperationHttpChannel.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 #ifndef DEFAULTOPERATIONHTTPCHANNEL_HPP_
18 #define DEFAULTOPERATIONHTTPCHANNEL_HPP_
19 
20 #include "kaa/KaaDefaults.hpp"
21 
24 
25 namespace kaa {
26 
28 public:
30  const KeyPair& clientKeys,
31  IKaaClientContext& context)
32  : AbstractHttpChannel(channelManager, clientKeys, context)
33  {
34 
35  }
36 
37  virtual const std::string& getId() const { return CHANNEL_ID; }
38  virtual const std::map<TransportType, ChannelDirection>& getSupportedTransportTypes() const { return SUPPORTED_TYPES; }
39 
40 private:
41  virtual std::shared_ptr<IHttpRequest> createRequest(IPTransportInfoPtr server, const std::vector<std::uint8_t>& body)
42  {
43  return getHttpDataProcessor()->createOperationRequest(server->getURL() + getURLSuffix(), body);
44  }
45 
46  virtual std::string retrieveResponse(const IHttpResponse& response)
47  {
48  if (response.getStatusCode() != HttpStatusCode::OK) {
49  throw HttpTransportException(response.getStatusCode(), (boost::format("Invalid response code %1%") % response.getStatusCode()).str());
50  }
52  }
53 
54  virtual ServerType getServerType() const {
56  }
57 
58  virtual std::string getURLSuffix() {
59  return "/EP/Sync";
60  }
61 
62 private:
63  static const std::string CHANNEL_ID;
64  static const std::map<TransportType, ChannelDirection> SUPPORTED_TYPES;
65 };
66 
67 }
68 
69 #endif /* DEFAULTOPERATIONHTTPCHANNEL_HPP_ */
HttpDataProcessor * getHttpDataProcessor()
ServerType
Definition: ServerType.hpp:22
virtual const std::string & getId() const
DefaultOperationHttpChannel(IKaaChannelManager &channelManager, const KeyPair &clientKeys, IKaaClientContext &context)
std::shared_ptr< IHttpRequest > createOperationRequest(const HttpUrl &url, const std::vector< std::uint8_t > &data)
virtual const std::map< TransportType, ChannelDirection > & getSupportedTransportTypes() const
std::string retrieveOperationResponse(const IHttpResponse &response)
std::shared_ptr< IPTransportInfo > IPTransportInfoPtr