• 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() 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 HasObject();
78     bool HasFileType(std::string &fileUri) const;
79     void SetFileUri(const std::string &fileUri);
80 
81     std::vector<UriInfo> GetUris() const;
82     void SetUris(std::vector<UriInfo> uris);
83     void API_EXPORT ClearUris();
84     void API_EXPORT ComputeUris(const std::function<bool(UriInfo &)> &action);
85 protected:
86     UDType dataType_;
87     std::string utdId_;
88     std::string utdId2_;
89     ValueType value_;
90     bool hasObject_ = false;
91 private:
92     void AddFileUriType(std::set<std::string> &utdIds, const std::shared_ptr<Object> &fileUri) const;
93 
94     std::string uid_; // unique identifier
95     std::shared_ptr<std::map<std::string, ValueType>> entries_ = std::make_shared<std::map<std::string, ValueType>>();
96     std::vector<UriInfo> uris_;
97     uint32_t dataId_ = 0;
98     uint32_t recordId_ = 0;
99     std::string channelName_;
100     std::shared_ptr<EntryGetter> entryGetter_;
101     mutable std::recursive_mutex mutex_;
102 };
103 } // namespace UDMF
104 } // namespace OHOS
105 #endif // UDMF_UNIFIED_RECORD_H
106