代码拉取完成,页面将自动刷新
diff --git a/frameworks/libs/distributeddb/communicator/include/communicator_aggregator.h b/frameworks/libs/distributeddb/communicator/include/communicator_aggregator.h
index 6034cb15e..97c03a01d 100644
--- a/frameworks/libs/distributeddb/communicator/include/communicator_aggregator.h
+++ b/frameworks/libs/distributeddb/communicator/include/communicator_aggregator.h
@@ -93,6 +93,8 @@ public:
std::shared_ptr<ExtendHeaderHandle> GetExtendHeaderHandle(const ExtendInfo ¶mInfo);
void ClearOnlineLabel() override;
+
+ std::string GetTargetUserId(const ExtendInfo ¶mInfo) const;
private:
// Working in a dedicated thread
void SendDataRoutine();
diff --git a/frameworks/libs/distributeddb/communicator/include/iadapter.h b/frameworks/libs/distributeddb/communicator/include/iadapter.h
index d9273d829..6ef353e39 100644
--- a/frameworks/libs/distributeddb/communicator/include/iadapter.h
+++ b/frameworks/libs/distributeddb/communicator/include/iadapter.h
@@ -78,6 +78,8 @@ public:
virtual std::shared_ptr<ExtendHeaderHandle> GetExtendHeaderHandle(const ExtendInfo ¶mInfo) = 0;
+ virtual std::string GetTargetUserId(const ExtendInfo ¶mInfo) = 0;
+
virtual ~IAdapter() {};
};
} // namespace DistributedDB
diff --git a/frameworks/libs/distributeddb/communicator/include/icommunicator.h b/frameworks/libs/distributeddb/communicator/include/icommunicator.h
index 4b73ab326..fa3eed8c6 100644
--- a/frameworks/libs/distributeddb/communicator/include/icommunicator.h
+++ b/frameworks/libs/distributeddb/communicator/include/icommunicator.h
@@ -84,6 +84,8 @@ public:
virtual int SendMessage(const std::string &dstTarget, const Message *inMsg, const SendConfig &config,
const OnSendEnd &onEnd) = 0; // HW Code Regulation do not allow to use default parameters on virtual function
+ virtual std::string GetTargetUserId(const ExtendInfo ¶mInfo) const = 0;
+
virtual ~ICommunicator() {};
};
} // namespace DistributedDB
diff --git a/frameworks/libs/distributeddb/communicator/include/network_adapter.h b/frameworks/libs/distributeddb/communicator/include/network_adapter.h
index 06ebd559b..4885972b9 100644
--- a/frameworks/libs/distributeddb/communicator/include/network_adapter.h
+++ b/frameworks/libs/distributeddb/communicator/include/network_adapter.h
@@ -54,6 +54,7 @@ public:
bool IsDeviceOnline(const std::string &device) override;
std::shared_ptr<ExtendHeaderHandle> GetExtendHeaderHandle(const ExtendInfo ¶mInfo) override;
+ std::string GetTargetUserId(const ExtendInfo ¶mInfo) override;
private:
void OnDataReceiveHandler(const DeviceInfos &srcDevInfo, const uint8_t *data, uint32_t length);
void OnDeviceChangeHandler(const DeviceInfos &devInfo, bool isOnline);
diff --git a/frameworks/libs/distributeddb/communicator/src/communicator.cpp b/frameworks/libs/distributeddb/communicator/src/communicator.cpp
index 608adaf91..c54584e8c 100644
--- a/frameworks/libs/distributeddb/communicator/src/communicator.cpp
+++ b/frameworks/libs/distributeddb/communicator/src/communicator.cpp
@@ -269,5 +269,10 @@ void Communicator::TriggerUnknownMessageFeedback(const std::string &dstTarget, M
}
}
+std::string Communicator::GetTargetUserId(const ExtendInfo ¶mInfo) const
+{
+ return commAggrHandle_->GetTargetUserId(paramInfo);
+}
+
DEFINE_OBJECT_TAG_FACILITIES(Communicator)
} // namespace DistributedDB
diff --git a/frameworks/libs/distributeddb/communicator/src/communicator.h b/frameworks/libs/distributeddb/communicator/src/communicator.h
index 976ce0ae9..41ede2362 100644
--- a/frameworks/libs/distributeddb/communicator/src/communicator.h
+++ b/frameworks/libs/distributeddb/communicator/src/communicator.h
@@ -67,6 +67,7 @@ public:
// Call by CommunicatorAggregator directly
LabelType GetCommunicatorLabel() const;
+ std::string GetTargetUserId(const ExtendInfo ¶mInfo) const override;
private:
void TriggerVersionNegotiation(const std::string &dstTarget);
void TriggerUnknownMessageFeedback(const std::string &dstTarget, Message* &oriMsg);
diff --git a/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp b/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp
index ea724de99..d3383977c 100644
--- a/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp
+++ b/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp
@@ -1170,5 +1170,10 @@ void CommunicatorAggregator::ClearOnlineLabel()
}
commLinker_->ClearOnlineLabel();
}
+
+std::string CommunicatorAggregator::GetTargetUserId(const ExtendInfo ¶mInfo) const
+{
+ return adapterHandle_->GetTargetUserId(paramInfo);
+}
DEFINE_OBJECT_TAG_FACILITIES(CommunicatorAggregator)
} // namespace DistributedDB
diff --git a/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp b/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp
index d3071c96f..053c0f87d 100644
--- a/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp
+++ b/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp
@@ -436,4 +436,9 @@ std::shared_ptr<ExtendHeaderHandle> NetworkAdapter::GetExtendHeaderHandle(const
{
return processCommunicator_->GetExtendHeaderHandle(paramInfo);
}
+
+std::string NetworkAdapter::GetTargetUserId(const ExtendInfo ¶mInfo)
+{
+ return processCommunicator_->GetTargetUserId(paramInfo);
+}
} // namespace DistributedDB
diff --git a/frameworks/libs/distributeddb/interfaces/include/iprocess_communicator.h b/frameworks/libs/distributeddb/interfaces/include/iprocess_communicator.h
index 0fdb757aa..2683c1853 100644
--- a/frameworks/libs/distributeddb/interfaces/include/iprocess_communicator.h
+++ b/frameworks/libs/distributeddb/interfaces/include/iprocess_communicator.h
@@ -184,6 +184,11 @@ public:
virtual void RegOnSendAble([[gnu::unused]] const OnSendAble &sendAbleCallback)
{
}
+
+ virtual std::string GetTargetUserId(const ExtendInfo ¶mInfo)
+ {
+ return "";
+ }
};
} // namespace DistributedDB
diff --git a/frameworks/libs/distributeddb/syncer/src/device/communicator_proxy.cpp b/frameworks/libs/distributeddb/syncer/src/device/communicator_proxy.cpp
index 15327f254..847d17ee2 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/communicator_proxy.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/communicator_proxy.cpp
@@ -272,4 +272,27 @@ void CommunicatorProxy::Dump(int fd)
DBDumpHelper::Dump(fd, "\t\ttarget = %s, label = %s\n", target.c_str(), label.c_str());
}
}
+
+std::string CommunicatorProxy::GetTargetUserId(const ExtendInfo ¶mInfo) const
+{
+ ICommunicator *targetCommunicator = nullptr;
+ {
+ std::lock_guard<std::mutex> lock(devCommMapLock_);
+ if (devCommMap_.count(paramInfo.dstTarget) != 0) {
+ targetCommunicator = devCommMap_.at(paramInfo.dstTarget).second;
+ RefObject::IncObjRef(targetCommunicator);
+ }
+ }
+ if (targetCommunicator != nullptr) {
+ std::string targetUserId = targetCommunicator->GetTargetUserId(paramInfo);
+ RefObject::DecObjRef(targetCommunicator);
+ return targetUserId;
+ }
+
+ if (mainComm_ != nullptr) {
+ return mainComm_->GetTargetUserId(paramInfo);
+ }
+
+ return "";
+}
} // namespace DistributedDB
\ No newline at end of file
diff --git a/frameworks/libs/distributeddb/syncer/src/device/communicator_proxy.h b/frameworks/libs/distributeddb/syncer/src/device/communicator_proxy.h
index fafd852f7..9049a37b0 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/communicator_proxy.h
+++ b/frameworks/libs/distributeddb/syncer/src/device/communicator_proxy.h
@@ -55,6 +55,8 @@ public:
void Dump(int fd);
+ std::string GetTargetUserId(const ExtendInfo ¶mInfo) const override;
+
private:
ICommunicator *mainComm_;
mutable std::mutex devCommMapLock_;
diff --git a/frameworks/libs/distributeddb/syncer/src/device/isync_task_context.h b/frameworks/libs/distributeddb/syncer/src/device/isync_task_context.h
index 91ed88936..62a84de9c 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/isync_task_context.h
+++ b/frameworks/libs/distributeddb/syncer/src/device/isync_task_context.h
@@ -76,6 +76,10 @@ public:
// Get the current task deviceId.
virtual std::string GetDeviceId() const = 0;
+ virtual std::string GetTargetUserId() const = 0;
+
+ virtual void SetTargetUserId(const std::string &userId) = 0;
+
virtual void SetTaskExecStatus(int status) = 0;
virtual int GetTaskExecStatus() const = 0;
diff --git a/frameworks/libs/distributeddb/syncer/src/device/sync_engine.cpp b/frameworks/libs/distributeddb/syncer/src/device/sync_engine.cpp
index 5d4a60e55..5ceab2622 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/sync_engine.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/sync_engine.cpp
@@ -665,6 +665,7 @@ int SyncEngine::ExecSyncTask(ISyncTaskContext *context)
return -E_OBJ_IS_KILLED;
}
auto timeout = GetTimeout(context->GetDeviceId());
+ context->SetTargetUserId(GetTargetUserId(context->GetDeviceId()));
AutoLock lockGuard(context);
int status = context->GetTaskExecStatus();
if ((status == SyncTaskContext::RUNNING) || context->IsKilled()) {
@@ -1376,4 +1377,29 @@ uint32_t SyncEngine::GetTimeout(const std::string &dev)
RefObject::DecObjRef(communicator);
return timeout;
}
+
+std::string SyncEngine::GetTargetUserId(const std::string &dev)
+{
+ std::string targetUserId;
+ ICommunicator *communicator = nullptr;
+ {
+ std::lock_guard<std::mutex> autoLock(communicatorProxyLock_);
+ if (communicatorProxy_ == nullptr) {
+ LOGW("[SyncEngine] Communicator is null when get target user");
+ return targetUserId;
+ }
+ communicator = communicatorProxy_;
+ RefObject::IncObjRef(communicator);
+ }
+ DBProperties properties = syncInterface_->GetDbProperties();
+ ExtendInfo extendInfo;
+ extendInfo.appId = properties.GetStringProp(DBProperties::APP_ID, "");
+ extendInfo.userId = properties.GetStringProp(DBProperties::USER_ID, "");
+ extendInfo.storeId = properties.GetStringProp(DBProperties::STORE_ID, "");
+ extendInfo.dstTarget = dev;
+ extendInfo.subUserId = properties.GetStringProp(DBProperties::SUB_USER, "");
+ targetUserId = communicator->GetTargetUserId(extendInfo);
+ RefObject::DecObjRef(communicator);
+ return targetUserId;
+}
} // namespace DistributedDB
diff --git a/frameworks/libs/distributeddb/syncer/src/device/sync_engine.h b/frameworks/libs/distributeddb/syncer/src/device/sync_engine.h
index 78c931922..f81b7a474 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/sync_engine.h
+++ b/frameworks/libs/distributeddb/syncer/src/device/sync_engine.h
@@ -237,6 +237,7 @@ private:
uint32_t GetTimeout(const std::string &dev);
+ std::string GetTargetUserId(const std::string &dev);
ICommunicator *communicator_;
DeviceManager *deviceManager_;
std::function<void(const std::string &)> onRemoteDataChanged_;
diff --git a/frameworks/libs/distributeddb/syncer/src/device/sync_task_context.cpp b/frameworks/libs/distributeddb/syncer/src/device/sync_task_context.cpp
index 4fd93de50..63fb64aa5 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/sync_task_context.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/sync_task_context.cpp
@@ -285,6 +285,16 @@ std::string SyncTaskContext::GetDeviceId() const
return deviceId_;
}
+std::string SyncTaskContext::GetTargetUserId() const
+{
+ return targetUserId_;
+}
+
+void SyncTaskContext::SetTargetUserId(const std::string &userId)
+{
+ targetUserId_ = userId;
+}
+
void SyncTaskContext::SetTaskExecStatus(int status)
{
taskExecStatus_ = status;
diff --git a/frameworks/libs/distributeddb/syncer/src/device/sync_task_context.h b/frameworks/libs/distributeddb/syncer/src/device/sync_task_context.h
index 42d53e7dc..7885b91fe 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/sync_task_context.h
+++ b/frameworks/libs/distributeddb/syncer/src/device/sync_task_context.h
@@ -78,6 +78,10 @@ public:
// Get the current task deviceId.
std::string GetDeviceId() const override;
+ std::string GetTargetUserId() const override;
+
+ void SetTargetUserId(const std::string &userId) override;
+
// Set the sync task queue exec status
void SetTaskExecStatus(int status) override;
@@ -260,6 +264,7 @@ protected:
volatile int status_;
volatile int taskExecStatus_;
std::string deviceId_;
+ std::string targetUserId_;
std::string syncActionName_;
ISyncInterface *syncInterface_;
ICommunicator *communicator_;
diff --git a/frameworks/libs/distributeddb/test/unittest/common/communicator/adapter_stub.cpp b/frameworks/libs/distributeddb/test/unittest/common/communicator/adapter_stub.cpp
index 0d2f5c9d2..324774d42 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/communicator/adapter_stub.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/communicator/adapter_stub.cpp
@@ -449,4 +449,10 @@ void AdapterStub::ApplySendBitError(const uint8_t *bytes, uint32_t length)
phyHeader->checkSum = HostToNet(CalculateXorSum(bytes + LENGTH_BEFORE_SUM_RANGE,
length - LENGTH_BEFORE_SUM_RANGE));
}
+}
+
+std::string AdapterStub::GetTargetUserId(const ExtendInfo ¶mInfo)
+{
+ (void)paramInfo;
+ return targetUserId_;
}
\ No newline at end of file
diff --git a/frameworks/libs/distributeddb/test/unittest/common/communicator/adapter_stub.h b/frameworks/libs/distributeddb/test/unittest/common/communicator/adapter_stub.h
index 13c8396f3..b8d37935b 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/communicator/adapter_stub.h
+++ b/frameworks/libs/distributeddb/test/unittest/common/communicator/adapter_stub.h
@@ -85,6 +85,8 @@ public:
void SimulateSendBitErrorInPaddingLenField(bool doFlag, uint8_t inPaddingLen);
void SimulateSendBitErrorInMessageIdField(bool doFlag, uint32_t inMessageId);
void ForkSendBytes(const OnSendBytes &onSendBytes);
+
+ std::string GetTargetUserId(const ExtendInfo ¶mInfo) override;
private:
void Connect(AdapterStub *inStub);
void Disconnect(AdapterStub *inStub);
@@ -137,6 +139,8 @@ private:
std::mutex sendBytesMutex_;
OnSendBytes onSendBytes_;
+
+ std::string targetUserId_;
};
}
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/mock_communicator.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/mock_communicator.h
index d0340cf87..8befecd23 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/mock_communicator.h
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/mock_communicator.h
@@ -35,6 +35,7 @@ public:
MOCK_METHOD2(RegOnMessageCallback, int(const OnMessageCallback &, const Finalizer &));
MOCK_METHOD1(Activate, void(const std::string &));
MOCK_CONST_METHOD1(IsDeviceOnline, bool(const std::string &));
+ MOCK_CONST_METHOD1(GetTargetUserId, std::string(const ExtendInfo &));
};
} // namespace DistributedDB
#endif // #define MOCK_COMMUNICATOR_H
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator.cpp
index 9d6df07de..b5d11e85f 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator.cpp
@@ -236,4 +236,14 @@ void VirtualCommunicator::SetDropMessageTypeByDevice(MessageId msgid, uint32_t d
dropMsgTimes_ = 0;
}
}
+
+std::string VirtualCommunicator::GetTargetUserId(const ExtendInfo ¶mInfo) const
+{
+ return targetUserId_;
+}
+
+void VirtualCommunicator::SetTargetUserId(const std::string &userId)
+{
+ targetUserId_ = userId;
+}
} // namespace DistributedDB
\ No newline at end of file
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator.h
index f904df098..9c7778ca1 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator.h
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator.h
@@ -83,6 +83,9 @@ public:
void SetRemoteVersion(uint16_t remoteVersion);
+ std::string GetTargetUserId(const ExtendInfo ¶mInfo) const override;
+
+ void SetTargetUserId(const std::string &userId);
private:
int TimeSync();
int DataSync();
@@ -112,6 +115,8 @@ private:
uint32_t mtuSize_ = 5 * 1024 * 1024; // 5 * 1024 * 1024B
uint16_t remoteVersion_ = UINT16_MAX;
+
+ std::string targetUserId_;
};
} // namespace DistributedDB
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_time_sync_communicator.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_time_sync_communicator.cpp
index 6890e94b4..a3a302aed 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_time_sync_communicator.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_time_sync_communicator.cpp
@@ -151,4 +151,9 @@ void VirtualTimeSyncCommunicator::SetRemoteVersion(uint16_t remoteVersion)
{
version_ = remoteVersion;
}
+
+std::string VirtualTimeSyncCommunicator::GetTargetUserId(const ExtendInfo ¶mInfo) const
+{
+ return "";
+}
} // namespace DistributedDB
\ No newline at end of file
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_time_sync_communicator.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_time_sync_communicator.h
index 0478c24c0..c068e1f48 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_time_sync_communicator.h
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_time_sync_communicator.h
@@ -72,6 +72,8 @@ public:
void SetRemoteVersion(uint16_t remoteVersion);
+ std::string GetTargetUserId(const ExtendInfo ¶mInfo) const override;
+
private:
TimeSync *srcTimeSync_;
TimeSync *dstTimeSync_;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。