xref: /haiku/headers/private/netservices/UrlRequest.h (revision 2ca1376080f866aafba1edc95eaa036b92ed2078)
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 #ifdef LIBNETAPI_DEPRECATED
44 	virtual status_t				Pause();
45 	virtual status_t				Resume();
46 #endif
47 
48 	virtual	status_t				Stop();
49 	virtual void					SetTimeout(bigtime_t timeout) {}
50 
51 	// URL protocol parameters modification
52 			status_t				SetUrl(const BUrl& url);
53 			status_t				SetContext(BUrlContext* context);
54 			status_t				SetListener(BUrlProtocolListener* listener);
55 #ifndef LIBNETAPI_DEPRECATED
56 			status_t				SetOutput(BDataIO* output);
57 #endif
58 
59 	// URL protocol parameters access
60 			const BUrl&				Url() const;
61 			BUrlContext*			Context() const;
62 			BUrlProtocolListener*	Listener() const;
63 			const BString&			Protocol() const;
64 #ifndef LIBNETAPI_DEPRECATED
65 			BDataIO*				Output() const;
66 #endif
67 
68 	// URL protocol informations
69 			bool					IsRunning() const;
70 			status_t				Status() const;
71 	virtual const BUrlResult&		Result() const = 0;
72 
73 
74 protected:
75 	static	int32					_ThreadEntry(void* arg);
76 	virtual	void					_ProtocolSetup() {};
77 	virtual	status_t				_ProtocolLoop() = 0;
78 	virtual void					_EmitDebug(BUrlProtocolDebugMessage type,
79 										const char* format, ...);
80 protected:
81 			BUrl					fUrl;
82 			BReference<BUrlContext>	fContext;
83 			BUrlProtocolListener*	fListener;
84 #ifndef LIBNETAPI_DEPRECATED
85 			BDataIO*				fOutput;
86 #endif
87 
88 			bool					fQuit;
89 			bool					fRunning;
90 			status_t				fThreadStatus;
91 			thread_id				fThreadId;
92 			BString					fThreadName;
93 			BString					fProtocol;
94 };
95 
96 #ifndef LIBNETAPI_DEPRECATED
97 } // namespace Network
98 
99 } // namespace BPrivate
100 #endif
101 
102 #endif // _B_URL_REQUEST_H_
103