xref: /haiku/headers/private/netservices/UrlRequest.h (revision 4a32f48e70297d9a634646f01e08c2f451ecd6bd)
1 /*
2  * Copyright 2010-2014 Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _B_URL_REQUEST_H_
6 #define _B_URL_REQUEST_H_
7 
8 
9 #include <Url.h>
10 #include <UrlContext.h>
11 #include <UrlProtocolListener.h>
12 #include <UrlResult.h>
13 #include <OS.h>
14 #include <Referenceable.h>
15 
16 
17 #ifndef LIBNETAPI_DEPRECATED
18 namespace BPrivate {
19 
20 namespace Network {
21 #endif
22 
23 class BUrlRequest {
24 public:
25 #ifdef LIBNETAPI_DEPRECATED
26 									BUrlRequest(const BUrl& url,
27 										BUrlProtocolListener* listener,
28 										BUrlContext* context,
29 										const char* threadName,
30 										const char* protocolName);
31 #else
32 									BUrlRequest(const BUrl& url,
33 										BDataIO* output,
34 										BUrlProtocolListener* listener,
35 										BUrlContext* context,
36 										const char* threadName,
37 										const char* protocolName);
38 #endif
39 	virtual							~BUrlRequest();
40 
41 	// URL protocol thread management
42 	virtual	thread_id				Run();
43 	virtual	status_t				Stop();
44 	virtual void					SetTimeout(bigtime_t timeout) {}
45 
46 	// URL protocol parameters modification
47 			status_t				SetUrl(const BUrl& url);
48 			status_t				SetContext(BUrlContext* context);
49 			status_t				SetListener(BUrlProtocolListener* listener);
50 #ifndef LIBNETAPI_DEPRECATED
51 			status_t				SetOutput(BDataIO* output);
52 #endif
53 
54 	// URL protocol parameters access
55 			const BUrl&				Url() const;
56 			BUrlContext*			Context() const;
57 			BUrlProtocolListener*	Listener() const;
58 			const BString&			Protocol() const;
59 #ifndef LIBNETAPI_DEPRECATED
60 			BDataIO*				Output() const;
61 #endif
62 
63 	// URL protocol informations
64 			bool					IsRunning() const;
65 			status_t				Status() const;
66 	virtual const BUrlResult&		Result() const = 0;
67 
68 
69 protected:
70 	static	int32					_ThreadEntry(void* arg);
71 	virtual	void					_ProtocolSetup() {};
72 	virtual	status_t				_ProtocolLoop() = 0;
73 	virtual void					_EmitDebug(BUrlProtocolDebugMessage type,
74 										const char* format, ...);
75 protected:
76 			BUrl					fUrl;
77 			BReference<BUrlContext>	fContext;
78 			BUrlProtocolListener*	fListener;
79 #ifndef LIBNETAPI_DEPRECATED
80 			BDataIO*				fOutput;
81 #endif
82 
83 			bool					fQuit;
84 			bool					fRunning;
85 			status_t				fThreadStatus;
86 			thread_id				fThreadId;
87 			BString					fThreadName;
88 			BString					fProtocol;
89 };
90 
91 #ifndef LIBNETAPI_DEPRECATED
92 } // namespace Network
93 
94 } // namespace BPrivate
95 #endif
96 
97 #endif // _B_URL_REQUEST_H_
98