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 INPUT_ACTIVE_SUBSCRIBE_MANAGER_H 17 #define INPUT_ACTIVE_SUBSCRIBE_MANAGER_H 18 19 #include <map> 20 #include <singleton.h> 21 #include "i_input_event_consumer.h" 22 23 namespace OHOS { 24 namespace MMI { 25 class InputActiveSubscribeManager final { 26 DECLARE_SINGLETON(InputActiveSubscribeManager); 27 public: 28 class SubscribeInputActiveInfo { 29 public: SubscribeInputActiveInfo(std::shared_ptr<IInputEventConsumer> inputEventConsumer,int64_t interval)30 SubscribeInputActiveInfo(std::shared_ptr<IInputEventConsumer> inputEventConsumer, int64_t interval) 31 : inputActiveInterval_(interval), callback_(inputEventConsumer) {}; 32 ~SubscribeInputActiveInfo() = default; GetInputActiveInterval()33 int64_t GetInputActiveInterval() const 34 { 35 return inputActiveInterval_; 36 } GetCallback()37 std::shared_ptr<IInputEventConsumer> GetCallback() const 38 { 39 return callback_; 40 } 41 private: 42 int64_t inputActiveInterval_ { 0 }; 43 std::shared_ptr<IInputEventConsumer> callback_ { nullptr }; 44 }; 45 public: 46 DISALLOW_MOVE(InputActiveSubscribeManager); 47 int32_t SubscribeInputActive(std::shared_ptr<IInputEventConsumer> inputEventConsumer, int64_t interval); 48 int32_t UnsubscribeInputActive(int32_t subscribeId); 49 50 int32_t OnSubscribeInputActiveCallback(std::shared_ptr<KeyEvent> keyEvent, int32_t subscribeId); 51 int32_t OnSubscribeInputActiveCallback(std::shared_ptr<PointerEvent> pointerEvent, int32_t subscribeId); 52 void OnConnected(); 53 54 private: 55 std::shared_ptr<SubscribeInputActiveInfo> subscribeInfo_ = nullptr; 56 std::mutex mtx_; 57 }; 58 #define INPUT_ACTIVE_SUBSCRIBE_MGR ::OHOS::Singleton<InputActiveSubscribeManager>::GetInstance() 59 } // namespace MMI 60 } // namespace OHOS 61 #endif // INPUT_ACTIVE_SUBSCRIBE_MANAGER_H