mirror of
https://gitee.com/openharmony/distributeddatamgr_datamgr_service
synced 2024-11-22 22:40:22 +00:00
update
Signed-off-by: zuojiangjiang <zuojiangjiang@huawei.com>
This commit is contained in:
parent
7d39d0ac85
commit
79e93a868b
@ -37,13 +37,7 @@
|
||||
}
|
||||
],
|
||||
"distrusts": [],
|
||||
"switches": [
|
||||
{
|
||||
"bundleName": "distributed_device_profile_service",
|
||||
"appId": "distributed_device_profile_service",
|
||||
"checker": "SystemChecker"
|
||||
}
|
||||
]
|
||||
"switches": []
|
||||
},
|
||||
"networks": {
|
||||
"chains": [
|
||||
|
@ -44,9 +44,10 @@ Status CommunicatorContext::RegSessionListener(const DevChangeListener *observer
|
||||
ZLOGE("observer is nullptr");
|
||||
return Status::INVALID_ARGUMENT;
|
||||
}
|
||||
if (!observers_.Insert(observer, observer)) {
|
||||
ZLOGE("insert observer fail");
|
||||
return Status::ERROR;
|
||||
std::lock_guard<decltype(mutex_)> lock(mutex_);
|
||||
auto it = std::find(observers_.begin(), observers_.end(), observer);
|
||||
if (it == observers_.end()) {
|
||||
observers_.emplace_back(observer);
|
||||
}
|
||||
return Status::SUCCESS;
|
||||
}
|
||||
@ -63,9 +64,10 @@ Status CommunicatorContext::UnRegSessionListener(const DevChangeListener *observ
|
||||
ZLOGE("observer is nullptr");
|
||||
return Status::INVALID_ARGUMENT;
|
||||
}
|
||||
if (!observers_.Erase(observer)) {
|
||||
ZLOGE("erase observer fail");
|
||||
return Status::ERROR;
|
||||
std::lock_guard<decltype(mutex_)> lock(mutex_);
|
||||
auto it = std::find(observers_.begin(), observers_.end(), observer);
|
||||
if (it != observers_.end()) {
|
||||
observers_.erase(it);
|
||||
}
|
||||
return Status::SUCCESS;
|
||||
}
|
||||
@ -77,19 +79,17 @@ void CommunicatorContext::NotifySessionReady(const std::string &deviceId)
|
||||
return;
|
||||
}
|
||||
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;
|
||||
devInfo.uuid = deviceId;
|
||||
for (const auto &observer : observers) {
|
||||
if (observer != nullptr) {
|
||||
observer->OnSessionReady(devInfo);
|
||||
{
|
||||
std::lock_guard<decltype(mutex_)> lock(mutex_);
|
||||
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_);
|
||||
if (closeListener_) {
|
||||
|
@ -52,7 +52,8 @@ private:
|
||||
mutable std::mutex sessionMutex_;
|
||||
OnCloseAble closeListener_;
|
||||
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_ {};
|
||||
};
|
||||
} // namespace OHOS::DistributedData
|
||||
|
@ -150,7 +150,7 @@ void KvStoreMetaManager::InitDeviceOnline()
|
||||
EventCenter::GetInstance().PostEvent(std::move(finEvent));
|
||||
};
|
||||
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) {
|
||||
auto status = store->Sync({ deviceId }, DistributedDB::SyncMode::SYNC_MODE_PUSH_PULL, onComplete);
|
||||
if (status == OK) {
|
||||
|
@ -36,6 +36,7 @@ enum class CHANGE_FLAG {
|
||||
class KvStoreMetaManager {
|
||||
public:
|
||||
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)>;
|
||||
|
||||
class MetaDeviceChangeListenerImpl : public AppDistributedKv::AppDeviceChangeListener {
|
||||
|
Loading…
Reference in New Issue
Block a user