1 /* 2 * Copyright (C) 2024 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 FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_KEY_EVENT_PROXY_CONSUMER_STUB_H 17 #define FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_KEY_EVENT_PROXY_CONSUMER_STUB_H 18 19 #include <cstdint> 20 #include <string> 21 22 #include "i_keyevent_consumer.h" 23 #include "iremote_stub.h" 24 #include "key_event.h" 25 #include "message_handler.h" 26 #include "message_option.h" 27 #include "message_parcel.h" 28 #include "nocopyable.h" 29 #include "refbase.h" 30 31 namespace OHOS { 32 namespace MiscServices { 33 class KeyEventConsumerStub : public IRemoteStub<IKeyEventConsumer> { 34 public: 35 DISALLOW_COPY_AND_MOVE(KeyEventConsumerStub); 36 int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 37 using KeyEventCallback = std::function<void(std::shared_ptr<MMI::KeyEvent> &keyEvent, bool isConsumed)>; 38 KeyEventConsumerStub(KeyEventCallback callback, std::shared_ptr<MMI::KeyEvent> keyEvent); 39 ~KeyEventConsumerStub(); 40 int32_t OnKeyEventResult(bool isConsumed) override; 41 42 private: 43 int32_t OnKeyEventResultOnRemote(MessageParcel &data, MessageParcel &reply); 44 using RequestHandler = int32_t (KeyEventConsumerStub::*)(MessageParcel &, MessageParcel &); 45 static constexpr RequestHandler HANDLERS[KEY_EVENT_CONSUMER_CMD_END] = { 46 [KEY_EVENT_RESULT] = &KeyEventConsumerStub::OnKeyEventResultOnRemote, 47 }; 48 KeyEventCallback callback_; 49 std::shared_ptr<MMI::KeyEvent> keyEvent_; 50 }; 51 } // namespace MiscServices 52 } // namespace OHOS 53 #endif // FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_KEY_EVENT_PROXY_CONSUMER_STUB_H 54