AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
DavsClient.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 ACSDKDAVSCLIENT_DAVSCLIENT_H_
17 #define ACSDKDAVSCLIENT_DAVSCLIENT_H_
18 
22 #include <unordered_map>
23 #include "DavsHandler.h"
25 
26 namespace alexaClientSDK {
27 namespace acsdkAssets {
28 namespace davs {
29 
33 public:
34  ~DavsClient() override = default;
35 
49  static std::shared_ptr<DavsClient> create(
50  std::string workingDirectory,
51  std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::AuthDelegateInterface> authDelegate,
52  std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::InternetConnectionMonitorInterface> wifiMonitor,
53  std::shared_ptr<davsInterfaces::DavsEndpointHandlerInterface> davsEndpointHandler,
54  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder = nullptr,
55  std::chrono::seconds forcedUpdateInterval = std::chrono::seconds(0));
56 
60  bool getIdleState() const;
61 
62  void setIdleState(bool idleState);
63 
67  std::shared_ptr<commonInterfaces::DavsRequest> artifactRequest,
68  std::shared_ptr<davsInterfaces::DavsDownloadCallbackInterface> downloadCallback,
69  std::shared_ptr<davsInterfaces::DavsCheckCallbackInterface> checkCallback,
70  bool downloadImmediately) override;
71  void deregisterArtifact(const std::string& requestUUID) override;
73  std::shared_ptr<commonInterfaces::DavsRequest> artifactRequest,
74  std::shared_ptr<davsInterfaces::DavsDownloadCallbackInterface> downloadCallback,
75  std::shared_ptr<davsInterfaces::DavsCheckCallbackInterface> checkCallback) override;
76  void enableAutoUpdate(const std::string& requestUUID, bool enable) override;
78 
82  void onConnectionStatusChanged(bool connected) override;
83 
84  /***
85  * Information from parsed Json Artifact Push Notification
86  */
87  struct ArtifactGroup {
90  };
91 
92  /***
93  * Take a json containing list of artifact group
94  * Parse the json. E.g:{"artifactList":[{"type":"test","key":"tar"}]}
95  * Then check and update the corresponding artifact
96  * @param jsonArtifactList
97  */
98  void checkAndUpdateArtifactGroupFromJson(const std::string& jsonArtifactList);
99 
100  /***
101  * Take a vector of ArtifactGroup and iterate every Artifact to check and then update
102  * @param artifactVector containing artifact requesting to be updated
103  */
104  void checkAndUpdateArtifactGroupVector(const std::vector<DavsClient::ArtifactGroup>& artifactVector);
105 
106 private:
107  DavsClient(
108  std::string workingDirectory,
109  std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::AuthDelegateInterface> authDelegate,
110  std::shared_ptr<davsInterfaces::DavsEndpointHandlerInterface> davsEndpointHandler,
111  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder = nullptr,
112  std::chrono::seconds forcedUpdateInterval = std::chrono::seconds(0));
113 
114  std::string handleRequest(
115  std::shared_ptr<commonInterfaces::DavsRequest> artifactRequest,
116  std::shared_ptr<davsInterfaces::DavsDownloadCallbackInterface> downloadCallback,
117  std::shared_ptr<davsInterfaces::DavsCheckCallbackInterface> checkCallback,
118  bool enableAutoUpdate,
119  bool downloadImmediately);
120 
121  /***
122  * Check below if an artifact requesting update before do it:
123  * + Still relevant
124  * + Enabled update
125  * + Registered
126  * @param artifactGroup that is requesting an update
127  */
128  void executeUpdateRegisteredArtifact(const ArtifactGroup& artifactGroup);
129 
135  std::vector<ArtifactGroup> executeParseArtifactGroupFromJson(const std::string& jsonArtifactList);
136 
137 private:
138  const std::string m_workingDirectory;
139 
141  const std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::AuthDelegateInterface> m_authDelegate;
142 
144  const std::shared_ptr<davsInterfaces::DavsEndpointHandlerInterface> m_davsEndpointHandler;
145 
147  const std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> m_metricRecorder;
148 
150  const std::chrono::seconds m_forcedUpdateInterval;
151 
153  const std::shared_ptr<alexaClientSDK::avsCommon::utils::power::PowerResource> m_powerResource;
154 
156  std::unordered_map<std::string, std::shared_ptr<DavsHandler>> m_handlers;
157 
159 
160  bool m_isDeviceIdle;
161  bool m_isConnected;
162 };
163 
164 } // namespace davs
165 } // namespace acsdkAssets
166 } // namespace alexaClientSDK
167 
168 #endif // ACSDKDAVSCLIENT_DAVSCLIENT_H_
std::string registerArtifact(std::shared_ptr< commonInterfaces::DavsRequest > artifactRequest, std::shared_ptr< davsInterfaces::DavsDownloadCallbackInterface > downloadCallback, std::shared_ptr< davsInterfaces::DavsCheckCallbackInterface > checkCallback, bool downloadImmediately) override
void deregisterArtifact(const std::string &requestUUID) override
::std::string string
Definition: gtest-port.h:1097
Single-thread executor implementation.
Definition: Executor.h:45
static std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder
Metric recorder shared ptr.
Definition: BaseAPLCapabilityAgentTest.cpp:261
std::string downloadOnce(std::shared_ptr< commonInterfaces::DavsRequest > artifactRequest, std::shared_ptr< davsInterfaces::DavsDownloadCallbackInterface > downloadCallback, std::shared_ptr< davsInterfaces::DavsCheckCallbackInterface > checkCallback) override
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void enableAutoUpdate(const std::string &requestUUID, bool enable) override
static std::shared_ptr< DavsClient > create(std::string workingDirectory, std::shared_ptr< alexaClientSDK::avsCommon::sdkInterfaces::AuthDelegateInterface > authDelegate, std::shared_ptr< alexaClientSDK::avsCommon::sdkInterfaces::InternetConnectionMonitorInterface > wifiMonitor, std::shared_ptr< davsInterfaces::DavsEndpointHandlerInterface > davsEndpointHandler, std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder=nullptr, std::chrono::seconds forcedUpdateInterval=std::chrono::seconds(0))
Definition: InternetConnectionObserverInterface.h:26
void onConnectionStatusChanged(bool connected) override
AuthDelegate that curlWrapper will use to get the Authentication Token.
void checkAndUpdateArtifactGroupFromJson(const std::string &jsonArtifactList)
AuthDelegate that curlWrapper will use to get the Authentication Token.
void checkAndUpdateArtifactGroupVector(const std::vector< DavsClient::ArtifactGroup > &artifactVector)
AuthDelegate that curlWrapper will use to get the Authentication Token.

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