AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
EndpointRegistrationManager.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 #ifndef ALEXA_CLIENT_SDK_ENDPOINTS_INCLUDE_ENDPOINTS_ENDPOINTREGISTRATIONMANAGER_H_
16 #define ALEXA_CLIENT_SDK_ENDPOINTS_INCLUDE_ENDPOINTS_ENDPOINTREGISTRATIONMANAGER_H_
17 
18 #include <functional>
19 #include <future>
20 #include <list>
21 #include <memory>
22 #include <mutex>
23 #include <string>
24 #include <unordered_map>
25 #include <utility>
26 
38 
39 namespace alexaClientSDK {
40 namespace endpoints {
41 
48 public:
57 
62 
71  static std::unique_ptr<EndpointRegistrationManager> create(
72  std::shared_ptr<avsCommon::sdkInterfaces::DirectiveSequencerInterface> directiveSequencer,
73  std::shared_ptr<avsCommon::sdkInterfaces::CapabilitiesDelegateInterface> capabilitiesDelegate,
74  const EndpointIdentifier& defaultEndpointId);
75 
80 
83  std::future<RegistrationResult> registerEndpoint(std::shared_ptr<EndpointInterface> endpoint) override;
84  std::future<UpdateResult> updateEndpoint(
85  const EndpointIdentifier& endpointId,
86  const std::shared_ptr<EndpointModificationData>& endpointModificationData) override;
87  std::future<DeregistrationResult> deregisterEndpoint(const EndpointIdentifier& endpointId) override;
88  void addObserver(std::shared_ptr<EndpointRegistrationObserverInterface> observer) override;
89  void removeObserver(const std::shared_ptr<EndpointRegistrationObserverInterface>& observer) override;
91 
92 protected:
95  void doShutdown() override;
97 
98 private:
100  using PendingRegistration = std::pair<std::shared_ptr<EndpointInterface>, std::promise<RegistrationResult>>;
101 
103  using PendingDeregistration = std::pair<std::shared_ptr<EndpointInterface>, std::promise<DeregistrationResult>>;
104 
106  using PendingUpdate = std::pair<std::shared_ptr<EndpointInterface>, std::promise<UpdateResult>>;
107 
111  class CapabilityRegistrationProxy : public avsCommon::sdkInterfaces::CapabilitiesDelegateObserverInterface {
112  public:
118  void setCallback(
119  std::function<void(
120  const std::pair<CapabilitiesDelegateObserverInterface::State, std::vector<EndpointIdentifier>>&
121  addedOrUpdatedEndpoints,
122  const std::pair<CapabilitiesDelegateObserverInterface::State, std::vector<EndpointIdentifier>>&
123  deletedEndpoints)> callback);
124 
127  void onCapabilitiesStateChange(
128  State newState,
129  Error newError,
130  const std::vector<EndpointIdentifier>& addedOrUpdatedEndpointIds,
131  const std::vector<EndpointIdentifier>& deletedEndpointIds) override;
133  private:
134  // The function callback.
135  std::function<void(
136  const std::pair<CapabilitiesDelegateObserverInterface::State, std::vector<EndpointIdentifier>>&
137  addedOrUpdatedEndpoints,
138  const std::pair<CapabilitiesDelegateObserverInterface::State, std::vector<EndpointIdentifier>>&
139  deletedEndpoints)>
140  m_callback;
141  };
142 
151  std::shared_ptr<avsCommon::sdkInterfaces::DirectiveSequencerInterface> directiveSequencer,
152  std::shared_ptr<avsCommon::sdkInterfaces::CapabilitiesDelegateInterface> capabilitiesDelegate,
153  const EndpointIdentifier& defaultEndpointId);
154 
160  void executeRegisterEndpoint(const std::shared_ptr<EndpointInterface>& endpoint);
161 
168  void executeUpdateEndpoint(
169  const std::shared_ptr<EndpointInterface>& endpoint,
170  const std::shared_ptr<EndpointModificationData>& endpointModificationData);
171 
177  void executeDeregisterEndpoint(const std::shared_ptr<EndpointInterface>& endpoint);
178 
186  bool addCapabilities(
187  const std::shared_ptr<EndpointInterface>& endpoint,
188  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface>>* handlersAdded);
189 
198  bool addCapability(
199  const std::shared_ptr<EndpointInterface>& endpoint,
200  const std::pair<
202  std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface>> capability,
203  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface>>* handlersAdded);
204 
211  bool addCapabilities(const std::shared_ptr<EndpointInterface>& endpoint);
212 
220  bool removeCapabilities(
221  const std::shared_ptr<EndpointInterface>& endpoint,
222  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface>>* handlersRemoved);
223 
232  bool removeCapability(
233  const std::shared_ptr<EndpointInterface>& endpoint,
234  const std::pair<
236  std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface>> capability,
237  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface>>* handlersRemoved);
238 
245  bool removeCapabilities(const std::shared_ptr<EndpointInterface>& endpoint);
246 
254  void updateAddedOrUpdatedEndpoints(
255  const std::pair<CapabilityRegistrationProxy::State, std::vector<EndpointIdentifier>>& addedOrUpdatedEndpoints);
256 
264  void removeDeletedEndpoints(
265  const std::pair<CapabilityRegistrationProxy::State, std::vector<EndpointIdentifier>>& deletedEndpoints);
266 
276  void onCapabilityRegistrationStatusChanged(
277  const std::pair<CapabilityRegistrationProxy::State, std::vector<EndpointIdentifier>>& addedOrUpdatedEndpoints,
278  const std::pair<CapabilityRegistrationProxy::State, std::vector<EndpointIdentifier>>& deletedEndpoints);
279 
281  mutable std::mutex m_observersMutex;
282 
284  std::list<std::shared_ptr<EndpointRegistrationObserverInterface>> m_observers;
285 
287  std::shared_ptr<avsCommon::sdkInterfaces::DirectiveSequencerInterface> m_directiveSequencer;
288 
290  std::shared_ptr<avsCommon::sdkInterfaces::CapabilitiesDelegateInterface> m_capabilitiesDelegate;
291 
293  mutable std::mutex m_endpointsMutex;
294 
296  std::unordered_map<EndpointIdentifier, std::shared_ptr<EndpointInterface>> m_endpoints;
297 
299  std::unordered_map<EndpointIdentifier, PendingRegistration> m_pendingRegistrations;
300 
302  std::unordered_map<EndpointIdentifier, PendingDeregistration> m_pendingDeregistrations;
303 
305  std::unordered_map<EndpointIdentifier, PendingUpdate> m_pendingUpdates;
306 
309  const EndpointIdentifier m_defaultEndpointId;
310 
312  std::shared_ptr<CapabilityRegistrationProxy> m_capabilityRegistrationProxy;
313 
316 };
317 
318 } // namespace endpoints
319 } // namespace alexaClientSDK
320 
321 #endif // ALEXA_CLIENT_SDK_ENDPOINTS_INCLUDE_ENDPOINTS_ENDPOINTREGISTRATIONMANAGER_H_
std::future< RegistrationResult > registerEndpoint(std::shared_ptr< EndpointInterface > endpoint) override
void removeObserver(const std::shared_ptr< EndpointRegistrationObserverInterface > &observer) override
std::future< DeregistrationResult > deregisterEndpoint(const EndpointIdentifier &endpointId) override
Definition: EndpointRegistrationManager.h:45
Single-thread executor implementation.
Definition: Executor.h:45
Definition: CapabilitiesDelegateObserverInterface.h:29
std::future< UpdateResult > updateEndpoint(const EndpointIdentifier &endpointId, const std::shared_ptr< EndpointModificationData > &endpointModificationData) override
State
The enum State describes the state of the CapabilitiesDelegate.
Definition: CapabilitiesDelegateObserverInterface.h:32
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
std::string EndpointIdentifier
Definition: EndpointIdentifier.h:38
Definition: CapabilityConfiguration.h:42
avsCommon::sdkInterfaces::endpoints::EndpointIdentifier EndpointIdentifier
Definition: EndpointRegistrationManager.h:51
void addObserver(std::shared_ptr< EndpointRegistrationObserverInterface > observer) override
static std::unique_ptr< EndpointRegistrationManager > create(std::shared_ptr< avsCommon::sdkInterfaces::DirectiveSequencerInterface > directiveSequencer, std::shared_ptr< avsCommon::sdkInterfaces::CapabilitiesDelegateInterface > capabilitiesDelegate, const EndpointIdentifier &defaultEndpointId)

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0