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