diff --git a/frameworks/native/runtime/connect_server_manager.cpp b/frameworks/native/runtime/connect_server_manager.cpp index 0da18ec997..3ba5fe46b6 100644 --- a/frameworks/native/runtime/connect_server_manager.cpp +++ b/frameworks/native/runtime/connect_server_manager.cpp @@ -42,6 +42,8 @@ using StartServer = void (*)(const std::string&); using SendMessage = void (*)(const std::string&); using StopServer = void (*)(const std::string&); using StoreMessage = void (*)(int32_t, const std::string&); +using StoreInspectorInfo = void (*)(const std::string&, const std::string&); +using SetSwitchCallBack = void (*)(const std::function& setSwitchStatus); using RemoveMessage = void (*)(int32_t); using WaitForDebugger = bool (*)(); @@ -113,6 +115,14 @@ bool ConnectServerManager::AddInstance(int32_t instanceId, const std::string& in } } + auto setSwitchCallBack = reinterpret_cast( + dlsym(handlerConnectServerSo_, "SetSwitchCallBack")); + if (setSwitchCallBack == nullptr) { + HILOG_ERROR("ConnectServerManager::AddInstance failed to find symbol 'setSwitchCallBack'"); + return false; + } + setSwitchCallBack(std::bind(&ConnectServerManager::SetLayoutInspectorStatus, this, std::placeholders::_1)); + // Get the message including information of new instance, which will be send to IDE. std::string message = GetInstanceMapMessage("addInstance", instanceId, instanceName); @@ -186,4 +196,24 @@ void ConnectServerManager::RemoveInstance(int32_t instanceId) } sendMessage(message); } + +void ConnectServerManager::SendInspector(const std::string& jsonTreeStr, const std::string& jsonSnapshotStr) +{ + auto sendMessage = reinterpret_cast(dlsym(handlerConnectServerSo_, "SendMessage")); + if (sendMessage == nullptr) { + HILOG_ERROR("ConnectServerManager::AddInstance failed to find symbol 'SendMessage'"); + return; + } + + sendMessage(jsonTreeStr); + sendMessage(jsonSnapshotStr); + auto storeInspectorInfo = reinterpret_cast( + dlsym(handlerConnectServerSo_, "StoreInspectorInfo")); + if (storeInspectorInfo == nullptr) { + HILOG_ERROR("ConnectServerManager::AddInstance failed to find symbol 'StoreInspectorInfo'"); + return; + } + storeInspectorInfo(jsonTreeStr, jsonSnapshotStr); +} + } // namespace OHOS::AbilityRuntime \ No newline at end of file diff --git a/frameworks/native/runtime/connect_server_manager.h b/frameworks/native/runtime/connect_server_manager.h index 4f4c2e6802..f5759068f4 100644 --- a/frameworks/native/runtime/connect_server_manager.h +++ b/frameworks/native/runtime/connect_server_manager.h @@ -26,9 +26,17 @@ public: void StartConnectServer(const std::string& bundleName); void StopConnectServer(); - + void SetLayoutInspectorStatus(bool status) + { + layoutInspectorStatus_ = status; + } + bool GetlayoutInspectorStatus() const + { + return layoutInspectorStatus_; + } bool AddInstance(int32_t instanceId, const std::string& instanceName = "PandaDebugger"); void RemoveInstance(int32_t instanceId); + void SendInspector(const std::string& jsonTreeStr, const std::string& jsonSnapshotStr); private: ConnectServerManager() = default; @@ -39,7 +47,7 @@ private: std::mutex mutex_; std::unordered_map instanceMap_; - + bool layoutInspectorStatus_ = false; ConnectServerManager(const ConnectServerManager&) = delete; ConnectServerManager(ConnectServerManager&&) = delete; ConnectServerManager& operator=(const ConnectServerManager&) = delete;