A new BInvoker implementation. The InvokeNotify is now implemented as it should.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3886 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Marc Flerackers
2003-07-07 07:58:14 +00:00
parent fb28706b69
commit 19225ae191
+71 -103
View File
@@ -19,21 +19,17 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
// File Name: Invoker.cpp // File Name: Control.cpp
// Author: Frans van Nispen ([email protected]) // Author: Marc Flerackers ([email protected])
// Description: BMessageFilter class creates objects that filter // Description: BInvoker class defines a protocol for objects that
// in-coming BMessages. // post messages to a "target".
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Standard Includes ----------------------------------------------------------- // Standard Includes -----------------------------------------------------------
#include <stdio.h>
// System Includes ------------------------------------------------------------- // System Includes -------------------------------------------------------------
#include <Application.h> #include "Invoker.h"
#include <Handler.h> #include <Support/Errors.h>
#include <Invoker.h>
#include <Message.h>
#include <Messenger.h>
// Project Includes ------------------------------------------------------------ // Project Includes ------------------------------------------------------------
@@ -44,28 +40,30 @@
// Globals --------------------------------------------------------------------- // Globals ---------------------------------------------------------------------
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BInvoker::BInvoker() BInvoker::BInvoker(BMessage *message, BMessenger messenger)
: fMessage(NULL), : fMessage(message),
fMessenger(be_app), fMessenger(messenger),
fReplyTo(NULL), fReplyTo(NULL),
fTimeout(B_INFINITE_TIMEOUT) fTimeout(B_INFINITE_TIMEOUT),
{ fNotifyKind(0)
{
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BInvoker::BInvoker(BMessage* message, const BHandler* handler, BInvoker::BInvoker(BMessage *message, const BHandler *handler,
const BLooper* looper) const BLooper *looper)
: fMessage(message), : fMessage(message),
fMessenger(BMessenger(handler, looper)), fMessenger(BMessenger(handler, looper)),
fReplyTo(NULL), fReplyTo(NULL),
fTimeout(B_INFINITE_TIMEOUT) fTimeout(B_INFINITE_TIMEOUT),
fNotifyKind(0)
{ {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BInvoker::BInvoker(BMessage* message, BMessenger target) BInvoker::BInvoker()
: fMessage(message), : fMessage(NULL),
fMessenger(BMessenger(target)),
fReplyTo(NULL), fReplyTo(NULL),
fTimeout(B_INFINITE_TIMEOUT) fTimeout(B_INFINITE_TIMEOUT),
fNotifyKind(0)
{ {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -74,14 +72,20 @@ BInvoker::~BInvoker()
delete fMessage; delete fMessage;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
status_t BInvoker::SetMessage(BMessage* message) status_t BInvoker::SetMessage(BMessage *message)
{ {
delete fMessage; if (fMessage == message)
return B_OK;
if (fMessage)
delete fMessage;
fMessage = message; fMessage = message;
return B_OK; return B_OK;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BMessage* BInvoker::Message() const BMessage *BInvoker::Message() const
{ {
return fMessage; return fMessage;
} }
@@ -89,25 +93,23 @@ BMessage* BInvoker::Message() const
uint32 BInvoker::Command() const uint32 BInvoker::Command() const
{ {
if (fMessage) if (fMessage)
{
return fMessage->what; return fMessage->what;
}
else else
{ return 0;
return (uint32)NULL;
}
}
//------------------------------------------------------------------------------
status_t BInvoker::SetTarget(const BHandler* handler, const BLooper* looper)
{
fMessenger = BMessenger(handler, looper);
return fMessenger.IsValid();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
status_t BInvoker::SetTarget(BMessenger messenger) status_t BInvoker::SetTarget(BMessenger messenger)
{ {
fMessenger = messenger; fMessenger = messenger;
return fMessenger.IsValid();
return B_OK;
}
//------------------------------------------------------------------------------
status_t BInvoker::SetTarget(const BHandler *handler, const BLooper *looper)
{
fMessenger = BMessenger(handler, looper);
return B_OK;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool BInvoker::IsTargetLocal() const bool BInvoker::IsTargetLocal() const
@@ -115,7 +117,7 @@ bool BInvoker::IsTargetLocal() const
return fMessenger.IsTargetLocal(); return fMessenger.IsTargetLocal();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BHandler* BInvoker::Target(BLooper** looper) const BHandler *BInvoker::Target(BLooper **looper) const
{ {
return fMessenger.Target(looper); return fMessenger.Target(looper);
} }
@@ -125,60 +127,47 @@ BMessenger BInvoker::Messenger() const
return fMessenger; return fMessenger;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
status_t BInvoker::SetHandlerForReply(BHandler* handler) status_t BInvoker::SetHandlerForReply(BHandler *replyHandler)
{ {
fReplyTo = handler; fReplyTo = replyHandler;
return B_OK; return B_OK;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BHandler* BInvoker::HandlerForReply() const BHandler *BInvoker::HandlerForReply() const
{ {
return fReplyTo; return fReplyTo;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
status_t BInvoker::Invoke(BMessage* msg) status_t BInvoker::Invoke(BMessage *message)
{ {
return InvokeNotify( msg ); if (!message)
message = Message();
if (!message)
return B_BAD_VALUE;
return fMessenger.SendMessage(message, fReplyTo, fTimeout);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
status_t BInvoker::InvokeNotify(BMessage* msg, uint32 kind) status_t BInvoker::InvokeNotify(BMessage *message, uint32 kind)
{ {
fNotifyKind = kind; if (fNotifyKind != 0)
return B_WOULD_BLOCK;
BMessage clone(kind); BeginInvokeNotify(kind);
status_t err = B_BAD_VALUE;
if (!msg && fNotifyKind == B_CONTROL_INVOKED)
{
msg = fMessage;
}
if (!msg) status_t err = Invoke(message);
{
if (!Target()->IsWatched())
return err;
}
else
{
clone = *msg;
}
clone.AddInt64("when", system_time()); EndInvokeNotify();
clone.AddPointer("source", this);
if (msg)
{
err = fMessenger.SendMessage( &clone, fReplyTo, fTimeout);
}
// Also send invocation to any observers of this handler.
Target()->SendNotices(kind, &clone);
return err; return err;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
status_t BInvoker::SetTimeout(bigtime_t timeout) status_t BInvoker::SetTimeout(bigtime_t timeout)
{ {
fTimeout = timeout; fTimeout = timeout;
return B_OK; return B_OK;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -187,18 +176,15 @@ bigtime_t BInvoker::Timeout() const
return fTimeout; return fTimeout;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
uint32 BInvoker::InvokeKind(bool* notify) uint32 BInvoker::InvokeKind(bool *notify)
{ {
if (fNotifyKind == B_CONTROL_INVOKED) if (notify)
{ *notify = (fNotifyKind != 0) ? true : false;
*notify = false;
}
else
{
*notify = true;
}
return fNotifyKind; if (fNotifyKind != 0)
return fNotifyKind;
else
return B_CONTROL_INVOKED;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BInvoker::BeginInvokeNotify(uint32 kind) void BInvoker::BeginInvokeNotify(uint32 kind)
@@ -208,37 +194,19 @@ void BInvoker::BeginInvokeNotify(uint32 kind)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BInvoker::EndInvokeNotify() void BInvoker::EndInvokeNotify()
{ {
fNotifyKind = B_CONTROL_INVOKED; fNotifyKind = 0;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BInvoker::_ReservedInvoker1() void BInvoker::_ReservedInvoker1() {}
{ void BInvoker::_ReservedInvoker2() {}
} void BInvoker::_ReservedInvoker3() {}
//------------------------------------------------------------------------------
void BInvoker::_ReservedInvoker2()
{
}
//------------------------------------------------------------------------------
void BInvoker::_ReservedInvoker3()
{
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BInvoker::BInvoker(const BInvoker &) BInvoker::BInvoker(const BInvoker &)
{ {
// No copy construction allowed!
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BInvoker& BInvoker::operator=(const BInvoker&) BInvoker &BInvoker::operator=(const BInvoker &)
{ {
// No assignment allowed!
return *this; return *this;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/*
* $Log $
*
* $Id $
*
*/