From 9d69dc097d9ed89ff288101868a60c07660a6841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 21 Apr 2015 18:44:24 +0200 Subject: [PATCH] libroot: added ability to communicate with the launch_daemon. * These methods don't really work yet, as BMessage doesn't support replying with a KMessage; the request is received, but the reply never gets to the target. --- headers/private/libroot/launch.h | 29 ++++++++++++++++++++ src/kits/app/Jamfile | 2 +- src/kits/app/LaunchRoster.cpp | 3 ++- src/system/libroot/os/Jamfile | 3 ++- src/system/libroot/os/launch.cpp | 45 ++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 headers/private/libroot/launch.h create mode 100644 src/system/libroot/os/launch.cpp diff --git a/headers/private/libroot/launch.h b/headers/private/libroot/launch.h new file mode 100644 index 0000000000..55122ef823 --- /dev/null +++ b/headers/private/libroot/launch.h @@ -0,0 +1,29 @@ +/* + * Copyright 2015, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _LIBROOT_LAUNCH_H +#define _LIBROOT_LAUNCH_H + + +#include +#include + + +#ifdef __cplusplus +namespace BPrivate { + + +class KMessage; + + +port_id get_launch_daemon_port(); +status_t send_request_to_launch_daemon(KMessage& request, KMessage& reply); +status_t get_launch_data(const char* signature, KMessage& data); + + +} // namespace BPrivate +#endif // __cplusplus + + +#endif // _LIBROOT_LAUNCH_H diff --git a/src/kits/app/Jamfile b/src/kits/app/Jamfile index 8de9740741..57cccffb49 100644 --- a/src/kits/app/Jamfile +++ b/src/kits/app/Jamfile @@ -18,7 +18,7 @@ if $(RUN_WITHOUT_APP_SERVER) != 0 { } UseLibraryHeaders icon ; -UsePrivateHeaders shared app interface kernel locale notification ; +UsePrivateHeaders shared app interface kernel libroot locale notification ; SetSubDirSupportedPlatforms haiku libbe_test ; diff --git a/src/kits/app/LaunchRoster.cpp b/src/kits/app/LaunchRoster.cpp index 20d3e3b411..bdb558c128 100644 --- a/src/kits/app/LaunchRoster.cpp +++ b/src/kits/app/LaunchRoster.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -107,7 +108,7 @@ void BLaunchRoster::_InitMessenger() { // find the launch_daemon port - port_id daemonPort = find_port(B_LAUNCH_DAEMON_PORT_NAME); + port_id daemonPort = BPrivate::get_launch_daemon_port(); port_info info; if (daemonPort >= 0 && get_port_info(daemonPort, &info) == B_OK) { BMessenger::Private(fMessenger).SetTo(info.team, daemonPort, diff --git a/src/system/libroot/os/Jamfile b/src/system/libroot/os/Jamfile index b27301252c..572f8921e7 100644 --- a/src/system/libroot/os/Jamfile +++ b/src/system/libroot/os/Jamfile @@ -2,7 +2,7 @@ SubDir HAIKU_TOP src system libroot os ; UsePrivateHeaders kernel ; # for util/KMessage.h -UsePrivateHeaders libroot runtime_loader shared ; +UsePrivateHeaders app libroot runtime_loader shared ; local architectureObject ; for architectureObject in [ MultiArchSubDirSetup ] { @@ -28,6 +28,7 @@ for architectureObject in [ MultiArchSubDirSetup ] { fs_query.cpp fs_volume.c image.cpp + launch.cpp memory.cpp parsedate.cpp port.c diff --git a/src/system/libroot/os/launch.cpp b/src/system/libroot/os/launch.cpp new file mode 100644 index 0000000000..d3812e1fd1 --- /dev/null +++ b/src/system/libroot/os/launch.cpp @@ -0,0 +1,45 @@ +/* + * Copyright 2015, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ + + +#include + +#include +#include + + +static port_id sLaunchDaemonPort = -1; + + +port_id +BPrivate::get_launch_daemon_port() +{ + if (sLaunchDaemonPort < 0) + sLaunchDaemonPort = find_port(B_LAUNCH_DAEMON_PORT_NAME); + + return sLaunchDaemonPort; +} + + +status_t +BPrivate::send_request_to_launch_daemon(KMessage& request, KMessage& reply) +{ + status_t status = request.SendTo(get_launch_daemon_port(), + B_PREFERRED_TOKEN, &reply); + if (status != B_OK) + return status; + + return (status_t)reply.What(); +} + + +status_t +BPrivate::get_launch_data(const char* signature, KMessage& data) +{ + BPrivate::KMessage request(B_GET_LAUNCH_DATA); + request.AddString("name", signature); + + return BPrivate::send_request_to_launch_daemon(request, data); +}