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