AlexaClientSDK  1.25.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_
bool isEnabled() override
Definition: AVSConnectionManager.cpp:158
Definition: MessageRouterObserverInterface.h:31
void onConnectionStatusChanged(bool connected) override
Definition: AVSConnectionManager.cpp:225
Definition: AbstractAVSConnectionManager.h:33
void addMessageObserver(std::shared_ptr< avsCommon::sdkInterfaces::MessageObserverInterface > observer) override
Definition: AVSConnectionManager.cpp:241
static std::shared_ptr< MessageSenderInterface > createMessageSenderInterface(const std::shared_ptr< AVSConnectionManagerInterface > &connectionManager)
Definition: AVSConnectionManager.cpp:38
void reconnect() override
Definition: AVSConnectionManager.cpp:163
void removeMessageObserver(std::shared_ptr< avsCommon::sdkInterfaces::MessageObserverInterface > observer) override
Definition: AVSConnectionManager.cpp:252
Definition: AVSConnectionManager.h:69
void sendMessage(std::shared_ptr< avsCommon::avs::MessageRequest > request) override
Definition: AVSConnectionManager.cpp:175
void setAVSGateway(const std::string &avsGateway) override
Definition: AVSConnectionManager.cpp:206
std::string getAVSGateway() const override
Definition: AVSConnectionManager.cpp:215
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void onWakeConnectionRetry() override
Definition: AVSConnectionManager.cpp:196
bool isConnected() const override
Definition: AVSConnectionManager.cpp:188
Definition: InternetConnectionObserverInterface.h:26
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: AVSConnectionManager.cpp:43
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)
Definition: AVSConnectionManager.cpp:54
void disable() override
Definition: AVSConnectionManager.cpp:148
void enable() override
Definition: AVSConnectionManager.cpp:138
Status
Definition: ConnectionStatusObserverInterface.h:36

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