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 SetConnectCallback(const std::function<void(bool)>& callback); 46 47 void StoreInspectorInfo(const std::string& jsonTreeStr, const std::string& jsonSnapshotStr); 48 49 void RemoveMessage(int32_t instanceId); 50 51 bool WaitForConnection(); 52 53 void SetDebugModeCallBack(const std::function<void()>& setDebugMode); 54 55 void SetSwitchCallBack(const std::function<void(bool)>& setSwitchStatus, 56 const std::function<void(int32_t)>& createLayoutInfo, int32_t instanceId); 57 58 #ifdef __cplusplus 59 #if __cplusplus 60 } 61 #endif 62 #endif /* End of #ifdef __cplusplus */ 63 64 struct LayoutInspectorInfo { 65 std::string tree; 66 std::string snapShot; 67 }; 68 69 class ConnectInspector { 70 public: 71 ConnectInspector() = default; 72 ~ConnectInspector() = default; 73 74 std::string componentName_; 75 std::unordered_map<int32_t, std::string> infoBuffer_; 76 LayoutInspectorInfo layoutInspectorInfo_; 77 std::unique_ptr<ConnectServer> connectServer_; 78 std::atomic<bool> waitingForDebugger_ = true; 79 std::queue<std::string> ideMsgQueue_; 80 std::function<void(bool)> setSwitchStatus_; 81 std::function<void(int32_t)> createLayoutInfo_; 82 std::function<void()> setDebugMode_; 83 int32_t instanceId_ = -1; 84 }; 85 } // namespace OHOS::ArkCompiler::Toolchain 86 87 #endif // ARKCOMPILER_TOOLCHAIN_CONNECT_SERVER_CONNECT_INSPECTOR_H 88