mirror of
https://gitee.com/openharmony/distributeddatamgr_datamgr_service
synced 2024-11-27 00:51:12 +00:00
update
Signed-off-by: zuojiangjiang <zuojiangjiang@huawei.com>
This commit is contained in:
parent
7d39d0ac85
commit
79e93a868b
@ -37,13 +37,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"distrusts": [],
|
"distrusts": [],
|
||||||
"switches": [
|
"switches": []
|
||||||
{
|
|
||||||
"bundleName": "distributed_device_profile_service",
|
|
||||||
"appId": "distributed_device_profile_service",
|
|
||||||
"checker": "SystemChecker"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"networks": {
|
"networks": {
|
||||||
"chains": [
|
"chains": [
|
||||||
|
@ -44,9 +44,10 @@ Status CommunicatorContext::RegSessionListener(const DevChangeListener *observer
|
|||||||
ZLOGE("observer is nullptr");
|
ZLOGE("observer is nullptr");
|
||||||
return Status::INVALID_ARGUMENT;
|
return Status::INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
if (!observers_.Insert(observer, observer)) {
|
std::lock_guard<decltype(mutex_)> lock(mutex_);
|
||||||
ZLOGE("insert observer fail");
|
auto it = std::find(observers_.begin(), observers_.end(), observer);
|
||||||
return Status::ERROR;
|
if (it == observers_.end()) {
|
||||||
|
observers_.emplace_back(observer);
|
||||||
}
|
}
|
||||||
return Status::SUCCESS;
|
return Status::SUCCESS;
|
||||||
}
|
}
|
||||||
@ -63,9 +64,10 @@ Status CommunicatorContext::UnRegSessionListener(const DevChangeListener *observ
|
|||||||
ZLOGE("observer is nullptr");
|
ZLOGE("observer is nullptr");
|
||||||
return Status::INVALID_ARGUMENT;
|
return Status::INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
if (!observers_.Erase(observer)) {
|
std::lock_guard<decltype(mutex_)> lock(mutex_);
|
||||||
ZLOGE("erase observer fail");
|
auto it = std::find(observers_.begin(), observers_.end(), observer);
|
||||||
return Status::ERROR;
|
if (it != observers_.end()) {
|
||||||
|
observers_.erase(it);
|
||||||
}
|
}
|
||||||
return Status::SUCCESS;
|
return Status::SUCCESS;
|
||||||
}
|
}
|
||||||
@ -77,19 +79,17 @@ void CommunicatorContext::NotifySessionReady(const std::string &deviceId)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
devices_.Insert(deviceId, deviceId);
|
devices_.Insert(deviceId, deviceId);
|
||||||
std::vector<const DevChangeListener *> observers;
|
|
||||||
observers_.ForEach([&observers](const auto &key, auto &value) {
|
|
||||||
observers.emplace_back(value);
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
ZLOGI("Notify session begin, deviceId:%{public}s, observer count:%{public}zu",
|
|
||||||
KvUtils::ToBeAnonymous(deviceId).c_str(), observers.size());
|
|
||||||
DeviceInfo devInfo;
|
DeviceInfo devInfo;
|
||||||
devInfo.uuid = deviceId;
|
devInfo.uuid = deviceId;
|
||||||
for (const auto &observer : observers) {
|
{
|
||||||
if (observer != nullptr) {
|
std::lock_guard<decltype(mutex_)> lock(mutex_);
|
||||||
observer->OnSessionReady(devInfo);
|
for (const auto &observer : observers_) {
|
||||||
|
if (observer != nullptr) {
|
||||||
|
observer->OnSessionReady(devInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
ZLOGI("Notify session begin, deviceId:%{public}s, observer count:%{public}zu",
|
||||||
|
KvUtils::ToBeAnonymous(deviceId).c_str(), observers_.size());
|
||||||
}
|
}
|
||||||
std::lock_guard<decltype(sessionMutex_)> sessionLockGard(sessionMutex_);
|
std::lock_guard<decltype(sessionMutex_)> sessionLockGard(sessionMutex_);
|
||||||
if (closeListener_) {
|
if (closeListener_) {
|
||||||
|
@ -52,7 +52,8 @@ private:
|
|||||||
mutable std::mutex sessionMutex_;
|
mutable std::mutex sessionMutex_;
|
||||||
OnCloseAble closeListener_;
|
OnCloseAble closeListener_;
|
||||||
std::shared_ptr<ExecutorPool> executors_;
|
std::shared_ptr<ExecutorPool> executors_;
|
||||||
ConcurrentMap<const DevChangeListener *, const DevChangeListener *> observers_ {};
|
std::mutex mutex_;
|
||||||
|
std::vector<const DevChangeListener *> observers_;
|
||||||
ConcurrentMap<const std::string, const std::string> devices_ {};
|
ConcurrentMap<const std::string, const std::string> devices_ {};
|
||||||
};
|
};
|
||||||
} // namespace OHOS::DistributedData
|
} // namespace OHOS::DistributedData
|
||||||
|
@ -150,7 +150,7 @@ void KvStoreMetaManager::InitDeviceOnline()
|
|||||||
EventCenter::GetInstance().PostEvent(std::move(finEvent));
|
EventCenter::GetInstance().PostEvent(std::move(finEvent));
|
||||||
};
|
};
|
||||||
auto store = GetMetaKvStore();
|
auto store = GetMetaKvStore();
|
||||||
uint16_t mask = data.dynamic & 0x000F;
|
uint16_t mask = data.dynamic & DEFAULT_MASK;
|
||||||
if (((mask & DeviceMatrix::META_STORE_MASK) != 0) && store != nullptr) {
|
if (((mask & DeviceMatrix::META_STORE_MASK) != 0) && store != nullptr) {
|
||||||
auto status = store->Sync({ deviceId }, DistributedDB::SyncMode::SYNC_MODE_PUSH_PULL, onComplete);
|
auto status = store->Sync({ deviceId }, DistributedDB::SyncMode::SYNC_MODE_PUSH_PULL, onComplete);
|
||||||
if (status == OK) {
|
if (status == OK) {
|
||||||
|
@ -36,6 +36,7 @@ enum class CHANGE_FLAG {
|
|||||||
class KvStoreMetaManager {
|
class KvStoreMetaManager {
|
||||||
public:
|
public:
|
||||||
static constexpr uint32_t META_STORE_VERSION = 0x03000001;
|
static constexpr uint32_t META_STORE_VERSION = 0x03000001;
|
||||||
|
static constexpr uint16_t DEFAULT_MASK = 0x000F;
|
||||||
using ChangeObserver = std::function<void(const std::vector<uint8_t> &, const std::vector<uint8_t> &, CHANGE_FLAG)>;
|
using ChangeObserver = std::function<void(const std::vector<uint8_t> &, const std::vector<uint8_t> &, CHANGE_FLAG)>;
|
||||||
|
|
||||||
class MetaDeviceChangeListenerImpl : public AppDistributedKv::AppDeviceChangeListener {
|
class MetaDeviceChangeListenerImpl : public AppDistributedKv::AppDeviceChangeListener {
|
||||||
|
Loading…
Reference in New Issue
Block a user