• 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 SCREEN_CAPTURE_MONITOR_CALLBACK_H
17 #define SCREEN_CAPTURE_MONITOR_CALLBACK_H
18 
19 #include "screen_capture_monitor.h"
20 #include "napi/native_api.h"
21 #include "napi/native_node_api.h"
22 #include "common_napi.h"
23 
24 namespace OHOS {
25 namespace Media {
26 
27 class ScreenCaptureMonitorCallback : public ScreenCaptureMonitor::ScreenCaptureMonitorListener {
28 public:
29     explicit ScreenCaptureMonitorCallback(napi_env env);
30     virtual ~ScreenCaptureMonitorCallback();
31     void SaveCallbackReference(const std::string &name, std::weak_ptr<AutoRef> ref);
32     void CancelCallbackReference(const std::string &name);
33 private:
34     struct ScreenCaptureMonitorJsCallback {
35         std::weak_ptr<AutoRef> autoRef;
36         std::string callbackName = "unknown";
37         ScreenCaptureMonitorEvent captureEvent;
38     };
39     void OnScreenCaptureStarted(int32_t pid) override;
40     void OnScreenCaptureFinished(int32_t pid) override;
41     void OnJsCaptureCallBack(ScreenCaptureMonitorJsCallback *jsCb) const;
42 
43     napi_env env_ = nullptr;
44     std::mutex mutex_;
45     std::map<std::string, std::weak_ptr<AutoRef>> refMap_;
46 };
47 } // Media
48 } // OHOS
49 #endif