• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 INPUT_SCREEN_CAPTURE_AGENT_H
17 #define INPUT_SCREEN_CAPTURE_AGENT_H
18 
19 #include <dlfcn.h>
20 
21 #include "singleton.h"
22 #include "util.h"
23 
24 namespace OHOS {
25 namespace MMI {
26 
27 struct ScreenCaptureHandle {
28     void *handle;
29     int32_t (*isWorking)(int32_t);
30     void (*registerListener)(ScreenCaptureCallback);
31     bool (*isMusicActivate)();
32 
ScreenCaptureHandleScreenCaptureHandle33     ScreenCaptureHandle(): handle(nullptr), isWorking(nullptr), registerListener(nullptr),
34         isMusicActivate(nullptr) {}
35 
FreeScreenCaptureHandle36     void Free()
37     {
38         if (handle != nullptr) {
39             dlclose(handle);
40             handle = nullptr;
41         }
42         isWorking = nullptr;
43         registerListener = nullptr;
44         isMusicActivate = nullptr;
45     }
46 };
47 
48 class InputScreenCaptureAgent : public Singleton<InputScreenCaptureAgent> {
49 public:
50     ~InputScreenCaptureAgent() override;
51     bool IsScreenCaptureWorking(int32_t capturePid);
52     void RegisterListener(ScreenCaptureCallback callback);
53     bool IsMusicActivate();
54 private:
55     int32_t LoadLibrary();
56     int32_t LoadAudioLibrary();
57     ScreenCaptureHandle handle_;
58     std::mutex agentMutex_;
59 };
60 }
61 }
62 
63 #endif