1 /* 2 * Copyright (c) 2023 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 SWITCH_EVENT_INPUT_SUBSCRIBE_MANAGER_H 17 #define SWITCH_EVENT_INPUT_SUBSCRIBE_MANAGER_H 18 19 #include <functional> 20 #include <map> 21 #include <memory> 22 23 #include <singleton.h> 24 25 #include "switch_event.h" 26 27 namespace OHOS { 28 namespace MMI { 29 class SwitchEventInputSubscribeManager final { 30 DECLARE_SINGLETON(SwitchEventInputSubscribeManager); 31 32 public: 33 DISALLOW_MOVE(SwitchEventInputSubscribeManager); 34 35 int32_t SubscribeSwitchEvent(std::function<void(std::shared_ptr<SwitchEvent>)> callback); 36 int32_t UnsubscribeSwitchEvent(int32_t subscribeId); 37 38 int32_t OnSubscribeSwitchEventCallback(std::shared_ptr<SwitchEvent> event, int32_t subscribeId); 39 void OnConnected(); 40 41 private: 42 std::map<int32_t, std::function<void(std::shared_ptr<SwitchEvent>)>> subscribeInfos_; 43 static int32_t subscribeManagerId_; 44 std::mutex mtx_; 45 }; 46 47 #define SWITCH_EVENT_INPUT_SUBSCRIBE_MGR ::OHOS::Singleton<SwitchEventInputSubscribeManager>::GetInstance() 48 } // namespace MMI 49 } // namespace OHOS 50 #endif // SWITCH_EVENT_INPUT_SUBSCRIBE_MANAGER_H