xref: /haiku/headers/private/netservices/UrlRequest.h (revision 9e4c5cf124438891e20947b72d13412d78018800)
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 									BUrlRequest(const BUrl& url,
26 										BUrlProtocolListener* listener,
27 										BUrlContext* context,
28 										const char* threadName,
29 										const char* protocolName);
30 	virtual							~BUrlRequest();
31 
32 	// URL protocol thread management
33 	virtual	thread_id				Run();
34 	virtual status_t				Pause();
35 	virtual status_t				Resume();
36 	virtual	status_t				Stop();
37 	virtual void					SetTimeout(bigtime_t timeout) {}
38 
39 	// URL protocol parameters modification
40 			status_t				SetUrl(const BUrl& url);
41 			status_t				SetContext(BUrlContext* context);
42 			status_t				SetListener(BUrlProtocolListener* listener);
43 
44 	// URL protocol parameters access
45 			const BUrl&				Url() const;
46 			BUrlContext*			Context() const;
47 			BUrlProtocolListener*	Listener() const;
48 			const BString&			Protocol() const;
49 
50 	// URL protocol informations
51 			bool					IsRunning() const;
52 			status_t				Status() const;
53 	virtual const BUrlResult&		Result() const = 0;
54 
55 
56 protected:
57 	static	int32					_ThreadEntry(void* arg);
58 	virtual	void					_ProtocolSetup() {};
59 	virtual	status_t				_ProtocolLoop() = 0;
60 	virtual void					_EmitDebug(BUrlProtocolDebugMessage type,
61 										const char* format, ...);
62 protected:
63 			BUrl					fUrl;
64 			BReference<BUrlContext>	fContext;
65 			BUrlProtocolListener*	fListener;
66 
67 			bool					fQuit;
68 			bool					fRunning;
69 			status_t				fThreadStatus;
70 			thread_id				fThreadId;
71 			BString					fThreadName;
72 			BString					fProtocol;
73 };
74 
75 #ifndef LIBNETAPI_DEPRECATED
76 } // namespace Network
77 
78 } // namespace BPrivate
79 #endif
80 
81 #endif // _B_URL_REQUEST_H_
82