2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 #ifndef MESSAGE_DELIVERER_H
7 #define MESSAGE_DELIVERER_H
10 #include <Messenger.h>
12 struct messaging_target
;
15 class MessagingTargetSet
{
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
{
27 DefaultMessagingTargetSet(const messaging_target
*targets
,
29 virtual ~DefaultMessagingTargetSet();
31 virtual bool HasNext() const;
32 virtual bool Next(port_id
&port
, int32
&token
);
33 virtual void Rewind();
36 const messaging_target
*fTargets
;
41 // SingleMessagingTargetSet
42 class SingleMessagingTargetSet
: public MessagingTargetSet
{
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();
59 class MessageDeliverer
{
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
);
81 class TargetMessageHandle
;
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
;
96 TargetPortMap
*fTargetPorts
;
97 thread_id fDelivererThread
;
98 volatile bool fTerminating
;
101 #endif // MESSAGE_DELIVERER_H