• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 UDMF_UNIFIED_RECORD_H
17 #define UDMF_UNIFIED_RECORD_H
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 #include "entry_getter.h"
23 #include "unified_meta.h"
24 #include "visibility.h"
25 #include "unified_types.h"
26 
27 namespace OHOS {
28 namespace UDMF {
29 class UnifiedRecord {
30 public:
31     API_EXPORT UnifiedRecord();
32     explicit API_EXPORT UnifiedRecord(UDType type);
33     API_EXPORT UnifiedRecord(UDType type, ValueType value);
34     virtual ~UnifiedRecord() = default;
35 
36     API_EXPORT UnifiedRecord(const UnifiedRecord& other) = delete;
37     API_EXPORT UnifiedRecord& operator=(const UnifiedRecord& other) = delete;
38     API_EXPORT UnifiedRecord(UnifiedRecord &&other) = delete;
39     API_EXPORT UnifiedRecord& operator=(UnifiedRecord &&other) = delete;
40 
41     UDType API_EXPORT GetType() const;
42     std::vector<std::string> API_EXPORT GetTypes() const;
43     void API_EXPORT SetType(const UDType &type);
44     virtual int64_t API_EXPORT GetSize();
45 
46     std::string API_EXPORT GetUid() const;
47     void API_EXPORT SetUid(const std::string &id);
48     ValueType API_EXPORT GetValue();
49     void SetValue(const ValueType &value);
50     ValueType API_EXPORT GetOriginValue() const;
51 
52     void API_EXPORT SetUtdId(const std::string &utdId);
53     std::set<std::string> API_EXPORT GetUtdIds() const;
54     std::set<std::string> API_EXPORT GetUtdIdsWithAddFileType(bool isSpecific) const;
55     std::string API_EXPORT GetUtdId() const;
56     void API_EXPORT SetUtdId2(const std::string &utdId);
57     std::string API_EXPORT GetUtdId2() const;
58 
59     bool API_EXPORT HasType(const std::string &utdId) const;
60     void API_EXPORT AddEntry(const std::string &utdId, ValueType &&value);
61     ValueType API_EXPORT GetEntry(const std::string &utdId);
62     std::shared_ptr<std::map<std::string, ValueType>> API_EXPORT GetEntries();
63     std::shared_ptr<std::map<std::string, ValueType>> API_EXPORT GetInnerEntries() const;
64     void SetInnerEntries(std::shared_ptr<std::map<std::string, ValueType>> entries);
65     int64_t GetInnerEntriesSize() const;
66 
67     void API_EXPORT SetEntryGetter(const std::vector<std::string> &utdIds,
68         const std::shared_ptr<EntryGetter> &entryGetter);
69     std::shared_ptr<EntryGetter> API_EXPORT GetEntryGetter();
70     void API_EXPORT SetDataId(uint32_t dataId);
71     uint32_t API_EXPORT GetDataId() const;
72     void API_EXPORT SetRecordId(uint32_t recordId);
73     uint32_t API_EXPORT GetRecordId() const;
74     void API_EXPORT SetChannelName(const std::string &channelName);
75 
76     virtual void InitObject();
77     bool HasFileType(std::string &fileUri) const;
78     void SetFileUri(const std::string &fileUri);
79 
80     std::vector<UriInfo> GetUris() const;
81     void SetUris(std::vector<UriInfo> uris);
82     void API_EXPORT ClearUris();
83     void API_EXPORT ComputeUris(const std::function<bool(UriInfo &)> &action);
84 protected:
85     UDType dataType_;
86     std::string utdId_;
87     std::string utdId2_;
88     ValueType value_;
89 private:
90     void AddFileUriType(std::set<std::string> &utdIds, const std::shared_ptr<Object> &fileUri, bool isSpecific) const;
91 
92     std::string uid_; // unique identifier
93     std::shared_ptr<std::map<std::string, ValueType>> entries_ = std::make_shared<std::map<std::string, ValueType>>();
94     std::vector<UriInfo> uris_ {};
95     uint32_t dataId_ = 0;
96     uint32_t recordId_ = 0;
97     std::string channelName_;
98     std::shared_ptr<EntryGetter> entryGetter_;
99     mutable std::recursive_mutex mutex_;
100 };
101 } // namespace UDMF
102 } // namespace OHOS
103 #endif // UDMF_UNIFIED_RECORD_H
104