• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 METADATA_H
17 #define METADATA_H
18 
19 #include <unordered_map>
20 #include <variant>
21 #include "scanner_utils.h"
22 #include "fetch_result.h"
23 #include "abs_shared_result_set.h"
24 
25 namespace OHOS {
26 namespace Media {
27 #define EXPORT __attribute__ ((visibility ("default")))
28 class Metadata {
29 public:
30     EXPORT Metadata();
31     EXPORT ~Metadata() = default;
32     using VariantData = std::variant<int32_t, std::string, int64_t, double>;
33 
34     EXPORT void SetFileId(const VariantData &id);
35     EXPORT int32_t GetFileId() const;
36 
37     EXPORT void SetFilePath(const VariantData &path);
38     EXPORT const std::string &GetFilePath() const;
39 
40     void SetUri(const VariantData &uri);
41     const std::string &GetUri() const;
42 
43     EXPORT void SetRelativePath(const VariantData &relativePath);
44     EXPORT const std::string &GetRelativePath() const;
45 
46     EXPORT void SetFileMimeType(const VariantData &mimeType);
47     EXPORT const std::string &GetFileMimeType() const;
48 
49     EXPORT void SetFileMediaType(const VariantData &mediaType);
50     EXPORT MediaType GetFileMediaType() const;
51 
52     EXPORT void SetFileName(const VariantData &name);
53     EXPORT const std::string &GetFileName() const;
54 
55     EXPORT void SetFileSize(const VariantData &size);
56     EXPORT int64_t GetFileSize() const;
57 
58     void SetFileDateAdded(const VariantData &dateAdded);
59     int64_t GetFileDateAdded() const;
60 
61     EXPORT void SetFileDateModified(const VariantData &dateModified);
62     EXPORT int64_t GetFileDateModified() const;
63 
64     EXPORT void SetFileExtension(const VariantData &fileExt);
65     const std::string &GetFileExtension() const;
66 
67     EXPORT void SetFileTitle(const VariantData &title);
68     EXPORT const std::string &GetFileTitle() const;
69 
70     void SetFileArtist(const VariantData &artist);
71     const std::string &GetFileArtist() const;
72 
73     EXPORT void SetAlbum(const VariantData &album);
74     EXPORT const std::string &GetAlbum() const;
75 
76     void SetFileHeight(const VariantData &height);
77     EXPORT int32_t GetFileHeight() const;
78 
79     void SetFileWidth(const VariantData &width);
80     EXPORT int32_t GetFileWidth() const;
81 
82     void SetOrientation(const VariantData &orientation);
83     EXPORT int32_t GetOrientation() const;
84 
85     void SetFileDuration(const VariantData &duration);
86     EXPORT int32_t GetFileDuration() const;
87 
88     EXPORT int32_t GetParentId() const;
89     EXPORT void SetParentId(const VariantData &id);
90 
91     void SetAlbumId(const VariantData &albumId);
92     int32_t GetAlbumId() const;
93 
94     EXPORT void SetAlbumName(const VariantData &album);
95     EXPORT const std::string &GetAlbumName() const;
96 
97     EXPORT void SetRecyclePath(const VariantData &recyclePath);
98     EXPORT const std::string &GetRecyclePath() const;
99 
100     EXPORT void SetDateTaken(const VariantData &dateTaken);
101     EXPORT int64_t GetDateTaken() const;
102 
103     void SetLongitude(const VariantData &longitude);
104     EXPORT double GetLongitude() const;
105 
106     void SetLatitude(const VariantData &latitude);
107     EXPORT double GetLatitude() const;
108 
109     void SetTimePending(const VariantData &timePending);
110     int64_t GetTimePending() const;
111 
112     void SetUserComment(const VariantData &userComment);
113     const std::string &GetUserComment() const;
114 
115     void SetAllExif(const VariantData &allExif);
116     EXPORT const std::string &GetAllExif() const;
117 
118     void SetDateYear(const VariantData &dateYear);
119     const std::string &getDateYear() const;
120 
121     void SetDateMonth(const VariantData &dateMonth);
122     const std::string &getDateMonth() const;
123 
124     void SetDateDay(const VariantData &dateDay);
125     const std::string &GetDateDay() const;
126 
127     void SetShootingMode(const VariantData &shootingMode);
128     EXPORT const std::string &GetShootingMode() const;
129 
130     void SetShootingModeTag(const VariantData &shootingMode);
131     EXPORT const std::string &GetShootingModeTag() const;
132 
133     void SetLastVisitTime(const VariantData &lastVisitTime);
134     EXPORT int64_t GetLastVisitTime() const;
135 
136 #ifdef MEDIALIBRARY_COMPATIBILITY
137     void SetPhotoSubType(const VariantData &photoSubType);
138     int32_t GetPhotoSubType() const;
139 #endif
140     void SetForAdd(bool forAdd);
141     bool GetForAdd() const;
142     void SetTableName(const std::string &tableName);
143     std::string GetTableName();
144 
145     EXPORT void Init();
146 
147     using MetadataFnPtr = void (Metadata::*)(const VariantData &);
148     std::unordered_map<std::string, std::pair<ResultSetDataType, MetadataFnPtr>> memberFuncMap_;
149 
150 private:
151     int32_t id_;
152     std::string uri_;
153     std::string filePath_;
154     std::string relativePath_;
155 
156     std::string mimeType_;
157     MediaType mediaType_;
158     std::string name_;
159 
160     int64_t size_;
161     int64_t dateModified_;
162     int64_t dateAdded_;
163 
164     std::string fileExt_;
165     int32_t parentId_;
166 
167     // audio
168     std::string title_;
169     std::string artist_;
170     std::string album_;
171 
172     // video, image
173     int32_t height_;
174     int32_t width_;
175     int32_t duration_;
176     int32_t orientation_;
177     string dateYear_;
178     string dateMonth_;
179     string dateDay_;
180     string shootingMode_;
181     string shootingModeTag_;
182     int64_t lastVisitTime_;
183 
184     // video, audio, image
185     int64_t dateTaken_;
186 
187     // image
188     double longitude_;
189     double latitude_;
190     std::string userComment_;
191     std::string allExif_;
192 
193     // album
194     int32_t albumId_;
195     std::string albumName_;
196 
197     // recycle
198     std::string recyclePath_;
199 
200     // pending
201     int64_t timePending_;
202 #ifdef MEDIALIBRARY_COMPATIBILITY
203     // photo subtype
204     int32_t photoSubType_ = 0;
205 #endif
206     bool forAdd_ = false;
207     std::string tableName_;
208 };
209 } // namespace Media
210 } // namespace OHOS
211 
212 #endif // METADATA_H
213