1 /* 2 * Copyright (c) 2023-2024 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 bool 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 void SetRecordCallback(const std::function<void(void)> &startRecordFunc, 63 const std::function<void(void)> &stopRecordFunc); 64 65 #ifdef __cplusplus 66 #if __cplusplus 67 } 68 #endif 69 #endif /* End of #ifdef __cplusplus */ 70 71 struct LayoutInspectorInfo { 72 std::string tree; 73 std::string snapShot; 74 }; 75 76 class ConnectInspector { 77 public: 78 ConnectInspector() = default; 79 ~ConnectInspector() = default; 80 81 std::string componentName_; 82 std::unordered_map<int32_t, std::string> infoBuffer_; 83 LayoutInspectorInfo layoutInspectorInfo_; 84 std::unique_ptr<ConnectServer> connectServer_; 85 std::atomic<bool> waitingForDebugger_ = true; 86 std::queue<std::string> ideMsgQueue_; 87 std::function<void(bool)> setSwitchStatus_; 88 std::function<void(bool)> setArkUIStateProfilerStatus_; 89 std::function<void(int32_t)> createLayoutInfo_; 90 std::function<void()> setDebugMode_; 91 int32_t instanceId_ = -1; 92 std::function<void(void)> startRecord_; 93 std::function<void(void)> stopRecord_; 94 bool isRecording_ = false; 95 }; 96 } // namespace OHOS::ArkCompiler::Toolchain 97 98 #endif // ARKCOMPILER_TOOLCHAIN_CONNECT_SERVER_CONNECT_INSPECTOR_H 99