summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
json_object *uidJ = json_object_new_string(uid.c_str());
+ json_object_object_add(eventJ, "uid", uidJ);
+ json_object *actionJ = json_object_new_string("plugin://vshl-core#onVoiceTriggerEvent");
+ json_object_object_add(eventJ, "action", actionJ);
+ json_object_array_add(eventsJ, eventJ);
+
+ // Call into controller to add event actions
+ // NOTE: AFAICT the JSON objects end up reused by the controller data
+ // structures, so eventsJ should not be freed with a put after
+ // this call.
+ int rc = AddActionsToSection(sAfbApi->getApi(), section, eventsJ, 0);
+ if (rc != 0) {
+ stringstream message;
+ message << "AddVoiceTriggerEvents: AddActionsToSection rc = " << rc;
+ sLogger->log(Level::WARNING, TAG, message.str().c_str());
+ }
+ return rc;
+}
+
+CTLP_CAPI(subscribeVoiceTriggerEvents, source, argsJ, eventJ) {
+ // Subscribe to signal-composer voice/PTT events
+ const char **tmp = signalcomposer_events;
+ json_object *args = json_object_new_object();
+ json_object *signals = json_object_new_array();
+
+ while (*tmp) {
+ json_object_array_add(signals, json_object_new_string(*tmp++));
+ }
+ json_object_object_add(args, "signal", signals);
+ if (json_object_array_length(signals)) {
+ struct json_object *responseJ;
+ int rc = afb_api_call_sync(sAfbApi->getApi(), "signal-composer",
+ "subscribe", args, &responseJ, NULL, NULL);
+ if (rc == 0 && responseJ) {
+ struct json_object *uuidJ;
+ json_object_object_get_ex(responseJ, "uuid", &uuidJ);
+ if (uuidJ) {
+ std::string uuid(json_object_get_string(uuidJ));
+ std::string api("signal-composer");
+ AddVoiceTriggerEvents(api, uuid);
+ }
+ }
+ if (responseJ)
+ json_object_put(responseJ);
+ } else {
+ json_object_put(args);
+ }
+
+ // Always return zero so service will start
+ return 0;
+}
+
CTLP_CAPI(startListening, source, argsJ, eventJ) {
if (sVoiceAgentsDataManager == nullptr) {
return -1;
diff --git a/src/plugins/VshlCoreApi.h b/src/plugins/VshlCoreApi.h
index eb90190..7c5bf69 100644
--- a/src/plugins/VshlCoreApi.h
+++ b/src/plugins/VshlCoreApi.h
@@ -29,7 +29,9 @@ int onConnectionStateEvent(CtlSourceT* source, json_object* argsJ, json_object*
int onDialogStateEvent(CtlSourceT* source, json_object* argsJ, json_object* queryJ);
int onLoginPairReceivedEvent(CtlSourceT* source, json_object* argsJ, json_object* queryJ);
int onLoginPairExpiredEvent(CtlSourceT* source, json_object* argsJ, json_object* queryJ);
+int onVoiceTriggerEvent(CtlSourceT* source, json_object* argsJ, json_object* queryJ);
int loadVoiceAgentsConfig(CtlSourceT* source, json_object* argsJ, json_object* queryJ);
+int subscribeVoiceTriggerEvents(CtlSourceT* source, json_object* argsJ, json_object* queryJ);
int startListening(CtlSourceT* source, json_object* argsJ, json_object* queryJ);
int cancelListening(CtlSourceT* source, json_object* argsJ, json_object* queryJ);
int enumerateVoiceAgents(CtlSourceT* source, json_object* argsJ, json_object* queryJ);