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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
|
/* Copyright (C) 2011, 2012 Matthias Vogelgesang <matthias.vogelgesang@kit.edu>
(Karlsruhe Institute of Technology)
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.1 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 St, Fifth Floor, Boston, MA 02110, USA */
#ifndef __UCA_KIRO_CAMERA_H
#define __UCA_KIRO_CAMERA_H
#include <glib-object.h>
#include "uca/uca-camera.h"
#include "kiro/kiro-messenger.h"
G_BEGIN_DECLS
#define UCA_TYPE_KIRO_CAMERA (uca_kiro_camera_get_type())
#define UCA_KIRO_CAMERA(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), UCA_TYPE_KIRO_CAMERA, UcaKiroCamera))
#define UCA_IS_KIRO_CAMERA(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), UCA_TYPE_KIRO_CAMERA))
#define UCA_KIRO_CAMERA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), UCA_TYPE_KIRO_CAMERA, UcaKiroCameraClass))
#define UCA_IS_KIRO_CAMERA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), UCA_TYPE_KIRO_CAMERA))
#define UCA_KIRO_CAMERA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), UCA_TYPE_KIRO_CAMERA, UcaKiroCameraClass))
#define UCA_KIRO_CAMERA_ERROR uca_kiro_camera_error_quark()
GQuark uca_kiro_camera_error_quark(void);
typedef enum {
UCA_KIRO_CAMERA_ERROR_MISSING_ADDRESS = UCA_CAMERA_ERROR_END_OF_STREAM,
UCA_KIRO_CAMERA_ERROR_ADDRESS_WRONG_FORMAT,
UCA_KIRO_CAMERA_ERROR_KIRO_CONNECTION_FAILED
} UcaKiroCameraError;
typedef struct _UcaKiroCamera UcaKiroCamera;
typedef struct _UcaKiroCameraClass UcaKiroCameraClass;
typedef struct _UcaKiroCameraPrivate UcaKiroCameraPrivate;
/**
* UcaKiroCamera:
*
* Creates #UcaKiroCamera instances by loading corresponding shared objects. The
* contents of the #UcaKiroCamera structure are private and should only be
* accessed via the provided API.
*/
struct _UcaKiroCamera {
/*< private >*/
UcaCamera parent;
UcaKiroCameraPrivate *priv;
};
/**
* UcaKiroCameraClass:
*
* #UcaKiroCamera class
*/
struct _UcaKiroCameraClass {
/*< private >*/
UcaCameraClass parent;
};
G_END_DECLS
//HELPER FUNCTIONS AND CONSTRUCTS FOR SERVER AND CAMERA PLUGIN
typedef enum {
KIROCS_UPDATE,
KIROCS_FETCH,
KIROCS_INSTALL,
KIROCS_READY,
KIROCS_RPC,
KIROCS_EXIT
} KiroCsCommands;
typedef enum {
KIROCS_RPC_START_RECORDING,
KIROCS_RPC_STOP_RECORDING,
KIROCS_RPC_START_READOUT,
KIROCS_RPC_STOP_READOUT,
KIROCS_RPC_TRIGGER,
KIROCS_RPC_GRAB,
KIROCS_RPC_READOUT
// KIROCS_RPC_WRITE is currently not supported
} KiroCsRPC;
typedef struct {
guint32 id;
guint32 size;
gboolean scalar;
} PropUpdate;
typedef struct {
PropUpdate base;
guint64 prop_raw;
} PropUpdateScalar;
typedef struct {
PropUpdate base;
gchar str[1];
} PropUpdateString;
typedef struct {
guint32 id;
GType value_type;
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;
} 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;
}
#define GVALUE_TO_GVARIANT(VALUE, FUNC, TYPE, GTYPE) { \
TYPE tmp; \
gchar *gvclass = g_malloc0 (2); \
gvclass[0] = gtype_to_gvariant_class (GTYPE); \
tmp = FUNC (VALUE); \
ret = g_variant_new (gvclass, tmp); \
g_free (gvclass); \
}
GVariant*
variant_from_scalar (GValue *value)
{
GVariant *ret = NULL;
GType type = G_VALUE_TYPE (value);
switch (type) {
case G_TYPE_BOOLEAN:
GVALUE_TO_GVARIANT (value, g_value_get_boolean, gboolean, type);
break;
case G_TYPE_CHAR:
GVALUE_TO_GVARIANT (value, g_value_get_char, gchar, type);
break;
case G_TYPE_INT:
GVALUE_TO_GVARIANT (value, g_value_get_int, gint, type);
break;
case G_TYPE_ENUM:
GVALUE_TO_GVARIANT (value, g_value_get_int, gint, type);
break;
case G_TYPE_UINT:
GVALUE_TO_GVARIANT (value, g_value_get_uint, guint, type);
break;
case G_TYPE_LONG:
GVALUE_TO_GVARIANT (value, g_value_get_long, glong, type);
break;
case G_TYPE_ULONG:
GVALUE_TO_GVARIANT (value, g_value_get_ulong, gulong, type);
break;
case G_TYPE_INT64:
GVALUE_TO_GVARIANT (value, g_value_get_int64, gint64, type);
break;
case G_TYPE_UINT64:
GVALUE_TO_GVARIANT (value, g_value_get_uint64, guint64, type);
break;
case G_TYPE_FLOAT:
GVALUE_TO_GVARIANT (value, g_value_get_float, gfloat, type);
break;
case G_TYPE_DOUBLE:
GVALUE_TO_GVARIANT (value, g_value_get_double, 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) {
GVALUE_TO_GVARIANT (value, g_value_get_int, gint, type);
break;
}
if (type == UCA_TYPE_CAMERA_TRIGGER_TYPE) {
GVALUE_TO_GVARIANT (value, g_value_get_int, gint, type);
break;
}
g_critical ("Type %s not handled! (GET)", g_type_name (type));
break;
}
return ret;
}
guint
property_id_from_name(const gchar* name, guint n_props, GParamSpec **props)
{
guint idx = 0;
gboolean found = FALSE;
for (;idx < n_props; ++idx) {
if (0 == g_strcmp0(name, props[idx]->name)) {
found = TRUE;
break;
}
}
return found ? (idx + 1) : 0;
}
void
g_value_write_to_raw_data (const GValue *value, gpointer raw)
{
GType type = G_VALUE_TYPE (value);
switch (type) {
case G_TYPE_BOOLEAN:
*(gboolean *)raw = g_value_get_boolean (value);
break;
case G_TYPE_CHAR:
*(gchar *)raw = g_value_get_char (value);
break;
case G_TYPE_INT:
*(gint *)raw = g_value_get_int (value);
break;
case G_TYPE_ENUM:
*(gint *)raw = g_value_get_enum (value);
break;
case G_TYPE_UINT:
*(guint *)raw = g_value_get_uint (value);
break;
case G_TYPE_LONG:
*(glong *)raw = g_value_get_long (value);
break;
case G_TYPE_ULONG:
*(gulong *)raw = g_value_get_ulong (value);
break;
case G_TYPE_INT64:
*(gint64 *)raw = g_value_get_int64 (value);
break;
case G_TYPE_UINT64:
*(guint64 *)raw = g_value_get_uint64 (value);
break;
case G_TYPE_FLOAT:
*(gfloat *)raw = g_value_get_float (value);
break;
case G_TYPE_DOUBLE:
*(gdouble *)raw = g_value_get_double (value);
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) {
*(gint *)raw = g_value_get_int (value);
break;
}
if (type == UCA_TYPE_CAMERA_TRIGGER_TYPE) {
*(gint *)raw = g_value_get_int (value);
break;
}
g_critical ("Type %s not handled! (GET)", g_type_name (type));
break;
}
}
void
g_value_set_from_raw_data (GValue *value, gpointer raw)
{
GType type = G_VALUE_TYPE (value);
switch (type) {
case G_TYPE_BOOLEAN:
g_value_set_boolean (value, *(gboolean *)raw);
break;
case G_TYPE_CHAR:
g_value_set_char (value, *(gchar *)raw);
break;
case G_TYPE_INT:
g_value_set_int (value, *(gint *)raw);
break;
case G_TYPE_ENUM:
g_value_set_enum (value, *(gint *)raw);
break;
case G_TYPE_UINT:
g_value_set_uint (value, *(guint *)raw);
break;
case G_TYPE_LONG:
g_value_set_long (value, *(glong *)raw);
break;
case G_TYPE_ULONG:
g_value_set_ulong (value, *(gulong *)raw);
break;
case G_TYPE_INT64:
g_value_set_int64 (value, *(gint64 *)raw);
break;
case G_TYPE_UINT64:
g_value_set_uint64 (value, *(guint64 *)raw);
break;
case G_TYPE_FLOAT:
g_value_set_float (value, *(gfloat *)raw);
break;
case G_TYPE_DOUBLE:
g_value_set_double (value, *(gdouble *)raw);
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) {
g_value_set_enum (value, *(gint *)raw);
break;
}
if (type == UCA_TYPE_CAMERA_TRIGGER_TYPE) {
g_value_set_enum (value, *(gint *)raw);
break;
}
g_critical ("Type %s not handled! (SET)", g_type_name (type));
break;
}
}
#endif
|