15edcfe96SAxel Dörfler/*
22bc07d28SAxel Dörfler * Copyright 2001-2015, Haiku.
35edcfe96SAxel Dörfler * Distributed under the terms of the MIT License.
45edcfe96SAxel Dörfler *
55edcfe96SAxel Dörfler * Authors:
65edcfe96SAxel Dörfler *		Ingo Weinhold (bonefish@users.sf.net)
75edcfe96SAxel Dörfler */
85edcfe96SAxel Dörfler
94fb9da18SAxel Dörfler
105edcfe96SAxel Dörfler//! Access class for BRoster members
115edcfe96SAxel Dörfler
122ed834e3SIngo Weinhold
132ed834e3SIngo Weinhold#include <RosterPrivate.h>
14f8ec4c04SIngo Weinhold
152ed834e3SIngo Weinhold#include <Roster.h>
162ed834e3SIngo Weinhold
17f8ec4c04SIngo Weinhold#include <locks.h>
18f8ec4c04SIngo Weinhold
194fb9da18SAxel Dörfler
202ed834e3SIngo Weinhold/*!	\class BRoster::Private
212ed834e3SIngo Weinhold	\brief Class used to access private BRoster members.
222ed834e3SIngo Weinhold
232ed834e3SIngo Weinhold	This way, the only friend BRoster needs is this class.
242ed834e3SIngo Weinhold*/
252ed834e3SIngo Weinhold
264fb9da18SAxel Dörfler
272ed834e3SIngo Weinhold/*!	\brief Initializes the roster.
282ed834e3SIngo Weinhold
292ed834e3SIngo Weinhold	\param mainMessenger A BMessenger targeting the registrar application.
302ed834e3SIngo Weinhold	\param mimeMessenger A BMessenger targeting the MIME manager.
312ed834e3SIngo Weinhold*/
322ed834e3SIngo Weinholdvoid
332ed834e3SIngo WeinholdBRoster::Private::SetTo(BMessenger mainMessenger, BMessenger mimeMessenger)
342ed834e3SIngo Weinhold{
354fb9da18SAxel Dörfler	if (fRoster != NULL) {
36eb797182SAxel Dörfler		fRoster->fMessenger = mainMessenger;
37eb797182SAxel Dörfler		fRoster->fMimeMessenger = mimeMessenger;
38f8ec4c04SIngo Weinhold		fRoster->fMimeMessengerInitOnce = INIT_ONCE_INITIALIZED;
392ed834e3SIngo Weinhold	}
402ed834e3SIngo Weinhold}
412ed834e3SIngo Weinhold
424fb9da18SAxel Dörfler
432ed834e3SIngo Weinhold/*!	\brief Sends a message to the registrar.
442ed834e3SIngo Weinhold
452ed834e3SIngo Weinhold	\a mime specifies whether to send the message to the roster or to the
462ed834e3SIngo Weinhold	MIME data base service.
472ed834e3SIngo Weinhold	If \a reply is not \c NULL, the function waits for a reply.
482ed834e3SIngo Weinhold
492ed834e3SIngo Weinhold	\param message The message to be sent.
502ed834e3SIngo Weinhold	\param reply A pointer to a pre-allocated BMessage into which the reply
51b44215c0SIngo Weinhold		   message will be copied. May be \c NULL.
522ed834e3SIngo Weinhold	\param mime \c true, if the message should be sent to the MIME data base
532ed834e3SIngo Weinhold		   service, \c false for the roster.
542ed834e3SIngo Weinhold	\return
552ed834e3SIngo Weinhold	- \c B_OK: Everything went fine.
562ed834e3SIngo Weinhold	- \c B_BAD_VALUE: \c NULL \a message.
572ed834e3SIngo Weinhold	- \c B_NO_INIT: the roster is \c NULL.
582ed834e3SIngo Weinhold	- another error code
592ed834e3SIngo Weinhold*/
602ed834e3SIngo Weinholdstatus_t
612ed834e3SIngo WeinholdBRoster::Private::SendTo(BMessage *message, BMessage *reply, bool mime)
622ed834e3SIngo Weinhold{
634fb9da18SAxel Dörfler	if (message == NULL)
644fb9da18SAxel Dörfler		return B_BAD_VALUE;
654fb9da18SAxel Dörfler	if (fRoster == NULL)
664fb9da18SAxel Dörfler		return B_NO_INIT;
674fb9da18SAxel Dörfler
68b44215c0SIngo Weinhold	const BMessenger& messenger = mime
69b44215c0SIngo Weinhold		? fRoster->_MimeMessenger() : fRoster->fMessenger;
702bc07d28SAxel Dörfler	if (messenger.IsTargetLocal())
712bc07d28SAxel Dörfler		return B_BAD_VALUE;
724fb9da18SAxel Dörfler
73b44215c0SIngo Weinhold	return reply != NULL
74b44215c0SIngo Weinhold		? messenger.SendMessage(message, reply)
75b44215c0SIngo Weinhold		: messenger.SendMessage(message);
762ed834e3SIngo Weinhold}
772ed834e3SIngo Weinhold
784fb9da18SAxel Dörfler
792ed834e3SIngo Weinhold/*!	\brief Returns whether the roster's messengers are valid.
802ed834e3SIngo Weinhold
812ed834e3SIngo Weinhold	\a mime specifies whether to check the roster messenger or the one of
822ed834e3SIngo Weinhold	the MIME data base service.
832ed834e3SIngo Weinhold
842ed834e3SIngo Weinhold	\param mime \c true, if the MIME data base service messenger should be
852ed834e3SIngo Weinhold		   checked, \c false for the roster messenger.
862ed834e3SIngo Weinhold	\return \true, if the selected messenger is valid, \c false otherwise.
872ed834e3SIngo Weinhold*/
882ed834e3SIngo Weinholdbool
892ed834e3SIngo WeinholdBRoster::Private::IsMessengerValid(bool mime) const
902ed834e3SIngo Weinhold{
91f8ec4c04SIngo Weinhold	return fRoster != NULL && (mime ? fRoster->_MimeMessenger().IsValid()
924fb9da18SAxel Dörfler		: fRoster->fMessenger.IsValid());
932ed834e3SIngo Weinhold}
942ed834e3SIngo Weinhold
954fb9da18SAxel Dörfler
962ed834e3SIngo Weinhold/*!	\brief Initializes the global be_roster variable.
972ed834e3SIngo Weinhold
982ed834e3SIngo Weinhold	Called before the global constructors are invoked.
992ed834e3SIngo Weinhold*/
1005ac11568SIngo Weinholdvoid
1015ac11568SIngo WeinholdBRoster::Private::InitBeRoster()
1022ed834e3SIngo Weinhold{
1032ed834e3SIngo Weinhold	be_roster = new BRoster;
1042ed834e3SIngo Weinhold}
1052ed834e3SIngo Weinhold
1064fb9da18SAxel Dörfler
1072ed834e3SIngo Weinhold/*!	\brief Deletes the global be_roster.
1082ed834e3SIngo Weinhold
1092ed834e3SIngo Weinhold	Called after the global destructors are invoked.
1102ed834e3SIngo Weinhold*/
1115ac11568SIngo Weinholdvoid
1125ac11568SIngo WeinholdBRoster::Private::DeleteBeRoster()
1132ed834e3SIngo Weinhold{
1142ed834e3SIngo Weinhold	delete be_roster;
1152ed834e3SIngo Weinhold}