• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef INTERFACES_INNERKITS_NATIVE_INCLUDE_FILE_ASSET_H_
17 #define INTERFACES_INNERKITS_NATIVE_INCLUDE_FILE_ASSET_H_
18 
19 #include <memory>
20 #include <mutex>
21 #include <string>
22 #include <variant>
23 #include <unordered_map>
24 #include "medialibrary_type_const.h"
25 
26 namespace OHOS {
27 namespace Media {
28 
29 constexpr int MEMBER_TYPE_INT32 = 0;
30 constexpr int MEMBER_TYPE_INT64 = 1;
31 constexpr int MEMBER_TYPE_STRING = 2;
32 constexpr int MEMBER_TYPE_DOUBLE = 3;
33 
34 constexpr int OPEN_TYPE_READONLY = 0;
35 constexpr int OPEN_TYPE_WRITE = 1;
36 
37 /**
38  * @brief Class for filling all file asset parameters
39  *
40  * @since 1.0
41  * @version 1.0
42  */
43 class FileAsset {
44 public:
45     FileAsset();
46     virtual ~FileAsset() = default;
47 
48     int32_t GetId() const;
49     void SetId(int32_t id);
50 
51     int32_t GetCount() const;
52     void SetCount(int32_t count);
53 
54     const std::string &GetUri() const;
55     void SetUri(const std::string &uri);
56 
57     const std::string &GetPath() const;
58     void SetPath(const std::string &path);
59 
60     const std::string &GetRelativePath() const;
61     void SetRelativePath(const std::string &relativePath);
62 
63     const std::string &GetMimeType() const;
64     void SetMimeType(const std::string &mimeType);
65 
66     MediaType GetMediaType() const;
67     void SetMediaType(MediaType mediaType);
68 
69     const std::string &GetDisplayName() const;
70     void SetDisplayName(const std::string &displayName);
71 
72     int64_t GetSize() const;
73     void SetSize(int64_t size);
74 
75     int64_t GetDateAdded() const;
76     void SetDateAdded(int64_t dataAdded);
77 
78     int64_t GetDateModified() const;
79     void SetDateModified(int64_t dateModified);
80 
81     const std::string &GetTitle() const;
82     void SetTitle(const std::string &title);
83 
84     const std::string &GetArtist() const;
85     void SetArtist(const std::string &artist);
86 
87     const std::string &GetAlbum() const;
88     void SetAlbum(const std::string &album);
89 
90     int32_t GetPosition() const;
91     void SetPosition(int32_t position);
92 
93     int32_t GetWidth() const;
94     void SetWidth(int32_t width);
95 
96     int32_t GetHeight() const;
97     void SetHeight(int32_t height);
98 
99     int32_t GetDuration() const;
100     void SetDuration(int32_t duration);
101 
102     int32_t GetOrientation() const;
103     void SetOrientation(int32_t orientation);
104 
105     int32_t GetAlbumId() const;
106     void SetAlbumId(int32_t albumId);
107 
108     const std::string &GetAlbumName() const;
109     void SetAlbumName(const std::string &albumName);
110 
111     int32_t GetParent() const;
112     void SetParent(int32_t parent);
113     const std::string &GetAlbumUri() const;
114     void SetAlbumUri(const std::string &albumUri);
115     int64_t GetDateTaken() const;
116     void SetDateTaken(int64_t dataTaken);
117 
118     int64_t GetTimePending() const;
119     void SetTimePending(int64_t timePending);
120 
121     bool IsFavorite() const;
122     void SetFavorite(bool isFavorite);
123     int64_t GetDateTrashed() const;
124     void SetDateTrashed(int64_t dateTrashed);
125 
126     const std::string &GetSelfId() const;
127     void SetSelfId(const std::string &selfId);
128     int32_t GetIsTrash() const;
129     void SetIsTrash(int32_t isTrash);
130     const std::string GetOwnerPackage() const;
131     void SetOwnerPackage(const std::string &ownerPackage);
132     const std::string GetPackageName() const;
133     void SetPackageName(const std::string &packageName);
134 
135     const std::string &GetRecyclePath() const;
136     void SetRecyclePath(const std::string &recyclePath);
137 
138     ResultNapiType GetResultNapiType() const;
139     void SetResultNapiType(const ResultNapiType type);
140 
141     int32_t GetPhotoSubType() const;
142     void SetPhotoSubType(int32_t photoSubType);
143 
144     int32_t GetPhotoIndex() const;
145 
146     const std::string &GetCameraShotKey() const;
147     void SetCameraShotKey(const std::string &cameraShotKey);
148 
149     bool IsHidden() const;
150     void SetHidden(bool isHidden);
151 
152     void SetOpenStatus(int32_t fd, int32_t openStatus);
153     void RemoveOpenStatus(int32_t fd);
154     int32_t GetOpenStatus(int32_t fd);
155 
156     std::unordered_map<std::string, std::variant<int32_t, int64_t, std::string>> &GetMemberMap();
157     std::variant<int32_t, int64_t, std::string> &GetMemberValue(const std::string &name);
158 
159     void CommitModify();
160     bool IsDirectory();
161 
162     const std::string &GetAllExif() const;
163     void SetAllExif(const std::string &allExif);
164 
165     const std::string &GetUserComment() const;
166     void SetUserComment(const std::string &userComment);
167 
168     const std::string &GetFilePath() const;
169     void SetFilePath(const std::string &filePath);
170 
171 private:
172     const std::string &GetStrMember(const std::string &name) const;
173     int32_t GetInt32Member(const std::string &name) const;
174     int64_t GetInt64Member(const std::string &name) const;
175 
176     std::string albumUri_;
177     ResultNapiType resultNapiType_;
178     int32_t count_;
179     std::unordered_map<std::string, std::variant<int32_t, int64_t, std::string>> member_;
180     std::mutex openStatusMapMutex_;
181     std::shared_ptr<std::unordered_map<int32_t, int32_t>> openStatusMap_;
182 };
183 } // namespace Media
184 } // namespace OHOS
185 
186 #endif  // INTERFACES_INNERKITS_NATIVE_INCLUDE_FILE_ASSET_H_
187