• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_INSPECTOR_INSPECTOR_H
17 #define ARKCOMPILER_TOOLCHAIN_INSPECTOR_INSPECTOR_H
18 
19 #include "ws_server.h"
20 
21 #include <string>
22 
23 namespace panda::ecmascript {
24 class EcmaVM;
25 }  // namespace panda::ecmascript
26 
27 namespace OHOS::ArkCompiler::Toolchain {
28 using EcmaVM = panda::ecmascript::EcmaVM;
29 using DebuggerPostTask = std::function<void(std::function<void()>&&)>;
30 
31 #if __cplusplus
32 extern "C" {
33 #endif
34 
35 bool StartDebug(const std::string& componentName, void* vm, bool isDebugMode, int32_t instanceId,
36     const DebuggerPostTask& debuggerPostTask);
37 
38 void StopDebug(const std::string& componentName);
39 
40 #if __cplusplus
41 }
42 #endif
43 
44 class Inspector {
45 public:
46     Inspector() = default;
47     ~Inspector() = default;
48 
49     void OnMessage(std::string&& msg);
50 
51     static constexpr int32_t DELAY_CHECK_DISPATCH_STATUS = 100;
52 
53     pthread_t tid_ = 0;
54     void* vm_ = nullptr;
55     std::unique_ptr<WsServer> websocketServer_;
56     DebuggerPostTask debuggerPostTask_;
57 };
58 } // namespace OHOS::ArkCompiler::Toolchain
59 
60 #endif // ARKCOMPILER_TOOLCHAIN_INSPECTOR_INSPECTOR_H