• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INSPECTOR_CONNECT_INSPECTOR_H
17 #define ARKCOMPILER_TOOLCHAIN_INSPECTOR_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 SetConnectCallback(const std::function<void(bool)>& callback);
44 
45 void RemoveMessage(int32_t instanceId);
46 
47 bool WaitForConnection();
48 
49 void SetDebugModeCallBack(const std::function<void()>& setDebugMode);
50 
51 void SetSwitchCallBack(const std::function<void(int32_t)>& createLayoutInfo, int32_t instanceId);
52 
53 void SetProfilerCallback(const std::function<void(bool)> &setArkUIStateProfilerStatus);
54 
55 void SetRecordCallback(const std::function<void(void)> &startRecordFunc,
56     const std::function<void(void)> &stopRecordFunc);
57 
58 /**
59  * @brief set connect server message handler callback from ArkUI.
60  * @param arkUICallback message handler callback of ArkUI.
61  *     @param paramOfCallback message recvived from IDE.
62  */
63 void SetArkUICallback(const std::function<void(const char *)> &arkUICallback);
64 
65 /**
66  * @brief set connect server message handler callback from WMS.
67  * @param wMSCallback message handler callback of WMS.
68  *     @param paramOfCallback message recvived from IDE.
69  */
70 void SetWMSCallback(const std::function<void(const char *)> &wMSCallback);
71 
72 /**
73  * @brief set connect server message handler callback from cangjie.
74  */
75 using SendMsgCB = const std::function<void(const std::string& message)>;
76 using CJCallback = const std::function<void(const std::string& message, SendMsgCB)>;
77 void SetCangjieCallback(CJCallback &cangjieCallback);
78 
79 #ifdef __cplusplus
80 #if __cplusplus
81 }
82 #endif
83 #endif /* End of #ifdef __cplusplus */
84 
85 class ConnectInspector {
86 public:
87     ConnectInspector() = default;
88     ~ConnectInspector() = default;
89 
90     std::string componentName_;
91     std::unordered_map<int32_t, std::string> infoBuffer_;
92     std::unique_ptr<ConnectServer> connectServer_;
93     std::atomic<bool> waitingForDebugger_ = true;
94     std::function<void(bool)> setArkUIStateProfilerStatus_;
95     std::function<void(int32_t)> createLayoutInfo_;
96     std::function<void()> setDebugMode_;
97     int32_t instanceId_ = -1;
98     std::function<void(void)> startRecord_;
99     std::function<void(void)> stopRecord_;
100     bool isRecording_ = false;
101     std::function<void(const char *)> arkUICallback_;
102     std::function<void(const char *)> wMSCallback_;
103     std::function<void(const std::string& message, SendMsgCB)> cangjieCallback_;
104 };
105 
106 class ConnectRequest {
107 public:
108     explicit ConnectRequest(const std::string &message);
109     ~ConnectRequest() = default;
110 
IsValid()111     bool IsValid() const
112     {
113         return isSuccess_;
114     }
115 
GetDomain()116     const std::string &GetDomain() const
117     {
118         return domain_;
119     }
120 
121 private:
122     std::string domain_ {};
123     bool isSuccess_ {false};
124 };
125 } // namespace OHOS::ArkCompiler::Toolchain
126 
127 #endif // ARKCOMPILER_TOOLCHAIN_CONNECT_SERVER_CONNECT_INSPECTOR_H
128