summaryrefslogtreecommitdiffstats
path: root/src/ahl-config.c
diff options
context:
space:
mode:
authorTai Vuong <tvuong@audiokinetic.com>2017-10-04 14:21:28 -0400
committerTai Vuong <tvuong@audiokinetic.com>2017-10-04 14:21:28 -0400
commit539f65bb5ad87238422a5ca26c5b524c3be44bd1 (patch)
tree01fa955edf1e9b597a4a4247b3a35390c7b6ddbc /src/ahl-config.c
parentd69dc9732886074e9f400961b500e70d5c8305d7 (diff)
Post AudioWorkshop Work phase v1
Diffstat (limited to 'src/ahl-config.c')
-rw-r--r--src/ahl-config.c66
1 files changed, 38 insertions, 28 deletions
diff --git a/src/ahl-config.c b/src/ahl-config.c
index 432910f..dcf828f 100644
--- a/src/ahl-config.c
+++ b/src/ahl-config.c
@@ -23,15 +23,12 @@
#include "ahl-binding.h"
-// TODO: Term() to free all allocs upon exit...
-
extern AHLCtxT g_AHLCtx;
-PUBLIC int ParseHLBConfig() {
+int ParseHLBConfig() {
char * versionStr = NULL;
json_object * jAudioRoles = NULL;
json_object * jHALList = NULL;
- json_object * jStateList = NULL;
// TODO: This should be retrieve from binding startup arguments
char configfile_path[256];
@@ -46,40 +43,27 @@ PUBLIC int ParseHLBConfig() {
return 1;
}
- int err = wrap_json_unpack(config_JFile, "{s:s,s:o,s:o,s:o}", "version", &versionStr,"audio_roles",&jAudioRoles,"hal_list",&jHALList,"state_list",&jStateList);
+ int err = wrap_json_unpack(config_JFile, "{s:s,s:o,s:o}", "version", &versionStr,"audio_roles",&jAudioRoles,"hal_list",&jHALList);
if (err) {
AFB_ERROR("Invalid configuration file -> %s", configfile_path);
return 1;
}
- // Parse and populate list of known states
- g_AHLCtx.pDefaultStatesHT = g_hash_table_new(g_str_hash, g_str_equal);
- int iStateListLength = json_object_array_length(jStateList);
- for ( int i = 0; i < iStateListLength; i++)
- {
- char * pStateName = NULL;
- char * pStateVal = NULL;
- json_object * jStateobject = json_object_array_get_idx(jStateList,i);
- err = wrap_json_unpack(jStateobject, "{s:s,s:s}", "name", &pStateName,"default_val",&pStateVal);
- if (err) {
- AFB_ERROR("Invalid state object -> %s", json_object_get_string(jStateobject));
- return 1;
- }
-
- g_hash_table_insert(g_AHLCtx.pDefaultStatesHT, pStateName, pStateVal);
- }
-
int iHALListLength = json_object_array_length(jHALList);
int iNumberOfRoles = json_object_array_length(jAudioRoles);
+ g_AHLCtx.policyCtx.iNumberRoles = iNumberOfRoles;
+
// Dynamically allocated based on number or roles found
g_AHLCtx.pHALList = g_array_sized_new(FALSE, TRUE, sizeof(GString), iHALListLength);
- g_AHLCtx.policyCtx.pRolePriority = g_array_sized_new(FALSE, TRUE, sizeof(int), iNumberOfRoles);
+ g_AHLCtx.policyCtx.pRolePriority = g_hash_table_new(g_str_hash, g_str_equal);
g_AHLCtx.policyCtx.pAudioRoles = g_array_sized_new(FALSE, TRUE, sizeof(GString), iNumberOfRoles);
+ g_AHLCtx.policyCtx.pInterruptBehavior = g_array_sized_new(FALSE, TRUE, sizeof(int), iNumberOfRoles);
g_AHLCtx.policyCtx.pSourceEndpoints = g_ptr_array_sized_new(iNumberOfRoles);
g_AHLCtx.policyCtx.pSinkEndpoints = g_ptr_array_sized_new(iNumberOfRoles);
+ g_AHLCtx.policyCtx.pEventList = g_ptr_array_sized_new(iNumberOfRoles);
g_AHLCtx.policyCtx.iNumberRoles = iNumberOfRoles;
- for (unsigned int i = 0; i < iHALListLength; i++)
+ for (int i = 0; i < iHALListLength; i++)
{
char * pHAL = NULL;
json_object * jHAL = json_object_array_get_idx(jHALList,i);
@@ -96,17 +80,27 @@ PUBLIC int ParseHLBConfig() {
}
}
- for (unsigned int i = 0; i < iNumberOfRoles; i++)
+ for (int i = 0; i < iNumberOfRoles; i++)
{
int priority = 0;
json_object * jAudioRole = json_object_array_get_idx(jAudioRoles,i);
json_object * jOutputDevices = NULL;
json_object * jInputDevices = NULL;
+ json_object * jEvents = NULL;
char * pRoleName = NULL;
+ InterruptedBehaviorT interupBehavior = AHL_INTERRUPTEDBEHAVIOR_CONTINUE; //Default
+
int iNumOutDevices = 0;
int iNumInDevices = 0;
-
- err = wrap_json_unpack(jAudioRole, "{s:s,s:i,s?o,s?o}", "name", &pRoleName,"priority",&priority,"output",&jOutputDevices,"input",&jInputDevices);
+ int iNumEvents = 0;
+
+ err = wrap_json_unpack(jAudioRole, "{s:s,s:i,s?o,s?o,s?o,s?i}",
+ "name", &pRoleName,
+ "priority",&priority,
+ "output",&jOutputDevices,
+ "input",&jInputDevices,
+ "events",&jEvents,
+ "interupt_behavior",&interupBehavior);
if (err) {
AFB_ERROR("Invalid audio role configuration : %s", json_object_to_json_string(jAudioRole));
return 1;
@@ -116,10 +110,14 @@ PUBLIC int ParseHLBConfig() {
iNumOutDevices = json_object_array_length(jOutputDevices);
if (jInputDevices)
iNumInDevices = json_object_array_length(jInputDevices);
+ if (jEvents)
+ iNumEvents = json_object_array_length(jEvents);
GString * gRoleName = g_string_new( pRoleName );
g_array_append_val( g_AHLCtx.policyCtx.pAudioRoles, *gRoleName );
- g_array_append_val( g_AHLCtx.policyCtx.pRolePriority, priority );
+ g_hash_table_insert(g_AHLCtx.policyCtx.pRolePriority, pRoleName, &priority);
+
+ g_array_append_val(g_AHLCtx.policyCtx.pInterruptBehavior, interupBehavior);
// Sources
GArray * pRoleSourceDeviceArray = g_array_new(FALSE, TRUE, sizeof(EndpointInfoT));
@@ -131,6 +129,7 @@ PUBLIC int ParseHLBConfig() {
return 1;
}
}
+ // Sinks
GArray * pRoleSinkDeviceArray = g_array_new(FALSE, TRUE, sizeof(EndpointInfoT));
g_ptr_array_add(g_AHLCtx.policyCtx.pSinkEndpoints,pRoleSinkDeviceArray);
if (iNumOutDevices) {
@@ -140,6 +139,17 @@ PUBLIC int ParseHLBConfig() {
return 1;
}
}
+ // Events
+ GArray * pEventsArray = g_array_new(FALSE, TRUE, sizeof(GString));
+ g_ptr_array_add(g_AHLCtx.policyCtx.pEventList,pEventsArray);
+ // Parse and validate list of available events
+ for (int i = 0; i < iNumEvents; i++)
+ {
+ json_object * jEvent = json_object_array_get_idx(jEvents,i);
+ char * pEventName = (char *)json_object_get_string(jEvent);
+ GString * gsEventName = g_string_new(pEventName);
+ g_array_append_val(pEventsArray, *gsEventName);
+ }
}
// Build lists of all device URI referenced in config file (input/output)