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 #include "input_monitor_manager.h"
17
18 #include "multimodal_input_connect_manager.h"
19 #include "util.h"
20
21 namespace OHOS {
22 namespace MMI {
23 namespace {
24 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputMonitorManager" };
25 } // namespace
26
InputMonitorManager()27 InputMonitorManager::InputMonitorManager() {}
~InputMonitorManager()28 InputMonitorManager::~InputMonitorManager() {}
29
AddMonitor(std::shared_ptr<IInputEventConsumer> monitor)30 int32_t InputMonitorManager::AddMonitor(std::shared_ptr<IInputEventConsumer> monitor)
31 {
32 CHKPR(monitor, INVALID_HANDLER_ID);
33 return AddHandler(InputHandlerType::MONITOR, monitor);
34 }
35
RemoveMonitor(int32_t monitorId)36 void InputMonitorManager::RemoveMonitor(int32_t monitorId)
37 {
38 RemoveHandler(monitorId, InputHandlerType::MONITOR);
39 }
40
MarkConsumed(int32_t monitorId,int32_t eventId)41 void InputMonitorManager::MarkConsumed(int32_t monitorId, int32_t eventId)
42 {
43 MMI_HILOGD("Mark consumed state, monitor:%{public}d,event:%{public}d", monitorId, eventId);
44 if (!HasHandler(monitorId)) {
45 MMI_HILOGW("Failed to find the monitorId");
46 return;
47 }
48 int32_t ret = MultimodalInputConnMgr->MarkEventConsumed(eventId);
49 if (ret != RET_OK) {
50 MMI_HILOGE("Send to server failed, ret:%{public}d", ret);
51 }
52 }
53 } // namespace MMI
54 } // namespace OHOS
55