16 #ifndef ACSDKCOMMUNICATION_INMEMORYCOMMUNICATIONINVOKEHANDLER_H_ 17 #define ACSDKCOMMUNICATION_INMEMORYCOMMUNICATIONINVOKEHANDLER_H_ 21 #include <unordered_map> 27 namespace acsdkCommunication {
33 template <
typename ReturnType,
typename... Types>
42 functionImplementation)
override;
48 functionImplementation)
override;
58 std::mutex m_functionsGuard;
60 template <
typename ReturnType,
typename... Types>
64 functionImplementation) {
65 std::lock_guard<std::mutex> lock(m_functionsGuard);
66 auto it = m_functions.find(name);
67 if (it != m_functions.end()) {
68 if (!it->second.expired()) {
71 .
m(
"Function is already Registered")
72 .d(
"function", name));
76 m_functions.erase(it);
78 if (!functionImplementation) {
81 .
m(
"FunctionImplementation is a nullptr")
82 .d(
"function", name));
86 functionImplementation);
88 m_functions.insert({name, weakFunction});
91 template <
typename ReturnType,
typename... Types>
95 auto it = m_functions.find(name);
96 if (it == m_functions.end()) {
98 .
m(
"Function is not Registered")
99 .d(
"function", name));
102 auto function = it->second.lock();
105 .
m(
"Function is expired")
106 .d(
"function", name));
107 std::lock_guard<std::mutex> lock(m_functionsGuard);
108 m_functions.erase(it);
111 auto result =
function->functionToBeInvoked(name,
args...);
115 template <
typename ReturnType,
typename... Types>
119 functionImplementation) {
120 if (!functionImplementation) {
122 .
m(
"FunctionImplementation is a nullptr")
123 .d(
"function", name));
126 std::lock_guard<std::mutex> lock(m_functionsGuard);
127 auto it = m_functions.find(name);
128 if (it == m_functions.end()) {
130 .
m(
"Function is not Registered")
131 .d(
"function", name));
134 if (it->second.lock() != functionImplementation) {
136 .
m(
"Function is Registered but does not match")
137 .d(
"function", name));
140 m_functions.erase(it);
146 #endif // ACSDKCOMMUNICATION_INMEMORYCOMMUNICATIONINVOKEHANDLER_H_ def args
Definition: android_test.py:111
Definition: CommunicationInvokeHandlerInterface.h:35
bool registerFunction(const std::string &name, std::shared_ptr< acsdkCommunicationInterfaces::FunctionInvokerInterface< ReturnType, Types... >> functionImplementation) override
}@
Definition: InMemoryCommunicationInvokeHandler.h:61
Definition: InMemoryCommunicationInvokeHandler.h:34
::std::string string
Definition: gtest-port.h:1097
alexaClientSDK::avsCommon::utils::error::SuccessResult< ReturnType > invoke(const std::string &name, Types... args) override
}@
Definition: InMemoryCommunicationInvokeHandler.h:94
static SuccessResult< TValue > failure()
Definition: SuccessResult.h:87
Definition: SuccessResult.h:32
std::mutex m
Definition: AlexaPresentationTest.cpp:91
static SuccessResult< TValue > success(TValue value)
Definition: SuccessResult.h:92
bool deregister(const std::string &name, const std::shared_ptr< acsdkCommunicationInterfaces::FunctionInvokerInterface< ReturnType, Types... >> &functionImplementation) override
}@
Definition: InMemoryCommunicationInvokeHandler.h:116
#define ACSDK_ERROR(entry)
Definition: Logger.h:481
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
Definition: FunctionInvokerInterface.h:30
LogEntry is used to compile the log entry text to log via Logger.
Definition: LogEntry.h:33