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: arvgcfloat
25 * @short_description: Float interface
26 */
27
28 #include <arvgcfloat.h>
29 #include <arvgcfeaturenode.h>
30 #include <arvgc.h>
31 #include <arvmisc.h>
32
33 static void
arv_gc_float_default_init(ArvGcFloatInterface * gc_float_iface)34 arv_gc_float_default_init (ArvGcFloatInterface *gc_float_iface)
35 {
36 }
37
G_DEFINE_INTERFACE(ArvGcFloat,arv_gc_float,G_TYPE_OBJECT)38 G_DEFINE_INTERFACE (ArvGcFloat, arv_gc_float, G_TYPE_OBJECT)
39
40 double
41 arv_gc_float_get_value (ArvGcFloat *gc_float, GError **error)
42 {
43 g_return_val_if_fail (ARV_IS_GC_FLOAT (gc_float), 0.0);
44 g_return_val_if_fail (error == NULL || *error == NULL, 0.0);
45
46 return ARV_GC_FLOAT_GET_INTERFACE (gc_float)->get_value (gc_float, error);
47 }
48
49 void
arv_gc_float_set_value(ArvGcFloat * gc_float,double value,GError ** error)50 arv_gc_float_set_value (ArvGcFloat *gc_float, double value, GError **error)
51 {
52 g_return_if_fail (ARV_IS_GC_FLOAT (gc_float));
53 g_return_if_fail (error == NULL || *error == NULL);
54
55 ARV_GC_FLOAT_GET_INTERFACE (gc_float)->set_value (gc_float, value, error);
56 }
57
58 double
arv_gc_float_get_min(ArvGcFloat * gc_float,GError ** error)59 arv_gc_float_get_min (ArvGcFloat *gc_float, GError **error)
60 {
61 ArvGcFloatInterface *float_interface;
62
63 g_return_val_if_fail (ARV_IS_GC_FLOAT (gc_float), 0.0);
64 g_return_val_if_fail (error == NULL || *error == NULL, 0.0);
65
66 float_interface = ARV_GC_FLOAT_GET_INTERFACE (gc_float);
67
68 if (float_interface->get_min != NULL)
69 return float_interface->get_min (gc_float, error);
70
71 g_set_error (error, ARV_GC_ERROR, ARV_GC_ERROR_PROPERTY_NOT_DEFINED, "<Min> node not found for '%s'",
72 arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_float)));
73
74 return -G_MAXDOUBLE;
75 }
76
77 double
arv_gc_float_get_max(ArvGcFloat * gc_float,GError ** error)78 arv_gc_float_get_max (ArvGcFloat *gc_float, GError **error)
79 {
80 ArvGcFloatInterface *float_interface;
81
82 g_return_val_if_fail (ARV_IS_GC_FLOAT (gc_float), 0.0);
83 g_return_val_if_fail (error == NULL || *error == NULL, 0.0);
84
85 float_interface = ARV_GC_FLOAT_GET_INTERFACE (gc_float);
86
87 if (float_interface->get_max != NULL)
88 return float_interface->get_max (gc_float, error);
89
90 g_set_error (error, ARV_GC_ERROR, ARV_GC_ERROR_PROPERTY_NOT_DEFINED, "<Max> node not found for '%s'",
91 arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_float)));
92
93 return G_MAXDOUBLE;
94 }
95
96 double
arv_gc_float_get_inc(ArvGcFloat * gc_float,GError ** error)97 arv_gc_float_get_inc (ArvGcFloat *gc_float, GError **error)
98 {
99 ArvGcFloatInterface *float_interface;
100
101 g_return_val_if_fail (ARV_IS_GC_FLOAT (gc_float), 0.0);
102 g_return_val_if_fail (error == NULL || *error == NULL, 0.0);
103
104 float_interface = ARV_GC_FLOAT_GET_INTERFACE (gc_float);
105
106 if (float_interface->get_inc != NULL)
107 return float_interface->get_inc (gc_float, error);
108
109 g_set_error (error, ARV_GC_ERROR, ARV_GC_ERROR_PROPERTY_NOT_DEFINED, "<Inc> node not found for '%s'",
110 arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_float)));
111
112 return 1;
113 }
114
115 const char *
arv_gc_float_get_unit(ArvGcFloat * gc_float,GError ** error)116 arv_gc_float_get_unit (ArvGcFloat *gc_float, GError **error)
117 {
118 ArvGcFloatInterface *float_interface;
119
120 g_return_val_if_fail (ARV_IS_GC_FLOAT (gc_float), NULL);
121 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
122
123 float_interface = ARV_GC_FLOAT_GET_INTERFACE (gc_float);
124
125 if (float_interface->get_unit != NULL)
126 return float_interface->get_unit (gc_float, error);
127
128 g_set_error (error, ARV_GC_ERROR, ARV_GC_ERROR_PROPERTY_NOT_DEFINED, "<Unit> node not found for '%s'",
129 arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_float)));
130
131 return NULL;
132 }
133
arv_gc_float_impose_min(ArvGcFloat * gc_float,double minimum,GError ** error)134 void arv_gc_float_impose_min (ArvGcFloat *gc_float, double minimum, GError **error)
135 {
136 ArvGcFloatInterface *float_interface;
137
138 g_return_if_fail (ARV_IS_GC_FLOAT (gc_float));
139 g_return_if_fail (error == NULL || *error == NULL);
140
141 float_interface = ARV_GC_FLOAT_GET_INTERFACE (gc_float);
142
143 if (float_interface->impose_min != NULL)
144 float_interface->impose_min (gc_float, minimum, error);
145 else
146 g_set_error (error, ARV_GC_ERROR, ARV_GC_ERROR_PROPERTY_NOT_DEFINED, "<Min> node not found for '%s'",
147 arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_float)));
148 }
149
arv_gc_float_impose_max(ArvGcFloat * gc_float,double maximum,GError ** error)150 void arv_gc_float_impose_max (ArvGcFloat *gc_float, double maximum, GError **error)
151 {
152 ArvGcFloatInterface *float_interface;
153
154 g_return_if_fail (ARV_IS_GC_FLOAT (gc_float));
155 g_return_if_fail (error == NULL || *error == NULL);
156
157 float_interface = ARV_GC_FLOAT_GET_INTERFACE (gc_float);
158
159 if (float_interface->impose_max != NULL)
160 float_interface->impose_max (gc_float, maximum, error);
161 else
162 g_set_error (error, ARV_GC_ERROR, ARV_GC_ERROR_PROPERTY_NOT_DEFINED, "<Max> node not found for '%s'",
163 arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_float)));
164 }
165