aboutsummaryrefslogtreecommitdiffstats
path: root/src/fw_iso_resource_private.h
blob: f7ca0db83080e4bf5d79d7a7fc2c67db397dd39a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef __HINOKO_FW_ISO_RESOURCE_PRIVATE_H__
#define __HINOKO_FW_ISO_RESOURCE_PRIVATE_H__

#include "hinoko.h"

#include <unistd.h>
#include <errno.h>
#include <sys/ioctl.h>

#define GENERATION_PROP_NAME		"generation"

#define ALLOCATED_SIGNAL_NAME		"allocated"
#define DEALLOCATED_SIGNAL_NAME		"deallocated"

extern const char *const fw_iso_resource_err_msgs[HINOKO_FW_ISO_RESOURCE_ERROR_EVENT + 1];

#define generate_coded_error(error, code) 				\
	g_set_error_literal(error, HINOKO_FW_ISO_RESOURCE_ERROR, code,	\
			    fw_iso_resource_err_msgs[code])

#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_ioctl_error(error, errno, request)			\
	generate_syscall_error(error, errno, "ioctl(%s)", #request)

struct fw_iso_resource_state {
	int fd;
	struct fw_cdev_event_bus_reset bus_state;
};

enum fw_iso_resource_prop_type {
	FW_ISO_RESOURCE_PROP_TYPE_GENERATION = 1,
	FW_ISO_RESOURCE_PROP_TYPE_COUNT,
};

void fw_iso_resource_class_override_properties(GObjectClass *gobject_class);

void fw_iso_resource_state_get_property(const struct fw_iso_resource_state *state, GObject *obj,
					guint id, GValue *val, GParamSpec *spec);

void fw_iso_resource_state_init(struct fw_iso_resource_state *state);

void fw_iso_resource_state_release(struct fw_iso_resource_state *state);

gboolean fw_iso_resource_state_open(struct fw_iso_resource_state *state, const gchar *path,
				    gint open_flag, GError **error);

gboolean fw_iso_resource_state_create_source(struct fw_iso_resource_state *state,
					     HinokoFwIsoResource *inst,
					     void (*handle_event)(HinokoFwIsoResource *self,
								  const union fw_cdev_event *event),
					     GSource **source, GError **error);

gboolean fw_iso_resource_state_cache_bus_state(struct fw_iso_resource_state *state, GError **error);

struct fw_iso_resource_waiter {
	GMutex mutex;
	GCond cond;
	GError *error;
	gboolean handled;
	guint64 expiration;
	gulong handler_id;
};

void fw_iso_resource_waiter_init(struct fw_iso_resource_waiter *w, HinokoFwIsoResource *self,
				 const char *signal_name, guint timeout_ms);

gboolean fw_iso_resource_waiter_wait(struct fw_iso_resource_waiter *w, HinokoFwIsoResource *self,
				     GError **error);

void parse_iso_resource_event(const struct fw_cdev_event_iso_resource *ev, guint *channel,
			      guint *bandwidth, const char **signal_name, GError **error);

#endif