|
@@ -16,6 +16,59 @@
|
16
|
16
|
|
17
|
17
|
|
18
|
18
|
|
|
19
|
+
|
|
20
|
+static void _light_add_enumerator_device(light_device_enumerator_t *enumerator, light_device_t *new_device)
|
|
21
|
+{
|
|
22
|
+
|
|
23
|
+ uint64_t new_num_devices = enumerator->num_devices + 1;
|
|
24
|
+ light_device_t **new_devices = malloc(new_num_devices * sizeof(light_device_t*));
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+ for(uint64_t i = 0; i < enumerator->num_devices; i++)
|
|
28
|
+ {
|
|
29
|
+ new_devices[i] = enumerator->devices[i];
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+ new_devices[enumerator->num_devices] = new_device;
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+ if(enumerator->devices != NULL)
|
|
37
|
+ {
|
|
38
|
+ free(enumerator->devices);
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+ enumerator->devices = new_devices;
|
|
43
|
+ enumerator->num_devices = new_num_devices;
|
|
44
|
+}
|
|
45
|
+
|
|
46
|
+static void _light_add_device_target(light_device_t *device, light_device_target_t *new_target)
|
|
47
|
+{
|
|
48
|
+
|
|
49
|
+ uint64_t new_num_targets = device->num_targets + 1;
|
|
50
|
+ light_device_target_t **new_targets = malloc(new_num_targets * sizeof(light_device_target_t*));
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+ for(uint64_t i = 0; i < device->num_targets; i++)
|
|
54
|
+ {
|
|
55
|
+ new_targets[i] = device->targets[i];
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+ new_targets[device->num_targets] = new_target;
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+ if(device->targets != NULL)
|
|
63
|
+ {
|
|
64
|
+ free(device->targets);
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+ device->targets= new_targets;
|
|
69
|
+ device->num_targets = new_num_targets;
|
|
70
|
+}
|
|
71
|
+
|
19
|
72
|
static void _light_get_target_path(light_context_t* ctx, char* output_path, size_t output_size)
|
20
|
73
|
{
|
21
|
74
|
snprintf(output_path, output_size,
|
|
@@ -39,7 +92,6 @@ static void _light_get_target_file(light_context_t* ctx, char* output_path, size
|
39
|
92
|
);
|
40
|
93
|
}
|
41
|
94
|
|
42
|
|
-
|
43
|
95
|
static uint64_t _light_get_min_cap(light_context_t *ctx)
|
44
|
96
|
{
|
45
|
97
|
char target_path[NAME_MAX];
|
|
@@ -435,7 +487,7 @@ light_device_enumerator_t * light_create_enumerator(light_context_t *ctx, char c
|
435
|
487
|
}
|
436
|
488
|
|
437
|
489
|
|
438
|
|
- new_enumerators[ctx->num_enumerators] = malloc(sizeof(light_device_enumerator_t*));
|
|
490
|
+ new_enumerators[ctx->num_enumerators] = malloc(sizeof(light_device_enumerator_t));
|
439
|
491
|
light_device_enumerator_t *returner = new_enumerators[ctx->num_enumerators];
|
440
|
492
|
|
441
|
493
|
returner->devices = NULL;
|
|
@@ -473,23 +525,13 @@ bool light_init_enumerators(light_context_t *ctx)
|
473
|
525
|
return success;
|
474
|
526
|
}
|
475
|
527
|
|
476
|
|
-void light_dispose_device(light_device_t *device)
|
477
|
|
-{
|
478
|
|
- if(device->targets != NULL)
|
479
|
|
- {
|
480
|
|
- free(device->targets);
|
481
|
|
- device->targets = NULL;
|
482
|
|
- }
|
483
|
|
-
|
484
|
|
- device->num_targets = 0;
|
485
|
|
-}
|
486
|
|
-
|
487
|
528
|
bool light_free_enumerators(light_context_t *ctx)
|
488
|
529
|
{
|
489
|
530
|
bool success = true;
|
490
|
531
|
for(uint64_t i = 0; i < ctx->num_enumerators; i++)
|
491
|
532
|
{
|
492
|
533
|
light_device_enumerator_t * curr_enumerator = ctx->enumerators[i];
|
|
534
|
+
|
493
|
535
|
if(!curr_enumerator->free(curr_enumerator))
|
494
|
536
|
{
|
495
|
537
|
success = false;
|
|
@@ -497,6 +539,11 @@ bool light_free_enumerators(light_context_t *ctx)
|
497
|
539
|
|
498
|
540
|
if(curr_enumerator->devices != NULL)
|
499
|
541
|
{
|
|
542
|
+ for(uint64_t d = 0; d < curr_enumerator->num_devices; d++)
|
|
543
|
+ {
|
|
544
|
+ light_delete_device(curr_enumerator->devices[d]);
|
|
545
|
+ }
|
|
546
|
+
|
500
|
547
|
free(curr_enumerator->devices);
|
501
|
548
|
curr_enumerator->devices = NULL;
|
502
|
549
|
}
|
|
@@ -511,63 +558,6 @@ bool light_free_enumerators(light_context_t *ctx)
|
511
|
558
|
return success;
|
512
|
559
|
}
|
513
|
560
|
|
514
|
|
-void light_add_enumerator_device(light_device_enumerator_t *enumerator, light_device_t *new_device)
|
515
|
|
-{
|
516
|
|
-
|
517
|
|
- uint64_t new_num_devices = enumerator->num_devices + 1;
|
518
|
|
- light_device_t **new_devices = malloc(new_num_devices * sizeof(light_device_t*));
|
519
|
|
-
|
520
|
|
-
|
521
|
|
- for(uint64_t i = 0; i < enumerator->num_devices; i++)
|
522
|
|
- {
|
523
|
|
- new_devices[i] = enumerator->devices[i];
|
524
|
|
- }
|
525
|
|
-
|
526
|
|
-
|
527
|
|
- new_devices[enumerator->num_devices] = new_device;
|
528
|
|
-
|
529
|
|
-
|
530
|
|
- if(enumerator->devices != NULL)
|
531
|
|
- {
|
532
|
|
- free(enumerator->devices);
|
533
|
|
- }
|
534
|
|
-
|
535
|
|
-
|
536
|
|
- enumerator->devices = new_devices;
|
537
|
|
- enumerator->num_devices = new_num_devices;
|
538
|
|
-
|
539
|
|
- new_device->enumerator = enumerator;
|
540
|
|
-}
|
541
|
|
-
|
542
|
|
-void light_add_device_target(light_device_t *device, light_device_target_t *new_target)
|
543
|
|
-{
|
544
|
|
-
|
545
|
|
- uint64_t new_num_targets = device->num_targets + 1;
|
546
|
|
- light_device_target_t **new_targets = malloc(new_num_targets * sizeof(light_device_target_t*));
|
547
|
|
-
|
548
|
|
-
|
549
|
|
- for(uint64_t i = 0; i < device->num_targets; i++)
|
550
|
|
- {
|
551
|
|
- new_targets[i] = device->targets[i];
|
552
|
|
- }
|
553
|
|
-
|
554
|
|
-
|
555
|
|
- new_targets[device->num_targets] = new_target;
|
556
|
|
-
|
557
|
|
-
|
558
|
|
- if(device->targets != NULL)
|
559
|
|
- {
|
560
|
|
- free(device->targets);
|
561
|
|
- }
|
562
|
|
-
|
563
|
|
-
|
564
|
|
- device->targets= new_targets;
|
565
|
|
- device->num_targets = new_num_targets;
|
566
|
|
-
|
567
|
|
- new_target->device = device;
|
568
|
|
-}
|
569
|
|
-
|
570
|
|
-
|
571
|
561
|
bool light_split_target_path(char const *in_path, light_target_path_t *out_path)
|
572
|
562
|
{
|
573
|
563
|
char const * begin = in_path;
|
|
@@ -966,6 +956,64 @@ bool light_cmd_restore_brightness(light_context_t *ctx)
|
966
|
956
|
return true;
|
967
|
957
|
}
|
968
|
958
|
|
|
959
|
+light_device_t *light_create_device(light_device_enumerator_t *enumerator, char const *name, void *device_data)
|
|
960
|
+{
|
|
961
|
+ light_device_t *new_device = malloc(sizeof(light_device_t));
|
|
962
|
+ new_device->enumerator = enumerator;
|
|
963
|
+ new_device->targets = NULL;
|
|
964
|
+ new_device->num_targets = 0;
|
|
965
|
+ new_device->device_data = device_data;
|
|
966
|
+
|
|
967
|
+ snprintf(new_device->name, sizeof(new_device->name), "%s", name);
|
|
968
|
+
|
|
969
|
+ _light_add_enumerator_device(enumerator, new_device);
|
|
970
|
+
|
|
971
|
+ return new_device;
|
|
972
|
+}
|
969
|
973
|
|
|
974
|
+void light_delete_device(light_device_t *device)
|
|
975
|
+{
|
|
976
|
+ for(uint64_t i = 0; i < device->num_targets; i++)
|
|
977
|
+ {
|
|
978
|
+ light_delete_device_target(device->targets[i]);
|
|
979
|
+ }
|
|
980
|
+
|
|
981
|
+ if(device->targets != NULL)
|
|
982
|
+ {
|
|
983
|
+ free(device->targets);
|
|
984
|
+ }
|
|
985
|
+
|
|
986
|
+ if(device->device_data != NULL)
|
|
987
|
+ {
|
|
988
|
+ free(device->device_data);
|
|
989
|
+ }
|
|
990
|
+
|
|
991
|
+ free(device);
|
|
992
|
+}
|
970
|
993
|
|
|
994
|
+light_device_target_t *light_create_device_target(light_device_t *device, char const *name, LFUNCVALSET setfunc, LFUNCVALGET getfunc, LFUNCMAXVALGET getmaxfunc, LFUNCCUSTOMCMD cmdfunc, void *target_data)
|
|
995
|
+{
|
|
996
|
+ light_device_target_t *new_target = malloc(sizeof(light_device_target_t));
|
|
997
|
+ new_target->device = device;
|
|
998
|
+ new_target->set_value = setfunc;
|
|
999
|
+ new_target->get_value = getfunc;
|
|
1000
|
+ new_target->get_max_value = getmaxfunc;
|
|
1001
|
+ new_target->custom_command = cmdfunc;
|
|
1002
|
+ new_target->device_target_data = target_data;
|
|
1003
|
+
|
|
1004
|
+ snprintf(new_target->name, sizeof(new_target->name), "%s", name);
|
|
1005
|
+
|
|
1006
|
+ _light_add_device_target(device, new_target);
|
|
1007
|
+
|
|
1008
|
+ return new_target;
|
|
1009
|
+}
|
971
|
1010
|
|
|
1011
|
+void light_delete_device_target(light_device_target_t *device_target)
|
|
1012
|
+{
|
|
1013
|
+ if(device_target->device_target_data != NULL)
|
|
1014
|
+ {
|
|
1015
|
+ free(device_target->device_target_data);
|
|
1016
|
+ }
|
|
1017
|
+
|
|
1018
|
+ free(device_target);
|
|
1019
|
+}
|