kerneldevice: no need to subclass the type getters
We can just subclass the methods to check whether a given property exists and to get it as a string, and then implement in the generic class the actual boolean/int/hex type getters common for all.
This commit is contained in:
@@ -831,38 +831,6 @@ kernel_device_get_property (MMKernelDevice *self,
|
||||
return g_object_get_data (G_OBJECT (self), property);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
kernel_device_get_property_as_boolean (MMKernelDevice *self,
|
||||
const gchar *property)
|
||||
{
|
||||
const gchar *value;
|
||||
|
||||
value = g_object_get_data (G_OBJECT (self), property);
|
||||
return (value && mm_common_get_boolean_from_string (value, NULL));
|
||||
}
|
||||
|
||||
static gint
|
||||
kernel_device_get_property_as_int (MMKernelDevice *self,
|
||||
const gchar *property)
|
||||
{
|
||||
const gchar *value;
|
||||
gint aux = 0;
|
||||
|
||||
value = g_object_get_data (G_OBJECT (self), property);
|
||||
return ((value && mm_get_int_from_str (value, &aux)) ? aux : 0);
|
||||
}
|
||||
|
||||
static guint
|
||||
kernel_device_get_property_as_int_hex (MMKernelDevice *self,
|
||||
const gchar *property)
|
||||
{
|
||||
const gchar *value;
|
||||
guint aux = 0;
|
||||
|
||||
value = g_object_get_data (G_OBJECT (self), property);
|
||||
return ((value && mm_get_uint_from_hex_str (value, &aux)) ? aux : 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
MMKernelDevice *
|
||||
@@ -1047,16 +1015,10 @@ mm_kernel_device_generic_class_init (MMKernelDeviceGenericClass *klass)
|
||||
kernel_device_class->cmp = kernel_device_cmp;
|
||||
kernel_device_class->has_property = kernel_device_has_property;
|
||||
kernel_device_class->get_property = kernel_device_get_property;
|
||||
kernel_device_class->get_property_as_boolean = kernel_device_get_property_as_boolean;
|
||||
kernel_device_class->get_property_as_int = kernel_device_get_property_as_int;
|
||||
kernel_device_class->get_property_as_int_hex = kernel_device_get_property_as_int_hex;
|
||||
|
||||
/* Device-wide properties are stored per-port in the generic backend */
|
||||
kernel_device_class->has_global_property = kernel_device_has_property;
|
||||
kernel_device_class->get_global_property = kernel_device_get_property;
|
||||
kernel_device_class->get_global_property_as_boolean = kernel_device_get_property_as_boolean;
|
||||
kernel_device_class->get_global_property_as_int = kernel_device_get_property_as_int;
|
||||
kernel_device_class->get_global_property_as_int_hex = kernel_device_get_property_as_int_hex;
|
||||
kernel_device_class->has_global_property = kernel_device_has_property;
|
||||
kernel_device_class->get_global_property = kernel_device_get_property;
|
||||
|
||||
properties[PROP_PROPERTIES] =
|
||||
g_param_spec_object ("properties",
|
||||
|
||||
@@ -598,51 +598,6 @@ kernel_device_get_property (MMKernelDevice *_self,
|
||||
return g_udev_device_get_property (self->priv->device, property);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
kernel_device_get_property_as_boolean (MMKernelDevice *_self,
|
||||
const gchar *property)
|
||||
{
|
||||
MMKernelDeviceUdev *self;
|
||||
|
||||
self = MM_KERNEL_DEVICE_UDEV (_self);
|
||||
|
||||
if (!self->priv->device)
|
||||
return FALSE;
|
||||
|
||||
return g_udev_device_get_property_as_boolean (self->priv->device, property);
|
||||
}
|
||||
|
||||
static gint
|
||||
kernel_device_get_property_as_int (MMKernelDevice *_self,
|
||||
const gchar *property)
|
||||
{
|
||||
MMKernelDeviceUdev *self;
|
||||
|
||||
self = MM_KERNEL_DEVICE_UDEV (_self);
|
||||
|
||||
if (!self->priv->device)
|
||||
return -1;
|
||||
|
||||
return g_udev_device_get_property_as_int (self->priv->device, property);
|
||||
}
|
||||
|
||||
static guint
|
||||
kernel_device_get_property_as_int_hex (MMKernelDevice *_self,
|
||||
const gchar *property)
|
||||
{
|
||||
MMKernelDeviceUdev *self;
|
||||
const gchar *s;
|
||||
guint out = 0;
|
||||
|
||||
self = MM_KERNEL_DEVICE_UDEV (_self);
|
||||
|
||||
if (!self->priv->device)
|
||||
return G_MAXUINT;
|
||||
|
||||
s = g_udev_device_get_property (self->priv->device, property);
|
||||
return ((s && mm_get_uint_from_hex_str (s, &out)) ? out : 0);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
kernel_device_has_global_property (MMKernelDevice *_self,
|
||||
const gchar *property)
|
||||
@@ -676,59 +631,6 @@ kernel_device_get_global_property (MMKernelDevice *_self,
|
||||
return kernel_device_get_property (_self, property);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
kernel_device_get_global_property_as_boolean (MMKernelDevice *_self,
|
||||
const gchar *property)
|
||||
{
|
||||
MMKernelDeviceUdev *self;
|
||||
|
||||
self = MM_KERNEL_DEVICE_UDEV (_self);
|
||||
|
||||
ensure_physdev (self);
|
||||
if (self->priv->physdev &&
|
||||
g_udev_device_has_property (self->priv->physdev, property) &&
|
||||
g_udev_device_get_property (self->priv->physdev, property))
|
||||
return TRUE;
|
||||
|
||||
return kernel_device_get_property_as_boolean (_self, property);
|
||||
}
|
||||
|
||||
static gint
|
||||
kernel_device_get_global_property_as_int (MMKernelDevice *_self,
|
||||
const gchar *property)
|
||||
{
|
||||
MMKernelDeviceUdev *self;
|
||||
gint value;
|
||||
|
||||
self = MM_KERNEL_DEVICE_UDEV (_self);
|
||||
|
||||
ensure_physdev (self);
|
||||
if (self->priv->physdev &&
|
||||
g_udev_device_has_property (self->priv->physdev, property) &&
|
||||
(value = g_udev_device_get_property_as_int (self->priv->physdev, property)) >= 0)
|
||||
return value;
|
||||
|
||||
return kernel_device_get_property_as_int (_self, property);
|
||||
}
|
||||
|
||||
static guint
|
||||
kernel_device_get_global_property_as_int_hex (MMKernelDevice *_self,
|
||||
const gchar *property)
|
||||
{
|
||||
MMKernelDeviceUdev *self;
|
||||
const gchar *s;
|
||||
guint out = 0;
|
||||
|
||||
self = MM_KERNEL_DEVICE_UDEV (_self);
|
||||
|
||||
ensure_physdev (self);
|
||||
if (self->priv->physdev &&
|
||||
g_udev_device_has_property (self->priv->physdev, property) &&
|
||||
(s = g_udev_device_get_property (self->priv->physdev, property)) != NULL)
|
||||
return ((s && mm_get_uint_from_hex_str (s, &out)) ? out : 0);
|
||||
|
||||
return kernel_device_get_property_as_int_hex (_self, property);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -903,34 +805,28 @@ mm_kernel_device_udev_class_init (MMKernelDeviceUdevClass *klass)
|
||||
object_class->get_property = get_property;
|
||||
object_class->set_property = set_property;
|
||||
|
||||
kernel_device_class->get_subsystem = kernel_device_get_subsystem;
|
||||
kernel_device_class->get_name = kernel_device_get_name;
|
||||
kernel_device_class->get_driver = kernel_device_get_driver;
|
||||
kernel_device_class->get_sysfs_path = kernel_device_get_sysfs_path;
|
||||
kernel_device_class->get_physdev_uid = kernel_device_get_physdev_uid;
|
||||
kernel_device_class->get_physdev_vid = kernel_device_get_physdev_vid;
|
||||
kernel_device_class->get_physdev_pid = kernel_device_get_physdev_pid;
|
||||
kernel_device_class->get_physdev_revision = kernel_device_get_physdev_revision;
|
||||
kernel_device_class->get_physdev_sysfs_path = kernel_device_get_physdev_sysfs_path;
|
||||
kernel_device_class->get_physdev_subsystem = kernel_device_get_physdev_subsystem;
|
||||
kernel_device_class->get_physdev_manufacturer = kernel_device_get_physdev_manufacturer;
|
||||
kernel_device_class->get_physdev_product = kernel_device_get_physdev_product;
|
||||
kernel_device_class->get_interface_class = kernel_device_get_interface_class;
|
||||
kernel_device_class->get_interface_subclass = kernel_device_get_interface_subclass;
|
||||
kernel_device_class->get_interface_protocol = kernel_device_get_interface_protocol;
|
||||
kernel_device_class->get_interface_sysfs_path = kernel_device_get_interface_sysfs_path;
|
||||
kernel_device_class->get_interface_description = kernel_device_get_interface_description;
|
||||
kernel_device_class->cmp = kernel_device_cmp;
|
||||
kernel_device_class->has_property = kernel_device_has_property;
|
||||
kernel_device_class->get_property = kernel_device_get_property;
|
||||
kernel_device_class->get_property_as_boolean = kernel_device_get_property_as_boolean;
|
||||
kernel_device_class->get_property_as_int = kernel_device_get_property_as_int;
|
||||
kernel_device_class->get_property_as_int_hex = kernel_device_get_property_as_int_hex;
|
||||
kernel_device_class->has_global_property = kernel_device_has_global_property;
|
||||
kernel_device_class->get_global_property = kernel_device_get_global_property;
|
||||
kernel_device_class->get_global_property_as_boolean = kernel_device_get_global_property_as_boolean;
|
||||
kernel_device_class->get_global_property_as_int = kernel_device_get_global_property_as_int;
|
||||
kernel_device_class->get_global_property_as_int_hex = kernel_device_get_global_property_as_int_hex;
|
||||
kernel_device_class->get_subsystem = kernel_device_get_subsystem;
|
||||
kernel_device_class->get_name = kernel_device_get_name;
|
||||
kernel_device_class->get_driver = kernel_device_get_driver;
|
||||
kernel_device_class->get_sysfs_path = kernel_device_get_sysfs_path;
|
||||
kernel_device_class->get_physdev_uid = kernel_device_get_physdev_uid;
|
||||
kernel_device_class->get_physdev_vid = kernel_device_get_physdev_vid;
|
||||
kernel_device_class->get_physdev_pid = kernel_device_get_physdev_pid;
|
||||
kernel_device_class->get_physdev_revision = kernel_device_get_physdev_revision;
|
||||
kernel_device_class->get_physdev_sysfs_path = kernel_device_get_physdev_sysfs_path;
|
||||
kernel_device_class->get_physdev_subsystem = kernel_device_get_physdev_subsystem;
|
||||
kernel_device_class->get_physdev_manufacturer = kernel_device_get_physdev_manufacturer;
|
||||
kernel_device_class->get_physdev_product = kernel_device_get_physdev_product;
|
||||
kernel_device_class->get_interface_class = kernel_device_get_interface_class;
|
||||
kernel_device_class->get_interface_subclass = kernel_device_get_interface_subclass;
|
||||
kernel_device_class->get_interface_protocol = kernel_device_get_interface_protocol;
|
||||
kernel_device_class->get_interface_sysfs_path = kernel_device_get_interface_sysfs_path;
|
||||
kernel_device_class->get_interface_description = kernel_device_get_interface_description;
|
||||
kernel_device_class->cmp = kernel_device_cmp;
|
||||
kernel_device_class->has_property = kernel_device_has_property;
|
||||
kernel_device_class->get_property = kernel_device_get_property;
|
||||
kernel_device_class->has_global_property = kernel_device_has_global_property;
|
||||
kernel_device_class->get_global_property = kernel_device_get_global_property;
|
||||
|
||||
properties[PROP_UDEV_DEVICE] =
|
||||
g_param_spec_object ("udev-device",
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
#include <config.h>
|
||||
#include <string.h>
|
||||
|
||||
#define _LIBMM_INSIDE_MM
|
||||
#include <libmm-glib.h>
|
||||
|
||||
#include "mm-kernel-device.h"
|
||||
#include "mm-log-object.h"
|
||||
|
||||
@@ -196,27 +199,32 @@ gboolean
|
||||
mm_kernel_device_get_property_as_boolean (MMKernelDevice *self,
|
||||
const gchar *property)
|
||||
{
|
||||
return (MM_KERNEL_DEVICE_GET_CLASS (self)->get_property_as_boolean ?
|
||||
MM_KERNEL_DEVICE_GET_CLASS (self)->get_property_as_boolean (self, property) :
|
||||
FALSE);
|
||||
const gchar *value;
|
||||
|
||||
value = mm_kernel_device_get_property (self, property);
|
||||
return (value && mm_common_get_boolean_from_string (value, NULL));
|
||||
}
|
||||
|
||||
gint
|
||||
mm_kernel_device_get_property_as_int (MMKernelDevice *self,
|
||||
const gchar *property)
|
||||
{
|
||||
return (MM_KERNEL_DEVICE_GET_CLASS (self)->get_property_as_int ?
|
||||
MM_KERNEL_DEVICE_GET_CLASS (self)->get_property_as_int (self, property) :
|
||||
-1);
|
||||
const gchar *value;
|
||||
gint aux;
|
||||
|
||||
value = mm_kernel_device_get_property (self, property);
|
||||
return ((value && mm_get_int_from_str (value, &aux)) ? aux : 0);
|
||||
}
|
||||
|
||||
guint
|
||||
mm_kernel_device_get_property_as_int_hex (MMKernelDevice *self,
|
||||
const gchar *property)
|
||||
{
|
||||
return (MM_KERNEL_DEVICE_GET_CLASS (self)->get_property_as_int_hex ?
|
||||
MM_KERNEL_DEVICE_GET_CLASS (self)->get_property_as_int_hex (self, property) :
|
||||
0);
|
||||
const gchar *value;
|
||||
guint aux;
|
||||
|
||||
value = mm_kernel_device_get_property (self, property);
|
||||
return ((value && mm_get_uint_from_hex_str (value, &aux)) ? aux : 0);
|
||||
}
|
||||
|
||||
gboolean
|
||||
@@ -241,27 +249,32 @@ gboolean
|
||||
mm_kernel_device_get_global_property_as_boolean (MMKernelDevice *self,
|
||||
const gchar *property)
|
||||
{
|
||||
return (MM_KERNEL_DEVICE_GET_CLASS (self)->get_global_property_as_boolean ?
|
||||
MM_KERNEL_DEVICE_GET_CLASS (self)->get_global_property_as_boolean (self, property) :
|
||||
FALSE);
|
||||
const gchar *value;
|
||||
|
||||
value = mm_kernel_device_get_global_property (self, property);
|
||||
return (value && mm_common_get_boolean_from_string (value, NULL));
|
||||
}
|
||||
|
||||
gint
|
||||
mm_kernel_device_get_global_property_as_int (MMKernelDevice *self,
|
||||
const gchar *property)
|
||||
{
|
||||
return (MM_KERNEL_DEVICE_GET_CLASS (self)->get_global_property_as_int ?
|
||||
MM_KERNEL_DEVICE_GET_CLASS (self)->get_global_property_as_int (self, property) :
|
||||
-1);
|
||||
const gchar *value;
|
||||
gint aux;
|
||||
|
||||
value = mm_kernel_device_get_global_property (self, property);
|
||||
return ((value && mm_get_int_from_str (value, &aux)) ? aux : 0);
|
||||
}
|
||||
|
||||
guint
|
||||
mm_kernel_device_get_global_property_as_int_hex (MMKernelDevice *self,
|
||||
const gchar *property)
|
||||
{
|
||||
return (MM_KERNEL_DEVICE_GET_CLASS (self)->get_global_property_as_int_hex ?
|
||||
MM_KERNEL_DEVICE_GET_CLASS (self)->get_global_property_as_int_hex (self, property) :
|
||||
0);
|
||||
const gchar *value;
|
||||
guint aux;
|
||||
|
||||
value = mm_kernel_device_get_global_property (self, property);
|
||||
return ((value && mm_get_uint_from_hex_str (value, &aux)) ? aux : 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -58,17 +58,10 @@ struct _MMKernelDeviceClass {
|
||||
|
||||
gboolean (* cmp) (MMKernelDevice *a, MMKernelDevice *b);
|
||||
|
||||
gboolean (* has_property) (MMKernelDevice *self, const gchar *property);
|
||||
const gchar * (* get_property) (MMKernelDevice *self, const gchar *property);
|
||||
gboolean (* get_property_as_boolean) (MMKernelDevice *self, const gchar *property);
|
||||
gint (* get_property_as_int) (MMKernelDevice *self, const gchar *property);
|
||||
guint (* get_property_as_int_hex) (MMKernelDevice *self, const gchar *property);
|
||||
|
||||
gboolean (* has_global_property) (MMKernelDevice *self, const gchar *property);
|
||||
const gchar * (* get_global_property) (MMKernelDevice *self, const gchar *property);
|
||||
gboolean (* get_global_property_as_boolean) (MMKernelDevice *self, const gchar *property);
|
||||
gint (* get_global_property_as_int) (MMKernelDevice *self, const gchar *property);
|
||||
guint (* get_global_property_as_int_hex) (MMKernelDevice *self, const gchar *property);
|
||||
gboolean (* has_property) (MMKernelDevice *self, const gchar *property);
|
||||
const gchar * (* get_property) (MMKernelDevice *self, const gchar *property);
|
||||
gboolean (* has_global_property) (MMKernelDevice *self, const gchar *property);
|
||||
const gchar * (* get_global_property) (MMKernelDevice *self, const gchar *property);
|
||||
};
|
||||
|
||||
GType mm_kernel_device_get_type (void);
|
||||
|
||||
Reference in New Issue
Block a user