AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
ArtifactWrapper.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 ACSDKASSETMANAGERCLIENT_ARTIFACTWRAPPER_H_
17 #define ACSDKASSETMANAGERCLIENT_ARTIFACTWRAPPER_H_
18 
20 
21 #include <condition_variable>
22 #include <memory>
23 #include <mutex>
24 #include <string>
25 
32 
33 namespace alexaClientSDK {
34 namespace acsdkAssets {
35 namespace client {
36 
42  , public notifier::Notifier<clientInterfaces::ArtifactChangeObserver>
45 public:
57  static std::shared_ptr<ArtifactWrapper> create(
58  const std::shared_ptr<commonInterfaces::AmdCommunicationInterface>& amdComm,
59  const std::shared_ptr<commonInterfaces::ArtifactRequest>& request,
60  const std::shared_ptr<clientInterfaces::ArtifactUpdateValidator>& updateValidator = nullptr);
61 
62  ~ArtifactWrapper() override = default;
63 
64  inline bool operator==(const ArtifactWrapper& rhs) const {
65  return m_request->getSummary() == rhs.m_request->getSummary();
66  }
67 
68  inline bool operator!=(const ArtifactWrapper& rhs) const {
69  return !(rhs == *this);
70  }
71 
72  inline std::string name() const override {
73  return m_request->getSummary();
74  }
75 
81  bool download() const override;
82 
86  inline bool isAvailable() const override {
87  std::lock_guard<std::mutex> lock(m_stateMutex);
88  return m_state == commonInterfaces::State::LOADED;
89  }
90 
94  inline bool isPending() const override {
95  std::lock_guard<std::mutex> lock(m_stateMutex);
98  }
99 
100  inline std::shared_ptr<commonInterfaces::ArtifactRequest> getRequest() const override {
101  return m_request;
102  }
103 
107  std::string getPath() const override;
108 
112  commonInterfaces::Priority getPriority() const override;
113 
119  bool setPriority(commonInterfaces::Priority priority) override;
120 
124  void erase() override;
125 
126  void addWeakPtrObserver(const std::weak_ptr<clientInterfaces::ArtifactChangeObserver>& observer) override {
128  }
129 
130  void removeWeakPtrObserver(const std::weak_ptr<clientInterfaces::ArtifactChangeObserver>& observer) override {
132  }
133 
134 private:
137  std::shared_ptr<commonInterfaces::AmdCommunicationInterface> amdComm,
138  std::shared_ptr<commonInterfaces::ArtifactRequest> request,
139  const std::shared_ptr<clientInterfaces::ArtifactUpdateValidator>& updateValidator = nullptr);
140 
143  void onCommunicationPropertyChange(const std::string& PropertyName, int newValue) override;
144  void onCommunicationPropertyChange(const std::string& PropertyName, std::string newValue) override;
146 
151  void onAmdInit();
152 
156  void onStateChange(commonInterfaces::State newState);
157 
161  void onUpdateAvailable(const std::string& newPath);
162 
163 private:
164  const std::shared_ptr<commonInterfaces::AmdCommunicationInterface> m_amdComm;
165  const std::shared_ptr<commonInterfaces::ArtifactRequest> m_request;
166  const std::weak_ptr<clientInterfaces::ArtifactUpdateValidator> m_updateValidator;
167 
168  commonInterfaces::State m_state;
169  commonInterfaces::Priority m_desiredPriority;
170  mutable std::mutex m_stateMutex;
171  mutable std::condition_variable m_stateTrigger;
172 };
173 
174 } // namespace client
175 } // namespace acsdkAssets
176 } // namespace alexaClientSDK
177 
178 #endif // ACSDKASSETMANAGERCLIENT_ARTIFACTWRAPPER_H_
bool operator!=(const ArtifactWrapper &rhs) const
Definition: ArtifactWrapper.h:68
bool operator==(const ArtifactWrapper &rhs) const
Definition: ArtifactWrapper.h:64
static std::shared_ptr< ArtifactWrapper > create(const std::shared_ptr< commonInterfaces::AmdCommunicationInterface > &amdComm, const std::shared_ptr< commonInterfaces::ArtifactRequest > &request, const std::shared_ptr< clientInterfaces::ArtifactUpdateValidator > &updateValidator=nullptr)
::std::string string
Definition: gtest-port.h:1097
std::shared_ptr< commonInterfaces::ArtifactRequest > getRequest() const override
Definition: ArtifactWrapper.h:100
bool setPriority(commonInterfaces::Priority priority) override
std::string name() const override
Definition: ArtifactWrapper.h:72
void removeWeakPtrObserver(const std::weak_ptr< ObserverType > &observer) override
Remove an observer.
Definition: Notifier.h:80
Generic implementation of NotifierInterface.
Definition: Notifier.h:38
bool isPending() const override
Definition: ArtifactWrapper.h:94
void addWeakPtrObserver(const std::weak_ptr< ObserverType > &observer) override
Add a weak reference to an observer.
Definition: Notifier.h:75
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
bool isAvailable() const override
Definition: ArtifactWrapper.h:86
void addWeakPtrObserver(const std::weak_ptr< clientInterfaces::ArtifactChangeObserver > &observer) override
Add a weak reference to an observer.
Definition: ArtifactWrapper.h:126
commonInterfaces::Priority getPriority() const override
void removeWeakPtrObserver(const std::weak_ptr< clientInterfaces::ArtifactChangeObserver > &observer) override
Remove an observer.
Definition: ArtifactWrapper.h:130

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