forked from AravisProject/aravis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharvgcboolean.c
286 lines (228 loc) · 7.69 KB
/
arvgcboolean.c
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/* Aravis - Digital camera library
*
* Copyright © 2009-2022 Emmanuel Pacaud
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* Author: Emmanuel Pacaud <[email protected]>
*/
/**
* SECTION: arvgcboolean
* @short_description: Class for Boolean nodes
*/
#include <arvgcboolean.h>
#include <arvgcinteger.h>
#include <arvgcfeaturenodeprivate.h>
#include <arvgc.h>
#include <arvmisc.h>
#include <string.h>
static GObjectClass *parent_class = NULL;
struct _ArvGcBoolean {
ArvGcFeatureNode node;
ArvGcPropertyNode *value;
ArvGcPropertyNode *on_value;
ArvGcPropertyNode *off_value;
};
struct _ArvGcBooleanClass {
ArvGcFeatureNodeClass parent_class;
};
G_DEFINE_TYPE (ArvGcBoolean, arv_gc_boolean, ARV_TYPE_GC_FEATURE_NODE);
/* ArvDomNode implementation */
static const char *
arv_gc_boolean_get_node_name (ArvDomNode *node)
{
return "Boolean";
}
static void
arv_gc_boolean_post_new_child (ArvDomNode *self, ArvDomNode *child)
{
ArvGcBoolean *node = ARV_GC_BOOLEAN (self);
if (ARV_IS_GC_PROPERTY_NODE (child)) {
ArvGcPropertyNode *property_node = ARV_GC_PROPERTY_NODE (child);
switch (arv_gc_property_node_get_node_type (property_node)) {
case ARV_GC_PROPERTY_NODE_TYPE_VALUE:
case ARV_GC_PROPERTY_NODE_TYPE_P_VALUE:
node->value = property_node;
break;
case ARV_GC_PROPERTY_NODE_TYPE_ON_VALUE:
node->on_value = property_node;
break;
case ARV_GC_PROPERTY_NODE_TYPE_OFF_VALUE:
node->off_value = property_node;
break;
default:
ARV_DOM_NODE_CLASS (parent_class)->post_new_child (self, child);
break;
}
}
}
static void
arv_gc_boolean_pre_remove_child (ArvDomNode *self, ArvDomNode *child)
{
g_assert_not_reached ();
}
/* ArvGcBoolean implementation */
static gint64
arv_gc_boolean_get_on_value (ArvGcBoolean *gc_boolean, GError **error)
{
gint64 on_value;
GError *local_error = NULL;
if (gc_boolean->on_value == NULL)
return 1;
on_value = arv_gc_property_node_get_int64 (gc_boolean->on_value, &local_error);
if (local_error != NULL) {
g_propagate_prefixed_error (error, local_error, "[%s] ",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_boolean)));
return 1;
}
return on_value;
}
static gint64
arv_gc_boolean_get_off_value (ArvGcBoolean *gc_boolean, GError **error)
{
gint64 off_value;
GError *local_error = NULL;
if (gc_boolean->off_value == NULL)
return 0;
off_value = arv_gc_property_node_get_int64 (gc_boolean->off_value, &local_error);
if (local_error != NULL) {
g_propagate_prefixed_error (error, local_error, "[%s] ",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_boolean)));
return 0;
}
return off_value;
}
/**
* arv_gc_boolean_get_value:
* @gc_boolean: a #ArvGcBoolean
* @error: a #GError placeholder, %NULL to ignore
*
* Returns: the feature value.
*
* Since: 0.8.0
*/
gboolean
arv_gc_boolean_get_value (ArvGcBoolean *gc_boolean, GError **error)
{
gboolean value;
gint64 on_value;
GError *local_error = NULL;
g_return_val_if_fail (ARV_IS_GC_BOOLEAN (gc_boolean), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (gc_boolean->value == NULL)
return FALSE;
if (!arv_gc_feature_node_check_read_access (ARV_GC_FEATURE_NODE (gc_boolean), error))
return FALSE;
value = arv_gc_property_node_get_int64 (gc_boolean->value, &local_error);
if (local_error != NULL) {
g_propagate_prefixed_error (error, local_error, "[%s] ",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_boolean)));
return FALSE;
}
on_value = arv_gc_boolean_get_on_value (gc_boolean, &local_error);
if (local_error != NULL) {
g_propagate_prefixed_error (error, local_error, "[%s] ",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_boolean)));
return FALSE;
}
return value == on_value;
}
/**
* arv_gc_boolean_get_value_gi: (rename-to arv_gc_boolean_get_value)
* @gc_boolean: a #ArvGcBoolean
* @value: (out): feature value
* @error: a #GError placeholder, %NULL to ignore
*
* Get the feature value.
*
* Since: 0.8.0
*/
void
arv_gc_boolean_get_value_gi (ArvGcBoolean *gc_boolean, gboolean *value, GError **error)
{
GError *local_error = NULL;
g_return_if_fail (value != NULL);
*value = arv_gc_boolean_get_value (gc_boolean, &local_error);
if (local_error != NULL)
g_propagate_prefixed_error (error, local_error, "[%s] ",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_boolean)));
}
void
arv_gc_boolean_set_value (ArvGcBoolean *gc_boolean, gboolean v_boolean, GError **error)
{
gboolean value;
GError *local_error = NULL;
g_return_if_fail (ARV_IS_GC_BOOLEAN (gc_boolean));
g_return_if_fail (error == NULL || *error == NULL);
if (!arv_gc_feature_node_check_write_access (ARV_GC_FEATURE_NODE (gc_boolean), error))
return;
if (v_boolean)
value = arv_gc_boolean_get_on_value (gc_boolean, &local_error);
else
value = arv_gc_boolean_get_off_value (gc_boolean, &local_error);
if (local_error != NULL) {
g_propagate_prefixed_error (error, local_error, "[%s] ",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_boolean)));
return;
}
arv_gc_feature_node_increment_change_count (ARV_GC_FEATURE_NODE (gc_boolean));
arv_gc_property_node_set_int64 (gc_boolean->value, value, &local_error);
if (local_error != NULL)
g_propagate_prefixed_error (error, local_error, "[%s] ",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_boolean)));
}
static ArvGcFeatureNode *
arv_gc_boolean_get_linked_feature (ArvGcFeatureNode *gc_feature_node)
{
ArvGcBoolean *gc_boolean = ARV_GC_BOOLEAN (gc_feature_node);
ArvGcNode *pvalue_node = NULL;
if (gc_boolean->value == NULL)
return NULL;
pvalue_node = arv_gc_property_node_get_linked_node (gc_boolean->value);
if (ARV_IS_GC_FEATURE_NODE (pvalue_node))
return ARV_GC_FEATURE_NODE (pvalue_node);
return NULL;
}
ArvGcNode *
arv_gc_boolean_new (void)
{
ArvGcNode *node;
node = g_object_new (ARV_TYPE_GC_BOOLEAN, NULL);
return node;
}
static void
arv_gc_boolean_init (ArvGcBoolean *gc_boolean)
{
}
static void
arv_gc_boolean_finalize (GObject *object)
{
parent_class->finalize (object);
}
static void
arv_gc_boolean_class_init (ArvGcBooleanClass *this_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (this_class);
ArvDomNodeClass *dom_node_class = ARV_DOM_NODE_CLASS (this_class);
ArvGcFeatureNodeClass *gc_feature_node_class = ARV_GC_FEATURE_NODE_CLASS (this_class);
parent_class = g_type_class_peek_parent (this_class);
object_class->finalize = arv_gc_boolean_finalize;
dom_node_class->get_node_name = arv_gc_boolean_get_node_name;
dom_node_class->post_new_child = arv_gc_boolean_post_new_child;
dom_node_class->pre_remove_child = arv_gc_boolean_pre_remove_child;
gc_feature_node_class->get_linked_feature = arv_gc_boolean_get_linked_feature;
gc_feature_node_class->default_access_mode = ARV_GC_ACCESS_MODE_RW;
}