aboutsummaryrefslogtreecommitdiffstats
path: root/alsa-hook/PolicyAlsaHook.c
diff options
context:
space:
mode:
Diffstat (limited to 'alsa-hook/PolicyAlsaHook.c')
-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) {