• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_device_consumer.h"
17 
18 #include "multimodal_event_handler.h"
19 #include "multimodal_input_connect_manager.h"
20 #include "define_multimodal.h"
21 
22 #undef MMI_LOG_TAG
23 #define MMI_LOG_TAG "InputDeviceConsumer"
24 
25 namespace OHOS {
26 namespace MMI {
InputDeviceConsumer()27 InputDeviceConsumer::InputDeviceConsumer() {}
~InputDeviceConsumer()28 InputDeviceConsumer::~InputDeviceConsumer() {}
29 
SetInputDeviceConsumer(const std::vector<std::string> & deviceNames,std::shared_ptr<IInputEventConsumer> consumer)30 int32_t InputDeviceConsumer::SetInputDeviceConsumer(const std::vector<std::string>& deviceNames,
31     std::shared_ptr<IInputEventConsumer> consumer)
32 {
33     CALL_DEBUG_ENTER;
34     if (consumer == nullptr) {
35         return MULTIMODAL_INPUT_CONNECT_MGR->ClearInputDeviceConsumer(deviceNames);
36     }
37     deviceConsumer_ = consumer;
38     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetInputDeviceConsumer(deviceNames);
39     if (ret != RET_OK) {
40         MMI_HILOGE("Send to server failed, ret:%{public}d", ret);
41     }
42     deviceNames_ = deviceNames;
43     return ret;
44 }
45 
OnConnected()46 void InputDeviceConsumer::OnConnected()
47 {
48     CALL_DEBUG_ENTER;
49     std::lock_guard<std::mutex> guard(mtx_);
50     if (deviceNames_.empty()) {
51         return;
52     }
53     MULTIMODAL_INPUT_CONNECT_MGR->SetInputDeviceConsumer(deviceNames_);
54 }
55 } // namespace MMI
56 } // namespace OHOS
57