aboutsummaryrefslogtreecommitdiffstats
path: root/alsa-hook
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2017-11-05 15:35:11 +0100
committerFulup Ar Foll <fulup@iot.bzh>2017-11-05 15:35:11 +0100
commitd52e5cf217ac3dfd348e80e26eb6d8844c78fc1e (patch)
tree94c4321be207e270bcbcb9160ecbf52bab9d89ee /alsa-hook
parente5742e9244b21a866a1dc15b618a11a4e515e019 (diff)
Updated to support search value in response to be interger
Diffstat (limited to 'alsa-hook')
-rw-r--r--alsa-hook/PolicyAlsaHook.c51
1 files changed, 37 insertions, 14 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) {