BLooper: implement scripting
Change-Id: I73dd301ca7109675a4b629464ba7275a8095c77b Reviewed-on: https://review.haiku-os.org/c/haiku/+/2940 Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
+51
-2
@@ -18,6 +18,7 @@
|
|||||||
#include <new>
|
#include <new>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
@@ -284,8 +285,56 @@ BLooper::DispatchMessage(BMessage* message, BHandler* handler)
|
|||||||
void
|
void
|
||||||
BLooper::MessageReceived(BMessage* message)
|
BLooper::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
// TODO: implement scripting support
|
if (!message->HasSpecifiers()) {
|
||||||
BHandler::MessageReceived(message);
|
BHandler::MessageReceived(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BMessage replyMsg(B_REPLY);
|
||||||
|
status_t err = B_BAD_SCRIPT_SYNTAX;
|
||||||
|
int32 index;
|
||||||
|
BMessage specifier;
|
||||||
|
int32 what;
|
||||||
|
const char* property;
|
||||||
|
|
||||||
|
if (message->GetCurrentSpecifier(&index, &specifier, &what, &property)
|
||||||
|
!= B_OK) {
|
||||||
|
return BHandler::MessageReceived(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
BPropertyInfo propertyInfo(sLooperPropInfo);
|
||||||
|
switch (propertyInfo.FindMatch(message, index, &specifier, what,
|
||||||
|
property)) {
|
||||||
|
case 1: // Handlers: GET
|
||||||
|
if (message->what == B_GET_PROPERTY) {
|
||||||
|
int32 count = CountHandlers();
|
||||||
|
err = B_OK;
|
||||||
|
for (int32 i = 0; err == B_OK && i < count; i++) {
|
||||||
|
BMessenger messenger(HandlerAt(i));
|
||||||
|
err = replyMsg.AddMessenger("result", messenger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2: // Handler: COUNT
|
||||||
|
if (message->what == B_COUNT_PROPERTIES)
|
||||||
|
err = replyMsg.AddInt32("result", CountHandlers());
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return BHandler::MessageReceived(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err != B_OK) {
|
||||||
|
replyMsg.what = B_MESSAGE_NOT_UNDERSTOOD;
|
||||||
|
|
||||||
|
if (err == B_BAD_SCRIPT_SYNTAX)
|
||||||
|
replyMsg.AddString("message", "Didn't understand the specifier(s)");
|
||||||
|
else
|
||||||
|
replyMsg.AddString("message", strerror(err));
|
||||||
|
}
|
||||||
|
|
||||||
|
replyMsg.AddInt32("error", err);
|
||||||
|
message->SendReply(&replyMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user