Now we use the MessageDeliverer to send asynchronous messages to other apps. Seems to work when the target port is not full. The other case has not been tested yet.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11133 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <Autolock.h>
|
||||
#include <Message.h>
|
||||
#include <MessagePrivate.h>
|
||||
#include <Messenger.h>
|
||||
#include <OS.h>
|
||||
#include <RegistrarDefs.h>
|
||||
@@ -36,6 +37,7 @@
|
||||
#include "Debug.h"
|
||||
#include "Event.h"
|
||||
#include "EventQueue.h"
|
||||
#include "MessageDeliverer.h"
|
||||
#include "MessageRunnerManager.h"
|
||||
|
||||
/*! \class MessageRunnerManager
|
||||
@@ -163,7 +165,23 @@ struct MessageRunnerManager::RunnerInfo {
|
||||
{
|
||||
if (count > 0)
|
||||
count--;
|
||||
status_t error = target.SendMessage(message, replyTarget, 0);
|
||||
|
||||
// set the reply target
|
||||
BMessage::Private(message).SetReply(replyTarget);
|
||||
|
||||
// deliver the message: We use the MessageDeliverer to allow the
|
||||
// message to be delivered, even if the target port is temporarily
|
||||
// full. For periodic message runners, that have to deliver further
|
||||
// messages, we restrict the delivery timeout to the message interval.
|
||||
status_t error;
|
||||
if (count > 0) {
|
||||
error = MessageDeliverer::Default()->DeliverMessage(message, target,
|
||||
interval);
|
||||
} else {
|
||||
error = MessageDeliverer::Default()->DeliverMessage(message,
|
||||
target);
|
||||
}
|
||||
|
||||
// B_WOULD_BLOCK is as good as B_OK. We return an error only, if
|
||||
// there are serious problems with the target, i.e. if it doesn't
|
||||
// exist anymore for instance. A full message port is harmless.
|
||||
|
||||
@@ -29,8 +29,10 @@
|
||||
|
||||
#include <Application.h>
|
||||
#include <AppMisc.h>
|
||||
#include <AutoDeleter.h>
|
||||
#include <File.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <MessagePrivate.h>
|
||||
#include <MessengerPrivate.h>
|
||||
#include <Path.h>
|
||||
#include <storage_support.h>
|
||||
@@ -39,11 +41,12 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Debug.h"
|
||||
#include "EventMaskWatcher.h"
|
||||
#include "MessageDeliverer.h"
|
||||
#include "RegistrarDefs.h"
|
||||
#include "RosterAppInfo.h"
|
||||
#include "RosterSettingsCharStream.h"
|
||||
#include "TRoster.h"
|
||||
#include "EventMaskWatcher.h"
|
||||
|
||||
using namespace BPrivate;
|
||||
|
||||
@@ -717,6 +720,16 @@ TRoster::HandleBroadcast(BMessage *request)
|
||||
&& request->FindMessenger("reply_target", &replyTarget) != B_OK) {
|
||||
error = B_BAD_VALUE;
|
||||
}
|
||||
|
||||
// allocate an error for the message targets
|
||||
BMessenger *targets = NULL;
|
||||
if (error == B_OK) {
|
||||
targets = new(nothrow) BMessenger[fRegisteredApps.CountInfos()];
|
||||
if (!targets)
|
||||
error = B_NO_MEMORY;
|
||||
}
|
||||
ArrayDeleter<BMessenger> targetsDeleter(targets);
|
||||
|
||||
// reply to the request -- do this first, don't let the inquirer wait
|
||||
if (error == B_OK) {
|
||||
BMessage reply(B_REG_SUCCESS);
|
||||
@@ -726,20 +739,31 @@ TRoster::HandleBroadcast(BMessage *request)
|
||||
reply.AddInt32("error", error);
|
||||
request->SendReply(&reply);
|
||||
}
|
||||
|
||||
// broadcast the message
|
||||
team_id registrarTeam = BPrivate::current_team();
|
||||
if (error == B_OK) {
|
||||
// get the list of targets
|
||||
int32 targetCount = 0;
|
||||
for (AppInfoList::Iterator it = fRegisteredApps.It();
|
||||
it.IsValid();
|
||||
++it) {
|
||||
// don't send the message to the requesting team or the registrar
|
||||
if ((*it)->team != team && (*it)->team != registrarTeam) {
|
||||
BMessenger messenger;
|
||||
BMessenger::Private messengerPrivate(messenger);
|
||||
BMessenger::Private messengerPrivate(targets[targetCount]);
|
||||
messengerPrivate.SetTo((*it)->team, (*it)->port, 0, true);
|
||||
messenger.SendMessage(&message, replyTarget, 0);
|
||||
targetCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (targetCount > 0) {
|
||||
// set the reply target
|
||||
BMessage::Private(message).SetReply(replyTarget);
|
||||
|
||||
// send the messages
|
||||
MessageDeliverer::Default()->DeliverMessage(&message, targets,
|
||||
targetCount);
|
||||
}
|
||||
}
|
||||
|
||||
FUNCTION_END();
|
||||
@@ -1208,7 +1232,9 @@ TRoster::_AppActivated(RosterAppInfo *info)
|
||||
messengerPrivate.SetTo(info->team, info->port, 0, true);
|
||||
BMessage message(B_APP_ACTIVATED);
|
||||
message.AddBool("active", true);
|
||||
messenger.SendMessage(&message);
|
||||
// not sure, if it makes sense to use the MessageDeliverer here
|
||||
MessageDeliverer::Default()->DeliverMessage(&message, messenger);
|
||||
|
||||
// notify the watchers
|
||||
BMessage watcherMessage(B_SOME_APP_ACTIVATED);
|
||||
_AddMessageWatchingInfo(&watcherMessage, info);
|
||||
@@ -1234,7 +1260,8 @@ TRoster::_AppDeactivated(RosterAppInfo *info)
|
||||
messengerPrivate.SetTo(info->team, info->port, 0, true);
|
||||
BMessage message(B_APP_ACTIVATED);
|
||||
message.AddBool("active", false);
|
||||
messenger.SendMessage(&message);
|
||||
// not sure, if it makes sense to use the MessageDeliverer here
|
||||
MessageDeliverer::Default()->DeliverMessage(&message, messenger);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <Message.h>
|
||||
|
||||
#include "MessageDeliverer.h"
|
||||
#include "Watcher.h"
|
||||
|
||||
// Watcher
|
||||
@@ -88,7 +89,7 @@ Watcher::Target() const
|
||||
status_t
|
||||
Watcher::SendMessage(BMessage *message)
|
||||
{
|
||||
return fTarget.SendMessage(message, (BHandler*)NULL, 0);
|
||||
return MessageDeliverer::Default()->DeliverMessage(message, fTarget);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user