* Added missing MessagingCommandHandler methods.
* Added a class for handling "send message" commands and install by default. At least in theory messages issued by the kernel should now be delivered to the target. Still untested. * Added lock to protect the command handler map. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11144 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -8,9 +8,12 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <Autolock.h>
|
||||||
|
|
||||||
#include <syscalls.h>
|
#include <syscalls.h>
|
||||||
|
|
||||||
#include "Debug.h"
|
#include "Debug.h"
|
||||||
|
#include "MessageDeliverer.h"
|
||||||
#include "MessagingService.h"
|
#include "MessagingService.h"
|
||||||
|
|
||||||
// sService -- the singleton instance
|
// sService -- the singleton instance
|
||||||
@@ -149,6 +152,37 @@ MessagingArea::NextArea() const
|
|||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
MessagingCommandHandler::MessagingCommandHandler()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// destructor
|
||||||
|
MessagingCommandHandler::~MessagingCommandHandler()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
// DefaultSendCommandHandler
|
||||||
|
class MessagingService::DefaultSendCommandHandler
|
||||||
|
: public MessagingCommandHandler {
|
||||||
|
|
||||||
|
virtual void HandleMessagingCommand(uint32 _command, const void *data,
|
||||||
|
int32 dataSize)
|
||||||
|
{
|
||||||
|
const messaging_command_send_message *sendData
|
||||||
|
= (const messaging_command_send_message*)data;
|
||||||
|
const void *messageData = (uint8*)data
|
||||||
|
+ sizeof(messaging_command_send_message)
|
||||||
|
+ sizeof(messaging_target) * sendData->target_count;
|
||||||
|
|
||||||
|
MessageDeliverer::Default()->DeliverMessage(messageData,
|
||||||
|
sendData->message_size, sendData->targets, sendData->target_count);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// CommandHandlerMap
|
// CommandHandlerMap
|
||||||
struct MessagingService::CommandHandlerMap
|
struct MessagingService::CommandHandlerMap
|
||||||
: map<uint32, MessagingCommandHandler*> {
|
: map<uint32, MessagingCommandHandler*> {
|
||||||
@@ -156,7 +190,8 @@ struct MessagingService::CommandHandlerMap
|
|||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
MessagingService::MessagingService()
|
MessagingService::MessagingService()
|
||||||
: fLockSem(-1),
|
: fLock("messaging service"),
|
||||||
|
fLockSem(-1),
|
||||||
fCounterSem(-1),
|
fCounterSem(-1),
|
||||||
fFirstArea(NULL),
|
fFirstArea(NULL),
|
||||||
fCommandHandlers(NULL),
|
fCommandHandlers(NULL),
|
||||||
@@ -225,6 +260,12 @@ MessagingService::Init()
|
|||||||
// resume the command processor
|
// resume the command processor
|
||||||
resume_thread(fCommandProcessor);
|
resume_thread(fCommandProcessor);
|
||||||
|
|
||||||
|
// install the default send message command handler
|
||||||
|
MessagingCommandHandler *handler = new(nothrow) DefaultSendCommandHandler;
|
||||||
|
if (handler)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
SetCommandHandler(MESSAGING_COMMAND_SEND_MESSAGE, handler);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,6 +314,8 @@ void
|
|||||||
MessagingService::SetCommandHandler(uint32 command,
|
MessagingService::SetCommandHandler(uint32 command,
|
||||||
MessagingCommandHandler *handler)
|
MessagingCommandHandler *handler)
|
||||||
{
|
{
|
||||||
|
BAutolock _(fLock);
|
||||||
|
|
||||||
if (handler) {
|
if (handler) {
|
||||||
(*fCommandHandlers)[command] = handler;
|
(*fCommandHandlers)[command] = handler;
|
||||||
} else {
|
} else {
|
||||||
@@ -287,6 +330,8 @@ MessagingService::SetCommandHandler(uint32 command,
|
|||||||
MessagingCommandHandler *
|
MessagingCommandHandler *
|
||||||
MessagingService::_GetCommandHandler(uint32 command) const
|
MessagingService::_GetCommandHandler(uint32 command) const
|
||||||
{
|
{
|
||||||
|
BAutolock _(fLock);
|
||||||
|
|
||||||
CommandHandlerMap::iterator it = fCommandHandlers->find(command);
|
CommandHandlerMap::iterator it = fCommandHandlers->find(command);
|
||||||
return (it != fCommandHandlers->end() ? it->second : NULL);
|
return (it != fCommandHandlers->end() ? it->second : NULL);
|
||||||
}
|
}
|
||||||
@@ -331,6 +376,9 @@ MessagingService::_CommandProcessor()
|
|||||||
if (handler) {
|
if (handler) {
|
||||||
handler->HandleMessagingCommand(command->command, command->data,
|
handler->HandleMessagingCommand(command->command, command->data,
|
||||||
command->size - sizeof(messaging_command));
|
command->size - sizeof(messaging_command));
|
||||||
|
} else {
|
||||||
|
WARNING(("MessagingService::_CommandProcessor(): No handler "
|
||||||
|
"found for command %lu\n", command->command));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#ifndef MESSAGING_SERVICE_H
|
#ifndef MESSAGING_SERVICE_H
|
||||||
#define MESSAGING_SERVICE_H
|
#define MESSAGING_SERVICE_H
|
||||||
|
|
||||||
|
#include <Locker.h>
|
||||||
#include <MessagingServiceDefs.h>
|
#include <MessagingServiceDefs.h>
|
||||||
|
|
||||||
// MessagingCommandHandler
|
// MessagingCommandHandler
|
||||||
@@ -73,10 +74,12 @@ private:
|
|||||||
static int32 _CommandProcessorEntry(void *data);
|
static int32 _CommandProcessorEntry(void *data);
|
||||||
int32 _CommandProcessor();
|
int32 _CommandProcessor();
|
||||||
|
|
||||||
|
class DefaultSendCommandHandler;
|
||||||
struct CommandHandlerMap;
|
struct CommandHandlerMap;
|
||||||
|
|
||||||
static MessagingService *sService;
|
static MessagingService *sService;
|
||||||
|
|
||||||
|
mutable BLocker fLock;
|
||||||
sem_id fLockSem;
|
sem_id fLockSem;
|
||||||
sem_id fCounterSem;
|
sem_id fCounterSem;
|
||||||
MessagingArea *fFirstArea;
|
MessagingArea *fFirstArea;
|
||||||
|
|||||||
Reference in New Issue
Block a user