From ed31589c375022059cda2a96beb6b06f893748da Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Mon, 31 Oct 2016 22:14:39 +0100 Subject: [PATCH] URL Disaptching/Async listeners: forward debug messages This makes it possible for the Asynchronous listener to get the messages. It can then process them in a more fancy way. The default implementation will still log the messages to the console (if debug is enabled), but it will do so from the Async listener for asynchronous requests now. This means they will probably be logged from the same thread, and show up in a more readable way. This also makes it possible to listen to several requests and log them in a nice way (in a status window or whatever). --- headers/os/net/UrlProtocolDispatchingListener.h | 6 +++++- .../libnetapi/UrlProtocolAsynchronousListener.cpp | 11 +++++++++++ .../libnetapi/UrlProtocolDispatchingListener.cpp | 14 +++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/headers/os/net/UrlProtocolDispatchingListener.h b/headers/os/net/UrlProtocolDispatchingListener.h index 9d276b81b6..29fa46f2c9 100644 --- a/headers/os/net/UrlProtocolDispatchingListener.h +++ b/headers/os/net/UrlProtocolDispatchingListener.h @@ -27,7 +27,8 @@ enum { B_URL_PROTOCOL_DOWNLOAD_PROGRESS, B_URL_PROTOCOL_UPLOAD_PROGRESS, B_URL_PROTOCOL_REQUEST_COMPLETED, - B_URL_PROTOCOL_CERTIFICATE_VERIFICATION_FAILED + B_URL_PROTOCOL_CERTIFICATE_VERIFICATION_FAILED, + B_URL_PROTOCOL_DEBUG_MESSAGE }; @@ -53,6 +54,9 @@ public: ssize_t bytesSent, ssize_t bytesTotal); virtual void RequestCompleted(BUrlRequest* caller, bool success); + virtual void DebugMessage(BUrlRequest* caller, + BUrlProtocolDebugMessage type, + const char* text); virtual bool CertificateVerificationFailed( BUrlRequest* caller, BCertificate& certificate, diff --git a/src/kits/network/libnetapi/UrlProtocolAsynchronousListener.cpp b/src/kits/network/libnetapi/UrlProtocolAsynchronousListener.cpp index b90e9f6def..dc53a42351 100644 --- a/src/kits/network/libnetapi/UrlProtocolAsynchronousListener.cpp +++ b/src/kits/network/libnetapi/UrlProtocolAsynchronousListener.cpp @@ -12,6 +12,7 @@ #include #include #include +#include extern const char* kUrlProtocolMessageType; extern const char* kUrlProtocolCaller; @@ -142,6 +143,16 @@ BUrlProtocolAsynchronousListener::MessageReceived(BMessage* message) } break; + case B_URL_PROTOCOL_DEBUG_MESSAGE: + { + BUrlProtocolDebugMessage type + = (BUrlProtocolDebugMessage)message->FindInt32("url:type"); + BString text = message->FindString("url:text"); + + DebugMessage(caller, type, text); + } + break; + case B_URL_PROTOCOL_CERTIFICATE_VERIFICATION_FAILED: { const char* error = message->FindString("url:error"); diff --git a/src/kits/network/libnetapi/UrlProtocolDispatchingListener.cpp b/src/kits/network/libnetapi/UrlProtocolDispatchingListener.cpp index d3222cb875..ee4f184d2e 100644 --- a/src/kits/network/libnetapi/UrlProtocolDispatchingListener.cpp +++ b/src/kits/network/libnetapi/UrlProtocolDispatchingListener.cpp @@ -125,6 +125,18 @@ BUrlProtocolDispatchingListener::RequestCompleted(BUrlRequest* caller, } +void +BUrlProtocolDispatchingListener::DebugMessage(BUrlRequest* caller, + BUrlProtocolDebugMessage type, const char* text) +{ + BMessage message(B_URL_PROTOCOL_NOTIFICATION); + message.AddInt32("url:type", type); + message.AddString("url:text", text); + + _SendMessage(&message, B_URL_PROTOCOL_DEBUG_MESSAGE, caller); +} + + bool BUrlProtocolDispatchingListener::CertificateVerificationFailed( BUrlRequest* caller, BCertificate& certificate, const char* error) @@ -149,7 +161,7 @@ BUrlProtocolDispatchingListener::_SendMessage(BMessage* message, int8 notification, BUrlRequest* caller) { ASSERT(message != NULL); - + message->AddPointer(kUrlProtocolCaller, caller); message->AddInt8(kUrlProtocolMessageType, notification);