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 namespace BPrivate { 18 19 namespace Network { 20 21 22 class BUrlRequest { 23 public: 24 25 BUrlRequest(const BUrl& url, 26 BDataIO* output, 27 BUrlProtocolListener* listener, 28 BUrlContext* context, 29 const char* threadName, 30 const char* protocolName); 31 virtual ~BUrlRequest(); 32 33 // URL protocol thread management 34 virtual thread_id Run(); 35 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 status_t SetOutput(BDataIO* output); 44 45 // URL protocol parameters access 46 const BUrl& Url() const; 47 BUrlContext* Context() const; 48 BUrlProtocolListener* Listener() const; 49 const BString& Protocol() const; 50 BDataIO* Output() const; 51 52 // URL protocol informations 53 bool IsRunning() const; 54 status_t Status() const; 55 virtual const BUrlResult& Result() const = 0; 56 57 58 protected: 59 static int32 _ThreadEntry(void* arg); 60 virtual void _ProtocolSetup() {}; 61 virtual status_t _ProtocolLoop() = 0; 62 virtual void _EmitDebug(BUrlProtocolDebugMessage type, 63 const char* format, ...); 64 protected: 65 BUrl fUrl; 66 BReference<BUrlContext> fContext; 67 BUrlProtocolListener* fListener; 68 BDataIO* fOutput; 69 70 bool fQuit; 71 bool fRunning; 72 status_t fThreadStatus; 73 thread_id fThreadId; 74 BString fThreadName; 75 BString fProtocol; 76 }; 77 78 79 } // namespace Network 80 81 } // namespace BPrivate 82 83 #endif // _B_URL_REQUEST_H_ 84