16 #ifndef ALEXA_CLIENT_SDK_CONTEXTMANAGER_INCLUDE_CONTEXTMANAGER_CONTEXTMANAGER_H_ 17 #define ALEXA_CLIENT_SDK_CONTEXTMANAGER_INCLUDE_CONTEXTMANAGER_CONTEXTMANAGER_H_ 24 #include <unordered_map> 25 #include <unordered_set> 40 namespace contextManager {
57 const std::shared_ptr<avsCommon::utils::DeviceInfo>& deviceInfo,
58 const std::shared_ptr<avsCommon::utils::timing::MultiTimer>& multiTimer =
59 std::make_shared<avsCommon::utils::timing::MultiTimer>(),
60 const std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>&
metricRecorder =
nullptr);
71 static std::shared_ptr<ContextManager>
create(
73 std::shared_ptr<avsCommon::utils::timing::MultiTimer> multiTimer =
74 std::make_shared<avsCommon::utils::timing::MultiTimer>(),
75 std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>
metricRecorder =
nullptr);
84 std::shared_ptr<avsCommon::sdkInterfaces::StateProviderInterface> stateProvider)
override;
88 std::shared_ptr<avsCommon::sdkInterfaces::StateProviderInterface> stateProvider)
override;
99 std::shared_ptr<avsCommon::sdkInterfaces::ContextRequesterInterface> contextRequester,
101 const std::chrono::milliseconds& timeout)
override;
104 std::shared_ptr<avsCommon::sdkInterfaces::ContextRequesterInterface> contextRequester,
106 const std::chrono::milliseconds& timeout)
override;
121 bool isEndpointUnreachable)
override;
124 std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerObserverInterface> observer)
override;
127 const std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerObserverInterface>& observer)
override;
136 std::shared_ptr<avsCommon::sdkInterfaces::StateProviderInterface> stateProvider;
143 bool legacyCapability;
158 std::shared_ptr<avsCommon::sdkInterfaces::StateProviderInterface> initStateProvider =
nullptr,
169 std::shared_ptr<avsCommon::sdkInterfaces::StateProviderInterface> initStateProvider,
175 StateInfo(
const StateInfo&) =
default;
179 using CapabilitiesState = std::unordered_map<avsCommon::avs::CapabilityTag, StateInfo>;
187 struct RequestTracker {
191 const std::shared_ptr<avsCommon::sdkInterfaces::ContextRequesterInterface> contextRequester;
193 const bool skipReportableStateProperties;
204 std::shared_ptr<avsCommon::sdkInterfaces::ContextRequesterInterface> contextRequester,
205 bool skipReportableProperties);
218 std::shared_ptr<avsCommon::utils::timing::MultiTimer> multiTimer,
219 std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>
metricRecorder);
230 void updateCapabilityState(
242 void updateCapabilityState(
258 std::shared_ptr<avsCommon::sdkInterfaces::ContextRequesterInterface> contextRequester,
260 const std::chrono::milliseconds& timeout,
261 bool skipReportableStateProperties);
276 std::function<void()> getContextAvailableCallbackIfReadyLocked(
293 std::function<void()> getContextFailureCallbackLocked(
306 std::mutex m_endpointsStateMutex;
310 std::unordered_map<EndpointIdentifier, CapabilitiesState> m_endpointsState;
313 std::mutex m_requestsMutex;
316 std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> m_metricRecorder;
319 std::atomic<unsigned int> m_requestCounter;
322 std::unordered_map<unsigned int, std::unordered_set<avsCommon::avs::CapabilityTag>> m_pendingStateRequest;
325 std::unordered_map<avsCommon::sdkInterfaces::ContextRequestToken, RequestTracker> m_pendingRequests;
328 std::mutex m_observerMutex;
331 std::list<std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerObserverInterface>> m_observers;
334 std::atomic_bool m_shutdown;
340 std::shared_ptr<avsCommon::utils::timing::MultiTimer> m_multiTimer;
349 #endif // ALEXA_CLIENT_SDK_CONTEXTMANAGER_INCLUDE_CONTEXTMANAGER_CONTEXTMANAGER_H_ Definition: DeviceInfo.h:31
void reportStateChange(const avsCommon::avs::CapabilityTag &capabilityIdentifier, const avsCommon::avs::CapabilityState &capabilityState, avsCommon::sdkInterfaces::AlexaStateChangeCauseType cause) override
void removeStateProvider(const avsCommon::avs::CapabilityTag &capabilityIdentifier) override
SetStateResult
Definition: ContextManagerInterface.h:39
void addStateProvider(const avsCommon::avs::CapabilityTag &capabilityIdentifier, std::shared_ptr< avsCommon::sdkInterfaces::StateProviderInterface > stateProvider) override
void removeContextManagerObserver(const std::shared_ptr< avsCommon::sdkInterfaces::ContextManagerObserverInterface > &observer) override
static std::shared_ptr< ContextManager > create(const avsCommon::utils::DeviceInfo &deviceInfo, std::shared_ptr< avsCommon::utils::timing::MultiTimer > multiTimer=std::make_shared< avsCommon::utils::timing::MultiTimer >(), std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder=nullptr)
static std::shared_ptr< ContextManagerInterface > createContextManagerInterface(const std::shared_ptr< avsCommon::utils::DeviceInfo > &deviceInfo, const std::shared_ptr< avsCommon::utils::timing::MultiTimer > &multiTimer=std::make_shared< avsCommon::utils::timing::MultiTimer >(), const std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > &metricRecorder=nullptr)
Definition: CapabilityTag.h:32
::std::string string
Definition: gtest-port.h:1097
ContextRequestError
Definition: ContextRequesterInterface.h:40
Single-thread executor implementation.
Definition: Executor.h:45
StateRefreshPolicy
Definition: StateRefreshPolicy.h:31
unsigned int ContextRequestToken
Alias for the token used to identify a context request.
Definition: ContextRequestToken.h:23
AlexaStateChangeCauseType
Definition: AlexaStateChangeCauseType.h:28
static std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder
Metric recorder shared ptr.
Definition: BaseAPLCapabilityAgentTest.cpp:261
avsCommon::sdkInterfaces::ContextRequestToken getContext(std::shared_ptr< avsCommon::sdkInterfaces::ContextRequesterInterface > contextRequester, const std::string &endpointId, const std::chrono::milliseconds &timeout) override
void provideStateResponse(const avsCommon::avs::CapabilityTag &capabilityIdentifier, const avsCommon::avs::CapabilityState &capabilityState, avsCommon::sdkInterfaces::ContextRequestToken stateRequestToken) override
Definition: Optional.h:32
avsCommon::sdkInterfaces::SetStateResult setState(const avsCommon::avs::CapabilityTag &stateProviderName, const std::string &jsonState, const avsCommon::avs::StateRefreshPolicy &refreshPolicy, const avsCommon::sdkInterfaces::ContextRequestToken stateRequestToken=0) override
~ContextManager() override
Destructor.
Definition: CapabilityState.h:31
Definition: ContextManager.h:46
void provideStateUnavailableResponse(const avsCommon::avs::CapabilityTag &capabilityIdentifier, avsCommon::sdkInterfaces::ContextRequestToken stateRequestToken, bool isEndpointUnreachable) override
Definition: ContextManagerInterface.h:63
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
uint64_t Token
Alias for the token used to identify a task. This can be used to cancel a task execution.
Definition: MultiTimer.h:42
std::string EndpointIdentifier
Definition: EndpointIdentifier.h:38
avsCommon::sdkInterfaces::ContextRequestToken getContextWithoutReportableStateProperties(std::shared_ptr< avsCommon::sdkInterfaces::ContextRequesterInterface > contextRequester, const std::string &endpointId, const std::chrono::milliseconds &timeout) override
void setStateProvider(const avsCommon::avs::CapabilityTag &stateProviderName, std::shared_ptr< avsCommon::sdkInterfaces::StateProviderInterface > stateProvider) override
void addContextManagerObserver(std::shared_ptr< avsCommon::sdkInterfaces::ContextManagerObserverInterface > observer) override