mirror of
https://gitlab.com/mishakmak/pam-fprint-grosshack.git
synced 2026-04-09 04:13:33 +02:00
Clean up object creation code
Make all of FPrintManager's struct members private, warn of errors using a _get_error() function, as object creation can never fail. The only error possible shouldn't really be an error though, as it only means that no devices will be enumerated, but it could tell us about newly plugged devices instead.
This commit is contained in:
committed by
Daniel Drake
parent
3ad569b66a
commit
017f770480
@ -31,41 +31,37 @@ static gboolean fprint_manager_get_devices(FprintManager *manager,
|
||||
|
||||
static GObjectClass *parent_class = NULL;
|
||||
|
||||
static void manager_finalize(GObject *object)
|
||||
G_DEFINE_TYPE(FprintManager, fprint_manager, G_TYPE_OBJECT);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FprintManager *self = (FprintManager *) object;
|
||||
g_slist_free(self->dev_registry);
|
||||
GError *last_error;
|
||||
GSList *dev_registry;
|
||||
} FprintManagerPrivate;
|
||||
|
||||
#define FPRINT_MANAGER_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((o), FPRINT_TYPE_MANAGER, FprintManagerPrivate))
|
||||
|
||||
static void fprint_manager_finalize(GObject *object)
|
||||
{
|
||||
FprintManagerPrivate *priv = FPRINT_MANAGER_GET_PRIVATE (object);
|
||||
|
||||
g_slist_free(priv->dev_registry);
|
||||
if (priv->last_error)
|
||||
g_error_free (priv->last_error);
|
||||
|
||||
G_OBJECT_CLASS(parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static void manager_class_init(FprintManagerClass *klass)
|
||||
static void fprint_manager_class_init(FprintManagerClass *klass)
|
||||
{
|
||||
dbus_g_object_type_install_info(FPRINT_TYPE_MANAGER,
|
||||
&dbus_glib_fprint_manager_object_info);
|
||||
|
||||
G_OBJECT_CLASS(klass)->finalize = manager_finalize;
|
||||
parent_class = g_type_class_peek_parent(klass);
|
||||
}
|
||||
g_type_class_add_private ((GObjectClass *) klass, sizeof (FprintManagerPrivate));
|
||||
|
||||
GType fprint_manager_get_type(void)
|
||||
{
|
||||
static GType type = 0;
|
||||
if (type == 0) {
|
||||
static const GTypeInfo info = {
|
||||
sizeof(FprintManagerClass),
|
||||
NULL, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
(GClassInitFunc) manager_class_init,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof(FprintManager),
|
||||
0, /* n_preallocs */
|
||||
NULL,
|
||||
};
|
||||
type = g_type_register_static(G_TYPE_OBJECT, "FprintManagerType",
|
||||
&info, 0);
|
||||
}
|
||||
return type;
|
||||
G_OBJECT_CLASS(klass)->finalize = fprint_manager_finalize;
|
||||
parent_class = g_type_class_peek_parent(klass);
|
||||
}
|
||||
|
||||
static gchar *get_device_path(FprintDevice *rdev)
|
||||
@ -74,20 +70,19 @@ static gchar *get_device_path(FprintDevice *rdev)
|
||||
_fprint_device_get_id(rdev));
|
||||
}
|
||||
|
||||
FprintManager *fprint_manager_new(void)
|
||||
static void
|
||||
fprint_manager_init (FprintManager *manager)
|
||||
{
|
||||
FprintManager *manager;
|
||||
FprintManagerPrivate *priv = FPRINT_MANAGER_GET_PRIVATE (manager);
|
||||
struct fp_dscv_dev **discovered_devs = fp_discover_devs();
|
||||
struct fp_dscv_dev *ddev;
|
||||
int i = 0;
|
||||
|
||||
/* FIXME some or all of this should probably be moved into FprintManager
|
||||
* ctor. however i'm not sure how to raise errors from a constructor... */
|
||||
if (!discovered_devs) {
|
||||
priv->last_error = g_error_new (0, 0, "NO DEVICES AVAILABLE: FIXME");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!discovered_devs)
|
||||
return NULL;
|
||||
|
||||
manager = g_object_new(FPRINT_TYPE_MANAGER, NULL);
|
||||
dbus_g_connection_register_g_object(fprintd_dbus_conn,
|
||||
"/net/reactivated/Fprint/Manager", G_OBJECT(manager));
|
||||
|
||||
@ -95,20 +90,31 @@ FprintManager *fprint_manager_new(void)
|
||||
FprintDevice *rdev = fprint_device_new(ddev);
|
||||
gchar *path;
|
||||
|
||||
manager->dev_registry = g_slist_prepend(manager->dev_registry, rdev);
|
||||
priv->dev_registry = g_slist_prepend(priv->dev_registry, rdev);
|
||||
path = get_device_path(rdev);
|
||||
dbus_g_connection_register_g_object(fprintd_dbus_conn, path,
|
||||
G_OBJECT(rdev));
|
||||
g_free(path);
|
||||
}
|
||||
}
|
||||
|
||||
return manager;
|
||||
FprintManager *fprint_manager_new(void)
|
||||
{
|
||||
return g_object_new(FPRINT_TYPE_MANAGER, NULL);
|
||||
}
|
||||
|
||||
GError *fprint_manager_get_error(FprintManager *manager)
|
||||
{
|
||||
FprintManagerPrivate *priv = FPRINT_MANAGER_GET_PRIVATE (manager);
|
||||
|
||||
return g_error_copy (priv->last_error);
|
||||
}
|
||||
|
||||
static gboolean fprint_manager_get_devices(FprintManager *manager,
|
||||
GPtrArray **devices, GError **error)
|
||||
{
|
||||
GSList *elem = manager->dev_registry;
|
||||
FprintManagerPrivate *priv = FPRINT_MANAGER_GET_PRIVATE (manager);
|
||||
GSList *elem = priv->dev_registry;
|
||||
int num_open = g_slist_length(elem);
|
||||
GPtrArray *devs = g_ptr_array_sized_new(num_open);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user