From d52e5cf217ac3dfd348e80e26eb6d8844c78fc1e Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Sun, 5 Nov 2017 15:35:11 +0100 Subject: Updated to support search value in response to be interger --- alsa-hook/PolicyAlsaHook.c | 51 ++++++++++----- nbproject/configurations.xml | 146 ++++++++++++++++++++----------------------- 2 files changed, 106 insertions(+), 91 deletions(-) diff --git a/alsa-hook/PolicyAlsaHook.c b/alsa-hook/PolicyAlsaHook.c index 3fbf40e..6f88bca 100644 --- a/alsa-hook/PolicyAlsaHook.c +++ b/alsa-hook/PolicyAlsaHook.c @@ -78,6 +78,7 @@ typedef struct { typedef struct { const char *search; const char *value; + long ivalue; int signal; } afbEventT; @@ -136,7 +137,7 @@ void OnEventCB(void *handle, const char *event, int evtid, struct json_object *d afbClientT *afbClient = (afbClientT*) handle; afbEventT **afbEvent = afbClient->event; json_object *tmpJ; - int done; + int signal=0, index; // if no event handler just ignore events if (!afbEvent) goto OnErrorExit; @@ -144,17 +145,32 @@ void OnEventCB(void *handle, const char *event, int evtid, struct json_object *d if (afbClient->verbose) printf("ON-EVENT processing signal event=%s search=%s\n", event, json_object_get_string(dataJ)); // loop on event/signal mapping table - for (int index=0; afbEvent[index]!= NULL; index++) { + for (index=0; afbEvent[index]!= NULL; index++) { + int done; + done = json_object_object_get_ex(dataJ,afbEvent[index]->search, &tmpJ); if (done) { - const char *value=json_object_get_string(tmpJ); - if (!strcmp(afbEvent[index]->value, value)) { - if (afbEvent[index]->signal) { - if (afbClient->verbose) printf("ON-EVENT search=%s value=%s signal=%d\n", afbEvent[index]->search, value, afbEvent[index]->signal); - if (afbEvent[index]->signal) kill (getpid(), afbEvent[index]->signal); - } + + if (afbEvent[index]->value) { + // search value is a string + if (json_object_get_type(tmpJ) != json_type_string) goto OnErrorExit; + const char *value=json_object_get_string(tmpJ); + if (!strcmp(afbEvent[index]->value, value)) signal=afbEvent[index]->signal; + + } else { + + // search value is an integer + if (json_object_get_type(tmpJ) != json_type_int) goto OnErrorExit; + int ivalue=json_object_get_int(tmpJ); + if (ivalue == afbEvent[index]->ivalue) signal=afbEvent[index]->signal; } - } + break; + + } + } + if (signal) { + if (afbClient->verbose) printf("ON-EVENT self-signal search=%s signal=%d\n", afbEvent[index]->search, afbEvent[index]->signal); + if (afbEvent[index]->signal) kill (getpid(), afbEvent[index]->signal); } return; @@ -503,17 +519,24 @@ static int AlsaGetEvents (snd_config_t *node, afbEventT **afbEvent, const char*i err = snd_config_search(ctlconfig, "value", &itemConf); if (!err) { const char *value; - if (snd_config_get_string(itemConf, &value) < 0) { - SNDERR("Invalid event/signal 'value' should be a string %s", confEvents); - goto OnErrorExit; + switch (snd_config_get_type(itemConf)) { + case SND_CONFIG_TYPE_INTEGER: + snd_config_get_integer(itemConf, &afbEvent[callCount]->ivalue); + break; + + case SND_CONFIG_TYPE_STRING: + snd_config_get_string(itemConf, &value); + afbEvent[callCount]->value=strdup(value); + break; + default: + SNDERR("Invalid event/signal 'value' should be a string %s", confEvents); + goto OnErrorExit; } - afbEvent[callCount]->value=strdup(value); } else { SNDERR("Missing 'value' from event/signal 'value' from signal definition %s", confEvents); goto OnErrorExit; } - // move to next call if any callCount ++; if (callCount == MAX_EVT_CALL) { diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 4bd0c69..75116a1 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -1416,11 +1416,12 @@ false - - - - - + + + + + @@ -1429,10 +1430,10 @@ build - ${MAKE} -f Makefile populate + ${MAKE} -f Makefile ${MAKE} -f Makefile clean build/CMakeFiles/feature_tests.bin - + @@ -1442,7 +1443,7 @@ - + ../../../opt/include/afb Audio-Common @@ -1452,7 +1453,7 @@ - + ../../../opt/include/afb Audio-Common @@ -1462,7 +1463,7 @@ - + Audio-Common /usr/include/json-c @@ -1471,18 +1472,18 @@ - + - + build/Controller-afb - + /usr/include/json-c /usr/include/lua5.3 @@ -1493,7 +1494,7 @@ - + /usr/include/json-c /usr/include/lua5.3 @@ -1504,7 +1505,7 @@ - + /usr/include/json-c build/Controller-afb @@ -1512,7 +1513,7 @@ - + /usr/include/json-c /usr/include/lua5.3 @@ -1521,7 +1522,7 @@ - + ../../../opt/include build/Controller-afb @@ -1532,7 +1533,7 @@ ex="false" tool="0" flavor2="3"> - + Audio-Common build/HAL-afb/HAL-interface @@ -1543,7 +1544,7 @@ ex="false" tool="0" flavor2="3"> - + Audio-Common build/HAL-afb/HAL-interface @@ -1551,21 +1552,21 @@ - + build/HAL-afb/HAL-interface - + - + ../../../opt/include/afb HAL-afb/HAL_MOST_UNICENS @@ -1579,35 +1580,35 @@ ex="false" tool="1" flavor2="4"> - + - + - + - + - + HAL-afb/HAL_MOST_UNICENS build/HAL-afb/HAL_MOST_UNICENS @@ -1618,7 +1619,7 @@ ex="false" tool="0" flavor2="3"> - + ../../../opt/include/afb HAL-afb/HAL_MOST_UNICENS @@ -1630,7 +1631,7 @@ ex="false" tool="0" flavor2="3"> - + ../../../opt/include/afb HAL-afb/HAL_MOST_UNICENS @@ -1640,25 +1641,25 @@ - + - + - + - + Shared-Interface HAL-afb/HAL-interface @@ -1667,7 +1668,7 @@ - + HAL-afb/HAL-interface build/HAL-afb/Unicens-USB @@ -1675,11 +1676,11 @@ - + - + @@ -1717,7 +1718,7 @@ - + ../../../opt/include/afb afb-utilities @@ -1727,7 +1728,7 @@ - + afb-utilities /usr/include/json-c @@ -1736,55 +1737,27 @@ - - - ../../../opt/include/alsa - /usr/include/json-c - ../../../opt/include - build/alsa-binding - + - - - /usr/include/json-c - build/alsa-binding - + - - - ../../../opt/include/alsa - /usr/include/json-c - ../../../opt/include - build/alsa-binding - + - - - ../../../opt/include/alsa - /usr/include/json-c - ../../../opt/include - build/alsa-binding - + - - - ../../../opt/include/alsa - /usr/include/json-c - ../../../opt/include - build/alsa-binding - + - + @@ -2024,21 +1997,40 @@ - ../../../opt/include/afb - alsa-binding + /usr/include/json-c + ../../../opt/include + /usr/include/p11-kit-1 + ../../../opt/include/alsa + build/alsa-binding + + CONTROL_MAXPATH_LEN=255 + MAX_LINEAR_DB_SCALE=24 + MAX_SND_CARD=16 + NATIVE_LINUX + TLV_BYTE_SIZE=256 + alsa_4a_EXPORTS + - alsa-hook - ../../../opt/include/alsa /usr/include/json-c - ../../../opt/include/afb ../../../opt/include + /usr/include/p11-kit-1 + ../../../opt/include/alsa build/alsa-hook + + CONTROL_MAXPATH_LEN=255 + MAX_LINEAR_DB_SCALE=24 + MAX_SND_CARD=16 + NATIVE_LINUX + PIC + TLV_BYTE_SIZE=256 + policy_alsa_hook_EXPORTS + -- cgit 1.2.3-korg