• 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 class Metadata {
28 public:
29     Metadata();
30     ~Metadata() = default;
31     using VariantData = std::variant<int32_t, std::string, int64_t, double>;
32 
33     void SetFileId(const VariantData &id);
34     int32_t GetFileId() const;
35 
36     void SetFilePath(const VariantData &path);
37     const std::string &GetFilePath() const;
38 
39     void SetUri(const VariantData &uri);
40     const std::string &GetUri() const;
41 
42     void SetRelativePath(const VariantData &relativePath);
43     const std::string &GetRelativePath() const;
44 
45     void SetFileMimeType(const VariantData &mimeType);
46     const std::string &GetFileMimeType() const;
47 
48     void SetFileMediaType(const VariantData &mediaType);
49     MediaType GetFileMediaType() const;
50 
51     void SetFileName(const VariantData &name);
52     const std::string &GetFileName() const;
53 
54     void SetFileSize(const VariantData &size);
55     int64_t GetFileSize() const;
56 
57     void SetFileDateAdded(const VariantData &dateAdded);
58     int64_t GetFileDateAdded() const;
59 
60     void SetFileDateModified(const VariantData &dateModified);
61     int64_t GetFileDateModified() const;
62 
63     void SetFileExtension(const VariantData &fileExt);
64     const std::string &GetFileExtension() const;
65 
66     void SetFileTitle(const VariantData &title);
67     const std::string &GetFileTitle() const;
68 
69     void SetFileArtist(const VariantData &artist);
70     const std::string &GetFileArtist() const;
71 
72     void SetAlbum(const VariantData &album);
73     const std::string &GetAlbum() const;
74 
75     void SetFileHeight(const VariantData &height);
76     int32_t GetFileHeight() const;
77 
78     void SetFileWidth(const VariantData &width);
79     int32_t GetFileWidth() const;
80 
81     void SetOrientation(const VariantData &orientation);
82     int32_t GetOrientation() const;
83 
84     void SetFileDuration(const VariantData &duration);
85     int32_t GetFileDuration() const;
86 
87     int32_t GetParentId() const;
88     void SetParentId(const VariantData &id);
89 
90     void SetAlbumId(const VariantData &albumId);
91     int32_t GetAlbumId() const;
92 
93     void SetAlbumName(const VariantData &album);
94     const std::string &GetAlbumName() const;
95 
96     void SetRecyclePath(const VariantData &recyclePath);
97     const std::string &GetRecyclePath() const;
98 
99     void SetDateTaken(const VariantData &dateTaken);
100     int64_t GetDateTaken() const;
101 
102     void SetLongitude(const VariantData &longitude);
103     double GetLongitude() const;
104 
105     void SetLatitude(const VariantData &latitude);
106     double GetLatitude() const;
107 
108     void Init();
109 
110     using MetadataFnPtr = void (Metadata::*)(const VariantData &);
111     std::unordered_map<std::string, std::pair<ResultSetDataType, MetadataFnPtr>> memberFuncMap_;
112 
113 private:
114     int32_t id_;
115     std::string uri_;
116     std::string filePath_;
117     std::string relativePath_;
118 
119     std::string mimeType_;
120     MediaType mediaType_;
121     std::string name_;
122 
123     int64_t size_;
124     int64_t dateModified_;
125     int64_t dateAdded_;
126 
127     std::string fileExt_;
128     int32_t parentId_;
129 
130     // audio
131     std::string title_;
132     std::string artist_;
133     std::string album_;
134 
135     // video, image
136     int32_t height_;
137     int32_t width_;
138     int32_t duration_;
139     int32_t orientation_;
140 
141     // video, audio, image
142     int64_t dateTaken_;
143 
144     // image
145     double longitude_;
146     double latitude_;
147 
148     // album
149     int32_t albumId_;
150     std::string albumName_;
151 
152     // recycle
153     std::string recyclePath_;
154 };
155 } // namespace Media
156 } // namespace OHOS
157 
158 #endif // METADATA_H
159