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
|
/* 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 */
#include <glib.h>
#include "uca-camera.h"
#define UCA_CAMERA_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), UCA_TYPE_CAMERA, UcaCameraPrivate))
G_DEFINE_TYPE(UcaCamera, uca_camera, G_TYPE_OBJECT)
/**
* UcaCameraError:
* @UCA_CAMERA_ERROR_RECORDING: Camera is already recording
* @UCA_CAMERA_ERROR_NOT_RECORDING: Camera is not recording
*/
GQuark uca_camera_error_quark()
{
return g_quark_from_static_string("uca-camera-error-quark");
}
enum {
LAST_SIGNAL
};
enum {
PROP_0 = 0,
PROP_SENSOR_WIDTH,
PROP_SENSOR_HEIGHT,
PROP_SENSOR_BITDEPTH,
PROP_SENSOR_HORIZONTAL_BINNING,
PROP_SENSOR_HORIZONTAL_BINNINGS,
PROP_SENSOR_VERTICAL_BINNING,
PROP_SENSOR_VERTICAL_BINNINGS,
PROP_HAS_STREAMING,
PROP_HAS_CAMRAM_RECORDING,
PROP_IS_RECORDING,
N_PROPERTIES
};
struct _UcaCameraPrivate {
gboolean recording;
};
static GParamSpec *camera_properties[N_PROPERTIES] = { NULL, };
/* static guint camera_signals[LAST_SIGNAL] = { 0 }; */
static void uca_camera_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
static void uca_camera_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
UcaCameraPrivate *priv = UCA_CAMERA_GET_PRIVATE(object);
switch (property_id) {
case PROP_IS_RECORDING:
g_value_set_boolean(value, priv->recording);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
}
static void uca_camera_class_init(UcaCameraClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gobject_class->set_property = uca_camera_set_property;
gobject_class->get_property = uca_camera_get_property;
klass->start_recording = NULL;
klass->stop_recording = NULL;
klass->grab = NULL;
camera_properties[PROP_SENSOR_WIDTH] =
g_param_spec_uint("sensor-width",
"Width of sensor",
"Width of the sensor in pixels",
1, G_MAXUINT, 1,
G_PARAM_READABLE);
camera_properties[PROP_SENSOR_HEIGHT] =
g_param_spec_uint("sensor-height",
"Height of sensor",
"Height of the sensor in pixels",
1, G_MAXUINT, 1,
G_PARAM_READABLE);
camera_properties[PROP_SENSOR_BITDEPTH] =
g_param_spec_uint("sensor-bitdepth",
"Number of bits per pixel",
"Number of bits per pixel",
1, 32, 1,
G_PARAM_READABLE);
camera_properties[PROP_SENSOR_HORIZONTAL_BINNING] =
g_param_spec_uint("sensor-horizontal-binning",
"Horizontal binning",
"Number of sensor ADCs that are combined to one pixel in horizontal direction",
1, G_MAXUINT, 1,
G_PARAM_READWRITE);
camera_properties[PROP_SENSOR_HORIZONTAL_BINNINGS] =
g_param_spec_value_array("sensor-horizontal-binnings",
"Array of possible binnings",
"Array of possible binnings in horizontal direction",
g_param_spec_uint(
"sensor-horizontal-binning",
"Number of ADCs",
"Number of ADCs that make up one pixel",
1, G_MAXUINT, 1,
G_PARAM_READABLE), G_PARAM_READABLE);
camera_properties[PROP_SENSOR_VERTICAL_BINNING] =
g_param_spec_uint("sensor-vertical-binning",
"Vertical binning",
"Number of sensor ADCs that are combined to one pixel in vertical direction",
1, G_MAXUINT, 1,
G_PARAM_READWRITE);
camera_properties[PROP_SENSOR_VERTICAL_BINNINGS] =
g_param_spec_value_array("sensor-vertical-binnings",
"Array of possible binnings",
"Array of possible binnings in vertical direction",
g_param_spec_uint(
"sensor-vertical-binning",
"Number of ADCs",
"Number of ADCs that make up one pixel",
1, G_MAXUINT, 1,
G_PARAM_READABLE), G_PARAM_READABLE);
camera_properties[PROP_HAS_STREAMING] =
g_param_spec_boolean("has-streaming",
"Streaming capability",
"Is the camera able to stream the data",
TRUE, G_PARAM_READABLE);
camera_properties[PROP_HAS_CAMRAM_RECORDING] =
g_param_spec_boolean("has-camram-recording",
"Cam-RAM capability",
"Is the camera able to record the data in-camera",
FALSE, G_PARAM_READABLE);
camera_properties[PROP_IS_RECORDING] =
g_param_spec_boolean("is-recording",
"Is camera recording",
"Is the camera currently recording",
FALSE, G_PARAM_READABLE);
for (guint id = PROP_0 + 1; id < N_PROPERTIES; id++)
g_object_class_install_property(gobject_class, id, camera_properties[id]);
g_type_class_add_private(klass, sizeof(UcaCameraPrivate));
}
static void uca_camera_init(UcaCamera *camera)
{
camera->priv = UCA_CAMERA_GET_PRIVATE(camera);
camera->priv->recording = FALSE;
/*
* This here would be the best place to instantiate the tango server object,
* along these lines:
*
* // I'd prefer if you expose a single C method, so we don't have to
* // compile uca-camera.c with g++
* tango_handle = tango_server_new(camera);
*
* void tango_server_new(UcaCamera *camera)
* {
* // Do whatever is necessary. In the end you will have some kind of
* // Tango object t which needs to somehow hook up to the properties. A
* // list of all available properties can be enumerated with
* // g_object_class_list_properties(G_OBJECT_CLASS(camera),
* // &n_properties);
*
* // For setting/getting properties, use g_object_get/set_property() or
* // g_object_get/set() whatever is more suitable.
* }
*/
}
void uca_camera_start_recording(UcaCamera *camera, GError **error)
{
g_return_if_fail(UCA_IS_CAMERA(camera));
UcaCameraClass *klass = UCA_CAMERA_GET_CLASS(camera);
g_return_if_fail(klass != NULL);
g_return_if_fail(klass->start_recording != NULL);
if (camera->priv->recording) {
g_set_error(error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_RECORDING,
"Camera is already recording");
return;
}
(*klass->start_recording)(camera, error);
if (error == NULL) {
camera->priv->recording = TRUE;
g_object_notify_by_pspec(G_OBJECT(camera), camera_properties[PROP_IS_RECORDING]);
}
}
void uca_camera_stop_recording(UcaCamera *camera, GError **error)
{
g_return_if_fail(UCA_IS_CAMERA(camera));
UcaCameraClass *klass = UCA_CAMERA_GET_CLASS(camera);
g_return_if_fail(klass != NULL);
g_return_if_fail(klass->stop_recording != NULL);
if (!camera->priv->recording) {
g_set_error(error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_NOT_RECORDING,
"Camera is not recording");
return;
}
(*klass->stop_recording)(camera, error);
if (error == NULL) {
camera->priv->recording = FALSE;
g_object_notify_by_pspec(G_OBJECT(camera), camera_properties[PROP_IS_RECORDING]);
}
}
void uca_camera_set_grab_func(UcaCamera *camera, UcaCameraGrabFunc func)
{
/* TODO: implement */
}
void uca_camera_grab(UcaCamera *camera, gpointer data, GError **error)
{
g_return_if_fail(UCA_IS_CAMERA(camera));
UcaCameraClass *klass = UCA_CAMERA_GET_CLASS(camera);
g_return_if_fail(klass != NULL);
g_return_if_fail(klass->grab != NULL);
if (!camera->priv->recording) {
g_set_error(error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_NOT_RECORDING,
"Camera is not recording");
return;
}
(*klass->grab)(camera, data, error);
}
|