2 * Copyright 2015 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Axel Dörfler, axeld@pinc-software.de
10 #include <LaunchRoster.h>
12 #include <Application.h>
16 #include <LaunchDaemonDefs.h>
17 #include <LaunchRosterPrivate.h>
18 #include <MessengerPrivate.h>
21 using namespace BPrivate
;
24 BLaunchRoster::Private::Private(BLaunchRoster
* roster
)
31 BLaunchRoster::Private::Private(BLaunchRoster
& roster
)
39 BLaunchRoster::Private::RegisterSessionDaemon(const BMessenger
& daemon
)
41 BMessage
request(B_REGISTER_SESSION_DAEMON
);
42 status_t status
= request
.AddInt32("user", getuid());
44 status
= request
.AddMessenger("daemon", daemon
);
50 status
= fRoster
->fMessenger
.SendMessage(&request
, &result
);
63 BLaunchRoster::BLaunchRoster()
69 BLaunchRoster::~BLaunchRoster()
75 BLaunchRoster::InitCheck() const
77 return fMessenger
.Team() >= 0 ? B_OK
: B_ERROR
;
82 BLaunchRoster::GetData(BMessage
& data
)
87 return GetData(be_app
->Signature(), data
);
92 BLaunchRoster::GetData(const char* signature
, BMessage
& data
)
94 if (signature
== NULL
|| signature
[0] == '\0')
97 BMessage
request(B_GET_LAUNCH_DATA
);
98 status_t status
= request
.AddString("name", signature
);
100 status
= request
.AddInt32("user", getuid());
105 status
= fMessenger
.SendMessage(&request
, &data
);
107 // evaluate the reply
116 BLaunchRoster::GetPort(const char* name
)
121 return GetPort(be_app
->Signature(), name
);
126 BLaunchRoster::GetPort(const char* signature
, const char* name
)
129 status_t status
= GetData(signature
, data
);
130 if (status
== B_OK
) {
133 fieldName
<< name
<< "_";
136 port_id port
= data
.GetInt32(fieldName
.String(), B_NAME_NOT_FOUND
);
146 BLaunchRoster::Target(const char* name
, const BMessage
& data
,
147 const char* baseName
)
149 return Target(name
, &data
, baseName
);
154 BLaunchRoster::Target(const char* name
, const BMessage
* data
,
155 const char* baseName
)
160 BMessage
request(B_LAUNCH_TARGET
);
161 status_t status
= request
.AddInt32("user", getuid());
163 status
= request
.AddString("target", name
);
164 if (status
== B_OK
&& data
!= NULL
&& !data
->IsEmpty())
165 status
= request
.AddMessage("data", data
);
166 if (status
== B_OK
&& baseName
!= NULL
)
167 status
= request
.AddString("base target", baseName
);
173 status
= fMessenger
.SendMessage(&request
, &result
);
175 // evaluate the reply
177 status
= result
.what
;
184 BLaunchRoster::StartSession(const char* login
)
189 BMessage
request(B_LAUNCH_SESSION
);
190 status_t status
= request
.AddInt32("user", getuid());
192 status
= request
.AddString("login", login
);
198 status
= fMessenger
.SendMessage(&request
, &result
);
200 // evaluate the reply
202 status
= result
.what
;
209 BLaunchRoster::RegisterEvent(const BMessenger
& source
, const char* name
)
211 return _UpdateEvent(B_REGISTER_LAUNCH_EVENT
, source
, name
);
216 BLaunchRoster::UnregisterEvent(const BMessenger
& source
, const char* name
)
218 return _UpdateEvent(B_UNREGISTER_LAUNCH_EVENT
, source
, name
);
223 BLaunchRoster::NotifyEvent(const BMessenger
& source
, const char* name
)
225 return _UpdateEvent(B_NOTIFY_LAUNCH_EVENT
, source
, name
);
230 BLaunchRoster::_InitMessenger()
232 // find the launch_daemon port
233 port_id daemonPort
= BPrivate::get_launch_daemon_port();
235 if (daemonPort
>= 0 && get_port_info(daemonPort
, &info
) == B_OK
) {
236 BMessenger::Private(fMessenger
).SetTo(info
.team
, daemonPort
,
243 BLaunchRoster::_UpdateEvent(uint32 what
, const BMessenger
& source
,
246 if (be_app
== NULL
|| name
== NULL
|| name
[0] == '\0')
249 BMessage
request(what
);
250 status_t status
= request
.AddInt32("user", getuid());
252 status
= request
.AddMessenger("source", source
);
254 status
= request
.AddString("owner", be_app
->Signature());
256 status
= request
.AddString("name", name
);
262 status
= fMessenger
.SendMessage(&request
, &result
);
264 // evaluate the reply
266 status
= result
.what
;