• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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_ABILITY_INCLUDE_INPUT_METHOD_CORE_STUB_H
17 #define FRAMEWORKS_INPUTMETHOD_ABILITY_INCLUDE_INPUT_METHOD_CORE_STUB_H
18 
19 #include <condition_variable>
20 #include <cstdint>
21 #include <mutex>
22 
23 #include "i_input_control_channel.h"
24 #include "i_input_data_channel.h"
25 #include "i_input_method_agent.h"
26 #include "i_input_method_core.h"
27 #include "input_attribute.h"
28 #include "iremote_broker.h"
29 #include "iremote_stub.h"
30 #include "message_handler.h"
31 #include "message_parcel.h"
32 
33 namespace OHOS {
34 namespace MiscServices {
35 class InputMethodCoreStub : public IRemoteStub<IInputMethodCore> {
36 public:
37     DISALLOW_COPY_AND_MOVE(InputMethodCoreStub);
38     InputMethodCoreStub();
39     virtual ~InputMethodCoreStub();
40     int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
41     int32_t StartInput(const InputClientInfo &clientInfo, bool isBindFromClient) override;
42     int32_t StopInput(const sptr<IInputDataChannel> &channel) override;
43     int32_t ShowKeyboard() override;
44     int32_t HideKeyboard() override;
45     int32_t InitInputControlChannel(const sptr<IInputControlChannel> &inputControlChannel) override;
46     void StopInputService(bool isTerminateIme) override;
47     int32_t SetSubtype(const SubProperty &property) override;
48     bool IsEnable() override;
49     int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown) override;
50     int32_t OnSecurityChange(int32_t security) override;
51     void OnClientInactive(const sptr<IInputDataChannel> &channel) override;
52     int32_t OnTextConfigChange(const InputClientInfo &clientInfo) override;
53     void SetMessageHandler(MessageHandler *msgHandler);
54 
55 private:
56     MessageHandler *msgHandler_;
57     int32_t StartInputOnRemote(MessageParcel &data, MessageParcel &reply);
58     int32_t StopInputOnRemote(MessageParcel &data, MessageParcel &reply);
59     int32_t ShowKeyboardOnRemote(MessageParcel &data, MessageParcel &reply);
60     int32_t HideKeyboardOnRemote(MessageParcel &data, MessageParcel &reply);
61     int32_t InitInputControlChannelOnRemote(MessageParcel &data, MessageParcel &reply);
62     int32_t StopInputServiceOnRemote(MessageParcel &data, MessageParcel &reply);
63     int32_t SetSubtypeOnRemote(MessageParcel &data, MessageParcel &reply);
64     int32_t IsEnableOnRemote(MessageParcel &data, MessageParcel &reply);
65     int32_t IsPanelShownOnRemote(MessageParcel &data, MessageParcel &reply);
66     int32_t SecurityChangeOnRemote(MessageParcel &data, MessageParcel &reply);
67     int32_t OnClientInactiveOnRemote(MessageParcel &data, MessageParcel &reply);
68     int32_t OnTextConfigChangeOnRemote(MessageParcel &data, MessageParcel &reply);
69     using ParcelHandler = std::function<bool(MessageParcel &)>;
70     int32_t SendMessage(int code, ParcelHandler input = nullptr);
71     using RequestHandler = int32_t (InputMethodCoreStub::*)(MessageParcel &, MessageParcel &);
72     static inline const std::unordered_map<int32_t, RequestHandler> HANDLERS = {
73         { static_cast<uint32_t>(SHOW_KEYBOARD), &InputMethodCoreStub::ShowKeyboardOnRemote },
74         { static_cast<uint32_t>(STOP_INPUT_SERVICE), &InputMethodCoreStub::StopInputServiceOnRemote },
75         { static_cast<uint32_t>(HIDE_KEYBOARD), &InputMethodCoreStub::HideKeyboardOnRemote },
76         { static_cast<uint32_t>(INIT_INPUT_CONTROL_CHANNEL), &InputMethodCoreStub::InitInputControlChannelOnRemote },
77         { static_cast<uint32_t>(SET_SUBTYPE), &InputMethodCoreStub::SetSubtypeOnRemote },
78         { static_cast<uint32_t>(START_INPUT), &InputMethodCoreStub::StartInputOnRemote },
79         { static_cast<uint32_t>(STOP_INPUT), &InputMethodCoreStub::StopInputOnRemote },
80         { static_cast<uint32_t>(IS_ENABLE), &InputMethodCoreStub::IsEnableOnRemote },
81         { static_cast<uint32_t>(IS_PANEL_SHOWN), &InputMethodCoreStub::IsPanelShownOnRemote },
82         { static_cast<uint32_t>(SECURITY_CHANGE), &InputMethodCoreStub::SecurityChangeOnRemote },
83         { static_cast<uint32_t>(ON_CLIENT_INACTIVE), &InputMethodCoreStub::OnClientInactiveOnRemote },
84         { static_cast<uint32_t>(ON_TEXT_CONFIG_CHANGE), &InputMethodCoreStub::OnTextConfigChangeOnRemote },
85     };
86 };
87 } // namespace MiscServices
88 } // namespace OHOS
89 #endif // FRAMEWORKS_INPUTMETHOD_ABILITY_INCLUDE_INPUT_METHOD_CORE_STUB_H
90