• 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_JS_DISPLAY_LISTENER_H
17 #define OHOS_JS_DISPLAY_LISTENER_H
18 
19 #include <mutex>
20 #include "native_engine/native_engine.h"
21 #include "native_engine/native_value.h"
22 #include "refbase.h"
23 #include "display_manager.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 class JsDisplayListener : public DisplayManager::IDisplayListener {
28 public:
JsDisplayListener(NativeEngine * engine)29     explicit JsDisplayListener(NativeEngine* engine) : engine_(engine) {}
30     ~JsDisplayListener() override = default;
31     void AddCallback(NativeValue* jsListenerObject);
32     void RemoveAllCallback();
33     void RemoveCallback(NativeValue* jsListenerObject);
34     void OnCreate(DisplayId id) override;
35     void OnDestroy(DisplayId id) override;
36     void OnChange(DisplayId id) override;
37 
38 private:
39     void CallJsMethod(const char* methodName, NativeValue* const* argv = nullptr, size_t argc = 0);
40     NativeEngine* engine_ = nullptr;
41     std::mutex mtx_;
42     std::vector<std::unique_ptr<NativeReference>> jsCallBack_;
43     NativeValue* CreateDisplayIdArray(NativeEngine& engine, const std::vector<DisplayId>& data);
44 };
45 }  // namespace Rosen
46 }  // namespace OHOS
47 #endif /* OHOS_JS_DISPLAY_LISTENER_H */