/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "Be.h"


BInvoker::BInvoker () :
fMessage (0),
fMessenger (be_app),
fReplyTo (0),
fTimeout (B_INFINITE_TIMEOUT),
fNotifyKind (0)
{
}


BInvoker::BInvoker (BMessage *message, const BHandler *handler, const BLooper *looper) :
fMessage (message),
fMessenger (BMessenger (handler, looper)),
fReplyTo (0),
fTimeout (B_INFINITE_TIMEOUT),
fNotifyKind (0)
{
}


BInvoker::~BInvoker ()
{
	delete fMessage;
}


status_t BInvoker::SetMessage (BMessage *message)
{
	delete fMessage;
	fMessage = message;
	return B_OK;
}


BMessage* BInvoker::Message() const
{
	return fMessage;
}


status_t BInvoker::SetTarget (const BHandler *h, const BLooper *loop)
{
	fMessenger.fHandler = const_cast<BHandler*>(h);
	fMessenger.fLooper = const_cast<BLooper*>(loop);
	return B_BAD_VALUE;
}


status_t BInvoker::SetTarget (BMessenger messenger)
{
	fMessenger = messenger;
	return B_OK;
}


BHandler* BInvoker::Target(BLooper** looper) const
{
	return fMessenger.Target(looper);
}


status_t BInvoker::SetHandlerForReply (BHandler *handler)
{
	fReplyTo = handler;
	return B_OK;
}


status_t BInvoker::Invoke (BMessage *msg)
{
	status_t result = B_OK;

	if (msg)
		result = fMessenger.SendMessage (msg, fReplyTo);
	else if (fMessage)
		result = fMessenger.SendMessage (fMessage, fReplyTo);
	else
		result = B_BAD_VALUE;

	return result;
}


void BInvoker::_ReservedInvoker1 ()
{
}


void BInvoker::_ReservedInvoker2 ()
{
}


void BInvoker::_ReservedInvoker3 ()
{
}
