mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
sysprofd: implement org.gnome.Sysprof2 compatability API
This allows the new sysprofd to service requests for older clients expecting to talk to or.gnome.Sysprof2.
This commit is contained in:
@ -25,17 +25,21 @@
|
||||
#include <gio/gio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ipc-legacy.h"
|
||||
#include "ipc-service.h"
|
||||
|
||||
#include "ipc-legacy-impl.h"
|
||||
#include "ipc-service-impl.h"
|
||||
|
||||
#define BUS_NAME "org.gnome.Sysprof3"
|
||||
#define OBJECT_PATH "/org/gnome/Sysprof3"
|
||||
#define V2_PATH "/org/gnome/Sysprof2"
|
||||
#define V3_PATH "/org/gnome/Sysprof3"
|
||||
#define NAME_ACQUIRE_DELAY_SECS 3
|
||||
#define INACTIVITY_TIMEOUT_SECS 120
|
||||
|
||||
static GMainLoop *main_loop;
|
||||
static gboolean name_acquired;
|
||||
static gint exit_status = EXIT_SUCCESS;
|
||||
static const gchar *bus_names[] = { "org.gnome.Sysprof3", "org.gnome.Sysprof2" };
|
||||
static GMainLoop *main_loop;
|
||||
static gboolean name_acquired;
|
||||
static gint exit_status = EXIT_SUCCESS;
|
||||
|
||||
static guint inactivity;
|
||||
static G_LOCK_DEFINE (activity);
|
||||
@ -49,8 +53,8 @@ inactivity_cb (gpointer data)
|
||||
}
|
||||
|
||||
static void
|
||||
activity_cb (IpcService *service,
|
||||
gpointer user_data)
|
||||
activity_cb (GObject *object,
|
||||
gpointer user_data)
|
||||
{
|
||||
G_LOCK (activity);
|
||||
if (inactivity)
|
||||
@ -75,23 +79,28 @@ name_lost_cb (GDBusConnection *connection,
|
||||
const gchar *name,
|
||||
gpointer user_data)
|
||||
{
|
||||
/* Exit if we lost the name */
|
||||
if (g_strcmp0 (name, BUS_NAME) == 0)
|
||||
/* Exit if we lost one of our bus names */
|
||||
for (guint i = 0; i < G_N_ELEMENTS (bus_names); i++)
|
||||
{
|
||||
g_message ("Lost Bus Name: %s, exiting.", name);
|
||||
name_acquired = FALSE;
|
||||
g_main_loop_quit (main_loop);
|
||||
if (g_strcmp0 (name, bus_names[i]) == 0)
|
||||
{
|
||||
g_message ("Lost Bus Name: %s, exiting.", bus_names[i]);
|
||||
name_acquired = FALSE;
|
||||
g_main_loop_quit (main_loop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
wait_for_acquire_timeout_cb (gpointer data)
|
||||
{
|
||||
const gchar *bus_name = data;
|
||||
|
||||
if (!name_acquired)
|
||||
{
|
||||
exit_status = EXIT_FAILURE;
|
||||
g_critical ("Failed to acquire name on bus after %d seconds, exiting.",
|
||||
NAME_ACQUIRE_DELAY_SECS);
|
||||
g_critical ("Failed to acquire %s on bus after %d seconds, exiting.",
|
||||
bus_name, NAME_ACQUIRE_DELAY_SECS);
|
||||
g_main_loop_quit (main_loop);
|
||||
}
|
||||
|
||||
@ -113,31 +122,34 @@ main (gint argc,
|
||||
|
||||
if ((bus = g_bus_get_sync (bus_type, NULL, &error)))
|
||||
{
|
||||
g_autoptr(IpcService) service = ipc_service_impl_new ();
|
||||
g_autoptr(IpcLegacySysprof2) v2_service = ipc_legacy_impl_new ();
|
||||
g_autoptr(IpcService) v3_service = ipc_service_impl_new ();
|
||||
|
||||
g_signal_connect (service,
|
||||
"activity",
|
||||
G_CALLBACK (activity_cb),
|
||||
NULL);
|
||||
g_signal_connect (v3_service, "activity", G_CALLBACK (activity_cb), NULL);
|
||||
g_signal_connect (v2_service, "activity", G_CALLBACK (activity_cb), NULL);
|
||||
|
||||
activity_cb (service, NULL);
|
||||
activity_cb (NULL, NULL);
|
||||
|
||||
if (g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (service),
|
||||
bus,
|
||||
OBJECT_PATH,
|
||||
&error))
|
||||
if (g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (v3_service), bus, V3_PATH, &error) &&
|
||||
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (v2_service), bus, V2_PATH, &error))
|
||||
{
|
||||
g_bus_own_name_on_connection (bus,
|
||||
BUS_NAME,
|
||||
(G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
|
||||
G_BUS_NAME_OWNER_FLAGS_REPLACE),
|
||||
name_acquired_cb,
|
||||
name_lost_cb,
|
||||
NULL,
|
||||
NULL);
|
||||
g_timeout_add_seconds (NAME_ACQUIRE_DELAY_SECS,
|
||||
wait_for_acquire_timeout_cb,
|
||||
NULL);
|
||||
for (guint i = 0; i < G_N_ELEMENTS (bus_names); i++)
|
||||
{
|
||||
g_bus_own_name_on_connection (bus,
|
||||
bus_names[i],
|
||||
(G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
|
||||
G_BUS_NAME_OWNER_FLAGS_REPLACE),
|
||||
name_acquired_cb,
|
||||
name_lost_cb,
|
||||
NULL,
|
||||
NULL);
|
||||
g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
|
||||
NAME_ACQUIRE_DELAY_SECS,
|
||||
wait_for_acquire_timeout_cb,
|
||||
g_strdup (bus_names[i]),
|
||||
g_free);
|
||||
}
|
||||
|
||||
g_main_loop_run (main_loop);
|
||||
g_main_loop_unref (main_loop);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user