summaryrefslogtreecommitdiffstats
path: root/hook-plugin/PolicyHookCb.c
diff options
context:
space:
mode:
Diffstat (limited to 'hook-plugin/PolicyHookCb.c')
-rw-r--r--hook-plugin/PolicyHookCb.c72
1 files changed, 41 insertions, 31 deletions
diff --git a/hook-plugin/PolicyHookCb.c b/hook-plugin/PolicyHookCb.c
index b751ed6..1ca6670 100644
--- a/hook-plugin/PolicyHookCb.c
+++ b/hook-plugin/PolicyHookCb.c
@@ -30,6 +30,8 @@
#define _GNU_SOURCE
#include <stdio.h>
+#include <alloca.h>
+
#include <alsa/asoundlib.h>
#include <alsa/conf.h>
#include <alsa/pcm.h>
@@ -65,15 +67,12 @@
// Currently not implemented
#define UNUSED_ARG(x) UNUSED_ ## x __attribute__((__unused__))
-static void OnSuccessCB(void* UNUSED_ARG(handle) , void* UNUSED_ARG(request), struct json_object* UNUSED_ARG(reslt), const char* UNUSED_ARG(info)) {}
-static void OnFailureCB(void* UNUSED_ARG(closure), void* UNUSED_ARG(request), const char *UNUSED_ARG(status), const char *UNUSED_ARG(info)) {}
typedef struct {
const char *openVerb;
const char *closeVerb;
json_object *queryJ;
long timeout;
- size_t length;
sd_event_source *evtSource;
char *callIdTag;
@@ -169,46 +168,55 @@ OnErrorExit:
return;
}
-
-/* the callback interface for pws */
-static struct afb_proto_ws_client_itf itf = {
- .on_reply_success = OnSuccessCB,
- .on_reply_fail = OnFailureCB,
- .on_event_create = NULL,
- .on_event_remove = NULL,
- .on_event_subscribe = NULL,
- .on_event_unsubscribe = NULL,
- .on_event_push = OnEventCB,
- .on_event_broadcast = NULL,
- .on_subcall = NULL,
-};
-
-void OnResponseCB(void *handle, struct afb_wsj1_msg *msg) {
+static void OnSuccessCB(void* UNUSED_ARG(ctx) , void* handle, json_object* responseJ, const char* info) {
+
afbRequestT *afbRequest= (afbRequestT*)handle;
afbClientT *afbClient=(afbClientT*)afbRequest->afbClient;
- if (afbClient->verbose) printf("ON-RESPONSE call=%s response=%s\n", afbRequest->callIdTag, afb_wsj1_msg_object_s(msg));
+ if (afbClient->verbose) printf("OnSuccessCB callid='%s' response='%s' info='%s'\n", afbRequest->callIdTag, json_object_get_string(responseJ), info);
// Cancel timeout for this request
sd_event_source_unref(afbRequest->evtSource);
-
- if (! afb_wsj1_msg_is_reply_ok(msg)) goto OnErrorExit;
+ free(afbRequest->callIdTag);
// When not more waiting call release semaphore
afbClient->count--;
if (afbClient->count == 0) {
- if (afbClient->verbose) printf("ON-RESPONSE No More Waiting Request\n");
+ if (afbClient->verbose) printf("OnSuccessCB No More Waiting Request\n");
afbClient->error=0;
sem_post (&afbClient->semaphore);
}
- return;
+}
-OnErrorExit:
- fprintf(stderr, "ON-RESPONSE ERROR call=%s response=%s\n", afbRequest->callIdTag, afb_wsj1_msg_object_s(msg));
- afbClient->error=1;
+static void OnFailureCB(void* UNUSED_ARG(ctx), void* handle, const char *status, const char *info) {
+
+ afbRequestT *afbRequest= (afbRequestT*)handle;
+ afbClientT *afbClient=(afbClientT*)afbRequest->afbClient;
+
+ if (afbClient->verbose) printf("OnFailureCB callid='%s' status='%s' info='%s'\n", afbRequest->callIdTag, status, info);
+
+ // Cancel timeout for this request
+ sd_event_source_unref(afbRequest->evtSource);
+ free(afbRequest->callIdTag);
+
+ afbClient->error=1;
sem_post (&afbClient->semaphore);
}
+
+/* the callback interface for pws */
+static struct afb_proto_ws_client_itf itf = {
+ .on_reply_success = OnSuccessCB,
+ .on_reply_fail = OnFailureCB,
+ .on_event_create = NULL,
+ .on_event_remove = NULL,
+ .on_event_subscribe = NULL,
+ .on_event_unsubscribe = NULL,
+ .on_event_push = OnEventCB,
+ .on_event_broadcast = NULL,
+ .on_subcall = NULL,
+};
+
int OnTimeoutCB (sd_event_source* source, uint64_t timer, void* handle) {
afbClientT *afbClient= (afbClientT*)handle;
@@ -240,9 +248,11 @@ static int CallWithTimeout(afbClientT *afbClient, afbRequestT *afbRequest, int c
else apiVerb= afbRequest->openVerb;
// release action is optional
- if (apiVerb) {
+ if (apiVerb) {
+ char * sessionId;
+ (void) asprintf(&sessionId, "alsa-hook-pid:%d", getpid());
if (afbClient->verbose) printf("CALL-REQUEST verb=%s tag=%s\n", apiVerb, afbRequest->callIdTag);
- err = afb_proto_ws_client_call(afbClient->pws, apiVerb, afbRequest->queryJ, "xxxx", afbRequest);
+ err = afb_proto_ws_client_call(afbClient->pws, apiVerb, afbRequest->queryJ, sessionId, afbRequest);
if (err < 0 ) goto OnErrorExit;
}
// save client handle in request
@@ -372,7 +382,7 @@ int PLUGIN_ENTRY_POINT (snd_pcm_t *pcm, snd_config_t *conf) {
continue;
}
- if (strcmp(id, "request") == 0) {
+ if (strcmp(id, "controls") == 0) {
const char *callConf, *callLabel;
snd_config_type_t ctype;
snd_config_iterator_t currentCall, follow;
@@ -469,7 +479,7 @@ int PLUGIN_ENTRY_POINT (snd_pcm_t *pcm, snd_config_t *conf) {
}
continue;
}
- if (strcmp(id, "event") == 0) {
+ if (strcmp(id, "events") == 0) {
const char *callConf, *callLabel;
snd_config_type_t ctype;
snd_config_iterator_t currentCall, follow;
@@ -541,7 +551,7 @@ int PLUGIN_ENTRY_POINT (snd_pcm_t *pcm, snd_config_t *conf) {
return 0;
OnErrorExit:
- fprintf(stderr, "\nAlsaPcmHook Plugin Install Fail PCM=%s\n", snd_pcm_name(pcm));
+ fprintf(stderr, "\nAlsaPcmHook Plugin Policy Control Fail PCM=%s\n", snd_pcm_name(pcm));
if (h_close)
snd_pcm_hook_remove(h_close);