/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef SWITCH_SUBSCRIBER_HANDLER_H #define SWITCH_SUBSCRIBER_HANDLER_H #include #include #include #include #include #include #include #include #include "i_input_event_handler.h" #include "key_event.h" #include "switch_event.h" #include "uds_server.h" namespace OHOS { namespace MMI { class SwitchSubscriberHandler final : public IInputEventHandler { public: SwitchSubscriberHandler() = default; DISALLOW_COPY_AND_MOVE(SwitchSubscriberHandler); ~SwitchSubscriberHandler() = default; #ifdef OHOS_BUILD_ENABLE_KEYBOARD void HandleKeyEvent(const std::shared_ptr keyEvent) override; #endif // OHOS_BUILD_ENABLE_KEYBOARD #ifdef OHOS_BUILD_ENABLE_POINTER void HandlePointerEvent(const std::shared_ptr pointerEvent) override; #endif // OHOS_BUILD_ENABLE_POINTER #ifdef OHOS_BUILD_ENABLE_TOUCH void HandleTouchEvent(const std::shared_ptr pointerEvent) override; #endif // OHOS_BUILD_ENABLE_TOUCH #ifdef OHOS_BUILD_ENABLE_SWITCH void HandleSwitchEvent(const std::shared_ptr switchEvent) override; #endif // OHOS_BUILD_ENABLE_SWITCH int32_t SubscribeSwitchEvent(SessionPtr sess, int32_t subscribeId, int32_t switchType); int32_t UnsubscribeSwitchEvent(SessionPtr sess, int32_t subscribeId); void Dump(int32_t fd, const std::vector &args); private: struct Subscriber { Subscriber(int32_t id, SessionPtr sess, int32_t switchType) : id_(id), sess_(sess), switchType_(switchType), timerId_(-1) {} int32_t id_ { -1 }; SessionPtr sess_ { nullptr }; int32_t switchType_ { -1 }; int32_t timerId_ { -1 }; std::shared_ptr switchEvent_ { nullptr }; }; void InsertSubScriber(std::shared_ptr subs); private: bool OnSubscribeSwitchEvent(std::shared_ptr keyEvent); void NotifySubscriber(std::shared_ptr keyEvent, const std::shared_ptr &subscriber); void OnSessionDelete(SessionPtr sess); bool InitSessionDeleteCallback(); private: std::list> subscribers_ {}; std::atomic_bool callbackInitialized_ { false }; std::shared_ptr switchEvent_ { nullptr }; }; } // namespace MMI } // namespace OHOS #endif // SWITCH_SUBSCRIBER_HANDLER_H