summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Jahnke <tjahnk@users.noreply.github.com>2017-08-15 13:34:17 +0200
committerTobias Jahnke <tjahnk@users.noreply.github.com>2017-08-16 16:00:50 +0200
commit999340f641477f94e3730e53d8a8bf39fe93b0c4 (patch)
tree20fad1c4a16336e512a3035b51e9ac239dfb73eb
parent4aec17e1d42c1b0f3f628342bf24120299a0c819 (diff)
implemented listconfig in UNICENS wrapper
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/hal_most_unicens.c23
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/wrap_unicens.c110
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/wrap_unicens.h2
-rw-r--r--conf.d/cmake/config.cmake2
-rw-r--r--nbproject/configurations.xml88
5 files changed, 187 insertions, 38 deletions
diff --git a/HAL-afb/HAL_MOST_UNICENS/hal_most_unicens.c b/HAL-afb/HAL_MOST_UNICENS/hal_most_unicens.c
index 2cffe8d..7240fe0 100644
--- a/HAL-afb/HAL_MOST_UNICENS/hal_most_unicens.c
+++ b/HAL-afb/HAL_MOST_UNICENS/hal_most_unicens.c
@@ -23,10 +23,12 @@
#include "wrap_unicens.h"
#include "wrap_volume.h"
-#define XML_CONFIG_PATH "/home/agluser/DEVELOPMENT/AGL/BINDING/unicens2-binding/data/config_multichannel_audio_kit.xml"
-#define ALSA_CARD_NAME "Microchip MOST:1"
+#ifndef UCS2_CFG_PATH
+# define UCS2_CFG_PATH "/home/agluser/DEVELOPMENT/AGL/BINDING/unicens2-binding/data"
+#endif
-#define PCM_MAX_CHANNELS 6
+#define ALSA_CARD_NAME "Microchip MOST:1"
+#define PCM_MAX_CHANNELS 6
static int master_volume;
static json_bool master_switch;
@@ -96,6 +98,7 @@ STATIC alsaHalSndCardT alsaHalSndCard = {
/* initializes ALSA sound card, UNICENS API */
STATIC int unicens_service_init() {
int err = 0;
+ char *config_file = NULL;
AFB_NOTICE("Initializing HAL-MOST-UNICENS-BINDING");
err = halServiceInit(afbBindingV2.api, &alsaHalSndCard);
@@ -110,13 +113,25 @@ STATIC int unicens_service_init() {
goto OnErrorExit;
}
+ err = wrap_ucs_getconfig_sync(UCS2_CFG_PATH, &config_file);
+ if (err || (config_file == NULL)) {
+ AFB_ERROR("Failed to retrieve configuration");
+ goto OnErrorExit;
+ }
+ else {
+ AFB_NOTICE("Found configuration: %s", config_file);
+ }
+
err = wrap_ucs_subscribe_sync();
if (err) {
AFB_ERROR("Failed to subscribe to UNICENS binding");
goto OnErrorExit;
}
- err = wrap_ucs_initialize_sync(XML_CONFIG_PATH);
+ err = wrap_ucs_initialize_sync(config_file);
+ free(config_file);
+ config_file = NULL;
+
if (err) {
AFB_ERROR("Failed to initialize UNICENS binding");
goto OnErrorExit;
diff --git a/HAL-afb/HAL_MOST_UNICENS/wrap_unicens.c b/HAL-afb/HAL_MOST_UNICENS/wrap_unicens.c
index 0cac86b..dc82568 100644
--- a/HAL-afb/HAL_MOST_UNICENS/wrap_unicens.c
+++ b/HAL-afb/HAL_MOST_UNICENS/wrap_unicens.c
@@ -21,14 +21,18 @@
#include <string.h>
#include <json-c/json.h>
#include <afb/afb-binding.h>
-
#include "wrap_unicens.h"
#include "wrap-json.h"
typedef struct async_job_ {
- wrap_ucs_result_cb_t result_fptr;
+ wrap_ucs_result_cb_t result_fptr;
void *result_user_ptr;
-} async_job_t;
+} async_job_t;
+
+typedef struct parse_result_ {
+ int done;
+ char *str_result;
+} parse_result_t;
/* Subscribes to unicens2-binding events.
* \return Returns 0 if successful, otherwise != 0".
@@ -63,19 +67,78 @@ OnErrorExit:
return err;
}
+/* Checks if name ends with a given letter. */
+static int wrap_ucs_string_ends_with(const char *name, char letter) {
+
+ int result = 0;
+ size_t len = strlen(name);
+
+ if (len > 0) {
+
+ if (name[len] == letter) {
+ result = 1;
+ }
+ }
+
+ return result;
+}
+
+/* Callback for iteration through found files. Marks search as "done" as
+ * soon as the search pattern "kit.xml" matches.
+ * \param closure User reference. Points to parse_result_t.
+ * \param j_obj Points to json object within array.
+ */
+static void wrap_ucs_find_xml_cb(void *closure, struct json_object *j_obj) {
+
+ const char *dir, *name;
+ parse_result_t *result;
+
+ if (!closure)
+ return;
+
+ result = (parse_result_t *)closure;
+ if (result->done)
+ return;
+
+ wrap_json_unpack(j_obj, "{s:s, s:s}", "dirpath", &dir, "basename", &name);
+ AFB_DEBUG("Found file: %s", name);
+
+ if(strstr(name, "kit.xml") != NULL) {
+ size_t sz = strlen(dir)+strlen(name)+10;
+ char * full_path = malloc(sz);
+
+ strncpy(full_path, dir, sz);
+
+ if (!wrap_ucs_string_ends_with(dir, '/'))
+ strncat(full_path, "/", sz);
+
+ strncat(full_path, name, sz);
+ AFB_DEBUG("Found XML file: %s", full_path);
+
+ result->done = 1;
+ result->str_result = full_path;
+ }
+}
+
/* Retrieves XML configuration path to initialize unicens2-binding.
- * \param config_path Directory containing XML configuration file(s).
+ * \param config_path Directory containing XML configuration file(s).
+ * \param file_found Points to found file_path or NULL if not found.
+ * Memory must be released by calling free().
* \return Returns 0 if successful, otherwise != 0".
*/
-extern int wrap_ucs_getconfig_sync(const char *config_path) {
- json_object *j_response, *j_query = NULL;
- int err;
+extern int wrap_ucs_getconfig_sync(const char *config_path, char **file_found) {
+
+ int err = 0;
+ json_object *j_response, *j_query, *j_paths = NULL;
+ parse_result_t result = {.done = 0, .str_result = NULL};
+
+ *file_found = NULL;
/* Build JSON object to retrieve UNICENS configuration */
- if (config_path != NULL)
- err = wrap_json_pack(&j_query, "{s:s}", "cfgpath", config_path);
- else
+ if ((config_path == NULL) || (strcmp(config_path, "") == 0))
err = wrap_json_pack(&j_query, "{}");
+ else
+ err = wrap_json_pack(&j_query, "{s:s}", "cfgpath", config_path);
if (err) {
AFB_ERROR("Failed to create listconfig json object");
@@ -88,7 +151,25 @@ extern int wrap_ucs_getconfig_sync(const char *config_path) {
goto OnErrorExit;
}
else {
- AFB_NOTICE("UNICENS listconfig result, res=%s", json_object_to_json_string(j_response));
+ AFB_DEBUG("UNICENS listconfig result, res=%s", json_object_to_json_string(j_response));
+
+ if (json_object_object_get_ex(j_response, "response", &j_paths)) {
+
+ AFB_DEBUG("UNICENS listconfig result, paths=%s", json_object_to_json_string(j_paths));
+
+ wrap_json_optarray_for_all(j_paths, &wrap_ucs_find_xml_cb, &result);
+
+ if (result.done) {
+ *file_found = strdup(result.str_result);
+ free(result.str_result);
+ result.str_result = NULL;
+ }
+ else {
+ AFB_NOTICE("wrap_ucs_getconfig_sync, search pattern does not match for paths=%s", json_object_to_json_string(j_paths));
+ err = -1;
+ }
+ }
+
json_object_put(j_response);
}
json_object_put(j_query);
@@ -100,7 +181,6 @@ OnErrorExit:
return err;
}
-
/* Initializes the unicens2-binding.
* \param file_name Path to XML configuration file or \c NULL for
* first found file in default path.
@@ -170,11 +250,11 @@ extern int wrap_ucs_i2cwrite_sync(uint16_t node, uint8_t *data_ptr, uint8_t data
err = afb_service_call_sync("UNICENS", "writei2c", j_query, &j_response);
if (err) {
- AFB_ERROR("Failed to call writei2c");
+ AFB_ERROR("Failed to call writei2c_sync");
goto OnErrorExit;
}
else {
- AFB_NOTICE("Called writei2c, res=%s", "async"/*json_object_to_json_string(j_response)*/);
+ AFB_INFO("Called writei2c_sync, res=%s", json_object_to_json_string(j_response));
json_object_put(j_response);
}
@@ -191,7 +271,7 @@ OnErrorExit:
static void wrap_ucs_i2cwrite_cb(void *closure, int status, struct json_object *j_result) {
- AFB_DEBUG("wrap_ucs_i2cwrite_cb: closure=%p status=%d, res=%s", closure, status, json_object_to_json_string(j_result));
+ AFB_INFO("wrap_ucs_i2cwrite_cb: closure=%p status=%d, res=%s", closure, status, json_object_to_json_string(j_result));
if (closure) {
async_job_t *job_ptr = (async_job_t *)closure;
diff --git a/HAL-afb/HAL_MOST_UNICENS/wrap_unicens.h b/HAL-afb/HAL_MOST_UNICENS/wrap_unicens.h
index 268fb74..c28d13a 100644
--- a/HAL-afb/HAL_MOST_UNICENS/wrap_unicens.h
+++ b/HAL-afb/HAL_MOST_UNICENS/wrap_unicens.h
@@ -29,6 +29,6 @@ extern int wrap_ucs_i2cwrite(uint16_t node, uint8_t *data_ptr, uint8_t data_sz,
/* Synchronous API: functions */
extern int wrap_ucs_subscribe_sync();
-extern int wrap_ucs_getconfig_sync(const char *config_path);
+extern int wrap_ucs_getconfig_sync(const char *config_path, char **file_found);
extern int wrap_ucs_initialize_sync(const char* file_name);
extern int wrap_ucs_i2cwrite_sync(uint16_t node, uint8_t *data_ptr, uint8_t data_sz);
diff --git a/conf.d/cmake/config.cmake b/conf.d/cmake/config.cmake
index 73a00f6..9719711 100644
--- a/conf.d/cmake/config.cmake
+++ b/conf.d/cmake/config.cmake
@@ -83,6 +83,8 @@ set (PKG_REQUIRED_LIST
add_compile_options(-DCTL_PLUGIN_MAGIC=2468013579)
add_compile_options(-DCONTROL_PLUGIN_PATH="${CMAKE_BINARY_DIR}:${BINDINGS_INSTALL_DIR}/ctlplug:/usr/lib/afb/ctlplug")
+ add_compile_options(-DUCS2_CFG_PATH="../../unicens2-binding/data:/etc/default/ucs:../data:./data")
+
# Print a helper message when every thing is finished
# ----------------------------------------------------
set(CLOSING_MESSAGE "Debug in ./buid: afb-daemon --port=1234 --ldpaths=. --workdir=. --roothttp=../htdocs --tracereq=common --token='' --verbose")
diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml
index 75a5a25..f7241d3 100644
--- a/nbproject/configurations.xml
+++ b/nbproject/configurations.xml
@@ -61,6 +61,14 @@
<in>HalPlugPcm.c</in>
</df>
<df name="HAL_MOST_UNICENS">
+ <df name="ucs2-vol">
+ <df name="src">
+ <in>device_container.cpp</in>
+ <in>device_value.cpp</in>
+ <in>libmostvolume.cpp</in>
+ <in>setup.cpp</in>
+ </df>
+ </df>
<in>hal_most_unicens.c</in>
<in>wrap-json.c</in>
<in>wrap_unicens.c</in>
@@ -387,7 +395,7 @@
</cTool>
</item>
<item path="HAL-afb/HAL-interface/hal-volume.c" ex="false" tool="0" flavor2="3">
- <cTool flags="3">
+ <cTool flags="4">
<incDir>
<pElem>/usr/lib64/gcc/x86_64-suse-linux/5/include</pElem>
<pElem>build/HAL-afb/HAL-interface</pElem>
@@ -395,7 +403,7 @@
</cTool>
</item>
<item path="HAL-afb/HAL-plugin/HalPlugCb.c" ex="false" tool="0" flavor2="3">
- <cTool flags="3">
+ <cTool flags="4">
<incDir>
<pElem>HAL-afb/HAL-plugin</pElem>
<pElem>/usr/lib64/gcc/x86_64-suse-linux/5/include</pElem>
@@ -404,7 +412,7 @@
</cTool>
</item>
<item path="HAL-afb/HAL-plugin/HalPlugCtl.c" ex="false" tool="0" flavor2="3">
- <cTool flags="3">
+ <cTool flags="4">
<incDir>
<pElem>HAL-afb/HAL-plugin</pElem>
<pElem>/usr/lib64/gcc/x86_64-suse-linux/5/include</pElem>
@@ -413,7 +421,7 @@
</cTool>
</item>
<item path="HAL-afb/HAL-plugin/HalPlugPcm.c" ex="false" tool="0" flavor2="3">
- <cTool flags="1">
+ <cTool flags="2">
<incDir>
<pElem>../../../opt/include/afb</pElem>
<pElem>HAL-afb/HAL-plugin</pElem>
@@ -433,7 +441,7 @@
flavor2="3">
<incDir>
<pElem>/opt/AGL/include/afb</pElem>
- <pElem>HAL-afb/hal-most-unicens</pElem>
+ <pElem>HAL-afb/HAL_MOST_UNICENS</pElem>
<pElem>/usr/include/json-c</pElem>
<pElem>Shared-Interface</pElem>
<pElem>HAL-afb/HAL-interface</pElem>
@@ -441,11 +449,55 @@
</incDir>
</cTool>
</item>
+ <item path="HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_container.cpp"
+ ex="false"
+ tool="1"
+ flavor2="0">
+ <ccTool flags="1">
+ <incDir>
+ <pElem>HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc</pElem>
+ <pElem>HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src</pElem>
+ </incDir>
+ </ccTool>
+ </item>
+ <item path="HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_value.cpp"
+ ex="false"
+ tool="1"
+ flavor2="0">
+ <ccTool flags="1">
+ <incDir>
+ <pElem>HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src</pElem>
+ <pElem>HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc</pElem>
+ </incDir>
+ </ccTool>
+ </item>
+ <item path="HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/libmostvolume.cpp"
+ ex="false"
+ tool="1"
+ flavor2="0">
+ <ccTool flags="1">
+ <incDir>
+ <pElem>HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src</pElem>
+ <pElem>HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc</pElem>
+ </incDir>
+ </ccTool>
+ </item>
+ <item path="HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/setup.cpp"
+ ex="false"
+ tool="1"
+ flavor2="0">
+ <ccTool flags="1">
+ <incDir>
+ <pElem>HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc</pElem>
+ <pElem>HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src</pElem>
+ </incDir>
+ </ccTool>
+ </item>
<item path="HAL-afb/HAL_MOST_UNICENS/wrap-json.c"
ex="false"
tool="0"
flavor2="3">
- <cTool flags="3">
+ <cTool flags="4">
<incDir>
<pElem>HAL-afb/HAL-interface</pElem>
<pElem>build/HAL-afb/Unicens-USB</pElem>
@@ -458,10 +510,10 @@
flavor2="3">
<incDir>
<pElem>/opt/AGL/include/afb</pElem>
- <pElem>HAL-afb/hal-most-unicens</pElem>
- <pElem>/usr/include/json-c</pElem>
+ <pElem>HAL-afb/HAL_MOST_UNICENS</pElem>
<pElem>/usr/lib64/gcc/x86_64-suse-linux/5/include</pElem>
- <pElem>build/HAL-afb/hal-most-unicens</pElem>
+ <pElem>/usr/include/json-c</pElem>
+ <pElem>build/HAL-afb/HAL_MOST_UNICENS</pElem>
</incDir>
</cTool>
</item>
@@ -469,29 +521,29 @@
ex="false"
tool="0"
flavor2="3">
- <cTool flags="3">
+ <cTool flags="4">
<incDir>
<pElem>/opt/AGL/include/afb</pElem>
- <pElem>HAL-afb/hal-most-unicens</pElem>
+ <pElem>HAL-afb/HAL_MOST_UNICENS</pElem>
<pElem>/usr/lib64/gcc/x86_64-suse-linux/5/include</pElem>
- <pElem>HAL-afb/hal-most-unicens/ucs2-vol/inc</pElem>
- <pElem>build/HAL-afb/hal-most-unicens</pElem>
+ <pElem>HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc</pElem>
+ <pElem>build/HAL-afb/HAL_MOST_UNICENS</pElem>
</incDir>
</cTool>
</item>
<item path="HAL-afb/HDA-intel/IntelHdaHAL.c" ex="false" tool="0" flavor2="3">
- <cTool flags="3">
+ <cTool flags="4">
</cTool>
</item>
<item path="HAL-afb/Scarlett-Focusrite/ScarlettUsbHAL.c"
ex="false"
tool="0"
flavor2="3">
- <cTool flags="3">
+ <cTool flags="4">
</cTool>
</item>
<item path="HAL-afb/Unicens-USB/UnicensHAL.c" ex="false" tool="0" flavor2="3">
- <cTool flags="3">
+ <cTool flags="4">
<incDir>
<pElem>Shared-Interface</pElem>
<pElem>HAL-afb/HAL-interface</pElem>
@@ -502,7 +554,7 @@
</cTool>
</item>
<item path="HAL-afb/Unicens-USB/UnicensVol.c" ex="false" tool="0" flavor2="3">
- <cTool flags="3">
+ <cTool flags="4">
<incDir>
<pElem>HAL-afb/HAL-interface</pElem>
<pElem>/usr/lib64/gcc/x86_64-suse-linux/5/include</pElem>
@@ -519,7 +571,7 @@
</cTool>
</item>
<item path="Shared-Interface/audio-interface.c" ex="false" tool="0" flavor2="3">
- <cTool flags="3">
+ <cTool flags="4">
</cTool>
</folder>
<folder path="0/Alsa-afb">