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).
This commit is contained in:
parent
ed6d3d88c1
commit
ed31589c37
|
@ -27,7 +27,8 @@ enum {
|
||||||
B_URL_PROTOCOL_DOWNLOAD_PROGRESS,
|
B_URL_PROTOCOL_DOWNLOAD_PROGRESS,
|
||||||
B_URL_PROTOCOL_UPLOAD_PROGRESS,
|
B_URL_PROTOCOL_UPLOAD_PROGRESS,
|
||||||
B_URL_PROTOCOL_REQUEST_COMPLETED,
|
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);
|
ssize_t bytesSent, ssize_t bytesTotal);
|
||||||
virtual void RequestCompleted(BUrlRequest* caller,
|
virtual void RequestCompleted(BUrlRequest* caller,
|
||||||
bool success);
|
bool success);
|
||||||
|
virtual void DebugMessage(BUrlRequest* caller,
|
||||||
|
BUrlProtocolDebugMessage type,
|
||||||
|
const char* text);
|
||||||
virtual bool CertificateVerificationFailed(
|
virtual bool CertificateVerificationFailed(
|
||||||
BUrlRequest* caller,
|
BUrlRequest* caller,
|
||||||
BCertificate& certificate,
|
BCertificate& certificate,
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <AppKit.h>
|
#include <AppKit.h>
|
||||||
#include <UrlProtocolAsynchronousListener.h>
|
#include <UrlProtocolAsynchronousListener.h>
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
extern const char* kUrlProtocolMessageType;
|
extern const char* kUrlProtocolMessageType;
|
||||||
extern const char* kUrlProtocolCaller;
|
extern const char* kUrlProtocolCaller;
|
||||||
|
@ -142,6 +143,16 @@ BUrlProtocolAsynchronousListener::MessageReceived(BMessage* message)
|
||||||
}
|
}
|
||||||
break;
|
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:
|
case B_URL_PROTOCOL_CERTIFICATE_VERIFICATION_FAILED:
|
||||||
{
|
{
|
||||||
const char* error = message->FindString("url:error");
|
const char* error = message->FindString("url:error");
|
||||||
|
|
|
@ -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
|
bool
|
||||||
BUrlProtocolDispatchingListener::CertificateVerificationFailed(
|
BUrlProtocolDispatchingListener::CertificateVerificationFailed(
|
||||||
BUrlRequest* caller, BCertificate& certificate, const char* error)
|
BUrlRequest* caller, BCertificate& certificate, const char* error)
|
||||||
|
@ -149,7 +161,7 @@ BUrlProtocolDispatchingListener::_SendMessage(BMessage* message,
|
||||||
int8 notification, BUrlRequest* caller)
|
int8 notification, BUrlRequest* caller)
|
||||||
{
|
{
|
||||||
ASSERT(message != NULL);
|
ASSERT(message != NULL);
|
||||||
|
|
||||||
message->AddPointer(kUrlProtocolCaller, caller);
|
message->AddPointer(kUrlProtocolCaller, caller);
|
||||||
message->AddInt8(kUrlProtocolMessageType, notification);
|
message->AddInt8(kUrlProtocolMessageType, notification);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue