summaryrefslogtreecommitdiffstats
path: root/src/ahl-config.c
diff options
context:
space:
mode:
authorTai Vuong <tvuong@audiokinetic.com>2017-10-27 21:40:20 -0400
committerTai Vuong <tvuong@audiokinetic.com>2017-10-27 21:40:20 -0400
commit8a584f01b46d251fdc5de8b071eff755d99f0090 (patch)
tree625bfb4d66933b8fd18428027aa38c8a708368ce /src/ahl-config.c
parent9b7e1d0361d1a5eee415e453ae79925084552c68 (diff)
Add JSON object parameters for policy functions call, fix various bug and code stabilisation
Diffstat (limited to 'src/ahl-config.c')
-rw-r--r--src/ahl-config.c126
1 files changed, 61 insertions, 65 deletions
diff --git a/src/ahl-config.c b/src/ahl-config.c
index aa55b28..168311e 100644
--- a/src/ahl-config.c
+++ b/src/ahl-config.c
@@ -1,6 +1,5 @@
/*
* Copyright (C) 2017 "Audiokinetic Inc"
- * Author Francois Thibault <fthibault@audiokinetic.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +24,22 @@
extern AHLCtxT g_AHLCtx;
+static InterruptBehaviorT InterruptBehaviorToEnum(char * in_pInterruptBehaviorStr)
+{
+ g_assert_nonnull(in_pInterruptBehaviorStr);
+ if (strcasecmp(in_pInterruptBehaviorStr,AHL_INTERRUPTBEHAVIOR_CONTINUE)==0) {
+ return INTERRUPTBEHAVIOR_CONTINUE;
+ }
+ else if (strcasecmp(in_pInterruptBehaviorStr,AHL_INTERRUPTBEHAVIOR_CANCEL)==0) {
+ return INTERRUPTBEHAVIOR_CANCEL;
+ }
+ else if (strcasecmp(in_pInterruptBehaviorStr,AHL_INTERRUPTBEHAVIOR_PAUSE)==0) {
+ return INTERRUPTBEHAVIOR_PAUSE;
+ }
+ else
+ return INTERRUPTBEHAVIOR_MAXVALUE;
+}
+
int ParseHLBConfig() {
char * versionStr = NULL;
json_object * jAudioRoles = NULL;
@@ -33,7 +48,7 @@ int ParseHLBConfig() {
// TODO: This should be retrieve from binding startup arguments
char configfile_path[256];
- sprintf(configfile_path, "%s/opt/config/ahl-config.json", getenv("HOME"));
+ sprintf(configfile_path, "%s", getenv("AHL_CONFIG_FILE"));
AFB_INFO("High-level config file -> %s\n", configfile_path);
// Open configuration file
@@ -49,36 +64,31 @@ int ParseHLBConfig() {
AFB_ERROR("Invalid configuration file -> %s", configfile_path);
return 1;
}
- AFB_INFO("Version: %s", versionStr);
+ AFB_INFO("High-level audio API version: %s", "1.0.0");
+ AFB_INFO("Config version: %s", versionStr);
AFB_INFO("Policy module: %s", policyModule);
int iHALListLength = json_object_array_length(jHALList);
+ g_AHLCtx.policyCtx.pHALList = g_ptr_array_new_with_free_func(g_free);
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_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.pRoleInfo = g_hash_table_new(g_str_hash, g_str_equal);
for (int i = 0; i < iHALListLength; i++)
{
char * pHAL = NULL;
json_object * jHAL = json_object_array_get_idx(jHALList,i);
- pHAL = (char *)json_object_get_string(jHAL);
- GString * gHALName = g_string_new( pHAL );
- g_array_append_val( g_AHLCtx.pHALList, *gHALName );
-
- // Set dependency on HAL
- err = afb_daemon_require_api_v2(pHAL,1) ;
- if( err != 0 )
- {
- AFB_ERROR("Audio high level API could not set dependenvy on API: %s",pHAL);
- return 1;
+ if (jHAL) {
+ pHAL = (char *)json_object_get_string(jHAL);
+ char * pHALName = g_strdup( pHAL );
+ g_ptr_array_add( g_AHLCtx.policyCtx.pHALList, pHALName );
+
+ // Set dependency on HAL specified
+ err = afb_daemon_require_api_v2(pHAL,1) ;
+ if( err != 0 )
+ {
+ AFB_ERROR("Audio high level API could not set dependency on API: %s",pHAL);
+ return 1;
+ }
}
}
@@ -88,13 +98,13 @@ int ParseHLBConfig() {
json_object * jAudioRole = json_object_array_get_idx(jAudioRoles,i);
json_object * jOutputDevices = NULL;
json_object * jInputDevices = NULL;
- json_object * jEvents = NULL;
+ json_object * jActions = NULL;
char * pRoleName = NULL;
char * pInteruptBehavior = NULL;
int iNumOutDevices = 0;
int iNumInDevices = 0;
- int iNumEvents = 0;
+ int iNumActions = 0;
err = wrap_json_unpack(jAudioRole, "{s:s,s:i,s:s,s?o,s?o,s?o}",
"name", &pRoleName,
@@ -102,7 +112,7 @@ int ParseHLBConfig() {
"interupt_behavior",&pInteruptBehavior,
"output",&jOutputDevices,
"input",&jInputDevices,
- "events",&jEvents
+ "actions",&jActions
);
if (err) {
AFB_ERROR("Invalid audio role configuration : %s", json_object_to_json_string(jAudioRole));
@@ -113,61 +123,47 @@ 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_hash_table_insert(g_AHLCtx.policyCtx.pRolePriority, pRoleName, GINT_TO_POINTER(priority));
-
- // Map interupt behavior string to enum value
- InterruptedBehaviorT interuptBehavior = AHL_INTERRUPTEDBEHAVIOR_CONTINUE;
- if ( strcasecmp(pInteruptBehavior,AHL_INTERRUPTEDBEHAVIOR_CONTINUE_STR) == 0 ) {
- interuptBehavior = AHL_INTERRUPTEDBEHAVIOR_CONTINUE;
- }
- else if ( strcasecmp(pInteruptBehavior,AHL_INTERRUPTEDBEHAVIOR_CANCEL_STR) == 0 ) {
- interuptBehavior = AHL_INTERRUPTEDBEHAVIOR_CANCEL;
- }
- else if ( strcasecmp(pInteruptBehavior,AHL_INTERRUPTEDBEHAVIOR_PAUSE_STR) == 0 ) {
- interuptBehavior = AHL_INTERRUPTEDBEHAVIOR_PAUSE;
- }
- else {
- AFB_ERROR("Unknown interrupt behavior : %s", pInteruptBehavior);
- return 1;
+ if (jActions)
+ iNumActions = json_object_array_length(jActions);
+
+ RoleInfoT * pRoleInfo = (RoleInfoT*) malloc(sizeof(RoleInfoT));
+ memset(pRoleInfo,0,sizeof(RoleInfoT));
+ pRoleInfo->pRoleName = g_strdup( pRoleName );
+ pRoleInfo->iPriority = priority;
+ pRoleInfo->eInterruptBehavior = InterruptBehaviorToEnum(pInteruptBehavior);
+
+ // Actions
+ pRoleInfo->pActionList = g_ptr_array_new_with_free_func(g_free);
+ // Parse and validate list of available actions
+ for (int i = 0; i < iNumActions; i++)
+ {
+ json_object * jAction = json_object_array_get_idx(jActions,i);
+ char * pActionName = (char *)json_object_get_string(jAction);
+ if (pActionName)
+ g_ptr_array_add(pRoleInfo->pActionList, g_strdup(pActionName));
}
- g_array_append_val(g_AHLCtx.policyCtx.pInterruptBehavior, interuptBehavior);
// Sources
- GArray * pRoleSourceDeviceArray = g_array_new(FALSE, TRUE, sizeof(EndpointInfoT));
- g_ptr_array_add(g_AHLCtx.policyCtx.pSourceEndpoints,pRoleSourceDeviceArray);
+ pRoleInfo->pSourceEndpoints = g_ptr_array_new_with_free_func(g_free);
if (iNumInDevices) {
- err = EnumerateSources(jInputDevices,i,pRoleName);
+ err = EnumerateDevices(jInputDevices,pRoleName,ENDPOINTTYPE_SOURCE,pRoleInfo->pSourceEndpoints);
if (err) {
AFB_ERROR("Invalid input devices : %s", json_object_to_json_string(jInputDevices));
return 1;
}
}
// Sinks
- GArray * pRoleSinkDeviceArray = g_array_new(FALSE, TRUE, sizeof(EndpointInfoT));
- g_ptr_array_add(g_AHLCtx.policyCtx.pSinkEndpoints,pRoleSinkDeviceArray);
+ pRoleInfo->pSinkEndpoints = g_ptr_array_new_with_free_func(g_free);
if (iNumOutDevices) {
- err = EnumerateSinks(jOutputDevices,i,pRoleName);
+ err = EnumerateDevices(jOutputDevices,pRoleName,ENDPOINTTYPE_SINK,pRoleInfo->pSinkEndpoints);
if (err) {
AFB_ERROR("Invalid output devices : %s", json_object_to_json_string(jOutputDevices));
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);
- }
+
+ g_hash_table_insert(g_AHLCtx.policyCtx.pRoleInfo, pRoleInfo->pRoleName, pRoleInfo);
+
}
// Build lists of all device URI referenced in config file (input/output)