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 "flat_object_storage_engine.h"
16
17 #include "accesstoken_kit.h"
18 #include "ipc_skeleton.h"
19 #include "logger.h"
20 #include "objectstore_errors.h"
21 #include "process_communicator_impl.h"
22 #include "securec.h"
23 #include "softbus_adapter.h"
24 #include "string_utils.h"
25 #include "types_export.h"
26 #include "object_radar_reporter.h"
27
28 namespace OHOS::ObjectStore {
~FlatObjectStorageEngine()29 FlatObjectStorageEngine::~FlatObjectStorageEngine()
30 {
31 if (!isOpened_) {
32 return;
33 }
34 storeManager_ = nullptr;
35 LOG_INFO("FlatObjectStorageEngine::~FlatObjectStorageEngine Crash! end");
36 }
37
Open(const std::string & bundleName)38 uint32_t FlatObjectStorageEngine::Open(const std::string &bundleName)
39 {
40 if (isOpened_) {
41 LOG_INFO("FlatObjectDatabase: No need to reopen it");
42 return SUCCESS;
43 }
44 auto tokenId = IPCSkeleton::GetSelfTokenID();
45 int32_t ret = Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenId, DISTRIBUTED_DATASYNC);
46 LOG_INFO("bundleName:%{public}s, permission :%{public}d", bundleName.c_str(), ret);
47 if (ret == Security::AccessToken::PermissionState::PERMISSION_GRANTED) {
48 auto status = DistributedDB::KvStoreDelegateManager::SetProcessLabel("objectstoreDB", bundleName);
49 if (status != DistributedDB::DBStatus::OK) {
50 LOG_ERROR("delegate SetProcessLabel failed: %{public}d.", static_cast<int>(status));
51 }
52 status = DistributedDB::KvStoreDelegateManager::SetProcessCommunicator(
53 std::make_shared<ProcessCommunicatorImpl>());
54 if (status != DistributedDB::DBStatus::OK) {
55 LOG_ERROR("set distributed db communicator failed: %{public}d.", static_cast<int>(status));
56 }
57 }
58 storeManager_ = std::make_shared<DistributedDB::KvStoreDelegateManager>(bundleName, "default");
59 DistributedDB::KvStoreConfig config;
60 config.dataDir = "/data/log";
61 storeManager_->SetKvStoreConfig(config);
62 isOpened_ = true;
63 LOG_INFO("FlatObjectDatabase::Open Succeed");
64 return SUCCESS;
65 }
66
Close()67 uint32_t FlatObjectStorageEngine::Close()
68 {
69 if (!isOpened_) {
70 LOG_INFO("FlatObjectStorageEngine::Close has been closed!");
71 return SUCCESS;
72 }
73 std::lock_guard<std::mutex> lock(operationMutex_);
74 storeManager_ = nullptr;
75 isOpened_ = false;
76 return SUCCESS;
77 }
78
OnComplete(const std::string & key,const std::map<std::string,DistributedDB::DBStatus> & devices,std::shared_ptr<StatusWatcher> statusWatcher)79 void FlatObjectStorageEngine::OnComplete(const std::string &key,
80 const std::map<std::string, DistributedDB::DBStatus> &devices, std::shared_ptr<StatusWatcher> statusWatcher)
81 {
82 std::lock_guard<std::mutex> lock(watcherMutex_);
83 LOG_INFO("complete");
84 if (statusWatcher != nullptr) {
85 for (auto item : devices) {
86 statusWatcher->OnChanged(key, SoftBusAdapter::GetInstance()->ToNodeID(item.first),
87 item.second == DistributedDB::OK ? "online" : "offline");
88 }
89 }
90 }
91
CreateTable(const std::string & key)92 uint32_t FlatObjectStorageEngine::CreateTable(const std::string &key)
93 {
94 RadarReporter::ReportStage(std::string(__FUNCTION__), CREATE, CREATE_TABLE, IDLE);
95 if (!isOpened_) {
96 RadarReporter::ReportStateError(std::string(__FUNCTION__), CREATE, CREATE_TABLE,
97 RADAR_FAILED, DB_NOT_INIT, FINISHED);
98 return ERR_DB_NOT_INIT;
99 }
100 {
101 std::lock_guard<std::mutex> lock(operationMutex_);
102 if (delegates_.count(key) != 0) {
103 LOG_ERROR("FlatObjectStorageEngine::CreateTable %{public}s already created", key.c_str());
104 RadarReporter::ReportStateError(std::string(__FUNCTION__), CREATE, CREATE_TABLE, RADAR_FAILED,
105 DUPLICATE_CREATE, FINISHED);
106 return ERR_EXIST;
107 }
108 }
109 DistributedDB::KvStoreNbDelegate *kvStore = nullptr;
110 DistributedDB::DBStatus status;
111 DistributedDB::KvStoreNbDelegate::Option option = { true, true, false };
112 LOG_INFO("start create table");
113 storeManager_->GetKvStore(key, option,
114 [&status, &kvStore](DistributedDB::DBStatus dbStatus, DistributedDB::KvStoreNbDelegate *kvStoreNbDelegate) {
115 status = dbStatus;
116 kvStore = kvStoreNbDelegate;
117 LOG_INFO("create table result %{public}d", status);
118 });
119 if (status != DistributedDB::DBStatus::OK || kvStore == nullptr) {
120 LOG_ERROR("FlatObjectStorageEngine::CreateTable %{public}s getkvstore fail[%{public}d]", key.c_str(), status);
121 RadarReporter::ReportStateError(std::string(__FUNCTION__), CREATE, CREATE_TABLE,
122 RADAR_FAILED, status, FINISHED);
123 return ERR_DB_GETKV_FAIL;
124 }
125 bool autoSync = true;
126 DistributedDB::PragmaData data = static_cast<DistributedDB::PragmaData>(&autoSync);
127 LOG_INFO("start Pragma");
128 status = kvStore->Pragma(DistributedDB::AUTO_SYNC, data);
129 if (status != DistributedDB::DBStatus::OK) {
130 LOG_ERROR("FlatObjectStorageEngine::CreateTable %{public}s Pragma fail[%{public}d]", key.c_str(), status);
131 RadarReporter::ReportStateError(std::string(__FUNCTION__), CREATE, CREATE_TABLE,
132 RADAR_FAILED, status, FINISHED);
133 return ERR_DB_GETKV_FAIL;
134 }
135 LOG_INFO("create table %{public}s success", key.c_str());
136 {
137 std::lock_guard<std::mutex> lock(operationMutex_);
138 delegates_.insert_or_assign(key, kvStore);
139 }
140 auto onComplete = [key, this](const std::map<std::string, DistributedDB::DBStatus> &devices) {
141 OnComplete(key, devices, statusWatcher_);
142 };
143 std::vector<DeviceInfo> devices = SoftBusAdapter::GetInstance()->GetDeviceList();
144 std::vector<std::string> deviceIds;
145 for (auto item : devices) {
146 deviceIds.push_back(item.deviceId);
147 }
148 SyncAllData(key, deviceIds, onComplete);
149 RadarReporter::ReportStateFinished(std::string(__FUNCTION__), CREATE, CREATE_TABLE, RADAR_SUCCESS, FINISHED);
150 return SUCCESS;
151 }
152
GetTable(const std::string & key,std::map<std::string,Value> & result)153 uint32_t FlatObjectStorageEngine::GetTable(const std::string &key, std::map<std::string, Value> &result)
154 {
155 if (!isOpened_) {
156 LOG_ERROR("not opened %{public}s", key.c_str());
157 return ERR_DB_NOT_INIT;
158 }
159 std::lock_guard<std::mutex> lock(operationMutex_);
160 if (delegates_.count(key) == 0) {
161 LOG_INFO("FlatObjectStorageEngine::GetTable %{public}s not exist", key.c_str());
162 return ERR_DB_NOT_EXIST;
163 }
164 result.clear();
165 DistributedDB::KvStoreResultSet *resultSet = nullptr;
166 Key emptyKey;
167 LOG_DEBUG("start GetEntries");
168 auto delegate = delegates_.at(key);
169 DistributedDB::DBStatus status = delegate->GetEntries(emptyKey, resultSet);
170 if (status != DistributedDB::DBStatus::OK || resultSet == nullptr) {
171 LOG_INFO("FlatObjectStorageEngine::GetTable %{public}s GetEntries fail", key.c_str());
172 return ERR_DB_GET_FAIL;
173 }
174 LOG_DEBUG("end GetEntries");
175 while (resultSet->IsAfterLast()) {
176 DistributedDB::Entry entry;
177 status = resultSet->GetEntry(entry);
178 if (status != DistributedDB::DBStatus::OK) {
179 LOG_INFO("FlatObjectStorageEngine::GetTable GetEntry fail, errcode = %{public}d", status);
180 status = delegate->CloseResultSet(resultSet);
181 if (status != DistributedDB::DBStatus::OK) {
182 LOG_INFO("KvStoreNbDelegate::CloseResultSet fail, errcode = %{public}d", status);
183 return ERR_RESULTSET;
184 }
185 return ERR_DB_ENTRY_FAIL;
186 }
187 result.insert_or_assign(StringUtils::BytesToStr(entry.key), entry.value);
188 resultSet->MoveToNext();
189 }
190 status = delegate->CloseResultSet(resultSet);
191 if (status != DistributedDB::DBStatus::OK) {
192 LOG_INFO("KvStoreNbDelegate::CloseResultSet fail, errcode = %{public}d", status);
193 return ERR_RESULTSET;
194 }
195 return SUCCESS;
196 }
197
UpdateItem(const std::string & key,const std::string & itemKey,Value & value)198 uint32_t FlatObjectStorageEngine::UpdateItem(const std::string &key, const std::string &itemKey, Value &value)
199 {
200 if (!isOpened_) {
201 return ERR_DB_NOT_INIT;
202 }
203 std::lock_guard<std::mutex> lock(operationMutex_);
204 if (delegates_.count(key) == 0) {
205 LOG_INFO("FlatObjectStorageEngine::GetTable %{public}s not exist", key.c_str());
206 return ERR_DB_NOT_EXIST;
207 }
208 auto delegate = delegates_.at(key);
209 LOG_DEBUG("start Put");
210 auto status = delegate->Put(StringUtils::StrToBytes(itemKey), value);
211 if (status != DistributedDB::DBStatus::OK) {
212 LOG_ERROR("%{public}s Put fail[%{public}d]", key.c_str(), status);
213 return ERR_CLOSE_STORAGE;
214 }
215 LOG_DEBUG("put success");
216 return SUCCESS;
217 }
218
UpdateItems(const std::string & key,const std::map<std::string,std::vector<uint8_t>> & data)219 uint32_t FlatObjectStorageEngine::UpdateItems(
220 const std::string &key, const std::map<std::string, std::vector<uint8_t>> &data)
221 {
222 if (!isOpened_ || data.size() == 0) {
223 return ERR_DB_NOT_INIT;
224 }
225 std::lock_guard<std::mutex> lock(operationMutex_);
226 if (delegates_.count(key) == 0) {
227 LOG_INFO("FlatObjectStorageEngine::UpdateItems %{public}s not exist", key.c_str());
228 return ERR_DB_NOT_EXIST;
229 }
230
231 std::vector<DistributedDB::Entry> entries;
232 for (auto &item : data) {
233 DistributedDB::Entry entry = { .key = StringUtils::StrToBytes(item.first), .value = item.second };
234 entries.emplace_back(entry);
235 }
236 auto delegate = delegates_.at(key);
237 LOG_DEBUG("start PutBatch");
238 auto status = delegate->PutBatch(entries);
239 if (status != DistributedDB::DBStatus::OK) {
240 LOG_ERROR("%{public}s PutBatch fail[%{public}d]", key.c_str(), status);
241 return ERR_CLOSE_STORAGE;
242 }
243 LOG_DEBUG("put success");
244 return SUCCESS;
245 }
246
DeleteTable(const std::string & key)247 uint32_t FlatObjectStorageEngine::DeleteTable(const std::string &key)
248 {
249 if (!isOpened_) {
250 return ERR_DB_NOT_INIT;
251 }
252 std::lock_guard<std::mutex> lock(operationMutex_);
253 if (delegates_.count(key) == 0) {
254 LOG_INFO("FlatObjectStorageEngine::GetTable %{public}s not exist", key.c_str());
255 return ERR_DB_NOT_EXIST;
256 }
257 LOG_DEBUG("start DeleteTable %{public}s", key.c_str());
258 auto status = storeManager_->CloseKvStore(delegates_.at(key));
259 if (status != DistributedDB::DBStatus::OK) {
260 LOG_ERROR(
261 "FlatObjectStorageEngine::CloseKvStore %{public}s CloseKvStore fail[%{public}d]", key.c_str(), status);
262 return ERR_CLOSE_STORAGE;
263 }
264 LOG_DEBUG("DeleteTable success");
265 delegates_.erase(key);
266 return SUCCESS;
267 }
268
GetItem(const std::string & key,const std::string & itemKey,Value & value)269 uint32_t FlatObjectStorageEngine::GetItem(const std::string &key, const std::string &itemKey, Value &value)
270 {
271 if (!isOpened_) {
272 return ERR_DB_NOT_INIT;
273 }
274 std::lock_guard<std::mutex> lock(operationMutex_);
275 if (delegates_.count(key) == 0) {
276 LOG_ERROR("FlatObjectStorageEngine::GetItem %{public}s not exist", key.c_str());
277 return ERR_DB_NOT_EXIST;
278 }
279 LOG_DEBUG("start Get %{public}s", key.c_str());
280 DistributedDB::DBStatus status = delegates_.at(key)->Get(StringUtils::StrToBytes(itemKey), value);
281 if (status != DistributedDB::DBStatus::OK) {
282 LOG_ERROR("FlatObjectStorageEngine::GetItem %{public}s item fail %{public}d", itemKey.c_str(), status);
283 return status;
284 }
285 LOG_DEBUG("end Get %{public}s", key.c_str());
286 return SUCCESS;
287 }
288
RegisterObserver(const std::string & key,std::shared_ptr<TableWatcher> watcher)289 uint32_t FlatObjectStorageEngine::RegisterObserver(const std::string &key, std::shared_ptr<TableWatcher> watcher)
290 {
291 if (!isOpened_) {
292 LOG_ERROR("FlatObjectStorageEngine::RegisterObserver kvStore has not init");
293 return ERR_DB_NOT_INIT;
294 }
295 std::lock_guard<std::mutex> lock(operationMutex_);
296 if (delegates_.count(key) == 0) {
297 LOG_INFO("FlatObjectStorageEngine::RegisterObserver %{public}s not exist", key.c_str());
298 return ERR_DB_NOT_EXIST;
299 }
300 if (observerMap_.count(key) != 0) {
301 LOG_INFO("FlatObjectStorageEngine::RegisterObserver observer already exist.");
302 return SUCCESS;
303 }
304 auto delegate = delegates_.at(key);
305 std::vector<uint8_t> tmpKey;
306 LOG_DEBUG("start RegisterObserver %{public}s", key.c_str());
307 DistributedDB::DBStatus status =
308 delegate->RegisterObserver(tmpKey, DistributedDB::ObserverMode::OBSERVER_CHANGES_FOREIGN, watcher.get());
309 if (status != DistributedDB::DBStatus::OK) {
310 LOG_ERROR("FlatObjectStorageEngine::RegisterObserver watch err %{public}d", status);
311 return ERR_REGISTER;
312 }
313 LOG_DEBUG("end RegisterObserver %{public}s", key.c_str());
314 observerMap_.insert_or_assign(key, watcher);
315 return SUCCESS;
316 }
317
UnRegisterObserver(const std::string & key)318 uint32_t FlatObjectStorageEngine::UnRegisterObserver(const std::string &key)
319 {
320 if (!isOpened_) {
321 LOG_ERROR("FlatObjectStorageEngine::RegisterObserver kvStore has not init");
322 return ERR_DB_NOT_INIT;
323 }
324 std::lock_guard<std::mutex> lock(operationMutex_);
325 if (delegates_.count(key) == 0) {
326 LOG_INFO("FlatObjectStorageEngine::RegisterObserver %{public}s not exist", key.c_str());
327 return ERR_DB_NOT_EXIST;
328 }
329 auto iter = observerMap_.find(key);
330 if (iter == observerMap_.end()) {
331 LOG_ERROR("FlatObjectStorageEngine::UnRegisterObserver observer not exist.");
332 return ERR_NO_OBSERVER;
333 }
334 auto delegate = delegates_.at(key);
335 std::shared_ptr<TableWatcher> watcher = iter->second;
336 LOG_DEBUG("start UnRegisterObserver %{public}s", key.c_str());
337 DistributedDB::DBStatus status = delegate->UnRegisterObserver(watcher.get());
338 if (status != DistributedDB::DBStatus::OK) {
339 LOG_ERROR("FlatObjectStorageEngine::UnRegisterObserver unRegister err %{public}d", status);
340 return ERR_UNRIGSTER;
341 }
342 LOG_DEBUG("end UnRegisterObserver %{public}s", key.c_str());
343 observerMap_.erase(key);
344 return SUCCESS;
345 }
346
SetStatusNotifier(std::shared_ptr<StatusWatcher> watcher)347 uint32_t FlatObjectStorageEngine::SetStatusNotifier(std::shared_ptr<StatusWatcher> watcher)
348 {
349 if (!isOpened_) {
350 LOG_ERROR("FlatObjectStorageEngine::SetStatusNotifier kvStore has not init");
351 return ERR_DB_NOT_INIT;
352 }
353 auto databaseStatusNotifyCallback = [this](std::string userId, std::string appId, std::string storeId,
354 const std::string deviceId, bool onlineStatus) -> void {
355 std::lock_guard<std::mutex> lock(watcherMutex_);
356 LOG_INFO("complete");
357 if (statusWatcher_ == nullptr) {
358 LOG_INFO("FlatObjectStorageEngine::statusWatcher_ null");
359 return;
360 }
361 if (onlineStatus) {
362 auto onComplete = [this, storeId](const std::map<std::string, DistributedDB::DBStatus> &devices) {
363 for (auto item : devices) {
364 LOG_INFO("%{public}s pull data result %{public}d in device %{public}s",
365 SoftBusAdapter::ToBeAnonymous(storeId).c_str(), item.second,
366 SoftBusAdapter::ToBeAnonymous(SoftBusAdapter::GetInstance()->ToNodeID(item.first)).c_str());
367 }
368 if (statusWatcher_ != nullptr) {
369 for (auto item : devices) {
370 statusWatcher_->OnChanged(storeId, SoftBusAdapter::GetInstance()->ToNodeID(item.first),
371 item.second == DistributedDB::OK ? "online" : "offline");
372 }
373 }
374 };
375 SyncAllData(storeId, std::vector<std::string>({ deviceId }), onComplete);
376 } else {
377 statusWatcher_->OnChanged(storeId, SoftBusAdapter::GetInstance()->ToNodeID(deviceId), "offline");
378 }
379 };
380 storeManager_->SetStoreStatusNotifier(databaseStatusNotifyCallback);
381 LOG_INFO("FlatObjectStorageEngine::SetStatusNotifier success");
382 std::lock_guard<std::mutex> lock(watcherMutex_);
383 statusWatcher_ = watcher;
384 return SUCCESS;
385 }
386
SyncAllData(const std::string & sessionId,const std::vector<std::string> & deviceIds,const std::function<void (const std::map<std::string,DistributedDB::DBStatus> &)> & onComplete)387 uint32_t FlatObjectStorageEngine::SyncAllData(const std::string &sessionId, const std::vector<std::string> &deviceIds,
388 const std::function<void(const std::map<std::string, DistributedDB::DBStatus> &)> &onComplete)
389 {
390 LOG_INFO("start");
391 std::lock_guard<std::mutex> lock(operationMutex_);
392 if (delegates_.count(sessionId) == 0) {
393 LOG_ERROR("FlatObjectStorageEngine::SyncAllData %{public}s already deleted", sessionId.c_str());
394 return ERR_DB_NOT_EXIST;
395 }
396 DistributedDB::KvStoreNbDelegate *kvstore = delegates_.at(sessionId);
397 if (deviceIds.empty()) {
398 LOG_INFO("single device,no need sync");
399 return ERR_SINGLE_DEVICE;
400 }
401 LOG_INFO("start sync %{public}s", sessionId.c_str());
402 DistributedDB::DBStatus status = kvstore->Sync(deviceIds, DistributedDB::SyncMode::SYNC_MODE_PULL_ONLY, onComplete);
403 if (status != DistributedDB::DBStatus::OK) {
404 LOG_ERROR("FlatObjectStorageEngine::UnRegisterObserver unRegister err %{public}d", status);
405 return ERR_UNRIGSTER;
406 }
407 LOG_INFO("end sync %{public}s", sessionId.c_str());
408 return SUCCESS;
409 }
410
GetItems(const std::string & key,std::map<std::string,std::vector<uint8_t>> & data)411 uint32_t FlatObjectStorageEngine::GetItems(const std::string &key, std::map<std::string, std::vector<uint8_t>> &data)
412 {
413 if (!isOpened_) {
414 LOG_ERROR("FlatObjectStorageEngine::GetItems %{public}s not init", key.c_str());
415 return ERR_DB_NOT_INIT;
416 }
417 std::lock_guard<std::mutex> lock(operationMutex_);
418 if (delegates_.count(key) == 0) {
419 LOG_ERROR("FlatObjectStorageEngine::GetItems %{public}s not exist", key.c_str());
420 return ERR_DB_NOT_EXIST;
421 }
422 LOG_INFO("start Get %{public}s", key.c_str());
423 std::vector<DistributedDB::Entry> entries;
424 DistributedDB::DBStatus status = delegates_.at(key)->GetEntries(StringUtils::StrToBytes(""), entries);
425 if (status != DistributedDB::DBStatus::OK) {
426 LOG_ERROR("FlatObjectStorageEngine::GetItems item fail status = %{public}d", status);
427 return status;
428 }
429 for (auto &item : entries) {
430 data[StringUtils::BytesToStr(item.key)] = item.value;
431 }
432 LOG_INFO("end Get %{public}s", key.c_str());
433 return SUCCESS;
434 }
435
NotifyStatus(const std::string & sessionId,const std::string & deviceId,const std::string & status)436 void FlatObjectStorageEngine::NotifyStatus(const std::string &sessionId, const std::string &deviceId,
437 const std::string &status)
438 {
439 std::lock_guard<std::mutex> lock(watcherMutex_);
440 if (statusWatcher_ == nullptr) {
441 return;
442 }
443 statusWatcher_->OnChanged(sessionId, deviceId, status);
444 }
445
NotifyChange(const std::string & sessionId,const std::map<std::string,std::vector<uint8_t>> & changedData)446 void FlatObjectStorageEngine::NotifyChange(const std::string &sessionId,
447 const std::map<std::string, std::vector<uint8_t>> &changedData)
448 {
449 std::lock_guard<std::mutex> lock(operationMutex_);
450 if (observerMap_.count(sessionId) == 0) {
451 return;
452 }
453 std::vector<std::string> data {};
454 for (const auto &item : changedData) {
455 std::string key = item.first;
456 if (key.compare(0, FIELDS_PREFIX_LEN, FIELDS_PREFIX) == 0) {
457 key = key.substr(FIELDS_PREFIX_LEN);
458 }
459 data.push_back(key);
460 }
461 observerMap_[sessionId]->OnChanged(sessionId, data, false);
462 }
463
OnChange(const DistributedDB::KvStoreChangedData & data)464 void Watcher::OnChange(const DistributedDB::KvStoreChangedData &data)
465 {
466 std::vector<std::string> changedData;
467 std::string tmp;
468 for (DistributedDB::Entry item : data.GetEntriesInserted()) {
469 tmp = StringUtils::BytesToStr(item.key);
470 LOG_INFO("inserted %{public}s", tmp.c_str());
471 // property key start with p_, 2 is p_ size
472 if (tmp.compare(0, FIELDS_PREFIX_LEN, FIELDS_PREFIX) == 0) {
473 changedData.push_back(tmp.substr(FIELDS_PREFIX_LEN));
474 }
475 }
476 for (DistributedDB::Entry item : data.GetEntriesUpdated()) {
477 tmp = StringUtils::BytesToStr(item.key);
478 LOG_INFO("updated %{public}s", tmp.c_str());
479 // property key start with p_, 2 is p_ size
480 if (tmp.compare(0, FIELDS_PREFIX_LEN, FIELDS_PREFIX) == 0) {
481 changedData.push_back(tmp.substr(FIELDS_PREFIX_LEN));
482 }
483 }
484 this->OnChanged(sessionId_, changedData, true);
485 }
486
Watcher(const std::string & sessionId)487 Watcher::Watcher(const std::string &sessionId) : sessionId_(sessionId)
488 {
489 }
490 } // namespace OHOS::ObjectStore
491