• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "metadata/store_meta_data_local.h"
16 #include "utils/constant.h"
17 
18 namespace OHOS {
19 namespace DistributedData {
Marshal(json & node) const20 bool PolicyValue::Marshal(json &node) const
21 {
22     SetValue(node[GET_NAME(type)], type);
23     SetValue(node[GET_NAME(valueUint)], valueUint);
24     SetValue(node[GET_NAME(index)], index);
25     return true;
26 }
27 
Unmarshal(const json & node)28 bool PolicyValue::Unmarshal(const json &node)
29 {
30     GetValue(node, GET_NAME(type), type);
31     GetValue(node, GET_NAME(valueUint), valueUint);
32     GetValue(node, GET_NAME(index), index);
33     return true;
34 }
35 
IsValueEffect() const36 bool PolicyValue::IsValueEffect() const
37 {
38     return (index > 0);
39 }
40 
HasPolicy(uint32_t type)41 bool StoreMetaDataLocal::HasPolicy(uint32_t type)
42 {
43     for (const auto &policy : policies) {
44         if (policy.type == type) {
45             return true;
46         }
47     }
48     return false;
49 }
50 
GetPolicy(uint32_t type)51 PolicyValue StoreMetaDataLocal::GetPolicy(uint32_t type)
52 {
53     for (const auto &policy : policies) {
54         if (policy.type == type) {
55             return policy;
56         }
57     }
58     return PolicyValue();
59 }
60 
Marshal(json & node) const61 bool PromiseInfo::Marshal(json &node) const
62 {
63     SetValue(node[GET_NAME(tokenIds)], tokenIds);
64     SetValue(node[GET_NAME(uids)], uids);
65     SetValue(node[GET_NAME(permissionNames)], permissionNames);
66     return true;
67 }
68 
Unmarshal(const json & node)69 bool PromiseInfo::Unmarshal(const json &node)
70 {
71     GetValue(node, GET_NAME(tokenIds), tokenIds);
72     GetValue(node, GET_NAME(uids), uids);
73     GetValue(node, GET_NAME(permissionNames), permissionNames);
74     return true;
75 }
76 
Marshal(json & node) const77 bool StoreMetaDataLocal::Marshal(json &node) const
78 {
79     SetValue(node[GET_NAME(isAutoSync)], isAutoSync);
80     SetValue(node[GET_NAME(isBackup)], isBackup);
81     SetValue(node[GET_NAME(isDirty)], isDirty);
82     SetValue(node[GET_NAME(isEncrypt)], isEncrypt);
83     SetValue(node[GET_NAME(dataDir)], dataDir);
84     SetValue(node[GET_NAME(schema)], schema);
85     SetValue(node[GET_NAME(policies)], policies);
86     SetValue(node[GET_NAME(isPublic)], isPublic);
87     SetValue(node[GET_NAME(promiseInfo)], promiseInfo);
88     return true;
89 }
90 
Unmarshal(const json & node)91 bool StoreMetaDataLocal::Unmarshal(const json &node)
92 {
93     GetValue(node, GET_NAME(isAutoSync), isAutoSync);
94     GetValue(node, GET_NAME(isBackup), isBackup);
95     GetValue(node, GET_NAME(isDirty), isDirty);
96     GetValue(node, GET_NAME(isEncrypt), isEncrypt);
97     GetValue(node, GET_NAME(dataDir), dataDir);
98     GetValue(node, GET_NAME(schema), schema);
99     GetValue(node, GET_NAME(policies), policies);
100     GetValue(node, GET_NAME(isPublic), isPublic);
101     GetValue(node, GET_NAME(promiseInfo), promiseInfo);
102     return true;
103 }
104 
StoreMetaDataLocal()105 StoreMetaDataLocal::StoreMetaDataLocal()
106 {
107 }
108 
~StoreMetaDataLocal()109 StoreMetaDataLocal::~StoreMetaDataLocal()
110 {
111 }
112 
operator ==(const StoreMetaDataLocal & metaData) const113 bool StoreMetaDataLocal::operator==(const StoreMetaDataLocal &metaData) const
114 {
115     if (Constant::NotEqual(isAutoSync, metaData.isAutoSync) || Constant::NotEqual(isBackup, metaData.isBackup) ||
116         Constant::NotEqual(isDirty, metaData.isDirty) || Constant::NotEqual(isEncrypt, metaData.isEncrypt) ||
117         Constant::NotEqual(isPublic, metaData.isPublic)) {
118         return false;
119     }
120     return dataDir == metaData.dataDir;
121 }
122 
operator !=(const StoreMetaDataLocal & metaData) const123 bool StoreMetaDataLocal::operator!=(const StoreMetaDataLocal &metaData) const
124 {
125     return !(*this == metaData);
126 }
127 
GetKey(const std::initializer_list<std::string> & fields)128 std::string StoreMetaDataLocal::GetKey(const std::initializer_list<std::string> &fields)
129 {
130     return Constant::Join(KEY_PREFIX, Constant::KEY_SEPARATOR, fields);
131 }
132 
GetPrefix(const std::initializer_list<std::string> & fields)133 std::string StoreMetaDataLocal::GetPrefix(const std::initializer_list<std::string> &fields)
134 {
135     auto prefix = Constant::Join(KEY_PREFIX, Constant::KEY_SEPARATOR, fields);
136     prefix.append(Constant::KEY_SEPARATOR);
137     return prefix;
138 }
139 
GetPrefix(const std::initializer_list<std::string> & fields)140 std::string StoreDfxInfo::GetPrefix(const std::initializer_list<std::string> &fields)
141 {
142     auto prefix = Constant::Join(StoreDfxInfo::KEY_PREFIX, Constant::KEY_SEPARATOR, fields);
143     prefix.append(Constant::KEY_SEPARATOR);
144     return prefix;
145 }
146 
Marshal(json & node) const147 bool StoreDfxInfo::Marshal(json &node) const
148 {
149     SetValue(node[GET_NAME(lastOpenTime)], lastOpenTime);
150     return true;
151 }
152 
Unmarshal(const json & node)153 bool StoreDfxInfo::Unmarshal(const json &node)
154 {
155     GetValue(node, GET_NAME(lastOpenTime), lastOpenTime);
156     return true;
157 }
158 } // namespace DistributedData
159 } // namespace OHOS
160