summaryrefslogtreecommitdiff
path: root/src/freebsd/up-acpi-native.c
blob: eb58db5f42b28a6a393dd79779a26f0bcdaeca80 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/* up-acpi-native.c generated by valac, the Vala compiler
 * generated from up-acpi-native.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>


#define TYPE_UP_ACPI_NATIVE (up_acpi_native_get_type ())
#define UP_ACPI_NATIVE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UP_ACPI_NATIVE, UpAcpiNative))
#define UP_ACPI_NATIVE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UP_ACPI_NATIVE, UpAcpiNativeClass))
#define IS_UP_ACPI_NATIVE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UP_ACPI_NATIVE))
#define IS_UP_ACPI_NATIVE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UP_ACPI_NATIVE))
#define UP_ACPI_NATIVE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UP_ACPI_NATIVE, UpAcpiNativeClass))

typedef struct _UpAcpiNative UpAcpiNative;
typedef struct _UpAcpiNativeClass UpAcpiNativeClass;
typedef struct _UpAcpiNativePrivate UpAcpiNativePrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_match_info_free0(var) ((var == NULL) ? NULL : (var = (g_match_info_free (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _UpAcpiNative {
	GObject parent_instance;
	UpAcpiNativePrivate * priv;
};

struct _UpAcpiNativeClass {
	GObjectClass parent_class;
};

struct _UpAcpiNativePrivate {
	gchar	*_driver;
	gint	 _unit;
	gchar	*_path;
};


static gpointer up_acpi_native_parent_class = NULL;

GType up_acpi_native_get_type (void);
#define UP_ACPI_NATIVE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_UP_ACPI_NATIVE, UpAcpiNativePrivate))
enum  {
	UP_ACPI_NATIVE_DUMMY_PROPERTY,
	UP_ACPI_NATIVE_DRIVER,
	UP_ACPI_NATIVE_UNIT,
	UP_ACPI_NATIVE_PATH
};
UpAcpiNative* up_acpi_native_new (const char* path);
UpAcpiNative* up_acpi_native_construct (GType object_type, const char* path);
UpAcpiNative* up_acpi_native_new_driver_unit (const char* driver, gint unit);
UpAcpiNative* up_acpi_native_construct_driver_unit (GType object_type, const char* driver, gint unit);
const char* up_acpi_native_get_driver (UpAcpiNative* self);
gint up_acpi_native_get_unit (UpAcpiNative* self);
const char* up_acpi_native_get_path (UpAcpiNative* self);
static void up_acpi_native_finalize (GObject* obj);
static void up_acpi_native_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);



UpAcpiNative* up_acpi_native_construct (GType object_type, const char* path) {
	GError * _inner_error_;
	UpAcpiNative * self;
	GRegex* r;
	GMatchInfo* mi;
	gboolean ret = FALSE;
	char* _tmp9_;
	g_return_val_if_fail (path != NULL, NULL);
	_inner_error_ = NULL;
	self = (UpAcpiNative*) g_object_new (object_type, NULL);
	r = NULL;
	mi = NULL;
	{
		GRegex* _tmp0_;
		GRegex* _tmp1_;
		GMatchInfo* _tmp4_;
		gboolean _tmp3_;
		GMatchInfo* _tmp2_ = NULL;
		_tmp0_ = g_regex_new ("dev\\.([^\\.])\\.(\\d+)", 0, 0, &_inner_error_);
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			goto __finally0;
		}
		r = (_tmp1_ = _tmp0_, _g_regex_unref0 (r), _tmp1_);
		ret = (_tmp3_ = g_regex_match (r, path, 0, &_tmp2_), mi = (_tmp4_ = _tmp2_, _g_match_info_free0 (mi), _tmp4_), _tmp3_);
		if (ret) {
			char* _tmp5_;
			char* _tmp6_;
			self->priv->_driver = (_tmp5_ = g_match_info_fetch (mi, 1), _g_free0 (self->priv->_driver), _tmp5_);
			self->priv->_unit = atoi (_tmp6_ = g_match_info_fetch (mi, 2));
			_g_free0 (_tmp6_);
		} else {
			char* _tmp7_;
			self->priv->_driver = (_tmp7_ = NULL, _g_free0 (self->priv->_driver), _tmp7_);
			self->priv->_unit = -1;
		}
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		GError * re;
		re = _inner_error_;
		_inner_error_ = NULL;
		{
			char* _tmp8_;
			self->priv->_driver = (_tmp8_ = NULL, _g_free0 (self->priv->_driver), _tmp8_);
			self->priv->_unit = -1;
			_g_error_free0 (re);
		}
	}
	__finally0:
	if (_inner_error_ != NULL) {
		_g_regex_unref0 (r);
		_g_match_info_free0 (mi);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	self->priv->_path = (_tmp9_ = g_strdup (path), _g_free0 (self->priv->_path), _tmp9_);
	_g_regex_unref0 (r);
	_g_match_info_free0 (mi);
	return self;
}


UpAcpiNative* up_acpi_native_new (const char* path) {
	return up_acpi_native_construct (TYPE_UP_ACPI_NATIVE, path);
}


UpAcpiNative* up_acpi_native_construct_driver_unit (GType object_type, const char* driver, gint unit) {
	UpAcpiNative * self;
	char* _tmp0_;
	char* _tmp1_;
	g_return_val_if_fail (driver != NULL, NULL);
	self = (UpAcpiNative*) g_object_new (object_type, NULL);
	self->priv->_driver = (_tmp0_ = g_strdup (driver), _g_free0 (self->priv->_driver), _tmp0_);
	self->priv->_unit = unit;
	self->priv->_path = (_tmp1_ = g_strdup_printf ("dev.%s.%i", self->priv->_driver, self->priv->_unit), _g_free0 (self->priv->_path), _tmp1_);
	return self;
}


UpAcpiNative* up_acpi_native_new_driver_unit (const char* driver, gint unit) {
	return up_acpi_native_construct_driver_unit (TYPE_UP_ACPI_NATIVE, driver, unit);
}


const char* up_acpi_native_get_driver (UpAcpiNative* self) {
	const char* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self->priv->_driver;
	return result;
}


gint up_acpi_native_get_unit (UpAcpiNative* self) {
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_unit;
	return result;
}


const char* up_acpi_native_get_path (UpAcpiNative* self) {
	const char* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self->priv->_path;
	return result;
}


static void up_acpi_native_class_init (UpAcpiNativeClass * klass) {
	up_acpi_native_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (UpAcpiNativePrivate));
	G_OBJECT_CLASS (klass)->get_property = up_acpi_native_get_property;
	G_OBJECT_CLASS (klass)->finalize = up_acpi_native_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), UP_ACPI_NATIVE_DRIVER, g_param_spec_string ("driver", "driver", "driver", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), UP_ACPI_NATIVE_UNIT, g_param_spec_int ("unit", "unit", "unit", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), UP_ACPI_NATIVE_PATH, g_param_spec_string ("path", "path", "path", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
}


static void up_acpi_native_instance_init (UpAcpiNative * self) {
	self->priv = UP_ACPI_NATIVE_GET_PRIVATE (self);
}


static void up_acpi_native_finalize (GObject* obj) {
	UpAcpiNative * self;
	self = UP_ACPI_NATIVE (obj);
	_g_free0 (self->priv->_driver);
	_g_free0 (self->priv->_path);
	G_OBJECT_CLASS (up_acpi_native_parent_class)->finalize (obj);
}


GType up_acpi_native_get_type (void) {
	static GType up_acpi_native_type_id = 0;
	if (up_acpi_native_type_id == 0) {
		static const GTypeInfo g_define_type_info = { sizeof (UpAcpiNativeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) up_acpi_native_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UpAcpiNative), 0, (GInstanceInitFunc) up_acpi_native_instance_init, NULL };
		up_acpi_native_type_id = g_type_register_static (G_TYPE_OBJECT, "UpAcpiNative", &g_define_type_info, 0);
	}
	return up_acpi_native_type_id;
}


static void up_acpi_native_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	UpAcpiNative * self;
	self = UP_ACPI_NATIVE (object);
	switch (property_id) {
		case UP_ACPI_NATIVE_DRIVER:
		g_value_set_string (value, up_acpi_native_get_driver (self));
		break;
		case UP_ACPI_NATIVE_UNIT:
		g_value_set_int (value, up_acpi_native_get_unit (self));
		break;
		case UP_ACPI_NATIVE_PATH:
		g_value_set_string (value, up_acpi_native_get_path (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}