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
|
#include "uca/uca-camera.h"
#include "kiro/kiro-messenger.h"
typedef enum {
KIROCS_UPDATE,
KIROCS_INSTALL,
KIROCS_READY,
KIROCS_RPC,
KIROCS_EXIT
}KiroCsCommands;
typedef struct {
guint32 id;
guint32 size;
gboolean scalar;
gchar type[2];
gchar val[1];
} PropUpdate;
typedef struct {
guint32 str_len;
gchar str[1];
}StrProp;
typedef struct {
GType value_type;
guint32 name_len;
union PSpecs {
GParamSpecBoolean bool_spec;
GParamSpecChar char_spec;
GParamSpecInt int_spec;
GParamSpecUInt uint_spec;
GParamSpecLong long_spec;
GParamSpecULong ulong_spec;
GParamSpecInt64 int64_spec;
GParamSpecUInt64 uint64_spec;
GParamSpecFloat float_spec;
GParamSpecDouble double_spec;
StrProp str_spec;
} spec;
gchar name[1];
} PropertyRequisition;
//Forward declaration of the trigger enums for type handling
GType uca_camera_trigger_source_get_type (void) G_GNUC_CONST;
#define UCA_TYPE_CAMERA_TRIGGER_SOURCE (uca_camera_trigger_source_get_type ())
GType uca_camera_trigger_type_get_type (void) G_GNUC_CONST;
#define UCA_TYPE_CAMERA_TRIGGER_TYPE (uca_camera_trigger_type_get_type ())
gchar
gtype_to_gvariant_class (GType type)
{
gchar ret = '*';
switch (type) {
case G_TYPE_BOOLEAN:
ret = G_VARIANT_CLASS_BOOLEAN;
break;
case G_TYPE_CHAR:
ret = G_VARIANT_CLASS_BYTE;
break;
case G_TYPE_INT:
ret = G_VARIANT_CLASS_INT32;
break;
case G_TYPE_ENUM:
ret = G_VARIANT_CLASS_INT32;
break;
case G_TYPE_UINT:
ret = G_VARIANT_CLASS_UINT32;
break;
case G_TYPE_LONG:
ret = G_VARIANT_CLASS_INT64;
break;
case G_TYPE_ULONG:
ret = G_VARIANT_CLASS_UINT64;
break;
case G_TYPE_INT64:
ret = G_VARIANT_CLASS_INT64;
break;
case G_TYPE_UINT64:
ret = G_VARIANT_CLASS_UINT64;
break;
case G_TYPE_FLOAT:
ret = G_VARIANT_CLASS_DOUBLE;
break;
case G_TYPE_DOUBLE:
ret = G_VARIANT_CLASS_DOUBLE;
break;
default:
//ERROR
break;
}
return ret;
}
#define GOBJECT_SET(OBJ, PROP, TYPE, DATA) { \
g_object_set (OBJ, \
PROP, *(TYPE *)DATA, \
NULL); \
}
void
update_property_scalar (GObject *cam, const gchar *prop, GType type, gulong handler, gpointer data)
{
g_debug ("Updating %s, with handler %lu", prop, handler);
g_signal_handler_block (cam, handler);
switch (type) {
case G_TYPE_BOOLEAN:
GOBJECT_SET (cam, prop, gboolean, data);
break;
case G_TYPE_CHAR:
GOBJECT_SET (cam, prop, gchar, data);
break;
case G_TYPE_INT:
GOBJECT_SET (cam, prop, gint, data);
break;
case G_TYPE_ENUM:
GOBJECT_SET (cam, prop, gint, data);
break;
case G_TYPE_UINT:
GOBJECT_SET (cam, prop, guint, data);
break;
case G_TYPE_LONG:
GOBJECT_SET (cam, prop, glong, data);
break;
case G_TYPE_ULONG:
GOBJECT_SET (cam, prop, gulong, data);
break;
case G_TYPE_INT64:
GOBJECT_SET (cam, prop, gint64, data);
break;
case G_TYPE_UINT64:
GOBJECT_SET (cam, prop, guint64, data);
break;
case G_TYPE_FLOAT:
GOBJECT_SET (cam, prop, gfloat, data);
break;
case G_TYPE_DOUBLE:
GOBJECT_SET (cam, prop, gdouble, data);
break;
default:
//TRIGGER_TYPE and TRIGGER_SOURCE are not statically typed and can
//not be used in a switch statement...
if (type == UCA_TYPE_CAMERA_TRIGGER_SOURCE) {
GOBJECT_SET (cam, prop, gint, data);
break;
}
if (type == UCA_TYPE_CAMERA_TRIGGER_TYPE) {
GOBJECT_SET (cam, prop, gint, data);
break;
}
g_critical ("Type %s not handled! (SET)", g_type_name (type));
break;
}
g_signal_handler_unblock (cam, handler);
}
#define GOBJECT_GET(OBJ, PROP, TYPE, GTYPE) { \
TYPE tmp; \
gchar *gvclass = g_malloc0 (2); \
gvclass[0] = gtype_to_gvariant_class (GTYPE); \
g_object_get (OBJ, \
PROP, &tmp, \
NULL); \
ret = g_variant_new (gvclass, tmp); \
g_free (gvclass); \
}
GVariant*
read_property_scalar (GObject *cam, const gchar *prop, GType type)
{
GVariant *ret = NULL;
switch (type) {
case G_TYPE_BOOLEAN:
GOBJECT_GET (cam, prop, gboolean, type);
break;
case G_TYPE_CHAR:
GOBJECT_GET (cam, prop, gchar, type);
break;
case G_TYPE_INT:
GOBJECT_GET (cam, prop, gint, type);
break;
case G_TYPE_ENUM:
GOBJECT_GET (cam, prop, gint, type);
break;
case G_TYPE_UINT:
GOBJECT_GET (cam, prop, guint, type);
break;
case G_TYPE_LONG:
GOBJECT_GET (cam, prop, glong, type);
break;
case G_TYPE_ULONG:
GOBJECT_GET (cam, prop, gulong, type);
break;
case G_TYPE_INT64:
GOBJECT_GET (cam, prop, gint64, type);
break;
case G_TYPE_UINT64:
GOBJECT_GET (cam, prop, guint64, type);
break;
case G_TYPE_FLOAT:
GOBJECT_GET (cam, prop, gfloat, type);
break;
case G_TYPE_DOUBLE:
GOBJECT_GET (cam, prop, gdouble, type);
break;
default:
//TRIGGER_TYPE and TRIGGER_SOURCE are not statically typed and can
//not be used in a switch statement...
if (type == UCA_TYPE_CAMERA_TRIGGER_SOURCE) {
GOBJECT_GET (cam, prop, gint, type);
break;
}
if (type == UCA_TYPE_CAMERA_TRIGGER_TYPE) {
GOBJECT_GET (cam, prop, gint, type);
break;
}
g_critical ("Type %s not handled! (GET)", g_type_name (type));
break;
}
return ret;
}
|