1 /* 2 * Copyright (c) 2023 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 16 #ifndef ARKCOMPILER_TOOLCHAIN_CONNECT_SERVER_CONNECT_INSPECTOR_H 17 #define ARKCOMPILER_TOOLCHAIN_CONNECT_SERVER_CONNECT_INSPECTOR_H 18 19 #include <queue> 20 #include <string> 21 #include <unordered_map> 22 #include "connect_server.h" 23 24 namespace OHOS::ArkCompiler::Toolchain { 25 #ifdef __cplusplus 26 #if __cplusplus 27 extern "C" { 28 #endif 29 #endif /* End of #ifdef __cplusplus */ 30 31 // old process. 32 void StartServer(const std::string& componentName); 33 34 // socketpair process. 35 void StartServerForSocketPair(int socketfd); 36 37 void StopServer([[maybe_unused]] const std::string& componentName); 38 39 void SendMessage(const std::string& message); 40 41 void StoreMessage(int32_t instanceId, const std::string& message); 42 43 void SendLayoutMessage(const std::string& message); 44 45 void SendProfilerMessage(const std::string &message); 46 47 void SetConnectCallback(const std::function<void(bool)>& callback); 48 49 void StoreInspectorInfo(const std::string& jsonTreeStr, const std::string& jsonSnapshotStr); 50 51 void RemoveMessage(int32_t instanceId); 52 53 bool WaitForConnection(); 54 55 void SetDebugModeCallBack(const std::function<void()>& setDebugMode); 56 57 void SetSwitchCallBack(const std::function<void(bool)>& setSwitchStatus, 58 const std::function<void(int32_t)>& createLayoutInfo, int32_t instanceId); 59 60 void SetProfilerCallback(const std::function<void(bool)> &setArkUIStateProfilerStatus); 61 62 #ifdef __cplusplus 63 #if __cplusplus 64 } 65 #endif 66 #endif /* End of #ifdef __cplusplus */ 67 68 struct LayoutInspectorInfo { 69 std::string tree; 70 std::string snapShot; 71 }; 72 73 class ConnectInspector { 74 public: 75 ConnectInspector() = default; 76 ~ConnectInspector() = default; 77 78 std::string componentName_; 79 std::unordered_map<int32_t, std::string> infoBuffer_; 80 LayoutInspectorInfo layoutInspectorInfo_; 81 std::unique_ptr<ConnectServer> connectServer_; 82 std::atomic<bool> waitingForDebugger_ = true; 83 std::queue<std::string> ideMsgQueue_; 84 std::function<void(bool)> setSwitchStatus_; 85 std::function<void(bool)> setArkUIStateProfilerStatus_; 86 std::function<void(int32_t)> createLayoutInfo_; 87 std::function<void()> setDebugMode_; 88 int32_t instanceId_ = -1; 89 }; 90 } // namespace OHOS::ArkCompiler::Toolchain 91 92 #endif // ARKCOMPILER_TOOLCHAIN_CONNECT_SERVER_CONNECT_INSPECTOR_H 93