aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2022-05-03 07:57:47 +0900
committer坂本 貴史 <o-takashi@sakamocchi.jp>2022-05-03 08:31:29 +0900
commit2a8eec4921324e1dfaeeed24f49abb4fe531540f (patch)
tree88a8fd453a0340fde99529998583dda3987a96f1
parentff781a8f99791b6af95894a512dc77d2097f3463 (diff)
downloadlibhinoko-2a8eec4921324e1dfaeeed24f49abb4fe531540f.tar.gz
fw_iso_resource: make it GObject interface
Hinoko.FwIsoResource is now GObject Interface instead of GObject Abstract Class. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r--src/fw_iso_resource.c167
-rw-r--r--src/fw_iso_resource.h11
-rw-r--r--src/fw_iso_resource_auto.c40
-rw-r--r--src/fw_iso_resource_auto.h4
-rw-r--r--src/fw_iso_resource_once.c44
-rw-r--r--src/fw_iso_resource_once.h4
-rw-r--r--src/fw_iso_resource_private.h16
-rw-r--r--src/hinoko.map9
-rw-r--r--tests/fw-iso-resource30
-rw-r--r--tests/fw-iso-resource-auto12
-rw-r--r--tests/fw-iso-resource-once13
-rw-r--r--tests/meson.build1
12 files changed, 118 insertions, 233 deletions
diff --git a/src/fw_iso_resource.c b/src/fw_iso_resource.c
index cc7ef2c..b84b239 100644
--- a/src/fw_iso_resource.c
+++ b/src/fw_iso_resource.c
@@ -4,20 +4,18 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include <sys/ioctl.h>
/**
* HinokoFwIsoResource:
- * An abstract object to listen events of isochronous resource allocation/deallocation.
+ * An interface object to listen events of isochronous resource allocation and deallocation.
*
- * The [class@FwIsoResource] is an abstract object to listen events of isochronous resource
- * allocation/deallocation by file descriptor owned internally. This object is designed to be used
- * for any derived object.
+ * The [iface@FwIsoResource] should be implemented in GObject-derived object to listen events of
+ * isochronous resource allocation and deallocation.
+ *
+ * Since: 0.7.
*/
-typedef struct {
- int fd;
-} HinokoFwIsoResourcePrivate;
-G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(HinokoFwIsoResource, hinoko_fw_iso_resource, G_TYPE_OBJECT)
+
+G_DEFINE_INTERFACE(HinokoFwIsoResource, hinoko_fw_iso_resource, G_TYPE_OBJECT)
/**
* hinoko_fw_iso_resource_error_quark:
@@ -46,11 +44,6 @@ static const char *const err_msgs[] = {
HINOKO_FW_ISO_RESOURCE_ERROR_EVENT, \
"%d %s", errno, strerror(errno))
-#define generate_syscall_error(error, errno, format, arg) \
- g_set_error(error, HINOKO_FW_ISO_RESOURCE_ERROR, \
- HINOKO_FW_ISO_RESOURCE_ERROR_FAILED, \
- format " %d(%s)", arg, errno, strerror(errno))
-
#define generate_file_error(error, code, format, arg) \
g_set_error(error, G_FILE_ERROR, code, format, arg)
@@ -65,70 +58,24 @@ typedef struct {
guint bandwidth, const GError *error);
} FwIsoResourceSource;
-static void fw_iso_resource_finalize(GObject *obj)
-{
- HinokoFwIsoResource *self = HINOKO_FW_ISO_RESOURCE(obj);
- HinokoFwIsoResourcePrivate *priv =
- hinoko_fw_iso_resource_get_instance_private(self);
-
- if (priv->fd >= 0)
- close(priv->fd);
-
- G_OBJECT_CLASS(hinoko_fw_iso_resource_parent_class)->finalize(obj);
-}
-
-static gboolean fw_iso_resource_open_real(HinokoFwIsoResource *self, const gchar *path,
- gint open_flag, GError **error)
-{
- HinokoFwIsoResourcePrivate *priv;
-
- g_return_val_if_fail(HINOKO_IS_FW_ISO_RESOURCE(self), FALSE);
- priv = hinoko_fw_iso_resource_get_instance_private(self);
-
- return fw_iso_resource_open(&priv->fd, path, open_flag, error);
-}
-
-static void fw_iso_resource_handle_event(HinokoFwIsoResource *inst, const char *signal_name,
- guint channel, guint bandwidth, const GError *error)
-{
- g_signal_emit_by_name(inst, signal_name, channel, bandwidth, error);
-}
-
-static gboolean fw_iso_resource_create_source_real(HinokoFwIsoResource *self, GSource **source,
- GError **error)
+static void hinoko_fw_iso_resource_default_init(HinokoFwIsoResourceInterface *iface)
{
- HinokoFwIsoResourcePrivate *priv;
-
- g_return_val_if_fail(HINOKO_IS_FW_ISO_RESOURCE(self), FALSE);
- priv = hinoko_fw_iso_resource_get_instance_private(self);
-
- return fw_iso_resource_create_source(priv->fd, self, fw_iso_resource_handle_event, source,
- error);
-}
-
-static void hinoko_fw_iso_resource_class_init(HinokoFwIsoResourceClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-
- gobject_class->finalize = fw_iso_resource_finalize;
-
- klass->open = fw_iso_resource_open_real;
- klass->create_source = fw_iso_resource_create_source_real;
-
/**
* HinokoFwIsoResource::allocated:
- * @self: A [class@FwIsoResource].
+ * @self: A [iface@FwIsoResource].
* @channel: The deallocated channel number.
* @bandwidth: The deallocated amount of bandwidth.
* @error: (transfer none) (nullable) (in): A [struct@GLib.Error]. Error can be generated
* with domain of Hinoko.FwIsoResourceError and its EVENT code.
*
* Emitted when allocation of isochronous resource finishes.
+ *
+ * Since: 0.7.
*/
g_signal_new(ALLOCATED_SIGNAL_NAME,
- G_OBJECT_CLASS_TYPE(klass),
+ G_TYPE_FROM_INTERFACE(iface),
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(HinokoFwIsoResourceClass, allocated),
+ G_STRUCT_OFFSET(HinokoFwIsoResourceInterface, allocated),
NULL, NULL,
hinoko_sigs_marshal_VOID__UINT_UINT_BOXED,
G_TYPE_NONE,
@@ -136,31 +83,26 @@ static void hinoko_fw_iso_resource_class_init(HinokoFwIsoResourceClass *klass)
/**
* HinokoFwIsoResource::deallocated:
- * @self: A [class@FwIsoResource].
+ * @self: A [iface@FwIsoResource].
* @channel: The deallocated channel number.
* @bandwidth: The deallocated amount of bandwidth.
* @error: (transfer none) (nullable) (in): A [struct@GLib.Error]. Error can be generated
* with domain of Hinoko.FwIsoResourceError and its EVENT code.
*
* Emitted when deallocation of isochronous resource finishes.
+ *
+ * Since: 0.7.
*/
g_signal_new(DEALLOCATED_SIGNAL_NAME,
- G_OBJECT_CLASS_TYPE(klass),
+ G_TYPE_FROM_INTERFACE(iface),
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(HinokoFwIsoResourceClass, deallocated),
+ G_STRUCT_OFFSET(HinokoFwIsoResourceInterface, deallocated),
NULL, NULL,
hinoko_sigs_marshal_VOID__UINT_UINT_BOXED,
G_TYPE_NONE,
3, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_ERROR);
}
-static void hinoko_fw_iso_resource_init(HinokoFwIsoResource *self)
-{
- HinokoFwIsoResourcePrivate *priv =
- hinoko_fw_iso_resource_get_instance_private(self);
- priv->fd = -1;
-}
-
gboolean fw_iso_resource_open(int *fd, const gchar *path, gint open_flag, GError **error)
{
g_return_val_if_fail(fd != NULL, FALSE);
@@ -187,7 +129,7 @@ gboolean fw_iso_resource_open(int *fd, const gchar *path, gint open_flag, GError
}
/**
* hinoko_fw_iso_resource_open:
- * @self: A [class@FwIsoResource].
+ * @self: A [iface@FwIsoResource].
* @path: A path of any Linux FireWire character device.
* @open_flag: The flag of open(2) system call. O_RDONLY is forced to fulfil
* internally.
@@ -196,19 +138,17 @@ gboolean fw_iso_resource_open(int *fd, const gchar *path, gint open_flag, GError
*
* Open Linux FireWire character device to delegate any request for isochronous
* resource management to Linux FireWire subsystem.
+ *
+ * Since: 0.7.
*/
void hinoko_fw_iso_resource_open(HinokoFwIsoResource *self, const gchar *path, gint open_flag,
GError **error)
{
- HinokoFwIsoResourcePrivate *priv;
-
g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE(self));
g_return_if_fail(path != NULL && strlen(path) > 0);
g_return_if_fail(error == NULL || *error == NULL);
- priv = hinoko_fw_iso_resource_get_instance_private(self);
-
- (void)fw_iso_resource_open(&priv->fd, path, open_flag, error);
+ (void)HINOKO_FW_ISO_RESOURCE_GET_IFACE(self)->open(self, path, open_flag, error);
}
static void handle_event_signal(HinokoFwIsoResource *self, guint channel, guint bandwidth,
@@ -259,49 +199,6 @@ void fw_iso_resource_waiter_wait(HinokoFwIsoResource *self, struct fw_iso_resour
*error = w->error; // Delegate ownership.
}
-// For internal use.
-void hinoko_fw_iso_resource_ioctl(HinokoFwIsoResource *self,
- unsigned long request, void *argp,
- GError **error)
-{
- HinokoFwIsoResourcePrivate *priv;
-
- g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE(self));
- g_return_if_fail(request == FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE ||
- request == FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE ||
- request == FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE ||
- request == FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE);
-
- priv = hinoko_fw_iso_resource_get_instance_private(self);
- if (priv->fd < 0) {
- generate_local_error(error, HINOKO_FW_ISO_RESOURCE_ERROR_NOT_OPENED);
- return;
- }
-
- if (ioctl(priv->fd, request, argp) < 0) {
- const char *arg;
-
- switch (request) {
- case FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE:
- arg = "FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE";
- break;
- case FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE:
- arg = "FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE";
- break;
- case FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE:
- arg = "FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE";
- break;
- case FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE:
- arg = "FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE";
- break;
- default:
- arg = "Unknown";
- break;
- }
- generate_syscall_error(error, errno, "ioctl(%s)", arg);
- }
-}
-
static void handle_iso_resource_event(FwIsoResourceSource *src,
const struct fw_cdev_event_iso_resource *ev)
{
@@ -422,35 +319,23 @@ gboolean fw_iso_resource_create_source(int fd, HinokoFwIsoResource *inst,
/**
* hinoko_fw_iso_resource_create_source:
- * @self: A [class@FwIsoResource].
+ * @self: A [iface@FwIsoResource].
* @source: (out): A [struct@GLib.Source]
* @error: A [struct@GLib.Error].
*
* Create [struct@GLib.Source] for [struct@GLib.MainContext] to dispatch events for isochronous
* resource.
+ *
+ * Since: 0.7.
*/
void hinoko_fw_iso_resource_create_source(HinokoFwIsoResource *self, GSource **source,
GError **error)
{
- HinokoFwIsoResourcePrivate *priv;
-
- void (*handle_event)(HinokoFwIsoResource *self, const char *signal_name, guint channel,
- guint bandwidth, const GError *error);
-
g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE(self));
g_return_if_fail(source != NULL);
g_return_if_fail(error == NULL || *error == NULL);
- priv = hinoko_fw_iso_resource_get_instance_private(self);
-
- if (HINOKO_IS_FW_ISO_RESOURCE_AUTO(self))
- handle_event = fw_iso_resource_auto_handle_event;
- else if (HINOKO_IS_FW_ISO_RESOURCE_ONCE(self))
- handle_event = fw_iso_resource_once_handle_event;
- else
- handle_event = fw_iso_resource_handle_event;
-
- (void)fw_iso_resource_create_source(priv->fd, self, handle_event, source, error);
+ (void)HINOKO_FW_ISO_RESOURCE_GET_IFACE(self)->create_source(self, source, error);
}
/**
diff --git a/src/fw_iso_resource.h b/src/fw_iso_resource.h
index 532e78e..33e8f8e 100644
--- a/src/fw_iso_resource.h
+++ b/src/fw_iso_resource.h
@@ -8,15 +8,14 @@ G_BEGIN_DECLS
#define HINOKO_TYPE_FW_ISO_RESOURCE (hinoko_fw_iso_resource_get_type())
-G_DECLARE_DERIVABLE_TYPE(HinokoFwIsoResource, hinoko_fw_iso_resource, HINOKO, FW_ISO_RESOURCE,
- GObject);
+G_DECLARE_INTERFACE(HinokoFwIsoResource, hinoko_fw_iso_resource, HINOKO, FW_ISO_RESOURCE, GObject);
#define HINOKO_FW_ISO_RESOURCE_ERROR hinoko_fw_iso_resource_error_quark()
GQuark hinoko_fw_iso_resource_error_quark();
-struct _HinokoFwIsoResourceClass {
- GObjectClass parent_class;
+struct _HinokoFwIsoResourceInterface {
+ GTypeInterface parent_iface;
gboolean (*open)(HinokoFwIsoResource *self, const gchar *path, gint open_flag,
GError **error);
@@ -32,6 +31,8 @@ struct _HinokoFwIsoResourceClass {
* with domain of Hinoko.FwIsoResourceError and its EVENT code.
*
* Class closure for the [signal@FwIsoResource::allocated] signal.
+ *
+ * Since: 0.7.
*/
void (*allocated)(HinokoFwIsoResource *self, guint channel,
guint bandwidth, const GError *error);
@@ -45,6 +46,8 @@ struct _HinokoFwIsoResourceClass {
* with domain of Hinoko.FwIsoResourceError and its EVENT code.
*
* Class closure for the [signal@FwIsoResource::deallocated] signal.
+ *
+ * Since: 0.7.
*/
void (*deallocated)(HinokoFwIsoResource *self, guint channel,
guint bandwidth, const GError *error);
diff --git a/src/fw_iso_resource_auto.c b/src/fw_iso_resource_auto.c
index b967b3a..83d06ab 100644
--- a/src/fw_iso_resource_auto.c
+++ b/src/fw_iso_resource_auto.c
@@ -20,8 +20,11 @@ typedef struct {
guint handle;
} HinokoFwIsoResourceAutoPrivate;
-G_DEFINE_TYPE_WITH_CODE(HinokoFwIsoResourceAuto, hinoko_fw_iso_resource_auto, HINOKO_TYPE_FW_ISO_RESOURCE,
- G_ADD_PRIVATE(HinokoFwIsoResourceAuto))
+static void fw_iso_resource_iface_init(HinokoFwIsoResourceInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE(HinokoFwIsoResourceAuto, hinoko_fw_iso_resource_auto, G_TYPE_OBJECT,
+ G_ADD_PRIVATE(HinokoFwIsoResourceAuto)
+ G_IMPLEMENT_INTERFACE(HINOKO_TYPE_FW_ISO_RESOURCE, fw_iso_resource_iface_init))
/**
* hinoko_fw_iso_resource_auto_error_quark:
@@ -90,23 +93,13 @@ static void fw_iso_resource_auto_finalize(GObject *obj)
G_OBJECT_CLASS(hinoko_fw_iso_resource_auto_parent_class)->finalize(obj);
}
-static gboolean fw_iso_resource_auto_open(HinokoFwIsoResource *inst, const gchar *path,
- gint open_flag, GError **error);
-
-static gboolean fw_iso_resource_auto_create_source(HinokoFwIsoResource *inst, GSource **source,
- GError **error);
-
static void hinoko_fw_iso_resource_auto_class_init(HinokoFwIsoResourceAutoClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
- HinokoFwIsoResourceClass *parent_class = HINOKO_FW_ISO_RESOURCE_CLASS(klass);
gobject_class->get_property = fw_iso_resource_auto_get_property;
gobject_class->finalize = fw_iso_resource_auto_finalize;
- parent_class->open = fw_iso_resource_auto_open;
- parent_class->create_source = fw_iso_resource_auto_create_source;
-
fw_iso_resource_auto_props[FW_ISO_RESOURCE_AUTO_PROP_IS_ALLOCATED] =
g_param_spec_boolean("is-allocated", "is-allocated",
"Whether to allocated or not.",
@@ -196,6 +189,13 @@ static gboolean fw_iso_resource_auto_create_source(HinokoFwIsoResource *inst, GS
source, error);
}
+static void fw_iso_resource_iface_init(HinokoFwIsoResourceInterface *iface)
+{
+ iface->open = fw_iso_resource_auto_open;
+ iface->create_source = fw_iso_resource_auto_create_source;
+
+}
+
/**
* hinoko_fw_iso_resource_auto_new:
*
@@ -254,11 +254,12 @@ void hinoko_fw_iso_resource_auto_allocate_async(HinokoFwIsoResourceAuto *self,
}
res.bandwidth = bandwidth;
- hinoko_fw_iso_resource_ioctl(HINOKO_FW_ISO_RESOURCE(self),
- FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE, &res,
- error);
- if (*error == NULL)
+ if (ioctl(priv->fd, FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE, &res) < 0) {
+ generate_syscall_error(error, errno, "ioctl(%s)",
+ "FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE");
+ } else {
priv->handle = res.handle;
+ }
end:
g_mutex_unlock(&priv->mutex);
}
@@ -292,9 +293,10 @@ void hinoko_fw_iso_resource_auto_deallocate_async(HinokoFwIsoResourceAuto *self,
dealloc.handle = priv->handle;
- hinoko_fw_iso_resource_ioctl(HINOKO_FW_ISO_RESOURCE(self),
- FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE,
- &dealloc, error);
+ if (ioctl(priv->fd, FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE, &dealloc) < 0) {
+ generate_syscall_error(error, errno, "ioctl(%s)",
+ "FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE");
+ }
end:
g_mutex_unlock(&priv->mutex);
}
diff --git a/src/fw_iso_resource_auto.h b/src/fw_iso_resource_auto.h
index aa08768..b324ad2 100644
--- a/src/fw_iso_resource_auto.h
+++ b/src/fw_iso_resource_auto.h
@@ -9,14 +9,14 @@ G_BEGIN_DECLS
#define HINOKO_TYPE_FW_ISO_RESOURCE_AUTO (hinoko_fw_iso_resource_auto_get_type())
G_DECLARE_DERIVABLE_TYPE(HinokoFwIsoResourceAuto, hinoko_fw_iso_resource_auto, HINOKO,
- FW_ISO_RESOURCE_AUTO, HinokoFwIsoResource);
+ FW_ISO_RESOURCE_AUTO, GObject);
#define HINOKO_FW_ISO_RESOURCE_AUTO_ERROR hinoko_fw_iso_resource_auto_error_quark()
GQuark hinoko_fw_iso_resource_auto_error_quark();
struct _HinokoFwIsoResourceAutoClass {
- HinokoFwIsoResourceClass parent_class;
+ GObjectClass parent_class;
};
HinokoFwIsoResourceAuto *hinoko_fw_iso_resource_auto_new();
diff --git a/src/fw_iso_resource_once.c b/src/fw_iso_resource_once.c
index 742ae8d..1a3de3c 100644
--- a/src/fw_iso_resource_once.c
+++ b/src/fw_iso_resource_once.c
@@ -14,8 +14,11 @@ typedef struct {
int fd;
} HinokoFwIsoResourceOncePrivate;
-G_DEFINE_TYPE_WITH_CODE(HinokoFwIsoResourceOnce, hinoko_fw_iso_resource_once, HINOKO_TYPE_FW_ISO_RESOURCE,
- G_ADD_PRIVATE(HinokoFwIsoResourceOnce))
+static void fw_iso_resource_iface_init(HinokoFwIsoResourceInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE(HinokoFwIsoResourceOnce, hinoko_fw_iso_resource_once, G_TYPE_OBJECT,
+ G_ADD_PRIVATE(HinokoFwIsoResourceOnce)
+ G_IMPLEMENT_INTERFACE(HINOKO_TYPE_FW_ISO_RESOURCE, fw_iso_resource_iface_init))
static void fw_iso_resource_once_finalize(GObject *obj)
{
@@ -29,21 +32,11 @@ static void fw_iso_resource_once_finalize(GObject *obj)
G_OBJECT_CLASS(hinoko_fw_iso_resource_once_parent_class)->finalize(obj);
}
-static gboolean fw_iso_resource_once_open(HinokoFwIsoResource *inst, const gchar *path,
- gint open_flag, GError **error);
-
-static gboolean fw_iso_resource_once_create_source(HinokoFwIsoResource *inst, GSource **source,
- GError **error);
-
static void hinoko_fw_iso_resource_once_class_init(HinokoFwIsoResourceOnceClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
- HinokoFwIsoResourceClass *parent_class = HINOKO_FW_ISO_RESOURCE_CLASS(klass);
gobject_class->finalize = fw_iso_resource_once_finalize;
-
- parent_class->open = fw_iso_resource_once_open;
- parent_class->create_source = fw_iso_resource_once_create_source;
}
static void hinoko_fw_iso_resource_once_init(HinokoFwIsoResourceOnce *self)
@@ -87,6 +80,13 @@ static gboolean fw_iso_resource_once_create_source(HinokoFwIsoResource *inst, GS
source, error);
}
+static void fw_iso_resource_iface_init(HinokoFwIsoResourceInterface *iface)
+{
+ iface->open = fw_iso_resource_once_open;
+ iface->create_source = fw_iso_resource_once_create_source;
+
+}
+
/**
* hinoko_fw_iso_resource_once_new:
*
@@ -120,6 +120,8 @@ void hinoko_fw_iso_resource_once_allocate_async(HinokoFwIsoResourceOnce *self,
gsize channel_candidates_count,
guint bandwidth, GError **error)
{
+ HinokoFwIsoResourceOncePrivate *priv;
+
struct fw_cdev_allocate_iso_resource res = {0};
int i;
@@ -130,14 +132,18 @@ void hinoko_fw_iso_resource_once_allocate_async(HinokoFwIsoResourceOnce *self,
g_return_if_fail(channel_candidates_count > 0);
g_return_if_fail(bandwidth > 0);
+ priv = hinoko_fw_iso_resource_once_get_instance_private(self);
+
for (i = 0; i < channel_candidates_count; ++i) {
if (channel_candidates[i] < 64)
res.channels |= 1ull << channel_candidates[i];
}
res.bandwidth = bandwidth;
- hinoko_fw_iso_resource_ioctl(HINOKO_FW_ISO_RESOURCE(self),
- FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE, &res, error);
+ if (ioctl(priv->fd, FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE, &res) < 0) {
+ generate_syscall_error(error, errno, "ioctl(%s)",
+ "FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE");
+ }
}
/**
@@ -156,6 +162,8 @@ void hinoko_fw_iso_resource_once_allocate_async(HinokoFwIsoResourceOnce *self,
void hinoko_fw_iso_resource_once_deallocate_async(HinokoFwIsoResourceOnce *self, guint channel,
guint bandwidth, GError **error)
{
+ HinokoFwIsoResourceOncePrivate *priv;
+
struct fw_cdev_allocate_iso_resource res = {0};
g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE_ONCE(self));
@@ -164,11 +172,15 @@ void hinoko_fw_iso_resource_once_deallocate_async(HinokoFwIsoResourceOnce *self,
g_return_if_fail(channel < 64);
g_return_if_fail(bandwidth > 0);
+ priv = hinoko_fw_iso_resource_once_get_instance_private(self);
+
res.channels = 1ull << channel;
res.bandwidth = bandwidth;
- hinoko_fw_iso_resource_ioctl(HINOKO_FW_ISO_RESOURCE(self),
- FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE, &res, error);
+ if (ioctl(priv->fd, FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE, &res) < 0) {
+ generate_syscall_error(error, errno, "ioctl(%s)",
+ "FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE");
+ }
}
/**
diff --git a/src/fw_iso_resource_once.h b/src/fw_iso_resource_once.h
index 1093162..8583307 100644
--- a/src/fw_iso_resource_once.h
+++ b/src/fw_iso_resource_once.h
@@ -9,10 +9,10 @@ G_BEGIN_DECLS
#define HINOKO_TYPE_FW_ISO_RESOURCE_ONCE (hinoko_fw_iso_resource_once_get_type())
G_DECLARE_DERIVABLE_TYPE(HinokoFwIsoResourceOnce, hinoko_fw_iso_resource_once, HINOKO,
- FW_ISO_RESOURCE_ONCE, HinokoFwIsoResource);
+ FW_ISO_RESOURCE_ONCE, GObject);
struct _HinokoFwIsoResourceOnceClass {
- HinokoFwIsoResourceClass parent_class;
+ GObjectClass parent_class;
};
HinokoFwIsoResourceOnce *hinoko_fw_iso_resource_once_new();
diff --git a/src/fw_iso_resource_private.h b/src/fw_iso_resource_private.h
index 6ddf570..9a7a62c 100644
--- a/src/fw_iso_resource_private.h
+++ b/src/fw_iso_resource_private.h
@@ -6,10 +6,16 @@
#include <unistd.h>
#include <errno.h>
+#include <sys/ioctl.h>
#define ALLOCATED_SIGNAL_NAME "allocated"
#define DEALLOCATED_SIGNAL_NAME "deallocated"
+#define generate_syscall_error(error, errno, format, arg) \
+ g_set_error(error, HINOKO_FW_ISO_RESOURCE_ERROR, \
+ HINOKO_FW_ISO_RESOURCE_ERROR_FAILED, \
+ format " %d(%s)", arg, errno, strerror(errno))
+
gboolean fw_iso_resource_open(int *fd, const gchar *path, gint open_flag, GError **error);
gboolean fw_iso_resource_create_source(int fd, HinokoFwIsoResource *inst,
@@ -18,16 +24,6 @@ gboolean fw_iso_resource_create_source(int fd, HinokoFwIsoResource *inst,
guint bandwidth, const GError *error),
GSource **source, GError **error);
-void hinoko_fw_iso_resource_ioctl(HinokoFwIsoResource *self,
- unsigned long request, void *argp,
- GError **error);
-
-void fw_iso_resource_auto_handle_event(HinokoFwIsoResource *inst, const char *signal_name,
- guint channel, guint bandwidth, const GError *error);
-
-void fw_iso_resource_once_handle_event(HinokoFwIsoResource *inst, const char *signal_name,
- guint channel, guint bandwidth, const GError *error);
-
struct fw_iso_resource_waiter {
GMutex mutex;
GCond cond;
diff --git a/src/hinoko.map b/src/hinoko.map
index 36d0ef1..8c9db1c 100644
--- a/src/hinoko.map
+++ b/src/hinoko.map
@@ -49,12 +49,8 @@ HINOKO_0_3_0 {
HINOKO_0_4_0 {
global:
- "hinoko_fw_iso_resource_get_type";
- "hinoko_fw_iso_resource_open";
- "hinoko_fw_iso_resource_create_source";
"hinoko_fw_iso_resource_calculate_bandwidth";
- "hinoko_fw_iso_resource_auto_get_type";
"hinoko_fw_iso_resource_auto_new";
"hinoko_fw_iso_resource_auto_allocate_async";
"hinoko_fw_iso_resource_auto_deallocate_async";
@@ -85,6 +81,11 @@ HINOKO_0_6_0 {
HINOKO_0_7_0 {
global:
+ "hinoko_fw_iso_resource_get_type";
+ "hinoko_fw_iso_resource_open";
+ "hinoko_fw_iso_resource_create_source";
+
+ "hinoko_fw_iso_resource_auto_get_type";
"hinoko_fw_iso_resource_auto_allocate_sync";
"hinoko_fw_iso_resource_auto_deallocate_sync";
diff --git a/tests/fw-iso-resource b/tests/fw-iso-resource
deleted file mode 100644
index 0e21af4..0000000
--- a/tests/fw-iso-resource
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/usr/bin/env python3
-
-from sys import exit
-from errno import ENXIO
-
-from helper import test
-
-import gi
-gi.require_version('Hinoko', '0.0')
-from gi.repository import Hinoko
-
-target = Hinoko.FwIsoResource
-props = ()
-methods = (
- 'open',
- 'create_source',
- 'calculate_bandwidth',
-)
-vmethods = (
- 'do_allocated',
- 'do_deallocated',
-)
-signals = (
- 'allocated',
- 'deallocated',
-)
-
-if not test(target, props, methods, vmethods, signals):
- exit(ENXIO)
-
diff --git a/tests/fw-iso-resource-auto b/tests/fw-iso-resource-auto
index 6201e06..82517d6 100644
--- a/tests/fw-iso-resource-auto
+++ b/tests/fw-iso-resource-auto
@@ -17,13 +17,21 @@ props = (
)
methods = (
'new',
+ 'open',
+ 'create_source',
'allocate_async',
'deallocate_async',
'allocate_sync',
'deallocate_sync',
)
-vmethods = ()
-signals = ()
+vmethods = (
+ #'do_allocated',
+ #'do_deallocated',
+)
+signals = (
+ #'allocated',
+ #'deallocated',
+)
if not test(target, props, methods, vmethods, signals):
exit(ENXIO)
diff --git a/tests/fw-iso-resource-once b/tests/fw-iso-resource-once
index 1c092d9..62d2800 100644
--- a/tests/fw-iso-resource-once
+++ b/tests/fw-iso-resource-once
@@ -13,13 +13,22 @@ target = Hinoko.FwIsoResourceOnce()
props = ()
methods = (
'new',
+ 'open',
+ 'create_source',
'allocate_async',
'deallocate_async',
'allocate_sync',
'deallocate_sync',
)
-vmethods = ()
-signals = ()
+vmethods = (
+ #'do_allocated',
+ #'do_deallocated',
+)
+signals = (
+ #'allocated',
+ #'deallocated',
+)
+
if not test(target, props, methods, vmethods, signals):
exit(ENXIO)
diff --git a/tests/meson.build b/tests/meson.build
index f7fd634..68c2eb3 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -4,7 +4,6 @@ tests = [
'fw-iso-rx-single',
'fw-iso-rx-multiple',
'fw-iso-tx',
- 'fw-iso-resource',
'fw-iso-resource-auto',
'fw-iso-resource-once',
]