1e509ee18Sopenharmony_ci/* 2e509ee18Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3e509ee18Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e509ee18Sopenharmony_ci * you may not use this file except in compliance with the License. 5e509ee18Sopenharmony_ci * You may obtain a copy of the License at 6e509ee18Sopenharmony_ci * 7e509ee18Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e509ee18Sopenharmony_ci * 9e509ee18Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e509ee18Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e509ee18Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e509ee18Sopenharmony_ci * See the License for the specific language governing permissions and 13e509ee18Sopenharmony_ci * limitations under the License. 14e509ee18Sopenharmony_ci */ 15e509ee18Sopenharmony_ci 16e509ee18Sopenharmony_ci#ifndef ARKCOMPILER_TOOLCHAIN_INSPECTOR_INSPECTOR_H 17e509ee18Sopenharmony_ci#define ARKCOMPILER_TOOLCHAIN_INSPECTOR_INSPECTOR_H 18e509ee18Sopenharmony_ci 19e509ee18Sopenharmony_ci#include "inspector/ws_server.h" 20e509ee18Sopenharmony_ci 21e509ee18Sopenharmony_ci#include <string> 22e509ee18Sopenharmony_ci 23e509ee18Sopenharmony_cinamespace panda::ecmascript { 24e509ee18Sopenharmony_ciclass EcmaVM; 25e509ee18Sopenharmony_ci} // namespace panda::ecmascript 26e509ee18Sopenharmony_ci 27e509ee18Sopenharmony_cinamespace OHOS::ArkCompiler::Toolchain { 28e509ee18Sopenharmony_ciusing EcmaVM = panda::ecmascript::EcmaVM; 29e509ee18Sopenharmony_ciusing DebuggerPostTask = std::function<void(std::function<void()>&&)>; 30e509ee18Sopenharmony_ci 31e509ee18Sopenharmony_ci#if __cplusplus 32e509ee18Sopenharmony_ciextern "C" { 33e509ee18Sopenharmony_ci#endif 34e509ee18Sopenharmony_ci 35e509ee18Sopenharmony_cibool StartDebug(const std::string& componentName, void* vm, bool isDebugMode, 36e509ee18Sopenharmony_ci int32_t instanceId, const DebuggerPostTask& debuggerPostTask, int port); 37e509ee18Sopenharmony_ci 38e509ee18Sopenharmony_cibool StartDebugForSocketpair(int tid, int socketfd); 39e509ee18Sopenharmony_ci 40e509ee18Sopenharmony_cibool InitializeDebuggerForSocketpair(void* vm); 41e509ee18Sopenharmony_ci 42e509ee18Sopenharmony_civoid StopDebug(void* vm); 43e509ee18Sopenharmony_ci 44e509ee18Sopenharmony_civoid StopOldDebug(int tid, const std::string& componentName); 45e509ee18Sopenharmony_ci 46e509ee18Sopenharmony_civoid WaitForDebugger(void* vm); 47e509ee18Sopenharmony_ci 48e509ee18Sopenharmony_civoid StoreDebuggerInfo(int tid, void* vm, const DebuggerPostTask& debuggerPostTask); 49e509ee18Sopenharmony_ci 50e509ee18Sopenharmony_ci#if __cplusplus 51e509ee18Sopenharmony_ci} 52e509ee18Sopenharmony_ci#endif 53e509ee18Sopenharmony_ci 54e509ee18Sopenharmony_ciclass Inspector { 55e509ee18Sopenharmony_cipublic: 56e509ee18Sopenharmony_ci Inspector() = default; 57e509ee18Sopenharmony_ci ~Inspector() = default; 58e509ee18Sopenharmony_ci 59e509ee18Sopenharmony_ci void OnMessage(std::string&& msg); 60e509ee18Sopenharmony_ci#if defined(OHOS_PLATFORM) 61e509ee18Sopenharmony_ci uint64_t GetThreadOrTaskId(); 62e509ee18Sopenharmony_ci#endif // defined(OHOS_PLATFORM) 63e509ee18Sopenharmony_ci 64e509ee18Sopenharmony_ci static constexpr int32_t DELAY_CHECK_DISPATCH_STATUS = 100; 65e509ee18Sopenharmony_ci 66e509ee18Sopenharmony_ci pthread_t tid_ = 0; 67e509ee18Sopenharmony_ci int tidForSocketPair_ = 0; 68e509ee18Sopenharmony_ci void* vm_ = nullptr; 69e509ee18Sopenharmony_ci std::unique_ptr<WsServer> websocketServer_; 70e509ee18Sopenharmony_ci DebuggerPostTask debuggerPostTask_; 71e509ee18Sopenharmony_ci}; 72e509ee18Sopenharmony_ci} // namespace OHOS::ArkCompiler::Toolchain 73e509ee18Sopenharmony_ci 74e509ee18Sopenharmony_ci#endif // ARKCOMPILER_TOOLCHAIN_INSPECTOR_INSPECTOR_H