From 0c99273762e161b703ce0540596d66947d27e1d1 Mon Sep 17 00:00:00 2001
From: Jonathan Aillet <jonathan.aillet@iot.bzh>
Date: Sat, 9 Jun 2018 19:55:01 +0200
Subject: Move controller config exec before onload action

Before, the onload action specified in the audio configuration file
(see controller documention) was exectued before the sections
configuration execution call. So, the onload action was launched
before the hal was ready.
Now, onload action is launched last.

Change-Id: I05d46622b938ae5a818bd404779a2263ed334397
Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
---
 4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c
index 58dad10..13d5490 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c
@@ -121,12 +121,12 @@ static int HalCtlsInitOneApi(AFB_ApiT apiHandle)
 
 	// TBD JAI: handle refresh of hal status for dynamic card (/dev/by-id)
 
-	return CtlConfigExec(apiHandle, ctrlConfig);
+	return 0;
 }
 
 static int HalCtlsLoadOneApi(void *cbdata, AFB_ApiT apiHandle)
 {
-	int err;
+	int err = 0;
 	CtlConfigT *ctrlConfig;
 
 	if(! cbdata || ! apiHandle )
@@ -144,13 +144,17 @@ static int HalCtlsLoadOneApi(void *cbdata, AFB_ApiT apiHandle)
 	}
 
 	// Load section for corresponding Api
-	err = CtlLoadSections(apiHandle, ctrlConfig, ctrlSections);
+	err += CtlLoadSections(apiHandle, ctrlConfig, ctrlSections);
 
 	// Declare an event manager for this Api
 	afb_dynapi_on_event(apiHandle, HalCtlsDispatchApiEvent);
 
 	// Init Api function (does not receive user closure ???)
-	afb_dynapi_on_init(apiHandle, HalCtlsInitOneApi);
+	afb_dynapi_on_init(apiHandle, NULL);
+
+	err += HalCtlsInitOneApi(apiHandle);
+
+	err += CtlConfigExec(apiHandle, ctrlConfig);
 
 	return err;
 }
-- 
cgit