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

View File

@ -19,21 +19,17 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: Invoker.cpp
// Author: Frans van Nispen (xlr8@tref.nl)
// Description: BMessageFilter class creates objects that filter
// in-coming BMessages.
// File Name: Control.cpp
// Author: Marc Flerackers (mflerackers@androme.be)
// Description: BInvoker class defines a protocol for objects that
// post messages to a "target".
//------------------------------------------------------------------------------
// Standard Includes -----------------------------------------------------------
#include <stdio.h>
// System Includes -------------------------------------------------------------
#include <Application.h>
#include <Handler.h>
#include <Invoker.h>
#include <Message.h>
#include <Messenger.h>
#include "Invoker.h"
#include <Support/Errors.h>
// Project Includes ------------------------------------------------------------
@ -44,28 +40,30 @@
// Globals ---------------------------------------------------------------------
//------------------------------------------------------------------------------
BInvoker::BInvoker()
: fMessage(NULL),
fMessenger(be_app),
BInvoker::BInvoker(BMessage *message, BMessenger messenger)
: fMessage(message),
fMessenger(messenger),
fReplyTo(NULL),
fTimeout(B_INFINITE_TIMEOUT)
{
fTimeout(B_INFINITE_TIMEOUT),
fNotifyKind(0)
{
}
//------------------------------------------------------------------------------
BInvoker::BInvoker(BMessage* message, const BHandler* handler,
const BLooper* looper)
BInvoker::BInvoker(BMessage *message, const BHandler *handler,
const BLooper *looper)
: fMessage(message),
fMessenger(BMessenger(handler, looper)),
fReplyTo(NULL),
fTimeout(B_INFINITE_TIMEOUT)
fTimeout(B_INFINITE_TIMEOUT),
fNotifyKind(0)
{
}
//------------------------------------------------------------------------------
BInvoker::BInvoker(BMessage* message, BMessenger target)
: fMessage(message),
fMessenger(BMessenger(target)),
BInvoker::BInvoker()
: fMessage(NULL),
fReplyTo(NULL),
fTimeout(B_INFINITE_TIMEOUT)
fTimeout(B_INFINITE_TIMEOUT),
fNotifyKind(0)
{
}
//------------------------------------------------------------------------------
@ -74,14 +72,20 @@ BInvoker::~BInvoker()
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;
return B_OK;
}
//------------------------------------------------------------------------------
BMessage* BInvoker::Message() const
BMessage *BInvoker::Message() const
{
return fMessage;
}
@ -89,25 +93,23 @@ BMessage* BInvoker::Message() const
uint32 BInvoker::Command() const
{
if (fMessage)
{
return fMessage->what;
}
else
{
return (uint32)NULL;
}
}
//------------------------------------------------------------------------------
status_t BInvoker::SetTarget(const BHandler* handler, const BLooper* looper)
{
fMessenger = BMessenger(handler, looper);
return fMessenger.IsValid();
return 0;
}
//------------------------------------------------------------------------------
status_t BInvoker::SetTarget(BMessenger 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
@ -115,7 +117,7 @@ bool BInvoker::IsTargetLocal() const
return fMessenger.IsTargetLocal();
}
//------------------------------------------------------------------------------
BHandler* BInvoker::Target(BLooper** looper) const
BHandler *BInvoker::Target(BLooper **looper) const
{
return fMessenger.Target(looper);
}
@ -125,60 +127,47 @@ BMessenger BInvoker::Messenger() const
return fMessenger;
}
//------------------------------------------------------------------------------
status_t BInvoker::SetHandlerForReply(BHandler* handler)
status_t BInvoker::SetHandlerForReply(BHandler *replyHandler)
{
fReplyTo = handler;
fReplyTo = replyHandler;
return B_OK;
}
//------------------------------------------------------------------------------
BHandler* BInvoker::HandlerForReply() const
BHandler *BInvoker::HandlerForReply() const
{
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);
status_t err = B_BAD_VALUE;
if (!msg && fNotifyKind == B_CONTROL_INVOKED)
{
msg = fMessage;
}
BeginInvokeNotify(kind);
if (!msg)
{
if (!Target()->IsWatched())
return err;
}
else
{
clone = *msg;
}
status_t err = Invoke(message);
clone.AddInt64("when", system_time());
clone.AddPointer("source", this);
EndInvokeNotify();
if (msg)
{
err = fMessenger.SendMessage( &clone, fReplyTo, fTimeout);
}
// Also send invocation to any observers of this handler.
Target()->SendNotices(kind, &clone);
return err;
}
//------------------------------------------------------------------------------
status_t BInvoker::SetTimeout(bigtime_t timeout)
{
fTimeout = timeout;
return B_OK;
}
//------------------------------------------------------------------------------
@ -187,18 +176,15 @@ bigtime_t BInvoker::Timeout() const
return fTimeout;
}
//------------------------------------------------------------------------------
uint32 BInvoker::InvokeKind(bool* notify)
uint32 BInvoker::InvokeKind(bool *notify)
{
if (fNotifyKind == B_CONTROL_INVOKED)
{
*notify = false;
}
else
{
*notify = true;
}
if (notify)
*notify = (fNotifyKind != 0) ? true : false;
return fNotifyKind;
if (fNotifyKind != 0)
return fNotifyKind;
else
return B_CONTROL_INVOKED;
}
//------------------------------------------------------------------------------
void BInvoker::BeginInvokeNotify(uint32 kind)
@ -208,37 +194,19 @@ void BInvoker::BeginInvokeNotify(uint32 kind)
//------------------------------------------------------------------------------
void BInvoker::EndInvokeNotify()
{
fNotifyKind = B_CONTROL_INVOKED;
fNotifyKind = 0;
}
//------------------------------------------------------------------------------
void BInvoker::_ReservedInvoker1()
{
}
//------------------------------------------------------------------------------
void BInvoker::_ReservedInvoker2()
{
}
//------------------------------------------------------------------------------
void BInvoker::_ReservedInvoker3()
{
}
void BInvoker::_ReservedInvoker1() {}
void BInvoker::_ReservedInvoker2() {}
void BInvoker::_ReservedInvoker3() {}
//------------------------------------------------------------------------------
BInvoker::BInvoker(const BInvoker &)
{
// No copy construction allowed!
}
//------------------------------------------------------------------------------
BInvoker& BInvoker::operator=(const BInvoker&)
BInvoker &BInvoker::operator=(const BInvoker &)
{
// No assignment allowed!
return *this;
}
//------------------------------------------------------------------------------
/*
* $Log $
*
* $Id $
*
*/