AlexaClientSDK  1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Resource.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_RESOURCE_H_
17 #define ACSDKASSETMANAGER_SRC_RESOURCE_H_
18 
19 #include <memory>
20 #include <string>
21 
22 namespace alexaClientSDK {
23 namespace acsdkAssets {
24 namespace manager {
25 
26 class StorageManager;
27 
34 class Resource {
35 public:
39  inline const std::string& getId() const {
40  return m_id;
41  }
42 
46  inline const std::string& getPath() const {
47  return m_fullResourcePath;
48  }
49 
53  inline size_t getSizeBytes() const {
54  return m_sizeBytes;
55  }
56 
60  inline bool exists() const {
61  return m_sizeBytes > 0;
62  }
63 
64 private:
75  static std::shared_ptr<Resource> create(
76  const std::string& parentDirectory,
77  const std::string& id,
78  const std::string& source);
79 
93  static std::shared_ptr<Resource> createFromStorage(const std::string& resourceDirectory);
94 
102  static std::shared_ptr<Resource> createFromConfigFile(const std::string& resourceDirectory);
103 
104  Resource(
105  const std::string& resourceDirectory,
106  const std::string& resourceName,
107  const std::string& id,
108  size_t sizeBytes);
109 
115  bool saveMetadata();
116 
120  void erase();
121 
122  inline int incrementRefCount() {
123  return ++m_refCount;
124  }
125  inline int decrementRefCount() {
126  return --m_refCount;
127  }
128 
129 private:
130  // The parent directory where the resource is stored, like "/some/path/abc"
131  const std::string m_resourceDirectory;
132  // The name of the file or directory that is stored inside the resource directory, like "resource.txt"
133  const std::string m_resourceName;
134  // Id of the resource, usually the checksum, like "abc"
135  const std::string m_id;
136  // Size of the entire resource directory
137  size_t m_sizeBytes;
138  // The complete path of the resource including the name, like "/some/path/abc/resource.txt"
139  std::string m_fullResourcePath;
140  // Count of how many requesters reference this resource.
141  int m_refCount;
142 
143  // it's important that the creation, ref counting, and deletion of resource happens only by the Storage Manager.
144  friend StorageManager;
145 };
146 
147 } // namespace manager
148 } // namespace acsdkAssets
149 } // namespace alexaClientSDK
150 
151 #endif // ACSDKASSETMANAGER_SRC_RESOURCE_H_
alexaClientSDK::acsdkAssets::manager::Resource::getPath
const std::string & getPath() const
Definition: Resource.h:46
alexaClientSDK::acsdkAssets::manager::Resource
Definition: Resource.h:34
alexaClientSDK::acsdkAssets::manager::Resource::getSizeBytes
size_t getSizeBytes() const
Definition: Resource.h:53
alexaClientSDK
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
alexaClientSDK::acsdkAssets::manager::Resource::getId
const std::string & getId() const
Definition: Resource.h:39
alexaClientSDK::acsdkAssets::manager::Resource::exists
bool exists() const
Definition: Resource.h:60

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