1 /* Aravis - Digital camera library
2 *
3 * Copyright © 2009-2010 Emmanuel Pacaud
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 * Author: Emmanuel Pacaud <emmanuel@gnome.org>
21 */
22
23 /**
24 * SECTION: arvgccommand
25 * @short_description: Class for Command nodes
26 */
27
28 #include <arvgccommand.h>
29 #include <arvgcinteger.h>
30 #include <arvgcport.h>
31 #include <arvgc.h>
32 #include <arvmisc.h>
33 #include <arvdebug.h>
34 #include <stdlib.h>
35 #include <string.h>
36
37 static GObjectClass *parent_class = NULL;
38
39 /* ArvGcFeatureNode implementation */
40
41 static const char *
arv_gc_command_get_node_name(ArvDomNode * node)42 arv_gc_command_get_node_name (ArvDomNode *node)
43 {
44 return "Command";
45 }
46
47 static void
arv_gc_command_post_new_child(ArvDomNode * self,ArvDomNode * child)48 arv_gc_command_post_new_child (ArvDomNode *self, ArvDomNode *child)
49 {
50 ArvGcCommand *node = ARV_GC_COMMAND (self);
51
52 if (ARV_IS_GC_PROPERTY_NODE (child)) {
53 ArvGcPropertyNode *property_node = ARV_GC_PROPERTY_NODE (child);
54
55 switch (arv_gc_property_node_get_node_type (property_node)) {
56 case ARV_GC_PROPERTY_NODE_TYPE_VALUE:
57 case ARV_GC_PROPERTY_NODE_TYPE_P_VALUE:
58 node->value = property_node;
59 break;
60 case ARV_GC_PROPERTY_NODE_TYPE_COMMAND_VALUE:
61 case ARV_GC_PROPERTY_NODE_TYPE_P_COMMAND_VALUE:
62 node->command_value = property_node;
63 break;
64 default:
65 ARV_DOM_NODE_CLASS (parent_class)->post_new_child (self, child);
66 break;
67 }
68 }
69 }
70
71 static void
arv_gc_command_pre_remove_child(ArvDomNode * self,ArvDomNode * child)72 arv_gc_command_pre_remove_child (ArvDomNode *self, ArvDomNode *child)
73 {
74 g_assert_not_reached ();
75 }
76
77 /* ArvGcFeatureNode implementation */
78
79 /* ArvGcCommand implementation */
80
81 void
arv_gc_command_execute(ArvGcCommand * gc_command,GError ** error)82 arv_gc_command_execute (ArvGcCommand *gc_command, GError **error)
83 {
84 ArvGc *genicam;
85 GError *local_error = NULL;
86 gint64 command_value;
87
88 g_return_if_fail (ARV_IS_GC_COMMAND (gc_command));
89 genicam = arv_gc_node_get_genicam (ARV_GC_NODE (gc_command));
90 g_return_if_fail (ARV_IS_GC (genicam));
91
92 if (gc_command->value == NULL)
93 return;
94
95 command_value = arv_gc_property_node_get_int64 (gc_command->command_value, &local_error);
96
97 if (local_error != NULL) {
98 g_propagate_error (error, local_error);
99 return;
100 }
101
102 arv_gc_property_node_set_int64 (gc_command->value, command_value, &local_error);
103
104 if (local_error != NULL) {
105 g_propagate_error (error, local_error);
106 return;
107 }
108
109 arv_log_genicam ("[GcCommand::execute] %s (0x%x)",
110 arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_command)),
111 command_value);
112 }
113
114 ArvGcNode *
arv_gc_command_new(void)115 arv_gc_command_new (void)
116 {
117 ArvGcNode *node;
118
119 node = g_object_new (ARV_TYPE_GC_COMMAND, NULL);
120
121 return node;
122 }
123
124 static void
arv_gc_command_init(ArvGcCommand * gc_command)125 arv_gc_command_init (ArvGcCommand *gc_command)
126 {
127 }
128
129 static void
arv_gc_command_finalize(GObject * object)130 arv_gc_command_finalize (GObject *object)
131 {
132 parent_class->finalize (object);
133 }
134
135 static void
arv_gc_command_class_init(ArvGcCommandClass * this_class)136 arv_gc_command_class_init (ArvGcCommandClass *this_class)
137 {
138 GObjectClass *object_class = G_OBJECT_CLASS (this_class);
139 ArvDomNodeClass *dom_node_class = ARV_DOM_NODE_CLASS (this_class);
140
141 parent_class = g_type_class_peek_parent (this_class);
142
143 object_class->finalize = arv_gc_command_finalize;
144 dom_node_class->get_node_name = arv_gc_command_get_node_name;
145 dom_node_class->post_new_child = arv_gc_command_post_new_child;
146 dom_node_class->pre_remove_child = arv_gc_command_pre_remove_child;
147 }
148
149 G_DEFINE_TYPE (ArvGcCommand, arv_gc_command, ARV_TYPE_GC_FEATURE_NODE)
150