1 /*
2 * Copyright 2001-2005, Haiku.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 * Marc Flerackers (mflerackers@androme.be)
7 */
8
9
10 #include <Invoker.h>
11
12
BInvoker(BMessage * message,BMessenger messenger)13 BInvoker::BInvoker(BMessage* message, BMessenger messenger)
14 :
15 fMessage(message),
16 fMessenger(messenger),
17 fReplyTo(NULL),
18 fTimeout(B_INFINITE_TIMEOUT),
19 fNotifyKind(0)
20 {
21 }
22
23
BInvoker(BMessage * message,const BHandler * handler,const BLooper * looper)24 BInvoker::BInvoker(BMessage* message, const BHandler* handler,
25 const BLooper* looper)
26 :
27 fMessage(message),
28 fMessenger(BMessenger(handler, looper)),
29 fReplyTo(NULL),
30 fTimeout(B_INFINITE_TIMEOUT),
31 fNotifyKind(0)
32 {
33 }
34
35
BInvoker()36 BInvoker::BInvoker()
37 :
38 fMessage(NULL),
39 fReplyTo(NULL),
40 fTimeout(B_INFINITE_TIMEOUT),
41 fNotifyKind(0)
42 {
43 }
44
45
~BInvoker()46 BInvoker::~BInvoker()
47 {
48 delete fMessage;
49 }
50
51
52 status_t
SetMessage(BMessage * message)53 BInvoker::SetMessage(BMessage* message)
54 {
55 if (fMessage == message)
56 return B_OK;
57
58 delete fMessage;
59 fMessage = message;
60
61 return B_OK;
62 }
63
64
65 BMessage*
Message() const66 BInvoker::Message() const
67 {
68 return fMessage;
69 }
70
71
72 uint32
Command() const73 BInvoker::Command() const
74 {
75 if (fMessage)
76 return fMessage->what;
77
78 return 0;
79 }
80
81
82 status_t
SetTarget(BMessenger messenger)83 BInvoker::SetTarget(BMessenger messenger)
84 {
85 fMessenger = messenger;
86 return B_OK;
87 }
88
89
90 status_t
SetTarget(const BHandler * handler,const BLooper * looper)91 BInvoker::SetTarget(const BHandler* handler, const BLooper* looper)
92 {
93 fMessenger = BMessenger(handler, looper);
94 return B_OK;
95 }
96
97
98 bool
IsTargetLocal() const99 BInvoker::IsTargetLocal() const
100 {
101 return fMessenger.IsTargetLocal();
102 }
103
104
105 BHandler*
Target(BLooper ** _looper) const106 BInvoker::Target(BLooper** _looper) const
107 {
108 return fMessenger.Target(_looper);
109 }
110
111
112 BMessenger
Messenger() const113 BInvoker::Messenger() const
114 {
115 return fMessenger;
116 }
117
118
119 status_t
SetHandlerForReply(BHandler * replyHandler)120 BInvoker::SetHandlerForReply(BHandler* replyHandler)
121 {
122 fReplyTo = replyHandler;
123 return B_OK;
124 }
125
126
127 BHandler*
HandlerForReply() const128 BInvoker::HandlerForReply() const
129 {
130 return fReplyTo;
131 }
132
133
134 status_t
Invoke(BMessage * message)135 BInvoker::Invoke(BMessage* message)
136 {
137 if (!message)
138 message = Message();
139
140 if (!message)
141 return B_BAD_VALUE;
142
143 return fMessenger.SendMessage(message, fReplyTo, fTimeout);
144 }
145
146
147 status_t
InvokeNotify(BMessage * message,uint32 kind)148 BInvoker::InvokeNotify(BMessage* message, uint32 kind)
149 {
150 if (fNotifyKind != 0)
151 return B_WOULD_BLOCK;
152
153 BeginInvokeNotify(kind);
154 status_t err = Invoke(message);
155 EndInvokeNotify();
156
157 return err;
158 }
159
160
161 status_t
SetTimeout(bigtime_t timeout)162 BInvoker::SetTimeout(bigtime_t timeout)
163 {
164 fTimeout = timeout;
165 return B_OK;
166 }
167
168
169 bigtime_t
Timeout() const170 BInvoker::Timeout() const
171 {
172 return fTimeout;
173 }
174
175
176 uint32
InvokeKind(bool * _notify)177 BInvoker::InvokeKind(bool* _notify)
178 {
179 if (_notify)
180 *_notify = fNotifyKind != 0;
181
182 if (fNotifyKind != 0)
183 return fNotifyKind;
184
185 return B_CONTROL_INVOKED;
186 }
187
188
189 void
BeginInvokeNotify(uint32 kind)190 BInvoker::BeginInvokeNotify(uint32 kind)
191 {
192 fNotifyKind = kind;
193 }
194
195
196 void
EndInvokeNotify()197 BInvoker::EndInvokeNotify()
198 {
199 fNotifyKind = 0;
200 }
201
202
_ReservedInvoker1()203 void BInvoker::_ReservedInvoker1() {}
_ReservedInvoker2()204 void BInvoker::_ReservedInvoker2() {}
_ReservedInvoker3()205 void BInvoker::_ReservedInvoker3() {}
206
207
BInvoker(const BInvoker &)208 BInvoker::BInvoker(const BInvoker &)
209 {
210 }
211
212
213 BInvoker &
operator =(const BInvoker &)214 BInvoker::operator=(const BInvoker &)
215 {
216 return *this;
217 }
218
219