AlexaClientSDK  1.26.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 
66  std::string registerArtifact(
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;
72  std::string downloadOnce(
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 {
88  std::string type;
89  std::string key;
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_
alexaClientSDK::acsdkAssets::davs::DavsClient::ArtifactGroup
Definition: DavsClient.h:87
alexaClientSDK::acsdkAssets::davs::DavsClient::ArtifactGroup::type
std::string type
Definition: DavsClient.h:90
alexaClientSDK::acsdkAssets::davs::DavsClient::onConnectionStatusChanged
void onConnectionStatusChanged(bool connected) override
Definition: DavsClient.cpp:220
alexaClientSDK::acsdkAssets::davs::DavsClient::checkAndUpdateArtifactGroupVector
void checkAndUpdateArtifactGroupVector(const std::vector< DavsClient::ArtifactGroup > &artifactVector)
Definition: DavsClient.cpp:264
alexaClientSDK::acsdkAssets::davs::DavsClient::~DavsClient
~DavsClient() override=default
InternetConnectionObserverInterface.h
alexaClientSDK::acsdkAssets::davs::DavsClient::downloadOnce
std::string downloadOnce(std::shared_ptr< commonInterfaces::DavsRequest > artifactRequest, std::shared_ptr< davsInterfaces::DavsDownloadCallbackInterface > downloadCallback, std::shared_ptr< davsInterfaces::DavsCheckCallbackInterface > checkCallback) override
Definition: DavsClient.cpp:189
alexaClientSDK::acsdkAssets::davs::DavsClient
Definition: DavsClient.h:30
alexaClientSDK::acsdkAssets::davs::DavsClient::checkAndUpdateArtifactGroupFromJson
void checkAndUpdateArtifactGroupFromJson(const std::string &jsonArtifactList)
Definition: DavsClient.cpp:258
alexaClientSDK::avsCommon::utils::threading::Executor
Definition: Executor.h:40
alexaClientSDK::acsdkAssets::davs::DavsClient::enableAutoUpdate
void enableAutoUpdate(const std::string &requestUUID, bool enable) override
Definition: DavsClient.cpp:196
InternetConnectionMonitorInterface.h
alexaClientSDK::acsdkAssets::davs::DavsClient::registerArtifact
std::string registerArtifact(std::shared_ptr< commonInterfaces::DavsRequest > artifactRequest, std::shared_ptr< davsInterfaces::DavsDownloadCallbackInterface > downloadCallback, std::shared_ptr< davsInterfaces::DavsCheckCallbackInterface > checkCallback, bool downloadImmediately) override
Definition: DavsClient.cpp:169
Executor.h
alexaClientSDK::acsdkAssets::davsInterfaces::ArtifactHandlerInterface
Definition: ArtifactHandlerInterface.h:26
alexaClientSDK
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
alexaClientSDK::acsdkAssets::davs::DavsClient::create
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: DavsClient.cpp:63
alexaClientSDK::avsCommon::sdkInterfaces::InternetConnectionObserverInterface
Definition: InternetConnectionObserverInterface.h:26
DavsEndpointHandlerInterface.h
alexaClientSDK::acsdkAssets::davs::DavsClient::getIdleState
bool getIdleState() const
Definition: DavsClient.cpp:205
DavsHandler.h
alexaClientSDK::acsdkAssets::davs::DavsClient::ArtifactGroup::key
std::string key
Definition: DavsClient.h:91
alexaClientSDK::acsdkAssets::davs::DavsClient::setIdleState
void setIdleState(bool idleState)
Definition: DavsClient.cpp:209
alexaClientSDK::acsdkAssets::davs::DavsClient::deregisterArtifact
void deregisterArtifact(const std::string &requestUUID) override
Definition: DavsClient.cpp:177

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