libsysprof-ui: add helper to check for sysprof-3 support

This commit is contained in:
Christian Hergert
2019-06-13 17:37:59 -07:00
parent a95287b2d2
commit 37960fc0c7
4 changed files with 146 additions and 0 deletions

View File

@ -5,6 +5,7 @@ libsysprof_ui_public_sources = [
'sysprof-capture-view.c',
'sysprof-callgraph-aid.c',
'sysprof-callgraph-view.c',
'sysprof-check.c',
'sysprof-color-cycle.c',
'sysprof-cpu-aid.c',
'sysprof-cpu-visualizer-row.c',
@ -56,6 +57,7 @@ libsysprof_ui_public_headers = [
'sysprof-callgraph-aid.h',
'sysprof-callgraph-view.h',
'sysprof-cell-renderer-percent.h',
'sysprof-check.h',
'sysprof-cpu-aid.h',
'sysprof-cpu-visualizer-row.h',
'sysprof-display.h',

View File

@ -0,0 +1,106 @@
/* sysprof-check.c
*
* Copyright 2019 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#define G_LOG_DOMAIN "sysprof-check"
#include "config.h"
#include "sysprof-check.h"
static void
sysprof_check_supported_ping_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
GDBusConnection *bus = (GDBusConnection *)object;
g_autoptr(GVariant) reply = NULL;
g_autoptr(GError) error = NULL;
g_autoptr(GTask) task = user_data;
g_assert (G_IS_DBUS_CONNECTION (bus));
g_assert (G_IS_ASYNC_RESULT (result));
g_assert (G_IS_TASK (task));
if (!(reply = g_dbus_connection_call_finish (bus, result, &error)))
g_task_return_error (task, g_steal_pointer (&error));
else
g_task_return_boolean (task, TRUE);
}
static void
sysprof_check_supported_bus_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
g_autoptr(GDBusConnection) bus = NULL;
g_autoptr(GError) error = NULL;
g_autoptr(GTask) task = user_data;
g_assert (G_IS_ASYNC_RESULT (result));
g_assert (G_IS_TASK (task));
if (!(bus = g_bus_get_finish (result, &error)))
g_task_return_error (task, g_steal_pointer (&error));
else
g_dbus_connection_call (bus,
"org.gnome.Sysprof3",
"/org/gnome/Sysprof3",
"org.freedesktop.DBus.Peer",
"Ping",
g_variant_new ("()"),
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
g_task_get_cancellable (task),
sysprof_check_supported_ping_cb,
g_object_ref (task));
}
void
sysprof_check_supported_async (GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_autoptr(GTask) task = NULL;
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
task = g_task_new (NULL, cancellable, callback, user_data);
g_task_set_source_tag (task, sysprof_check_supported_async);
/* Get access to the System D-Bus and check to see if we can ping the
* service that is found at org.gnome.Sysprof3.
*/
g_bus_get (G_BUS_TYPE_SYSTEM,
cancellable,
sysprof_check_supported_bus_cb,
g_steal_pointer (&task));
}
gboolean
sysprof_check_supported_finish (GAsyncResult *result,
GError **error)
{
g_return_val_if_fail (G_IS_TASK (result), FALSE);
return g_task_propagate_boolean (G_TASK (result), error);
}

View File

@ -0,0 +1,37 @@
/* sysprof-check.h
*
* Copyright 2019 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#pragma once
#include <gio/gio.h>
#include "sysprof-version-macros.h"
G_BEGIN_DECLS
SYSPROF_AVAILABLE_IN_ALL
void sysprof_check_supported_async (GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_check_supported_finish (GAsyncResult *result,
GError **error);
G_END_DECLS

View File

@ -32,6 +32,7 @@ G_BEGIN_DECLS
# include "sysprof-capture-view.h"
# include "sysprof-callgraph-aid.h"
# include "sysprof-cell-renderer-percent.h"
# include "sysprof-check.h"
# include "sysprof-cpu-aid.h"
# include "sysprof-cpu-visualizer-row.h"
# include "sysprof-display.h"