xref: /haiku/src/kits/app/RosterPrivate.cpp (revision 9522c1e4f21b0292084467c927e4169770db1329)
1 /*
2  * Copyright 2001-2009, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Ingo Weinhold (bonefish@users.sf.net)
7  */
8 
9 
10 //! Access class for BRoster members
11 
12 
13 #include <RosterPrivate.h>
14 
15 #include <Roster.h>
16 
17 #include <locks.h>
18 
19 
20 /*!	\class BRoster::Private
21 	\brief Class used to access private BRoster members.
22 
23 	This way, the only friend BRoster needs is this class.
24 */
25 
26 
27 /*!	\brief Initializes the roster.
28 
29 	\param mainMessenger A BMessenger targeting the registrar application.
30 	\param mimeMessenger A BMessenger targeting the MIME manager.
31 */
32 void
33 BRoster::Private::SetTo(BMessenger mainMessenger, BMessenger mimeMessenger)
34 {
35 	if (fRoster != NULL) {
36 		fRoster->fMessenger = mainMessenger;
37 		fRoster->fMimeMessenger = mimeMessenger;
38 		fRoster->fMimeMessengerInitOnce = INIT_ONCE_INITIALIZED;
39 	}
40 }
41 
42 
43 /*!	\brief Sends a message to the registrar.
44 
45 	\a mime specifies whether to send the message to the roster or to the
46 	MIME data base service.
47 	If \a reply is not \c NULL, the function waits for a reply.
48 
49 	\param message The message to be sent.
50 	\param reply A pointer to a pre-allocated BMessage into which the reply
51 		   message will be copied. May be \c NULL.
52 	\param mime \c true, if the message should be sent to the MIME data base
53 		   service, \c false for the roster.
54 	\return
55 	- \c B_OK: Everything went fine.
56 	- \c B_BAD_VALUE: \c NULL \a message.
57 	- \c B_NO_INIT: the roster is \c NULL.
58 	- another error code
59 */
60 status_t
61 BRoster::Private::SendTo(BMessage *message, BMessage *reply, bool mime)
62 {
63 	if (message == NULL)
64 		return B_BAD_VALUE;
65 	if (fRoster == NULL)
66 		return B_NO_INIT;
67 
68 	const BMessenger& messenger = mime
69 		? fRoster->_MimeMessenger() : fRoster->fMessenger;
70 
71 	return reply != NULL
72 		? messenger.SendMessage(message, reply)
73 		: messenger.SendMessage(message);
74 }
75 
76 
77 /*!	\brief Returns whether the roster's messengers are valid.
78 
79 	\a mime specifies whether to check the roster messenger or the one of
80 	the MIME data base service.
81 
82 	\param mime \c true, if the MIME data base service messenger should be
83 		   checked, \c false for the roster messenger.
84 	\return \true, if the selected messenger is valid, \c false otherwise.
85 */
86 bool
87 BRoster::Private::IsMessengerValid(bool mime) const
88 {
89 	return fRoster != NULL && (mime ? fRoster->_MimeMessenger().IsValid()
90 		: fRoster->fMessenger.IsValid());
91 }
92 
93 
94 /*!	\brief Initializes the global be_roster variable.
95 
96 	Called before the global constructors are invoked.
97 */
98 void
99 BRoster::Private::InitBeRoster()
100 {
101 	be_roster = new BRoster;
102 }
103 
104 
105 /*!	\brief Deletes the global be_roster.
106 
107 	Called after the global destructors are invoked.
108 */
109 void
110 BRoster::Private::DeleteBeRoster()
111 {
112 	delete be_roster;
113 }
114