• 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 "visibility.h"
24 #include "unified_types.h"
25 
26 namespace OHOS {
27 namespace UDMF {
28 class API_EXPORT UnifiedRecord {
29 public:
30     UnifiedRecord();
31     explicit UnifiedRecord(UDType type);
32     UnifiedRecord(UDType type, ValueType value);
33     virtual ~UnifiedRecord() = default;
34 
35     UnifiedRecord(const UnifiedRecord& other) = delete;
36     UnifiedRecord& operator=(const UnifiedRecord& other) = delete;
37     UnifiedRecord(UnifiedRecord &&other) = delete;
38     UnifiedRecord& operator=(UnifiedRecord &&other) = delete;
39 
40     UDType GetType() const;
41     std::vector<std::string> GetTypes() const;
42     void SetType(const UDType &type);
43     virtual int64_t GetSize();
44 
45     std::string GetUid() const;
46     void SetUid(const std::string &id);
47     ValueType GetValue();
48     void SetValue(const ValueType &value);
49     ValueType GetOriginValue() const;
50 
51     void SetUtdId(const std::string &utdId);
52     std::set<std::string> GetUtdIds() const;
53     std::string GetUtdId() const;
54 
55     bool HasType(const std::string &utdId) const;
56     void AddEntry(const std::string &utdId, ValueType &&value);
57     ValueType GetEntry(const std::string &utdId);
58     std::shared_ptr<std::map<std::string, ValueType>> GetEntries();
59     std::shared_ptr<std::map<std::string, ValueType>> GetInnerEntries() const;
60     void SetInnerEntries(std::shared_ptr<std::map<std::string, ValueType>> entries);
61     int64_t GetInnerEntriesSize() const;
62 
63     void SetEntryGetter(const std::vector<std::string> &utdIds, const std::shared_ptr<EntryGetter> &entryGetter);
64     std::shared_ptr<EntryGetter> GetEntryGetter();
65     void SetDataId(uint32_t dataId);
66     uint32_t GetDataId() const;
67     void SetRecordId(uint32_t recordId);
68     uint32_t GetRecordId() const;
69     void SetChannelName(const std::string &channelName);
70 
71     virtual void InitObject();
72     bool HasObject();
73     bool HasFileType(std::string &fileUri) const;
74     void SetFileUri(const std::string &fileUri);
75 protected:
76     static constexpr const char *UNIFORM_DATA_TYPE = "uniformDataType";
77     static constexpr const char *DETAILS = "details";
78     UDType dataType_;
79     ValueType value_;
80     bool hasObject_ = false;
81 private:
82     std::string uid_; // unique identifier
83     std::string utdId_;
84     std::shared_ptr<std::map<std::string, ValueType>> entries_ = std::make_shared<std::map<std::string, ValueType>>();
85     uint32_t dataId_ = 0;
86     uint32_t recordId_ = 0;
87     std::string channelName_;
88     std::shared_ptr<EntryGetter> entryGetter_;
89     mutable std::recursive_mutex mutex_;
90 };
91 } // namespace UDMF
92 } // namespace OHOS
93 #endif // UDMF_UNIFIED_RECORD_H
94