AlexaClientSDK  1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
UrlRequester.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_SRC_URLREQUESTER_H_
17 #define ACSDKASSETMANAGER_SRC_URLREQUESTER_H_
18 
21 
22 #include <atomic>
23 #include <future>
24 
25 #include "Requester.h"
28 
29 namespace alexaClientSDK {
30 namespace acsdkAssets {
31 namespace manager {
32 
37 class UrlRequester : public Requester {
38 public:
40  public:
41  ~CurlProgressCallback() override = default;
42 
43  void enable(size_t budget) {
44  availableBudget = budget;
45  }
46 
47  void cancel() {
48  availableBudget = 0;
49  }
50 
51  bool onProgressUpdate(long dlTotal, long dlNow, long, long) override {
52  return availableBudget >= static_cast<size_t>(dlNow);
53  }
54 
55  private:
56  std::atomic_size_t availableBudget{0};
57  };
58 
59  ~UrlRequester() override;
60 
63  bool download() override;
65 
66 private:
67  UrlRequester(
68  std::shared_ptr<StorageManager> storageManager,
69  std::shared_ptr<commonInterfaces::AmdCommunicationInterface> communicationHandler,
70  std::shared_ptr<RequesterMetadata> metadata,
71  std::string metadataFilePath,
72  std::string workingDirectory,
73  std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::AuthDelegateInterface> authDelegate,
74  std::shared_ptr<alexaClientSDK::avsCommon::utils::power::PowerResource> powerResource,
75  std::shared_ptr<UrlAllowListWrapper> allowUrlList);
76 
77  size_t deleteAndCleanupLocked(std::unique_lock<std::mutex>& lock) override;
78 
83  void downloadWorker();
84 
85 private:
87  std::string m_workingDirectory;
89  std::condition_variable m_stateTrigger;
91  std::future<void> m_downloadFuture;
93  std::shared_ptr<CurlProgressCallback> m_downloadProgressTrigger;
95  std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::AuthDelegateInterface> m_authDelegate;
97  std::shared_ptr<alexaClientSDK::avsCommon::utils::power::PowerResource> m_powerResource;
99  std::shared_ptr<UrlAllowListWrapper> m_allowUrlList;
100 
101  friend RequesterFactory;
102 };
103 
104 } // namespace manager
105 } // namespace acsdkAssets
106 } // namespace alexaClientSDK
107 
108 #endif // ACSDKASSETMANAGER_SRC_URLREQUESTER_H_
PowerResource.h
alexaClientSDK::acsdkAssets::common::CurlProgressCallbackInterface
Definition: CurlProgressCallbackInterface.h:23
alexaClientSDK::acsdkAssets::manager::UrlRequester::CurlProgressCallback::enable
void enable(size_t budget)
Definition: UrlRequester.h:43
alexaClientSDK::acsdkAssets::manager::UrlRequester::download
bool download() override
Definition: UrlRequester.cpp:109
alexaClientSDK::acsdkAssets::manager::UrlRequester::CurlProgressCallback
Definition: UrlRequester.h:39
alexaClientSDK::acsdkAssets::manager::UrlRequester::CurlProgressCallback::onProgressUpdate
bool onProgressUpdate(long dlTotal, long dlNow, long, long) override
Definition: UrlRequester.h:51
Requester.h
alexaClientSDK::acsdkAssets::manager::UrlRequester::~UrlRequester
~UrlRequester() override
Definition: UrlRequester.cpp:97
alexaClientSDK
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
AuthDelegateInterface.h
UrlAllowListWrapper.h
alexaClientSDK::acsdkAssets::manager::UrlRequester::CurlProgressCallback::~CurlProgressCallback
~CurlProgressCallback() override=default
alexaClientSDK::acsdkAssets::manager::UrlRequester
Definition: UrlRequester.h:37
alexaClientSDK::acsdkAssets::manager::UrlRequester::CurlProgressCallback::cancel
void cancel()
Definition: UrlRequester.h:47
CurlProgressCallbackInterface.h
alexaClientSDK::acsdkAssets::manager::Requester
Definition: Requester.h:41

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