vfs: check userland buffers before reading them.
[haiku.git] / src / servers / registrar / MessageDeliverer.h
blobf76d0389eea0171dbfc957ddabe8656a64ff2db6
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 MESSAGE_DELIVERER_H
7 #define MESSAGE_DELIVERER_H
9 #include <Locker.h>
10 #include <Messenger.h>
12 struct messaging_target;
14 // MessagingTargetSet
15 class MessagingTargetSet {
16 public:
17 virtual ~MessagingTargetSet();
19 virtual bool HasNext() const = 0;
20 virtual bool Next(port_id &port, int32 &token) = 0;
21 virtual void Rewind() = 0;
24 // DefaultMessagingTargetSet
25 class DefaultMessagingTargetSet : public MessagingTargetSet {
26 public:
27 DefaultMessagingTargetSet(const messaging_target *targets,
28 int32 targetCount);
29 virtual ~DefaultMessagingTargetSet();
31 virtual bool HasNext() const;
32 virtual bool Next(port_id &port, int32 &token);
33 virtual void Rewind();
35 private:
36 const messaging_target *fTargets;
37 int32 fTargetCount;
38 int32 fNextIndex;
41 // SingleMessagingTargetSet
42 class SingleMessagingTargetSet : public MessagingTargetSet {
43 public:
44 SingleMessagingTargetSet(BMessenger target);
45 SingleMessagingTargetSet(port_id port, int32 token);
46 virtual ~SingleMessagingTargetSet();
48 virtual bool HasNext() const;
49 virtual bool Next(port_id &port, int32 &token);
50 virtual void Rewind();
52 private:
53 port_id fPort;
54 int32 fToken;
55 bool fAtBeginning;
58 // MessageDeliverer
59 class MessageDeliverer {
60 private:
61 MessageDeliverer();
62 ~MessageDeliverer();
64 status_t Init();
66 public:
67 static status_t CreateDefault();
68 static void DeleteDefault();
69 static MessageDeliverer *Default();
71 status_t DeliverMessage(BMessage *message, BMessenger target,
72 bigtime_t timeout = B_INFINITE_TIMEOUT);
73 status_t DeliverMessage(BMessage *message, MessagingTargetSet &targets,
74 bigtime_t timeout = B_INFINITE_TIMEOUT);
75 status_t DeliverMessage(const void *message, int32 messageSize,
76 MessagingTargetSet &targets, bigtime_t timeout = B_INFINITE_TIMEOUT);
78 private:
79 class Message;
80 class TargetMessage;
81 class TargetMessageHandle;
82 class TargetPort;
83 struct TargetPortMap;
85 TargetPort *_GetTargetPort(port_id portID, bool create = false);
86 void _PutTargetPort(TargetPort *port);
88 status_t _SendMessage(Message *message, port_id portID, int32 token);
90 static int32 _DelivererThreadEntry(void *data);
91 int32 _DelivererThread();
93 static MessageDeliverer *sDeliverer;
95 BLocker fLock;
96 TargetPortMap *fTargetPorts;
97 thread_id fDelivererThread;
98 volatile bool fTerminating;
101 #endif // MESSAGE_DELIVERER_H