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 13BInvoker::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 24BInvoker::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 36BInvoker::BInvoker() 37 : 38 fMessage(NULL), 39 fReplyTo(NULL), 40 fTimeout(B_INFINITE_TIMEOUT), 41 fNotifyKind(0) 42{ 43} 44 45 46BInvoker::~BInvoker() 47{ 48 delete fMessage; 49} 50 51 52status_t 53BInvoker::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 65BMessage* 66BInvoker::Message() const 67{ 68 return fMessage; 69} 70 71 72uint32 73BInvoker::Command() const 74{ 75 if (fMessage) 76 return fMessage->what; 77 78 return 0; 79} 80 81 82status_t 83BInvoker::SetTarget(BMessenger messenger) 84{ 85 fMessenger = messenger; 86 return B_OK; 87} 88 89 90status_t 91BInvoker::SetTarget(const BHandler* handler, const BLooper* looper) 92{ 93 fMessenger = BMessenger(handler, looper); 94 return B_OK; 95} 96 97 98bool 99BInvoker::IsTargetLocal() const 100{ 101 return fMessenger.IsTargetLocal(); 102} 103 104 105BHandler* 106BInvoker::Target(BLooper** _looper) const 107{ 108 return fMessenger.Target(_looper); 109} 110 111 112BMessenger 113BInvoker::Messenger() const 114{ 115 return fMessenger; 116} 117 118 119status_t 120BInvoker::SetHandlerForReply(BHandler* replyHandler) 121{ 122 fReplyTo = replyHandler; 123 return B_OK; 124} 125 126 127BHandler* 128BInvoker::HandlerForReply() const 129{ 130 return fReplyTo; 131} 132 133 134status_t 135BInvoker::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 147status_t 148BInvoker::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 161status_t 162BInvoker::SetTimeout(bigtime_t timeout) 163{ 164 fTimeout = timeout; 165 return B_OK; 166} 167 168 169bigtime_t 170BInvoker::Timeout() const 171{ 172 return fTimeout; 173} 174 175 176uint32 177BInvoker::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 189void 190BInvoker::BeginInvokeNotify(uint32 kind) 191{ 192 fNotifyKind = kind; 193} 194 195 196void 197BInvoker::EndInvokeNotify() 198{ 199 fNotifyKind = 0; 200} 201 202 203void BInvoker::_ReservedInvoker1() {} 204void BInvoker::_ReservedInvoker2() {} 205void BInvoker::_ReservedInvoker3() {} 206 207 208BInvoker::BInvoker(const BInvoker &) 209{ 210} 211 212 213BInvoker & 214BInvoker::operator=(const BInvoker &) 215{ 216 return *this; 217} 218 219