• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 void StartServer(const std::string& componentName);
32 
33 void StopServer([[maybe_unused]] const std::string& componentName);
34 
35 void SendMessage(const std::string& message);
36 
37 void StoreMessage(int32_t instanceId, const std::string& message);
38 
39 void SendLayoutMessage(const std::string& message);
40 
41 void StoreInspectorInfo(const std::string& jsonTreeStr,  const std::string& jsonSnapshotStr);
42 
43 void RemoveMessage(int32_t instanceId);
44 
45 bool WaitForConnection();
46 
47 void SetSwitchCallBack(const std::function<void(bool)>& setSwitchStatus,
48     const std::function<void(int32_t)>& createLayoutInfo, int32_t instanceId);
49 
50 #ifdef __cplusplus
51 #if __cplusplus
52 }
53 #endif
54 #endif /* End of #ifdef __cplusplus */
55 
56 struct LayoutInspectorInfo {
57     std::string tree;
58     std::string snapShot;
59 };
60 
61 class ConnectInspector {
62 public:
63     ConnectInspector() = default;
64     ~ConnectInspector() = default;
65 
66     std::string componentName_;
67     std::unordered_map<int32_t, std::string> infoBuffer_;
68     LayoutInspectorInfo layoutInspectorInfo_;
69     std::unique_ptr<ConnectServer> connectServer_;
70     std::atomic<bool> waitingForDebugger_ = true;
71     std::queue<std::string> ideMsgQueue_;
72     std::function<void(bool)> setSwitchStatus_;
73     std::function<void(int32_t)> createLayoutInfo_;
74     int32_t instanceId_ = -1;
75 };
76 } // namespace OHOS::ArkCompiler::Toolchain
77 
78 #endif // ARKCOMPILER_TOOLCHAIN_CONNECT_SERVER_CONNECT_INSPECTOR_H
79