xref: /haiku/src/kits/app/RosterPrivate.cpp (revision 2b76973fa2401f7a5edf68e6470f3d3210cbcff3)
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.
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 	if (mime)
69 		return fRoster->_MimeMessenger().SendMessage(message, reply);
70 
71 	return fRoster->fMessenger.SendMessage(message, reply);
72 }
73 
74 
75 /*!	\brief Returns whether the roster's messengers are valid.
76 
77 	\a mime specifies whether to check the roster messenger or the one of
78 	the MIME data base service.
79 
80 	\param mime \c true, if the MIME data base service messenger should be
81 		   checked, \c false for the roster messenger.
82 	\return \true, if the selected messenger is valid, \c false otherwise.
83 */
84 bool
85 BRoster::Private::IsMessengerValid(bool mime) const
86 {
87 	return fRoster != NULL && (mime ? fRoster->_MimeMessenger().IsValid()
88 		: fRoster->fMessenger.IsValid());
89 }
90 
91 
92 /*!	\brief Initializes the global be_roster variable.
93 
94 	Called before the global constructors are invoked.
95 */
96 void
97 BRoster::Private::InitBeRoster()
98 {
99 	be_roster = new BRoster;
100 }
101 
102 
103 /*!	\brief Deletes the global be_roster.
104 
105 	Called after the global destructors are invoked.
106 */
107 void
108 BRoster::Private::DeleteBeRoster()
109 {
110 	delete be_roster;
111 }
112