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 TABLET_SUBSCRIBER_HANDLER_H 17 #define TABLET_SUBSCRIBER_HANDLER_H 18 19 #include <algorithm> 20 #include <atomic> 21 #include <list> 22 #include <map> 23 #include <memory> 24 #include <mutex> 25 #include <set> 26 #include <thread> 27 #include "singleton.h" 28 #include "i_input_event_handler.h" 29 #include "key_event.h" 30 #include "switch_event.h" 31 #include "uds_server.h" 32 33 namespace OHOS { 34 namespace MMI { 35 class TabletSubscriberHandler final { 36 DECLARE_DELAYED_SINGLETON(TabletSubscriberHandler); 37 public: 38 DISALLOW_COPY_AND_MOVE(TabletSubscriberHandler); 39 void HandleTabletEvent(const std::shared_ptr<PointerEvent> pointerEvent); 40 int32_t SubscribeTabletProximity(SessionPtr sess, int32_t subscribeId); 41 int32_t UnsubscribetabletProximity(SessionPtr sess, int32_t subscribeId); 42 void Dump(int32_t fd, const std::vector<std::string> &args); 43 private: 44 struct Subscriber { SubscriberSubscriber45 Subscriber(int32_t id, SessionPtr sess) 46 : id_(id), sess_(sess), timerId_(-1) {} 47 int32_t id_ { -1 }; 48 SessionPtr sess_ { nullptr }; 49 int32_t timerId_ { -1 }; 50 }; 51 void InsertSubScriber(std::shared_ptr<Subscriber> subs); 52 private: 53 bool OnSubscribeTabletProximity(std::shared_ptr<PointerEvent> keyEvent); 54 void NotifySubscriber(std::shared_ptr<PointerEvent> keyEvent, 55 const std::shared_ptr<Subscriber> &subscriber); 56 void OnSessionDelete(SessionPtr sess); 57 bool InitSessionDeleteCallback(); 58 private: 59 std::list<std::shared_ptr<Subscriber>> subscribers_ {}; 60 std::atomic_bool callbackInitialized_ { false }; 61 }; 62 #define TABLET_SCRIBER_HANDLER ::OHOS::DelayedSingleton<TabletSubscriberHandler>::GetInstance() 63 } // namespace MMI 64 } // namespace OHOS 65 #endif // TABLET_SUBSCRIBER_HANDLER_H 66