]> git.tdb.fi Git - libs/net.git/blob - source/client.h
2554ac432c7cbed367313f170313fc559afd0956
[libs/net.git] / source / client.h
1 /* $Id$
2
3 This file is part of libmsphttp
4 Copyright © 2008  Mikkosoft Productions, Mikko Rasa
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_HTTP_CLIENT_H_
9 #define MSP_HTTP_CLIENT_H_
10
11 #include <string>
12 #include <sigc++/signal.h>
13 #include <msp/io/eventdispatcher.h>
14 #include <msp/net/streamsocket.h>
15
16 namespace Msp {
17 namespace Http {
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, int> signal_socket_error;
27
28 private:
29         Net::StreamSocket *sock;
30         IO::EventDispatcher *event_disp;
31         Request *request;
32         Response *response;
33         std::string in_buf;
34
35         Client(const Client &);
36         Client &operator=(const Client &);
37 public:
38         Client();
39         ~Client();
40
41         void use_event_dispatcher(IO::EventDispatcher *);
42         void start_request(const Request &);
43         const Response *get_url(const std::string &);
44         void tick();
45         void wait_response();
46         void abort();
47         const Request *get_request() const { return request; }
48         const Response *get_response() const { return response; }
49 private:
50         void connect_finished(int);
51         void data_available();
52 };
53
54 } // namespace Http
55 } // namespace Msp
56
57 #endif