• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 WINDOW_INSPECTOR_H
17 #define WINDOW_INSPECTOR_H
18 
19 #include <mutex>
20 #include <optional>
21 
22 #include "wm_common.h"
23 #include "wm_single_instance.h"
24 
25 namespace OHOS::Rosen {
26 struct WindowListInfo {
27     std::string windowName;
28     uint32_t windowId;
29     uint32_t windowType;
30     Rect windowRect;
31 };
32 
33 using SendWMSMessageFunc = void (*)(const std::string& message);
34 using SetWMSCallbackFunc = void (*)(const std::function<void(const char*)>& wmsCallback);
35 using GetWMSWindowListCallback = std::function<std::optional<WindowListInfo>()>;
36 
37 class WindowInspector {
38 WM_DECLARE_SINGLE_INSTANCE_BASE(WindowInspector);
39 public:
40     void RegisterGetWMSWindowListCallback(uint32_t windowId, GetWMSWindowListCallback&& func);
41     void UnregisterGetWMSWindowListCallback(uint32_t windowId);
42 
43 protected:
44     WindowInspector();
45     virtual ~WindowInspector() = default;
46 
47 private:
48     bool isConnectServerSuccess_ = false;
49     void* handlerConnectServerSo_ = nullptr;
50     SendWMSMessageFunc sendWMSMessageFunc_ = nullptr;
51     SetWMSCallbackFunc setWMSCallbackFunc_ = nullptr;
52 
53     std::mutex callbackMutex_;
54     std::unordered_map<uint32_t, GetWMSWindowListCallback> getWMSWindowListCallbacks_;
55     // Above guarded by callbackMutex_
56 
57     void ConnectServer();
58     bool IsConnectServerSuccess() const;
59     bool ProcessArkUIInspectorMessage(const std::string& message, std::string& jsonStr);
60     void SendMessageToIDE(const std::string& jsonStr);
61 };
62 } // namespace OHOS::Rosen
63 
64 #endif // WINDOW_INSPECTOR_H