xref: /haiku/src/kits/app/RosterPrivate.cpp (revision 81f5654c124bf46fba0fd251f208e2d88d81e1ce)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2001-2002, OpenBeOS
3 //
4 //	Permission is hereby granted, free of charge, to any person obtaining a
5 //	copy of this software and associated documentation files (the "Software"),
6 //	to deal in the Software without restriction, including without limitation
7 //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 //	and/or sell copies of the Software, and to permit persons to whom the
9 //	Software is furnished to do so, subject to the following conditions:
10 //
11 //	The above copyright notice and this permission notice shall be included in
12 //	all copies or substantial portions of the Software.
13 //
14 //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 //	DEALINGS IN THE SOFTWARE.
21 //
22 //	File Name:		RosterPrivate.cpp
23 //	Author(s):		Ingo Weinhold (bonefish@users.sf.net)
24 //	Description:	Access class for BRoster members
25 //------------------------------------------------------------------------------
26 
27 #include <RosterPrivate.h>
28 #include <Roster.h>
29 
30 /*!	\class BRoster::Private
31 	\brief Class used to access private BRoster members.
32 
33 	This way, the only friend BRoster needs is this class.
34 */
35 
36 // SetTo
37 /*!	\brief Initializes the roster.
38 
39 	\param mainMessenger A BMessenger targeting the registrar application.
40 	\param mimeMessenger A BMessenger targeting the MIME manager.
41 */
42 void
43 BRoster::Private::SetTo(BMessenger mainMessenger, BMessenger mimeMessenger)
44 {
45 	if (fRoster) {
46 		fRoster->fMess = mainMessenger;
47 		fRoster->fMimeMess = mimeMessenger;
48 	}
49 }
50 
51 // SendTo
52 /*!	\brief Sends a message to the registrar.
53 
54 	\a mime specifies whether to send the message to the roster or to the
55 	MIME data base service.
56 	If \a reply is not \c NULL, the function waits for a reply.
57 
58 	\param message The message to be sent.
59 	\param reply A pointer to a pre-allocated BMessage into which the reply
60 		   message will be copied.
61 	\param mime \c true, if the message should be sent to the MIME data base
62 		   service, \c false for the roster.
63 	\return
64 	- \c B_OK: Everything went fine.
65 	- \c B_BAD_VALUE: \c NULL \a message.
66 	- \c B_NO_INIT: the roster is \c NULL.
67 	- another error code
68 */
69 status_t
70 BRoster::Private::SendTo(BMessage *message, BMessage *reply, bool mime)
71 {
72 	status_t error = (message ? B_OK : B_BAD_VALUE);
73 	if (error == B_OK && !fRoster)
74 		error = B_NO_INIT;
75 	if (error == B_OK) {
76 		if (mime)
77 			error = fRoster->fMimeMess.SendMessage(message, reply);
78 		else
79 			error = fRoster->fMess.SendMessage(message, reply);
80 	}
81 	return error;
82 }
83 
84 // IsMessengerValid
85 /*!	\brief Returns whether the roster's messengers are valid.
86 
87 	\a mime specifies whether to check the roster messenger or the one of
88 	the MIME data base service.
89 
90 	\param mime \c true, if the MIME data base service messenger should be
91 		   checked, \c false for the roster messenger.
92 	\return \true, if the selected messenger is valid, \c false otherwise.
93 */
94 bool
95 BRoster::Private::IsMessengerValid(bool mime) const
96 {
97 	return (fRoster && (mime ? fRoster->fMimeMess.IsValid()
98 							 : fRoster->fMess.IsValid()));
99 }
100 
101 
102 // _init_roster_
103 /*!	\brief Initializes the global be_roster variable.
104 
105 	Called before the global constructors are invoked.
106 
107 	\return Unknown!
108 
109 	\todo Investigate what the return value means.
110 */
111 int
112 _init_roster_()
113 {
114 	be_roster = new BRoster;
115 	return 0;
116 }
117 
118 // _delete_roster_
119 /*!	\brief Deletes the global be_roster.
120 
121 	Called after the global destructors are invoked.
122 
123 	\return Unknown!
124 
125 	\todo Investigate what the return value means.
126 */
127 int
128 _delete_roster_()
129 {
130 	delete be_roster;
131 	return 0;
132 }
133 
134