• 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 #define EXPORT __attribute__ ((visibility ("default")))
29 
30 constexpr int MEMBER_TYPE_INT32 = 0;
31 constexpr int MEMBER_TYPE_INT64 = 1;
32 constexpr int MEMBER_TYPE_STRING = 2;
33 constexpr int MEMBER_TYPE_DOUBLE = 3;
34 
35 constexpr int OPEN_TYPE_READONLY = 0;
36 constexpr int OPEN_TYPE_WRITE = 1;
37 
38 /**
39  * @brief Class for filling all file asset parameters
40  *
41  * @since 1.0
42  * @version 1.0
43  */
44 class FileAsset {
45 public:
46     EXPORT FileAsset();
47     EXPORT virtual ~FileAsset() = default;
48 
49     EXPORT int32_t GetId() const;
50     EXPORT void SetId(int32_t id);
51 
52     EXPORT int32_t GetCount() const;
53     EXPORT void SetCount(int32_t count);
54 
55     EXPORT const std::string &GetUri() const;
56     EXPORT void SetUri(const std::string &uri);
57 
58     EXPORT const std::string &GetPath() const;
59     EXPORT void SetPath(const std::string &path);
60 
61     EXPORT const std::string &GetRelativePath() const;
62     EXPORT void SetRelativePath(const std::string &relativePath);
63 
64     EXPORT const std::string &GetMimeType() const;
65     EXPORT void SetMimeType(const std::string &mimeType);
66 
67     EXPORT MediaType GetMediaType() const;
68     EXPORT void SetMediaType(MediaType mediaType);
69 
70     EXPORT const std::string &GetDisplayName() const;
71     EXPORT void SetDisplayName(const std::string &displayName);
72 
73     EXPORT int64_t GetSize() const;
74     EXPORT void SetSize(int64_t size);
75 
76     EXPORT const std::string &GetCloudId() const;
77     EXPORT void SetCloudId(const std::string &cloudId);
78 
79     EXPORT int64_t GetDateAdded() const;
80     EXPORT void SetDateAdded(int64_t dataAdded);
81 
82     EXPORT int64_t GetDateModified() const;
83     EXPORT void SetDateModified(int64_t dateModified);
84 
85     EXPORT const std::string &GetTitle() const;
86     EXPORT void SetTitle(const std::string &title);
87 
88     EXPORT const std::string &GetArtist() const;
89     EXPORT void SetArtist(const std::string &artist);
90 
91     EXPORT const std::string &GetAlbum() const;
92     EXPORT void SetAlbum(const std::string &album);
93 
94     EXPORT int32_t GetPosition() const;
95     EXPORT void SetPosition(int32_t position);
96 
97     EXPORT int32_t GetWidth() const;
98     EXPORT void SetWidth(int32_t width);
99 
100     EXPORT int32_t GetHeight() const;
101     EXPORT void SetHeight(int32_t height);
102 
103     EXPORT int32_t GetDuration() const;
104     EXPORT void SetDuration(int32_t duration);
105 
106     EXPORT int32_t GetOrientation() const;
107     EXPORT void SetOrientation(int32_t orientation);
108 
109     EXPORT int32_t GetAlbumId() const;
110     EXPORT void SetAlbumId(int32_t albumId);
111 
112     EXPORT int32_t GetOwnerAlbumId() const;
113     EXPORT void SetOwnerAlbumId(int32_t albumId);
114 
115     EXPORT const std::string &GetAlbumName() const;
116     EXPORT void SetAlbumName(const std::string &albumName);
117 
118     EXPORT int32_t GetParent() const;
119     EXPORT void SetParent(int32_t parent);
120     EXPORT const std::string &GetAlbumUri() const;
121     EXPORT void SetAlbumUri(const std::string &albumUri);
122     EXPORT int64_t GetDateTaken() const;
123     EXPORT void SetDateTaken(int64_t dataTaken);
124 
125     EXPORT int64_t GetTimePending() const;
126     EXPORT void SetTimePending(int64_t timePending);
127 
128     EXPORT bool IsFavorite() const;
129     EXPORT void SetFavorite(bool isFavorite);
130     EXPORT bool IsRecentShow() const;
131     EXPORT void SetRecentShow(bool isRecentShow);
132     EXPORT int64_t GetDateTrashed() const;
133     EXPORT void SetDateTrashed(int64_t dateTrashed);
134 
135     EXPORT std::string GetPhotoId() const;
136     EXPORT void SetPhotoId(const std::string &photoId);
137 
138     EXPORT std::pair<std::string, int> GetPhotoIdAndQuality() const;
139     EXPORT void SetPhotoIdAndQuality(const std::string &photoId, int photoQuality);
140 
141     EXPORT void SetLatitude(double latitude);
142     EXPORT double GetLatitude();
143     EXPORT void SetLongitude(double longitude);
144     EXPORT double GetLongitude();
145 
146     EXPORT const std::string &GetSelfId() const;
147     EXPORT void SetSelfId(const std::string &selfId);
148     EXPORT int32_t GetIsTrash() const;
149     EXPORT void SetIsTrash(int32_t isTrash);
150     EXPORT const std::string GetOwnerPackage() const;
151     EXPORT void SetOwnerPackage(const std::string &ownerPackage);
152     EXPORT const std::string GetOwnerAppId() const;
153     EXPORT void SetOwnerAppId(const std::string &ownerAppId);
154     EXPORT const std::string GetPackageName() const;
155     EXPORT void SetPackageName(const std::string &packageName);
156 
157     EXPORT const std::string &GetRecyclePath() const;
158     EXPORT void SetRecyclePath(const std::string &recyclePath);
159 
160     EXPORT ResultNapiType GetResultNapiType() const;
161     EXPORT void SetResultNapiType(const ResultNapiType type);
162 
163     EXPORT int32_t GetPhotoSubType() const;
164     EXPORT void SetPhotoSubType(int32_t photoSubType);
165 
166     EXPORT int32_t GetPhotoIndex() const;
167 
168     EXPORT int32_t GetOriginalSubType() const;
169 
170     EXPORT const std::string &GetCameraShotKey() const;
171     EXPORT void SetCameraShotKey(const std::string &cameraShotKey);
172 
173     EXPORT bool IsHidden() const;
174     EXPORT void SetHidden(bool isHidden);
175 
176     EXPORT void SetOpenStatus(int32_t fd, int32_t openStatus);
177     EXPORT void RemoveOpenStatus(int32_t fd);
178     EXPORT int32_t GetOpenStatus(int32_t fd);
179 
180     EXPORT std::unordered_map<std::string, std::variant<int32_t, int64_t, std::string, double>> &GetMemberMap();
181     EXPORT std::variant<int32_t, int64_t, std::string, double> &GetMemberValue(const std::string &name);
182 
183     EXPORT std::string GetAssetJson();
184     EXPORT void SetResultTypeMap(const std::string &colName, ResultSetDataType type);
185 
186     EXPORT const std::string &GetAllExif() const;
187     EXPORT void SetAllExif(const std::string &allExif);
188 
189     EXPORT const std::string &GetFrontCamera() const;
190     EXPORT void SetFrontCamera(const std::string &frontCamera);
191 
192     EXPORT const std::string &GetUserComment() const;
193     EXPORT void SetUserComment(const std::string &userComment);
194 
195     EXPORT const std::string &GetFilePath() const;
196     EXPORT void SetFilePath(const std::string &filePath);
197 
198     EXPORT int64_t GetPhotoEditTime() const;
199     EXPORT void SetPhotoEditTime(int64_t photoEditTime);
200 
201     EXPORT int32_t GetMovingPhotoEffectMode() const;
202     EXPORT void SetMovingPhotoEffectMode(int32_t effectMode);
203 
204     EXPORT int64_t GetCoverPosition() const;
205     EXPORT void SetCoverPosition(int64_t coverPosition);
206 
207     EXPORT const std::string &GetBurstKey() const;
208     EXPORT void SetBurstKey(const std::string &burstKey);
209 
210     EXPORT int32_t GetBurstCoverLevel() const;
211     EXPORT void SetBurstCoverLevel(int32_t burstCoverLevel);
212 
213     EXPORT const std::string &GetDetailTime() const;
214     EXPORT void SetDetailTime(const std::string &detailTime);
215 
216     EXPORT int32_t GetCEAvailable() const;
217     EXPORT void SetCEAvailable(int32_t ceAvailable);
218 
219     EXPORT int32_t GetSupportedWatermarkType() const;
220     EXPORT void SetSupportedWatermarkType(int32_t watermarkType);
221 
222     EXPORT int32_t GetIsAuto() const;
223     EXPORT void SetIsAuto(int32_t isAuto);
224 
225     EXPORT int32_t GetDirty() const;
226     EXPORT void SetDirty(int32_t dirty);
227 
228     EXPORT std::string GetMediaSuffix() const;
229     EXPORT void SetMediaSuffix(const std::string &mediaSuffix);
230 
231     EXPORT const std::string &GetStrMember(const std::string &name) const;
232     EXPORT int32_t GetInt32Member(const std::string &name) const;
233     EXPORT int64_t GetInt64Member(const std::string &name) const;
234     EXPORT double GetDoubleMember(const std::string &name) const;
SetMemberValue(const std::string & name,const std::variant<int32_t,int64_t,std::string,double> & value)235     EXPORT void SetMemberValue(const std::string &name,
236                                const std::variant<int32_t, int64_t, std::string, double> &value)
237     {
238         member_[name] = value;
239     }
240 
241     EXPORT void SetUserId(int32_t userId);
242     EXPORT int32_t GetUserId();
243 
244 private:
245     int32_t userId_;
246     std::string albumUri_;
247     ResultNapiType resultNapiType_;
248     std::unordered_map<std::string, std::variant<int32_t, int64_t, std::string, double>> member_;
249     std::mutex openStatusMapMutex_;
250     std::shared_ptr<std::unordered_map<int32_t, int32_t>> openStatusMap_;
251     std::mutex resultTypeMapMutex_;
252     std::unordered_map<std::string, ResultSetDataType> resultTypeMap_;
253 };
254 } // namespace Media
255 } // namespace OHOS
256 
257 #endif  // INTERFACES_INNERKITS_NATIVE_INCLUDE_FILE_ASSET_H_
258