2005-01-24 04:26:39 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2005, Ingo Weinhold, bonefish@users.sf.net. All rights reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MESSAGING_SERVICE_H
|
|
|
|
#define MESSAGING_SERVICE_H
|
|
|
|
|
2005-01-30 04:17:09 +03:00
|
|
|
#include <Locker.h>
|
2005-01-24 04:26:39 +03:00
|
|
|
#include <MessagingServiceDefs.h>
|
|
|
|
|
2005-01-25 17:58:37 +03:00
|
|
|
// MessagingCommandHandler
|
|
|
|
class MessagingCommandHandler {
|
|
|
|
public:
|
|
|
|
MessagingCommandHandler();
|
|
|
|
virtual ~MessagingCommandHandler();
|
|
|
|
|
|
|
|
virtual void HandleMessagingCommand(uint32 command, const void *data,
|
|
|
|
int32 dataSize) = 0;
|
|
|
|
};
|
|
|
|
|
2005-01-24 04:26:39 +03:00
|
|
|
// MessagingArea
|
|
|
|
class MessagingArea {
|
|
|
|
public:
|
|
|
|
~MessagingArea();
|
|
|
|
|
|
|
|
static status_t Create(area_id kernelAreaID, sem_id lockSem,
|
|
|
|
sem_id counterSem, MessagingArea *&area);
|
|
|
|
|
|
|
|
bool Lock();
|
|
|
|
void Unlock();
|
|
|
|
|
|
|
|
area_id ID() const;
|
|
|
|
int32 Size() const;
|
|
|
|
|
|
|
|
int32 CountCommands() const;
|
|
|
|
const messaging_command *PopCommand();
|
|
|
|
|
|
|
|
void Discard();
|
|
|
|
|
|
|
|
area_id NextKernelAreaID() const;
|
|
|
|
void SetNextArea(MessagingArea *area);
|
|
|
|
MessagingArea *NextArea() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
MessagingArea();
|
|
|
|
|
|
|
|
messaging_area_header *fHeader;
|
|
|
|
area_id fID;
|
|
|
|
int32 fSize;
|
|
|
|
sem_id fLockSem;
|
|
|
|
sem_id fCounterSem; // TODO: Remove, if not needed.
|
|
|
|
MessagingArea *fNextArea;
|
|
|
|
};
|
|
|
|
|
|
|
|
// MessagingService
|
|
|
|
class MessagingService {
|
2005-01-25 17:58:37 +03:00
|
|
|
private:
|
2005-01-24 04:26:39 +03:00
|
|
|
MessagingService();
|
|
|
|
~MessagingService();
|
|
|
|
|
|
|
|
status_t Init();
|
|
|
|
|
2005-01-25 17:58:37 +03:00
|
|
|
public:
|
|
|
|
static status_t CreateDefault();
|
|
|
|
static void DeleteDefault();
|
|
|
|
static MessagingService *Default();
|
|
|
|
|
|
|
|
void SetCommandHandler(uint32 command, MessagingCommandHandler *handler);
|
|
|
|
|
2005-01-24 04:26:39 +03:00
|
|
|
private:
|
2005-01-25 17:58:37 +03:00
|
|
|
MessagingCommandHandler *_GetCommandHandler(uint32 command) const;
|
|
|
|
|
2005-01-24 04:26:39 +03:00
|
|
|
static int32 _CommandProcessorEntry(void *data);
|
|
|
|
int32 _CommandProcessor();
|
|
|
|
|
2005-01-30 04:17:09 +03:00
|
|
|
class DefaultSendCommandHandler;
|
2005-01-25 17:58:37 +03:00
|
|
|
struct CommandHandlerMap;
|
|
|
|
|
|
|
|
static MessagingService *sService;
|
|
|
|
|
2005-01-30 04:17:09 +03:00
|
|
|
mutable BLocker fLock;
|
2005-01-25 17:58:37 +03:00
|
|
|
sem_id fLockSem;
|
|
|
|
sem_id fCounterSem;
|
|
|
|
MessagingArea *fFirstArea;
|
|
|
|
CommandHandlerMap *fCommandHandlers;
|
|
|
|
thread_id fCommandProcessor;
|
|
|
|
volatile bool fTerminating;
|
2005-01-24 04:26:39 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // MESSAGING_SERVICE_H
|