client-cpp  0.6.3
HttpClient.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 #ifndef HTTPCLIENT_HPP_
18 #define HTTPCLIENT_HPP_
19 
20 #include "kaa/KaaDefaults.hpp"
21 
22 #if defined(KAA_DEFAULT_BOOTSTRAP_HTTP_CHANNEL) || \
23  defined(KAA_DEFAULT_OPERATION_HTTP_CHANNEL) || \
24  defined(KAA_DEFAULT_LONG_POLL_CHANNEL)
25 
26 #include "kaa/http/IHttpClient.hpp"
27 #include <boost/asio.hpp>
28 
29 #include "kaa/KaaThread.hpp"
30 
31 namespace kaa {
32 
33 class HttpClient : public IHttpClient
34 {
35 public:
36  HttpClient() : io_(), sock_(io_) { }
37  ~HttpClient() { }
38 
39  virtual std::shared_ptr<IHttpResponse> sendRequest(const IHttpRequest& request);
40  virtual void closeConnection();
41 
42 private:
43  void checkError(const boost::system::error_code& code);
44  void doSocketClose();
45 
46 private:
47  boost::asio::io_service io_;
48  boost::asio::ip::tcp::socket sock_;
49 
50  KAA_MUTEX_DECLARE(guard_);
51 };
52 
53 }
54 
55 #endif
56 
57 #endif /* HTTPCLIENT_HPP_ */
#define KAA_MUTEX_DECLARE(name)
Definition: KaaThread.hpp:71