UrlRequest.h revision 89b4e98a
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
32	// URL protocol parameters modification
33			status_t				SetUrl(const BUrl& url);
34			status_t				SetContext(BUrlContext* context);
35			status_t				SetListener(BUrlProtocolListener* listener);
36
37	// URL protocol parameters access
38			const BUrl&				Url() const;
39			BUrlContext*			Context() const;
40			BUrlProtocolListener*	Listener() const;
41			const BString&			Protocol() const;
42
43	// URL protocol informations
44			bool					IsRunning() const;
45			status_t				Status() const;
46	virtual const BUrlResult&		Result() const = 0;
47
48
49protected:
50	static	int32					_ThreadEntry(void* arg);
51	virtual	void					_ProtocolSetup() {};
52	virtual	status_t				_ProtocolLoop() = 0;
53	virtual void					_EmitDebug(BUrlProtocolDebugMessage type,
54										const char* format, ...);
55protected:
56			BUrl					fUrl;
57			BReference<BUrlContext>	fContext;
58			BUrlProtocolListener*	fListener;
59
60			bool					fQuit;
61			bool					fRunning;
62			status_t				fThreadStatus;
63			thread_id				fThreadId;
64			BString					fThreadName;
65			BString					fProtocol;
66};
67
68
69#endif // _B_URL_REQUEST_H_
70