Files
haiku-beta6/src/kits/app/Invoker.cpp
T

213 lines
6.5 KiB
C++
Raw Normal View History

2002-07-09 12:24:59 +00:00
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, OpenBeOS
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
2003-09-04 20:01:17 +00:00
// File Name: Invoker.cpp
// Author: Marc Flerackers ([email protected])
// Description: BInvoker class defines a protocol for objects that
// post messages to a "target".
2002-07-09 12:24:59 +00:00
//------------------------------------------------------------------------------
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
2003-09-04 20:01:17 +00:00
#include <Invoker.h>
2003-07-09 18:46:04 +00:00
#include <Errors.h>
2002-07-09 12:24:59 +00:00
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
//------------------------------------------------------------------------------
BInvoker::BInvoker(BMessage *message, BMessenger messenger)
: fMessage(message),
fMessenger(messenger),
2002-07-09 12:24:59 +00:00
fReplyTo(NULL),
fTimeout(B_INFINITE_TIMEOUT),
fNotifyKind(0)
{
2002-07-09 12:24:59 +00:00
}
//------------------------------------------------------------------------------
BInvoker::BInvoker(BMessage *message, const BHandler *handler,
const BLooper *looper)
2002-07-09 12:24:59 +00:00
: fMessage(message),
fMessenger(BMessenger(handler, looper)),
fReplyTo(NULL),
fTimeout(B_INFINITE_TIMEOUT),
fNotifyKind(0)
2002-07-09 12:24:59 +00:00
{
}
//------------------------------------------------------------------------------
BInvoker::BInvoker()
: fMessage(NULL),
2002-07-09 12:24:59 +00:00
fReplyTo(NULL),
fTimeout(B_INFINITE_TIMEOUT),
fNotifyKind(0)
2002-07-09 12:24:59 +00:00
{
}
//------------------------------------------------------------------------------
BInvoker::~BInvoker()
{
delete fMessage;
}
//------------------------------------------------------------------------------
status_t BInvoker::SetMessage(BMessage *message)
2002-07-09 12:24:59 +00:00
{
if (fMessage == message)
return B_OK;
if (fMessage)
delete fMessage;
2002-07-09 12:24:59 +00:00
fMessage = message;
2002-07-09 12:24:59 +00:00
return B_OK;
}
//------------------------------------------------------------------------------
BMessage *BInvoker::Message() const
2002-07-09 12:24:59 +00:00
{
return fMessage;
}
//------------------------------------------------------------------------------
uint32 BInvoker::Command() const
{
if (fMessage)
return fMessage->what;
else
return 0;
2002-07-09 12:24:59 +00:00
}
//------------------------------------------------------------------------------
status_t BInvoker::SetTarget(BMessenger messenger)
2002-07-09 12:24:59 +00:00
{
fMessenger = messenger;
return B_OK;
2002-07-09 12:24:59 +00:00
}
//------------------------------------------------------------------------------
status_t BInvoker::SetTarget(const BHandler *handler, const BLooper *looper)
2002-07-09 12:24:59 +00:00
{
fMessenger = BMessenger(handler, looper);
return B_OK;
2002-07-09 12:24:59 +00:00
}
//------------------------------------------------------------------------------
bool BInvoker::IsTargetLocal() const
{
return fMessenger.IsTargetLocal();
}
//------------------------------------------------------------------------------
BHandler *BInvoker::Target(BLooper **looper) const
2002-07-09 12:24:59 +00:00
{
return fMessenger.Target(looper);
}
//------------------------------------------------------------------------------
BMessenger BInvoker::Messenger() const
{
return fMessenger;
}
//------------------------------------------------------------------------------
status_t BInvoker::SetHandlerForReply(BHandler *replyHandler)
2002-07-09 12:24:59 +00:00
{
fReplyTo = replyHandler;
2002-07-09 12:24:59 +00:00
return B_OK;
}
//------------------------------------------------------------------------------
BHandler *BInvoker::HandlerForReply() const
2002-07-09 12:24:59 +00:00
{
return fReplyTo;
}
//------------------------------------------------------------------------------
status_t BInvoker::Invoke(BMessage *message)
2002-07-09 12:24:59 +00:00
{
if (!message)
message = Message();
if (!message)
return B_BAD_VALUE;
return fMessenger.SendMessage(message, fReplyTo, fTimeout);
2002-07-09 12:24:59 +00:00
}
//------------------------------------------------------------------------------
status_t BInvoker::InvokeNotify(BMessage *message, uint32 kind)
2002-07-09 12:24:59 +00:00
{
if (fNotifyKind != 0)
return B_WOULD_BLOCK;
BeginInvokeNotify(kind);
status_t err = Invoke(message);
EndInvokeNotify();
2002-07-09 12:24:59 +00:00
return err;
}
//------------------------------------------------------------------------------
status_t BInvoker::SetTimeout(bigtime_t timeout)
{
fTimeout = timeout;
2002-07-09 12:24:59 +00:00
return B_OK;
}
//------------------------------------------------------------------------------
bigtime_t BInvoker::Timeout() const
{
return fTimeout;
}
//------------------------------------------------------------------------------
uint32 BInvoker::InvokeKind(bool *notify)
2002-07-09 12:24:59 +00:00
{
if (notify)
*notify = (fNotifyKind != 0) ? true : false;
2002-07-09 12:24:59 +00:00
if (fNotifyKind != 0)
return fNotifyKind;
else
return B_CONTROL_INVOKED;
2002-07-09 12:24:59 +00:00
}
//------------------------------------------------------------------------------
void BInvoker::BeginInvokeNotify(uint32 kind)
{
fNotifyKind = kind;
}
//------------------------------------------------------------------------------
void BInvoker::EndInvokeNotify()
{
fNotifyKind = 0;
2002-07-09 12:24:59 +00:00
}
//------------------------------------------------------------------------------
void BInvoker::_ReservedInvoker1() {}
void BInvoker::_ReservedInvoker2() {}
void BInvoker::_ReservedInvoker3() {}
2002-07-09 12:24:59 +00:00
//------------------------------------------------------------------------------
BInvoker::BInvoker(const BInvoker &)
{
}
//------------------------------------------------------------------------------
BInvoker &BInvoker::operator=(const BInvoker &)
2002-07-09 12:24:59 +00:00
{
return *this;
}
//------------------------------------------------------------------------------