• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 OHOS_ABILITY_RUNTIME_CONNECT_SERVER_MANAGER_H
17 #define OHOS_ABILITY_RUNTIME_CONNECT_SERVER_MANAGER_H
18 
19 #include <mutex>
20 #include <unordered_map>
21 
22 namespace OHOS::AbilityRuntime {
23 class ConnectServerManager final {
24 public:
25     static ConnectServerManager& Get();
26 
27     void StartConnectServer(const std::string& bundleName);
28     void StopConnectServer();
29     bool AddInstance(int32_t instanceId, const std::string& instanceName = "PandaDebugger");
30     void RemoveInstance(int32_t instanceId);
31     void SendInspector(const std::string& jsonTreeStr, const std::string& jsonSnapshotStr);
32     void SetLayoutInspectorCallback(
33         const std::function<void(int32_t)> &createLayoutInfo, const std::function<void(bool)> &setStatus);
34     std::function<void(int32_t)> GetLayoutInspectorCallback();
35 
36 private:
37     ConnectServerManager() = default;
38     ~ConnectServerManager();
39 
40     void* handlerConnectServerSo_ = nullptr;
41     std::string bundleName_;
42 
43     std::mutex mutex_;
44     static std::mutex instanceMutex_;
45     std::unordered_map<int32_t, std::string> instanceMap_;
46     std::function<void(int32_t)> createLayoutInfo_;
47     std::function<void(int32_t)> setStatus_;
48     ConnectServerManager(const ConnectServerManager&) = delete;
49     ConnectServerManager(ConnectServerManager&&) = delete;
50     ConnectServerManager& operator=(const ConnectServerManager&) = delete;
51     ConnectServerManager& operator=(ConnectServerManager&&) = delete;
52 };
53 } // namespace OHOS::AbilityRuntime
54 
55 #endif // OHOS_ABILITY_RUNTIME_CONNECT_SERVER_MANAGER_H