KISSCPP
a C++ library for rapid application development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
client.hpp
Go to the documentation of this file.
1 // File : client.hpp
2 // Author: Dirk J. Botha <bothadj@gmail.com>
3 //
4 // This file is part of kisscpp library.
5 //
6 // The kisscpp library is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // The kisscpp library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with the kisscpp library. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef _CLIENT_HPP_
20 #define _CLIENT_HPP_
21 
22 #include <iostream>
23 
24 #include <boost/asio.hpp>
25 #include <boost/asio/basic_streambuf.hpp>
26 #include <boost/date_time/posix_time/posix_time.hpp>
27 #include "boost_ptree.hpp"
28 #include "logstream.hpp"
29 #include "request_status.hpp"
30 #include "configuration.hpp"
31 
32 using boost::asio::ip::tcp;
33 
34 namespace kisscpp
35 {
36  class client
37  {
38  public:
39  client(BoostPtree &_request, BoostPtree &_response, int timeout = 10);
40 
41  ~client() { socket_.close(); };
42 
43  private:
44  void handle_connect (const boost::system::error_code& error);
45  void handle_write (const boost::system::error_code& error);
46  void handle_read (const boost::system::error_code& error);
47  void handle_timeout (const boost::system::error_code& error);
48 
49  private:
50  boost::asio::io_service io_service_;
51  tcp::socket socket_;
52  tcp::resolver::iterator endpoint_iterator_;
53  char *ackMessage_;
54  BoostPtree request_;
55  BoostPtree response_;
56  boost::asio::deadline_timer timeout_timer_;
57  boost::asio::streambuf incomming_stream_buffer_;
58  };
59 }
60 
61 typedef boost::shared_ptr<kisscpp::client> SharedClient;
62 
63 #endif //_CLIENT_CLIENT_HPP_
64 
boost::shared_ptr< kisscpp::client > SharedClient
Definition: client.hpp:61
boost::property_tree::ptree BoostPtree
Definition: boost_ptree.hpp:31
Definition: client.hpp:36
LogStream & error(LogStream &s, const bool permanent=false)
Definition: logstream.hpp:339
client(BoostPtree &_request, BoostPtree &_response, int timeout=10)
Definition: client.cpp:24
~client()
Definition: client.hpp:41