]> git.tdb.fi Git - libs/net.git/blob - source/http/client.h
37acf0cfe0e3bb08d1483520e9a3cd7bc557dc76
[libs/net.git] / source / http / client.h
1 #ifndef MSP_HTTP_CLIENT_H_
2 #define MSP_HTTP_CLIENT_H_
3
4 #include <string>
5 #include <sigc++/signal.h>
6 #include <msp/io/eventdispatcher.h>
7 #include <msp/net/streamsocket.h>
8
9 namespace Msp {
10 namespace Http {
11
12 class client_busy: public std::logic_error
13 {
14 public:
15         client_busy(): std::logic_error(std::string()) { }
16         virtual ~client_busy() throw() { }
17 };
18
19 class Request;
20 class Response;
21
22 class Client
23 {
24 public:
25         sigc::signal<void, const Response &> signal_response_complete;
26         sigc::signal<void, const std::exception &> signal_socket_error;
27
28 private:
29         Net::StreamSocket *sock;
30         IO::EventDispatcher *event_disp;
31         std::string user_agent;
32         Request *request;
33         Response *response;
34         std::string in_buf;
35
36         Client(const Client &);
37         Client &operator=(const Client &);
38 public:
39         Client();
40         ~Client();
41
42         void use_event_dispatcher(IO::EventDispatcher *);
43         void set_user_agent(const std::string &);
44         void start_request(const Request &);
45         const Response *get_url(const std::string &);
46         void tick();
47         void wait_response();
48         void abort();
49         const Request *get_request() const { return request; }
50         const Response *get_response() const { return response; }
51 private:
52         void connect_finished(const std::exception *);
53         void data_available();
54 };
55
56 } // namespace Http
57 } // namespace Msp
58
59 #endif