summaryrefslogtreecommitdiffstats
path: root/src/plugins/voiceagents
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/voiceagents')
-rw-r--r--src/plugins/voiceagents/VoiceAgentEventNames.h3
-rw-r--r--src/plugins/voiceagents/VoiceAgentsDataManager.h32
-rw-r--r--src/plugins/voiceagents/VoiceAgentsDataManagerImpl.cpp54
-rw-r--r--src/plugins/voiceagents/include/VoiceAgent.h11
-rw-r--r--src/plugins/voiceagents/include/VoiceAgentEventsHandler.h19
-rw-r--r--src/plugins/voiceagents/src/VoiceAgentEventsHandler.cpp19
-rw-r--r--src/plugins/voiceagents/src/VoiceAgentImpl.cpp11
-rw-r--r--src/plugins/voiceagents/test/VoiceAgentTest.cpp7
-rw-r--r--src/plugins/voiceagents/test/VoiceAgentsDataManagerTest.cpp9
-rw-r--r--src/plugins/voiceagents/test/VoiceAgentsTestData.h3
10 files changed, 95 insertions, 73 deletions
diff --git a/src/plugins/voiceagents/VoiceAgentEventNames.h b/src/plugins/voiceagents/VoiceAgentEventNames.h
index 4575528..92cc8dc 100644
--- a/src/plugins/voiceagents/VoiceAgentEventNames.h
+++ b/src/plugins/voiceagents/VoiceAgentEventNames.h
@@ -19,8 +19,7 @@
#include <string>
using namespace std;
-
-namespace vshl {
+namespace vshlcore {
namespace voiceagents {
static string VSHL_EVENT_AUTH_STATE_EVENT = "voice_authstate_event";
diff --git a/src/plugins/voiceagents/VoiceAgentsDataManager.h b/src/plugins/voiceagents/VoiceAgentsDataManager.h
index a4c9143..a91d7eb 100644
--- a/src/plugins/voiceagents/VoiceAgentsDataManager.h
+++ b/src/plugins/voiceagents/VoiceAgentsDataManager.h
@@ -27,8 +27,7 @@
#include "interfaces/voiceagents/IVoiceAgentsChangeObserver.h"
#include "voiceagents/include/VoiceAgent.h"
#include "voiceagents/include/VoiceAgentEventsHandler.h"
-
-namespace vshl {
+namespace vshlcore {
namespace voiceagents {
/*
* This class implements the data model for voiceagents.
@@ -39,8 +38,8 @@ class VoiceAgentsDataManager {
public:
// Create a VoiceAgentsDataManager.
static std::unique_ptr<VoiceAgentsDataManager> create(
- shared_ptr<vshl::common::interfaces::ILogger> logger,
- shared_ptr<vshl::common::interfaces::IAFBApi> afbApi);
+ shared_ptr<vshlcore::common::interfaces::ILogger> logger,
+ shared_ptr<vshlcore::common::interfaces::IAFBApi> afbApi);
/**
* Activates the list of voiceagents.
@@ -84,22 +83,22 @@ public:
bool removeVoiceAgent(const string& voiceAgentId);
// Returns the set of all voice agents in @c VoiceAgentsDataManger cache
- std::set<std::shared_ptr<vshl::common::interfaces::IVoiceAgent>> getAllVoiceAgents();
+ std::set<std::shared_ptr<vshlcore::common::interfaces::IVoiceAgent>> getAllVoiceAgents();
// Returns the event filter that belongs to the core module.
- shared_ptr<vshl::common::interfaces::IEventFilter> getEventFilter() const;
+ shared_ptr<vshlcore::common::interfaces::IEventFilter> getEventFilter() const;
// Subscribe to an event coming from the voiceagent.
bool subscribeToVshlEventFromVoiceAgent(
- vshl::common::interfaces::IAFBRequest& request,
+ vshlcore::common::interfaces::IAFBRequest& request,
const string eventName,
const string voiceagentId);
// Adds a new voiceagent change observer.
- bool addVoiceAgentsChangeObserver(shared_ptr<vshl::common::interfaces::IVoiceAgentsChangeObserver> observer);
+ bool addVoiceAgentsChangeObserver(shared_ptr<vshlcore::common::interfaces::IVoiceAgentsChangeObserver> observer);
// Removes the voiceagent change observer from the list.
- bool removeVoiceAgentsChangeObserver(shared_ptr<vshl::common::interfaces::IVoiceAgentsChangeObserver> observer);
+ bool removeVoiceAgentsChangeObserver(shared_ptr<vshlcore::common::interfaces::IVoiceAgentsChangeObserver> observer);
// Destructor
~VoiceAgentsDataManager();
@@ -107,14 +106,17 @@ public:
private:
// Constructor
VoiceAgentsDataManager(
- shared_ptr<vshl::common::interfaces::ILogger> logger,
- shared_ptr<vshl::common::interfaces::IAFBApi> afbApi);
+ shared_ptr<vshlcore::common::interfaces::ILogger> logger,
+ shared_ptr<vshlcore::common::interfaces::IAFBApi> afbApi);
+
+ // Sets the voiceagent ID
+ bool sendVoiceAgentIdToVA(const shared_ptr<VoiceAgent>& voiceAgent);
// Binding API reference
- shared_ptr<vshl::common::interfaces::IAFBApi> mAfbApi;
+ shared_ptr<vshlcore::common::interfaces::IAFBApi> mAfbApi;
// A list of all the voiceagent change observers
- unordered_set<shared_ptr<vshl::common::interfaces::IVoiceAgentsChangeObserver>> mVoiceAgentChangeObservers;
+ unordered_set<shared_ptr<vshlcore::common::interfaces::IVoiceAgentsChangeObserver>> mVoiceAgentChangeObservers;
// A map of voiceagents grouped by ID
unordered_map<string, shared_ptr<VoiceAgent>> mVoiceAgents;
@@ -126,7 +128,9 @@ private:
string mDefaultVoiceAgentId;
// Logger
- shared_ptr<vshl::common::interfaces::ILogger> mLogger;
+ shared_ptr<vshlcore::common::interfaces::ILogger> mLogger;
+
+ bool mAlreadyPeformedSubscriptions;
};
} // namespace voiceagents
diff --git a/src/plugins/voiceagents/VoiceAgentsDataManagerImpl.cpp b/src/plugins/voiceagents/VoiceAgentsDataManagerImpl.cpp
index 626a7fc..00f57e3 100644
--- a/src/plugins/voiceagents/VoiceAgentsDataManagerImpl.cpp
+++ b/src/plugins/voiceagents/VoiceAgentsDataManagerImpl.cpp
@@ -16,29 +16,30 @@
#include "voiceagents/include/VoiceAgentEventsHandler.h"
-static string TAG = "vshl::voiceagents::VoiceAgentsDataManager";
+static string VA_VERB_SETVOICEAGENTID = "setVoiceAgentId";
+static string TAG = "vshlcore::voiceagents::VoiceAgentsDataManager";
/**
* Specifies the severity level of a log message
*/
-using Level = vshl::common::interfaces::ILogger::Level;
-
-namespace vshl {
+using Level = vshlcore::common::interfaces::ILogger::Level;
+namespace vshlcore {
namespace voiceagents {
std::unique_ptr<VoiceAgentsDataManager> VoiceAgentsDataManager::create(
- shared_ptr<vshl::common::interfaces::ILogger> logger,
- shared_ptr<vshl::common::interfaces::IAFBApi> afbApi) {
+ shared_ptr<vshlcore::common::interfaces::ILogger> logger,
+ shared_ptr<vshlcore::common::interfaces::IAFBApi> afbApi) {
return std::unique_ptr<VoiceAgentsDataManager>(new VoiceAgentsDataManager(logger, afbApi));
}
// Constructor
VoiceAgentsDataManager::VoiceAgentsDataManager(
- shared_ptr<vshl::common::interfaces::ILogger> logger,
- shared_ptr<vshl::common::interfaces::IAFBApi> afbApi) :
+ shared_ptr<vshlcore::common::interfaces::ILogger> logger,
+ shared_ptr<vshlcore::common::interfaces::IAFBApi> afbApi) :
mLogger(logger),
mAfbApi(afbApi) {
mVoiceAgentEventsHandler = VoiceAgentEventsHandler::create(mLogger, mAfbApi);
+ mAlreadyPeformedSubscriptions = false;
}
// Destructor
@@ -178,6 +179,7 @@ bool VoiceAgentsDataManager::addNewVoiceAgent(
}
mVoiceAgents.insert(make_pair(voiceAgent->getId(), voiceAgent));
+ sendVoiceAgentIdToVA(voiceAgent);
// Notify the observers
for (auto observer : mVoiceAgentChangeObservers) {
@@ -218,8 +220,8 @@ bool VoiceAgentsDataManager::removeVoiceAgent(const string& voiceAgentId) {
return true;
}
-std::set<std::shared_ptr<vshl::common::interfaces::IVoiceAgent>> VoiceAgentsDataManager::getAllVoiceAgents() {
- std::set<std::shared_ptr<vshl::common::interfaces::IVoiceAgent>> voiceAgentsSet;
+std::set<std::shared_ptr<vshlcore::common::interfaces::IVoiceAgent>> VoiceAgentsDataManager::getAllVoiceAgents() {
+ std::set<std::shared_ptr<vshlcore::common::interfaces::IVoiceAgent>> voiceAgentsSet;
for (auto element : mVoiceAgents) {
voiceAgentsSet.insert(element.second);
}
@@ -228,12 +230,12 @@ std::set<std::shared_ptr<vshl::common::interfaces::IVoiceAgent>> VoiceAgentsData
}
// Returns the event filter that belongs to the core module.
-shared_ptr<vshl::common::interfaces::IEventFilter> VoiceAgentsDataManager::getEventFilter() const {
+shared_ptr<vshlcore::common::interfaces::IEventFilter> VoiceAgentsDataManager::getEventFilter() const {
return mVoiceAgentEventsHandler;
}
bool VoiceAgentsDataManager::subscribeToVshlEventFromVoiceAgent(
- vshl::common::interfaces::IAFBRequest& request,
+ vshlcore::common::interfaces::IAFBRequest& request,
const string eventName,
const string voiceAgentId) {
auto voiceAgentIt = mVoiceAgents.find(voiceAgentId);
@@ -250,7 +252,7 @@ bool VoiceAgentsDataManager::subscribeToVshlEventFromVoiceAgent(
}
bool VoiceAgentsDataManager::addVoiceAgentsChangeObserver(
- shared_ptr<vshl::common::interfaces::IVoiceAgentsChangeObserver> observer) {
+ shared_ptr<vshlcore::common::interfaces::IVoiceAgentsChangeObserver> observer) {
if (!observer) {
return false;
}
@@ -260,7 +262,7 @@ bool VoiceAgentsDataManager::addVoiceAgentsChangeObserver(
}
bool VoiceAgentsDataManager::removeVoiceAgentsChangeObserver(
- shared_ptr<vshl::common::interfaces::IVoiceAgentsChangeObserver> observer) {
+ shared_ptr<vshlcore::common::interfaces::IVoiceAgentsChangeObserver> observer) {
if (!observer) {
return false;
}
@@ -268,5 +270,29 @@ bool VoiceAgentsDataManager::removeVoiceAgentsChangeObserver(
mVoiceAgentChangeObservers.erase(observer);
return true;
}
+
+bool VoiceAgentsDataManager::sendVoiceAgentIdToVA(const shared_ptr<VoiceAgent>& voiceAgent) {
+ if (!mAfbApi) {
+ mLogger->log(
+ Level::ERROR, TAG, "Failed to call sendVoiceAgentIdToVA on voicegent: " + voiceAgent->getId() + ", No API.");
+ return false;
+ }
+
+ json_object* argsJ = json_object_new_object();
+ json_object* idJ = json_object_new_string(voiceAgent->getId().c_str());
+ json_object_object_add(argsJ, "va_id", idJ);
+
+ std::string error, info;
+ json_object* resultJ;
+
+ int rc = mAfbApi->callSync(voiceAgent->getApi(), VA_VERB_SETVOICEAGENTID, argsJ, &resultJ, error, info);
+
+ if (resultJ) {
+ free(resultJ);
+ }
+
+ return true;
+}
+
} // namespace voiceagents
} // namespace vshl
diff --git a/src/plugins/voiceagents/include/VoiceAgent.h b/src/plugins/voiceagents/include/VoiceAgent.h
index 4dd55d4..684baf0 100644
--- a/src/plugins/voiceagents/include/VoiceAgent.h
+++ b/src/plugins/voiceagents/include/VoiceAgent.h
@@ -22,17 +22,16 @@
#include "interfaces/voiceagents/IVoiceAgent.h"
using namespace std;
-
-namespace vshl {
+namespace vshlcore {
namespace voiceagents {
/*
* Default implementation of IVoiceAgent interface.
*/
-class VoiceAgent : public vshl::common::interfaces::IVoiceAgent {
+class VoiceAgent : public vshlcore::common::interfaces::IVoiceAgent {
public:
// Creates @c VoiceAgent instance
static shared_ptr<VoiceAgent>
- create(shared_ptr<vshl::common::interfaces::ILogger> logger, const string &id,
+ create(shared_ptr<vshlcore::common::interfaces::ILogger> logger, const string &id,
const string &name, const string &description, const string &api,
const string &vendor, const string &activeWakeword,
const bool isActive,
@@ -55,14 +54,14 @@ public:
private:
// Constructor
- VoiceAgent(shared_ptr<vshl::common::interfaces::ILogger> logger,
+ VoiceAgent(shared_ptr<vshlcore::common::interfaces::ILogger> logger,
const string &id, const string &name, const string &description,
const string &api, const string &vendor,
const string &activeWakeword, const bool isActive,
const shared_ptr<unordered_set<string>> wakewords);
// Logger
- shared_ptr<vshl::common::interfaces::ILogger> mLogger;
+ shared_ptr<vshlcore::common::interfaces::ILogger> mLogger;
// Id
string mId;
diff --git a/src/plugins/voiceagents/include/VoiceAgentEventsHandler.h b/src/plugins/voiceagents/include/VoiceAgentEventsHandler.h
index 3c1ca6c..00acfe1 100644
--- a/src/plugins/voiceagents/include/VoiceAgentEventsHandler.h
+++ b/src/plugins/voiceagents/include/VoiceAgentEventsHandler.h
@@ -26,8 +26,7 @@
#include "voiceagents/include/VoiceAgent.h"
using namespace std;
-
-namespace vshl {
+namespace vshlcore {
namespace voiceagents {
/*
* This class is reponsible for handling agent specific events
@@ -35,12 +34,12 @@ namespace voiceagents {
* This class also listen to the incoming events from voice agents
* and implements propagation to application layer.
*/
-class VoiceAgentEventsHandler : public vshl::common::interfaces::IEventFilter {
+class VoiceAgentEventsHandler : public vshlcore::common::interfaces::IEventFilter {
public:
// Create a VREventFilter.
static shared_ptr<VoiceAgentEventsHandler> create(
- shared_ptr<vshl::common::interfaces::ILogger> logger,
- shared_ptr<vshl::common::interfaces::IAFBApi> afbApi);
+ shared_ptr<vshlcore::common::interfaces::ILogger> logger,
+ shared_ptr<vshlcore::common::interfaces::IAFBApi> afbApi);
// Creates all the vshl events for a specific voiceagent id.
// For e.g if voiceagent is VA-001 then a new vshl event
@@ -53,7 +52,7 @@ public:
// Subscribe to a vshl event corresponding to a voiceagent.
bool subscribeToVshlEventFromVoiceAgent(
- vshl::common::interfaces::IAFBRequest& request,
+ vshlcore::common::interfaces::IAFBRequest& request,
const string eventName,
const shared_ptr<VoiceAgent> voiceAgent);
@@ -68,8 +67,8 @@ protected:
private:
// Constructor
VoiceAgentEventsHandler(
- shared_ptr<vshl::common::interfaces::ILogger> logger,
- shared_ptr<vshl::common::interfaces::IAFBApi> afbApi);
+ shared_ptr<vshlcore::common::interfaces::ILogger> logger,
+ shared_ptr<vshlcore::common::interfaces::IAFBApi> afbApi);
// Helper method to generate the event name with voiceagent Id
// concatenated.
@@ -80,13 +79,13 @@ private:
bool callSubscribeVerb(const shared_ptr<VoiceAgent> voiceAgent);
// Binding API reference
- shared_ptr<vshl::common::interfaces::IAFBApi> mAfbApi;
+ shared_ptr<vshlcore::common::interfaces::IAFBApi> mAfbApi;
// A map of VSHL event ID to its Event object
unordered_map<string, shared_ptr<common::interfaces::IAFBApi::IAFBEvent>> mEventsMap;
// Logger
- shared_ptr<vshl::common::interfaces::ILogger> mLogger;
+ shared_ptr<vshlcore::common::interfaces::ILogger> mLogger;
};
} // namespace voiceagents
diff --git a/src/plugins/voiceagents/src/VoiceAgentEventsHandler.cpp b/src/plugins/voiceagents/src/VoiceAgentEventsHandler.cpp
index 4952721..3b55505 100644
--- a/src/plugins/voiceagents/src/VoiceAgentEventsHandler.cpp
+++ b/src/plugins/voiceagents/src/VoiceAgentEventsHandler.cpp
@@ -14,25 +14,24 @@
*/
#include "voiceagents/include/VoiceAgentEventsHandler.h"
-static string TAG = "vshl::voiceagents::VoiceAgentEventsHandler";
+static string TAG = "vshlcore::voiceagents::VoiceAgentEventsHandler";
static string VA_VERB_SUBSCRIBE = "subscribe";
-using Level = vshl::common::interfaces::ILogger::Level;
-using namespace vshl::common::interfaces;
-
-namespace vshl {
+using Level = vshlcore::common::interfaces::ILogger::Level;
+using namespace vshlcore::common::interfaces;
+namespace vshlcore {
namespace voiceagents {
shared_ptr<VoiceAgentEventsHandler> VoiceAgentEventsHandler::create(
- shared_ptr<vshl::common::interfaces::ILogger> logger,
- shared_ptr<vshl::common::interfaces::IAFBApi> afbApi) {
+ shared_ptr<vshlcore::common::interfaces::ILogger> logger,
+ shared_ptr<vshlcore::common::interfaces::IAFBApi> afbApi) {
auto eventFilter = std::shared_ptr<VoiceAgentEventsHandler>(new VoiceAgentEventsHandler(logger, afbApi));
return eventFilter;
}
VoiceAgentEventsHandler::VoiceAgentEventsHandler(
- shared_ptr<vshl::common::interfaces::ILogger> logger,
- shared_ptr<vshl::common::interfaces::IAFBApi> afbApi) :
+ shared_ptr<vshlcore::common::interfaces::ILogger> logger,
+ shared_ptr<vshlcore::common::interfaces::IAFBApi> afbApi) :
mAfbApi(afbApi),
mLogger(logger) {
}
@@ -70,7 +69,7 @@ void VoiceAgentEventsHandler::removeVshlEventsForVoiceAgent(const string voiceAg
}
bool VoiceAgentEventsHandler::subscribeToVshlEventFromVoiceAgent(
- vshl::common::interfaces::IAFBRequest& request,
+ vshlcore::common::interfaces::IAFBRequest& request,
const string eventName,
const shared_ptr<VoiceAgent> voiceAgent) {
auto supportedEventsIt = find(VSHL_EVENTS.begin(), VSHL_EVENTS.end(), eventName);
diff --git a/src/plugins/voiceagents/src/VoiceAgentImpl.cpp b/src/plugins/voiceagents/src/VoiceAgentImpl.cpp
index f2ef8a1..39a92c4 100644
--- a/src/plugins/voiceagents/src/VoiceAgentImpl.cpp
+++ b/src/plugins/voiceagents/src/VoiceAgentImpl.cpp
@@ -16,18 +16,17 @@
#include "voiceagents/include/VoiceAgent.h"
-static string TAG = "vshl::voiceagents::VoiceAgent";
+static string TAG = "vshlcore::voiceagents::VoiceAgent";
/**
* Specifies the severity level of a log message
*/
-using Level = vshl::common::interfaces::ILogger::Level;
-
-namespace vshl {
+using Level = vshlcore::common::interfaces::ILogger::Level;
+namespace vshlcore {
namespace voiceagents {
// Creates @c VoiceAgent instance
shared_ptr<VoiceAgent> VoiceAgent::create(
- shared_ptr<vshl::common::interfaces::ILogger> logger,
+ shared_ptr<vshlcore::common::interfaces::ILogger> logger,
const string& id,
const string& name,
const string& description,
@@ -51,7 +50,7 @@ shared_ptr<VoiceAgent> VoiceAgent::create(
}
VoiceAgent::VoiceAgent(
- shared_ptr<vshl::common::interfaces::ILogger> logger,
+ shared_ptr<vshlcore::common::interfaces::ILogger> logger,
const string& id,
const string& name,
const string& description,
diff --git a/src/plugins/voiceagents/test/VoiceAgentTest.cpp b/src/plugins/voiceagents/test/VoiceAgentTest.cpp
index e5ad15e..9730182 100644
--- a/src/plugins/voiceagents/test/VoiceAgentTest.cpp
+++ b/src/plugins/voiceagents/test/VoiceAgentTest.cpp
@@ -20,10 +20,9 @@
#include "voiceagents/test/VoiceAgentsTestData.h"
#include "test/common/ConsoleLogger.h"
-using namespace vshl::voiceagents;
-using namespace vshl::test::common;
-
-namespace vshl {
+using namespace vshlcore::voiceagents;
+using namespace vshlcore::test::common;
+namespace vshlcore {
namespace test {
class VoiceAgentTest : public ::testing::Test {
diff --git a/src/plugins/voiceagents/test/VoiceAgentsDataManagerTest.cpp b/src/plugins/voiceagents/test/VoiceAgentsDataManagerTest.cpp
index 58c62ed..9f63c73 100644
--- a/src/plugins/voiceagents/test/VoiceAgentsDataManagerTest.cpp
+++ b/src/plugins/voiceagents/test/VoiceAgentsDataManagerTest.cpp
@@ -22,12 +22,11 @@
#include "test/mocks/VoiceAgentsChangeObserverMock.h"
#include "voiceagents/test/VoiceAgentsTestData.h"
-using namespace vshl::common::interfaces;
-using namespace vshl::voiceagents;
+using namespace vshlcore::common::interfaces;
+using namespace vshlcore::voiceagents;
-using namespace vshl::test::common;
-
-namespace vshl {
+using namespace vshlcore::test::common;
+namespace vshlcore {
namespace test {
class VoiceAgentDataManagerTest : public ::testing::Test {
diff --git a/src/plugins/voiceagents/test/VoiceAgentsTestData.h b/src/plugins/voiceagents/test/VoiceAgentsTestData.h
index ced068f..104123b 100644
--- a/src/plugins/voiceagents/test/VoiceAgentsTestData.h
+++ b/src/plugins/voiceagents/test/VoiceAgentsTestData.h
@@ -17,8 +17,7 @@
#include <string>
#include <unordered_set>
#include <vector>
-
-namespace vshl {
+namespace vshlcore {
namespace test {
typedef std::shared_ptr<std::unordered_set<std::string>> WakeWords;