-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy patharvgc.c
328 lines (287 loc) · 10.5 KB
/
arvgc.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/* Aravis - Digital camera library
*
* Copyright © 2009-2012 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., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: Emmanuel Pacaud <emmanuel@gnome.org>
*/
/**
* SECTION:arvgc
* @short_description: Genicam root document class
*
* #ArvGc implements the root document for the storage of the Genicam feature
* nodes. It builds the node tree by parsing an xml file in the Genicam
* standard format. See http://www.genicam.org.
*/
#include <arvgc.h>
#include <arvgcnode.h>
#include <arvgcpropertynode.h>
#include <arvgcindexnode.h>
#include <arvgcvariablenode.h>
#include <arvgcinvalidatornode.h>
#include <arvgcregisterdescriptionnode.h>
#include <arvgcgroupnode.h>
#include <arvgccategory.h>
#include <arvgcenumeration.h>
#include <arvgcenumentry.h>
#include <arvgcintegernode.h>
#include <arvgcfloatnode.h>
#include <arvgcregisternode.h>
#include <arvgcstructentrynode.h>
#include <arvgccommand.h>
#include <arvgcinteger.h>
#include <arvgcfloat.h>
#include <arvgcboolean.h>
#include <arvgcswissknife.h>
#include <arvgcconverter.h>
#include <arvgcport.h>
#include <arvdebug.h>
#include <arvdomparser.h>
#include <string.h>
static GObjectClass *parent_class = NULL;
/* ArvDomNode implementation */
static gboolean
arv_gc_can_append_child (ArvDomNode *self, ArvDomNode *child)
{
return ARV_IS_GC_NODE (child);
}
/* ArvDomDocument implementation */
static ArvDomElement *
arv_gc_create_element (ArvDomDocument *document, const char *tag_name)
{
ArvGcNode *node = NULL;
if (strcmp (tag_name, "Category") == 0)
node = arv_gc_category_new ();
else if (strcmp (tag_name, "Command") == 0)
node = arv_gc_command_new ();
else if (strcmp (tag_name, "Converter") == 0)
node = arv_gc_converter_new ();
else if (strcmp (tag_name, "IntConverter") == 0)
node = arv_gc_converter_new_integer ();
else if (strcmp (tag_name, "IntReg") == 0)
node = arv_gc_register_node_new_integer ();
else if (strcmp (tag_name, "MaskedIntReg") == 0)
node = arv_gc_register_node_new_masked_integer ();
else if (strcmp (tag_name, "FloatReg") == 0)
node = arv_gc_register_node_new_float ();
else if (strcmp (tag_name, "StringReg") == 0)
node = arv_gc_register_node_new_string ();
else if (strcmp (tag_name, "StructReg") == 0)
node = arv_gc_register_node_new_struct_register ();
else if (strcmp (tag_name, "StructEntry") == 0)
node = arv_gc_struct_entry_node_new ();
else if (strcmp (tag_name, "Integer") == 0)
node = arv_gc_integer_node_new ();
else if (strcmp (tag_name, "Float") == 0)
node = arv_gc_float_node_new ();
else if (strcmp (tag_name, "Boolean") == 0)
node = arv_gc_boolean_new ();
else if (strcmp (tag_name, "Enumeration") == 0)
node = arv_gc_enumeration_new ();
else if (strcmp (tag_name, "EnumEntry") == 0)
node = arv_gc_enum_entry_new ();
else if (strcmp (tag_name, "SwissKnife") == 0)
node = arv_gc_swiss_knife_new ();
else if (strcmp (tag_name, "IntSwissKnife") == 0)
node = arv_gc_swiss_knife_new_integer ();
else if (strcmp (tag_name, "Port") == 0)
node = arv_gc_port_new ();
else if (strcmp (tag_name, "pIndex") == 0)
node = arv_gc_index_node_new ();
else if (strcmp (tag_name, "RegisterDescription") == 0)
node = arv_gc_register_description_node_new ();
else if (strcmp (tag_name, "pFeature") == 0)
node = arv_gc_property_node_new_p_feature ();
else if (strcmp (tag_name, "Value") == 0)
node = arv_gc_property_node_new_value ();
else if (strcmp (tag_name, "pValue") == 0)
node = arv_gc_property_node_new_p_value ();
else if (strcmp (tag_name, "Address") == 0)
node = arv_gc_property_node_new_address ();
else if (strcmp (tag_name, "pAddress") == 0)
node = arv_gc_property_node_new_p_address ();
else if (strcmp (tag_name, "Description") == 0)
node = arv_gc_property_node_new_description ();
else if (strcmp (tag_name, "ToolTip") == 0)
node = arv_gc_property_node_new_tooltip ();
else if (strcmp (tag_name, "DisplayName") == 0)
node = arv_gc_property_node_new_display_name ();
else if (strcmp (tag_name, "Min") == 0)
node = arv_gc_property_node_new_minimum ();
else if (strcmp (tag_name, "pMin") == 0)
node = arv_gc_property_node_new_p_minimum ();
else if (strcmp (tag_name, "Max") == 0)
node = arv_gc_property_node_new_maximum ();
else if (strcmp (tag_name, "pMax") == 0)
node = arv_gc_property_node_new_p_maximum ();
else if (strcmp (tag_name, "Inc") == 0)
node = arv_gc_property_node_new_increment ();
else if (strcmp (tag_name, "pInc") == 0)
node = arv_gc_property_node_new_p_increment ();
else if (strcmp (tag_name, "Unit") == 0)
node = arv_gc_property_node_new_unit ();
else if (strcmp (tag_name, "OnValue") == 0)
node = arv_gc_property_node_new_on_value ();
else if (strcmp (tag_name, "OffValue") == 0)
node = arv_gc_property_node_new_off_value ();
else if (strcmp (tag_name, "pIsImplemented") == 0)
node = arv_gc_property_node_new_p_is_implemented ();
else if (strcmp (tag_name, "pIsAvailable") == 0)
node = arv_gc_property_node_new_p_is_available ();
else if (strcmp (tag_name, "pIsLocked") == 0)
node = arv_gc_property_node_new_p_is_locked ();
else if (strcmp (tag_name, "Length") == 0)
node = arv_gc_property_node_new_length ();
else if (strcmp (tag_name, "pLength") == 0)
node = arv_gc_property_node_new_p_length ();
else if (strcmp (tag_name, "pPort") == 0)
node = arv_gc_property_node_new_p_port ();
else if (strcmp (tag_name, "pVariable") == 0)
node = arv_gc_variable_node_new ();
else if (strcmp (tag_name, "Formula") == 0)
node = arv_gc_property_node_new_formula ();
else if (strcmp (tag_name, "FormulaTo") == 0)
node = arv_gc_property_node_new_formula_to ();
else if (strcmp (tag_name, "FormulaFrom") == 0)
node = arv_gc_property_node_new_formula_from ();
else if (strcmp (tag_name, "Expression") == 0)
node = arv_gc_property_node_new_expression ();
else if (strcmp (tag_name, "Constant") == 0)
node = arv_gc_property_node_new_constant ();
else if (strcmp (tag_name, "AccessMode") == 0)
node = arv_gc_property_node_new_access_mode ();
else if (strcmp (tag_name, "Cachable") == 0)
node = arv_gc_property_node_new_cachable ();
else if (strcmp (tag_name, "PollingTime") == 0)
node = arv_gc_property_node_new_polling_time ();
else if (strcmp (tag_name, "Endianess") == 0)
node = arv_gc_property_node_new_endianess ();
else if (strcmp (tag_name, "Sign") == 0)
node = arv_gc_property_node_new_sign ();
else if (strcmp (tag_name, "LSB") == 0)
node = arv_gc_property_node_new_lsb ();
else if (strcmp (tag_name, "MSB") == 0)
node = arv_gc_property_node_new_msb ();
else if (strcmp (tag_name, "Bit") == 0)
node = arv_gc_property_node_new_bit ();
else if (strcmp (tag_name, "pInvalidator") == 0)
node = arv_gc_invalidator_node_new ();
else if (strcmp (tag_name, "CommandValue") == 0)
node = arv_gc_property_node_new_command_value ();
else if (strcmp (tag_name, "pCommandValue") == 0)
node = arv_gc_property_node_new_p_command_value ();
else if (strcmp (tag_name, "Group") == 0)
node = arv_gc_group_node_new ();
else
arv_debug_dom ("[Genicam::create_element] Unknow tag (%s)", tag_name);
return ARV_DOM_ELEMENT (node);
}
/* ArvGc implementation */
/**
* arv_gc_get_node:
* @genicam: a #ArvGc object
* @name: node name
*
* Retrieves a genicam node by name.
*
* Return value: (transfer none): a #ArvGcNode, null if not found.
*/
ArvGcNode *
arv_gc_get_node (ArvGc *genicam, const char *name)
{
g_return_val_if_fail (ARV_IS_GC (genicam), NULL);
g_return_val_if_fail (name != NULL, NULL);
return g_hash_table_lookup (genicam->nodes, name);
}
/**
* arv_gc_get_device:
* @genicam: a #ArvGc object
*
* Retrieves the device handled by this genicam interface. The device is used for register access.
*
* Return value: (transfer none): a #ArvDevice.
*/
ArvDevice *
arv_gc_get_device (ArvGc *genicam)
{
g_return_val_if_fail (ARV_IS_GC (genicam), NULL);
return genicam->device;
}
void
arv_gc_register_feature_node (ArvGc *genicam, ArvGcFeatureNode *node)
{
const char *name;
g_return_if_fail (ARV_IS_GC (genicam));
g_return_if_fail (ARV_IS_GC_FEATURE_NODE (node));
name = arv_gc_feature_node_get_name (node);
if (name == NULL)
return;
g_object_ref (node);
g_hash_table_remove (genicam->nodes, (char *) name);
g_hash_table_insert (genicam->nodes, (char *) name, node);
arv_log_genicam ("[Gc::register_feature_node] Register node '%s' [%s]", name,
arv_dom_node_get_node_name (ARV_DOM_NODE (node)));
}
void
arv_gc_set_default_node_data (ArvGc *genicam, const char *node_name, const char *node_data)
{
g_return_if_fail (ARV_IS_GC (genicam));
g_return_if_fail (node_name != NULL);
g_return_if_fail (node_data != NULL);
if (arv_gc_get_node (genicam, node_name) != NULL)
return;
arv_dom_document_append_from_memory (ARV_DOM_DOCUMENT (genicam), NULL, node_data, -1, NULL);
}
ArvGc *
arv_gc_new (ArvDevice *device, const void *xml, size_t size)
{
ArvDomDocument *document;
ArvGc *genicam;
document = arv_dom_document_new_from_memory (xml, size, NULL);
if (!ARV_IS_GC (document)) {
if (document != NULL)
g_object_unref (document);
return NULL;
}
genicam = ARV_GC (document);
genicam->device = device;
return genicam;
}
static void
arv_gc_init (ArvGc *genicam)
{
genicam->nodes = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
}
static void
arv_gc_finalize (GObject *object)
{
ArvGc *genicam = ARV_GC (object);
g_hash_table_unref (genicam->nodes);
parent_class->finalize (object);
}
static void
arv_gc_class_init (ArvGcClass *node_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (node_class);
ArvDomNodeClass *d_node_class = ARV_DOM_NODE_CLASS (node_class);
ArvDomDocumentClass *d_document_class = ARV_DOM_DOCUMENT_CLASS (node_class);
parent_class = g_type_class_peek_parent (node_class);
object_class->finalize = arv_gc_finalize;
d_node_class->can_append_child = arv_gc_can_append_child;
d_document_class->create_element = arv_gc_create_element;
}
G_DEFINE_TYPE (ArvGc, arv_gc, ARV_TYPE_DOM_DOCUMENT)