AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
AssetManager.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 ACSDKASSETMANAGER_ASSETMANAGER_H_
17 #define ACSDKASSETMANAGER_ASSETMANAGER_H_
18 
22 #include <atomic>
23 #include <memory>
24 #include <unordered_set>
25 
29 
30 namespace alexaClientSDK {
31 namespace acsdkAssets {
32 namespace manager {
33 
34 class RequesterFactory;
35 class StorageManager;
36 class Requester;
37 
38 enum class IdleState { ACTIVE = 0, IDLE = 1 };
39 
41  : public std::enable_shared_from_this<AssetManager>
42  , public acsdkCommunicationInterfaces::FunctionInvokerInterface<bool, std::string> {
43 public:
54  static std::shared_ptr<AssetManager> create(
55  const std::shared_ptr<commonInterfaces::AmdCommunicationInterface>& communicationHandler,
56  const std::shared_ptr<davs::DavsClient>& davsClient,
57  const std::string& artifactsDirectory,
58  const std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::AuthDelegateInterface>& authDelegate,
59  const std::shared_ptr<UrlAllowListWrapper>& allowList);
60 
61  ~AssetManager() override;
62 
70  bool downloadArtifact(const std::shared_ptr<commonInterfaces::ArtifactRequest>& request);
71 
73  inline void queueDownloadArtifact(const std::shared_ptr<commonInterfaces::ArtifactRequest>& request) {
74  m_executor.execute([this, request] { downloadArtifact(request); });
75  }
76 
83  bool queueDownloadArtifact(const std::string& requestString);
84 
90  void deleteArtifact(const std::string& summaryString);
91 
93  inline void queueDeleteArtifact(const std::string& summaryString) {
94  m_executor.execute([this, summaryString] { deleteArtifact(summaryString); });
95  }
96 
103  void handleUpdate(const std::string& summaryString, bool acceptUpdate);
104 
106  inline void queueHandleUpdate(const std::string& summaryString, bool acceptUpdate) {
107  m_executor.execute([this, summaryString, acceptUpdate] { handleUpdate(summaryString, acceptUpdate); });
108  }
109 
119  bool freeUpSpace(size_t requestedAmount);
120 
122  inline void queueFreeUpSpace(size_t requestedAmount) {
123  m_executor.execute([this, requestedAmount] { freeUpSpace(requestedAmount); });
124  }
125 
130  void onIdleChanged(int value);
131 
135  size_t getBudget();
136 
144  void setBudget(uint32_t valueMB);
145 
146  // override functionInvokerInterface for download and delete.
147  bool functionToBeInvoked(const std::string& name, std::string arg) override;
148 
149 private:
150  explicit AssetManager(
151  std::shared_ptr<commonInterfaces::AmdCommunicationInterface> communicationHandler,
152  std::shared_ptr<davs::DavsClient> davsClient,
153  const std::string& baseDirectory,
154  std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::AuthDelegateInterface> authDelegate,
155  std::shared_ptr<UrlAllowListWrapper> allowUrlList);
156 
162  bool init();
163 
170  std::shared_ptr<Requester> findRequesterLocked(
171  const std::shared_ptr<commonInterfaces::ArtifactRequest>& request) const;
172 
173 private:
174  const std::shared_ptr<commonInterfaces::AmdCommunicationInterface> m_communicationHandler;
175  const std::shared_ptr<davs::DavsClient> m_davsClient;
176  const std::string m_resourcesDirectory;
177  const std::string m_requestsDirectory;
178  const std::string m_urlTmpDirectory;
179  const std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::AuthDelegateInterface> m_authDelegate;
180  const std::shared_ptr<UrlAllowListWrapper> m_urlAllowList;
181  std::unique_ptr<RequesterFactory> m_requesterFactory;
183  std::mutex m_requestersMutex;
184  std::unordered_set<std::shared_ptr<Requester>> m_requesters;
185  std::shared_ptr<StorageManager> m_storageManager;
186 };
187 
188 } // namespace manager
189 } // namespace acsdkAssets
190 } // namespace alexaClientSDK
191 
192 #endif // ACSDKASSETMANAGER_ASSETMANAGER_H_
void queueFreeUpSpace(size_t requestedAmount)
Definition: AssetManager.h:122
::std::string string
Definition: gtest-port.h:1097
Single-thread executor implementation.
Definition: Executor.h:45
void queueDeleteArtifact(const std::string &summaryString)
Definition: AssetManager.h:93
IdleState
Definition: AssetManager.h:38
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void queueDownloadArtifact(const std::shared_ptr< commonInterfaces::ArtifactRequest > &request)
Definition: AssetManager.h:73
void queueHandleUpdate(const std::string &summaryString, bool acceptUpdate)
Definition: AssetManager.h:106
Requester
An enum class indicating whether an operation originated from a Device or Cloud (AVS).
Definition: Requester.h:24

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