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
|
/*
* Copyright (C) 2016 "IoT.bzh"
* Author Jonathan Aillet <jonathan.aillet@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <wrap-json.h>
#include "../4a-hal-utilities/4a-hal-utilities-data.h"
#include "../4a-hal-utilities/4a-hal-utilities-verbs-loader.h"
#include "4a-hal-controllers-cb.h"
/*******************************************************************************
* HAL controllers sections parsing functions *
******************************************************************************/
int HalCtlsHalMixerConfig(afb_dynapi *apiHandle, CtlSectionT *section, json_object *MixerJ)
{
unsigned int streamCount, idx;
char *currentStreamName;
CtlConfigT *ctrlConfig;
struct SpecificHalData *currentHalData;
json_object *streamsArray, *currentStream;
struct HalUtlApiVerb *CtlHalDynApiStreamVerbs;
if(! apiHandle || ! section)
return -1;
if(MixerJ) {
ctrlConfig = (CtlConfigT *) afb_dynapi_get_userdata(apiHandle);
if(! ctrlConfig)
return -2;
currentHalData = (struct SpecificHalData *) ctrlConfig->external;
if(! currentHalData)
return -3;
if(json_object_is_type(MixerJ, json_type_object))
currentHalData->ctlHalSpecificData->halMixerJ = MixerJ;
else
return -4;
if(wrap_json_unpack(MixerJ, "{s:s}", "mixerapi", ¤tHalData->ctlHalSpecificData->mixerApiName))
return -5;
if(! json_object_object_get_ex(MixerJ, "streams", &streamsArray))
return -6;
switch(json_object_get_type(streamsArray)) {
case json_type_object:
streamCount = 1;
break;
case json_type_array:
streamCount = json_object_array_length(streamsArray);
break;
default:
return -7;
}
currentHalData->ctlHalSpecificData->ctlHalStreamsData.count = streamCount;
currentHalData->ctlHalSpecificData->ctlHalStreamsData.data =
(struct CtlHalStreamData *) calloc(streamCount, sizeof (struct CtlHalStreamData *));
CtlHalDynApiStreamVerbs = alloca((streamCount + 1) * sizeof(struct HalUtlApiVerb));
memset(CtlHalDynApiStreamVerbs, '\0', (streamCount + 1) * sizeof(struct HalUtlApiVerb));
CtlHalDynApiStreamVerbs[streamCount + 1].verb = NULL;
for(idx = 0; idx < streamCount; idx++) {
if(streamCount > 1)
currentStream = json_object_array_get_idx(streamsArray, (int) idx);
else
currentStream = streamsArray;
if(wrap_json_unpack(currentStream, "{s:s}", "uid", ¤tStreamName))
return -9-idx;
currentHalData->ctlHalSpecificData->ctlHalStreamsData.data[idx].name = strdup(currentStreamName);
currentHalData->ctlHalSpecificData->ctlHalStreamsData.data[idx].cardId = NULL;
CtlHalDynApiStreamVerbs[idx].verb = currentStreamName;
CtlHalDynApiStreamVerbs[idx].callback = HalCtlsActionOnStream;
CtlHalDynApiStreamVerbs[idx].info = "Peform action on this stream";
}
if(HalUtlLoadVerbs(apiHandle, CtlHalDynApiStreamVerbs))
return -8;
}
return 0;
}
// TODO JAI: create a new section parser to get 'halmap' and store them into hal structure
/*******************************************************************************
* HAL controllers verbs functions *
******************************************************************************/
// TODO JAI : to implement
void HalCtlsActionOnStream(afb_request *request)
{
AFB_REQUEST_WARNING(request, "JAI :%s not implemented yet", __func__);
afb_request_success(request, json_object_new_boolean(false), NULL);
}
// TODO JAI : to implement
void HalCtlsListVerbs(afb_request *request)
{
AFB_REQUEST_WARNING(request, "JAI :%s not implemented yet", __func__);
afb_request_success(request, json_object_new_boolean(false), NULL);
}
|