1 /* 2 * Copyright 2010 Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _B_URL_SYNCHRONOUS_REQUEST_H_ 6 #define _B_URL_SYNCHRONOUS_REQUEST_H_ 7 8 9 #include <UrlRequest.h> 10 #include <UrlProtocolListener.h> 11 12 13 #ifndef LIBNETAPI_DEPRECATED 14 namespace BPrivate { 15 16 namespace Network { 17 #endif 18 19 class BUrlSynchronousRequest : public BUrlRequest, public BUrlProtocolListener { 20 public: 21 BUrlSynchronousRequest(BUrlRequest& asynchronousRequest); 22 virtual ~BUrlSynchronousRequest() { }; 23 24 // Synchronous wait 25 virtual status_t Perform(); 26 virtual status_t WaitUntilCompletion(); 27 28 // Protocol hooks 29 virtual void ConnectionOpened(BUrlRequest* caller); 30 virtual void HostnameResolved(BUrlRequest* caller, 31 const char* ip); 32 virtual void ResponseStarted(BUrlRequest* caller); 33 #ifdef LIBNETAPI_DEPRECATED 34 virtual void HeadersReceived(BUrlRequest* caller, 35 const BUrlResult& result); 36 virtual void DataReceived(BUrlRequest* caller, 37 const char* data, off_t position, 38 ssize_t size); 39 virtual void DownloadProgress(BUrlRequest* caller, 40 ssize_t bytesReceived, ssize_t bytesTotal); 41 virtual void UploadProgress(BUrlRequest* caller, 42 ssize_t bytesSent, ssize_t bytesTotal); 43 #else 44 virtual void HeadersReceived(BUrlRequest* caller); 45 virtual void BytesWritten(BUrlRequest* caller, 46 size_t bytesWritten); 47 virtual void DownloadProgress(BUrlRequest* caller, 48 off_t bytesReceived, off_t bytesTotal); 49 virtual void UploadProgress(BUrlRequest* caller, 50 off_t bytesSent, off_t bytesTotal); 51 #endif 52 53 virtual void RequestCompleted(BUrlRequest* caller, 54 bool success); 55 56 57 protected: 58 bool fRequestComplete; 59 BUrlRequest& fWrappedRequest; 60 }; 61 62 63 #ifndef LIBNETAPI_DEPRECATED 64 } // namespace Network 65 66 } // namespace BPrivate 67 #endif 68 69 #endif // _B_URL_SYNCHRONOUS_REQUEST_H_ 70