• 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 INPUTMETHOD_IMF_PANEL_LISTENER_IMPL_H
17 #define INPUTMETHOD_IMF_PANEL_LISTENER_IMPL_H
18 
19 #include <mutex>
20 #include <thread>
21 #include <uv.h>
22 
23 #include "concurrent_map.h"
24 #include "js_callback_object.h"
25 #include "panel_status_listener.h"
26 #include "napi/native_api.h"
27 #include "napi/native_node_api.h"
28 
29 namespace OHOS {
30 namespace MiscServices {
31 class PanelListenerImpl : public PanelStatusListener {
32 public:
33     static std::shared_ptr<PanelListenerImpl> GetInstance();
34     ~PanelListenerImpl();
35     void OnPanelStatus(uint32_t windowId, bool isShow) override;
36     void SaveInfo(napi_env env, const std::string &type, napi_value callback, uint32_t windowId);
37     void RemoveInfo(const std::string &type, uint32_t windowId);
38 
39     struct UvEntry {
40         std::shared_ptr<JSCallbackObject> cbCopy;
UvEntryUvEntry41         explicit UvEntry(const std::shared_ptr<JSCallbackObject> &cb) : cbCopy(cb) {}
42     };
43     ConcurrentMap<uint32_t, ConcurrentMap<std::string, std::shared_ptr<JSCallbackObject>>> callbacks_;
44     static std::mutex listenerMutex_;
45     static std::shared_ptr<PanelListenerImpl> instance_;
46 };
47 } // namespace MiscServices
48 } // namespace OHOS
49 
50 #endif //INPUTMETHOD_IMF_PANEL_LISTENER_IMPL_H
51