forked from AravisProject/aravis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharvdevice.c
1201 lines (1001 loc) · 32.1 KB
/
arvdevice.c
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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Aravis - Digital camera library
*
* Copyright © 2009-2022 Emmanuel Pacaud
*
* 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 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 Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* Author: Emmanuel Pacaud <[email protected]>
*/
/**
* SECTION: arvdevice
* @short_description: Abstract base class for device handling
*
* #ArvDevice is an abstract base class for the control of cameras. It provides
* an easy access to the camera settings, and to its genicam interface for more
* advanced uses.
*/
#include <arvdevice.h>
#include <arvdeviceprivate.h>
#include <arvgc.h>
#include <arvgccommand.h>
#include <arvgcinteger.h>
#include <arvgcfloat.h>
#include <arvgcfeaturenode.h>
#include <arvgcboolean.h>
#include <arvgcenumeration.h>
#include <arvgcstring.h>
#include <arvstream.h>
#include <arvdebug.h>
enum {
ARV_DEVICE_SIGNAL_CONTROL_LOST,
ARV_DEVICE_SIGNAL_LAST
} ArvDeviceSignals;
static guint arv_device_signals[ARV_DEVICE_SIGNAL_LAST] = {0};
GQuark
arv_device_error_quark (void)
{
return g_quark_from_static_string ("arv-device-error-quark");
}
typedef struct {
GError *init_error;
} ArvDevicePrivate;
static void arv_device_initable_iface_init (GInitableIface *iface);
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (ArvDevice, arv_device, G_TYPE_OBJECT,
G_ADD_PRIVATE (ArvDevice)
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, arv_device_initable_iface_init))
/**
* arv_device_create_stream: (skip)
* @device: a #ArvDevice
* @callback: (scope call): a frame processing callback
* @user_data: (allow-none) (closure): user data for @callback
* @error: a #GError placeholder, %NULL to ignore
*
* Creates a new #ArvStream for video stream handling. See
* @ArvStreamCallback for details regarding the callback function.
*
* Return value: (transfer full): a new #ArvStream.
*
* Since: 0.2.0
*/
ArvStream *
arv_device_create_stream (ArvDevice *device, ArvStreamCallback callback, void *user_data, GError **error)
{
return arv_device_create_stream_full(device, callback, user_data, NULL, error);
}
/**
* arv_device_create_stream_full: (rename-to arv_device_create_stream)
* @device: a #ArvDevice
* @callback: (scope notified): a frame processing callback
* @user_data: (allow-none) (closure): user data for @callback
* @destroy: a #GDestroyNotify placeholder, %NULL to ignore
* @error: a #GError placeholder, %NULL to ignore
*
* Creates a new #ArvStream for video stream handling. See
* @ArvStreamCallback for details regarding the callback function.
*
* Return value: (transfer full): a new #ArvStream.
*
* Since: 0.8.23
*/
ArvStream *
arv_device_create_stream_full (ArvDevice *device, ArvStreamCallback callback, void *user_data, GDestroyNotify destroy, GError **error)
{
g_return_val_if_fail (ARV_IS_DEVICE (device), NULL);
return ARV_DEVICE_GET_CLASS (device)->create_stream (device, callback, user_data, destroy, error);
}
/**
* arv_device_read_memory:
* @device: a #ArvDevice
* @address: memory address
* @size: number of bytes to read
* @buffer: a buffer for the storage of the read data
* @error: (out) (allow-none): a #GError placeholder
*
* Reads @size bytes from the device memory.
*
* Return value: (skip): TRUE on success.
*
* Since: 0.2.0
**/
gboolean
arv_device_read_memory (ArvDevice *device, guint64 address, guint32 size, void *buffer, GError **error)
{
g_return_val_if_fail (ARV_IS_DEVICE (device), FALSE);
g_return_val_if_fail (buffer != NULL, FALSE);
g_return_val_if_fail (size > 0, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
return ARV_DEVICE_GET_CLASS (device)->read_memory (device, address, size, buffer, error);
}
/**
* arv_device_write_memory:
* @device: a #ArvDevice
* @address: memory address
* @size: size of the returned buffer
* @buffer: (transfer full): the buffer read from memory
* @error: (out) (allow-none): a #GError placeholder
*
* Writes @size bytes to the device memory.
*
* Return value: (skip): TRUE on success.
*
* Since: 0.2.0
**/
gboolean
arv_device_write_memory (ArvDevice *device, guint64 address, guint32 size, void *buffer, GError **error)
{
g_return_val_if_fail (ARV_IS_DEVICE (device), FALSE);
g_return_val_if_fail (buffer != NULL, FALSE);
g_return_val_if_fail (size > 0, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
return ARV_DEVICE_GET_CLASS (device)->write_memory (device, address, size, buffer, error);
}
/**
* arv_device_read_register:
* @device: a #ArvDevice
* @address: register address
* @value: (out): a placeholder for the read value
* @error: (out) (allow-none): a #GError placeholder
*
* Reads the value of a device register.
*
* Return value: (skip): TRUE on success.
*
* Since: 0.2.0
**/
gboolean
arv_device_read_register (ArvDevice *device, guint64 address, guint32 *value, GError **error)
{
g_return_val_if_fail (ARV_IS_DEVICE (device), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
return ARV_DEVICE_GET_CLASS (device)->read_register (device, address, value, error);
}
/**
* arv_device_write_register:
* @device: a #ArvDevice
* @address: the register address
* @value: value to write
* @error: (out) (allow-none): a #GError placeholder
*
* Writes @value to a device register.
*
* Return value: (skip): TRUE on success.
*
* Since: 0.2.0
**/
gboolean
arv_device_write_register (ArvDevice *device, guint64 address, guint32 value, GError **error)
{
g_return_val_if_fail (ARV_IS_DEVICE (device), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
return ARV_DEVICE_GET_CLASS (device)->write_register (device, address, value, error);
}
/**
* arv_device_get_genicam:
* @device: a #ArvDevice
*
* Retrieves the genicam interface of the given device.
*
* Return value: (transfer none): the genicam interface.
*
* Since: 0.2.0
*/
ArvGc *
arv_device_get_genicam (ArvDevice *device)
{
g_return_val_if_fail (ARV_IS_DEVICE (device), NULL);
return ARV_DEVICE_GET_CLASS (device)->get_genicam (device);
}
/**
* arv_device_get_genicam_xml:
* @device: a #ArvDevice
* @size: (out) (allow-none): placeholder for the returned data size (bytes)
*
* Gets the Genicam XML data stored in the device memory.
*
* Returns: (transfer none): a pointer to the Genicam XML data, owned by the device.
*
* Since: 0.2.0
**/
const char *
arv_device_get_genicam_xml (ArvDevice *device, size_t *size)
{
g_return_val_if_fail (ARV_IS_DEVICE (device), NULL);
g_return_val_if_fail (size != NULL, NULL);
if (ARV_DEVICE_GET_CLASS (device)->get_genicam_xml != NULL)
return ARV_DEVICE_GET_CLASS (device)->get_genicam_xml (device, size);
*size = 0;
return NULL;
}
/**
* arv_device_create_chunk_parser:
* @device: a #ArvDevice
*
* Create a #ArvChunkParser object, to be used for chunk data extraction from #ArvBuffer.
*
* Returns: (transfer full): a new #ArvChunkParser object, NULL on error.
*
* Since: 0.4.0
**/
ArvChunkParser *
arv_device_create_chunk_parser (ArvDevice *device)
{
const char *xml = NULL;
gsize size = 0;
g_return_val_if_fail (ARV_IS_DEVICE (device), NULL);
xml = arv_device_get_genicam_xml (device, &size);
return arv_chunk_parser_new (xml, size);
}
/**
* arv_device_get_feature:
* @device: a #ArvDevice
* @feature: feature name
*
* Return value: (transfer none): the genicam node corresponding to the feature name, NULL if not found.
*
* Since: 0.2.0
*/
ArvGcNode *
arv_device_get_feature (ArvDevice *device, const char *feature)
{
ArvGc *genicam;
genicam = arv_device_get_genicam (device);
g_return_val_if_fail (ARV_IS_GC (genicam), NULL);
return arv_gc_get_node (genicam, feature);
}
/**
* arv_device_get_feature_access_mode:
* @device: a #ArvDevice
* @feature: feature name
*
* Return value: The actual feature access mode, which is a combination of ImposedAccessMode property and actual
* register access mode.
*
* Since: 0.8.22
*/
ArvGcAccessMode
arv_device_get_feature_access_mode (ArvDevice *device, const char *feature)
{
ArvGcNode* node;
g_return_val_if_fail (ARV_IS_DEVICE (device), ARV_GC_ACCESS_MODE_UNDEFINED);
g_return_val_if_fail (feature != NULL, ARV_GC_ACCESS_MODE_UNDEFINED);
node = arv_device_get_feature (device, feature);
return ARV_IS_GC_FEATURE_NODE (node) && arv_gc_feature_node_get_actual_access_mode (ARV_GC_FEATURE_NODE (node));
}
/**
* arv_device_is_feature_available:
* @device: a #ArvDevice
* @feature: feature name
* @error: a #GError placeholder, %NULL to ignore
*
* Return: %TRUE if feature is available, %FALSE if not or on error.
*
* Since: 0.8.0
*/
gboolean
arv_device_is_feature_available (ArvDevice *device, const char *feature, GError **error)
{
ArvGcNode* node;
g_return_val_if_fail (ARV_IS_DEVICE (device), FALSE);
g_return_val_if_fail (feature != NULL, FALSE);
node = arv_device_get_feature (device, feature);
return ARV_IS_GC_FEATURE_NODE (node) && arv_gc_feature_node_is_available (ARV_GC_FEATURE_NODE (node), error);
}
/**
* arv_device_is_feature_implemented:
* @device: a #ArvDevice
* @feature: feature name
* @error: a #GError placeholder, %NULL to ignore
*
* Return: %TRUE if feature is implemented, %FALSE if not or on error.
*
* Since: 0.8.23
*/
gboolean
arv_device_is_feature_implemented (ArvDevice *device, const char *feature, GError **error)
{
ArvGcNode* node;
g_return_val_if_fail (ARV_IS_DEVICE (device), FALSE);
g_return_val_if_fail (feature != NULL, FALSE);
node = arv_device_get_feature (device, feature);
return ARV_IS_GC_FEATURE_NODE (node) && arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (node), error);
}
static void *
_get_feature (ArvDevice *device, GType node_type, const char *feature, GError **error)
{
void *node;
g_return_val_if_fail (ARV_IS_DEVICE (device), NULL);
g_return_val_if_fail (feature != NULL, NULL);
node = arv_device_get_feature (device, feature);
if (node == NULL) {
g_set_error (error, ARV_DEVICE_ERROR, ARV_DEVICE_ERROR_FEATURE_NOT_FOUND,
"[%s] Not found", feature);
return NULL;
}
if (!(G_TYPE_CHECK_INSTANCE_TYPE ((node), node_type))) {
g_set_error (error, ARV_DEVICE_ERROR, ARV_DEVICE_ERROR_WRONG_FEATURE,
"[%s:%s] Not a %s", feature, G_OBJECT_TYPE_NAME (node), g_type_name (node_type));
return NULL;
}
return node;
}
/**
* arv_device_execute_command:
* @device: a #ArvDevice
* @feature: feature name
* @error: a #GError placeholder
*
* Execute a genicam command.
*
* Since: 0.8.0
*/
void
arv_device_execute_command (ArvDevice *device, const char *feature, GError **error)
{
ArvGcNode *node;
node = _get_feature (device, ARV_TYPE_GC_COMMAND, feature, error);
if (node != NULL)
arv_gc_command_execute (ARV_GC_COMMAND (node), error);
}
/**
* arv_device_set_boolean_feature_value:
* @device: a #ArvDevice
* @feature: feature name
* @value: feature value
* @error: a #GError placeholder
*
* Set the value of a boolean feature.
*
* Since: 0.8.0
*/
void
arv_device_set_boolean_feature_value (ArvDevice *device, const char *feature, gboolean value, GError **error)
{
ArvGcNode *node;
node = _get_feature (device, ARV_TYPE_GC_BOOLEAN, feature, error);
if (node != NULL)
arv_gc_boolean_set_value (ARV_GC_BOOLEAN (node), value, error);
}
/**
* arv_device_get_boolean_feature_value:
* @device: a #ArvDevice
* @feature: feature name
* @error: a #GError placeholder
*
* Returns: the feature value, %FALSE on error.
*
* Since: 0.8.0
*/
gboolean
arv_device_get_boolean_feature_value (ArvDevice *device, const char *feature, GError **error)
{
ArvGcNode *node;
node = _get_feature (device, ARV_TYPE_GC_BOOLEAN, feature, error);
if (node != NULL)
return arv_gc_boolean_get_value (ARV_GC_BOOLEAN (node), error);
return FALSE;
}
/**
* arv_device_get_boolean_feature_value_gi: (rename-to arv_device_get_boolean_feature_value)
* @device: a #ArvDevice
* @feature: feature name
* @value: (out): feature value
* @error: a #GError placeholder
*
* Get the feature value, or %FALSE on error.
*
* Since: 0.8.0
*/
void
arv_device_get_boolean_feature_value_gi (ArvDevice *device, const char *feature, gboolean *value, GError **error)
{
g_return_if_fail (value != NULL);
*value = arv_device_get_boolean_feature_value (device, feature, error);
}
/**
* arv_device_set_string_feature_value:
* @device: a #ArvDevice
* @feature: feature name
* @value: new feature value
* @error: a #GError placeholder
*
* Set the string feature value.
*
* Since: 0.8.0
*/
void
arv_device_set_string_feature_value (ArvDevice *device, const char *feature, const char *value, GError **error)
{
ArvGcNode *node;
node = _get_feature (device, ARV_TYPE_GC_STRING, feature, error);
if (node != NULL)
arv_gc_string_set_value (ARV_GC_STRING (node), value, error);
}
/**
* arv_device_get_string_feature_value:
* @device: a #ArvDevice
* @feature: feature name
* @error: a #GError placeholder
*
* Returns: the string feature value, %NULL on error.
*
* Since: 0.8.0
*/
const char *
arv_device_get_string_feature_value (ArvDevice *device, const char *feature, GError **error)
{
ArvGcNode *node;
node = _get_feature (device, ARV_TYPE_GC_STRING, feature, error);
if (node != NULL)
return arv_gc_string_get_value (ARV_GC_STRING (node), error);
return NULL;
}
/**
* arv_device_set_integer_feature_value:
* @device: a #ArvDevice
* @feature: feature name
* @value: new feature value
* @error: a #GError placeholder
*
* Set the integer feature value.
*
* Since: 0.8.0
*/
void
arv_device_set_integer_feature_value (ArvDevice *device, const char *feature, gint64 value, GError **error)
{
ArvGcNode *node;
node = _get_feature (device, ARV_TYPE_GC_INTEGER, feature, error);
if (node != NULL)
arv_gc_integer_set_value (ARV_GC_INTEGER (node), value, error);
}
/**
* arv_device_get_integer_feature_value:
* @device: a #ArvDevice
* @feature: feature name
* @error: a #GError placeholder
*
* Returns: the integer feature value, 0 on error.
*
* Since: 0.8.0
*/
gint64
arv_device_get_integer_feature_value (ArvDevice *device, const char *feature, GError **error)
{
ArvGcNode *node;
node = _get_feature (device, ARV_TYPE_GC_INTEGER, feature, error);
if (node != NULL)
return arv_gc_integer_get_value (ARV_GC_INTEGER (node), error);
return 0;
}
/**
* arv_device_get_integer_feature_bounds:
* @device: a #ArvDevice
* @feature: feature name
* @min: (out): minimum feature value
* @max: (out): maximum feature value
* @error: a #GError placeholder
*
* Retrieves feature bounds.
*
* Since: 0.8.0
*/
void
arv_device_get_integer_feature_bounds (ArvDevice *device, const char *feature, gint64 *min, gint64 *max, GError **error)
{
ArvGcNode *node;
if (min != NULL)
*min = G_MININT64;
if (max != NULL)
*max = G_MAXINT64;
node = _get_feature (device, ARV_TYPE_GC_INTEGER, feature, error);
if (node != NULL) {
GError *local_error = NULL;
if (min != NULL) {
gint64 minimum;
minimum = arv_gc_integer_get_min (ARV_GC_INTEGER (node), &local_error);
if (local_error != NULL) {
g_propagate_error (error, local_error);
return;
}
*min = minimum;
}
if (max != NULL) {
gint64 maximum;
maximum = arv_gc_integer_get_max (ARV_GC_INTEGER (node), &local_error);
if (local_error != NULL) {
g_propagate_error (error, local_error);
return;
}
*max = maximum;
}
}
}
/**
* arv_device_get_integer_feature_increment:
* @device: a #ArvDevice
* @feature: feature name
* @error: a #GError placeholder
*
* Not all integer features have evenly distributed allowed values, which means the returned increment may not reflect the allowed value
* set.
*
* Returns: feature value increment, or 1 on error.
*
* Since: 0.8.0
*/
gint64
arv_device_get_integer_feature_increment (ArvDevice *device, const char *feature, GError **error)
{
ArvGcNode *node;
node = _get_feature (device, ARV_TYPE_GC_INTEGER, feature, error);
if (node != NULL) {
GError *local_error = NULL;
gint64 increment;
increment = arv_gc_integer_get_inc (ARV_GC_INTEGER (node), &local_error);
if (local_error != NULL) {
g_propagate_error (error, local_error);
return 1;
}
return increment;
}
return 1;
}
/**
* arv_device_set_float_feature_value:
* @device: a #ArvDevice
* @feature: feature name
* @value: new feature value
* @error: a #GError placeholder
*
* Set the float feature value.
*
* Since: 0.8.0
*/
void
arv_device_set_float_feature_value (ArvDevice *device, const char *feature, double value, GError **error)
{
ArvGcNode *node;
node = _get_feature (device, ARV_TYPE_GC_FLOAT, feature, error);
if (node != NULL)
arv_gc_float_set_value (ARV_GC_FLOAT (node), value, error);
}
/**
* arv_device_get_float_feature_value:
* @device: a #ArvDevice
* @feature: feature name
* @error: a #GError placeholder
*
* Returns: the float feature value, 0.0 on error.
*
* Since: 0.8.0
*/
double
arv_device_get_float_feature_value (ArvDevice *device, const char *feature, GError **error)
{
ArvGcNode *node;
node = _get_feature (device, ARV_TYPE_GC_FLOAT, feature, error);
if (node != NULL)
return arv_gc_float_get_value (ARV_GC_FLOAT (node), error);
return 0.0;
}
/**
* arv_device_get_float_feature_bounds:
* @device: a #ArvDevice
* @feature: feature name
* @min: (out): minimum feature value
* @max: (out): maximum feature value
* @error: a #GError placeholder
*
* Retrieves feature bounds.
*
* Since: 0.8.0
*/
void
arv_device_get_float_feature_bounds (ArvDevice *device, const char *feature, double *min, double *max, GError **error)
{
ArvGcNode *node;
if (min != NULL)
*min = -G_MAXDOUBLE;
if (max != NULL)
*max = G_MAXDOUBLE;
node = _get_feature (device, ARV_TYPE_GC_FLOAT, feature, error);
if (node != NULL) {
GError *local_error = NULL;
if (min != NULL) {
double minimum;
minimum = arv_gc_float_get_min (ARV_GC_FLOAT (node), &local_error);
if (local_error != NULL) {
g_propagate_error (error, local_error);
return;
}
*min = minimum;
}
if (max != NULL) {
double maximum;
maximum = arv_gc_float_get_max (ARV_GC_FLOAT (node), &local_error);
if (local_error != NULL) {
g_propagate_error (error, local_error);
return;
}
*max = maximum;
}
}
}
/**
* arv_device_get_float_feature_increment:
* @device: a #ArvDevice
* @feature: feature name
* @error: a #GError placeholder
*
* Not all float features have evenly distributed allowed values, which means the returned increment may not reflect the allowed value
* set.
*
* Returns: feature value increment, or #G_MINDOUBLE on error.
*
* Since: 0.8.16
*/
double
arv_device_get_float_feature_increment (ArvDevice *device, const char *feature, GError **error)
{
ArvGcNode *node;
node = _get_feature (device, ARV_TYPE_GC_FLOAT, feature, error);
if (node != NULL) {
GError *local_error = NULL;
double increment;
increment = arv_gc_float_get_inc (ARV_GC_FLOAT (node), &local_error);
if (local_error != NULL) {
g_propagate_error (error, local_error);
return G_MINDOUBLE;
}
return increment;
}
return G_MINDOUBLE;
}
/**
* arv_device_dup_available_enumeration_feature_values:
* @device: an #ArvDevice
* @feature: feature name
* @n_values: placeholder for the number of returned values
* @error: a #GError placeholder
*
* Get all the available values of @feature, as integers.
*
* Returns: (array length=n_values) (transfer container): a newly created array of 64 bit integers, which must freed after use using g_free,
* or NULL on error.
*
* Since: 0.8.0
*/
gint64 *
arv_device_dup_available_enumeration_feature_values (ArvDevice *device, const char *feature, guint *n_values, GError **error)
{
ArvGcNode *node;
if (n_values != NULL)
*n_values = 0;
node = _get_feature (device, ARV_TYPE_GC_ENUMERATION, feature, error);
if (node != NULL)
return arv_gc_enumeration_dup_available_int_values (ARV_GC_ENUMERATION (node), n_values, error);
return NULL;
}
/**
* arv_device_dup_available_enumeration_feature_values_as_strings:
* @device: an #ArvDevice
* @feature: feature name
* @n_values: placeholder for the number of returned values
* @error: a #GError placeholder
*
* Get all the available values of @feature, as strings.
*
* Returns: (array length=n_values) (transfer container): a newly created array of const strings, which must freed after use using g_free,
* or NULL on error.
*
* Since: 0.8.0
*/
const char **
arv_device_dup_available_enumeration_feature_values_as_strings (ArvDevice *device, const char *feature, guint *n_values, GError **error)
{
ArvGcNode *node;
if (n_values != NULL)
*n_values = 0;
node = _get_feature (device, ARV_TYPE_GC_ENUMERATION, feature, error);
if (node != NULL)
return arv_gc_enumeration_dup_available_string_values (ARV_GC_ENUMERATION (node), n_values, error);
return NULL;
}
/**
* arv_device_dup_available_enumeration_feature_values_as_display_names:
* @device: an #ArvDevice
* @feature: feature name
* @n_values: placeholder for the number of returned values
* @error: a #GError placeholder
*
* Get display names of all the available entries of @feature.
*
* Returns: (array length=n_values) (transfer container): a newly created array of const strings, to be freed after use using g_free, or
* %NULL on error.
*
* Since: 0.8.0
*/
const char **
arv_device_dup_available_enumeration_feature_values_as_display_names (ArvDevice *device, const char *feature, guint *n_values, GError **error)
{
ArvGcNode *node;
if (n_values != NULL)
*n_values = 0;
node = _get_feature (device, ARV_TYPE_GC_ENUMERATION, feature, error);
if (node != NULL)
return arv_gc_enumeration_dup_available_display_names (ARV_GC_ENUMERATION (node), n_values, error);
return NULL;
}
/**
* arv_device_is_enumeration_entry_available:
* @device: an #ArvDevice instance
* @feature: enumeration feature name
* @entry: entry name
* @error: a #GError placeholder
*
* Returns: %TRUE if the feature and the feature entry are available
*
* Since: 0.8.17
*/
gboolean
arv_device_is_enumeration_entry_available (ArvDevice *device, const char *feature, const char *entry, GError **error)
{
GError *local_error = NULL;
const char **entries = NULL;
guint n_entries = 0;
gboolean is_available = FALSE;
unsigned int i;
if (!arv_device_is_feature_available (device, feature, &local_error)) {
if (local_error != NULL)
g_propagate_error (error, local_error);
return FALSE;
}
entries = arv_device_dup_available_enumeration_feature_values_as_strings (device, feature, &n_entries,
&local_error);
if (local_error != NULL) {
g_propagate_error (error, local_error);
return FALSE;
}
for (i = 0; i < n_entries && !is_available; i++) {
if (g_strcmp0 (entry, entries[i]) == 0)
is_available = TRUE;
}
g_free (entries);
return is_available;
}
/**
* arv_device_set_features_from_string:
* @device: a #ArvDevice
* @string: a space separated list of features assignments
* @error: a #GError placeholder, %NULL to ignore
*
* Set features from a string containing a list of space separated feature assignments or command names. For example:
*
* |[<!-- language="C" -->
* arv_device_set_features_from_string (device, "Width=256 Height=256 PixelFormat='Mono8' TriggerStart", &error);
* ]|
*
* Since: 0.8.0
*/
gboolean
arv_device_set_features_from_string (ArvDevice *device, const char *string, GError **error)
{
GMatchInfo *match_info = NULL;
GError *local_error = NULL;
GRegex *regex;
g_return_val_if_fail (ARV_IS_DEVICE (device), FALSE);
if (string == NULL)
return TRUE;
regex = g_regex_new ("((?<Key>[^\\s\"'\\=]+)|\"(?<Key>[^\"]*)\"|'(?<Key>[^']*)')"
"(?:\\=((?<Value>[^\\s\"']+)|\"(?<Value>[^\"]*)\"|'(?<Value>[^']*)'))?",
G_REGEX_DUPNAMES, 0, NULL);
if (g_regex_match (regex, string, 0, &match_info)) {
while (g_match_info_matches (match_info) && local_error == NULL) {
ArvGcNode *feature;
char *key = g_match_info_fetch_named (match_info, "Key");
char *value = g_match_info_fetch_named (match_info, "Value");
size_t key_length = key != NULL ? strlen (key) : 0;
if (key_length > 4 && key[0] == 'R' && key[1] == '[' && key[key_length - 1] == ']') {
char *end;
gint64 address;
gint64 int_value;
address = g_ascii_strtoll (&key[2], &end, 0);
if (end == NULL || end != key + key_length -1) {
g_set_error (&local_error,
ARV_DEVICE_ERROR,
ARV_DEVICE_ERROR_INVALID_PARAMETER,
"Invalid address in %s", key);
} else {
int_value = g_ascii_strtoll (value, &end, 0);
if (end == NULL || end[0] != '\0') {
g_set_error (&local_error,
ARV_DEVICE_ERROR,
ARV_DEVICE_ERROR_INVALID_PARAMETER,
"Invalid %s value for %s", value, key);
} else {
arv_device_write_register (device, address, int_value, &local_error);
}
}
} else {
feature = arv_device_get_feature (device, key);
if (ARV_IS_GC_FEATURE_NODE (feature)) {
if (ARV_IS_GC_COMMAND (feature)) {
arv_device_execute_command (device, key, &local_error);
} else if (value != NULL) {