2008-03-05 20:00:28 +00:00
|
|
|
/*
|
|
|
|
|
* /net/reactivated/Fprint/Manager object implementation
|
|
|
|
|
* Copyright (C) 2008 Daniel Drake <dsd@gentoo.org>
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
* Copyright (C) 2020 Marco Trevisan <marco.trevisan@canonical.com>
|
2008-03-05 20:00:28 +00:00
|
|
|
*
|
|
|
|
|
* 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 2 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, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2008-11-03 15:00:31 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <stdlib.h>
|
2008-03-05 20:00:28 +00:00
|
|
|
#include <glib.h>
|
2008-05-14 18:25:40 +01:00
|
|
|
#include <glib/gi18n.h>
|
2019-07-30 19:45:50 +02:00
|
|
|
#include <fprint.h>
|
2008-03-05 20:00:28 +00:00
|
|
|
#include <glib-object.h>
|
|
|
|
|
|
|
|
|
|
#include "fprintd.h"
|
|
|
|
|
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
static void fprint_manager_constructed (GObject *object);
|
2008-03-05 20:00:28 +00:00
|
|
|
static gboolean fprint_manager_get_devices(FprintManager *manager,
|
|
|
|
|
GPtrArray **devices, GError **error);
|
2008-11-20 10:51:58 +00:00
|
|
|
static gboolean fprint_manager_get_default_device(FprintManager *manager,
|
|
|
|
|
const char **device, GError **error);
|
2008-05-14 01:03:14 +01:00
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
GDBusConnection *connection;
|
2020-11-05 13:03:04 +01:00
|
|
|
GDBusObjectManager *object_manager;
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
FprintDBusManager *dbus_manager;
|
2019-07-30 19:45:50 +02:00
|
|
|
FpContext *context;
|
2008-11-21 11:15:05 +00:00
|
|
|
gboolean no_timeout;
|
2008-11-03 15:00:31 +00:00
|
|
|
guint timeout_id;
|
2008-05-14 01:03:14 +01:00
|
|
|
} FprintManagerPrivate;
|
|
|
|
|
|
2020-01-14 14:00:39 +01:00
|
|
|
G_DEFINE_TYPE_WITH_CODE(FprintManager, fprint_manager, G_TYPE_OBJECT, G_ADD_PRIVATE (FprintManager))
|
2008-05-14 01:03:14 +01:00
|
|
|
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
|
|
|
|
FPRINT_MANAGER_CONNECTION,
|
|
|
|
|
N_PROPS
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static GParamSpec *properties[N_PROPS];
|
|
|
|
|
|
2008-05-14 01:03:14 +01:00
|
|
|
static void fprint_manager_finalize(GObject *object)
|
2008-03-05 20:00:28 +00:00
|
|
|
{
|
2020-01-14 14:00:39 +01:00
|
|
|
FprintManagerPrivate *priv = fprint_manager_get_instance_private (FPRINT_MANAGER (object));
|
2008-05-14 01:03:14 +01:00
|
|
|
|
2020-11-05 13:03:04 +01:00
|
|
|
g_clear_object (&priv->object_manager);
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
g_clear_object (&priv->dbus_manager);
|
|
|
|
|
g_clear_object (&priv->connection);
|
2019-07-30 19:45:50 +02:00
|
|
|
g_clear_object (&priv->context);
|
2008-05-14 01:03:14 +01:00
|
|
|
|
2020-01-28 18:30:32 +01:00
|
|
|
G_OBJECT_CLASS(fprint_manager_parent_class)->finalize(object);
|
2008-03-05 20:00:28 +00:00
|
|
|
}
|
|
|
|
|
|
2020-11-05 13:03:04 +01:00
|
|
|
static FprintDevice *
|
|
|
|
|
fprint_dbus_object_skeleton_get_device (FprintDBusObjectSkeleton *object) {
|
|
|
|
|
FprintDevice *rdev;
|
|
|
|
|
|
|
|
|
|
g_object_get (object, "device", &rdev, NULL);
|
|
|
|
|
return rdev;
|
|
|
|
|
}
|
|
|
|
|
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
static void fprint_manager_set_property (GObject *object, guint property_id,
|
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
FprintManager *self = FPRINT_MANAGER (object);
|
|
|
|
|
FprintManagerPrivate *priv = fprint_manager_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
|
case FPRINT_MANAGER_CONNECTION:
|
|
|
|
|
priv->connection = g_value_dup_object (value);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void fprint_manager_get_property (GObject *object, guint property_id,
|
|
|
|
|
GValue *value, GParamSpec *pspec)
|
2008-03-05 20:00:28 +00:00
|
|
|
{
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
FprintManager *self = FPRINT_MANAGER (object);
|
|
|
|
|
FprintManagerPrivate *priv = fprint_manager_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
|
case FPRINT_MANAGER_CONNECTION:
|
|
|
|
|
g_value_set_object (value, priv->connection);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-03-05 20:00:28 +00:00
|
|
|
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
static void fprint_manager_class_init(FprintManagerClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
|
|
object_class->constructed = fprint_manager_constructed;
|
|
|
|
|
object_class->set_property = fprint_manager_set_property;
|
|
|
|
|
object_class->get_property = fprint_manager_get_property;
|
|
|
|
|
object_class->finalize = fprint_manager_finalize;
|
|
|
|
|
|
|
|
|
|
properties[FPRINT_MANAGER_CONNECTION] =
|
|
|
|
|
g_param_spec_object ("connection",
|
|
|
|
|
"Connection",
|
|
|
|
|
"Set GDBus connection property",
|
|
|
|
|
G_TYPE_DBUS_CONNECTION,
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, N_PROPS, properties);
|
2008-03-05 20:00:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gchar *get_device_path(FprintDevice *rdev)
|
|
|
|
|
{
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
return g_strdup_printf (FPRINT_SERVICE_PATH "/Device/%d",
|
2008-03-05 20:00:28 +00:00
|
|
|
_fprint_device_get_id(rdev));
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-03 15:00:31 +00:00
|
|
|
static gboolean
|
|
|
|
|
fprint_manager_timeout_cb (FprintManager *manager)
|
|
|
|
|
{
|
|
|
|
|
//FIXME kill all the devices
|
|
|
|
|
exit(0);
|
2008-11-03 17:20:59 +00:00
|
|
|
return FALSE;
|
2008-11-03 15:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2008-11-03 17:20:59 +00:00
|
|
|
fprint_manager_in_use_notified (FprintDevice *rdev, GParamSpec *spec, FprintManager *manager)
|
2008-11-03 15:00:31 +00:00
|
|
|
{
|
2020-01-14 14:00:39 +01:00
|
|
|
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
|
2008-11-03 17:20:59 +00:00
|
|
|
guint num_devices_used = 0;
|
2020-11-05 13:03:04 +01:00
|
|
|
g_autolist(GDBusObject) devices = NULL;
|
|
|
|
|
GList *l;
|
2008-11-03 17:20:59 +00:00
|
|
|
gboolean in_use;
|
2008-11-03 15:00:31 +00:00
|
|
|
|
2008-11-22 00:27:45 +00:00
|
|
|
if (priv->timeout_id > 0) {
|
2008-11-03 15:00:31 +00:00
|
|
|
g_source_remove (priv->timeout_id);
|
|
|
|
|
priv->timeout_id = 0;
|
|
|
|
|
}
|
2008-11-26 13:55:15 +00:00
|
|
|
if (priv->no_timeout)
|
2008-11-21 22:56:49 +00:00
|
|
|
return;
|
2008-11-03 17:20:59 +00:00
|
|
|
|
2020-11-05 13:03:04 +01:00
|
|
|
devices = g_dbus_object_manager_get_objects (priv->object_manager);
|
|
|
|
|
|
|
|
|
|
for (l = devices; l != NULL; l = l->next) {
|
|
|
|
|
g_autoptr(FprintDevice) dev = NULL;
|
|
|
|
|
FprintDBusObjectSkeleton *object = l->data;
|
2008-11-03 17:20:59 +00:00
|
|
|
|
2020-11-05 13:03:04 +01:00
|
|
|
dev = fprint_dbus_object_skeleton_get_device (object);
|
2008-11-03 17:20:59 +00:00
|
|
|
g_object_get (G_OBJECT(dev), "in-use", &in_use, NULL);
|
|
|
|
|
if (in_use != FALSE)
|
|
|
|
|
num_devices_used++;
|
2008-11-03 15:00:31 +00:00
|
|
|
}
|
2008-11-03 17:20:59 +00:00
|
|
|
|
2008-11-22 00:27:45 +00:00
|
|
|
if (num_devices_used == 0)
|
2008-11-03 17:20:59 +00:00
|
|
|
priv->timeout_id = g_timeout_add_seconds (TIMEOUT, (GSourceFunc) fprint_manager_timeout_cb, manager);
|
2008-11-03 15:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
static gboolean
|
|
|
|
|
handle_get_devices (FprintManager *manager, GDBusMethodInvocation *invocation,
|
|
|
|
|
FprintDBusManager *skeleton)
|
|
|
|
|
{
|
|
|
|
|
g_autoptr(GPtrArray) devices = NULL;
|
|
|
|
|
g_autoptr(GError) error = NULL;
|
|
|
|
|
|
|
|
|
|
if (!fprint_manager_get_devices (manager, &devices, &error)) {
|
|
|
|
|
g_dbus_method_invocation_return_gerror (invocation, error);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprint_dbus_manager_complete_get_devices (skeleton, invocation,
|
|
|
|
|
(const gchar *const *)
|
|
|
|
|
devices->pdata);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
handle_get_default_device (FprintManager *manager,
|
|
|
|
|
GDBusMethodInvocation *invocation,
|
|
|
|
|
FprintDBusManager *skeleton)
|
|
|
|
|
{
|
|
|
|
|
const gchar *device;
|
|
|
|
|
g_autoptr(GError) error = NULL;
|
|
|
|
|
|
|
|
|
|
if (!fprint_manager_get_default_device (manager, &device, &error)) {
|
|
|
|
|
g_dbus_method_invocation_return_gerror (invocation, error);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprint_dbus_manager_complete_get_default_device (skeleton, invocation,
|
|
|
|
|
device);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-14 01:03:14 +01:00
|
|
|
static void
|
2019-07-30 19:45:50 +02:00
|
|
|
device_added_cb (FprintManager *manager, FpDevice *device, FpContext *context)
|
2008-03-05 20:00:28 +00:00
|
|
|
{
|
2020-01-14 14:00:39 +01:00
|
|
|
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
|
2020-11-05 13:03:04 +01:00
|
|
|
g_autoptr(FprintDBusObjectSkeleton) object = NULL;
|
2019-07-30 19:45:50 +02:00
|
|
|
FprintDevice *rdev = fprint_device_new(device);
|
|
|
|
|
g_autofree gchar *path = NULL;
|
2008-03-05 20:00:28 +00:00
|
|
|
|
2019-07-30 19:45:50 +02:00
|
|
|
g_signal_connect (G_OBJECT(rdev), "notify::in-use",
|
|
|
|
|
G_CALLBACK (fprint_manager_in_use_notified), manager);
|
2008-03-05 20:00:28 +00:00
|
|
|
|
2019-07-30 19:45:50 +02:00
|
|
|
path = get_device_path (rdev);
|
2020-11-05 13:03:04 +01:00
|
|
|
|
|
|
|
|
object = fprint_dbus_object_skeleton_new (path);
|
|
|
|
|
fprint_dbus_object_skeleton_set_device (object,
|
|
|
|
|
FPRINT_DBUS_DEVICE (rdev));
|
|
|
|
|
g_dbus_object_manager_server_export (
|
|
|
|
|
G_DBUS_OBJECT_MANAGER_SERVER (priv->object_manager),
|
|
|
|
|
G_DBUS_OBJECT_SKELETON (object));
|
2019-07-30 19:45:50 +02:00
|
|
|
}
|
2008-11-24 12:50:34 +00:00
|
|
|
|
2019-07-30 19:45:50 +02:00
|
|
|
static void
|
|
|
|
|
device_removed_cb (FprintManager *manager, FpDevice *device, FpContext *context)
|
|
|
|
|
{
|
2020-01-14 14:00:39 +01:00
|
|
|
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
|
2020-11-05 13:03:04 +01:00
|
|
|
g_autolist (FprintDBusObjectSkeleton) objects = NULL;
|
|
|
|
|
GList *item;
|
2008-03-05 20:00:28 +00:00
|
|
|
|
2020-11-05 13:03:04 +01:00
|
|
|
objects = g_dbus_object_manager_get_objects (priv->object_manager);
|
2008-11-03 15:00:31 +00:00
|
|
|
|
2020-11-05 13:03:04 +01:00
|
|
|
for (item = objects; item; item = item->next) {
|
|
|
|
|
g_autoptr(FprintDevice) rdev = NULL;
|
|
|
|
|
g_autoptr(FpDevice) dev = NULL;
|
|
|
|
|
FprintDBusObjectSkeleton *object = item->data;
|
2019-07-30 19:45:50 +02:00
|
|
|
|
2020-11-05 13:03:04 +01:00
|
|
|
rdev = fprint_dbus_object_skeleton_get_device (object);
|
2019-07-30 19:45:50 +02:00
|
|
|
g_object_get (rdev, "dev", &dev, NULL);
|
|
|
|
|
if (dev != device)
|
|
|
|
|
continue;
|
|
|
|
|
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
g_dbus_interface_skeleton_unexport (
|
|
|
|
|
G_DBUS_INTERFACE_SKELETON (rdev));
|
2019-07-30 19:45:50 +02:00
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_data (rdev, manager);
|
|
|
|
|
|
|
|
|
|
/* We cannot continue to iterate at this point, but we don't need to either */
|
|
|
|
|
break;
|
2008-03-05 20:00:28 +00:00
|
|
|
}
|
2019-07-30 19:45:50 +02:00
|
|
|
|
|
|
|
|
/* The device that disappeared might have been in-use.
|
|
|
|
|
* Do we need to do anything else in this case to clean up more gracefully? */
|
|
|
|
|
fprint_manager_in_use_notified (NULL, NULL, manager);
|
|
|
|
|
}
|
|
|
|
|
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
static void fprint_manager_constructed (GObject *object)
|
2019-07-30 19:45:50 +02:00
|
|
|
{
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
FprintManager *manager = FPRINT_MANAGER (object);
|
2020-01-14 14:00:39 +01:00
|
|
|
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
|
2020-11-05 13:03:04 +01:00
|
|
|
GDBusObjectManagerServer *object_manager_server;
|
|
|
|
|
|
|
|
|
|
object_manager_server =
|
|
|
|
|
g_dbus_object_manager_server_new (FPRINT_SERVICE_PATH "/Device");
|
2019-07-30 19:45:50 +02:00
|
|
|
|
2020-11-05 13:03:04 +01:00
|
|
|
priv->object_manager = G_DBUS_OBJECT_MANAGER (object_manager_server);
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
priv->dbus_manager = fprint_dbus_manager_skeleton_new ();
|
2019-07-30 19:45:50 +02:00
|
|
|
priv->context = fp_context_new ();
|
|
|
|
|
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
g_signal_connect_object (priv->dbus_manager,
|
|
|
|
|
"handle-get-devices",
|
|
|
|
|
G_CALLBACK (handle_get_devices),
|
|
|
|
|
manager,
|
|
|
|
|
G_CONNECT_SWAPPED);
|
|
|
|
|
g_signal_connect_object (priv->dbus_manager,
|
|
|
|
|
"handle-get-default-device",
|
|
|
|
|
G_CALLBACK (handle_get_default_device),
|
|
|
|
|
manager,
|
|
|
|
|
G_CONNECT_SWAPPED);
|
|
|
|
|
|
|
|
|
|
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->dbus_manager),
|
|
|
|
|
priv->connection,
|
|
|
|
|
FPRINT_SERVICE_PATH "/Manager", NULL);
|
|
|
|
|
|
2020-11-05 13:03:04 +01:00
|
|
|
g_dbus_object_manager_server_set_connection (object_manager_server,
|
|
|
|
|
priv->connection);
|
|
|
|
|
|
2019-07-30 19:45:50 +02:00
|
|
|
/* And register the signals for initial enumeration and hotplug. */
|
|
|
|
|
g_signal_connect_object (priv->context,
|
|
|
|
|
"device-added",
|
|
|
|
|
(GCallback) device_added_cb,
|
|
|
|
|
manager,
|
|
|
|
|
G_CONNECT_SWAPPED);
|
|
|
|
|
|
|
|
|
|
g_signal_connect_object (priv->context,
|
|
|
|
|
"device-removed",
|
|
|
|
|
(GCallback) device_removed_cb,
|
|
|
|
|
manager,
|
|
|
|
|
G_CONNECT_SWAPPED);
|
|
|
|
|
|
2020-02-03 20:39:44 +01:00
|
|
|
/* Prepare everything by enumerating all devices.
|
|
|
|
|
* This blocks the main loop until the existing devices are enumerated
|
|
|
|
|
*/
|
2019-07-30 19:45:50 +02:00
|
|
|
fp_context_enumerate (priv->context);
|
|
|
|
|
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
G_OBJECT_CLASS (fprint_manager_parent_class)->constructed (object);
|
2008-05-14 01:03:14 +01:00
|
|
|
}
|
|
|
|
|
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
static void
|
|
|
|
|
fprint_manager_init (FprintManager *manager)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FprintManager *fprint_manager_new (GDBusConnection *connection, gboolean no_timeout)
|
2008-05-14 01:03:14 +01:00
|
|
|
{
|
2008-11-21 11:15:05 +00:00
|
|
|
FprintManagerPrivate *priv;
|
|
|
|
|
GObject *object;
|
|
|
|
|
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
object = g_object_new (FPRINT_TYPE_MANAGER, "connection", connection, NULL);
|
2020-01-14 14:00:39 +01:00
|
|
|
priv = fprint_manager_get_instance_private (FPRINT_MANAGER (object));
|
2008-11-21 11:15:05 +00:00
|
|
|
priv->no_timeout = no_timeout;
|
|
|
|
|
|
2008-11-21 22:56:49 +00:00
|
|
|
if (!priv->no_timeout)
|
|
|
|
|
priv->timeout_id = g_timeout_add_seconds (TIMEOUT, (GSourceFunc) fprint_manager_timeout_cb, object);
|
|
|
|
|
|
2008-11-21 11:15:05 +00:00
|
|
|
return FPRINT_MANAGER (object);
|
2008-05-14 01:03:14 +01:00
|
|
|
}
|
|
|
|
|
|
2008-03-05 20:00:28 +00:00
|
|
|
static gboolean fprint_manager_get_devices(FprintManager *manager,
|
|
|
|
|
GPtrArray **devices, GError **error)
|
|
|
|
|
{
|
2020-01-14 14:00:39 +01:00
|
|
|
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
|
2020-11-05 13:03:04 +01:00
|
|
|
g_autolist (FprintDBusObjectSkeleton) objects = NULL;
|
|
|
|
|
GList *l;
|
2019-07-30 19:45:50 +02:00
|
|
|
int num_open;
|
|
|
|
|
GPtrArray *devs;
|
|
|
|
|
|
2020-11-05 13:03:04 +01:00
|
|
|
objects = g_dbus_object_manager_get_objects (priv->object_manager);
|
|
|
|
|
objects = g_list_reverse (objects);
|
|
|
|
|
|
|
|
|
|
num_open = g_list_length (objects);
|
2019-07-30 19:45:50 +02:00
|
|
|
devs = g_ptr_array_sized_new(num_open);
|
2008-03-05 20:00:28 +00:00
|
|
|
|
2015-02-03 16:55:48 +01:00
|
|
|
if (num_open > 0) {
|
2020-11-05 13:03:04 +01:00
|
|
|
for (l = objects; l != NULL; l = l->next) {
|
|
|
|
|
g_autoptr(FprintDevice) rdev = NULL;
|
|
|
|
|
FprintDBusObjectSkeleton *object = l->data;
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
const char *path;
|
|
|
|
|
|
2020-11-05 13:03:04 +01:00
|
|
|
rdev = fprint_dbus_object_skeleton_get_device (object);
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
path = g_dbus_interface_skeleton_get_object_path (
|
2020-11-05 13:03:04 +01:00
|
|
|
G_DBUS_INTERFACE_SKELETON (rdev));
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
g_ptr_array_add (devs, (char *) path);
|
2015-02-03 16:55:48 +01:00
|
|
|
}
|
|
|
|
|
}
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
g_ptr_array_add (devs, NULL);
|
2015-02-03 16:55:48 +01:00
|
|
|
|
2008-03-05 20:00:28 +00:00
|
|
|
*devices = devs;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-20 10:51:58 +00:00
|
|
|
static gboolean fprint_manager_get_default_device(FprintManager *manager,
|
|
|
|
|
const char **device, GError **error)
|
|
|
|
|
{
|
2020-01-14 14:00:39 +01:00
|
|
|
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
|
2020-11-05 13:03:04 +01:00
|
|
|
g_autolist (FprintDBusObjectSkeleton) objects = NULL;
|
2019-07-30 19:45:50 +02:00
|
|
|
int num_open;
|
|
|
|
|
|
2020-11-05 13:03:04 +01:00
|
|
|
objects = g_dbus_object_manager_get_objects (priv->object_manager);
|
|
|
|
|
num_open = g_list_length (objects);
|
2008-11-20 10:51:58 +00:00
|
|
|
|
|
|
|
|
if (num_open > 0) {
|
2020-11-05 13:03:04 +01:00
|
|
|
g_autoptr(FprintDevice) rdev = NULL;
|
|
|
|
|
FprintDBusObjectSkeleton *object = g_list_last (objects)->data;
|
|
|
|
|
|
|
|
|
|
rdev = fprint_dbus_object_skeleton_get_device (object);
|
|
|
|
|
*device = g_dbus_interface_skeleton_get_object_path (
|
|
|
|
|
G_DBUS_INTERFACE_SKELETON (rdev));
|
2008-11-20 10:51:58 +00:00
|
|
|
return TRUE;
|
|
|
|
|
} else {
|
2008-11-24 18:23:30 +00:00
|
|
|
g_set_error (error, FPRINT_ERROR, FPRINT_ERROR_NO_SUCH_DEVICE,
|
|
|
|
|
"No devices available");
|
2008-11-20 10:51:58 +00:00
|
|
|
*device = NULL;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-11-21 11:15:05 +00:00
|
|
|
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
GQuark fprint_error_quark (void)
|
2008-11-24 12:33:20 +00:00
|
|
|
{
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
static volatile gsize quark = 0;
|
2020-11-06 19:19:24 +01:00
|
|
|
if (g_once_init_enter (&quark)) {
|
|
|
|
|
g_autoptr(GEnumClass) errors_enum = NULL;
|
|
|
|
|
GQuark domain;
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
domain = g_quark_from_static_string ("fprintd-error-quark");
|
|
|
|
|
errors_enum = g_type_class_ref (FPRINT_TYPE_ERROR);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < errors_enum->n_values; ++i) {
|
|
|
|
|
GEnumValue *value = &errors_enum->values[i];
|
|
|
|
|
|
|
|
|
|
g_dbus_error_register_error (domain, value->value,
|
|
|
|
|
value->value_nick);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_once_init_leave (&quark, domain);
|
2008-11-24 12:33:20 +00:00
|
|
|
}
|
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.
So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.
Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.
Fixes: #61
2020-02-03 20:29:56 +01:00
|
|
|
return (GQuark) quark;
|
2008-11-24 12:33:20 +00:00
|
|
|
}
|