Fawkes API Fawkes Development Version
CameraControlInterface.cpp
1
2/***************************************************************************
3 * CameraControlInterface.cpp - Fawkes BlackBoard Interface - CameraControlInterface
4 *
5 * Templated created: Thu Oct 12 10:49:19 2006
6 * Copyright 2014 Tim Niemueller
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#include <interfaces/CameraControlInterface.h>
25
26#include <core/exceptions/software.h>
27
28#include <map>
29#include <string>
30#include <cstring>
31#include <cstdlib>
32
33namespace fawkes {
34
35/** @class CameraControlInterface <interfaces/CameraControlInterface.h>
36 * CameraControlInterface Fawkes BlackBoard Interface.
37 *
38
39 * @ingroup FawkesInterfaces
40 */
41
42
43
44/** Constructor */
45CameraControlInterface::CameraControlInterface() : Interface()
46{
47 data_size = sizeof(CameraControlInterface_data_t);
48 data_ptr = malloc(data_size);
49 data = (CameraControlInterface_data_t *)data_ptr;
50 data_ts = (interface_data_ts_t *)data_ptr;
51 memset(data_ptr, 0, data_size);
52 enum_map_Effect[(int)EFF_NONE] = "EFF_NONE";
53 enum_map_Effect[(int)EFF_PASTEL] = "EFF_PASTEL";
54 enum_map_Effect[(int)EFF_NEGATIVE] = "EFF_NEGATIVE";
55 enum_map_Effect[(int)EFF_BW] = "EFF_BW";
56 enum_map_Effect[(int)EFF_SOLARIZE] = "EFF_SOLARIZE";
57 add_fieldinfo(IFT_ENUM, "effect", 1, &data->effect, "Effect", &enum_map_Effect);
58 add_fieldinfo(IFT_BOOL, "effect_supported", 1, &data->effect_supported);
59 add_fieldinfo(IFT_UINT32, "zoom", 1, &data->zoom);
60 add_fieldinfo(IFT_BOOL, "zoom_supported", 1, &data->zoom_supported);
61 add_fieldinfo(IFT_UINT32, "zoom_max", 1, &data->zoom_max);
62 add_fieldinfo(IFT_UINT32, "zoom_min", 1, &data->zoom_min);
63 add_fieldinfo(IFT_BOOL, "mirror", 1, &data->mirror);
64 add_fieldinfo(IFT_BOOL, "mirror_supported", 1, &data->mirror_supported);
65 add_messageinfo("SetEffectMessage");
66 add_messageinfo("SetZoomMessage");
67 add_messageinfo("SetMirrorMessage");
68 unsigned char tmp_hash[] = {0xc, 0xc9, 0x4a, 0x24, 0x89, 0xb8, 0x9c, 0xd1, 0x7f, 0xf5, 0xc4, 0xa3, 0x41, 0xca, 0x9a, 0xc1};
69 set_hash(tmp_hash);
70}
71
72/** Destructor */
73CameraControlInterface::~CameraControlInterface()
74{
75 free(data_ptr);
76}
77/** Convert Effect constant to string.
78 * @param value value to convert to string
79 * @return constant value as string.
80 */
81const char *
82CameraControlInterface::tostring_Effect(Effect value) const
83{
84 switch (value) {
85 case EFF_NONE: return "EFF_NONE";
86 case EFF_PASTEL: return "EFF_PASTEL";
87 case EFF_NEGATIVE: return "EFF_NEGATIVE";
88 case EFF_BW: return "EFF_BW";
89 case EFF_SOLARIZE: return "EFF_SOLARIZE";
90 default: return "UNKNOWN";
91 }
92}
93/* Methods */
94/** Get effect value.
95 * Currently active effect.
96 * @return effect value
97 */
99CameraControlInterface::effect() const
100{
101 return (CameraControlInterface::Effect)data->effect;
102}
103
104/** Get maximum length of effect value.
105 * @return length of effect value, can be length of the array or number of
106 * maximum number of characters for a string
107 */
108size_t
109CameraControlInterface::maxlenof_effect() const
110{
111 return 1;
112}
113
114/** Set effect value.
115 * Currently active effect.
116 * @param new_effect new effect value
117 */
118void
119CameraControlInterface::set_effect(const Effect new_effect)
120{
121 set_field(data->effect, new_effect);
122}
123
124/** Get effect_supported value.
125 * Are effects supported?
126 * @return effect_supported value
127 */
128bool
129CameraControlInterface::is_effect_supported() const
130{
131 return data->effect_supported;
132}
133
134/** Get maximum length of effect_supported value.
135 * @return length of effect_supported value, can be length of the array or number of
136 * maximum number of characters for a string
137 */
138size_t
139CameraControlInterface::maxlenof_effect_supported() const
140{
141 return 1;
142}
143
144/** Set effect_supported value.
145 * Are effects supported?
146 * @param new_effect_supported new effect_supported value
147 */
148void
149CameraControlInterface::set_effect_supported(const bool new_effect_supported)
150{
151 set_field(data->effect_supported, new_effect_supported);
152}
153
154/** Get zoom value.
155 * Current zoom setting.
156 * @return zoom value
157 */
158uint32_t
159CameraControlInterface::zoom() const
160{
161 return data->zoom;
162}
163
164/** Get maximum length of zoom value.
165 * @return length of zoom value, can be length of the array or number of
166 * maximum number of characters for a string
167 */
168size_t
169CameraControlInterface::maxlenof_zoom() const
170{
171 return 1;
172}
173
174/** Set zoom value.
175 * Current zoom setting.
176 * @param new_zoom new zoom value
177 */
178void
179CameraControlInterface::set_zoom(const uint32_t new_zoom)
180{
181 set_field(data->zoom, new_zoom);
182}
183
184/** Get zoom_supported value.
185 * Is zooming supported?
186 * @return zoom_supported value
187 */
188bool
189CameraControlInterface::is_zoom_supported() const
190{
191 return data->zoom_supported;
192}
193
194/** Get maximum length of zoom_supported value.
195 * @return length of zoom_supported value, can be length of the array or number of
196 * maximum number of characters for a string
197 */
198size_t
199CameraControlInterface::maxlenof_zoom_supported() const
200{
201 return 1;
202}
203
204/** Set zoom_supported value.
205 * Is zooming supported?
206 * @param new_zoom_supported new zoom_supported value
207 */
208void
209CameraControlInterface::set_zoom_supported(const bool new_zoom_supported)
210{
211 set_field(data->zoom_supported, new_zoom_supported);
212}
213
214/** Get zoom_max value.
215 * Maximum zoom value
216 * @return zoom_max value
217 */
218uint32_t
219CameraControlInterface::zoom_max() const
220{
221 return data->zoom_max;
222}
223
224/** Get maximum length of zoom_max value.
225 * @return length of zoom_max value, can be length of the array or number of
226 * maximum number of characters for a string
227 */
228size_t
229CameraControlInterface::maxlenof_zoom_max() const
230{
231 return 1;
232}
233
234/** Set zoom_max value.
235 * Maximum zoom value
236 * @param new_zoom_max new zoom_max value
237 */
238void
239CameraControlInterface::set_zoom_max(const uint32_t new_zoom_max)
240{
241 set_field(data->zoom_max, new_zoom_max);
242}
243
244/** Get zoom_min value.
245 * Minimum zoom
246 * @return zoom_min value
247 */
248uint32_t
249CameraControlInterface::zoom_min() const
250{
251 return data->zoom_min;
252}
253
254/** Get maximum length of zoom_min value.
255 * @return length of zoom_min value, can be length of the array or number of
256 * maximum number of characters for a string
257 */
258size_t
259CameraControlInterface::maxlenof_zoom_min() const
260{
261 return 1;
262}
263
264/** Set zoom_min value.
265 * Minimum zoom
266 * @param new_zoom_min new zoom_min value
267 */
268void
269CameraControlInterface::set_zoom_min(const uint32_t new_zoom_min)
270{
271 set_field(data->zoom_min, new_zoom_min);
272}
273
274/** Get mirror value.
275 * Is the image mirrored?
276 * @return mirror value
277 */
278bool
279CameraControlInterface::is_mirror() const
280{
281 return data->mirror;
282}
283
284/** Get maximum length of mirror value.
285 * @return length of mirror value, can be length of the array or number of
286 * maximum number of characters for a string
287 */
288size_t
289CameraControlInterface::maxlenof_mirror() const
290{
291 return 1;
292}
293
294/** Set mirror value.
295 * Is the image mirrored?
296 * @param new_mirror new mirror value
297 */
298void
299CameraControlInterface::set_mirror(const bool new_mirror)
300{
301 set_field(data->mirror, new_mirror);
302}
303
304/** Get mirror_supported value.
305 * Is mirroring supported?
306 * @return mirror_supported value
307 */
308bool
309CameraControlInterface::is_mirror_supported() const
310{
311 return data->mirror_supported;
312}
313
314/** Get maximum length of mirror_supported value.
315 * @return length of mirror_supported value, can be length of the array or number of
316 * maximum number of characters for a string
317 */
318size_t
319CameraControlInterface::maxlenof_mirror_supported() const
320{
321 return 1;
322}
323
324/** Set mirror_supported value.
325 * Is mirroring supported?
326 * @param new_mirror_supported new mirror_supported value
327 */
328void
329CameraControlInterface::set_mirror_supported(const bool new_mirror_supported)
330{
331 set_field(data->mirror_supported, new_mirror_supported);
332}
333
334/* =========== message create =========== */
335Message *
336CameraControlInterface::create_message(const char *type) const
337{
338 if ( strncmp("SetEffectMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
339 return new SetEffectMessage();
340 } else if ( strncmp("SetZoomMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
341 return new SetZoomMessage();
342 } else if ( strncmp("SetMirrorMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
343 return new SetMirrorMessage();
344 } else {
345 throw UnknownTypeException("The given type '%s' does not match any known "
346 "message type for this interface type.", type);
347 }
348}
349
350
351/** Copy values from other interface.
352 * @param other other interface to copy values from
353 */
354void
355CameraControlInterface::copy_values(const Interface *other)
356{
357 const CameraControlInterface *oi = dynamic_cast<const CameraControlInterface *>(other);
358 if (oi == NULL) {
359 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
360 type(), other->type());
361 }
362 memcpy(data, oi->data, sizeof(CameraControlInterface_data_t));
363}
364
365const char *
366CameraControlInterface::enum_tostring(const char *enumtype, int val) const
367{
368 if (strcmp(enumtype, "Effect") == 0) {
369 return tostring_Effect((Effect)val);
370 }
371 throw UnknownTypeException("Unknown enum type %s", enumtype);
372}
373
374/* =========== messages =========== */
375/** @class CameraControlInterface::SetEffectMessage <interfaces/CameraControlInterface.h>
376 * SetEffectMessage Fawkes BlackBoard Interface Message.
377 *
378
379 */
380
381
382/** Constructor with initial values.
383 * @param ini_effect initial value for effect
384 */
385CameraControlInterface::SetEffectMessage::SetEffectMessage(const Effect ini_effect) : Message("SetEffectMessage")
386{
387 data_size = sizeof(SetEffectMessage_data_t);
388 data_ptr = malloc(data_size);
389 memset(data_ptr, 0, data_size);
390 data = (SetEffectMessage_data_t *)data_ptr;
392 data->effect = ini_effect;
393 enum_map_Effect[(int)EFF_NONE] = "EFF_NONE";
394 enum_map_Effect[(int)EFF_PASTEL] = "EFF_PASTEL";
395 enum_map_Effect[(int)EFF_NEGATIVE] = "EFF_NEGATIVE";
396 enum_map_Effect[(int)EFF_BW] = "EFF_BW";
397 enum_map_Effect[(int)EFF_SOLARIZE] = "EFF_SOLARIZE";
398 add_fieldinfo(IFT_ENUM, "effect", 1, &data->effect, "Effect", &enum_map_Effect);
399}
400/** Constructor */
402{
403 data_size = sizeof(SetEffectMessage_data_t);
404 data_ptr = malloc(data_size);
405 memset(data_ptr, 0, data_size);
406 data = (SetEffectMessage_data_t *)data_ptr;
408 enum_map_Effect[(int)EFF_NONE] = "EFF_NONE";
409 enum_map_Effect[(int)EFF_PASTEL] = "EFF_PASTEL";
410 enum_map_Effect[(int)EFF_NEGATIVE] = "EFF_NEGATIVE";
411 enum_map_Effect[(int)EFF_BW] = "EFF_BW";
412 enum_map_Effect[(int)EFF_SOLARIZE] = "EFF_SOLARIZE";
413 add_fieldinfo(IFT_ENUM, "effect", 1, &data->effect, "Effect", &enum_map_Effect);
414}
415
416/** Destructor */
418{
419 free(data_ptr);
420}
421
422/** Copy constructor.
423 * @param m message to copy from
424 */
426{
427 data_size = m->data_size;
428 data_ptr = malloc(data_size);
429 memcpy(data_ptr, m->data_ptr, data_size);
430 data = (SetEffectMessage_data_t *)data_ptr;
432}
433
434/* Methods */
435/** Get effect value.
436 * Currently active effect.
437 * @return effect value
438 */
441{
442 return (CameraControlInterface::Effect)data->effect;
443}
444
445/** Get maximum length of effect value.
446 * @return length of effect value, can be length of the array or number of
447 * maximum number of characters for a string
448 */
449size_t
451{
452 return 1;
453}
454
455/** Set effect value.
456 * Currently active effect.
457 * @param new_effect new effect value
458 */
459void
461{
462 set_field(data->effect, new_effect);
463}
464
465/** Clone this message.
466 * Produces a message of the same type as this message and copies the
467 * data to the new message.
468 * @return clone of this message
469 */
470Message *
472{
474}
475/** @class CameraControlInterface::SetZoomMessage <interfaces/CameraControlInterface.h>
476 * SetZoomMessage Fawkes BlackBoard Interface Message.
477 *
478
479 */
480
481
482/** Constructor with initial values.
483 * @param ini_zoom initial value for zoom
484 */
485CameraControlInterface::SetZoomMessage::SetZoomMessage(const uint32_t ini_zoom) : Message("SetZoomMessage")
486{
487 data_size = sizeof(SetZoomMessage_data_t);
488 data_ptr = malloc(data_size);
489 memset(data_ptr, 0, data_size);
490 data = (SetZoomMessage_data_t *)data_ptr;
492 data->zoom = ini_zoom;
493 enum_map_Effect[(int)EFF_NONE] = "EFF_NONE";
494 enum_map_Effect[(int)EFF_PASTEL] = "EFF_PASTEL";
495 enum_map_Effect[(int)EFF_NEGATIVE] = "EFF_NEGATIVE";
496 enum_map_Effect[(int)EFF_BW] = "EFF_BW";
497 enum_map_Effect[(int)EFF_SOLARIZE] = "EFF_SOLARIZE";
498 add_fieldinfo(IFT_UINT32, "zoom", 1, &data->zoom);
499}
500/** Constructor */
502{
503 data_size = sizeof(SetZoomMessage_data_t);
504 data_ptr = malloc(data_size);
505 memset(data_ptr, 0, data_size);
506 data = (SetZoomMessage_data_t *)data_ptr;
508 enum_map_Effect[(int)EFF_NONE] = "EFF_NONE";
509 enum_map_Effect[(int)EFF_PASTEL] = "EFF_PASTEL";
510 enum_map_Effect[(int)EFF_NEGATIVE] = "EFF_NEGATIVE";
511 enum_map_Effect[(int)EFF_BW] = "EFF_BW";
512 enum_map_Effect[(int)EFF_SOLARIZE] = "EFF_SOLARIZE";
513 add_fieldinfo(IFT_UINT32, "zoom", 1, &data->zoom);
514}
515
516/** Destructor */
518{
519 free(data_ptr);
520}
521
522/** Copy constructor.
523 * @param m message to copy from
524 */
526{
527 data_size = m->data_size;
528 data_ptr = malloc(data_size);
529 memcpy(data_ptr, m->data_ptr, data_size);
530 data = (SetZoomMessage_data_t *)data_ptr;
532}
533
534/* Methods */
535/** Get zoom value.
536 * Current zoom setting.
537 * @return zoom value
538 */
539uint32_t
541{
542 return data->zoom;
543}
544
545/** Get maximum length of zoom value.
546 * @return length of zoom value, can be length of the array or number of
547 * maximum number of characters for a string
548 */
549size_t
551{
552 return 1;
553}
554
555/** Set zoom value.
556 * Current zoom setting.
557 * @param new_zoom new zoom value
558 */
559void
561{
562 set_field(data->zoom, new_zoom);
563}
564
565/** Clone this message.
566 * Produces a message of the same type as this message and copies the
567 * data to the new message.
568 * @return clone of this message
569 */
570Message *
572{
574}
575/** @class CameraControlInterface::SetMirrorMessage <interfaces/CameraControlInterface.h>
576 * SetMirrorMessage Fawkes BlackBoard Interface Message.
577 *
578
579 */
580
581
582/** Constructor with initial values.
583 * @param ini_mirror initial value for mirror
584 */
585CameraControlInterface::SetMirrorMessage::SetMirrorMessage(const bool ini_mirror) : Message("SetMirrorMessage")
586{
587 data_size = sizeof(SetMirrorMessage_data_t);
588 data_ptr = malloc(data_size);
589 memset(data_ptr, 0, data_size);
590 data = (SetMirrorMessage_data_t *)data_ptr;
592 data->mirror = ini_mirror;
593 enum_map_Effect[(int)EFF_NONE] = "EFF_NONE";
594 enum_map_Effect[(int)EFF_PASTEL] = "EFF_PASTEL";
595 enum_map_Effect[(int)EFF_NEGATIVE] = "EFF_NEGATIVE";
596 enum_map_Effect[(int)EFF_BW] = "EFF_BW";
597 enum_map_Effect[(int)EFF_SOLARIZE] = "EFF_SOLARIZE";
598 add_fieldinfo(IFT_BOOL, "mirror", 1, &data->mirror);
599}
600/** Constructor */
602{
603 data_size = sizeof(SetMirrorMessage_data_t);
604 data_ptr = malloc(data_size);
605 memset(data_ptr, 0, data_size);
606 data = (SetMirrorMessage_data_t *)data_ptr;
608 enum_map_Effect[(int)EFF_NONE] = "EFF_NONE";
609 enum_map_Effect[(int)EFF_PASTEL] = "EFF_PASTEL";
610 enum_map_Effect[(int)EFF_NEGATIVE] = "EFF_NEGATIVE";
611 enum_map_Effect[(int)EFF_BW] = "EFF_BW";
612 enum_map_Effect[(int)EFF_SOLARIZE] = "EFF_SOLARIZE";
613 add_fieldinfo(IFT_BOOL, "mirror", 1, &data->mirror);
614}
615
616/** Destructor */
618{
619 free(data_ptr);
620}
621
622/** Copy constructor.
623 * @param m message to copy from
624 */
626{
627 data_size = m->data_size;
628 data_ptr = malloc(data_size);
629 memcpy(data_ptr, m->data_ptr, data_size);
630 data = (SetMirrorMessage_data_t *)data_ptr;
632}
633
634/* Methods */
635/** Get mirror value.
636 * Is the image mirrored?
637 * @return mirror value
638 */
639bool
641{
642 return data->mirror;
643}
644
645/** Get maximum length of mirror value.
646 * @return length of mirror value, can be length of the array or number of
647 * maximum number of characters for a string
648 */
649size_t
651{
652 return 1;
653}
654
655/** Set mirror value.
656 * Is the image mirrored?
657 * @param new_mirror new mirror value
658 */
659void
661{
662 set_field(data->mirror, new_mirror);
663}
664
665/** Clone this message.
666 * Produces a message of the same type as this message and copies the
667 * data to the new message.
668 * @return clone of this message
669 */
670Message *
672{
674}
675/** Check if message is valid and can be enqueued.
676 * @param message Message to check
677 * @return true if the message is valid, false otherwise.
678 */
679bool
681{
682 const SetEffectMessage *m0 = dynamic_cast<const SetEffectMessage *>(message);
683 if ( m0 != NULL ) {
684 return true;
685 }
686 const SetZoomMessage *m1 = dynamic_cast<const SetZoomMessage *>(message);
687 if ( m1 != NULL ) {
688 return true;
689 }
690 const SetMirrorMessage *m2 = dynamic_cast<const SetMirrorMessage *>(message);
691 if ( m2 != NULL ) {
692 return true;
693 }
694 return false;
695}
696
697/// @cond INTERNALS
698EXPORT_INTERFACE(CameraControlInterface)
699/// @endcond
700
701
702} // end namespace fawkes
SetEffectMessage Fawkes BlackBoard Interface Message.
void set_effect(const Effect new_effect)
Set effect value.
size_t maxlenof_effect() const
Get maximum length of effect value.
virtual Message * clone() const
Clone this message.
SetMirrorMessage Fawkes BlackBoard Interface Message.
virtual Message * clone() const
Clone this message.
void set_mirror(const bool new_mirror)
Set mirror value.
size_t maxlenof_mirror() const
Get maximum length of mirror value.
SetZoomMessage Fawkes BlackBoard Interface Message.
void set_zoom(const uint32_t new_zoom)
Set zoom value.
size_t maxlenof_zoom() const
Get maximum length of zoom value.
virtual Message * clone() const
Clone this message.
CameraControlInterface Fawkes BlackBoard Interface.
Effect
Enumeration defining the possible effects.
@ EFF_NEGATIVE
Negative/Positive Reversal.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
const char * type() const
Get type of interface.
Definition: interface.cpp:652
void * data_ptr
Pointer to local memory storage.
Definition: interface.h:244
void set_field(FieldT &field, DataT &data)
Set a field, set data_changed to true and update data_changed accordingly.
Definition: interface.h:304
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0, const interface_enum_map_t *enum_map=0)
Add an entry to the info list.
Definition: message.cpp:435
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:146
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:156
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:147
Fawkes library namespace.
@ IFT_UINT32
32 bit unsigned integer field
Definition: types.h:43
@ IFT_BOOL
boolean field
Definition: types.h:37
@ IFT_ENUM
field with interface specific enum type
Definition: types.h:50
Timestamp data, must be present and first entries for each interface data structs!...
Definition: message.h:152