AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
AVSConnectionManager.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 
16 #ifndef ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_AVSCONNECTIONMANAGER_H_
17 #define ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_AVSCONNECTIONMANAGER_H_
18 
19 #include <atomic>
20 #include <memory>
21 #include <mutex>
22 #include <string>
23 #include <unordered_set>
24 
32 
35 
36 namespace alexaClientSDK {
37 namespace acl {
38 
74  , public std::enable_shared_from_this<AVSConnectionManager> {
75 public:
82  static std::shared_ptr<MessageSenderInterface> createMessageSenderInterface(
83  const std::shared_ptr<AVSConnectionManagerInterface>& connectionManager);
84 
93  static std::shared_ptr<AVSConnectionManagerInterface> createAVSConnectionManagerInterface(
94  const std::shared_ptr<acsdkShutdownManagerInterfaces::ShutdownNotifierInterface>& shutdownNotifier,
95  const std::shared_ptr<MessageRouterInterface>& messageRouter,
96  const std::shared_ptr<avsCommon::sdkInterfaces::InternetConnectionMonitorInterface>& internetConnectionMonitor);
97 
111  static std::shared_ptr<AVSConnectionManager> create(
112  std::shared_ptr<MessageRouterInterface> messageRouter,
113  bool isEnabled = true,
114  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::ConnectionStatusObserverInterface>>
115  connectionStatusObservers =
116  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::ConnectionStatusObserverInterface>>(),
117  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface>> messageObservers =
118  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface>>(),
119  std::shared_ptr<avsCommon::sdkInterfaces::InternetConnectionMonitorInterface> internetConnectionMonitor =
120  nullptr);
121 
124  void enable() override;
125  void disable() override;
126  bool isEnabled() override;
127  void reconnect() override;
128  bool isConnected() const override;
129  void onWakeConnectionRetry() override;
130  void addMessageObserver(std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface> observer) override;
131  void removeMessageObserver(std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface> observer) override;
133 
136  void sendMessage(std::shared_ptr<avsCommon::avs::MessageRequest> request) override;
138 
141  void setAVSGateway(const std::string& avsGateway) override;
142  std::string getAVSGateway() const override;
144 
147  void onConnectionStatusChanged(bool connected) override;
149 
150 private:
161  std::shared_ptr<MessageRouterInterface> messageRouter,
162  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::ConnectionStatusObserverInterface>>
163  connectionStatusObservers =
164  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::ConnectionStatusObserverInterface>>(),
165  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface>> messageObserver =
166  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface>>(),
167  std::shared_ptr<avsCommon::sdkInterfaces::InternetConnectionMonitorInterface> internetConnectionMonitor =
168  nullptr);
169 
170  void doShutdown() override;
171 
174  const std::vector<ConnectionStatusObserverInterface::EngineConnectionStatus>& engineConnectionStatuses)
175  override;
176 
177  void receive(const std::string& contextId, const std::string& message) override;
178 
179  std::shared_ptr<MessageRouterInterface> getMessageRouter() const;
180 
182  std::mutex m_isEnabledMutex;
183 
185  mutable std::mutex m_messageRouterMutex;
186 
188  bool m_isEnabled;
189 
191  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface>> m_messageObservers;
192 
194  std::mutex m_messageObserverMutex;
195 
197  std::shared_ptr<MessageRouterInterface> m_messageRouter;
198 
200  std::shared_ptr<avsCommon::sdkInterfaces::InternetConnectionMonitorInterface> m_internetConnectionMonitor;
201 };
202 
203 } // namespace acl
204 } // namespace alexaClientSDK
205 
206 #endif // ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_AVSCONNECTIONMANAGER_H_
static std::shared_ptr< MessageSenderInterface > createMessageSenderInterface(const std::shared_ptr< AVSConnectionManagerInterface > &connectionManager)
Definition: MessageRouterObserverInterface.h:31
void onConnectionStatusChanged(bool connected) override
::std::string string
Definition: gtest-port.h:1097
Definition: AbstractAVSConnectionManager.h:33
void addMessageObserver(std::shared_ptr< avsCommon::sdkInterfaces::MessageObserverInterface > observer) override
void removeMessageObserver(std::shared_ptr< avsCommon::sdkInterfaces::MessageObserverInterface > observer) override
Definition: AVSConnectionManager.h:69
void sendMessage(std::shared_ptr< avsCommon::avs::MessageRequest > request) override
void setAVSGateway(const std::string &avsGateway) override
std::string getAVSGateway() const override
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
static std::shared_ptr< AVSConnectionManager > create(std::shared_ptr< MessageRouterInterface > messageRouter, bool isEnabled=true, std::unordered_set< std::shared_ptr< avsCommon::sdkInterfaces::ConnectionStatusObserverInterface >> connectionStatusObservers=std::unordered_set< std::shared_ptr< avsCommon::sdkInterfaces::ConnectionStatusObserverInterface >>(), std::unordered_set< std::shared_ptr< avsCommon::sdkInterfaces::MessageObserverInterface >> messageObservers=std::unordered_set< std::shared_ptr< avsCommon::sdkInterfaces::MessageObserverInterface >>(), std::shared_ptr< avsCommon::sdkInterfaces::InternetConnectionMonitorInterface > internetConnectionMonitor=nullptr)
static std::shared_ptr< AVSConnectionManagerInterface > createAVSConnectionManagerInterface(const std::shared_ptr< acsdkShutdownManagerInterfaces::ShutdownNotifierInterface > &shutdownNotifier, const std::shared_ptr< MessageRouterInterface > &messageRouter, const std::shared_ptr< avsCommon::sdkInterfaces::InternetConnectionMonitorInterface > &internetConnectionMonitor)
Definition: InternetConnectionObserverInterface.h:26
tuple message
Definition: gtest_output_test.py:331
Status
Definition: ConnectionStatusObserverInterface.h:36

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