AlexaClientSDK  1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
InternetConnectionMonitor.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_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_NETWORK_INTERNETCONNECTIONMONITOR_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_NETWORK_INTERNETCONNECTIONMONITOR_H_
18 
19 #include <chrono>
20 #include <memory>
21 #include <mutex>
22 #include <unordered_set>
23 
30 
31 namespace alexaClientSDK {
32 namespace avsCommon {
33 namespace utils {
34 namespace network {
35 
40 public:
47  static std::shared_ptr<sdkInterfaces::InternetConnectionMonitorInterface> createInternetConnectionMonitorInterface(
48  const std::shared_ptr<sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface>& contentFetcherFactory);
49 
57  static std::unique_ptr<InternetConnectionMonitor> create(
58  std::shared_ptr<sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface> contentFetcherFactory);
59 
64 
68  std::shared_ptr<avsCommon::sdkInterfaces::InternetConnectionObserverInterface> observer) override;
70  std::shared_ptr<avsCommon::sdkInterfaces::InternetConnectionObserverInterface> observer) override;
72 
73 private:
80  std::shared_ptr<sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface> contentFetcherFactory);
81 
85  void startMonitoring();
86 
90  void stopMonitoring();
91 
99  void testConnection();
100 
106  void updateConnectionStatus(bool connected);
107 
109  std::unordered_set<std::shared_ptr<sdkInterfaces::InternetConnectionObserverInterface>> m_observers;
110 
112  bool m_connected;
113 
115  std::chrono::seconds m_period;
116 
118  avsCommon::utils::timing::Timer m_connectionTestTimer;
119 
121  std::atomic<bool> m_isShuttingDown;
122 
124  std::shared_ptr<avsCommon::sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface> m_contentFetcherFactory;
125 
127  std::mutex m_mutex;
128 };
129 
130 } // namespace network
131 } // namespace utils
132 } // namespace avsCommon
133 } // namespace alexaClientSDK
134 
135 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_NETWORK_INTERNETCONNECTIONMONITOR_H_
virtual ~InternetConnectionMonitor()
Definition: InternetConnectionMonitor.cpp:244
static std::shared_ptr< sdkInterfaces::InternetConnectionMonitorInterface > createInternetConnectionMonitorInterface(const std::shared_ptr< sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface > &contentFetcherFactory)
Definition: InternetConnectionMonitor.cpp:57
void addInternetConnectionObserver(std::shared_ptr< avsCommon::sdkInterfaces::InternetConnectionObserverInterface > observer) override
Definition: InternetConnectionMonitor.cpp:85
static std::unique_ptr< InternetConnectionMonitor > create(std::shared_ptr< sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface > contentFetcherFactory)
Definition: InternetConnectionMonitor.cpp:66
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void removeInternetConnectionObserver(std::shared_ptr< avsCommon::sdkInterfaces::InternetConnectionObserverInterface > observer) override
Definition: InternetConnectionMonitor.cpp:107
Definition: InternetConnectionMonitorInterface.h:30

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