UrlRequest.h revision 654ae69a
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
17class BUrlRequest {
18public:
19									BUrlRequest(const BUrl& url,
20										BUrlProtocolListener* listener,
21										BUrlContext* context,
22										const char* threadName,
23										const char* protocolName);
24	virtual							~BUrlRequest();
25
26	// URL protocol thread management
27	virtual	thread_id				Run();
28	virtual status_t				Pause();
29	virtual status_t				Resume();
30	virtual	status_t				Stop();
31	virtual status_t				SetTimeout(bigtime_t timeout) {}
32
33	// URL protocol parameters modification
34			status_t				SetUrl(const BUrl& url);
35			status_t				SetContext(BUrlContext* context);
36			status_t				SetListener(BUrlProtocolListener* listener);
37
38	// URL protocol parameters access
39			const BUrl&				Url() const;
40			BUrlContext*			Context() const;
41			BUrlProtocolListener*	Listener() const;
42			const BString&			Protocol() const;
43
44	// URL protocol informations
45			bool					IsRunning() const;
46			status_t				Status() const;
47	virtual const BUrlResult&		Result() const = 0;
48
49
50protected:
51	static	int32					_ThreadEntry(void* arg);
52	virtual	void					_ProtocolSetup() {};
53	virtual	status_t				_ProtocolLoop() = 0;
54	virtual void					_EmitDebug(BUrlProtocolDebugMessage type,
55										const char* format, ...);
56protected:
57			BUrl					fUrl;
58			BReference<BUrlContext>	fContext;
59			BUrlProtocolListener*	fListener;
60
61			bool					fQuit;
62			bool					fRunning;
63			status_t				fThreadStatus;
64			thread_id				fThreadId;
65			BString					fThreadName;
66			BString					fProtocol;
67};
68
69
70#endif // _B_URL_REQUEST_H_
71