1 /* 2 * Copyright (c) 2021-2022 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 SERVER_MSG_HANDLER_H 17 #define SERVER_MSG_HANDLER_H 18 19 #include "nocopyable.h" 20 21 #include "event_dispatch_handler.h" 22 #include "i_event_filter.h" 23 #include "input_handler_type.h" 24 #include "key_option.h" 25 #include "msg_handler.h" 26 27 namespace OHOS { 28 namespace MMI { 29 typedef std::function<int32_t(SessionPtr sess, NetPacket& pkt)> ServerMsgFun; 30 class ServerMsgHandler : public MsgHandler<MmiMessageId, ServerMsgFun> { 31 public: 32 ServerMsgHandler(); 33 DISALLOW_COPY_AND_MOVE(ServerMsgHandler); 34 virtual ~ServerMsgHandler() override; 35 36 void Init(UDSServer& udsServer); 37 void OnMsgHandler(SessionPtr sess, NetPacket& pkt); 38 #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR) 39 int32_t OnAddInputHandler(SessionPtr sess, InputHandlerType handlerType, HandleEventType eventType); 40 int32_t OnRemoveInputHandler(SessionPtr sess, InputHandlerType handlerType, HandleEventType eventType); 41 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR 42 #ifdef OHOS_BUILD_ENABLE_MONITOR 43 int32_t OnMarkConsumed(SessionPtr sess, int32_t eventId); 44 #endif // OHOS_BUILD_ENABLE_MONITOR 45 #ifdef OHOS_BUILD_ENABLE_KEYBOARD 46 int32_t OnSubscribeKeyEvent(IUdsServer *server, int32_t pid, 47 int32_t subscribeId, const std::shared_ptr<KeyOption> option); 48 int32_t OnUnsubscribeKeyEvent(IUdsServer *server, int32_t pid, int32_t subscribeId); 49 #endif // OHOS_BUILD_ENABLE_KEYBOARD 50 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) 51 int32_t OnMoveMouse(int32_t offsetX, int32_t offsetY); 52 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING 53 #ifdef OHOS_BUILD_ENABLE_KEYBOARD 54 int32_t OnInjectKeyEvent(const std::shared_ptr<KeyEvent> keyEvent); 55 int32_t OnGetFunctionKeyState(int32_t funcKey, bool &state); 56 int32_t OnSetFunctionKeyState(int32_t funcKey, bool enable); 57 #endif // OHOS_BUILD_ENABLE_KEYBOARD 58 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 59 int32_t OnInjectPointerEvent(const std::shared_ptr<PointerEvent> pointerEvent); 60 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 61 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 62 int32_t AddInputEventFilter(sptr<IEventFilter> filter); 63 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 64 protected: 65 int32_t MarkProcessed(SessionPtr sess, NetPacket& pkt); 66 int32_t OnRegisterMsgHandler(SessionPtr sess, NetPacket& pkt); 67 int32_t OnDisplayInfo(SessionPtr sess, NetPacket& pkt); 68 69 private: 70 #ifdef OHOS_BUILD_ENABLE_TOUCH 71 bool FixTargetWindowId(std::shared_ptr<PointerEvent> pointerEvent, int32_t action); 72 #endif // OHOS_BUILD_ENABLE_TOUCH 73 74 private: 75 UDSServer *udsServer_ { nullptr }; 76 int32_t targetWindowId_ { -1 }; 77 }; 78 } // namespace MMI 79 } // namespace OHOS 80 #endif // SERVER_MSG_HANDLER_H 81