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 #include <mutex> 21 22 #include "singleton.h" 23 #include "util.h" 24 25 namespace OHOS { 26 namespace MMI { 27 28 struct ScreenCaptureHandle { 29 void *handle; 30 int32_t (*isWorking)(); 31 void (*registerListener)(ScreenCaptureCallback); 32 ScreenCaptureHandleOHOS::MMI::ScreenCaptureHandle33 ScreenCaptureHandle(): handle(nullptr), isWorking(nullptr), registerListener(nullptr) {} 34 FreeOHOS::MMI::ScreenCaptureHandle35 void Free() 36 { 37 if (handle != nullptr) { 38 dlclose(handle); 39 handle = nullptr; 40 } 41 isWorking = nullptr; 42 registerListener = nullptr; 43 } 44 }; 45 46 class InputScreenCaptureAgent : public Singleton<InputScreenCaptureAgent> { 47 public: 48 ~InputScreenCaptureAgent() override; 49 int32_t IsScreenCaptureWorking(); 50 void RegisterListener(ScreenCaptureCallback callback); 51 52 private: 53 int32_t LoadLibrary(); 54 ScreenCaptureHandle handle_; 55 std::mutex agentMutex_; 56 }; 57 } 58 } 59 60 #endif