| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include <gio/gio.h> |
| 5 |
#include <stdarg.h> |
| 6 |
|
| 7 |
#include "internal.h" |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
struct _GpiodglibRequestConfig { |
| 16 |
GObject parent_instance; |
| 17 |
struct gpiod_request_config *handle; |
| 18 |
}; |
| 19 |
|
| 20 |
typedef enum { |
| 21 |
GPIODGLIB_REQUEST_CONFIG_PROP_CONSUMER = 1, |
| 22 |
GPIODGLIB_REQUEST_CONFIG_PROP_EVENT_BUFFER_SIZE, |
| 23 |
} GpiodglibRequestConfigProp; |
| 24 |
|
| 25 |
G_DEFINE_TYPE(GpiodglibRequestConfig, gpiodglib_request_config, G_TYPE_OBJECT); |
| 26 |
|
| 27 |
static void gpiodglib_request_config_get_property(GObject *obj, guint prop_id, |
| 28 |
GValue *val, |
| 29 |
GParamSpec *pspec) |
| 30 |
{ |
| 31 |
GpiodglibRequestConfig *self = GPIODGLIB_REQUEST_CONFIG_OBJ(obj); |
| 32 |
|
| 33 |
switch ((GpiodglibRequestConfigProp)prop_id) { |
| 34 |
case GPIODGLIB_REQUEST_CONFIG_PROP_CONSUMER: |
| 35 |
g_value_set_string(val, |
| 36 |
gpiod_request_config_get_consumer(self->handle)); |
| 37 |
break; |
| 38 |
case GPIODGLIB_REQUEST_CONFIG_PROP_EVENT_BUFFER_SIZE: |
| 39 |
g_value_set_uint(val, |
| 40 |
gpiod_request_config_get_event_buffer_size( |
| 41 |
self->handle)); |
| 42 |
break; |
| 43 |
default: |
| 44 |
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
static void gpiodglib_request_config_set_property(GObject *obj, guint prop_id, |
| 49 |
const GValue *val, |
| 50 |
GParamSpec *pspec) |
| 51 |
{ |
| 52 |
GpiodglibRequestConfig *self = GPIODGLIB_REQUEST_CONFIG_OBJ(obj); |
| 53 |
|
| 54 |
switch ((GpiodglibRequestConfigProp)prop_id) { |
| 55 |
case GPIODGLIB_REQUEST_CONFIG_PROP_CONSUMER: |
| 56 |
gpiod_request_config_set_consumer(self->handle, |
| 57 |
g_value_get_string(val)); |
| 58 |
break; |
| 59 |
case GPIODGLIB_REQUEST_CONFIG_PROP_EVENT_BUFFER_SIZE: |
| 60 |
gpiod_request_config_set_event_buffer_size(self->handle, |
| 61 |
g_value_get_uint(val)); |
| 62 |
break; |
| 63 |
default: |
| 64 |
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
static void gpiodglib_request_config_finalize(GObject *obj) |
| 69 |
{ |
| 70 |
GpiodglibRequestConfig *self = GPIODGLIB_REQUEST_CONFIG_OBJ(obj); |
| 71 |
|
| 72 |
g_clear_pointer(&self->handle, gpiod_request_config_free); |
| 73 |
|
| 74 |
G_OBJECT_CLASS(gpiodglib_request_config_parent_class)->finalize(obj); |
| 75 |
} |
| 76 |
|
| 77 |
static void gpiodglib_request_config_class_init( |
| 78 |
GpiodglibRequestConfigClass *request_config_class) |
| 79 |
{ |
| 80 |
GObjectClass *class = G_OBJECT_CLASS(request_config_class); |
| 81 |
|
| 82 |
class->set_property = gpiodglib_request_config_set_property; |
| 83 |
class->get_property = gpiodglib_request_config_get_property; |
| 84 |
class->finalize = gpiodglib_request_config_finalize; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
g_object_class_install_property(class, |
| 92 |
GPIODGLIB_REQUEST_CONFIG_PROP_CONSUMER, |
| 93 |
g_param_spec_string("consumer", "Consumer", |
| 94 |
"Name of the request consumer.", |
| 95 |
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
g_object_class_install_property(class, |
| 103 |
GPIODGLIB_REQUEST_CONFIG_PROP_EVENT_BUFFER_SIZE, |
| 104 |
g_param_spec_uint("event-buffer-size", "Event Buffer Size", |
| 105 |
"Size of the kernel event buffer size of the request.", |
| 106 |
0, G_MAXUINT, 64, |
| 107 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
| 108 |
} |
| 109 |
|
| 110 |
static void gpiodglib_request_config_init(GpiodglibRequestConfig *self) |
| 111 |
{ |
| 112 |
self->handle = gpiod_request_config_new(); |
| 113 |
if (!self->handle) |
| 114 |
|
| 115 |
g_error("Failed to allocate memory for the request-config object."); |
| 116 |
} |
| 117 |
|
| 118 |
GpiodglibRequestConfig * |
| 119 |
gpiodglib_request_config_new(const gchar *first_prop, ...) |
| 120 |
{ |
| 121 |
GpiodglibRequestConfig *settings; |
| 122 |
va_list va; |
| 123 |
|
| 124 |
va_start(va, first_prop); |
| 125 |
settings = GPIODGLIB_REQUEST_CONFIG_OBJ( |
| 126 |
g_object_new_valist(GPIODGLIB_REQUEST_CONFIG_TYPE, |
| 127 |
first_prop, va)); |
| 128 |
va_end(va); |
| 129 |
|
| 130 |
return settings; |
| 131 |
} |
| 132 |
|
| 133 |
void gpiodglib_request_config_set_consumer(GpiodglibRequestConfig *self, |
| 134 |
const gchar *consumer) |
| 135 |
{ |
| 136 |
g_assert(self); |
| 137 |
|
| 138 |
_gpiodglib_set_prop_string(G_OBJECT(self), "consumer", consumer); |
| 139 |
} |
| 140 |
|
| 141 |
gchar *gpiodglib_request_config_dup_consumer(GpiodglibRequestConfig *self) |
| 142 |
{ |
| 143 |
g_assert(self); |
| 144 |
|
| 145 |
return _gpiodglib_dup_prop_string(G_OBJECT(self), "consumer"); |
| 146 |
} |
| 147 |
|
| 148 |
void |
| 149 |
gpiodglib_request_config_set_event_buffer_size(GpiodglibRequestConfig *self, |
| 150 |
guint event_buffer_size) |
| 151 |
{ |
| 152 |
g_assert(self); |
| 153 |
|
| 154 |
_gpiodglib_set_prop_uint(G_OBJECT(self), "event-buffer-size", |
| 155 |
event_buffer_size); |
| 156 |
} |
| 157 |
|
| 158 |
guint |
| 159 |
gpiodglib_request_config_get_event_buffer_size(GpiodglibRequestConfig *self) |
| 160 |
{ |
| 161 |
g_assert(self); |
| 162 |
|
| 163 |
return _gpiodglib_get_prop_uint(G_OBJECT(self), "event-buffer-size"); |
| 164 |
} |
| 165 |
|
| 166 |
struct gpiod_request_config * |
| 167 |
_gpiodglib_request_config_get_handle(GpiodglibRequestConfig *req_cfg) |
| 168 |
{ |
| 169 |
return req_cfg->handle; |
| 170 |
} |