vfs: check userland buffers before reading them.
[haiku.git] / src / servers / registrar / MessagingService.h
blobad9cdf054636072cc28fb6732d6bd4ea826c5dcc
1 /*
2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
6 #ifndef MESSAGING_SERVICE_H
7 #define MESSAGING_SERVICE_H
9 #include <Locker.h>
10 #include <MessagingServiceDefs.h>
12 // MessagingCommandHandler
13 class MessagingCommandHandler {
14 public:
15 MessagingCommandHandler();
16 virtual ~MessagingCommandHandler();
18 virtual void HandleMessagingCommand(uint32 command, const void *data,
19 int32 dataSize) = 0;
22 // MessagingArea
23 class MessagingArea {
24 public:
25 ~MessagingArea();
27 static status_t Create(area_id kernelAreaID, sem_id lockSem,
28 sem_id counterSem, MessagingArea *&area);
30 bool Lock();
31 void Unlock();
33 area_id ID() const;
34 int32 Size() const;
36 int32 CountCommands() const;
37 const messaging_command *PopCommand();
39 void Discard();
41 area_id NextKernelAreaID() const;
42 void SetNextArea(MessagingArea *area);
43 MessagingArea *NextArea() const;
45 private:
46 MessagingArea();
48 messaging_area_header *fHeader;
49 area_id fID;
50 int32 fSize;
51 sem_id fLockSem;
52 sem_id fCounterSem; // TODO: Remove, if not needed.
53 MessagingArea *fNextArea;
56 // MessagingService
57 class MessagingService {
58 private:
59 MessagingService();
60 ~MessagingService();
62 status_t Init();
64 public:
65 static status_t CreateDefault();
66 static void DeleteDefault();
67 static MessagingService *Default();
69 void SetCommandHandler(uint32 command, MessagingCommandHandler *handler);
71 private:
72 MessagingCommandHandler *_GetCommandHandler(uint32 command) const;
74 static int32 _CommandProcessorEntry(void *data);
75 int32 _CommandProcessor();
77 class DefaultSendCommandHandler;
78 struct CommandHandlerMap;
80 static MessagingService *sService;
82 mutable BLocker fLock;
83 sem_id fLockSem;
84 sem_id fCounterSem;
85 MessagingArea *fFirstArea;
86 CommandHandlerMap *fCommandHandlers;
87 thread_id fCommandProcessor;
88 volatile bool fTerminating;
91 #endif // MESSAGING_SERVICE_H