From 7d067bb1874d99b4be4d3e7514b93dce898aec79 Mon Sep 17 00:00:00 2001 From: xxxx Date: Wed, 8 Jun 2022 08:55:08 +0800 Subject: [PATCH] Description: add dinput config Match-id-0f3fd500564870a3c9c547c539f095cb0bdb9901 --- common/include/constants_dinput.h | 244 ---- common/include/dinput_errcode.h | 121 -- common/include/input_hub.cpp | 876 -------------- common/include/input_hub.h | 141 --- common/include/test/BUILD.gn | 18 - .../include/test/whitelistunittest/BUILD.gn | 83 -- .../whitelistunittest/white_list_test.cpp | 377 ------ .../test/whitelistunittest/white_list_test.h | 34 - common/include/white_list_util.cpp | 259 ---- common/include/white_list_util.h | 57 - .../include/dinput_sink_trans_callback.h | 35 - .../common/include/dinput_softbus_define.h | 70 -- .../include/dinput_source_trans_callback.h | 37 - services/sink/inputcollector/BUILD.gn | 61 - .../include/distributed_input_collector.h | 63 - .../src/distributed_input_collector.cpp | 161 --- services/sink/sinkmanager/BUILD.gn | 74 -- .../distributed_input_sink_event_handler.h | 43 - .../include/distributed_input_sink_manager.h | 107 -- .../distributed_input_sink_event_handler.cpp | 45 - .../src/distributed_input_sink_manager.cpp | 356 ------ services/sink/sinkmanager/test/BUILD.gn | 18 - .../test/sinkmanagerunittest/BUILD.gn | 95 -- .../distributed_input_sinkmanager_test.cpp | 60 - .../distributed_input_sinkmanager_test.h | 46 - services/sink/transport/BUILD.gn | 64 - .../include/distributed_input_sink_switch.h | 53 - .../distributed_input_sink_transport.h | 85 -- .../src/distributed_input_sink_switch.cpp | 192 --- .../src/distributed_input_sink_transport.cpp | 456 ------- services/sink/transport/test/BUILD.gn | 18 - .../transport/test/sinktransunittest/BUILD.gn | 80 -- .../distributed_input_sinktrans_test.cpp | 166 --- .../distributed_input_sinktrans_test.h | 42 - .../test/sinktransunittest/mock/session.h | 479 -------- .../mock/softbus_bus_center.h | 675 ----------- .../sinktransunittest/mock/softbus_common.h | 386 ------ services/source/inputinject/BUILD.gn | 65 - .../include/distributed_input_inject.h | 53 - .../include/distributed_input_node_manager.h | 67 - .../inputinject/include/virtual_device.h | 68 -- .../inputinject/include/virtual_keyboard.h | 39 - .../inputinject/include/virtual_mouse.h | 39 - .../inputinject/include/virtual_touchpad.h | 39 - .../src/distributed_input_inject.cpp | 128 -- .../src/distributed_input_node_manager.cpp | 218 ---- .../source/inputinject/src/virtual_device.cpp | 178 --- .../inputinject/src/virtual_keyboard.cpp | 76 -- .../source/inputinject/src/virtual_mouse.cpp | 67 - .../inputinject/src/virtual_touchpad.cpp | 90 -- services/source/inputinject/test/BUILD.gn | 18 - .../test/sourceinjectunittest/BUILD.gn | 88 -- .../distributed_input_sourceinject_test.cpp | 259 ---- .../distributed_input_sourceinject_test.h | 42 - services/source/sourcemanager/BUILD.gn | 94 -- .../distributed_input_source_event_handler.h | 43 - .../distributed_input_source_manager.h | 237 ---- ...distributed_input_source_event_handler.cpp | 45 - .../src/distributed_input_source_manager.cpp | 1075 ----------------- services/source/sourcemanager/test/BUILD.gn | 18 - .../test/sourcemanagerunittest/BUILD.gn | 119 -- .../distributed_input_sourcemanager_test.cpp | 349 ------ .../distributed_input_sourcemanager_test.h | 114 -- services/source/transport/BUILD.gn | 66 - .../distributed_input_source_transport.h | 80 -- .../distributed_input_source_transport.cpp | 584 --------- services/source/transport/test/BUILD.gn | 18 - .../test/sourcetransunittest/BUILD.gn | 81 -- .../distributed_input_sourcetrans_test.cpp | 127 -- .../distributed_input_sourcetrans_test.h | 42 - .../test/sourcetransunittest/mock/session.h | 479 -------- .../mock/softbus_bus_center.h | 675 ----------- .../sourcetransunittest/mock/softbus_common.h | 386 ------ sinkhandler/BUILD.gn | 68 -- .../include/distributed_input_sink_handler.h | 85 -- .../include/load_d_input_sink_callback.h | 36 - .../src/distributed_input_sink_handler.cpp | 107 -- .../src/load_d_input_sink_callback.cpp | 44 - sinkhandler/test/BUILD.gn | 18 - sinkhandler/test/unittest/BUILD.gn | 86 -- .../distributed_input_sinkhandler_test.cpp | 109 -- .../distributed_input_sinkhandler_test.h | 45 - .../mock/mock_distributed_input_client.cpp | 173 --- sourcehandler/BUILD.gn | 68 -- .../distributed_input_source_handler.h | 90 -- .../include/load_d_input_source_callback.h | 35 - .../src/distributed_input_source_handler.cpp | 114 -- .../src/load_d_input_source_callback.cpp | 45 - sourcehandler/test/BUILD.gn | 18 - sourcehandler/test/unittest/BUILD.gn | 86 -- .../distributed_input_sourcehandler_test.cpp | 149 --- .../distributed_input_sourcehandler_test.h | 66 - .../mock/mock_distributed_input_client.cpp | 173 --- 93 files changed, 13958 deletions(-) delete mode 100644 common/include/constants_dinput.h delete mode 100644 common/include/dinput_errcode.h delete mode 100644 common/include/input_hub.cpp delete mode 100644 common/include/input_hub.h delete mode 100644 common/include/test/BUILD.gn delete mode 100644 common/include/test/whitelistunittest/BUILD.gn delete mode 100644 common/include/test/whitelistunittest/white_list_test.cpp delete mode 100644 common/include/test/whitelistunittest/white_list_test.h delete mode 100644 common/include/white_list_util.cpp delete mode 100644 common/include/white_list_util.h delete mode 100644 services/common/include/dinput_sink_trans_callback.h delete mode 100644 services/common/include/dinput_softbus_define.h delete mode 100644 services/common/include/dinput_source_trans_callback.h delete mode 100644 services/sink/inputcollector/BUILD.gn delete mode 100644 services/sink/inputcollector/include/distributed_input_collector.h delete mode 100644 services/sink/inputcollector/src/distributed_input_collector.cpp delete mode 100644 services/sink/sinkmanager/BUILD.gn delete mode 100644 services/sink/sinkmanager/include/distributed_input_sink_event_handler.h delete mode 100644 services/sink/sinkmanager/include/distributed_input_sink_manager.h delete mode 100644 services/sink/sinkmanager/src/distributed_input_sink_event_handler.cpp delete mode 100644 services/sink/sinkmanager/src/distributed_input_sink_manager.cpp delete mode 100644 services/sink/sinkmanager/test/BUILD.gn delete mode 100644 services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn delete mode 100644 services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp delete mode 100644 services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.h delete mode 100644 services/sink/transport/BUILD.gn delete mode 100644 services/sink/transport/include/distributed_input_sink_switch.h delete mode 100644 services/sink/transport/include/distributed_input_sink_transport.h delete mode 100644 services/sink/transport/src/distributed_input_sink_switch.cpp delete mode 100644 services/sink/transport/src/distributed_input_sink_transport.cpp delete mode 100644 services/sink/transport/test/BUILD.gn delete mode 100644 services/sink/transport/test/sinktransunittest/BUILD.gn delete mode 100644 services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.cpp delete mode 100644 services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.h delete mode 100644 services/sink/transport/test/sinktransunittest/mock/session.h delete mode 100644 services/sink/transport/test/sinktransunittest/mock/softbus_bus_center.h delete mode 100644 services/sink/transport/test/sinktransunittest/mock/softbus_common.h delete mode 100644 services/source/inputinject/BUILD.gn delete mode 100644 services/source/inputinject/include/distributed_input_inject.h delete mode 100644 services/source/inputinject/include/distributed_input_node_manager.h delete mode 100644 services/source/inputinject/include/virtual_device.h delete mode 100644 services/source/inputinject/include/virtual_keyboard.h delete mode 100644 services/source/inputinject/include/virtual_mouse.h delete mode 100644 services/source/inputinject/include/virtual_touchpad.h delete mode 100644 services/source/inputinject/src/distributed_input_inject.cpp delete mode 100644 services/source/inputinject/src/distributed_input_node_manager.cpp delete mode 100644 services/source/inputinject/src/virtual_device.cpp delete mode 100644 services/source/inputinject/src/virtual_keyboard.cpp delete mode 100644 services/source/inputinject/src/virtual_mouse.cpp delete mode 100644 services/source/inputinject/src/virtual_touchpad.cpp delete mode 100644 services/source/inputinject/test/BUILD.gn delete mode 100644 services/source/inputinject/test/sourceinjectunittest/BUILD.gn delete mode 100644 services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp delete mode 100644 services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.h delete mode 100644 services/source/sourcemanager/BUILD.gn delete mode 100644 services/source/sourcemanager/include/distributed_input_source_event_handler.h delete mode 100644 services/source/sourcemanager/include/distributed_input_source_manager.h delete mode 100644 services/source/sourcemanager/src/distributed_input_source_event_handler.cpp delete mode 100644 services/source/sourcemanager/src/distributed_input_source_manager.cpp delete mode 100644 services/source/sourcemanager/test/BUILD.gn delete mode 100644 services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn delete mode 100644 services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp delete mode 100644 services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h delete mode 100644 services/source/transport/BUILD.gn delete mode 100644 services/source/transport/include/distributed_input_source_transport.h delete mode 100644 services/source/transport/src/distributed_input_source_transport.cpp delete mode 100644 services/source/transport/test/BUILD.gn delete mode 100644 services/source/transport/test/sourcetransunittest/BUILD.gn delete mode 100644 services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.cpp delete mode 100644 services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.h delete mode 100644 services/source/transport/test/sourcetransunittest/mock/session.h delete mode 100644 services/source/transport/test/sourcetransunittest/mock/softbus_bus_center.h delete mode 100644 services/source/transport/test/sourcetransunittest/mock/softbus_common.h delete mode 100644 sinkhandler/BUILD.gn delete mode 100644 sinkhandler/include/distributed_input_sink_handler.h delete mode 100644 sinkhandler/include/load_d_input_sink_callback.h delete mode 100644 sinkhandler/src/distributed_input_sink_handler.cpp delete mode 100644 sinkhandler/src/load_d_input_sink_callback.cpp delete mode 100644 sinkhandler/test/BUILD.gn delete mode 100644 sinkhandler/test/unittest/BUILD.gn delete mode 100644 sinkhandler/test/unittest/distributed_input_sinkhandler_test.cpp delete mode 100644 sinkhandler/test/unittest/distributed_input_sinkhandler_test.h delete mode 100644 sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp delete mode 100644 sourcehandler/BUILD.gn delete mode 100644 sourcehandler/include/distributed_input_source_handler.h delete mode 100644 sourcehandler/include/load_d_input_source_callback.h delete mode 100644 sourcehandler/src/distributed_input_source_handler.cpp delete mode 100644 sourcehandler/src/load_d_input_source_callback.cpp delete mode 100644 sourcehandler/test/BUILD.gn delete mode 100644 sourcehandler/test/unittest/BUILD.gn delete mode 100644 sourcehandler/test/unittest/distributed_input_sourcehandler_test.cpp delete mode 100644 sourcehandler/test/unittest/distributed_input_sourcehandler_test.h delete mode 100644 sourcehandler/test/unittest/mock/mock_distributed_input_client.cpp diff --git a/common/include/constants_dinput.h b/common/include/constants_dinput.h deleted file mode 100644 index 640e306..0000000 --- a/common/include/constants_dinput.h +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DISTRIBUTED_INPUT_CONSTANTS_H -#define OHOS_DISTRIBUTED_INPUT_CONSTANTS_H - -#include -#include -#include - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -#define INPUT_KEY_WHEN "when" -#define INPUT_KEY_TYPE "type" -#define INPUT_KEY_CODE "code" -#define INPUT_KEY_VALUE "value" -#define INPUT_KEY_DESCRIPTOR "descriptor" -#define INPUT_KEY_PATH "path" - -#define VIRTUAL_DEVICE_NAME "Hos Distributed Virtual Device " - - /** - * Status code. - */ - constexpr int32_t NO_ERROR = 0; - constexpr int32_t ERROR = -1; - - /** - * Status code, indicates general success. - */ - constexpr int32_t SUCCESS = 0; - - /** - * Status code, indicates general failure. - */ - constexpr int32_t FAILURE = -60000; - - /** - * Status code, DISERVER general failure. - */ - constexpr int32_t FAILURE_DIS = -60001; - - /** - * Status code, hardware is resigtring. - */ - constexpr int32_t FAILURE_REGISTING = -60002; - - /** - * Status code, hardware is unresigtring. - */ - constexpr int32_t FAILURE_UNREGISTING = -60003; - - /** - * Input Type NULL. - */ - constexpr int32_t INPUT_TYPE_NULL = 0; - - /** - * Input Type MOUSE. - */ - constexpr int32_t INPUT_TYPE_MOUSE = 1; - - /** - * Input Type KEYBOARD. - */ - constexpr int32_t INPUT_TYPE_KEYBOARD = 2; - - /** - * Input Type TOUCH. - */ - constexpr int32_t INPUT_TYPE_TOUCH = 4; - - /** - * Input Type ALL. - */ - constexpr int32_t INPUT_TYPE_ALL = INPUT_TYPE_MOUSE | INPUT_TYPE_KEYBOARD | INPUT_TYPE_TOUCH; - - constexpr int32_t INPUT_LOADSA_TIMEOUT_MS = 10000; - - constexpr int32_t SESSION_WAIT_TIMEOUT_SECOND = 5; - - enum class EHandlerMsgType { - DINPUT_SINK_EVENT_HANDLER_MSG = 1, - DINPUT_SOURCE_EVENT_HANDLER_MSG = 2 - }; - - struct BusinessEvent { - std::vector pressedKeys; - int32_t keyCode; - int32_t keyAction; - }; - - /* - * A raw event as retrieved from the input_event. - */ - struct RawEvent { - int64_t when; - int32_t type; - int32_t code; - int32_t value; - std::string descriptor; - std::string path; - }; - - /* - * Input device Info retrieved from the kernel. - */ - struct InputDevice { - inline InputDevice() : bus(0), vendor(0), product(0), version(0) {} - std::string name; - std::string location; - std::string uniqueId; - uint16_t bus; - uint16_t vendor; - uint16_t product; - uint16_t version; - std::string descriptor; - uint16_t nonce; - uint32_t classes; - }; - - /* - * Distributed Hardware Handle - */ - struct HardwareHandle { - // equipment ID - std::string eqId; - - // Hardware ID - std::string hhId; - - // Hardware detailed information - std::string hdInfo; - }; - - // Synthetic raw event type codes produced when devices are added or removed. - enum class DeviceType { - // Sent when a device is added. - DEVICE_ADDED = 0x10000000, - - // Sent when a device is removed. - DEVICE_REMOVED = 0x20000000, - - // Sent when all added/removed devices from the most recent scan have been reported. - // This event is always sent at least once. - FINISHED_DEVICE_SCAN = 0x30000000, - - FIRST_SYNTHETIC_EVENT = DEVICE_ADDED, - }; - - /* - * Input device connection status - */ - struct InputDeviceEvent { - DeviceType type; - InputDevice deviceInfo; - }; - - /* - * Input device classes. - */ - enum class DeviceClasses { - /* The input device is a keyboard or has buttons. */ - INPUT_DEVICE_CLASS_KEYBOARD = 0x00000001, - - /* The input device is an alpha-numeric keyboard (not just a dial pad). */ - INPUT_DEVICE_CLASS_ALPHAKEY = 0x00000002, - - /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */ - INPUT_DEVICE_CLASS_TOUCH = 0x00000004, - - /* The input device is a cursor device such as a trackball or mouse. */ - INPUT_DEVICE_CLASS_CURSOR = 0x00000008, - - /* The input device is a multi-touch touchscreen. */ - INPUT_DEVICE_CLASS_TOUCH_MT = 0x00000010, - - /* The input device is a directional pad (implies keyboard, has DPAD keys). */ - INPUT_DEVICE_CLASS_DPAD = 0x00000020, - - /* The input device is a gamepad (implies keyboard, has BUTTON keys). */ - INPUT_DEVICE_CLASS_GAMEPAD = 0x00000040, - - /* The input device has switches. */ - INPUT_DEVICE_CLASS_SWITCH = 0x00000080, - - /* The input device is a joystick (implies gamepad, has joystick absolute axes). */ - INPUT_DEVICE_CLASS_JOYSTICK = 0x00000100, - - /* The input device has a vibrator (supports FF_RUMBLE). */ - INPUT_DEVICE_CLASS_VIBRATOR = 0x00000200, - - /* The input device has a microphone. */ - INPUT_DEVICE_CLASS_MIC = 0x00000400, - - /* The input device is an external stylus (has data we want to fuse with touch data). */ - INPUT_DEVICE_CLASS_EXTERNAL_STYLUS = 0x00000800, - - /* The input device has a rotary encoder. */ - INPUT_DEVICE_CLASS_ROTARY_ENCODER = 0x00001000, - - /* The input device is virtual (not a real device, not part of UI configuration). */ - INPUT_DEVICE_CLASS_VIRTUAL = 0x40000000, - - /* The input device is external (not built-in). */ - INPUT_DEVICE_CLASS_EXTERNAL = 0x80000000, - }; - - /** - * Device Type definitions - */ - enum class DInputServerType { - /** - * null server - */ - NULL_SERVER_TYPE = 0, - - /** - * source server - */ - SOURCE_SERVER_TYPE = 1, - - /** - * sink server. - */ - SINK_SERVER_TYPE = 2, - }; -} -} -} -#endif diff --git a/common/include/dinput_errcode.h b/common/include/dinput_errcode.h deleted file mode 100644 index d377dc8..0000000 --- a/common/include/dinput_errcode.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DINPUT_ERRCODE_H -#define OHOS_DINPUT_ERRCODE_H - -#include - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { - constexpr int32_t DH_SUCCESS = 0; - - constexpr int32_t ERR_DH_INPUT_HUB_EPOLL_INIT_FAIL = -60000; - constexpr int32_t ERR_DH_INPUT_HUB_EPOLL_WAIT_TIMEOUT = -60001; - constexpr int32_t ERR_DH_INPUT_HUB_OPEN_DEVICEPATH_FAIL = -60002; - constexpr int32_t ERR_DH_INPUT_HUB_MAKE_INPUT_DEVICE_FAIL = -60003; - constexpr int32_t ERR_DH_INPUT_HUB_MAKE_DEVICE_FAIL = -60004; - constexpr int32_t ERR_DH_INPUT_HUB_UNREGISTER_FD_FAIL = -60005; - constexpr int32_t ERR_DH_INPUT_HUB_GET_EVENT_FAIL = -60006; - constexpr int32_t ERR_DH_INPUT_HUB_DEVICE_ENABLE_FAIL = -60007; - // whilte list error code - constexpr int32_t ERR_DH_INPUT_WHILTELIST_INIT_FAIL = -61001; - constexpr int32_t ERR_DH_INPUT_WHILTELIST_GET_WHILTELIST_FAIL = -61002; - // handler error code - constexpr int32_t ERR_DH_INPUT_HANDLER_GET_DEVICE_ID_FAIL = -63000; - // service sink error code - constexpr int32_t ERR_DH_INPUT_SERVER_SINK_COLLECTOR_INIT_FAIL = -64000; - constexpr int32_t ERR_DH_INPUT_SERVER_SINK_MANAGER_INIT_FAIL = -64001; - constexpr int32_t ERR_DH_INPUT_SERVER_SINK_START_SWITCH_FAIL = -64002; - constexpr int32_t ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL = -64003; - constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_INIT_FAIL = -64004; - constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPPREPARE_FAIL = 64005; - constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPUNPREPARE_FAIL = -64006; - constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPSTART_FAIL = -64007; - constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPSTOP_FAIL = -64008; - constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_SENDMESSAGE_FAIL = -64009; - // service source error code - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_INJECT_REGISTER_FAIL = -65000; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_INJECT_UNREGISTER_FAIL = -65001; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_INJECT_PREPARE_FAIL = -65002; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL = -65003;// - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_OPEN_DEVICE_NODE_FAIL = -65004; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL = -65005; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_CLOSE_DEVICE_FAIL = -65006; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_GET_DEVICE_FAIL = -65007; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_INIT_FAIL = -65008; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANSGER_RELEASE_FAIL = -65009; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL = -65010; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL = -65011; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REMOVE_INPUT_NODE_FAIL = -65012; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_DELETE_DEVICE_FAIL = -65013; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL = -65014; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL = -65015; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL = -65016; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL = -65017; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_INIT_FAIL = -65018; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_DEVICE_SESSION_STATE = -65019; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_OPEN_SESSION_FAIL = -65020; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_OPEN_SESSION_TIMEOUT = -65021; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_PREPARE_FAIL = -65022; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_UNPREPARE_FAIL = -65023; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL = -65024; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL = -65025; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE = -65026; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL = -65027; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_MSG_IS_BAD = -65028; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_MSG_IS_BAD = -65029; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_MSG_IS_BAD = -65030; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_MSG_IS_BAD = -65031; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD = -65032; - constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD = -65033; - // handler error code - constexpr int32_t ERR_DH_INPUT_SINK_HANDLER_INIT_SINK_SA_FAIL = -66000; - constexpr int32_t ERR_DH_INPUT_SINK_HANDLER_INIT_SOURCE_SA_FAIL = -66001; - // interface error code - constexpr int32_t ERR_DH_INPUT_IPC_INVALID_DESCRIPTOR = -67000; - constexpr int32_t ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL = -67001; - constexpr int32_t ERR_DH_INPUT_CLIENT_GET_SINK_PROXY_FAIL = -67002; - constexpr int32_t ERR_DH_INPUT_CLIENT_REGISTER_FAIL = -67003; - constexpr int32_t ERR_DH_INPUT_CLIENT_UNREGISTER_FAIL = -67004; - constexpr int32_t ERR_DH_INPUT_CLIENT_PREPARE_FAIL = -67005; - constexpr int32_t ERR_DH_INPUT_CLIENT_UNPREPARE_FAIL = -67006; - constexpr int32_t ERR_DH_INPUT_CLIENT_START_FAIL = -67007; - constexpr int32_t ERR_DH_INPUT_CLIENT_STOP_FAIL = -67008; - constexpr int32_t ERR_DH_INPUT_SINK_PROXY_INIT_FAIL = -67009; - constexpr int32_t ERR_DH_INPUT_SINK_PROXY_RELEASE_FAIL = -67010; - constexpr int32_t ERR_DH_INPUT_SINK_PROXY_IS_START_INPUT_FAIL = -67011; - constexpr int32_t ERR_DH_INPUT_SINK_STUB_ON_REMOTE_REQUEST_FAIL = -67012; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_INIT_FAIL = -67013; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_RELEASE_FAIL = -67014; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_REGISTER_WRITE_MSG_FAIL = -67015; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_REGISTER_FAIL = -67016; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_WRITE_MSG_FAIL = -67017; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_FAIL = -67018; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_PREPARE_WRITE_MSG_FAIL = -67019; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_PREPARE_FAIL = -67020; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_WRITE_MSG_FAIL = -67021; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_FAIL = -67022; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_START_WRITE_MSG_FAIL = -67023; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_START_FAIL = -67024; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_STOP_WRITE_MSG_FAIL = -67025; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL = -67026; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_IS_START_INPUT_FAIL = -67027; - constexpr int32_t ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL = -67028; -} -} -} -#endif \ No newline at end of file diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp deleted file mode 100644 index 1615290..0000000 --- a/common/include/input_hub.cpp +++ /dev/null @@ -1,876 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "input_hub.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "anonymous_string.h" -#include "distributed_hardware_log.h" - -#include "dinput_errcode.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -namespace { -static const char *DEVICE_PATH = "/dev/input"; -static const uint32_t INPUT_DEVICE_CLASS_KEYBOARD = static_cast(DeviceClasses::INPUT_DEVICE_CLASS_KEYBOARD); -static const uint32_t INPUT_DEVICE_CLASS_CURSOR = static_cast(DeviceClasses::INPUT_DEVICE_CLASS_CURSOR); -} - -InputHub::InputHub() : needToScanDevices_(true), - nextDeviceId_(1), pendingEventCount_(0), - pendingEventIndex_(0), pendingINotify_(false), - deviceChanged_(false) -{ - Initialize(); -} - -InputHub::~InputHub() -{ - Release(); -} - -int32_t InputHub::Initialize() -{ - epollFd_ = epoll_create1(EPOLL_CLOEXEC); - if (epollFd_ < 0) { - DHLOGE("Could not create epoll instance: %s", strerror(errno)); - return ERR_DH_INPUT_HUB_EPOLL_INIT_FAIL; - } - - iNotifyFd_ = inotify_init(); - inputWd_ = inotify_add_watch(iNotifyFd_, DEVICE_PATH, IN_DELETE | IN_CREATE); - if (inputWd_ < 0) { - DHLOGE( - "Could not register INotify for %s: %s", DEVICE_PATH, strerror(errno)); - return ERR_DH_INPUT_HUB_EPOLL_INIT_FAIL; - } - - struct epoll_event eventItem = {}; - eventItem.events = EPOLLIN; - eventItem.data.fd = iNotifyFd_; - int result = epoll_ctl(epollFd_, EPOLL_CTL_ADD, iNotifyFd_, &eventItem); - if (result != 0) { - DHLOGE("Could not add INotify to epoll instance. errno=%d", errno); - return ERR_DH_INPUT_HUB_EPOLL_INIT_FAIL; - } - - return DH_SUCCESS; -} - -int32_t InputHub::Release() -{ - CloseAllDevicesLocked(); - - ::close(epollFd_); - ::close(iNotifyFd_); - return DH_SUCCESS; -} - -size_t InputHub::CollectInputEvents(RawEvent* buffer, size_t bufferSize) -{ - size_t count; - for (;;) { - if (needToScanDevices_) { - needToScanDevices_ = false; - ScanInputDevices(DEVICE_PATH); - } - while (!openingDevices_.empty()) { - std::unique_lock deviceLock(visitMutex_); - std::unique_ptr device = std::move(*openingDevices_.rbegin()); - openingDevices_.pop_back(); - DHLOGI("Reporting device opened: id=%s, name=%s\n", - GetAnonyInt32(device->id).c_str(), device->path.c_str()); - auto [dev_it, inserted] = devices_.insert_or_assign(device->id, std::move(device)); - if (!inserted) { - DHLOGI("Device id %s exists, replaced. \n", GetAnonyInt32(device->id).c_str()); - } - } - deviceChanged_ = false; - count = GetEvents(buffer, bufferSize); - // readNotify() will modify the list of devices so this must be done after - // processing all other events to ensure that we read all remaining events - // before closing the devices. - if (pendingINotify_ && pendingEventIndex_ >= pendingEventCount_) { - pendingINotify_ = false; - ReadNotifyLocked(); - deviceChanged_ = true; - } - - // Report added or removed devices immediately. - if (deviceChanged_) { - continue; - } - - if (count > 0) { - break; - } - - if (RefreshEpollItem() < 0) { - break; - } - } - - // All done, return the number of events we read. - return count; -} - -size_t InputHub::GetEvents(RawEvent* buffer, size_t bufferSize) -{ - RawEvent* event = buffer; - size_t capacity = bufferSize; - while (pendingEventIndex_ < pendingEventCount_) { - std::unique_lock my_lock(operationMutex_); - const struct epoll_event& eventItem = mPendingEventItems[pendingEventIndex_++]; - if (eventItem.data.fd == iNotifyFd_) { - if (eventItem.events & EPOLLIN) { - pendingINotify_ = true; - } else { - DHLOGI("Received no epoll event 0x%08x.", eventItem.events); - } - continue; - } - Device* device = GetDeviceByFd(eventItem.data.fd); - if (!device) { - continue; - } - if (eventItem.events & EPOLLIN) { - struct input_event readBuffer[bufferSize]; - int32_t readSize = read(device->fd, readBuffer, sizeof(struct input_event) * capacity); - size_t count = ReadInputEvent(readSize, *device); - for (size_t i = 0; i < count; i++) { - struct input_event& iev = readBuffer[i]; - event->when = ProcessEventTimestamp(iev); - event->type = iev.type; - event->code = iev.code; - event->value = iev.value; - event->path = device->path; - if (event->type == EV_KEY) { - DHLOGD("1.E2E-Test Sink collect EV_KEY, Code: %d, Value: %d, Path: %s, When: " PRId64"", - event->code, event->value, event->path.c_str(), event->when); - } else if (event->type == EV_REL) { - DHLOGD("1.E2E-Test Sink collect EV_REL, Code: %d, Value: %d, Path: %s, When: " PRId64"", - event->code, event->value, event->path.c_str(), event->when); - } else if (event->type == EV_ABS) { - DHLOGD("1.E2E-Test Sink collect EV_ABS, Code: %d, Value: %d, Path: %s, When: " PRId64"", - event->code, event->value, event->path.c_str(), event->when); - } else { - DHLOGW("1.E2E-Test Sink collect other type!"); - } - event->descriptor = device->identifier.descriptor; - event += 1; - capacity -= 1; - } - if (capacity == 0) { - pendingEventIndex_ -= 1; - break; - } - } else if (eventItem.events & EPOLLHUP) { - DHLOGI("Removing device %s due to epoll hang-up event.", - device->identifier.name.c_str()); - deviceChanged_ = true; - CloseDeviceLocked(*device); - } - } - return event - buffer; -} - -size_t InputHub::ReadInputEvent(int32_t readSize, Device& device) -{ - size_t count = 0; - if (readSize == 0 || (readSize < 0 && errno == ENODEV)) { - // Device was removed before INotify noticed. - DHLOGE("could not get event, removed? (fd: %d size: %d" - " errno: %d)\n", - device.fd, readSize, errno); - deviceChanged_ = true; - CloseDeviceLocked(device); - } else if (readSize < 0) { - if (errno != EAGAIN && errno != EINTR) { - DHLOGW("could not get event (errno=%d)", errno); - } - } else if ((readSize % sizeof(struct input_event)) != 0) { - DHLOGW("could not get event (wrong size: %d)", readSize); - } else { - count = size_t(readSize) / sizeof(struct input_event); - return count; - } - return count; -} - -size_t InputHub::DeviceIsExists(InputDeviceEvent* buffer, size_t bufferSize) -{ - InputDeviceEvent* event = buffer; - size_t capacity = bufferSize; - // Report any devices that had last been added/removed. - for (auto it = closingDevices_.begin(); it != closingDevices_.end();) { - std::unique_ptr device = std::move(*it); - DHLOGI("Reporting device closed: id=%s, name=%s\n", GetAnonyInt32(device->id).c_str(), device->path.c_str()); - event->type = DeviceType::DEVICE_REMOVED; - event->deviceInfo = device->identifier; - event += 1; - it = closingDevices_.erase(it); - if (--capacity == 0) { - break; - } - } - if (needToScanDevices_) { - needToScanDevices_ = false; - ScanInputDevices(DEVICE_PATH); - } - while (!openingDevices_.empty()) { - std::unique_lock deviceLock(visitMutex_); - std::unique_ptr device = std::move(*openingDevices_.rbegin()); - openingDevices_.pop_back(); - DHLOGI("Reporting device opened: id=%s, name=%s\n", GetAnonyInt32(device->id).c_str(), device->path.c_str()); - event->type = DeviceType::DEVICE_ADDED; - event->deviceInfo = device->identifier; - event += 1; - - auto [dev_it, inserted] = devices_.insert_or_assign(device->id, std::move(device)); - if (!inserted) { - DHLOGI("Device id %s exists, replaced. \n", GetAnonyInt32(device->id).c_str()); - } - if (--capacity == 0) { - break; - } - } - return event - buffer; -} - -size_t InputHub::CollectInputHandler(InputDeviceEvent* buffer, size_t bufferSize) -{ - size_t count; - for (;;) { - count = DeviceIsExists(buffer, bufferSize); - deviceChanged_ = false; - GetDeviceHandler(); - - if (pendingINotify_ && pendingEventIndex_ >= pendingEventCount_) { - pendingINotify_ = false; - ReadNotifyLocked(); - deviceChanged_ = true; - } - - // Report added or removed devices immediately. - if (deviceChanged_) { - continue; - } - if (count > 0) { - break; - } - if (RefreshEpollItem() < 0) { - break; - } - } - - // All done, return the number of events we read. - return count; -} - -void InputHub::GetDeviceHandler() -{ - while (pendingEventIndex_ < pendingEventCount_) { - std::unique_lock my_lock(operationMutex_); - const struct epoll_event& eventItem = mPendingEventItems[pendingEventIndex_++]; - if (eventItem.data.fd == iNotifyFd_) { - if (eventItem.events & EPOLLIN) { - pendingINotify_ = true; - } else { - DHLOGI( - "Received unexpected epoll event 0x%08x for INotify.", eventItem.events); - } - continue; - } - - Device* device = GetDeviceByFdLocked(eventItem.data.fd); - if (!device) { - DHLOGE( - "Received unexpected epoll event 0x%08x for unknown fd %d.", - eventItem.events, eventItem.data.fd); - continue; - } - - if (eventItem.events & EPOLLHUP) { - DHLOGI("Removing device %s due to epoll hang-up event.", - device->identifier.name.c_str()); - deviceChanged_ = true; - CloseDeviceLocked(*device); - } - } -} - -int32_t InputHub::RefreshEpollItem() -{ - pendingEventIndex_ = 0; - int pollResult = epoll_wait(epollFd_, mPendingEventItems, EPOLL_MAX_EVENTS, 0); - if (pollResult == 0) { - // Timed out. - pendingEventCount_ = 0; - return ERR_DH_INPUT_HUB_EPOLL_WAIT_TIMEOUT; - } - - if (pollResult < 0) { - // An error occurred. - pendingEventCount_ = 0; - - // Sleep after errors to avoid locking up the system. - // Hopefully the error is transient. - if (errno != EINTR) { - DHLOGE("poll failed (errno=%d)\n", errno); - usleep(SLEEP_TIME); - } - } else { - // Some events occurred. - pendingEventCount_ = size_t(pollResult); - } - return DH_SUCCESS; -} - -std::vector InputHub::GetAllInputDevices() -{ - std::unique_lock deviceLock(visitMutex_); - std::vector vecDevice; - for (const auto& [id, device] : devices_) { - vecDevice.push_back(device->identifier); - } - return vecDevice; -} - -void InputHub::ScanInputDevices(const std::string& dirname) -{ - char devname[PATH_MAX]; - char *filename; - DIR *dir; - struct dirent *de; - dir = opendir(dirname.c_str()); - if (dir == nullptr) { - DHLOGE("error opendir dev/input :%{public}s\n", strerror(errno)); - return; - } - - if (strcpy_s(devname, PATH_MAX, dirname.c_str()) != 0) { - DHLOGE("error strcpy_s :%{public}s\n", strerror(errno)); - } - filename = devname + strlen(devname); - *filename++ = '/'; - while ((de = readdir(dir))) { - if (de->d_name[0] == '.' && - (de->d_name[1] == '\0' || - (de->d_name[1] == '.' && de->d_name[DIR_FILE_NAME_SECOND] == '\0'))) { - continue; - } - if (strcpy_s(filename, sizeof(de->d_name), de->d_name) != 0) { - DHLOGE("error strcpy_s second :%{public}s\n", strerror(errno)); - } - DHLOGE("scan dir failed for %{public}s", filename); - OpenInputDeviceLocked(devname); - } - closedir(dir); -} - -int32_t InputHub::OpenInputDeviceLocked(const std::string& devicePath) -{ - { - std::unique_lock deviceLock(visitMutex_); - for (const auto& [deviceId, device] : devices_) { - if (device->path == devicePath) { - return DH_SUCCESS; // device was already registered - } - } - } - - std::unique_lock my_lock(operationMutex_); - DHLOGI("Opening device: %s", devicePath.c_str()); - chmod(devicePath.c_str(), S_IWRITE | S_IREAD); - int fd = open(devicePath.c_str(), O_RDWR | O_CLOEXEC | O_NONBLOCK); - if (fd < 0) { - DHLOGE("could not open %s, %s\n", devicePath.c_str(), strerror(errno)); - return ERR_DH_INPUT_HUB_OPEN_DEVICEPATH_FAIL; - } - - InputDevice identifier; - if (MakeInputDevice(fd, identifier) < 0) { - return ERR_DH_INPUT_HUB_MAKE_INPUT_DEVICE_FAIL; - } - AssignDescriptorLocked(identifier); - - // Allocate device. (The device object takes ownership of the fd at this point.) - int32_t deviceId = nextDeviceId_++; - std::unique_ptr device = std::make_unique(fd, deviceId, devicePath, identifier); - - DHLOGI("add device %d: %s\n", deviceId, devicePath.c_str()); - DHLOGI(" bus: %04x\n" - " vendor %04x\n" - " product %04x\n" - " version %04x\n", - identifier.bus, identifier.vendor, identifier.product, identifier.version); - DHLOGI(" name: \"%s\"\n", identifier.name.c_str()); - DHLOGI(" location: \"%s\"\n", identifier.location.c_str()); - DHLOGI(" unique id: \"%s\"\n", identifier.uniqueId.c_str()); - DHLOGI(" descriptor: \"%s\"\n", identifier.descriptor.c_str()); - - if (MakeDevice(fd, std::move(device)) < 0) { - return ERR_DH_INPUT_HUB_MAKE_DEVICE_FAIL; - } - - return DH_SUCCESS; -} - -int32_t InputHub::MakeInputDevice(int fd, InputDevice& identifier) -{ - char buffer[80] = {}; - // Get device name. - if (ioctl(fd, EVIOCGNAME(sizeof(buffer) - 1), &buffer) < 1) { - DHLOGE( - "Could not get device name for %s", strerror(errno)); - } else { - buffer[sizeof(buffer) - 1] = '\0'; - identifier.name = buffer; - } - - // If the device is already a virtual device, don't monitor it. - if (identifier.name.find(VIRTUAL_DEVICE_NAME) != std::string::npos) { - return ERR_DH_INPUT_HUB_MAKE_INPUT_DEVICE_FAIL; - } - // Get device driver version. - int driverVersion; - if (ioctl(fd, EVIOCGVERSION, &driverVersion)) { - DHLOGE("could not get driver version for %s\n", strerror(errno)); - close(fd); - return ERR_DH_INPUT_HUB_MAKE_INPUT_DEVICE_FAIL; - } - // Get device identifier. - struct input_id inputId; - if (ioctl(fd, EVIOCGID, &inputId)) { - DHLOGE("could not get device input id for %s\n", strerror(errno)); - close(fd); - return ERR_DH_INPUT_HUB_MAKE_INPUT_DEVICE_FAIL; - } - identifier.bus = inputId.bustype; - identifier.product = inputId.product; - identifier.vendor = inputId.vendor; - identifier.version = inputId.version; - // Get device physical location. - if (ioctl(fd, EVIOCGPHYS(sizeof(buffer) - 1), &buffer) < 1) { - DHLOGE("could not get location for %s\n", strerror(errno)); - } else { - buffer[sizeof(buffer) - 1] = '\0'; - identifier.location = buffer; - } - // Get device unique id. - if (ioctl(fd, EVIOCGUNIQ(sizeof(buffer) - 1), &buffer) < 1) { - DHLOGE("could not get idstring for %s\n", strerror(errno)); - } else { - buffer[sizeof(buffer) - 1] = '\0'; - identifier.uniqueId = buffer; - } - - return DH_SUCCESS; -} - -int32_t InputHub::MakeDevice(int fd, std::unique_ptr device) -{ - // Figure out the kinds of events the device reports. - ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(device->keyBitmask)), device->keyBitmask); - ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(device->absBitmask)), device->absBitmask); - ioctl(fd, EVIOCGBIT(EV_REL, sizeof(device->relBitmask)), device->relBitmask); - - // See if this is a keyboard. - bool haveKeyboardKeys = ContainsNonZeroByte(device->keyBitmask, 0, SizeofBitArray(BTN_MISC)); - if (haveKeyboardKeys) { - device->classes |= INPUT_DEVICE_CLASS_KEYBOARD; - } - - // See if this is a cursor device such as a trackball or mouse. - if (TestBit(BTN_MOUSE, device->keyBitmask) - && TestBit(REL_X, device->relBitmask) - && TestBit(REL_Y, device->relBitmask)) { - device->classes |= INPUT_DEVICE_CLASS_CURSOR; - } - - // If the device isn't recognized as something we handle, don't monitor it. - if (device->classes == 0) { - DHLOGI("Dropping device: name='%s'", device->identifier.name.c_str()); - return ERR_DH_INPUT_HUB_MAKE_DEVICE_FAIL; - } - - if (RegisterDeviceForEpollLocked(*device) != DH_SUCCESS) { - return ERR_DH_INPUT_HUB_MAKE_DEVICE_FAIL; - } - - DHLOGI("New device: fd=%d, name='%s', classes=0x%x,", - fd, device->identifier.name.c_str(), device->classes); - device->identifier.classes = device->classes; - AddDeviceLocked(std::move(device)); - return DH_SUCCESS; -} - -void InputHub::AssignDescriptorLocked(InputDevice& identifier) -{ - identifier.nonce = 0; - std::string rawDescriptor = GenerateDescriptor(identifier); - if (identifier.uniqueId.empty()) { - // If it didn't have a unique id check for conflicts and enforce - // uniqueness if necessary. - while (GetDeviceByDescriptorLocked(identifier.descriptor) != nullptr) { - identifier.nonce++; - rawDescriptor = GenerateDescriptor(identifier); - } - } - DHLOGI( - "Created descriptor: raw=%s, cooked=%s", rawDescriptor.c_str(), - identifier.descriptor.c_str()); -} - -std::string InputHub::StringPrintf(const char* format, ...) const -{ - static const int kSpaceLength = 1024; - char space[kSpaceLength]; - - va_list ap; - va_start(ap, format); - std::string result; - int ret = vsnprintf_s(space, sizeof(space), sizeof(space) - 1, format, ap); - if (ret >= DH_SUCCESS && ret < sizeof(space)) { - result = space; - } else { - return "the buffer is overflow!"; - } - va_end(ap); - return result; -} - -std::string InputHub::Sha256(const std::string& in) const -{ - SHA256_CTX ctx; - SHA256_Init(&ctx); - SHA256_Update(&ctx, reinterpret_cast(in.c_str()), in.size()); - u_char digest[SHA_DIGEST_LENGTH]; - SHA256_Final(digest, &ctx); - - std::string out; - for (size_t i = 0; i < SHA_DIGEST_LENGTH; i++) { - out += StringPrintf("%02x", digest[i]); - } - return out; -} - -std::string InputHub::GenerateDescriptor(InputDevice& identifier) const -{ - std::string rawDescriptor; - rawDescriptor += StringPrintf(":%04x:%04x:", identifier.vendor, - identifier.product); - // add handling for USB devices to not uniqueify kbs that show up twice - if (!identifier.uniqueId.empty()) { - rawDescriptor += "uniqueId:"; - rawDescriptor += identifier.uniqueId; - } else if (identifier.nonce != 0) { - rawDescriptor += StringPrintf("nonce:%04x", identifier.nonce); - } - - if (identifier.vendor == 0 && identifier.product == 0) { - // If we don't know the vendor and product id, then the device is probably - // built-in so we need to rely on other information to uniquely identify - // the input device. Usually we try to avoid relying on the device name or - // location but for built-in input device, they are unlikely to ever change. - if (!identifier.name.empty()) { - rawDescriptor += "name:"; - rawDescriptor += identifier.name; - } else if (!identifier.location.empty()) { - rawDescriptor += "location:"; - rawDescriptor += identifier.location; - } - } - identifier.descriptor = Sha256(rawDescriptor); - return rawDescriptor; -} - -int32_t InputHub::RegisterDeviceForEpollLocked(const Device& device) -{ - int32_t result = RegisterFdForEpoll(device.fd); - if (result != DH_SUCCESS) { - DHLOGE("Could not add input device fd to epoll for device %d", device.id); - return result; - } - return result; -} - -int32_t InputHub::RegisterFdForEpoll(int fd) -{ - struct epoll_event eventItem = {}; - eventItem.events = EPOLLIN | EPOLLWAKEUP; - eventItem.data.fd = fd; - if (epoll_ctl(epollFd_, EPOLL_CTL_ADD, fd, &eventItem)) { - DHLOGE( - "Could not add fd to epoll instance: %s", strerror(errno)); - return -errno; - } - return DH_SUCCESS; -} - -void InputHub::AddDeviceLocked(std::unique_ptr device) -{ - std::unique_lock deviceLock(visitMutex_); - openingDevices_.push_back(std::move(device)); -} - -void InputHub::CloseDeviceLocked(Device& device) -{ - DHLOGI( - "Removed device: path=%s name=%s id=%s fd=%d classes=0x%x", - device.path.c_str(), device.identifier.name.c_str(), GetAnonyInt32(device.id).c_str(), - device.fd, device.classes); - - UnregisterDeviceFromEpollLocked(device); - device.Close(); - std::unique_lock deviceLock(visitMutex_); - closingDevices_.push_back(std::move(devices_[device.id])); - devices_.erase(device.id); -} - -int32_t InputHub::UnregisterDeviceFromEpollLocked(const Device& device) const -{ - if (device.HasValidFd()) { - int32_t result = UnregisterFdFromEpoll(device.fd); - if (result != DH_SUCCESS) { - DHLOGE( - "Could not remove input device fd from epoll for device %s", GetAnonyInt32(device.id).c_str()); - return result; - } - } - return DH_SUCCESS; -} - -int32_t InputHub::UnregisterFdFromEpoll(int fd) const -{ - if (epoll_ctl(epollFd_, EPOLL_CTL_DEL, fd, nullptr)) { - DHLOGE( - "Could not remove fd from epoll instance: %s", strerror(errno)); - return ERR_DH_INPUT_HUB_UNREGISTER_FD_FAIL; - } - return DH_SUCCESS; -} - -int32_t InputHub::ReadNotifyLocked() -{ - int res; - char event_buf[512]; - int event_size; - int event_pos = 0; - struct inotify_event *event; - - DHLOGI("readNotify nfd: %d\n", iNotifyFd_); - res = read(iNotifyFd_, event_buf, sizeof(event_buf)); - if (res < (int)sizeof(*event)) { - if (errno == EINTR) - return DH_SUCCESS; - DHLOGE("could not get event, %s\n", strerror(errno)); - return ERR_DH_INPUT_HUB_GET_EVENT_FAIL; - } - - while (res >= (int) sizeof(*event)) { - event = (struct inotify_event *)(event_buf + event_pos); - JudgeDeviceOpenOrClose(*event); - event_size = sizeof(*event) + event->len; - res -= event_size; - event_pos += event_size; - } - return DH_SUCCESS; -} - -void InputHub::JudgeDeviceOpenOrClose(const inotify_event& event) -{ - if (event.len) { - if (event.wd == inputWd_) { - std::string filename = std::string(DEVICE_PATH) + "/" + event.name; - if (event.mask & IN_CREATE) { - OpenInputDeviceLocked(filename); - } else { - DHLOGI( - "Removing device '%s' due to inotify event\n", filename.c_str()); - CloseDeviceByPathLocked(filename); - } - } else { - DHLOGI("Unexpected inotify event, wd = %i", event.wd); - } - } -} - -void InputHub::CloseDeviceByPathLocked(const std::string& devicePath) -{ - Device* device = GetDeviceByPathLocked(devicePath); - if (device) { - CloseDeviceLocked(*device); - return; - } - DHLOGI( - "Remove device: %s not found, device may already have been removed.", devicePath.c_str()); -} - -void InputHub::CloseAllDevicesLocked() -{ - while (!devices_.empty()) { - CloseDeviceLocked(*(devices_.begin()->second)); - } -} - -InputHub::Device* InputHub::GetDeviceByDescriptorLocked(const std::string& descriptor) -{ - std::unique_lock deviceLock(visitMutex_); - for (const auto& [id, device] : devices_) { - if (descriptor == device->identifier.descriptor) { - return device.get(); - } - } - return nullptr; -} - -InputHub::Device* InputHub::GetDeviceByPathLocked(const std::string& devicePath) -{ - std::unique_lock deviceLock(visitMutex_); - for (const auto& [id, device] : devices_) { - if (device->path == devicePath) { - return device.get(); - } - } - return nullptr; -} - -InputHub::Device* InputHub::GetDeviceByFdLocked(int fd) -{ - std::unique_lock deviceLock(visitMutex_); - for (const auto& [id, device] : devices_) { - if (device->fd == fd) { - return device.get(); - } - } - return nullptr; -} - -InputHub::Device* InputHub::GetDeviceByFd(int fd) -{ - std::unique_lock deviceLock(visitMutex_); - for (const auto& [id, device] : devices_) { - if (device->fd == fd) { - if (GetIsSupportInputTypes(device->classes)) { - return device.get(); - } - } - } - return nullptr; -} - -bool InputHub::ContainsNonZeroByte(const uint8_t* array, uint32_t startIndex, uint32_t endIndex) -{ - const uint8_t* end = array + endIndex; - array += startIndex; - while (array != end) { - if (*(array++) != 0) { - return true; - } - } - return false; -} - -int64_t InputHub::ProcessEventTimestamp(const input_event& event) -{ - const int64_t inputEventTime = event.input_event_sec * 1000000000LL + event.input_event_usec * 1000LL; - return inputEventTime; -} - -bool InputHub::TestBit(uint32_t bit, const uint8_t* array) -{ - constexpr int units = 8; - return (array)[(bit) / units] & (1 << ((bit) % units)); -} - -uint32_t InputHub::SizeofBitArray(uint32_t bit) -{ - constexpr int round = 7; - constexpr int divisor = 8; - return ((bit) + round) / divisor; -} - -bool InputHub::GetIsSupportInputTypes(uint32_t classes) -{ - return classes & input_types_; -} -void InputHub::SetSupportInputType(const uint32_t& inputTypes) -{ - input_types_ = inputTypes; - DHLOGI("SetSupportInputType: inputTypes=0x%x,", input_types_); -} - -InputHub::Device::Device(int fd, int32_t id, const std::string& path, - const InputDevice& identifier) : next(nullptr), fd(fd), id(id), path(path), identifier(identifier), - classes(0), enabled(true), isVirtual(fd < 0) { - memset_s(keyBitmask, sizeof(keyBitmask), 0, sizeof(keyBitmask)); - memset_s(absBitmask, sizeof(absBitmask), 0, sizeof(absBitmask)); - memset_s(relBitmask, sizeof(relBitmask), 0, sizeof(relBitmask)); -} - -InputHub::Device::~Device() -{ - Close(); -} - -void InputHub::Device::Close() -{ - if (fd >= 0) { - ::close(fd); - fd = -1; - } -} - -int32_t InputHub::Device::Enable() -{ - chmod(path.c_str(), S_IWRITE | S_IREAD); - fd = open(path.c_str(), O_RDWR | O_CLOEXEC | O_NONBLOCK); - if (fd < 0) { - DHLOGE("could not open %s, %s\n", path.c_str(), strerror(errno)); - return ERR_DH_INPUT_HUB_DEVICE_ENABLE_FAIL; - } - enabled = true; - return DH_SUCCESS; -} - -int32_t InputHub::Device::Disable() -{ - Close(); - enabled = false; - return DH_SUCCESS; -} - -bool InputHub::Device::HasValidFd() const -{ - return !isVirtual && enabled; -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/common/include/input_hub.h b/common/include/input_hub.h deleted file mode 100644 index e4b4e89..0000000 --- a/common/include/input_hub.h +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef INPUT_HUB_H -#define INPUT_HUB_H - -#include -#include - -#include -#include - -#include - -#include "constants_dinput.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class InputHub { -public: - InputHub(); - ~InputHub(); - size_t CollectInputEvents(RawEvent* buffer, size_t bufferSize); - size_t CollectInputHandler(InputDeviceEvent* buffer, size_t bufferSize); - size_t DeviceIsExists(InputDeviceEvent* event, size_t capacity); - std::vector GetAllInputDevices(); - void SetSupportInputType(const uint32_t& inputType); -private: - struct Device { - Device* next; - int fd; // may be -1 if device is closed - const int32_t id; - const std::string path; - InputDevice identifier; - uint32_t classes; - uint8_t keyBitmask[(KEY_MAX + 1) / 8]; - uint8_t absBitmask[(ABS_MAX + 1) / 8]; - uint8_t relBitmask[(REL_MAX + 1) / 8]; - - Device(int fd, int32_t id, const std::string& path, - const InputDevice& identifier); - ~Device(); - void Close(); - bool enabled; // initially true - int32_t Enable(); - int32_t Disable(); - bool HasValidFd() const; - const bool isVirtual; // set if fd < 0 is passed to constructor - }; - - int32_t Initialize(); - int32_t Release(); - - size_t GetEvents(RawEvent* buffer, size_t bufferSize); - size_t ReadInputEvent(int32_t readSize, Device& device); - void GetDeviceHandler(); - int32_t RefreshEpollItem(); - - void ScanInputDevices(const std::string& dirname); - int32_t OpenInputDeviceLocked(const std::string& devicePath); - int32_t MakeInputDevice(int fd, InputDevice& identifier); - int32_t MakeDevice(int fd, std::unique_ptr device); - void AssignDescriptorLocked(InputDevice& identifier); - std::string GenerateDescriptor(InputDevice& identifier) const; - std::string StringPrintf(const char* format, ...) const; - std::string Sha256(const std::string& in) const; - - int32_t RegisterFdForEpoll(int fd); - int32_t RegisterDeviceForEpollLocked(const Device& device); - void AddDeviceLocked(std::unique_ptr device); - void CloseDeviceLocked(Device& device); - int32_t UnregisterDeviceFromEpollLocked(const Device& device) const; - int32_t UnregisterFdFromEpoll(int fd) const; - int32_t ReadNotifyLocked(); - void CloseDeviceByPathLocked(const std::string& devicePath); - void CloseAllDevicesLocked(); - void JudgeDeviceOpenOrClose(const inotify_event& event); - Device* GetDeviceByDescriptorLocked(const std::string& descriptor); - Device* GetDeviceByPathLocked(const std::string& devicePath); - Device* GetDeviceByFdLocked(int fd); - Device* GetDeviceByFd(int fd); - - bool ContainsNonZeroByte(const uint8_t* array, uint32_t startIndex, uint32_t endIndex); - int64_t ProcessEventTimestamp(const input_event& event); - /* this macro is used to tell if "bit" is set in "array" - * it selects a byte from the array, and does a boolean AND - * operation with a byte that only has the relevant bit set. - * eg. to check for the 12th bit, we do (array[1] & 1<<4) - */ - bool TestBit(uint32_t bit, const uint8_t* array); - /* this macro computes the number of bytes needed to represent a bit array of the specified size */ - uint32_t SizeofBitArray(uint32_t bit); - bool GetIsSupportInputTypes(uint32_t classes); - - int epollFd_; - int iNotifyFd_; - int inputWd_; - - std::vector> openingDevices_; - std::vector> closingDevices_; - std::unordered_map> devices_; - bool needToScanDevices_; - std::string deviceId_; - int32_t nextDeviceId_; - - // Maximum number of signalled FDs to handle at a time. - static const int EPOLL_MAX_EVENTS = 16; - static const int SLEEP_TIME = 100000; - // The array of pending epoll events and the index of the next event to be handled. - struct epoll_event mPendingEventItems[EPOLL_MAX_EVENTS]; - size_t pendingEventCount_; - size_t pendingEventIndex_; - bool pendingINotify_; - std::mutex operationMutex_; - std::mutex visitMutex_; - bool deviceChanged_; - uint32_t input_types_; - - static const int DIR_FILE_NAME_SECOND = 2; - static const int MOVE_POSITION_SIXTEEN = 16; - static const int DRIVER_VERSION_MOVE = 8; - static const uint16_t DRIVER_VERSION_MAX = 0xff; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - -#endif // INPUT_HUB_H diff --git a/common/include/test/BUILD.gn b/common/include/test/BUILD.gn deleted file mode 100644 index c4446c3..0000000 --- a/common/include/test/BUILD.gn +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -group("test") { - testonly = true - - deps = [ "whitelistunittest:whitelistunittest" ] -} diff --git a/common/include/test/whitelistunittest/BUILD.gn b/common/include/test/whitelistunittest/BUILD.gn deleted file mode 100644 index 570a9b8..0000000 --- a/common/include/test/whitelistunittest/BUILD.gn +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/test.gni") -import("//foundation/distributedhardware/distributedinput/distributedinput.gni") -module_out_path = "distributedinput_stander/white_list_test" - -group("whitelistunittest") { - testonly = true - - deps = [ ":distributed_input_white_list_test" ] -} - -## UnitTest distributed_input_manager_service_test {{{ -ohos_unittest("distributed_input_white_list_test") { - module_out_path = module_out_path - - include_dirs = [ - "${innerkits_path}/include", - "${innerkits_path}/src", - "${ipc_path}/include", - "${ipc_path}/src", - "//foundation/distributedhardware/distributedinput/services/sink/transport/include", - "//foundation/distributedhardware/distributedinput/frameworks/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${common_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${service_common}/include", - "//third_party/json/include", - "//foundation/communication/dsoftbus/interfaces/kits/transport", - ] - - sources = [ - "${common_path}/include/white_list_util.cpp", - "white_list_test.cpp", - ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", - "-Dprivate=public", - "-Dprotected=public", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedinpututtest\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "//foundation/bundlemanager/bundle_framework/interfaces/innerkits/libeventhandler:libeventhandler", - "//utils/native/base:utils", - "${fwk_utils_path}:distributedhardwareutils", - "//foundation/communication/dsoftbus/sdk:softbus_client", - ] - - external_deps = [ - "ipc:ipc_core", - "safwk:system_ability_fwk", - "hiviewdfx_hilog_native:libhilog", - "samgr_standard:samgr_proxy", - ] - - cflags_cc = [ "-DHILOG_ENABLE" ] -} - -## UnitTest distributed_input_manager_service_test }}} diff --git a/common/include/test/whitelistunittest/white_list_test.cpp b/common/include/test/whitelistunittest/white_list_test.cpp deleted file mode 100644 index a90492c..0000000 --- a/common/include/test/whitelistunittest/white_list_test.cpp +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "white_list_test.h" -#include "constants_dinput.h" -#include "dinput_errcode.h" -#include "white_list_util.h" - -using namespace testing::ext; -using namespace OHOS::DistributedHardware::DistributedInput; -using namespace std; - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -void WhiteListTest::SetUp() -{ -} - -void WhiteListTest::TearDown() -{ -} - -void WhiteListTest::SetUpTestCase() -{ -} - -void WhiteListTest::TearDownTestCase() -{ -} - -HWTEST_F(WhiteListTest, Init01, testing::ext::TestSize.Level0) -{ - std::string deviceId = "whitelist"; - int32_t ret = WhiteListUtil::GetInstance().Init(deviceId); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(WhiteListTest, Init02, testing::ext::TestSize.Level0) -{ - std::string deviceId; - int32_t ret = WhiteListUtil::GetInstance().Init(deviceId); - EXPECT_EQ(ERR_DH_INPUT_WHILTELIST_INIT_FAIL, ret); -} - -HWTEST_F(WhiteListTest, Init03, testing::ext::TestSize.Level0) -{ - std::string deviceId = "test"; - int32_t ret = WhiteListUtil::GetInstance().Init(deviceId); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(WhiteListTest, SyncWhiteList01, testing::ext::TestSize.Level0) -{ - // 11|22,33|44,55,66 - // 1,2|3,4,5 - std::string deviceId = "test"; - TYPE_KEY_CODE_VEC vecKeyCode; - TYPE_COMBINATION_KEY_VEC vecCombinationKey; - TYPE_WHITE_LIST_VEC vecWhiteList; - vecKeyCode.push_back(11); - vecKeyCode.push_back(22); - vecCombinationKey.push_back(vecKeyCode); - vecKeyCode.clear(); - vecKeyCode.push_back(33); - vecKeyCode.push_back(44); - vecCombinationKey.push_back(vecKeyCode); - vecKeyCode.clear(); - vecKeyCode.push_back(55); - vecCombinationKey.push_back(vecKeyCode); - vecKeyCode.clear(); - vecKeyCode.push_back(66); - vecCombinationKey.push_back(vecKeyCode); - vecWhiteList.push_back(vecCombinationKey); - vecKeyCode.clear(); - vecCombinationKey.clear(); - int32_t ret = WhiteListUtil::GetInstance().SyncWhiteList(deviceId, vecWhiteList); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(WhiteListTest, SyncWhiteList02, testing::ext::TestSize.Level0) -{ - // 11|22,33|44,55,66 - // 1,2|3,4,5 - std::string deviceId = "test1"; - TYPE_KEY_CODE_VEC vecKeyCode; - TYPE_COMBINATION_KEY_VEC vecCombinationKey; - TYPE_WHITE_LIST_VEC vecWhiteList; - - vecKeyCode.push_back(1); - vecCombinationKey.push_back(vecKeyCode); - vecKeyCode.clear(); - vecKeyCode.push_back(2); - vecKeyCode.push_back(3); - vecCombinationKey.push_back(vecKeyCode); - vecKeyCode.clear(); - vecKeyCode.push_back(4); - vecCombinationKey.push_back(vecKeyCode); - vecKeyCode.clear(); - vecKeyCode.push_back(5); - vecCombinationKey.push_back(vecKeyCode); - vecWhiteList.push_back(vecCombinationKey); - vecKeyCode.clear(); - vecCombinationKey.clear(); - int32_t ret = WhiteListUtil::GetInstance().SyncWhiteList(deviceId, vecWhiteList); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(WhiteListTest, SyncWhiteList03, testing::ext::TestSize.Level0) -{ - // 1,2,1,2 - std::string deviceId = "test1"; - TYPE_KEY_CODE_VEC vecKeyCode; - TYPE_COMBINATION_KEY_VEC vecCombinationKey; - TYPE_WHITE_LIST_VEC vecWhiteList; - - vecKeyCode.push_back(1); - vecCombinationKey.push_back(vecKeyCode); - vecKeyCode.clear(); - vecKeyCode.push_back(2); - vecCombinationKey.push_back(vecKeyCode); - vecKeyCode.clear(); - vecKeyCode.push_back(1); - vecCombinationKey.push_back(vecKeyCode); - vecKeyCode.clear(); - vecKeyCode.push_back(2); - vecCombinationKey.push_back(vecKeyCode); - vecWhiteList.push_back(vecCombinationKey); - vecKeyCode.clear(); - vecCombinationKey.clear(); - int32_t ret = WhiteListUtil::GetInstance().SyncWhiteList(deviceId, vecWhiteList); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(WhiteListTest, SyncWhiteList04, testing::ext::TestSize.Level0) -{ - // 2,8|3,4,5 - std::string deviceId = "test1"; - TYPE_KEY_CODE_VEC vecKeyCode; - TYPE_COMBINATION_KEY_VEC vecCombinationKey; - TYPE_WHITE_LIST_VEC vecWhiteList; - vecKeyCode.push_back(2); - vecCombinationKey.push_back(vecKeyCode); - vecKeyCode.clear(); - vecKeyCode.push_back(8); - vecKeyCode.push_back(3); - vecCombinationKey.push_back(vecKeyCode); - vecKeyCode.clear(); - vecKeyCode.push_back(4); - vecCombinationKey.push_back(vecKeyCode); - vecKeyCode.clear(); - vecKeyCode.push_back(5); - vecCombinationKey.push_back(vecKeyCode); - vecWhiteList.push_back(vecCombinationKey); - vecKeyCode.clear(); - vecCombinationKey.clear(); - int32_t ret = WhiteListUtil::GetInstance().SyncWhiteList(deviceId, vecWhiteList); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(WhiteListTest, GetWhiteList01, testing::ext::TestSize.Level0) -{ - std::string deviceId = "test"; - TYPE_WHITE_LIST_VEC vecWhiteList; - int32_t ret = WhiteListUtil::GetInstance().GetWhiteList(deviceId, vecWhiteList); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(WhiteListTest, GetWhiteList02, testing::ext::TestSize.Level0) -{ - std::string deviceId = "test1"; - TYPE_WHITE_LIST_VEC vecWhiteList; - int32_t ret = WhiteListUtil::GetInstance().GetWhiteList(deviceId, vecWhiteList); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(WhiteListTest, GetWhiteList03, testing::ext::TestSize.Level0) -{ - std::string deviceId = "xxx"; - TYPE_WHITE_LIST_VEC vecWhiteList; - int32_t ret = WhiteListUtil::GetInstance().GetWhiteList(deviceId, vecWhiteList); - EXPECT_EQ(ERR_DH_INPUT_WHILTELIST_GET_WHILTELIST_FAIL, ret); -} - -HWTEST_F(WhiteListTest, GetWhiteList04, testing::ext::TestSize.Level0) -{ - std::string deviceId = ""; - TYPE_WHITE_LIST_VEC vecWhiteList; - int32_t ret = WhiteListUtil::GetInstance().GetWhiteList(deviceId, vecWhiteList); - EXPECT_EQ(ERR_DH_INPUT_WHILTELIST_GET_WHILTELIST_FAIL, ret); -} - -HWTEST_F(WhiteListTest, IsNeedFilterOut01, testing::ext::TestSize.Level0) -{ - // 11,33,55,66 - std::string deviceId = "test"; - BusinessEvent event; - event.pressedKeys.push_back(11); - event.pressedKeys.push_back(33); - event.keyCode = 55; - event.keyAction = 66; - bool ret = WhiteListUtil::GetInstance().IsNeedFilterOut(deviceId, event); - EXPECT_EQ(true, ret); -} - -HWTEST_F(WhiteListTest, IsNeedFilterOut02, testing::ext::TestSize.Level0) -{ - // 11,44,55,66 - std::string deviceId = "test"; - BusinessEvent event; - event.pressedKeys.push_back(11); - event.pressedKeys.push_back(44); - event.keyCode = 55; - event.keyAction = 66; - bool ret = WhiteListUtil::GetInstance().IsNeedFilterOut(deviceId, event); - EXPECT_EQ(true, ret); -} - -HWTEST_F(WhiteListTest, IsNeedFilterOut03, testing::ext::TestSize.Level0) -{ - // 22,33,55,66 - std::string deviceId = "test"; - BusinessEvent event; - event.pressedKeys.push_back(22); - event.pressedKeys.push_back(33); - event.keyCode = 55; - event.keyAction = 66; - bool ret = WhiteListUtil::GetInstance().IsNeedFilterOut(deviceId, event); - EXPECT_EQ(true, ret); -} - -HWTEST_F(WhiteListTest, IsNeedFilterOut04, testing::ext::TestSize.Level0) -{ - // 22,44,55,66 - std::string deviceId = "test"; - BusinessEvent event; - event.pressedKeys.push_back(22); - event.pressedKeys.push_back(44); - event.keyCode = 55; - event.keyAction = 66; - bool ret = WhiteListUtil::GetInstance().IsNeedFilterOut(deviceId, event); - EXPECT_EQ(true, ret); -} - -HWTEST_F(WhiteListTest, IsNeedFilterOut05, testing::ext::TestSize.Level0) -{ - // 1,2,4,5 - std::string deviceId = "test"; - BusinessEvent event; - event.pressedKeys.push_back(1); - event.pressedKeys.push_back(2); - event.keyCode = 4; - event.keyAction = 5; - bool ret = WhiteListUtil::GetInstance().IsNeedFilterOut(deviceId, event); - EXPECT_EQ(false, ret); -} - -HWTEST_F(WhiteListTest, IsNeedFilterOut06, testing::ext::TestSize.Level0) -{ - // 1,3,4,5 - std::string deviceId = "test"; - BusinessEvent event; - event.pressedKeys.push_back(1); - event.pressedKeys.push_back(3); - event.keyCode = 4; - event.keyAction = 5; - bool ret = WhiteListUtil::GetInstance().IsNeedFilterOut(deviceId, event); - EXPECT_EQ(false, ret); -} - -HWTEST_F(WhiteListTest, IsNeedFilterOut07, testing::ext::TestSize.Level0) -{ - // 2,2,4,5 - std::string deviceId = "test"; - BusinessEvent event; - event.pressedKeys.push_back(2); - event.pressedKeys.push_back(2); - event.keyCode = 4; - event.keyAction = 5; - bool ret = WhiteListUtil::GetInstance().IsNeedFilterOut(deviceId, event); - EXPECT_EQ(false, ret); -} - -HWTEST_F(WhiteListTest, IsNeedFilterOut08, testing::ext::TestSize.Level0) -{ - // 1,1,4,5 - std::string deviceId = "test"; - BusinessEvent event; - event.pressedKeys.push_back(1); - event.pressedKeys.push_back(1); - event.keyCode = 4; - event.keyAction = 5; - bool ret = WhiteListUtil::GetInstance().IsNeedFilterOut(deviceId, event); - EXPECT_EQ(false, ret); -} - -HWTEST_F(WhiteListTest, IsNeedFilterOut09, testing::ext::TestSize.Level0) -{ - // 1,2,1,5 - std::string deviceId = "test"; - BusinessEvent event; - event.pressedKeys.push_back(1); - event.pressedKeys.push_back(2); - event.keyCode = 1; - event.keyAction = 5; - bool ret = WhiteListUtil::GetInstance().IsNeedFilterOut(deviceId, event); - EXPECT_EQ(false, ret); -} - -HWTEST_F(WhiteListTest, IsNeedFilterOut10, testing::ext::TestSize.Level0) -{ - // 1,2,4,1 - std::string deviceId = "test"; - BusinessEvent event; - event.pressedKeys.push_back(1); - event.pressedKeys.push_back(2); - event.keyCode = 4; - event.keyAction = 1; - bool ret = WhiteListUtil::GetInstance().IsNeedFilterOut(deviceId, event); - EXPECT_EQ(false, ret); -} - -HWTEST_F(WhiteListTest, IsNeedFilterOut11, testing::ext::TestSize.Level0) -{ - // 1,2,4,5,6 - std::string deviceId = "test"; - BusinessEvent event; - event.pressedKeys.push_back(1); - event.pressedKeys.push_back(2); - event.pressedKeys.push_back(4); - event.keyCode = 5; - event.keyAction = 6; - bool ret = WhiteListUtil::GetInstance().IsNeedFilterOut(deviceId, event); - EXPECT_EQ(false, ret); -} - -HWTEST_F(WhiteListTest, ClearWhiteList01, testing::ext::TestSize.Level0) -{ - std::string deviceId = "test"; - int32_t ret = WhiteListUtil::GetInstance().ClearWhiteList(deviceId); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(WhiteListTest, ClearWhiteList02, testing::ext::TestSize.Level0) -{ - std::string deviceId = "test1"; - int32_t ret = WhiteListUtil::GetInstance().ClearWhiteList(deviceId); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(WhiteListTest, ClearWhiteList03, testing::ext::TestSize.Level0) -{ - std::string deviceId; - int32_t ret = WhiteListUtil::GetInstance().ClearWhiteList(deviceId); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(WhiteListTest, UnInit01, testing::ext::TestSize.Level0) -{ - int32_t ret = WhiteListUtil::GetInstance().UnInit(); - EXPECT_EQ(SUCCESS, ret); -} -} -} -} \ No newline at end of file diff --git a/common/include/test/whitelistunittest/white_list_test.h b/common/include/test/whitelistunittest/white_list_test.h deleted file mode 100644 index 4cdea36..0000000 --- a/common/include/test/whitelistunittest/white_list_test.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef WHITE_LIST_TEST_H -#define WHITE_LIST_TEST_H - -#include - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class WhiteListTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS -#endif // WHITE_LIST_TEST_H diff --git a/common/include/white_list_util.cpp b/common/include/white_list_util.cpp deleted file mode 100644 index cf9f51a..0000000 --- a/common/include/white_list_util.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "white_list_util.h" - -#include -#include -#include - -#include "anonymous_string.h" -#include "distributed_hardware_log.h" - -#include "dinput_errcode.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -namespace { - const char *g_filepath = "/system/profile/dinput_business_event_whitelist.cfg"; - const char *g_splitSymbol1 = ","; - const char *g_splitSymbol2 = "|"; -} - -WhiteListUtil::WhiteListUtil() -{ -} - -WhiteListUtil::~WhiteListUtil() -{ -} - -WhiteListUtil &WhiteListUtil::GetInstance(void) -{ - static WhiteListUtil instance; - return instance; -} - -int32_t WhiteListUtil::Init(const std::string &deviceId) -{ - DHLOGI("start, deviceId=%s", GetAnonyString(deviceId).c_str()); - ClearWhiteList(); - - if (deviceId.empty()) { - // device id error - DHLOGE("%s error, deviceId empty", __func__); - return ERR_DH_INPUT_WHILTELIST_INIT_FAIL; - } - - std::ifstream inFile(g_filepath, std::ios::in | std::ios::binary); - if (!inFile.is_open()) { - // file open error - DHLOGE("%s error, file open fail path=%s", __func__, g_filepath); - return ERR_DH_INPUT_WHILTELIST_INIT_FAIL; - } - - TYPE_KEY_CODE_VEC vecKeyCode; - TYPE_COMBINATION_KEY_VEC vecCombinationKey; - TYPE_WHITE_LIST_VEC vecWhiteList; - - std::string line; - while (getline(inFile, line)) { - DHLOGI("%s called success, line=%s", __func__, line.c_str()); - - vecKeyCode.clear(); - vecCombinationKey.clear(); - - std::size_t pos1 = line.find(g_splitSymbol1); - while (std::string::npos != pos1) { - std::string column = line.substr(0, pos1); - line = line.substr(pos1 + 1, line.size()); - pos1 = line.find(g_splitSymbol1); - vecKeyCode.clear(); - ReadLineDataStepOne(column, vecKeyCode, vecCombinationKey); - } - - if (!line.empty()) { - int32_t keyCode = std::stoi(line); - if (keyCode) { - vecKeyCode.push_back(keyCode); - } - - if (!vecKeyCode.empty()) { - vecCombinationKey.push_back(vecKeyCode); - vecKeyCode.clear(); - } - } - - if (!vecCombinationKey.empty()) { - vecWhiteList.push_back(vecCombinationKey); - vecCombinationKey.clear(); - } - } - - inFile.close(); - - std::lock_guard lock(mutex_); - mapDeviceWhiteList_[deviceId] = vecWhiteList; - - DHLOGI("success, deviceId=%s", GetAnonyString(deviceId).c_str()); - return DH_SUCCESS; -} - -int32_t WhiteListUtil::UnInit(void) -{ - DHLOGI("%s called", __func__); - ClearWhiteList(); - return DH_SUCCESS; -} - -void WhiteListUtil::ReadLineDataStepOne(std::string &column, TYPE_KEY_CODE_VEC &vecKeyCode, - TYPE_COMBINATION_KEY_VEC &vecCombinationKey) const -{ - std::size_t pos2 = column.find(g_splitSymbol2); - while (std::string::npos != pos2) { - std::string single = column.substr(0, pos2); - column = column.substr(pos2 + 1, column.size()); - pos2 = column.find(g_splitSymbol2); - - if (!single.empty()) { - int32_t keyCode = std::stoi(single); - if (keyCode) { - vecKeyCode.push_back(keyCode); - } - } - } - - if (!column.empty()) { - int32_t keyCode = std::stoi(column); - if (keyCode) { - vecKeyCode.push_back(keyCode); - } - } - - if (!vecKeyCode.empty()) { - vecCombinationKey.push_back(vecKeyCode); - vecKeyCode.clear(); - } -} - -int32_t WhiteListUtil::SyncWhiteList(const std::string &deviceId, const TYPE_WHITE_LIST_VEC &vecWhiteList) -{ - DHLOGI("deviceId=%s", GetAnonyString(deviceId).c_str()); - - std::lock_guard lock(mutex_); - mapDeviceWhiteList_[deviceId] = vecWhiteList; - return DH_SUCCESS; -} - -int32_t WhiteListUtil::ClearWhiteList(const std::string &deviceId) -{ - DHLOGI("deviceId=%s", GetAnonyString(deviceId).c_str()); - - std::lock_guard lock(mutex_); - mapDeviceWhiteList_.erase(deviceId); - return DH_SUCCESS; -} - -int32_t WhiteListUtil::ClearWhiteList(void) -{ - std::lock_guard lock(mutex_); - TYPE_DEVICE_WHITE_LIST_MAP().swap(mapDeviceWhiteList_); - return DH_SUCCESS; -} - -int32_t WhiteListUtil::GetWhiteList(const std::string &deviceId, TYPE_WHITE_LIST_VEC &vecWhiteList) -{ - DHLOGI("start, deviceId=%s", GetAnonyString(deviceId).c_str()); - - std::lock_guard lock(mutex_); - TYPE_DEVICE_WHITE_LIST_MAP::iterator iter = mapDeviceWhiteList_.find(deviceId); - if (iter != mapDeviceWhiteList_.end()) { - vecWhiteList = iter->second; - DHLOGI("GetWhiteList success, deviceId=%s", GetAnonyString(deviceId).c_str()); - return DH_SUCCESS; - } - - DHLOGI("GetWhiteList fail, deviceId=%s", GetAnonyString(deviceId).c_str()); - return ERR_DH_INPUT_WHILTELIST_GET_WHILTELIST_FAIL; -} - -bool WhiteListUtil::CheckSubVecData(const TYPE_COMBINATION_KEY_VEC::iterator &iter2, - const TYPE_KEY_CODE_VEC::iterator &iter3) const -{ - bool bIsMatching = false; - for (TYPE_KEY_CODE_VEC::iterator iter4 = iter2->begin(); iter4 != iter2->end(); ++iter4) { - if (*iter4 == *iter3) { - bIsMatching = true; - break; - } - } - return bIsMatching; -} - -bool WhiteListUtil::IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event) -{ - DHLOGI("start, deviceId=%s", GetAnonyString(deviceId).c_str()); - - std::lock_guard lock(mutex_); - if (mapDeviceWhiteList_.empty()) { - DHLOGE("%s called, whilte list is empty!", __func__); - return false; - } - - TYPE_DEVICE_WHITE_LIST_MAP::iterator iter = mapDeviceWhiteList_.find(deviceId); - if (iter == mapDeviceWhiteList_.end()) { - DHLOGE("%s called, not find by deviceId!", __func__); - return false; - } - - TYPE_KEY_CODE_VEC vecKeyCode = event.pressedKeys; - vecKeyCode.push_back(event.keyCode); - vecKeyCode.push_back(event.keyAction); - if (vecKeyCode.empty()) { - DHLOGE("%s called, vecKeyCode is empty!", __func__); - return false; - } - - bool bIsMatching = false; - TYPE_WHITE_LIST_VEC vecWhiteList = iter->second; - for (TYPE_WHITE_LIST_VEC::iterator iter1 = vecWhiteList.begin(); iter1 != vecWhiteList.end(); ++iter1) { - if (vecKeyCode.size() != iter1->size()) { - DHLOGI( - "%s called, vecKeyCodeSize=%d, iter1Size=%d", - __func__, vecKeyCode.size(), iter1->size()); - continue; - } - - TYPE_COMBINATION_KEY_VEC::iterator iter2 = iter1->begin(); - TYPE_KEY_CODE_VEC::iterator iter3 = vecKeyCode.begin(); - for (; iter2 != iter1->end() && iter3 != vecKeyCode.end(); ++iter2, ++iter3) { - bIsMatching = false; - bIsMatching = CheckSubVecData(iter2, iter3); - if (!bIsMatching) { - break; - } - } - if (bIsMatching) { - break; - } - } - - DHLOGI("%s called, bIsMatching=%d", __func__, bIsMatching); - return bIsMatching; -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/common/include/white_list_util.h b/common/include/white_list_util.h deleted file mode 100644 index bb942d8..0000000 --- a/common/include/white_list_util.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef WHITE_LIST_UTIL_H -#define WHITE_LIST_UTIL_H - -#include - -#include "constants_dinput.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -using TYPE_KEY_CODE_VEC = std::vector; -using TYPE_COMBINATION_KEY_VEC = std::vector; -using TYPE_WHITE_LIST_VEC = std::vector; -using TYPE_DEVICE_WHITE_LIST_MAP = std::map; -class WhiteListUtil { -public: - static WhiteListUtil &GetInstance(void); - int32_t Init(const std::string &deviceId); - int32_t UnInit(void); - int32_t SyncWhiteList(const std::string &deviceId, const TYPE_WHITE_LIST_VEC &vecWhiteList); - int32_t ClearWhiteList(const std::string &deviceId); - int32_t ClearWhiteList(void); - int32_t GetWhiteList(const std::string &deviceId, TYPE_WHITE_LIST_VEC &vecWhiteList); - bool IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event); -private: - WhiteListUtil(); - ~WhiteListUtil(); - WhiteListUtil(const WhiteListUtil &other) = delete; - const WhiteListUtil &operator=(const WhiteListUtil &other) = delete; - void ReadLineDataStepOne(std::string &column, TYPE_KEY_CODE_VEC &vecKeyCode, - TYPE_COMBINATION_KEY_VEC &vecCombinationKey) const; - bool CheckSubVecData(const TYPE_COMBINATION_KEY_VEC::iterator &iter2, - const TYPE_KEY_CODE_VEC::iterator &iter3) const; -private: - TYPE_DEVICE_WHITE_LIST_MAP mapDeviceWhiteList_; - std::mutex mutex_; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - -#endif // WHITE_LIST_UTIL_H diff --git a/services/common/include/dinput_sink_trans_callback.h b/services/common/include/dinput_sink_trans_callback.h deleted file mode 100644 index ff5de1c..0000000 --- a/services/common/include/dinput_sink_trans_callback.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DISTRIBUTED_INPUT_SINK_TANTS_H -#define OHOS_DISTRIBUTED_INPUT_SINK_TANTS_H - -#include - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DInputSinkTransCallback { -public: - virtual void onPrepareRemoteInput(const int32_t& sessionId, const std::string &deviceId) = 0; - virtual void onUnprepareRemoteInput(const int32_t& sessionId) = 0; - virtual void onStartRemoteInput(const int32_t& sessionId, const uint32_t& inputTypes) = 0; - virtual void onStopRemoteInput(const int32_t& sessionId, const uint32_t& inputTypes) = 0; - virtual ~DInputSinkTransCallback() {} -}; -} -} -} -#endif diff --git a/services/common/include/dinput_softbus_define.h b/services/common/include/dinput_softbus_define.h deleted file mode 100644 index 7931cd0..0000000 --- a/services/common/include/dinput_softbus_define.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISTRIBUTED_INPUT_SOFTBUS_DEFINE_H -#define DISTRIBUTED_INPUT_SOFTBUS_DEFINE_H - -#include -#include - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { - struct InnerMsgData { - std::string deviceId; - std::string dataStr; - InnerMsgData(std::string devId, std::string data) : deviceId(devId), dataStr(data) {}; - }; - - struct SwitchStateData { - int32_t sessionId; - bool switchState; - SwitchStateData(int32_t session, bool state) : sessionId(session), switchState(state) {}; - }; - - const int32_t ENCRYPT_TAG_LEN = 32; - const int32_t MSG_MAX_SIZE = 45 * 1024; - - const uint32_t SESSION_NAME_SIZE_MAX = 256; - const uint32_t DEVICE_ID_SIZE_MAX = 65; - const uint32_t INTERCEPT_STRING_LENGTH = 20; - - const std::string DINPUT_PKG_NAME = "ohos.dhardware.dinput"; - const std::string SESSION_NAME_SOURCE = "ohos.dhardware.dinput.so_"; - const std::string SESSION_NAME_SINK = "ohos.dhardware.dinput.si_"; - const std::string GROUP_ID = "input_softbus_group_id"; - - #define DINPUT_SOFTBUS_KEY_CMD_TYPE "dinput_softbus_key_cmd_type" - #define DINPUT_SOFTBUS_KEY_DEVICE_ID "dinput_softbus_key_device_id" - #define DINPUT_SOFTBUS_KEY_SESSION_ID "dinput_softbus_key_session_id" - #define DINPUT_SOFTBUS_KEY_INPUT_TYPE "dinput_softbus_key_input_type" - #define DINPUT_SOFTBUS_KEY_RESP_VALUE "dinput_softbus_key_resp_value" - #define DINPUT_SOFTBUS_KEY_WHITE_LIST "dinput_softbus_key_list_list" - #define DINPUT_SOFTBUS_KEY_INPUT_DATA "dinput_softbus_key_input_data" - - // json value - const uint32_t TRANS_SINK_MSG_ONPREPARE = 1; - const uint32_t TRANS_SINK_MSG_ONUNPREPARE = 2; - const uint32_t TRANS_SINK_MSG_ONSTART = 3; - const uint32_t TRANS_SINK_MSG_ONSTOP = 4; - const uint32_t TRANS_SINK_MSG_BODY_DATA = 5; - const uint32_t TRANS_SOURCE_MSG_PREPARE = 11; - const uint32_t TRANS_SOURCE_MSG_UNPREPARE = 12; - const uint32_t TRANS_SOURCE_MSG_START = 13; - const uint32_t TRANS_SOURCE_MSG_STOP = 14; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS -#endif // DISTRIBUTED_INPUT_SOFTBUS_DEFINE_H diff --git a/services/common/include/dinput_source_trans_callback.h b/services/common/include/dinput_source_trans_callback.h deleted file mode 100644 index 38ad893..0000000 --- a/services/common/include/dinput_source_trans_callback.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DISTRIBUTED_INPUT_SOURCE_TRANS_H -#define OHOS_DISTRIBUTED_INPUT_SOURCE_TRANS_H - -#include - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DInputSourceTransCallback { -public: - virtual void onResponseRegisterDistributedHardware(const std::string deviceId, const std::string dhId, - bool result) = 0; - virtual void onResponsePrepareRemoteInput(const std::string deviceId, bool result, const std::string &object) = 0; - virtual void onResponseUnprepareRemoteInput(const std::string deviceId, bool result) = 0; - virtual void onResponseStartRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result) = 0; - virtual void onResponseStopRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result) = 0; - virtual void onReceivedEventRemoteInput(const std::string deviceId, const std::string &object) = 0; -}; -} -} -} -#endif diff --git a/services/sink/inputcollector/BUILD.gn b/services/sink/inputcollector/BUILD.gn deleted file mode 100644 index f81c01d..0000000 --- a/services/sink/inputcollector/BUILD.gn +++ /dev/null @@ -1,61 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//foundation/distributedhardware/distributedinput/distributedinput.gni") - -ohos_shared_library("libdinput_collector") { - include_dirs = [ - "include", - "${common_path}/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "//third_party/json/include", - ] - - sources = [ - "src/distributed_input_collector.cpp", - "${common_path}/include/input_hub.cpp", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedinputcollector\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "//foundation/bundlemanager/bundle_framework/interfaces/innerkits/libeventhandler:libeventhandler", - "//utils/native/base:utils", - "${fwk_utils_path}:distributedhardwareutils", - "//third_party/openssl:libcrypto_static", - ] - - external_deps = [ - "ipc:ipc_core", - "safwk:system_ability_fwk", - "hiviewdfx_hilog_native:libhilog", - "samgr_standard:samgr_proxy", - ] - - cflags_cc = [ "-DHILOG_ENABLE" ] - - subsystem_name = "distributedhardware" - - part_name = "distributed_input" - -} diff --git a/services/sink/inputcollector/include/distributed_input_collector.h b/services/sink/inputcollector/include/distributed_input_collector.h deleted file mode 100644 index 75fa47b..0000000 --- a/services/sink/inputcollector/include/distributed_input_collector.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISTRIBUTED_INPUT_COLLECTOR_H -#define DISTRIBUTED_INPUT_COLLECTOR_H - -#include -#include -#include - -#include -#include - -#include "event_handler.h" - -#include "constants_dinput.h" -#include "input_hub.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputCollector { -public: - static DistributedInputCollector &GetInstance(); - int32_t Init(std::shared_ptr sinkHandler); - void SetInputTypes(const int32_t& inputType); - -private: - DistributedInputCollector(); - ~DistributedInputCollector(); - - bool InitCollectEventsThread(); - static void *CollectEventsThread(void *param); - void StartCollectEventsThread(); - void StopCollectEventsThread(); - - // The event queue. - static const int INPUT_EVENT_BUFFER_SIZE = 256; - RawEvent mEventBuffer[INPUT_EVENT_BUFFER_SIZE]; - pthread_t collectThreadID_; - bool isCollectingEvents_; - bool isStartGetDeviceHandlerThread; - std::unique_ptr inputHub_; - std::shared_ptr sinkHandler_; - uint32_t input_types_; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - -#endif // DISTRIBUTED_INPUT_COLLECTOR_H \ No newline at end of file diff --git a/services/sink/inputcollector/src/distributed_input_collector.cpp b/services/sink/inputcollector/src/distributed_input_collector.cpp deleted file mode 100644 index 62e4668..0000000 --- a/services/sink/inputcollector/src/distributed_input_collector.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_input_collector.h" - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "distributed_hardware_log.h" -#include "nlohmann/json.hpp" - -#include "dinput_errcode.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -namespace { -static const uint32_t INPUT_DEVICE_CLASS_KEYBOARD = static_cast(DeviceClasses::INPUT_DEVICE_CLASS_KEYBOARD); -static const uint32_t INPUT_DEVICE_CLASS_CURSOR = static_cast(DeviceClasses::INPUT_DEVICE_CLASS_CURSOR); -} - -DistributedInputCollector::DistributedInputCollector() - : collectThreadID_(-1), isCollectingEvents_(false), - isStartGetDeviceHandlerThread(false), input_types_(0) -{ - inputHub_ = std::make_unique(); -} - -DistributedInputCollector::~DistributedInputCollector() -{ - StopCollectEventsThread(); -} - -DistributedInputCollector &DistributedInputCollector::GetInstance() -{ - static DistributedInputCollector instance; - return instance; -} - -int32_t DistributedInputCollector::Init(std::shared_ptr sinkHandler) -{ - sinkHandler_ = sinkHandler; - if (sinkHandler_ == nullptr) { - DHLOGE("DistributedInputCollector::Init sinkHandler_ failed \n"); - return ERR_DH_INPUT_SERVER_SINK_COLLECTOR_INIT_FAIL; - } - if (!isStartGetDeviceHandlerThread) { - InitCollectEventsThread(); - isStartGetDeviceHandlerThread = true; - } - return DH_SUCCESS; -} - -bool DistributedInputCollector::InitCollectEventsThread() -{ - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); - - isCollectingEvents_ = true; - collectThreadID_ = -1; - int32_t ret = pthread_create(&collectThreadID_, &attr, CollectEventsThread, this); - if (ret != 0) { - DHLOGE( - "DistributedInputCollector::InitCollectEventsThread create thread failed:%d \n", ret); - pthread_attr_destroy(&attr); - collectThreadID_ = -1; - isCollectingEvents_ = false; - return false; - } - return true; -} - -void *DistributedInputCollector::CollectEventsThread(void *param) -{ - DistributedInputCollector *pThis = reinterpret_cast(param); - pThis->StartCollectEventsThread(); - DHLOGW("DistributedInputCollector::CollectEventsThread exist!"); - return nullptr; -} - -void DistributedInputCollector::StartCollectEventsThread() -{ - while (isCollectingEvents_) { - size_t count = inputHub_->CollectInputEvents(mEventBuffer, INPUT_EVENT_BUFFER_SIZE); - if (count > 0) { - DHLOGI("Count: %zu", count); - } else { - continue; - } - - // The RawEvent obtained by the controlled end calls transport and is - // sent to the main control end. - std::shared_ptr jsonArrayMsg = std::make_shared(); - for (int ind = 0; ind < count; ind++) { - nlohmann::json tmpJson; - tmpJson[INPUT_KEY_WHEN] = mEventBuffer[ind].when; - tmpJson[INPUT_KEY_TYPE] = mEventBuffer[ind].type; - tmpJson[INPUT_KEY_CODE] = mEventBuffer[ind].code; - tmpJson[INPUT_KEY_VALUE] = mEventBuffer[ind].value; - tmpJson[INPUT_KEY_PATH] = mEventBuffer[ind].path; - tmpJson[INPUT_KEY_DESCRIPTOR] = mEventBuffer[ind].descriptor; - jsonArrayMsg->push_back(tmpJson); - } - - AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( - static_cast(EHandlerMsgType::DINPUT_SINK_EVENT_HANDLER_MSG), jsonArrayMsg, 0); - if (sinkHandler_ != nullptr) { - sinkHandler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); - } - } - DHLOGW("DistributedInputCollector::StartCollectEventsThread exit!"); -} - -void DistributedInputCollector::StopCollectEventsThread() -{ - isCollectingEvents_ = false; - isStartGetDeviceHandlerThread = false; - if (collectThreadID_ != (pthread_t)(-1)) { - DHLOGI("DistributedInputCollector::Wait collect thread exit"); - pthread_join(collectThreadID_, NULL); - collectThreadID_ = (pthread_t)(-1); - } - DHLOGW("DistributedInputCollector::StopCollectEventsThread exit!"); -} - -void DistributedInputCollector::SetInputTypes(const int32_t& inputType) -{ - if (inputType & INPUT_TYPE_MOUSE) { - input_types_ |= INPUT_DEVICE_CLASS_CURSOR; - } - if (inputType & INPUT_TYPE_KEYBOARD) { - input_types_ |= INPUT_DEVICE_CLASS_KEYBOARD; - } - if (inputType & INPUT_TYPE_TOUCH) { - input_types_ |= INPUT_DEVICE_CLASS_CURSOR; - } - inputHub_->SetSupportInputType(input_types_); -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/sink/sinkmanager/BUILD.gn b/services/sink/sinkmanager/BUILD.gn deleted file mode 100644 index d5156af..0000000 --- a/services/sink/sinkmanager/BUILD.gn +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//foundation/distributedhardware/distributedinput/distributedinput.gni") - -ohos_shared_library("libdinput_sink") { - include_dirs = [ - "include", - "${frameworks_path}/include", - "${innerkits_path}/include", - "${innerkits_path}/src", - "${ipc_path}/include", - "${ipc_path}/src", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${common_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${service_common}/include", - "${services_sink_path}/transport/include", - "${services_sink_path}/inputcollector/include", - "//third_party/json/include", - ] - - sources = [ - "src/distributed_input_sink_manager.cpp", - "src/distributed_input_sink_event_handler.cpp", - "${ipc_path}/src/distributed_input_sink_stub.cpp", - "${common_path}/include/white_list_util.cpp", - "${ipc_path}/src/start_d_input_server_call_back_proxy.cpp", - "${ipc_path}/src/start_d_input_server_call_back_stub.cpp", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedinputmanagerkit\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "//foundation/distributedhardware/distributedinput/interfaces/inner_kits:libdinput_sdk", - "//foundation/bundlemanager/bundle_framework/interfaces/innerkits/libeventhandler:libeventhandler", - "//utils/native/base:utils", - "${fwk_utils_path}:distributedhardwareutils", - "//foundation/distributedhardware/distributedinput/services/sink/transport:libdinput_sink_trans", - "//foundation/distributedhardware/distributedinput/services/sink/inputcollector:libdinput_collector", - ] - - external_deps = [ - "ipc:ipc_core", - "safwk:system_ability_fwk", - "hiviewdfx_hilog_native:libhilog", - "samgr_standard:samgr_proxy", - ] - - cflags_cc = [ "-DHILOG_ENABLE" ] - - subsystem_name = "distributedhardware" - - part_name = "distributed_input" -} diff --git a/services/sink/sinkmanager/include/distributed_input_sink_event_handler.h b/services/sink/sinkmanager/include/distributed_input_sink_event_handler.h deleted file mode 100644 index efaac8b..0000000 --- a/services/sink/sinkmanager/include/distributed_input_sink_event_handler.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISRIBUTED_INPUT_SINK_EVENT_HANDLER_H -#define DISRIBUTED_INPUT_SINK_EVENT_HANDLER_H - -#include - -#include "event_handler.h" -#include "event_runner.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputSinkEventHandler : public AppExecFwk::EventHandler { -public: - DistributedInputSinkEventHandler(const std::shared_ptr &runner); - virtual ~DistributedInputSinkEventHandler(); - - bool ProxyPostTask(const Callback &callback, int64_t delayTime); - - bool ProxyPostTask(const Callback &callback, const std::string &name = std::string(), int64_t delayTime = 0); - - void ProxyRemoveTask(const std::string &name); - -private: -}; -} // namespace DistributedHardware -} // namespace DistributedInput -} // namespace OHOS -#endif // DISRIBUTED_INPUT_SINK_EVENT_HANDLER_H diff --git a/services/sink/sinkmanager/include/distributed_input_sink_manager.h b/services/sink/sinkmanager/include/distributed_input_sink_manager.h deleted file mode 100644 index 482c053..0000000 --- a/services/sink/sinkmanager/include/distributed_input_sink_manager.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISRIBUTED_INPUT_SINK_MANAGER_SERVICE_H -#define DISRIBUTED_INPUT_SINK_MANAGER_SERVICE_H - -#include -#include - -#include -#include - -#include "event_handler.h" -#include "singleton.h" -#include "system_ability.h" - -#include "constants_dinput.h" -#include "dinput_sink_trans_callback.h" -#include "distributed_input_sink_stub.h" -#include "distributed_input_sink_event_handler.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -enum class ServiceSinkRunningState { STATE_NOT_START, STATE_RUNNING }; - -class DistributedInputSinkManager : public SystemAbility, public DistributedInputSinkStub { - DECLARE_SYSTEM_ABILITY(DistributedInputSinkManager) - -public: - DistributedInputSinkManager(int32_t saId, bool runOnCreate); - ~DistributedInputSinkManager() = default; - - class DInputSinkListener : public DInputSinkTransCallback { - public: - DInputSinkListener(DistributedInputSinkManager *manager); - ~DInputSinkListener(); - void onPrepareRemoteInput(const int32_t& sessionId, const std::string &deviceId); - void onUnprepareRemoteInput(const int32_t& sessionId); - void onStartRemoteInput(const int32_t& sessionId, const uint32_t& inputTypes); - void onStopRemoteInput(const int32_t& sessionId, const uint32_t& inputTypes); - private: - DistributedInputSinkManager *sinkManagerObj_; - }; - -public: - void OnStart() override; - - void OnStop() override; - - virtual int32_t Init() override; - - virtual int32_t Release() override; - - virtual int32_t IsStartDistributedInput( - const uint32_t& inputType, sptr callback) override; - - IStartDInputServerCallback* GetStartDInputServerCback(); - - DInputServerType GetStartTransFlag(); - - void SetStartTransFlag(const DInputServerType flag); - - bool GetInitWhiteListFlag(); - - void SetInitWhiteListFlag(bool isInit); - - int32_t GetInputTypes(); - - void SetInputTypes(const uint32_t& inputTypess); - - /** - * GetEventHandler, get the ui_service manager service's handler. - * - * @return Returns EventHandler ptr. - */ - std::shared_ptr GetEventHandler(); - -private: - bool isAlreadyInitWhiteList_ = false; - ServiceSinkRunningState serviceRunningState_ = ServiceSinkRunningState::STATE_NOT_START; - DInputServerType isStartTrans_ = DInputServerType::NULL_SERVER_TYPE; - std::shared_ptr statuslistener_; - sptr startServerCallback_ = nullptr; - - std::shared_ptr runner_; - std::shared_ptr handler_; - bool InitAuto(); - int32_t input_types_; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - -#endif // DISRIBUTED_INPUT_SINK_MANAGER_SERVICE_H diff --git a/services/sink/sinkmanager/src/distributed_input_sink_event_handler.cpp b/services/sink/sinkmanager/src/distributed_input_sink_event_handler.cpp deleted file mode 100644 index 5da69c2..0000000 --- a/services/sink/sinkmanager/src/distributed_input_sink_event_handler.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_input_sink_event_handler.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -DistributedInputSinkEventHandler::DistributedInputSinkEventHandler( - const std::shared_ptr &runner) - : AppExecFwk::EventHandler(runner) -{ -} -DistributedInputSinkEventHandler::~DistributedInputSinkEventHandler() = default; - -bool DistributedInputSinkEventHandler::ProxyPostTask(const Callback &callback, int64_t delayTime) -{ - return AppExecFwk::EventHandler::PostTask(callback, delayTime); -} - -bool DistributedInputSinkEventHandler::ProxyPostTask( - const Callback &callback, const std::string &name, int64_t delayTime) -{ - return AppExecFwk::EventHandler::PostTask(callback, name, delayTime); -} - -void DistributedInputSinkEventHandler::ProxyRemoveTask(const std::string &name) -{ - AppExecFwk::EventHandler::RemoveTask(name); -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp deleted file mode 100644 index 6135a00..0000000 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ /dev/null @@ -1,356 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_input_sink_manager.h" - -#include "anonymous_string.h" -#include "distributed_hardware_log.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" -#include "nlohmann/json.hpp" -#include "system_ability_definition.h" - -#include "distributed_input_collector.h" -#include "distributed_input_sink_switch.h" -#include "distributed_input_sink_transport.h" - -#include "dinput_errcode.h" -#include "white_list_util.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -REGISTER_SYSTEM_ABILITY_BY_ID(DistributedInputSinkManager, DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID, true); - -DistributedInputSinkManager::DistributedInputSinkManager(int32_t saId, bool runOnCreate) - : SystemAbility(saId, runOnCreate) -{ - input_types_ = 0; -} - -DistributedInputSinkManager::DInputSinkListener::DInputSinkListener(DistributedInputSinkManager *manager) -{ - sinkManagerObj_ = manager; - sinkManagerObj_->SetInputTypes(INPUT_TYPE_NULL); - DHLOGI("DInputSinkListener init."); -} - -DistributedInputSinkManager::DInputSinkListener::~DInputSinkListener() -{ - sinkManagerObj_->SetInputTypes(INPUT_TYPE_NULL); - sinkManagerObj_ = nullptr; - DHLOGI("DInputSinkListener destory."); -} - -void DistributedInputSinkManager::DInputSinkListener::onPrepareRemoteInput( - const int32_t& sessionId, const std::string &deviceId) -{ - DHLOGI("onPrepareRemoteInput called, sessionId: %s", GetAnonyInt32(sessionId).c_str()); - - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONPREPARE; - std::string smsg = ""; - int ret = DistributedInputCollector::GetInstance().Init( - DistributedInputSinkTransport::GetInstance().GetEventHandler()); - if (ret != DH_SUCCESS) { - DHLOGE("DInputSinkListener init InputCollector error."); - jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = false; - jsonStr[DINPUT_SOFTBUS_KEY_WHITE_LIST] = ""; - smsg = jsonStr.dump(); - DistributedInputSinkTransport::GetInstance().RespPrepareRemoteInput(sessionId, smsg); - return; - } - - DistributedInputSinkSwitch::GetInstance().AddSession(sessionId); - - // send prepare result and if result ok, send white list - TYPE_WHITE_LIST_VEC vecFilter; - if (sinkManagerObj_->GetInitWhiteListFlag() == false) { - if (WhiteListUtil::GetInstance().Init(deviceId) != DH_SUCCESS) { - DHLOGE("%s called, init white list fail!", __func__); - jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true; - jsonStr[DINPUT_SOFTBUS_KEY_WHITE_LIST] = ""; - smsg = jsonStr.dump(); - DistributedInputSinkTransport::GetInstance().RespPrepareRemoteInput(sessionId, smsg); - return; - } - sinkManagerObj_->SetInitWhiteListFlag(true); - } - - WhiteListUtil::GetInstance().GetWhiteList(deviceId, vecFilter); - if (vecFilter.empty() || vecFilter[0].empty() || vecFilter[0][0].empty()) { - DHLOGE("onPrepareRemoteInput called, white list is null."); - jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true; - jsonStr[DINPUT_SOFTBUS_KEY_WHITE_LIST] = ""; - smsg = jsonStr.dump(); - DistributedInputSinkTransport::GetInstance().RespPrepareRemoteInput(sessionId, smsg); - return; - } - nlohmann::json filterMsg(vecFilter); - std::string object = filterMsg.dump(); - jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true; - jsonStr[DINPUT_SOFTBUS_KEY_WHITE_LIST] = object; - smsg = jsonStr.dump(); - DistributedInputSinkTransport::GetInstance().RespPrepareRemoteInput(sessionId, smsg); -} - -void DistributedInputSinkManager::DInputSinkListener::onUnprepareRemoteInput(const int32_t& sessionId) -{ - DHLOGI("onUnprepareRemoteInput called, sessionId: %s", GetAnonyInt32(sessionId).c_str()); - onStopRemoteInput(sessionId, INPUT_TYPE_ALL); - DistributedInputSinkSwitch::GetInstance().RemoveSession(sessionId); - - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONUNPREPARE; - jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true; - std::string smsg = jsonStr.dump(); - DistributedInputSinkTransport::GetInstance().RespUnprepareRemoteInput(sessionId, smsg); -} - -void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInput( - const int32_t& sessionId, const uint32_t& inputTypes) -{ - int32_t curSessionId = DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession(); - DHLOGI("onStartRemoteInput called, curSessionId:%s, new sessionId: %s", - GetAnonyInt32(curSessionId).c_str(), GetAnonyInt32(sessionId).c_str()); - // set new session - int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(sessionId); - - sinkManagerObj_->SetStartTransFlag((startRes == DH_SUCCESS) ? - DInputServerType::SINK_SERVER_TYPE : - DInputServerType::NULL_SERVER_TYPE); - - bool result = (startRes == DH_SUCCESS) ? true : false; - nlohmann::json jsonStrSta; - jsonStrSta[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONSTART; - jsonStrSta[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - jsonStrSta[DINPUT_SOFTBUS_KEY_RESP_VALUE] = result; - std::string smsgSta = jsonStrSta.dump(); - - DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsgSta); - - // Notify the interrupted master status - if (curSessionId == ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL) { - DHLOGI("onStartRemoteInput called, this is the only session."); - } else if (result) { - DHLOGI("onStartRemoteInput called, notify curSessionId:%s Interrupted.", - GetAnonyInt32(curSessionId).c_str()); - nlohmann::json jsonStrStp; - jsonStrStp[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONSTOP; - jsonStrStp[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - jsonStrStp[DINPUT_SOFTBUS_KEY_RESP_VALUE] = false; - std::string smsgStp = jsonStrStp.dump(); - DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(curSessionId, smsgStp); - sinkManagerObj_->SetInputTypes(INPUT_TYPE_NULL); - DistributedInputCollector::GetInstance().SetInputTypes(sinkManagerObj_->GetInputTypes()); - } else { - DHLOGI("onStartRemoteInput called, new session is error, not notify curSession."); - } - - // add the input type - if (startRes == DH_SUCCESS) { - sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() | inputTypes); - DistributedInputCollector::GetInstance().SetInputTypes(sinkManagerObj_->GetInputTypes()); - } - - IStartDInputServerCallback *startServerCB = sinkManagerObj_->GetStartDInputServerCback(); - if (startServerCB == nullptr) { - DHLOGE("onStartRemoteInput called, startServerCB is null."); - } else { - startServerCB->OnResult( - static_cast(sinkManagerObj_->GetStartTransFlag()), sinkManagerObj_->GetInputTypes()); - } -} - -void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInput( - const int32_t& sessionId, const uint32_t& inputTypes) -{ - DHLOGI("onStopRemoteInput called, sessionId: %s, inputTypes: %d", - GetAnonyInt32(sessionId).c_str(), inputTypes); - - sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() - - (sinkManagerObj_->GetInputTypes() & inputTypes)); - DistributedInputCollector::GetInstance().SetInputTypes(sinkManagerObj_->GetInputTypes()); - - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONSTOP; - jsonStr[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true; - std::string smsg = jsonStr.dump(); - DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(sessionId, smsg); - - if (sinkManagerObj_->GetInputTypes() == INPUT_TYPE_NULL) { - DistributedInputSinkSwitch::GetInstance().StopSwitch(sessionId); - if (DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession() == - ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL) { - DHLOGI("onStartRemoteInput called, all session is stop."); - sinkManagerObj_->SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE); - } - } - - IStartDInputServerCallback *startServerCB = sinkManagerObj_->GetStartDInputServerCback(); - if (startServerCB == nullptr) { - DHLOGE("onStartRemoteInput called, startServerCB is null."); - } else { - startServerCB->OnResult( - static_cast(sinkManagerObj_->GetStartTransFlag()), sinkManagerObj_->GetInputTypes()); - } -} - -void DistributedInputSinkManager::OnStart() -{ - if (serviceRunningState_ == ServiceSinkRunningState::STATE_RUNNING) { - DHLOGI("dinput Manager Service has already started."); - return; - } - DHLOGI("dinput Manager Service started."); - if (!InitAuto()) { - DHLOGI("failed to init service."); - return; - } - serviceRunningState_ = ServiceSinkRunningState::STATE_RUNNING; - runner_->Run(); - /* Publish service maybe failed, so we need call this function at the last, - * so it can't affect the TDD test program */ - bool ret = Publish(this); - if (!ret) { - return; - } - - DHLOGI("DistributedInputSinkManager start success."); -} - -bool DistributedInputSinkManager::InitAuto() -{ - runner_ = AppExecFwk::EventRunner::Create(true); - if (runner_ == nullptr) { - return false; - } - - handler_ = std::make_shared(runner_); - DHLOGI("init success"); - return true; -} - -void DistributedInputSinkManager::OnStop() -{ - DHLOGI("stop service"); - runner_.reset(); - handler_.reset(); - serviceRunningState_ = ServiceSinkRunningState::STATE_NOT_START; -} - -/** - * get event handler - * - * @return event handler object. - */ -std::shared_ptr DistributedInputSinkManager::GetEventHandler() -{ - return handler_; -} - -int32_t DistributedInputSinkManager::Init() -{ - DHLOGI("enter"); - isStartTrans_ = DInputServerType::NULL_SERVER_TYPE; - // transport init session - int32_t ret = DistributedInputSinkTransport::GetInstance().Init(); - if (ret != DH_SUCCESS) { - return ERR_DH_INPUT_SERVER_SINK_MANAGER_INIT_FAIL; - } - - statuslistener_ = std::make_shared(this); - DistributedInputSinkTransport::GetInstance().RegistSinkRespCallback(statuslistener_); - - serviceRunningState_ = ServiceSinkRunningState::STATE_RUNNING; - - return DH_SUCCESS; -} - -int32_t DistributedInputSinkManager::Release() -{ - DHLOGI("exit"); - - // 1.stop all session switch - DistributedInputSinkSwitch::GetInstance().StopAllSwitch(); - // 2.close all session - DistributedInputSinkTransport::GetInstance().CloseAllSession(); - - // 3.notify callback servertype - SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE); - IStartDInputServerCallback *startServerCB = GetStartDInputServerCback(); - if (startServerCB == nullptr) { - DHLOGE("Release() called, startServerCB is null."); - } else { - startServerCB->OnResult(0, 0); - } - - serviceRunningState_ = ServiceSinkRunningState::STATE_NOT_START; - DHLOGI("exit dinput sink sa."); - exit(0); - - return DH_SUCCESS; -} - -int32_t DistributedInputSinkManager::IsStartDistributedInput( - const uint32_t& inputType, sptr callback) -{ - if (callback != nullptr) { - startServerCallback_ = callback; - } - - if (inputType & GetInputTypes()) { - return static_cast(isStartTrans_); - } else { - return static_cast(DInputServerType::NULL_SERVER_TYPE); - } -} - -IStartDInputServerCallback* DistributedInputSinkManager::GetStartDInputServerCback() -{ - return startServerCallback_; -} - -DInputServerType DistributedInputSinkManager::GetStartTransFlag() -{ - return isStartTrans_; -} -void DistributedInputSinkManager::SetStartTransFlag(const DInputServerType flag) -{ - isStartTrans_ = flag; -} - -bool DistributedInputSinkManager::GetInitWhiteListFlag() -{ - return isAlreadyInitWhiteList_; -} - -void DistributedInputSinkManager::SetInitWhiteListFlag(bool isInit) -{ - isAlreadyInitWhiteList_ = isInit; -} - -int32_t DistributedInputSinkManager::GetInputTypes() -{ - return input_types_; -} -void DistributedInputSinkManager::SetInputTypes(const uint32_t& inputTypess) -{ - input_types_ = inputTypess; -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/sink/sinkmanager/test/BUILD.gn b/services/sink/sinkmanager/test/BUILD.gn deleted file mode 100644 index 89e8296..0000000 --- a/services/sink/sinkmanager/test/BUILD.gn +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -group("test") { - testonly = true - - deps = [ "sinkmanagerunittest:sinkmanagerunittest" ] -} diff --git a/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn b/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn deleted file mode 100644 index 570c429..0000000 --- a/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn +++ /dev/null @@ -1,95 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/test.gni") -import("//foundation/distributedhardware/distributedinput/distributedinput.gni") -module_out_path = "distributedinput_stander/sink_manager" - -group("sinkmanagerunittest") { - testonly = true - - deps = [ ":distributed_input_sinkmanager_test" ] -} - -## UnitTest distributed_input_manager_service_test {{{ -ohos_unittest("distributed_input_sinkmanager_test") { - module_out_path = module_out_path - - include_dirs = [ - "${innerkits_path}/include", - "${innerkits_path}/src", - "${ipc_path}/include", - "${ipc_path}/src", - "//foundation/distributedhardware/distributedinput/services/sink/transport/include", - "//foundation/distributedhardware/distributedinput/services/sink/sinkmanager/include", - "//foundation/distributedhardware/distributedinput/frameworks/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${common_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${service_common}/include", - "//third_party/json/include", - "//foundation/communication/dsoftbus/interfaces/kits/transport", - "${services_sink_path}/inputcollector/include", - ] - - sources = [ - "${common_path}/include/white_list_util.cpp", - "${common_path}/include/input_hub.cpp", - "//foundation/distributedhardware/distributedinput/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp", - "//foundation/distributedhardware/distributedinput/services/sink/transport/src/distributed_input_sink_switch.cpp", - "//foundation/distributedhardware/distributedinput/services/sink/transport/src/distributed_input_sink_transport.cpp", - "distributed_input_sinkmanager_test.cpp", - "//foundation/distributedhardware/distributedinput/services/sink/sinkmanager/src/distributed_input_sink_event_handler.cpp", - "${ipc_path}/src/distributed_input_sink_stub.cpp", - "${ipc_path}/src/start_d_input_server_call_back_proxy.cpp", - "${ipc_path}/src/start_d_input_server_call_back_stub.cpp", - "${services_sink_path}/inputcollector/src/distributed_input_collector.cpp", - ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", - "-Dprivate=public", - "-Dprotected=public", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedinpututtest\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "//foundation/bundlemanager/bundle_framework/interfaces/innerkits/libeventhandler:libeventhandler", - "//utils/native/base:utils", - "${fwk_utils_path}:distributedhardwareutils", - "//foundation/communication/dsoftbus/sdk:softbus_client", - "//third_party/openssl:libcrypto_static", - ] - - external_deps = [ - "ipc:ipc_core", - "safwk:system_ability_fwk", - "hiviewdfx_hilog_native:libhilog", - "samgr_standard:samgr_proxy", - ] - - cflags_cc = [ "-DHILOG_ENABLE" ] -} - -## UnitTest distributed_input_manager_service_test }}} diff --git a/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp b/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp deleted file mode 100644 index 0a2bd94..0000000 --- a/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "distributed_input_sinkmanager_test.h" - -#include "if_system_ability_manager.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" - - -using namespace testing::ext; -using namespace OHOS::DistributedHardware::DistributedInput; -using namespace std; -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -void DistributedInputSinkManagerTest::SetUp() -{ - sinkManager_ = new DistributedInputSinkManager(DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID, true); -} - -void DistributedInputSinkManagerTest::TearDown() -{ -} - -void DistributedInputSinkManagerTest::SetUpTestCase() -{ -} - -void DistributedInputSinkManagerTest::TearDownTestCase() -{ -} - -HWTEST_F(DistributedInputSinkManagerTest, Init01, testing::ext::TestSize.Level0) -{ - std::cout << "Init01"<< std::endl; - int32_t ret = sinkManager_->Init(); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSinkManagerTest, Release01, testing::ext::TestSize.Level0) -{ - std::cout << "Release01"<< std::endl; - int32_t ret = sinkManager_->Release(); - EXPECT_EQ(SUCCESS, ret); -} -} -} -} diff --git a/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.h b/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.h deleted file mode 100644 index 7795b6b..0000000 --- a/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISRIBUTED_INPUT_INNER_TEST_H -#define DISRIBUTED_INPUT_INNER_TEST_H - - -#include -#include -#include -#include - -#include - -#include "constants_dinput.h" -#include "distributed_input_sink_manager.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputSinkManagerTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; - -private: - DistributedInputSinkManager* sinkManager_; -}; -} -} -} -#endif // DISRIBUTED_INPUT_INNER_TEST_H diff --git a/services/sink/transport/BUILD.gn b/services/sink/transport/BUILD.gn deleted file mode 100644 index 5d2be3d..0000000 --- a/services/sink/transport/BUILD.gn +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//foundation/distributedhardware/distributedinput/distributedinput.gni") - -ohos_shared_library("libdinput_sink_trans") { - include_dirs = [ - "include", - "${common_path}/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "//third_party/json/include", - "//foundation/communication/dsoftbus/interfaces/kits/transport", - "${service_common}/include", - ] - - sources = [ - "src/distributed_input_sink_transport.cpp", - "src/distributed_input_sink_switch.cpp" - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedinputsinktransport\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "//foundation/bundlemanager/bundle_framework/interfaces/innerkits/libeventhandler:libeventhandler", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//utils/native/base:utils", - "${fwk_utils_path}:distributedhardwareutils", - "//foundation/communication/dsoftbus/sdk:softbus_client", - ] - - external_deps = [ - "ipc:ipc_core", - "safwk:system_ability_fwk", - "hiviewdfx_hilog_native:libhilog", - "samgr_standard:samgr_proxy", - ] - - cflags_cc = [ "-DHILOG_ENABLE" ] - - subsystem_name = "distributedhardware" - - part_name = "distributed_input" - -} diff --git a/services/sink/transport/include/distributed_input_sink_switch.h b/services/sink/transport/include/distributed_input_sink_switch.h deleted file mode 100644 index 4d7a68f..0000000 --- a/services/sink/transport/include/distributed_input_sink_switch.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISTRIBUTED_INPUT_SINK_SWITCH_H -#define DISTRIBUTED_INPUT_SINK_SWITCH_H - -#include -#include -#include -#include - -#include "dinput_softbus_define.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputSinkSwitch { -public: - static DistributedInputSinkSwitch &GetInstance(); - DistributedInputSinkSwitch(); - ~DistributedInputSinkSwitch(); - void InitSwitch(); - - int32_t StartSwitch(int32_t sessionId); - void StopSwitch(int32_t sessionId); - void AddSession(int32_t sessionId); - void RemoveSession(int32_t sessionId); - void StopAllSwitch(); - std::vector GetAllSessionId(); - int32_t GetSwitchOpenedSession(); - -private: - - std::mutex operationMutex_; - std::vector switchVector_; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - -#endif // DISTRIBUTED_INPUT_SINK_SWITCH_H diff --git a/services/sink/transport/include/distributed_input_sink_transport.h b/services/sink/transport/include/distributed_input_sink_transport.h deleted file mode 100644 index f36edca..0000000 --- a/services/sink/transport/include/distributed_input_sink_transport.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISTRIBUTED_INPUT_SINK_TRANSPORT_H -#define DISTRIBUTED_INPUT_SINK_TRANSPORT_H - -#include -#include -#include -#include - -#include "constants.h" -#include "event_handler.h" -#include "nlohmann/json.hpp" - -#include "dinput_sink_trans_callback.h" -#include "dinput_softbus_define.h" -#include "distributed_input_sink_switch.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputSinkTransport { -public: - static DistributedInputSinkTransport &GetInstance(); - DistributedInputSinkTransport(); - ~DistributedInputSinkTransport(); - - int32_t Init(); - - void RegistSinkRespCallback(std::shared_ptr callback); - int32_t RespPrepareRemoteInput(const int32_t sessionId, std::string &smsg); - int32_t RespUnprepareRemoteInput(const int32_t sessionId, std::string &smsg); - int32_t RespStartRemoteInput(const int32_t sessionId, std::string &smsg); - int32_t RespStopRemoteInput(const int32_t sessionId, std::string &smsg); - - int32_t OnSessionOpened(int32_t sessionId, int32_t result); - void OnSessionClosed(int32_t sessionId); - void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen); - - class DInputSinkEventHandler : public AppExecFwk::EventHandler { - public: - DInputSinkEventHandler(const std::shared_ptr &runner); - ~DInputSinkEventHandler() {} - - void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; - }; - - std::shared_ptr GetEventHandler(); - void CloseAllSession(); - -private: - int32_t SendMessage(int32_t sessionId, std::string &message); - void HandleSessionData(int32_t sessionId, const std::string& messageData); - void NotifyPrepareRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); - void NotifyUnprepareRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); - void NotifyStartRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); - void NotifyStopRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); - -private: - std::string deviceId_; - std::set sessionIdSet_; - std::map sessionDevMap_; - std::string mySessionName_; - - std::shared_ptr eventHandler_; - std::shared_ptr callback_; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - -#endif // DISTRIBUTED_INPUT_SINK_TRANSPORT_H diff --git a/services/sink/transport/src/distributed_input_sink_switch.cpp b/services/sink/transport/src/distributed_input_sink_switch.cpp deleted file mode 100644 index 5043dc4..0000000 --- a/services/sink/transport/src/distributed_input_sink_switch.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_input_sink_switch.h" - -#include "anonymous_string.h" -#include "distributed_hardware_log.h" - -#include "constants_dinput.h" -#include "dinput_errcode.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -DistributedInputSinkSwitch::DistributedInputSinkSwitch() -{ - InitSwitch(); -} - -DistributedInputSinkSwitch::~DistributedInputSinkSwitch() -{ - DHLOGI("~DistributedInputSinkSwitch()"); - InitSwitch(); -} - -DistributedInputSinkSwitch &DistributedInputSinkSwitch::GetInstance() -{ - static DistributedInputSinkSwitch instance; - return instance; -} - -void DistributedInputSinkSwitch::InitSwitch() -{ - DHLOGI("InitSwitch."); - std::unique_lock switchLock(operationMutex_); - switchVector_.clear(); -} - -int32_t DistributedInputSinkSwitch::StartSwitch(int32_t sessionId) -{ - std::unique_lock switchLock(operationMutex_); - if (switchVector_.empty()) { - DHLOGE("StartSwitch sessionId:%d fail,switchVector_ is null.", sessionId); - return ERR_DH_INPUT_SERVER_SINK_START_SWITCH_FAIL; - } else { - bool findOld = false; - for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); it++) { - if ((*it).sessionId == sessionId) { - (*it).switchState = true; - findOld = true; - break; - } - } - - if (findOld) { - DHLOGI("StartSwitch sessionId:%s is find.", GetAnonyInt32(sessionId).c_str()); - return DH_SUCCESS; - } else { - DHLOGE("StartSwitch sessionId:%s fail, not found.", GetAnonyInt32(sessionId).c_str()); - return ERR_DH_INPUT_SERVER_SINK_START_SWITCH_FAIL; - } - } -} - -void DistributedInputSinkSwitch::StopSwitch(int32_t sessionId) -{ - std::unique_lock switchLock(operationMutex_); - if (switchVector_.empty()) { - DHLOGE("StopSwitch sessionId:%s fail,switchVector_ is null.", GetAnonyInt32(sessionId).c_str()); - } else { - bool findOld = false; - for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); it++) { - if ((*it).sessionId == sessionId) { - (*it).switchState = false; - findOld = true; - break; - } - } - - if (findOld) { - DHLOGI("StopSwitch sessionId:%s is success.", GetAnonyInt32(sessionId).c_str()); - } else { - DHLOGE("StopSwitch sessionId:%s fail,not find it.", GetAnonyInt32(sessionId).c_str()); - } - } -} - -void DistributedInputSinkSwitch::StopAllSwitch() -{ - std::unique_lock switchLock(operationMutex_); - if (switchVector_.empty()) { - DHLOGW("StopAllSwitch switchVector_ is null."); - } else { - for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); it++) { - (*it).switchState = false; - } - DHLOGI("StopAllSwitch success."); - } -} - -void DistributedInputSinkSwitch::AddSession(int32_t sessionId) -{ - std::unique_lock switchLock(operationMutex_); - if (switchVector_.empty()) { - SwitchStateData tmp(sessionId, false); - switchVector_.push_back(tmp); - DHLOGI("AddSession sessionId:%s add first.", GetAnonyInt32(sessionId).c_str()); - } else { - bool findOld = false; - for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); it++) { - if ((*it).sessionId == sessionId) { - (*it).switchState = false; - findOld = true; - break; - } - } - - if (findOld) { - DHLOGI("AddSession sessionId:%s is find.", GetAnonyInt32(sessionId).c_str()); - } else { - SwitchStateData tmp(sessionId, false); - switchVector_.push_back(tmp); - DHLOGI("AddSession sessionId:%s add new.", GetAnonyInt32(sessionId).c_str()); - } - } -} - -void DistributedInputSinkSwitch::RemoveSession(int32_t sessionId) -{ - std::unique_lock switchLock(operationMutex_); - if (switchVector_.empty()) { - DHLOGE("RemoveSession sessionId:%s fail,switch_vector is null.", GetAnonyInt32(sessionId).c_str()); - } else { - bool findOld = false; - for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end();) { - if ((*it).sessionId == sessionId) { - it = switchVector_.erase(it); - findOld = true; - break; - } else { - it++; - } - } - if (findOld) { - DHLOGI("RemoveSession sessionId:%s is success.", GetAnonyInt32(sessionId).c_str()); - } else { - DHLOGE("RemoveSession sessionId:%s fail,not find it.", GetAnonyInt32(sessionId).c_str()); - } - } -} - -std::vector DistributedInputSinkSwitch::GetAllSessionId() -{ - std::unique_lock switchLock(operationMutex_); - std::vector tmpVecSession; - for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); it++) { - tmpVecSession.push_back((*it).sessionId); - } - return tmpVecSession; -} - -// get current session which state is on, if error return -1. -int32_t DistributedInputSinkSwitch::GetSwitchOpenedSession() -{ - std::unique_lock switchLock(operationMutex_); - if (switchVector_.empty()) { - DHLOGE("GetSwitchOpenedSession error, no data."); - return ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL; - } - for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); it++) { - if ((*it).switchState == true) { - return (*it).sessionId; - } - } - DHLOGE("GetSwitchOpenedSession no session is open."); - return ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL; -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/sink/transport/src/distributed_input_sink_transport.cpp b/services/sink/transport/src/distributed_input_sink_transport.cpp deleted file mode 100644 index 81639de..0000000 --- a/services/sink/transport/src/distributed_input_sink_transport.cpp +++ /dev/null @@ -1,456 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_input_sink_transport.h" - -#include - -#include "linux/input.h" - -#include "anonymous_string.h" -#include "distributed_hardware_log.h" -#include "securec.h" - -#include "constants_dinput.h" -#include "dinput_errcode.h" -#include "session.h" -#include "softbus_bus_center.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -DistributedInputSinkTransport::DistributedInputSinkTransport() -{ - std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); - eventHandler_ = std::make_shared(runner); - mySessionName_ = ""; - DHLOGI("DistributedInputSinkTransport eventHandler_"); -} - -DistributedInputSinkTransport::~DistributedInputSinkTransport() -{ - DHLOGI("~DistributedInputSinkTransport"); - sessionDevMap_.clear(); - (void)RemoveSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str()); -} - -DistributedInputSinkTransport::DInputSinkEventHandler::DInputSinkEventHandler( - const std::shared_ptr &runner) : AppExecFwk::EventHandler(runner) -{ -} - -static int32_t SessionOpened(int32_t sessionId, int32_t result) -{ - return DistributedInput::DistributedInputSinkTransport::GetInstance().OnSessionOpened(sessionId, result); -} - -static void SessionClosed(int32_t sessionId) -{ - DistributedInput::DistributedInputSinkTransport::GetInstance().OnSessionClosed(sessionId); -} - -static void BytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) -{ - DistributedInput::DistributedInputSinkTransport::GetInstance().OnBytesReceived(sessionId, data, dataLen); -} - -static void MessageReceived(int32_t sessionId, const void *data, uint32_t dataLen) -{ - (void)sessionId; - (void)data; - (void)dataLen; - DHLOGI("sessionId:%s, dataLen:%d", GetAnonyInt32(sessionId).c_str(), dataLen); -} - -static void StreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, - const StreamFrameInfo *param) -{ - (void)sessionId; - (void)data; - (void)ext; - (void)param; - DHLOGI("sessionId:%s", GetAnonyInt32(sessionId).c_str()); -} -DistributedInputSinkTransport &DistributedInputSinkTransport::GetInstance() -{ - static DistributedInputSinkTransport instance; - return instance; -} - -void DistributedInputSinkTransport::DInputSinkEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) -{ - DHLOGI("ProcessEvent"); - EHandlerMsgType eventId = static_cast(event->GetInnerEventId()); - switch (eventId) { - case EHandlerMsgType::DINPUT_SINK_EVENT_HANDLER_MSG: { - std::shared_ptr innerMsg = event->GetSharedObject(); - nlohmann::json sendMsg; - sendMsg[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_BODY_DATA; - sendMsg[DINPUT_SOFTBUS_KEY_INPUT_DATA] = innerMsg->dump(); - std::string smsg = sendMsg.dump(); - for (nlohmann::json::iterator it = innerMsg->begin(); it != innerMsg->end(); ++it) { - nlohmann::json oneData = *it; - int32_t code = oneData[INPUT_KEY_CODE]; - int32_t value = oneData[INPUT_KEY_VALUE]; - int64_t when = oneData[INPUT_KEY_WHEN]; - std::string path = oneData[INPUT_KEY_PATH]; - if (oneData[INPUT_KEY_TYPE] == EV_KEY) { - DHLOGD("2.E2E-Test Sink softBus send EV_KEY, Code: %d, Value: %d, Path: %s, When: %" PRId64"", - code, value, path.c_str(), when); - } else if (oneData[INPUT_KEY_TYPE] == EV_REL) { - DHLOGD("2.E2E-Test Sink softBus send EV_REL, Code: %d, Value: %d, Path: %s, When: %" PRId64"", - code, value, path.c_str(), when); - } else if (oneData[INPUT_KEY_TYPE] == EV_ABS) { - DHLOGD("2.E2E-Test Sink softBus send EV_ABS, Code: %d, Value: %d, Path: %s, When: %" PRId64"", - code, value, path.c_str(), when); - } else { - DHLOGW("2.E2E-Test Sink softBus send other type!"); - } - } - int32_t sessionId = DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession(); - if (sessionId > 0) { - DistributedInputSinkTransport::GetInstance().SendMessage(sessionId, smsg); - } else { - DHLOGE("ProcessEvent can't send input data, because no session switch on."); - } - break; - } - default: - DHLOGE("ProcessEvent error, because eventId is unkonwn."); - break; - } -} - -int32_t DistributedInputSinkTransport::Init() -{ - // 1.create session - DHLOGI("Init"); - ISessionListener iSessionListener = { - .OnSessionOpened = SessionOpened, - .OnSessionClosed = SessionClosed, - .OnBytesReceived = BytesReceived, - .OnMessageReceived = MessageReceived, - .OnStreamReceived = StreamReceived - }; - auto localNode = std::make_unique(); - int32_t retCode = GetLocalNodeDeviceInfo(DINPUT_PKG_NAME.c_str(), localNode.get()); - if (retCode != DH_SUCCESS) { - DHLOGE("Init could not get local device id."); - return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_INIT_FAIL; - } - std::string networkId = localNode->networkId; - DHLOGI("Init device networkId is %s", GetAnonyString(networkId).c_str()); - mySessionName_ = SESSION_NAME_SINK + networkId.substr(0, INTERCEPT_STRING_LENGTH); - - int32_t ret = CreateSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str(), &iSessionListener); - if (ret != DH_SUCCESS) { - DHLOGE("Init CreateSessionServer failed, error code %d.", ret); - return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_INIT_FAIL; - } - return DH_SUCCESS; -} - -std::shared_ptr DistributedInputSinkTransport::GetEventHandler() -{ - DHLOGI("GetEventHandler"); - return eventHandler_; -} - -void DistributedInputSinkTransport::RegistSinkRespCallback(std::shared_ptr callback) -{ - DHLOGI("RegistSinkRespCallback"); - callback_ = callback; -} - -int32_t DistributedInputSinkTransport::RespPrepareRemoteInput( - const int32_t sessionId, std::string &smsg) -{ - if (sessionId > 0) { - DHLOGI("RespPrepareRemoteInput session:%s, smsg:%s.", GetAnonyInt32(sessionId).c_str(), smsg.c_str()); - int32_t ret = SendMessage(sessionId, smsg); - if (ret != DH_SUCCESS) { - DHLOGE("RespPrepareRemoteInput error, SendMessage fail."); - return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPPREPARE_FAIL; - } - return DH_SUCCESS; - } else { - DHLOGE("RespPrepareRemoteInput error, sessionId <= 0."); - return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPPREPARE_FAIL; - } -} - -int32_t DistributedInputSinkTransport::RespUnprepareRemoteInput( - const int32_t sessionId, std::string &smsg) -{ - if (sessionId > 0) { - DHLOGI("RespUnprepareRemoteInput sessionId:%s, smsg:%s.", GetAnonyInt32(sessionId).c_str(), smsg.c_str()); - int32_t ret = SendMessage(sessionId, smsg); - if (ret != DH_SUCCESS) { - DHLOGE("RespUnprepareRemoteInput error, SendMessage fail."); - return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPUNPREPARE_FAIL; - } - return DH_SUCCESS; - } else { - DHLOGE("RespUnprepareRemoteInput error, sessionId <= 0."); - return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPUNPREPARE_FAIL; - } -} - -int32_t DistributedInputSinkTransport::RespStartRemoteInput( - const int32_t sessionId, std::string &smsg) -{ - if (sessionId > 0) { - DHLOGI("RespStartRemoteInput sessionId:%s, smsg:%s.", GetAnonyInt32(sessionId).c_str(), smsg.c_str()); - int32_t ret = SendMessage(sessionId, smsg); - if (ret != DH_SUCCESS) { - DHLOGE("RespStartRemoteInput error, SendMessage fail."); - return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPSTART_FAIL; - } - return DH_SUCCESS; - } else { - DHLOGE("RespStartRemoteInput error, sessionId <= 0."); - return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPSTART_FAIL; - } -} - -int32_t DistributedInputSinkTransport::RespStopRemoteInput( - const int32_t sessionId, std::string &smsg) -{ - if (sessionId > 0) { - DHLOGI("RespStopRemoteInput sessionId:%s, smsg:%s.", GetAnonyInt32(sessionId).c_str(), smsg.c_str()); - int32_t ret = SendMessage(sessionId, smsg); - if (ret != DH_SUCCESS) { - DHLOGE("RespStopRemoteInput error, SendMessage fail."); - return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPSTOP_FAIL; - } - return DH_SUCCESS; - } else { - DHLOGE("RespStopRemoteInput error, sessionId <= 0."); - return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPSTOP_FAIL; - } -} - -int32_t DistributedInputSinkTransport::SendMessage(int32_t sessionId, std::string &message) -{ - DHLOGI("start SendMessage"); - if (message.size() > MSG_MAX_SIZE) { - DHLOGE("SendMessage error: message.size() > MSG_MAX_SIZE"); - return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_SENDMESSAGE_FAIL; - } - uint8_t *buf = (uint8_t *)calloc((MSG_MAX_SIZE), sizeof(uint8_t)); - if (buf == nullptr) { - DHLOGE("SendMessage: malloc memory failed"); - return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_SENDMESSAGE_FAIL; - } - int32_t outLen = 0; - if (memcpy_s(buf, MSG_MAX_SIZE, (const uint8_t *)message.c_str(), message.size()) != DH_SUCCESS) { - DHLOGE("SendMessage: memcpy memory failed"); - free(buf); - return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_SENDMESSAGE_FAIL; - } - outLen = message.size(); - int32_t ret = SendBytes(sessionId, buf, outLen); - free(buf); - return ret; -} - -int32_t DistributedInputSinkTransport::OnSessionOpened(int32_t sessionId, int32_t result) -{ - if (result != DH_SUCCESS) { - DHLOGE("session open failed, sessionId %s", GetAnonyInt32(sessionId).c_str()); - if (sessionIdSet_.count(sessionId) > 0) { - sessionIdSet_.erase(sessionId); - } - return DH_SUCCESS; - } - - // return 1 is client - int32_t sessionSide = GetSessionSide(sessionId); - DHLOGI("session open succeed, sessionId %s, sessionSide %d", GetAnonyInt32(sessionId).c_str(), sessionSide); - - char mySessionName[SESSION_NAME_SIZE_MAX] = ""; - char peerSessionName[SESSION_NAME_SIZE_MAX] = ""; - char peerDevId[DEVICE_ID_SIZE_MAX] = ""; - int ret = GetMySessionName(sessionId, mySessionName, sizeof(mySessionName)); - if (ret != DH_SUCCESS) { - DHLOGI("get my session name failed, session id is %s", GetAnonyInt32(sessionId).c_str()); - } - // get other device session name - ret = GetPeerSessionName(sessionId, peerSessionName, sizeof(peerSessionName)); - if (ret != DH_SUCCESS) { - DHLOGI("get my peer session name failed, session id is %s", GetAnonyInt32(sessionId).c_str()); - } - - ret = GetPeerDeviceId(sessionId, peerDevId, sizeof(peerDevId)); - if (ret != DH_SUCCESS) { - DHLOGI("get my peer device id failed, session id is %s", GetAnonyInt32(sessionId).c_str()); - } - DHLOGI("mySessionName:%s, peerSessionName:%s, peerDevId:%s", - mySessionName, peerSessionName, GetAnonyString(peerDevId).c_str()); - - return DH_SUCCESS; -} - -void DistributedInputSinkTransport::OnSessionClosed(int32_t sessionId) -{ - DHLOGI("OnSessionClosed, sessionId:%s", GetAnonyInt32(sessionId).c_str()); - if (sessionIdSet_.count(sessionId) > 0) { - sessionIdSet_.erase(sessionId); - } - - DistributedInputSinkSwitch::GetInstance().RemoveSession(sessionId); -} - -void DistributedInputSinkTransport::OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) -{ - DHLOGI("OnBytesReceived, sessionId:%s, dataLen:%d", GetAnonyInt32(sessionId).c_str(), dataLen); - if (sessionId < 0 || data == nullptr || dataLen <= 0) { - DHLOGE("OnBytesReceived param check failed"); - return; - } - - uint8_t *buf = (uint8_t *)calloc(dataLen + 1, sizeof(uint8_t)); - if (buf == nullptr) { - DHLOGE("OnBytesReceived: malloc memory failed"); - return; - } - - if (memcpy_s(buf, dataLen + 1, (const uint8_t*)data, dataLen) != DH_SUCCESS) { - DHLOGE("OnBytesReceived: memcpy memory failed"); - free(buf); - return; - } - - std::string message = (char *)buf; - DHLOGI("OnBytesReceived message:%s.", message.c_str()); - HandleSessionData(sessionId, message); - - free(buf); - DHLOGI("OnBytesReceived completed"); - return; -} - -void DistributedInputSinkTransport::NotifyPrepareRemoteInput(int32_t sessionId, const nlohmann::json &recMsg) -{ - DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_PREPARE."); - if (!recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID].is_string()) { - DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_PREPARE data type error."); - return; - } - std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; - DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_PREPARE deviceId:%s.", - GetAnonyString(deviceId).c_str()); - callback_->onPrepareRemoteInput(sessionId, deviceId); -} - -void DistributedInputSinkTransport::NotifyUnprepareRemoteInput(int32_t sessionId, const nlohmann::json &recMsg) -{ - if (!recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID].is_string()) { - DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_UNPREPARE, data type is error."); - return; - } - std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; - DHLOGI("OnBytesReceived cmdType TRANS_SOURCE_MSG_UNPREPARE deviceId:%s.", - GetAnonyString(deviceId).c_str()); - callback_->onUnprepareRemoteInput(sessionId); -} - -void DistributedInputSinkTransport::NotifyStartRemoteInput(int32_t sessionId, const nlohmann::json &recMsg) -{ - if (!recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID].is_string()) { - DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_START, data type error."); - return; - } - std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; - uint32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; - DHLOGI("OnBytesRecei,ved cmdType is TRANS_SOURCE_MSG_START deviceId:%s inputTypes:%d .", - GetAnonyString(deviceId).c_str(), inputTypes); - callback_->onStartRemoteInput(sessionId, inputTypes); -} - -void DistributedInputSinkTransport::NotifyStopRemoteInput(int32_t sessionId, const nlohmann::json &recMsg) -{ - if (!recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID].is_string()) { - DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_STOP, data type is error."); - return; - } - std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; - uint32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; - DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_STOP deviceId:%s.", GetAnonyString(deviceId).c_str()); - callback_->onStopRemoteInput(sessionId, inputTypes); -} - -void DistributedInputSinkTransport::HandleSessionData(int32_t sessionId, const std::string& message) -{ - if (callback_ == nullptr) { - DHLOGE("OnBytesReceived the callback_ is null, the message:%s abort.", message.c_str()); - return; - } - - nlohmann::json recMsg = nlohmann::json::parse(message); - if (recMsg.is_discarded()) { - DHLOGE("OnBytesReceived jsonStr error."); - return; - } - - if (recMsg.contains(DINPUT_SOFTBUS_KEY_CMD_TYPE) != true) { - DHLOGE("OnBytesReceived message:%s is error, not contain cmdType.", message.c_str()); - return; - } - - if (recMsg[DINPUT_SOFTBUS_KEY_CMD_TYPE].is_number() != true) { - DHLOGE("OnBytesReceived cmdType is not number type."); - return; - } - - int cmdType = recMsg[DINPUT_SOFTBUS_KEY_CMD_TYPE]; - switch (cmdType) { - case TRANS_SOURCE_MSG_PREPARE: { - NotifyPrepareRemoteInput(sessionId, recMsg); - break; - } - case TRANS_SOURCE_MSG_UNPREPARE: { - NotifyUnprepareRemoteInput(sessionId, recMsg); - break; - } - case TRANS_SOURCE_MSG_START: { - NotifyStartRemoteInput(sessionId, recMsg); - break; - } - case TRANS_SOURCE_MSG_STOP: { - NotifyStopRemoteInput(sessionId, recMsg); - break; - } - default: - DHLOGE("OnBytesReceived cmdType is undefined."); - break; - } -} - -void DistributedInputSinkTransport::CloseAllSession() -{ - std::vector vecSession = DistributedInputSinkSwitch::GetInstance().GetAllSessionId(); - DHLOGI("CloseAllSession session vector size is %d", vecSession.size()); - for (int32_t kIndex = 0; kIndex < vecSession.size(); ++kIndex) { - CloseSession(vecSession[kIndex]); - DHLOGI("CloseAllSession [%d] sessionid is %s", kIndex, GetAnonyInt32(vecSession[kIndex]).c_str()); - } - - // clear session data - DistributedInputSinkSwitch::GetInstance().InitSwitch(); -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/sink/transport/test/BUILD.gn b/services/sink/transport/test/BUILD.gn deleted file mode 100644 index 51d05c3..0000000 --- a/services/sink/transport/test/BUILD.gn +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -group("test") { - testonly = true - - deps = [ "sinktransunittest:sinktransunittest" ] -} diff --git a/services/sink/transport/test/sinktransunittest/BUILD.gn b/services/sink/transport/test/sinktransunittest/BUILD.gn deleted file mode 100644 index 7a870ee..0000000 --- a/services/sink/transport/test/sinktransunittest/BUILD.gn +++ /dev/null @@ -1,80 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/test.gni") -import("//foundation/distributedhardware/distributedinput/distributedinput.gni") -module_out_path = "distributedinput_stander/sink_trans" - -group("sinktransunittest") { - testonly = true - - deps = [ ":distributed_input_sinktrans_test" ] -} - -## UnitTest distributed_input_manager_service_test {{{ -ohos_unittest("distributed_input_sinktrans_test") { - module_out_path = module_out_path - - include_dirs = [ - "//foundation/distributedhardware/distributedinput/services/sink/transport/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${common_path}/include", - "//utils/native/base/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${service_common}/include", - "//third_party/json/include", - "//foundation/distributedhardware/distributedinput/services/sink/transport/test/sinktransunittest/mock", - ] - - sources = [ - "//foundation/distributedhardware/distributedinput/services/sink/transport/src/distributed_input_sink_switch.cpp", - "//foundation/distributedhardware/distributedinput/services/sink/transport/src/distributed_input_sink_transport.cpp", - "distributed_input_sinktrans_test.cpp", - ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", - "-Dprivate=public", - "-Dprotected=public", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedinpututtest\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "//foundation/bundlemanager/bundle_framework/interfaces/innerkits/libeventhandler:libeventhandler", - "//utils/native/base:utils", - "${fwk_utils_path}:distributedhardwareutils", - "//foundation/communication/dsoftbus/sdk:softbus_client", - ] - - external_deps = [ - "ipc:ipc_core", - "safwk:system_ability_fwk", - "hiviewdfx_hilog_native:libhilog", - "samgr_standard:samgr_proxy", - ] - - cflags_cc = [ "-DHILOG_ENABLE" ] -} - -## UnitTest distributed_input_manager_service_test }}} diff --git a/services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.cpp b/services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.cpp deleted file mode 100644 index 49f7c1d..0000000 --- a/services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "dinput_errcode.h" -#include "distributed_input_sinktrans_test.h" - -using namespace testing::ext; -using namespace OHOS::DistributedHardware::DistributedInput; -using namespace std; -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -void DistributedInputSinkTransTest::SetUp() -{ -} - -void DistributedInputSinkTransTest::TearDown() -{ -} - -void DistributedInputSinkTransTest::SetUpTestCase() -{ -} - -void DistributedInputSinkTransTest::TearDownTestCase() -{ -} - -HWTEST_F(DistributedInputSinkTransTest, Init, testing::ext::TestSize.Level0) -{ - int32_t ret = DistributedInputSinkTransport::GetInstance().Init(); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSinkTransTest, RespPrepareRemoteInput01, testing::ext::TestSize.Level1) -{ - int32_t sessionId = -1; - std::string smsg = ""; - int32_t ret = DistributedInputSinkTransport::GetInstance().RespPrepareRemoteInput(sessionId, smsg); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPPREPARE_FAIL, ret); -} - -HWTEST_F(DistributedInputSinkTransTest, RespPrepareRemoteInput02, testing::ext::TestSize.Level1) -{ - int32_t sessionId = 0; - std::string smsg = ""; - int32_t ret = DistributedInputSinkTransport::GetInstance().RespPrepareRemoteInput(sessionId, smsg); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPPREPARE_FAIL, ret); -} - -HWTEST_F(DistributedInputSinkTransTest, RespPrepareRemoteInput03, testing::ext::TestSize.Level1) -{ - int32_t sessionId = 100; - std::string smsg = ""; - int32_t ret = DistributedInputSinkTransport::GetInstance().RespPrepareRemoteInput(sessionId, smsg); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSinkTransTest, RespUnprepareRemoteInput01, testing::ext::TestSize.Level0) -{ - int32_t sessionId = -1; - std::string smsg = ""; - int32_t ret = DistributedInputSinkTransport::GetInstance().RespUnprepareRemoteInput(sessionId, smsg); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPUNPREPARE_FAIL, ret); -} - -HWTEST_F(DistributedInputSinkTransTest, RespUnprepareRemoteInput02, testing::ext::TestSize.Level1) -{ - int32_t sessionId = 0; - std::string smsg = ""; - int32_t ret = DistributedInputSinkTransport::GetInstance().RespUnprepareRemoteInput(sessionId, smsg); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPUNPREPARE_FAIL, ret); -} - -HWTEST_F(DistributedInputSinkTransTest, RespUnprepareRemoteInput03, testing::ext::TestSize.Level1) -{ - int32_t sessionId = 100; - std::string smsg = ""; - int32_t ret = DistributedInputSinkTransport::GetInstance().RespUnprepareRemoteInput(sessionId, smsg); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSinkTransTest, RespStartRemoteInput01, testing::ext::TestSize.Level1) -{ - int32_t sessionId = -1; - std::string smsg = ""; - int32_t ret = DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsg); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPSTART_FAIL, ret); -} - -HWTEST_F(DistributedInputSinkTransTest, RespStartRemoteInput02, testing::ext::TestSize.Level1) -{ - int32_t sessionId = 0; - std::string smsg = ""; - int32_t ret = DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsg); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPSTART_FAIL, ret); -} - -HWTEST_F(DistributedInputSinkTransTest, RespStartRemoteInput03, testing::ext::TestSize.Level0) -{ - int32_t sessionId = 100; - std::string smsg = ""; - int32_t ret = DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsg); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSinkTransTest, RespStopRemoteInput01, testing::ext::TestSize.Level1) -{ - int32_t sessionId = -1; - std::string smsg = ""; - int32_t ret = DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(sessionId, smsg); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPSTOP_FAIL, ret); -} - -HWTEST_F(DistributedInputSinkTransTest, RespStopRemoteInput02, testing::ext::TestSize.Level1) -{ - int32_t sessionId = 0; - std::string smsg = ""; - int32_t ret = DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(sessionId, smsg); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPSTOP_FAIL, ret); -} - -HWTEST_F(DistributedInputSinkTransTest, RespStopRemoteInput03, testing::ext::TestSize.Level0) -{ - int32_t sessionId = 100; - std::string smsg = ""; - int32_t ret = DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(sessionId, smsg); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSinkTransTest, GetEventHandler, testing::ext::TestSize.Level1) -{ - std::shared_ptr eventHd = - DistributedInputSinkTransport::GetInstance().GetEventHandler(); - EXPECT_NE(nullptr, eventHd); -} - -HWTEST_F(DistributedInputSinkTransTest, StartSwitch01, testing::ext::TestSize.Level1) -{ - int32_t sessionId = 1000; - DistributedInputSinkSwitch::GetInstance().AddSession(sessionId); - int32_t ret = DistributedInputSinkSwitch::GetInstance().StartSwitch(sessionId); - EXPECT_EQ(SUCCESS, ret); -} -HWTEST_F(DistributedInputSinkTransTest, StartSwitch02, testing::ext::TestSize.Level1) -{ - int32_t sessionId = 1000; - DistributedInputSinkSwitch::GetInstance().AddSession(sessionId); - int32_t ret = DistributedInputSinkSwitch::GetInstance().StartSwitch(sessionId+10); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SINK_START_SWITCH_FAIL, ret); -} -} -} -} diff --git a/services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.h b/services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.h deleted file mode 100644 index 5ff4330..0000000 --- a/services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISRIBUTED_INPUT_INNER_TEST_H -#define DISRIBUTED_INPUT_INNER_TEST_H - -#include -#include -#include -#include - -#include - -#include "constants_dinput.h" -#include "distributed_input_sink_transport.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputSinkTransTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; -}; -} -} -} -#endif // DISRIBUTED_INPUT_INNER_TEST_H diff --git a/services/sink/transport/test/sinktransunittest/mock/session.h b/services/sink/transport/test/sinktransunittest/mock/session.h deleted file mode 100644 index fe5a96b..0000000 --- a/services/sink/transport/test/sinktransunittest/mock/session.h +++ /dev/null @@ -1,479 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @addtogroup Softbus - * @{ - * - * @brief Provides high-speed, secure communication between devices. - * - * This module implements unified distributed communication capability management between - * nearby devices, and provides link-independent device discovery and transmission interfaces - * to support service publishing and data transmission. - * - * @since 1.0 - * @version 1.0 -*/ - -/** - * @file session.h - * - * @brief Declares unified data transmission interfaces. - * - * This file provides data transmission capabilities, including creating and removing a session server, - * opening and closing sessions, receiving data, and querying basic session information. \n - * After multiple nearby devices are discovered and networked, these interfaces can be used to - * transmit data across devices. \n - * - * @since 1.0 - * @version 1.0 - */ -#ifndef SESSION_H -#define SESSION_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif -/** - * @brief business type of session - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - TYPE_MESSAGE = 1, - TYPE_BYTES, - TYPE_FILE, - TYPE_STREAM, - TYPE_BUTT, -} SessionType; - -typedef enum { - INVALID = -1, - /* - * Send any segment of a frame each time. - */ - RAW_STREAM, - /* - * Send a whole video frame each time. - */ - COMMON_VIDEO_STREAM, - /* - * Send a whole audio frame each time. - */ - COMMON_AUDIO_STREAM, - /* - * Slice frame mode. - */ - VIDEO_SLICE_STREAM, -} StreamType; - -typedef enum { - LINK_TYPE_WIFI_WLAN_5G = 1, - LINK_TYPE_WIFI_WLAN_2G = 2, - LINK_TYPE_WIFI_P2P = 3, - LINK_TYPE_BR = 4, - LINK_TYPE_MAX = 4, -} LinkType; - -/** - * @brief session attribute. - * - * control the attribute of session. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - /** @brief dataType{@link SessionType} */ - int dataType; - int linkTypeNum; - LinkType linkType[LINK_TYPE_MAX]; - union { - struct StreamAttr { - int streamType; - } streamAttr; - } attr; -} SessionAttribute; - -typedef struct { - char *buf; - int bufLen; -} StreamData; - -typedef struct { - int type; - int64_t value; -} TV; - -typedef struct { - int frameType; - int64_t timeStamp; - int seqNum; - int seqSubNum; - int level; - int bitMap; - int tvCount; - TV *tvList; -} StreamFrameInfo; - -typedef enum { - QOS_IMPROVE = 0, - QOS_RECOVER = 1 -} QosQuality; - -typedef enum { - TRANS_STREAM_QUALITY_EVENT = 1, - TRANS_CHANNEL_QUALITY_EVENT, - TRANS_CAN_DELAY_EVENT, - TRANS_CANT_DELAY_EVENT, - QOS_EVENT_MAX -} QosEvent; - -typedef enum { - WIFI_CHANNEL_QUALITY = 1, - FRAME_REALTIME_STATUS = 2, - BANDWIDTH_ESTIMATE_VALUE = 3, - JITTER_DETECTION_VALUE = 4, - STREAM_TRAFFIC_STASTICS = 5, -} TransEnumEventType; - -typedef struct { - int32_t channel; - int32_t score; -} WifiChannelQuality; - -typedef struct { - int32_t streamId; - int32_t seqNum; - int32_t level; - int32_t transStatus; - int32_t interval; -} FrameStatus; - -typedef struct { - uint32_t trend; - uint32_t rate; /* kbps */ -} BandwidthDetection; - -typedef struct { - int32_t jitterLevel; - uint32_t bufferTime; /* ms */ -} JitterEstimation; - -typedef struct { - uint64_t statisticsGotTime; /* time point that stream traficc statistics are obtained (ms) */ - uint64_t periodRecvBits; - uint32_t pktNum; - uint32_t periodRecvPkts; - uint32_t periodRecvPktLoss; - uint32_t periodRecvRate; /* kbps */ - uint64_t periodRecvRateBps; /* bps */ - uint32_t periodRtt; /* ms */ - uint32_t periodRecvPktLossHighPrecision; /* for example when lost rate is 1.10%, then 110 will returned */ - uint32_t periodSendLostPkts; - uint32_t periodSendPkts; - uint32_t periodSendPktLossHighPrecision; /* for example when lost rate is 1.10%, then 110 will returned */ - uint64_t periodSendBits; - uint64_t periodSendRateBps; /* bps */ -} StreamStatistics; - -typedef struct { - TransEnumEventType type; - union { - WifiChannelQuality wifiChannelInfo; - FrameStatus frameStatusInfo; - BandwidthDetection bandwidthInfo; - JitterEstimation jitterInfo; - StreamStatistics appStatistics; - } info; -} QosTv; - -/** - * @brief Defines session callbacks. - * - * When a session is opened or closed, or there is data to process, the related callback is invoked. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - /** - * @brief Called when a session is opened. - * - * This function can be used to verify the session or initialize resources related to the session. - * - * @param sessionId Indicates the session ID. - * @param result 0 if the session is opened successfully, returns an error code otherwise. - * @return Returns 0 if the session connection is accepted; returns a non-zero value - * otherwise (you do not need to call {@link CloseSession} to close the session). - * @since 1.0 - * @version 1.0 - */ - int (*OnSessionOpened)(int sessionId, int result); - - /** - * @brief Called when a session is closed. - * - * This function can be used to release resources related to the session. - * You do not need to call {@link CloseSession}. - * - * @param sessionId Indicates the session ID. - * @since 1.0 - * @version 1.0 - */ - void (*OnSessionClosed)(int sessionId); - - /** - * @brief Called when data is received. - * - * This function is used to notify that data is received. - * - * @param sessionId Indicates the session ID. - * @param data Indicates the pointer to the data received. - * @param dataLen Indicates the length of the data received. - * @since 1.0 - * @version 1.0 - */ - void (*OnBytesReceived)(int sessionId, const void *data, unsigned int dataLen); - - /** - * @brief Called when message is received. - * - * This function is used to notify that message is received. - * - * @param sessionId Indicates the session ID. - * @param data Indicates the pointer to the message data received. - * @param dataLen Indicates the length of the message received. - * @since 1.0 - * @version 1.0 - */ - void (*OnMessageReceived)(int sessionId, const void *data, unsigned int dataLen); - - void (*OnStreamReceived)(int sessionId, const StreamData *data, const StreamData *ext, - const StreamFrameInfo *param); - - /** - * @brief Called when QoS information is retrieved. - * - * This function is used to notify that QoS information is retrieved. - * - * @param sessionId Indicates the session ID. - * @param eventId Indicates the type of QoS information, e.g., channel quality and stream quality - * @param tvCount Indicates the number of structure returned in the fourth parameters, i.e., tvList. - * @param tvList Indicates the detailed information of data transmission. - * @since 1.0 - * @version 1.0 - */ - void (*OnQosEvent)(int sessionId, int eventId, int tvCount, const QosTv *tvList); -} ISessionListener; - -typedef struct { - int (*OnReceiveFileStarted)(int sessionId, const char *files, int fileCnt); - int (*OnReceiveFileProcess)(int sessionId, const char *firstFile, uint64_t bytesUpload, uint64_t bytesTotal); - void (*OnReceiveFileFinished)(int sessionId, const char *files, int fileCnt); - void (*OnFileTransError)(int sessionId); -} IFileReceiveListener; - -typedef struct { - int (*OnSendFileProcess)(int sessionId, uint64_t bytesUpload, uint64_t bytesTotal); - int (*OnSendFileFinished)(int sessionId, const char *firstFile); - void (*OnFileTransError)(int sessionId); -} IFileSendListener; - -/** - * @brief Creates a session server based on a package name and session name. - * - * A maximum of 18 session servers can be created. - * - * @param pkgName Indicates the pointer to the package name, which can be used to check whether the - * session server is in this package. The value cannot be empty and can contain a maximum of 64 characters. - * @param sessionName Indicates the pointer to the session name, which is the unique ID of the session server. - * The value cannot be empty and can contain a maximum of 64 characters. - * @param listener Indicates the pointer to the session callback structure, which cannot be empty. - * @return Returns 0 if the operation is successful; returns -1 otherwise. - * @see RemoveSessionServer - * @since 1.0 - * @version 1.0 - */ -int CreateSessionServer(const char *pkgName, const char *sessionName, const ISessionListener *listener) -{ - return 0; -}; - -/** - * @brief Removes a session server based on a package name and session name. - * - * @param pkgName Indicates the pointer to the name of the registered package, which can be used to check - * whether the session server is in this package. The value cannot be empty and can contain a maximum of 64 characters. - * @param sessionName Indicates the pointer to the session name. The value cannot be empty and can contain - * a maximum of 64 characters. - * @return Returns 0 if the operation is successful, returns -1 otherwise. - * @see CreateSessionServer - * @since 1.0 - * @version 1.0 - */ -int RemoveSessionServer(const char *pkgName, const char *sessionName) -{ - return 0; -}; - -/** - * @brief Initiate a session open request, which is an asynchronous process. - * - * The session connection is opened based on the service name to trigger the first packet interaction process. - * According to the {@link OnSessionOpened} Notify the user whether the session is successfully opened. - * Data can be transmitted only after the session is successfully opened. - * - * @param mySessionName local session name. - * @param peerSessionName remote session name. - * @param peerDeviceId remote device id. - * @param groupId group id. - * @param attr session attribute {@link SessionAttribute}. - * @return return sessionId if the session is opened successfully, returns an error code otherwise. - * @since 1.0 - * @version 1.0 - */ -int OpenSession(const char *mySessionName, const char *peerSessionName, const char *peerDeviceId, - const char *groupId, const SessionAttribute* attr) -{ - return 0; -}; - -/** - * @brief Closes a connected session based on a session ID. - * - * @param sessionId Indicates the session ID. - * @return no return value. - * @since 1.0 - * @version 1.0 - */ -void CloseSession(int sessionId) -{ - return; -}; - -/** - * @brief Sends data based on a session ID. - * - * @param sessionId Indicates the session ID. - * @param data Indicates the pointer to the data to send, which cannot be NULL. - * @param len Indicates the length of the data to send. The maximum length cannot exceed 984 characters. - * @return Returns 0 if the function is called successfully; returns -1 otherwise. - * @since 1.0 - * @version 1.0 - */ -int SendBytes(int sessionId, const void *data, unsigned int len) -{ - return 0; -}; - -/** - * @brief Sends message based on a session ID. - * - * @param sessionId Indicates the session ID. - * @param data Indicates the pointer to the message data to send, which cannot be NULL. - * @param len Indicates the length of the message to send. - * @return Returns 0 if the function is called successfully, returns an error code otherwise. - * @since 1.0 - * @version 1.0 - */ -int SendMessage(int sessionId, const void *data, unsigned int len) -{ - return 0; -}; - -int SendStream(int sessionId, const StreamData *data, const StreamData *ext, const StreamFrameInfo *param) -{ - return 0; -}; - -/** - * @brief Obtains the session name registered by the local device based on the session ID. - * - * @param sessionId Indicates the session ID. - * @param sessionName Indicates the pointer to the buffer for storing the session name. - * @param len Indicates the length of the buffer. - * @return Returns 0 if the operation is successful; returns -1 otherwise. - * @since 1.0 - * @version 1.0 - */ -int GetMySessionName(int sessionId, char *sessionName, unsigned int len) -{ - return 0; -}; - -/** - * @brief Obtains the session name registered by the peer device based on the session ID. - * - * @param sessionId Indicates the session ID. - * @param sessionName Indicates the pointer to the buffer for storing the session name. - * @param len Indicates the length of the buffer. - * @return Returns 0 if the operation is successful; returns -1 otherwise. - * @since 1.0 - * @version 1.0 - */ -int GetPeerSessionName(int sessionId, char *sessionName, unsigned int len) -{ - return 0; -}; - -/** - * @brief Obtains the peer device ID based on a session ID. - * - * @param sessionId Indicates the session ID. - * @param devId Indicates the pointer to the buffer for storing the device ID. - * @param len Indicates the length of the buffer. - * @return Returns 0 if the operation is successful; returns -1 otherwise. - * @since 1.0 - * @version 1.0 - */ -int GetPeerDeviceId(int sessionId, char *devId, unsigned int len) -{ - return 0; -}; - -int GetSessionSide(int sessionId) -{ - return 0; -}; - -int SetFileReceiveListener(const char *pkgName, const char *sessionName, - const IFileReceiveListener *recvListener, const char *rootDir) -{ - return 0; -}; - -int SetFileSendListener(const char *pkgName, const char *sessionName, const IFileSendListener *sendListener) -{ - return 0; -}; - -int SendFile(int sessionId, const char *sFileList[], const char *dFileList[], uint32_t fileCnt) -{ - return 0; -}; - -int32_t QosReport(int32_t sessionId, int32_t appType, int32_t quality) -{ - return 0; -}; - -#ifdef __cplusplus -} -#endif -#endif // SESSION_H diff --git a/services/sink/transport/test/sinktransunittest/mock/softbus_bus_center.h b/services/sink/transport/test/sinktransunittest/mock/softbus_bus_center.h deleted file mode 100644 index c8a5f8c..0000000 --- a/services/sink/transport/test/sinktransunittest/mock/softbus_bus_center.h +++ /dev/null @@ -1,675 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @addtogroup Softbus - * @{ - * - * @brief Provides high-speed, secure communication between devices. - * - * This module implements unified distributed communication capability management between nearby devices, and provides - * link-independent device discovery and transmission interfaces to support service publishing and data transmission. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file softbus_bus_center.h - * - * @brief Declares functions and constants for the bus center of the Intelligent Soft Bus. - * - * The functions are used to perform - * the following operations: \n - *
    - *
  • Adding a device to and removing a device from a LNN
  • - *
  • Listening for device online, offline, and information change events
  • - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef SOFTBUS_BUS_CENTER_H -#define SOFTBUS_BUS_CENTER_H - -#include -#include -#include - -#include "softbus_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Indicates the length of a device name buffer, including the terminating null character \0. - * - * @since 1.0 - * @version 1.0 - */ -#define DEVICE_NAME_BUF_LEN 128 - -/** - * @brief Indicates the mask bit for a device online event. - * If you want to receive such events, set the mask bit in {@link INodeStateCb.events}. - * - * @since 1.0 - * @version 1.0 - */ -#define EVENT_NODE_STATE_ONLINE 0x1 - -/** - * @brief Indicates the mask bit for a device offline event. - * If you want to receive such events, set the mask bit in {@link INodeStateCb.events}. - * - * @since 1.0 - * @version 1.0 - */ -#define EVENT_NODE_STATE_OFFLINE 0x02 - -/** - * @brief Indicates the mask bit for a peer device information change event. - * If you want to receive such events, set the mask bit in {@link INodeStateCb.events}. - * - * @since 1.0 - * @version 1.0 - */ -#define EVENT_NODE_STATE_INFO_CHANGED 0x04 - -/** - * @brief Indicates mask bits for {@link INodeStateCb.events}. - * - * @since 1.0 - * @version 1.0 - */ -#define EVENT_NODE_STATE_MASK 0x07 - -/** - * @brief The maximum length of meta node bypass info {@link MetaNodeConfigInfo.bypassInfo}. - * - * @since 1.0 - * @version 1.0 - */ -#define META_NODE_BYPASS_INFO_LEN 64 - -/** - * @brief The maximum of meta node {@link MetaNodeConfigInfo.bypassInfo}. - * - * @since 1.0 - * @version 1.0 - */ -#define MAX_META_NODE_NUM 3 - -/** - * @brief Enumerates keys for an online device. - * The key can be obtained via {@link GetNodeKeyInfo}. - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - NODE_KEY_UDID = 0, /**< UDID in string format*/ - NODE_KEY_UUID, /**< UUID in string format */ -} NodeDeviceInfoKey; - -/** - * @brief Enumerates accuracy for time synchronize among device. - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - LOW_ACCURACY = 10, - NORMAL_ACCURACY, - HIGH_ACCURACY, - SUPER_HIGH_ACCURACY, - UNAVAIL_ACCURACY = 0xFFFF, -} TimeSyncAccuracy; - -/** - * @brief Enumerates time synchronize period among device. - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - SHORT_PERIOD = 0, - NORMAL_PERIOD, - LONG_PERIOD, -} TimeSyncPeriod; - -/** - * @brief Enumerates time synchronize flag. - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - NODE_SPECIFIC = 0, - ALL_LNN, - WRITE_RTC, -} TimeSyncFlag; - -/** - * @brief Defines the basic information about a device. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - char networkId[NETWORK_ID_BUF_LEN]; /**< Device ID */ - char deviceName[DEVICE_NAME_BUF_LEN]; /**< Device name */ - uint16_t deviceTypeId; -} NodeBasicInfo; - -/** - * @brief Enumerates device information change types. For details, see {@link INodeStateCb.onNodeBasicInfoChanged}. - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - TYPE_NETWORK_ID = 0, /**< Network ID change */ - TYPE_DEVICE_NAME, /**< Device name change */ -} NodeBasicInfoType; - -/** - * @brief time synchronize result. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - int32_t millisecond; - int32_t microsecond; - TimeSyncAccuracy accuracy; -} TimeSyncResult; - -/** - * @brief time synchronize result info. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - TimeSyncResult result; - TimeSyncFlag flag; - union { - char targetNetworkId[NETWORK_ID_BUF_LEN]; - char masterNetworkId[NETWORK_ID_BUF_LEN]; - } target; -} TimeSyncResultInfo; - -/** - * @brief Enumerates error codes for service publishing failures. - * - * The error codes are returned to the caller through IPublishCallback. - * - */ -typedef enum { - /* publish success */ - PUBLISH_LNN_SUCCESS = 0, - /* Unsupported medium */ - PUBLISH_LNN_NOT_SUPPORT_MEDIUM = 1, - /* internal error */ - PUBLISH_LNN_INTERNAL = 2, - /* Unknown reason */ - PUBLISH_LNN_UNKNOWN = 0xFF -} PublishResult; - -/** - * @brief Enumerates error codes for service subscription failures. - * - * The error codes are returned to the caller through IDiscoveryCallback. - * - */ -typedef enum { - /* refresh success */ - REFRESH_LNN_SUCCESS = 0, - /* Unsupported medium */ - REFRESH_LNN_NOT_SUPPORT_MEDIUM = 1, - /* internal error */ - REFRESH_LNN_INTERNAL = 2, - /* Unknown error */ - REFRESH_LNN_UNKNOWN = 0xFF -} RefreshResult; - -/** - * @brief Defines the callbacks for successful and failed service publishing. - * - */ -typedef struct { - /** Callback for publish result */ - void (*OnPublishResult)(int publishId, PublishResult reason); -} IPublishCb; - -/** - * @brief Defines a callback for service subscription. - * - * Three types of callbacks are available. - * - */ -typedef struct { - /** Callback that is invoked when a device is found */ - void (*OnDeviceFound)(const DeviceInfo *device); - /** Callback for a subscription result */ - void (*OnDiscoverResult)(int32_t refreshId, RefreshResult reason); -} IRefreshCallback; - -/** - * @brief Defines a callback that is invoked when the device state or information changes. - * For details, see {@link RegNodeDeviceStateCb}. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - /** - * Mask of an event that is listened for. - * The event can be received only if the corresponding mask bit is set and the callback is specified. - */ - uint32_t events; - /** - * @brief Called when a specified device gets online. - * - * @param info Indicates the pointer to the basic information about the device. - * For details, see {@link NodeBasicInfo}. - * - * @since 1.0 - * @version 1.0 - */ - void (*onNodeOnline)(NodeBasicInfo *info); - /** - * @brief Called when a specified device gets offline. - * - * @param info Indicates the pointer to the basic information about the device. - * For details, see {@link NodeBasicInfo}. - * - * @since 1.0 - * @version 1.0 - */ - void (*onNodeOffline)(NodeBasicInfo *info); - /** - * @brief Called when the basic information of a device changes. - * - * @param type Indicates the device type. For details, see {@link NodeBasicInfoType}. - * @param info Indicates the pointer to the new basic information of the device. - * For details, see {@link NodeBasicInfo}. - * - * @since 1.0 - * @version 1.0 - */ - void (*onNodeBasicInfoChanged)(NodeBasicInfoType type, NodeBasicInfo *info); -} INodeStateCb; - -/** - * @brief Defines a callback that is invoked when the time synchronize has result. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - /** - * @brief Called when the time synchronize has result. - * - * @param info Contains the time synchronize result info, see {@link TimeSyncResultInfo}. - * @param retCode Indicates the result code. Value 0 indicates that the time synchronize is successful and - * result is valid, and any other value indicates the opposite. - * - * @since 1.0 - * @version 1.0 - */ - void (*onTimeSyncResult)(const TimeSyncResultInfo *info, int32_t retCode); -} ITimeSyncCb; - -/** - * @brief Defines a meta node configuration, see {@link ActiveMetaNode}. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - char udid[UDID_BUF_LEN]; - char deviceName[DEVICE_NAME_BUF_LEN]; - uint16_t deviceTypeId; - uint8_t addrNum; - ConnectionAddr addr[CONNECTION_ADDR_MAX]; - char bypassInfo[META_NODE_BYPASS_INFO_LEN]; -} MetaNodeConfigInfo; - -/** - * @brief Defines a meta node infomation, see {@link GetAllMetaNodeInfo}. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - char metaNodeId[NETWORK_ID_BUF_LEN]; - bool isOnline; - MetaNodeConfigInfo configInfo; -} MetaNodeInfo; - -/** - * @brief Called when a device is added to a LNN via {@link JoinLNN}. - * - * @param addr Indicates the pointer to the address of the peer device. - * @param networkId Indicates the pointer to the network ID of the device if it is successfully added to the LNN. - * This parameter makes no sense if the device fails to be added to the LNN. - * @param retCode Indicates the result code. Value 0 indicates that the device is successfully added to the LNN, - * and any other value indicates the opposite. - * - * @since 1.0 - * @version 1.0 - */ -typedef void (*OnJoinLNNResult)(ConnectionAddr *addr, const char *networkId, int32_t retCode); - -/** - * @brief Called when a device is removed from a LNN via {@link LeaveLNN}. - * - * @param networkId Indicates the pointer to the network ID of the device. - * @param retCode Indicates the result code. Value 0 indicates that the device is successfully - * removed from the LNN, and any other value indicates the opposite. - * - * @since 1.0 - * @version 1.0 - */ -typedef void (*OnLeaveLNNResult)(const char *networkId, int32_t retCode); - -/** - * @brief Adds the current device to the LNN where a specified device resides. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param target Indicates the pointer to the address of the specified device. For details, see {@link ConnectionAddr}. - * @param cb Indicates the callback for the result. If you set this parameter to NULL, you will not receive the result. - * - * @return Returns 0 if the request to add the device is accepted, and the result can be obtained from the - * callback; returns any other value if the device fails to be added to the network, in which case you will not receive - * the result. - * - * @since 1.0 - * @version 1.0 - */ -int32_t JoinLNN(const char *pkgName, ConnectionAddr *target, OnJoinLNNResult cb); - -/** - * @brief Removes the current device from the LNN. - * - * @param networkId Indicates the pointer to the network ID that is returned - * after the device is added to the LNN via {@link JoinLNN}. - * @param cb Indicates the callback for the result. If you set this parameter to NULL, - * you will not receive the result. - * - * @return Returns 0 if the request to remove the device is accepted, and the result can be obtained from the - * callback; returns any other value if the device fails to be removed from the network, in which case you will not - * receive the result. - * - * @since 1.0 - * @version 1.0 - */ -int32_t LeaveLNN(const char *pkgName, const char *networkId, OnLeaveLNNResult cb); - -/** - * @brief Registers a callback for device state changes. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param callback Indicates the pointer to the callback to register. For details, see {@link INodeStateCb}. - * - * @return Returns 0 if the registration is successful; returns any other value otherwise. - * - * @since 1.0 - * @version 1.0 - */ -int32_t RegNodeDeviceStateCb(const char *pkgName, INodeStateCb *callback) -{ - (void)pkgName; - (void)callback; - return 0; -}; - -/** - * @brief Unregisters a callback for device state changes. - * - * @param callback Indicates the pointer to the callback to unregister. For details, see {@link INodeStateCb}. - * - * @return Returns 0 if the unregistration is successful; returns any other value otherwise. - * - * @since 1.0 - * @version 1.0 - */ -int32_t UnregNodeDeviceStateCb(INodeStateCb *callback); - -/** - * @brief Obtains basic information about all the online devices. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param info Indicates the double pointer to the memory that stores the obtained basic information. - * @param infoNum Indicates the pointer to the number of devices. - * - * @return Returns 0 if the basic information is obtained, in which case info and infoNum are - * valid; returns any other value otherwise. - * - * @since 1.0 - * @version 1.0 - */ -int32_t GetAllNodeDeviceInfo(const char *pkgName, NodeBasicInfo **info, int32_t *infoNum) -{ - (void)pkgName; - (void)info; - (void)infoNum; - return 0; -}; - -/** - * @brief Releases the memory returned by {@link GetAllNodeDeviceInfo}. - * - * @param info Indicates the pointer to the memory returned by {@link GetAllNodeDeviceInfo}. - * - * @since 1.0 - * @version 1.0 - */ -void FreeNodeInfo(NodeBasicInfo *info); - -/** - * @brief Obtains basic information about the current device. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param info Indicates the double pointer to the memory that stores the obtained basic information. - * - * @return Returns 0 if the basic information is obtained, in which case info is valid; - * returns any other value otherwise. - * - * @since 1.0 - * @version 1.0 - */ -int32_t GetLocalNodeDeviceInfo(const char *pkgName, NodeBasicInfo *info) -{ - strcpy_s(info->networkId, NETWORK_ID_BUF_LEN, "test_networkId"); - strcpy_s(info->deviceName, DEVICE_NAME_BUF_LEN, "test_deviceName"); - info->deviceTypeId = 0; - return 0; -}; - -/** - * @brief Obtains a specified {@link NodeDeviceInfoKey} of an online device. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param networkId Indicates the pointer to the network ID of the device. - * @param key Indicates the key to be obtained. - * @param info Indicates the pointer to the buffer that stores the obtained key. - * @param infoLen Indicates the buffer length. - * - * @return Returns 0 if the {@link NodeDeviceInfoKey} is obtained, in which case info is valid; - * returns any other value otherwise. - * - * @since 1.0 - * @version 1.0 - */ -int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, - NodeDeviceInfoKey key, uint8_t *info, int32_t infoLen) -{ - (void)pkgName; - (void)networkId; - (void)key; - (void)info; - (void)infoLen; - return 0; -}; - -/** - * @brief Start the time synchronize with specific target node. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param targetNetworkId Indicates the pointer to the address of the specified device. - * @param accuracy Time synchronize accuracy. - * @param period Time synchronize period - * @param cb Indicates the callback for the result. - * - * @return Returns 0 if the request is accepted, and the result can be obtained from the - * callback; returns any other value if the request fails, in which case you will not receive - * the result. - * - * @since 1.0 - * @version 1.0 - */ -int32_t StartTimeSync(const char *pkgName, const char *targetNetworkId, TimeSyncAccuracy accuracy, - TimeSyncPeriod period, ITimeSyncCb *cb); - -/** - * @brief Stop the time synchronize with specific target node. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param targetNetworkId Indicates the pointer to the address of the specified device. - * - * @return Returns 0 if the request is removed; returns any other value if the request fails. - * - * @since 1.0 - * @version 1.0 - */ -int32_t StopTimeSync(const char *pkgName, const char *targetNetworkId); - -/** - * @brief Publishes a specified service. - * - * Peer devices in the same LAN as the device that publishes this service can discover this service as needed. - * The service is identified by publicId and pkgName. - * - * @param pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes. - * @param info Indicates the pointer to the service publishing information. For details, see {@link PublishInfo}. - * @param cb Indicates the pointer to the service publishing callback {@link IPublishCallback}. - * @return Returns SOFTBUS_INVALID_PARAM if any parameter is null or invalid. - * @return Returns SOFTBUS_DISCOVER_NOT_INIT if the Intelligent Soft Bus client fails to be initialized. - * @return Returns SOFTBUS_LOCK_ERR if the mutex fails to be locked. - * @return Returns SOFTBUS_OK if the service is successfully published. - */ -int32_t PublishLNN(const char *pkgName, const PublishInfo *info, const IPublishCb *cb); - -/** - * @brief stoppublishes a specified service. - * - * @param pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes. - * @param publishId Indicates the service ID. - * @return Returns SOFTBUS_INVALID_PARAM if pkgName is invalid. - * @return Returns SOFTBUS_DISCOVER_NOT_INIT if the Intelligent Soft Bus client fails to be initialized. - * @return Returns SOFTBUS_OK if the service is successfully unpublished. - */ -int32_t StopPublishLNN(const char *pkgName, int32_t publishId); - -/** - * @brief Subscribes to a specified service. - * - * Information about the device that publishes the service will be reported to the device that subscribes to - * the service. - * The service is identified by subscribeId and pkgName. - * - * @param pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes. - * @param info Indicates the pointer to the service subscription information. For details, see {@link RefreshInfo}. - * @param cb Indicates the service subscription callback {@link IRefreshCallback}. - * @return Returns SOFTBUS_INVALID_PARAM if any parameter is null or invalid. - * @return Returns SOFTBUS_DISCOVER_NOT_INIT if the Intelligent Soft Bus client fails to be initialized. - * @return Returns SOFTBUS_LOCK_ERR if the mutex fails to be locked. - * @return Returns SOFTBUS_OK if the service subscription is successful. - */ -int32_t RefreshLNN(const char *pkgName, const SubscribeInfo *info, const IRefreshCallback *cb); - -/** - * @brief Unsubscribes from a specified service. - * - * @param pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes. - * @param refreshId Indicates the service ID. - * @return Returns SOFTBUS_INVALID_PARAM if pkgName is invalid. - * @return Returns SOFTBUS_DISCOVER_NOT_INIT if the Intelligent Soft Bus client fails to be initialized. - * @return Returns SOFTBUS_OK if the service unsubscription is successful. - */ -int32_t StopRefreshLNN(const char *pkgName, int32_t refreshId); - -/** - * @brief Active meta node. The meta node online status will be notified by {@link INodeStateCb} - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param info Meta node configuration infomation, see {@link MetaNodeConfigInfo}. - * @param metaNodeId Save meta node ID when it is activated successfully, its buffer length must be not - * less then NETWORK_ID_BUF_LEN - * - * @return Returns 0 if the meta node is activated; returns any other value if the request fails. - * - * @since 1.0 - * @version 1.0 - */ -int32_t ActiveMetaNode(const char *pkgName, const MetaNodeConfigInfo *info, char *metaNodeId); - -/** - * @brief Deactive meta node. The meta node will be removed. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param metaNodeId The meta node ID which deactivated, it's obtained by {@link ActiveMetaNode}. - * - * @return Returns 0 if the meta node is deactivated; returns any other value if the request fails. - * - * @since 1.0 - * @version 1.0 - */ -int32_t DeactiveMetaNode(const char *pkgName, const char *metaNodeId); - -/** - * @brief Get all meta node by {@link ActiveMetaNode}. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param infos The buffer for save meta node info. - * @param infoNum The infos buffer num which maximum is {@link MAX_META_NODE_NUM}. - * - * @return Returns 0 if the call is success; returns any other value if it fails. - * - * @since 1.0 - * @version 1.0 - */ -int32_t GetAllMetaNodeInfo(const char *pkgName, MetaNodeInfo *infos, int32_t *infoNum); - -#ifdef __cplusplus -} -#endif - -#endif -/** @} */ \ No newline at end of file diff --git a/services/sink/transport/test/sinktransunittest/mock/softbus_common.h b/services/sink/transport/test/sinktransunittest/mock/softbus_common.h deleted file mode 100644 index e186fcf..0000000 --- a/services/sink/transport/test/sinktransunittest/mock/softbus_common.h +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @addtogroup SoftBus - * @{ - * - * @brief Provides high-speed, secure communication between devices. - * - * This module implements unified distributed communication capability management between nearby devices, and provides - * link-independent device discovery and transmission interfaces to support service publishing and data transmission. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file softbus_common.h - * - * @brief Declares common APIs for the Intelligent Soft Bus. - * - * This file provides common functions and constants for each submodule of the Intelligent Soft Bus, including: \n - * - *
      - *
    • Constants such as the network ID length
    • - *
    • Functions such as that for initializing the Intelligent Soft Bus client
    • - *
    - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef SOFTBUS_CLIENT_COMMON_H -#define SOFTBUS_CLIENT_COMMON_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Indicates the length of the Bluetooth device MAC address in string format, - * including the terminating null character \0. - * - * @since 1.0 - * @version 1.0 - */ -#define BT_MAC_LEN 18 - -/** - * @brief Indicates the length of the network ID string, including the terminating null character \0. - * - * @since 1.0 - * @version 1.0 - */ -#define NETWORK_ID_BUF_LEN 65 - -/** - * @brief Indicates the length of the UDID string, including the terminating null character \0. - * - * @since 1.0 - * @version 1.0 - */ -#define UDID_BUF_LEN 65 - -/** - * @brief Indicates the length of the UDID hash value. - * - * @since 1.0 - * @version 1.0 - */ -#define UDID_HASH_LEN 32 - -/** - * @brief Indicates the length of the UUID string, including the terminating null character \0. - * - * @since 1.0 - * @version 1.0 - */ -#define UUID_BUF_LEN 65 - -/** - * @brief Indicates the maximum length of an IP address in string format, - * including the terminating null character \0. IPv6 addresses are supported. - * - * @since 1.0 - * @version 1.0 - */ -#define IP_STR_MAX_LEN 46 - -/** - * @brief Indicates the maximum length of the account hash code in IDiscoveryCallback. - * - */ -#define MAX_ACCOUNT_HASH_LEN 96 - -/** - * @brief Indicates the maximum length of the capability data in PublishInfo and SubscribeInfo. - * - */ -#define MAX_CAPABILITYDATA_LEN 513 - -/** - * @brief Indicates the maximum length of the custom data in IDiscoveryCallback. - * - */ -#define DISC_MAX_CUST_DATA_LEN 219 - -/** - * @brief Indicates the maximum number of capabilities contained in the bitmap in IDiscoveryCallback. - * - */ -#define DISC_MAX_CAPABILITY_NUM 2 - -/** - * @brief Indicates the maximum length of the device name in IDiscoveryCallback. - * - */ -#define DISC_MAX_DEVICE_NAME_LEN 65 - -/** - * @brief Indicates the maximum length of the device ID in IDiscoveryCallback. - * - */ -#define DISC_MAX_DEVICE_ID_LEN 96 - -/** - * @brief Enumerates {@link ConnectionAddr} types of a device that is added to a LNN. - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - CONNECTION_ADDR_WLAN = 0, /**< WLAN */ - CONNECTION_ADDR_BR, /**< BR */ - CONNECTION_ADDR_BLE, /**< BLE */ - CONNECTION_ADDR_ETH, /**< Ethernet */ - CONNECTION_ADDR_MAX /**< Invalid type */ -} ConnectionAddrType; -/** - * @brief Defines the address of a device that is added to a LNN. - * For details, see {@link ConnectionAddr}. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - /**< Address type. This field is used to explain the info field. */ - ConnectionAddrType type; - /**< Connection address information */ - union { - /**< BR address */ - struct BrAddr { - char brMac[BT_MAC_LEN]; /**< BR MAC address in string format */ - } br; - /**< BLE address */ - struct BleAddr { - char bleMac[BT_MAC_LEN]; /**< BLE MAC address in string format */ - uint8_t udidHash[UDID_HASH_LEN]; /**< udid hash value */ - } ble; - /**< IPv4 or IPv6 address */ - struct IpAddr { - /** - * IP address in string format. It can be an IPv4 address written in dotted decimal notation - * or an IPv6 address written in hexadecimal colon-separated notation. - */ - char ip[IP_STR_MAX_LEN]; - uint16_t port; /**< Port number represented by the host byte order */ - } ip; - } info; - char peerUid[MAX_ACCOUNT_HASH_LEN]; -} ConnectionAddr; - -/** - * @brief Enumerates the modes in which services are published. - * - */ -typedef enum { - /* Passive */ - DISCOVER_MODE_PASSIVE = 0x55, - /* Proactive */ - DISCOVER_MODE_ACTIVE = 0xAA -} DiscoverMode; - -/** - * @brief Enumerates media, such as Bluetooth, Wi-Fi, and USB, used for publishing services. - * - * Currently, only COAP is supported. - * When AUTO is selected, all the supported media will be called automatically. - */ -typedef enum { - /** Automatic medium selection */ - AUTO = 0, - /** Bluetooth */ - BLE = 1, - /** Wi-Fi */ - COAP = 2, - /** USB */ - USB = 3, - /** HiLink */ - COAP1 = 4, - MEDIUM_BUTT -} ExchanageMedium; - -/** - * @brief Enumerates frequencies for publishing services. - * - * This enumeration applies only to Bluetooth and is not supported currently. - */ -typedef enum { - /** Low */ - LOW = 0, - /** Medium */ - MID = 1, - /** High */ - HIGH = 2, - /** Super-high */ - SUPER_HIGH = 3, - FREQ_BUTT -} ExchangeFreq; - -/** - * @brief Enumerates supported capabilities published by a device. - * - */ -typedef enum { - /** MeeTime */ - HICALL_CAPABILITY_BITMAP = 0, - /** Video reverse connection in the smart domain */ - PROFILE_CAPABILITY_BITMAP = 1, - /** Gallery in Vision */ - HOMEVISIONPIC_CAPABILITY_BITMAP = 2, - /** cast+ */ - CASTPLUS_CAPABILITY_BITMAP, - /** Input method in Vision */ - AA_CAPABILITY_BITMAP, - /** Device virtualization tool package */ - DVKIT_CAPABILITY_BITMAP, - /** Distributed middleware */ - DDMP_CAPABILITY_BITMAP, - /** Osd capability */ - OSD_CAPABILITY_BITMAP -} DataBitMap; - -/** - * @brief Defines the mapping between supported capabilities and bitmaps. - * - */ -typedef struct { - /** Bitmaps. For details, see {@link DataBitMap}. */ - DataBitMap bitmap; - /** Capability. For details, see {@link g_capabilityMap}. */ - char *capability; -} CapabilityMap; - -/** - * @brief Defines the mapping between supported capabilities and bitmaps. - * - */ -static const CapabilityMap g_capabilityMap[] = { - {HICALL_CAPABILITY_BITMAP, (char *)"hicall"}, - {PROFILE_CAPABILITY_BITMAP, (char *)"profile"}, - {HOMEVISIONPIC_CAPABILITY_BITMAP, (char *)"homevisionPic"}, - {CASTPLUS_CAPABILITY_BITMAP, (char *)"castPlus"}, - {AA_CAPABILITY_BITMAP, (char *)"aaCapability"}, - {DVKIT_CAPABILITY_BITMAP, (char *)"dvKit"}, - {DDMP_CAPABILITY_BITMAP, (char *)"ddmpCapability"}, - {OSD_CAPABILITY_BITMAP, (char *)"osdCapability"}, -}; - -/** - * @brief Defines service publishing information. - * - */ -typedef struct { - /** Service ID */ - int publishId; - /** Discovery mode for service publishing. For details, see {@link Discovermode}. */ - DiscoverMode mode; - /** Service publishing medium. For details, see {@link ExchanageMedium}. */ - ExchanageMedium medium; - /** Service publishing frequency. For details, see {@link ExchangeFre}. */ - ExchangeFreq freq; - /** Service publishing capabilities. For details, see {@link g_capabilityMap}. */ - const char *capability; - /** Capability data for service publishing */ - unsigned char *capabilityData; - /** Maximum length of the capability data for service publishing (512 bytes) */ - unsigned int dataLen; -} PublishInfo; - -/** - * @brief Defines service subscription information. - * - */ -typedef struct { - /** Service ID */ - int subscribeId; - /** Discovery mode for service subscription. For details, see {@link Discovermode}. */ - DiscoverMode mode; - /** Service subscription medium. For details, see {@link ExchanageMedium}. */ - ExchanageMedium medium; - /** Service subscription frequency. For details, see {@link ExchangeFre}. */ - ExchangeFreq freq; - /** only find the device with the same account */ - bool isSameAccount; - /** find the sleeping devices */ - bool isWakeRemote; - /** Service subscription capability. For details, see {@link g_capabilityMap}. */ - const char *capability; - /** Capability data for service subscription */ - unsigned char *capabilityData; - /** Maximum length of the capability data for service subscription (512 bytes) */ - unsigned int dataLen; -} SubscribeInfo; - -/** - * @brief Enumerates device types. - * - */ -typedef enum { - /* Smart speaker */ - SMART_SPEAKER = 0x00, - /* PC */ - DESKTOP_PC, - /* Laptop */ - LAPTOP, - /* Mobile phone */ - SMART_PHONE, - /* Tablet */ - SMART_PAD, - /* Smart watch */ - SMART_WATCH, - /* Smart car */ - SMART_CAR, - /* Kids' watch */ - CHILDREN_WATCH, - /* Smart TV */ - SMART_TV, -} DeviceType; - -/** - * @brief Defines the device information returned by IDiscoveryCallback. - * - */ -typedef struct { - /** Device ID. Its maximum length is specified by {@link DISC_MAX_DEVICE_ID_LEN}. */ - char devId[DISC_MAX_DEVICE_ID_LEN]; - /** Account hash code. Its maximum length is specified by {@link MAX_ACCOUNT_HASH_LEN}. */ - char accountHash[MAX_ACCOUNT_HASH_LEN]; - /** Device type. For details, see {@link DeviceType}. */ - DeviceType devType; - /** Device name. Its maximum length is specified by {@link DISC_MAX_DEVICE_NAME_LEN}. */ - char devName[DISC_MAX_DEVICE_NAME_LEN]; - /** Number of available connections */ - unsigned int addrNum; - /** Connection information. For details, see {@link ConnectAddr}. */ - ConnectionAddr addr[CONNECTION_ADDR_MAX]; - /** Number of capabilities */ - unsigned int capabilityBitmapNum; - /** Device capability bitmap. - * The maximum number of capabilities in the bitmap is specified by {@link DISC_MAX_CAPABILITY_NUM}. - */ - unsigned int capabilityBitmap[DISC_MAX_CAPABILITY_NUM]; - /** Custom data. Its length is specified by {@link DISC_MAX_CUST_DATA_LEN}. */ - char custData[DISC_MAX_CUST_DATA_LEN]; -} DeviceInfo; -#ifdef __cplusplus -} -#endif -#endif -/** @} */ diff --git a/services/source/inputinject/BUILD.gn b/services/source/inputinject/BUILD.gn deleted file mode 100644 index ee839a3..0000000 --- a/services/source/inputinject/BUILD.gn +++ /dev/null @@ -1,65 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//foundation/distributedhardware/distributedinput/distributedinput.gni") - -ohos_shared_library("libdinput_inject") { - include_dirs = [ - "include", - "${common_path}/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "//third_party/json/include", - ] - - sources = [ - "src/distributed_input_inject.cpp", - "src/distributed_input_node_manager.cpp", - "src/virtual_device.cpp", - "src/virtual_keyboard.cpp", - "src/virtual_mouse.cpp", - "src/virtual_touchpad.cpp", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedinputinjectkit\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "//foundation/bundlemanager/bundle_framework/interfaces/innerkits/libeventhandler:libeventhandler", - "//utils/native/base:utils", - "${fwk_utils_path}:distributedhardwareutils", - "//third_party/openssl:libcrypto_static", - ] - - external_deps = [ - "ipc:ipc_core", - "safwk:system_ability_fwk", - "hiviewdfx_hilog_native:libhilog", - "samgr_standard:samgr_proxy", - ] - - cflags_cc = [ "-DHILOG_ENABLE" ] - - subsystem_name = "distributedhardware" - - part_name = "distributed_input" - -} diff --git a/services/source/inputinject/include/distributed_input_inject.h b/services/source/inputinject/include/distributed_input_inject.h deleted file mode 100644 index 2d48278..0000000 --- a/services/source/inputinject/include/distributed_input_inject.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISTRIBUTED_INPUT_INJECT_H -#define DISTRIBUTED_INPUT_INJECT_H - -#include -#include - -#include "constants_dinput.h" -#include "distributed_input_node_manager.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputInject { -public: - static DistributedInputInject &GetInstance(); - int32_t RegisterDistributedHardware(const std::string& devId, const std::string& dhId, - const std::string& parameters); - - int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId); - int32_t RegisterDistributedEvent(RawEvent* buffer, size_t bufferSize); - int32_t StructTransJson(const InputDevice& pBuf, std::string& strDescriptor); - void StartInjectThread(); - void StopInjectThread(); - -private: - DistributedInputInject(); - ~DistributedInputInject(); - - std::unique_ptr inputNodeManager_; - - // The event queue. - static const int EVENT_BUFFER_SIZE = 16; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - -#endif // DISTRIBUTED_INPUT_INJECT_H \ No newline at end of file diff --git a/services/source/inputinject/include/distributed_input_node_manager.h b/services/source/inputinject/include/distributed_input_node_manager.h deleted file mode 100644 index faf467b..0000000 --- a/services/source/inputinject/include/distributed_input_node_manager.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISTRIBUTED_INPUT_NODE_MANAGER_H -#define DISTRIBUTED_INPUT_NODE_MANAGER_H - -#include -#include -#include -#include -#include -#include -#include - -#include "constants_dinput.h" -#include "virtual_device.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputNodeManager { -public: - DistributedInputNodeManager(); - ~DistributedInputNodeManager(); - - int32_t openDevicesNode(const std::string& devId, const std::string& dhId, - const std::string& parameters); - - int32_t getDevice(const std::string& dhId, VirtualDevice*& device); - void ReportEvent(const RawEvent rawEvent); - int32_t CloseDeviceLocked(const std::string& dhId); - void StartInjectThread(); - void StopInjectThread(); - -private: - void AddDeviceLocked(const std::string& dhId, std::unique_ptr device); - int32_t CreateHandle(InputDevice event, const std::string& devId); - void CloseAllDevicesLocked(); - void stringTransJsonTransStruct(const std::string& str, InputDevice& pBuf); - void InjectEvent(); - void ProcessInjectEvent(const std::shared_ptr &rawEvent); - - std::atomic isInjectThreadRunning_; - std::map> devices_; - std::mutex operationMutex_; - std::thread eventInjectThread_; - std::mutex mutex_; - std::condition_variable conditionVariable_; - std::queue> injectQueue_; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - -#endif // DISTRIBUTED_INPUT_INJECT_H \ No newline at end of file diff --git a/services/source/inputinject/include/virtual_device.h b/services/source/inputinject/include/virtual_device.h deleted file mode 100644 index 023f2cc..0000000 --- a/services/source/inputinject/include/virtual_device.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_VIRTUAL_DEVICE_H -#define OHOS_VIRTUAL_DEVICE_H - -#include -#include -#include - -#include -#include -#include - -#include -#include "linux/uinput.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class VirtualDevice { -public: - VirtualDevice(const std::string &device_name, uint16_t busType, - uint16_t vendorId, uint16_t product_id, uint16_t version); - virtual ~VirtualDevice(); - bool DoIoctl(int32_t fd, int32_t request, const uint32_t value); - bool CreateKey(); - bool SetPhys(const std::string deviceName); - bool SetUp(); - bool InjectInputEvent(const input_event& event); - void SetNetWorkId(const std::string netWorkId); - -protected: - VirtualDevice(); - virtual const std::vector& GetEventTypes() const = 0; - virtual const std::vector& GetKeys() const = 0; - virtual const std::vector& GetProperties() const = 0; - virtual const std::vector& GetAbs() const = 0; - virtual const std::vector& GetRelBits() const = 0; - - int32_t fd_ = -1; - std::string deviceName_; - std::string netWorkId_; - const uint16_t busTtype_; - const uint16_t vendorId_; - const uint16_t productId_; - const uint16_t version_; - struct uinput_user_dev dev_ {}; - struct uinput_abs_setup absTemp_ = {}; - std::vector absInit_; - const std::string pid_ = std::to_string(getpid()); -}; -} -} -} -#endif // OHOS_VIRTUAL_DEVICE_H diff --git a/services/source/inputinject/include/virtual_keyboard.h b/services/source/inputinject/include/virtual_keyboard.h deleted file mode 100644 index dd57c9b..0000000 --- a/services/source/inputinject/include/virtual_keyboard.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_VIRTUAL_KEYBOARD_H -#define OHOS_VIRTUAL_KEYBOARD_H - -#include "virtual_device.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class VirtualKeyboard : public VirtualDevice { -public: - VirtualKeyboard(const std::string &device_name, uint16_t busType, - uint16_t vendorId, uint16_t product_id, uint16_t version); - ~VirtualKeyboard(); -protected: - const std::vector& GetEventTypes() const override; - const std::vector& GetKeys() const override; - const std::vector& GetProperties() const override; - const std::vector& GetAbs() const override; - const std::vector& GetRelBits() const override; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_VIRTUAL_KEYBOARD_H diff --git a/services/source/inputinject/include/virtual_mouse.h b/services/source/inputinject/include/virtual_mouse.h deleted file mode 100644 index 722dc4a..0000000 --- a/services/source/inputinject/include/virtual_mouse.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_VIRTUAL_MOUSE_H -#define OHOS_VIRTUAL_MOUSE_H - -#include "virtual_device.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class VirtualMouse : public VirtualDevice { -public: - VirtualMouse(const std::string &device_name, uint16_t busType, - uint16_t vendorId, uint16_t product_id, uint16_t version); - ~VirtualMouse(); -protected: - const std::vector& GetEventTypes() const override; - const std::vector& GetKeys() const override; - const std::vector& GetRelBits() const override; - const std::vector& GetProperties() const override; - const std::vector& GetAbs() const override; -}; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -#endif // VIRTUALKEYBOARD_H diff --git a/services/source/inputinject/include/virtual_touchpad.h b/services/source/inputinject/include/virtual_touchpad.h deleted file mode 100644 index b909ba3..0000000 --- a/services/source/inputinject/include/virtual_touchpad.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_VIRTUAL_TOUCHPAD_H -#define OHOS_VIRTUAL_TOUCHPAD_H - -#include "virtual_device.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class VirtualTouchpad : public VirtualDevice { -public: - VirtualTouchpad(const std::string &device_name, uint16_t busType, - uint16_t vendorId, uint16_t product_id, uint16_t version); - ~VirtualTouchpad(); -protected: - const std::vector& GetEventTypes() const override; - const std::vector& GetKeys() const override; - const std::vector& GetAbs()const override; - const std::vector& GetProperties() const override; - const std::vector& GetRelBits() const override; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS -#endif diff --git a/services/source/inputinject/src/distributed_input_inject.cpp b/services/source/inputinject/src/distributed_input_inject.cpp deleted file mode 100644 index 744360a..0000000 --- a/services/source/inputinject/src/distributed_input_inject.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_input_inject.h" - -#include - -#include "anonymous_string.h" -#include "distributed_hardware_log.h" -#include "nlohmann/json.hpp" - -#include "dinput_errcode.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -DistributedInputInject::DistributedInputInject() -{ - inputNodeManager_ = std::make_unique(); -} - -DistributedInputInject::~DistributedInputInject() -{ - DHLOGI("~DistributedInputInject"); -} - -DistributedInputInject &DistributedInputInject::GetInstance() -{ - static DistributedInputInject instance; - return instance; -} - -int32_t DistributedInputInject::RegisterDistributedHardware(const std::string& devId, const std::string& dhId, - const std::string& parameters) -{ - DHLOGI("%s called, deviceId: %s, dhId: %s, parameters: %s", - __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), parameters.c_str()); - - if (inputNodeManager_ == nullptr) { - DHLOGE("the DistributedInputNodeManager is null\n"); - return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL; - } - if (inputNodeManager_->openDevicesNode(devId, dhId, parameters) < 0) { - DHLOGE("create virtual device error\n"); - return ERR_DH_INPUT_SERVER_SOURCE_INJECT_REGISTER_FAIL; - } - return DH_SUCCESS; -} - -int32_t DistributedInputInject::UnregisterDistributedHardware(const std::string& devId, const std::string& dhId) -{ - DHLOGI("%s called, deviceId: %s, dhId: %s", - __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); - if (inputNodeManager_ == nullptr) { - DHLOGE("the DistributedInputNodeManager is null\n"); - return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL; - } - if (inputNodeManager_->CloseDeviceLocked(dhId) < 0) { - DHLOGE("delete virtual device error\n"); - return ERR_DH_INPUT_SERVER_SOURCE_INJECT_UNREGISTER_FAIL; - } - return DH_SUCCESS; -} - -int32_t DistributedInputInject::StructTransJson(const InputDevice& pBuf, std::string& strDescriptor) -{ - DHLOGI( - "[%s] %d, %d, %d, %d, %s.\n", - (pBuf.name).c_str(), pBuf.bus, pBuf.vendor, pBuf.product, pBuf.version, (pBuf.descriptor).c_str()); - nlohmann::json tmpJson; - tmpJson["name"] = pBuf.name; - tmpJson["location"] = pBuf.location; - tmpJson["uniqueId"] = pBuf.uniqueId; - tmpJson["bus"] = pBuf.bus; - tmpJson["vendor"] = pBuf.vendor; - tmpJson["product"] = pBuf.product; - tmpJson["version"] = pBuf.version; - tmpJson["descriptor"] = pBuf.descriptor; - tmpJson["nonce"] = pBuf.nonce; - tmpJson["classes"] = pBuf.classes; - - std::ostringstream stream; - stream << tmpJson.dump(); - strDescriptor = stream.str(); - return DH_SUCCESS; -} - -int32_t DistributedInputInject::RegisterDistributedEvent(RawEvent* buffer, size_t bufferSize) -{ - if (inputNodeManager_ == nullptr) { - DHLOGE("the DistributedInputNodeManager is null\n"); - return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL; - } - DHLOGE("RegisterDistributedEvent start %zu\n", bufferSize); - for (size_t i = 0; i < bufferSize; i++) { - inputNodeManager_->ReportEvent(buffer[i]); - } - return DH_SUCCESS; -} - -void DistributedInputInject::StartInjectThread() -{ - if (inputNodeManager_ != nullptr) { - inputNodeManager_->StartInjectThread(); - } -} - -void DistributedInputInject::StopInjectThread() -{ - if (inputNodeManager_ != nullptr) { - inputNodeManager_->StopInjectThread(); - } -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp deleted file mode 100644 index 52fb031..0000000 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_input_node_manager.h" - -#include -#include - -#include -#include - -#include "anonymous_string.h" -#include "distributed_hardware_log.h" -#include "nlohmann/json.hpp" - -#include "dinput_errcode.h" -#include "virtual_keyboard.h" -#include "virtual_mouse.h" -#include "virtual_touchpad.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -namespace { -static const uint32_t INPUT_DEVICE_CLASS_KEYBOARD = static_cast(DeviceClasses::INPUT_DEVICE_CLASS_KEYBOARD); -static const uint32_t INPUT_DEVICE_CLASS_CURSOR = static_cast(DeviceClasses::INPUT_DEVICE_CLASS_CURSOR); -static const uint32_t INPUT_DEVICE_CLASS_TOUCH = static_cast(DeviceClasses::INPUT_DEVICE_CLASS_TOUCH); -} - -DistributedInputNodeManager::DistributedInputNodeManager() : isInjectThreadRunning_(false) -{ -} - -DistributedInputNodeManager::~DistributedInputNodeManager() -{ - CloseAllDevicesLocked(); - isInjectThreadRunning_.store(false); - if (eventInjectThread_.joinable()) { - eventInjectThread_.join(); - } -} - -int32_t DistributedInputNodeManager::openDevicesNode(const std::string& devId, const std::string& dhId, - const std::string& parameters) -{ - InputDevice event; - stringTransJsonTransStruct(parameters, event); - if (CreateHandle(event, devId) < 0) { - return ERR_DH_INPUT_SERVER_SOURCE_OPEN_DEVICE_NODE_FAIL; - } - - return DH_SUCCESS; -} - -void DistributedInputNodeManager::stringTransJsonTransStruct(const std::string& str, InputDevice& pBuf) -{ - nlohmann::json recMsg = nlohmann::json::parse(str); - recMsg.at("name").get_to(pBuf.name); - recMsg.at("location").get_to(pBuf.location); - recMsg.at("uniqueId").get_to(pBuf.uniqueId); - recMsg.at("bus").get_to(pBuf.bus); - recMsg.at("vendor").get_to(pBuf.vendor); - recMsg.at("product").get_to(pBuf.product); - recMsg.at("version").get_to(pBuf.version); - recMsg.at("descriptor").get_to(pBuf.descriptor); - recMsg.at("nonce").get_to(pBuf.nonce); - recMsg.at("classes").get_to(pBuf.classes); -} - -int32_t DistributedInputNodeManager::CreateHandle(InputDevice event, const std::string& devId) -{ - std::unique_lock my_lock(operationMutex_); - std::unique_ptr device; - if (event.classes & INPUT_DEVICE_CLASS_KEYBOARD) { - device = std::make_unique(event.name, event.bus, event.vendor, event.product, event.version); - } else if (event.classes & INPUT_DEVICE_CLASS_CURSOR) { - device = std::make_unique(event.name, event.bus, event.vendor, event.product, event.version); - } else if (event.classes & INPUT_DEVICE_CLASS_TOUCH) { - device = std::make_unique(event.name, event.bus, event.vendor, event.product, event.version); - } else { - DHLOGW("could not find the deviceType\n"); - return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL; - } - - if (device == nullptr) { - DHLOGE("could not create new virtual device == null\n"); - return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL; - } - - device->SetNetWorkId(devId); - - if (!device->SetUp()) { - DHLOGE("could not create new virtual device\n"); - return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL; - } - AddDeviceLocked(event.descriptor, std::move(device)); - return DH_SUCCESS; -} - -void DistributedInputNodeManager::AddDeviceLocked(const std::string& dhId, std::unique_ptr device) -{ - auto [dev_it, inserted] = devices_.insert_or_assign(dhId, std::move(device)); - if (!inserted) { - DHLOGI("Device id %s exists, replaced. \n", GetAnonyString(dhId).c_str()); - } -} - -int32_t DistributedInputNodeManager::CloseDeviceLocked(const std::string &dhId) -{ - DHLOGI("%s called, dhId=%s", __func__, GetAnonyString(dhId).c_str()); - std::map>::iterator iter = devices_.find(dhId); - if (iter != devices_.end()) { - devices_.erase(iter); - return DH_SUCCESS; - } - DHLOGE("%s called failure, dhId=%s", __func__, GetAnonyString(dhId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_CLOSE_DEVICE_FAIL; -} - -void DistributedInputNodeManager::CloseAllDevicesLocked() -{ - for (const auto & [id, virDevice] : devices_) { - CloseDeviceLocked(id); - } -} - -int32_t DistributedInputNodeManager::getDevice(const std::string& dhId, VirtualDevice*& device) -{ - for (const auto& [id, virdevice] : devices_) { - if (id == dhId) { - device = virdevice.get(); - return DH_SUCCESS; - } - } - return ERR_DH_INPUT_SERVER_SOURCE_GET_DEVICE_FAIL; -} - -void DistributedInputNodeManager::StartInjectThread() -{ - DHLOGI("start"); - isInjectThreadRunning_.store(true); - eventInjectThread_ = std::thread(&DistributedInputNodeManager::InjectEvent, this); -} - -void DistributedInputNodeManager::StopInjectThread() -{ - DHLOGI("start"); - isInjectThreadRunning_.store(false); - if (eventInjectThread_.joinable()) { - eventInjectThread_.join(); - } -} - -void DistributedInputNodeManager::ReportEvent(const RawEvent rawEvent) -{ - std::lock_guard lockGuard(mutex_); - injectQueue_.push(std::make_shared(rawEvent)); - conditionVariable_.notify_all(); -} - -void DistributedInputNodeManager::InjectEvent() -{ - DHLOGI("start"); - while (isInjectThreadRunning_.load()) { - std::shared_ptr event = nullptr; - { - std::unique_lock waitEventLock(mutex_); - conditionVariable_.wait(waitEventLock, [this] () { return !injectQueue_.empty(); }); - if (injectQueue_.empty()) { - continue; - } - event = injectQueue_.front(); - injectQueue_.pop(); - } - if (event == nullptr) { - DHLOGD("event is null!"); - continue; - } - - DHLOGD("process event, inject queue size: %zu", injectQueue_.size()); - ProcessInjectEvent(event); - } -} - -void DistributedInputNodeManager::ProcessInjectEvent(const std::shared_ptr &rawEvent) -{ - std::string dhId = rawEvent->descriptor; - struct input_event event = { - .type = rawEvent->type, - .code = rawEvent->code, - .value = rawEvent->value - }; - DHLOGI("InjectEvent dhId: %s, eventType: %d, eventCode: %d, eventValue: %d, when: " PRId64"", - GetAnonyString(dhId).c_str(), event.type, event.code, event.value, rawEvent->when); - VirtualDevice* device = nullptr; - if (getDevice(dhId, device) < 0) { - DHLOGE("could not find the device"); - return; - } - if (device != nullptr) { - device->InjectInputEvent(event); - } -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/source/inputinject/src/virtual_device.cpp b/services/source/inputinject/src/virtual_device.cpp deleted file mode 100644 index 76d15fe..0000000 --- a/services/source/inputinject/src/virtual_device.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "virtual_device.h" - -#include - -#include "anonymous_string.h" -#include "distributed_hardware_log.h" - -#include "constants_dinput.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -VirtualDevice::VirtualDevice() - : deviceName_(""), netWorkId_(""), busTtype_(0), vendorId_(0), productId_(0), version_(0) -{ -} - -VirtualDevice::VirtualDevice(const std::string &device_name, uint16_t busType, - uint16_t vendorId, uint16_t product_id, uint16_t version) : deviceName_( - device_name), busTtype_(busType), vendorId_(vendorId), productId_(product_id), version_(version) -{ -} - -VirtualDevice::~VirtualDevice() -{ - if (fd_ >= 0) { - ioctl(fd_, UI_DEV_DESTROY); - close(fd_); - fd_ = -1; - } -} - -bool VirtualDevice::DoIoctl(int32_t fd, int32_t request, const uint32_t value) -{ - int32_t rc = ioctl(fd, request, value); - if (rc < 0) { - DHLOGE("%s ioctl failed", __func__); - return false; - } - return true; -} - -bool VirtualDevice::CreateKey() -{ - auto fun = [&](int32_t uiSet, const std::vector& list) -> bool { - for (uint32_t evt_type : list) { - if (!DoIoctl(fd_, uiSet, evt_type)) { - DHLOGE( - "%s Error setting event type: %u", __func__, evt_type); - return false; - } - } - return true; - }; - - std::map> evt_type; - evt_type[UI_SET_EVBIT] = GetEventTypes(); - evt_type[UI_SET_KEYBIT] = GetKeys(); - evt_type[UI_SET_PROPBIT] = GetProperties(); - evt_type[UI_SET_ABSBIT] = GetAbs(); - evt_type[UI_SET_RELBIT] = GetRelBits(); - for (auto &it : evt_type) { - if (!fun(it.first, it.second)) { - return false; - } - } - - return true; -} - -bool VirtualDevice::SetPhys(const std::string deviceName) -{ - std::string phys; - phys.append(deviceName).append(pid_).append("/").append(pid_).append("|").append(netWorkId_); - - if (ioctl(fd_, UI_SET_PHYS, phys.c_str()) < 0) { - return false; - } - return true; -} - -bool VirtualDevice::SetUp() -{ - fd_ = open("/dev/uinput", O_WRONLY | O_NONBLOCK); - if (fd_ < 0) { - DHLOGE("Failed to open uinput %s", __func__); - return false; - } - - deviceName_ = VIRTUAL_DEVICE_NAME + deviceName_; - if (strncpy_s(dev_.name, sizeof(dev_.name), deviceName_.c_str(), deviceName_.size()) != 0) { - return false; - }; - - dev_.id.bustype = busTtype_; - dev_.id.vendor = vendorId_; - dev_.id.product = productId_; - dev_.id.version = version_; - - if (!SetPhys(deviceName_)) { - DHLOGE("Failed to set PHYS! %s", __func__); - return false; - } - - if (!CreateKey()) { - DHLOGE("Failed to create KeyValue %s", __func__); - return false; - } - - if (write(fd_, &dev_, sizeof(dev_)) < 0) { - DHLOGE("Unable to set input device info: %s", __func__); - return false; - } - - if (ioctl(fd_, UI_DEV_CREATE) < 0) { - DHLOGE( - "fd = %d, ioctl(fd_, UI_DEV_CREATE) = %d", - fd_, ioctl(fd_, UI_DEV_CREATE)); - DHLOGE("Unable to create input device : %s", __func__); - return false; - } - - char sysfs_device_name[16]; - if (ioctl(fd_, UI_GET_SYSNAME(sizeof(sysfs_device_name)), sysfs_device_name) < 0) { - DHLOGE("Unable to get input device name: %s", __func__); - } - DHLOGI("get input device name: %s", GetAnonyString(sysfs_device_name).c_str()); - return true; -} - -bool VirtualDevice::InjectInputEvent(const input_event& event) -{ - DHLOGI("InjectInputEvent %d", fd_); - - if (write(fd_, &event, sizeof(event)) < static_cast(sizeof(event))) { - DHLOGE("could not inject event, removed? (fd: %d", fd_); - return false; - } - if (event.type == EV_KEY) { - DHLOGD("4.E2E-Test Source write event into input driver EV_KEY, Code: %d, Value: %d, Sec: %ld, Sec1: %ld", - event.code, event.value, event.input_event_sec, event.input_event_usec); - } else if (event.type == EV_REL) { - DHLOGD("4.E2E-Test Source write event into input driver EV_REL, Code: %d, Value: %d, Sec: %ld, Sec1: %ld", - event.code, event.value, event.input_event_sec, event.input_event_usec); - } else if (event.type == EV_ABS) { - DHLOGD("4.E2E-Test Source write event into input driver EV_ABS, Code: %d, Value: %d, Sec: %ld, Sec1: %ld", - event.code, event.value, event.input_event_sec, event.input_event_usec); - } else { - DHLOGW("4.E2E-Test Source write event into input driver other type!"); - } - DHLOGE("InjectInputEvent end\n"); - - return true; -} - -void VirtualDevice::SetNetWorkId(const std::string netWorkId) -{ - DHLOGI("SetNetWorkId %s\n", GetAnonyString(netWorkId).c_str()); - netWorkId_.append(netWorkId); -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/source/inputinject/src/virtual_keyboard.cpp b/services/source/inputinject/src/virtual_keyboard.cpp deleted file mode 100644 index c1510eb..0000000 --- a/services/source/inputinject/src/virtual_keyboard.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "virtual_keyboard.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -VirtualKeyboard::VirtualKeyboard(const std::string &device_name, uint16_t busType, - uint16_t vendorId, uint16_t product_id, uint16_t version) : VirtualDevice( - device_name, busType, vendorId, product_id, version) {} - -VirtualKeyboard::~VirtualKeyboard() {} - -static std::vector g_virtualKey = { - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 85, - 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, - 113, 114, 115, 116, 117, 119, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, - 137, 138, 140, 142, 150, 152, 158, 159, 161, 163, 164, 165, 166, 173, 176, 177, 178, 179, 180, 183, 184, 185, - 186, 187, 188, 189, 190, 191, 192, 193, 194, 240, 211, 213, 214, 215, 218, 220, 221, 222, 223, 226, 227, 231, - 232, 233, 236, 237, 238, 239, 242, 243, 245, 246, 247, 248, 464, 522, 523, 141, 145, 146, 147, 148, 149, 151, - 153, 154, 157, 160, 162, 170, 175, 182, 200, 201, 202, 203, 204, 205, 101, 112, 118, 120 -}; - -const std::vector& VirtualKeyboard::GetEventTypes() const -{ - static const std::vector evt_types { - EV_KEY, EV_MSC, EV_LED, EV_REP, EV_SYN - }; - return evt_types; -} - -const std::vector& VirtualKeyboard::GetKeys() const -{ - static const std::vector keys(g_virtualKey.begin(), g_virtualKey.end()); - - return keys; -} - -const std::vector& VirtualKeyboard::GetProperties() const -{ - static const std::vector properties { - }; - return properties; -} - -const std::vector& VirtualKeyboard::GetAbs() const -{ - static const std::vector abs { - }; - return abs; -} - -const std::vector& VirtualKeyboard::GetRelBits() const -{ - static const std::vector relBits { - }; - return relBits; -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/source/inputinject/src/virtual_mouse.cpp b/services/source/inputinject/src/virtual_mouse.cpp deleted file mode 100644 index f383017..0000000 --- a/services/source/inputinject/src/virtual_mouse.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "virtual_mouse.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -VirtualMouse::VirtualMouse(const std::string &device_name, uint16_t busType, - uint16_t vendorId, uint16_t product_id, uint16_t version) : VirtualDevice( - device_name, busType, vendorId, product_id, version) {} - -VirtualMouse::~VirtualMouse() {} - -const std::vector& VirtualMouse::GetEventTypes() const -{ - static const std::vector evt_types { - EV_KEY, EV_REL, EV_MSC, EV_SYN - }; - return evt_types; -} - -const std::vector& VirtualMouse::GetKeys() const -{ - static const std::vector keys { - BTN_MOUSE, BTN_LEFT, BTN_RIGHT, BTN_MIDDLE, BTN_SIDE, BTN_EXTRA, BTN_FORWARD, BTN_BACK, BTN_TASK - }; - return keys; -} - -const std::vector& VirtualMouse::GetProperties() const -{ - static const std::vector properties { - }; - return properties; -} - -const std::vector& VirtualMouse::GetAbs() const -{ - static const std::vector abs { - }; - return abs; -} - -const std::vector& VirtualMouse::GetRelBits() const -{ - static const std::vector rels { - REL_X, REL_Y, REL_WHEEL, REL_WHEEL_HI_RES - }; - return rels; -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - diff --git a/services/source/inputinject/src/virtual_touchpad.cpp b/services/source/inputinject/src/virtual_touchpad.cpp deleted file mode 100644 index 0cc18a9..0000000 --- a/services/source/inputinject/src/virtual_touchpad.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "virtual_touchpad.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -VirtualTouchpad::VirtualTouchpad(const std::string &device_name, uint16_t busType, - uint16_t vendorId, uint16_t product_id, uint16_t version) : VirtualDevice( - device_name, busType, vendorId, product_id, version) -{ - const int ABS_MAX_WHEEL = 71; - - dev_.absmin[ABS_X] = 0; - dev_.absmax[ABS_X] = 1; - dev_.absfuzz[ABS_X] = 0; - dev_.absflat[ABS_X] = 0; - - dev_.absmin[ABS_Y] = 0; - dev_.absmax[ABS_Y] = 1; - dev_.absfuzz[ABS_Y] = 0; - dev_.absflat[ABS_Y] = 0; - - dev_.absmin[ABS_WHEEL] = 0; - dev_.absmax[ABS_WHEEL] = ABS_MAX_WHEEL; - dev_.absfuzz[ABS_WHEEL] = 0; - dev_.absflat[ABS_WHEEL] = 0; - - dev_.absmin[ABS_MISC] = 0; - dev_.absmax[ABS_MISC] = 0; - dev_.absfuzz[ABS_MISC] = 0; - dev_.absflat[ABS_MISC] = 0; -} - -VirtualTouchpad::~VirtualTouchpad() {} - -const std::vector& VirtualTouchpad::GetEventTypes() const -{ - static const std::vector evt_types { - EV_KEY, EV_ABS - }; - return evt_types; -} - -const std::vector& VirtualTouchpad::GetKeys() const -{ - static const std::vector keys { - BTN_0, BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_STYLUS, BTN_TOOL_PEN - }; - return keys; -} - -const std::vector& VirtualTouchpad::GetProperties() const -{ - static const std::vector properties { - }; - return properties; -} - -const std::vector& VirtualTouchpad::GetAbs() const -{ - static const std::vector abs { - ABS_X, ABS_Y, ABS_WHEEL, ABS_MISC - }; - return abs; -} - -const std::vector& VirtualTouchpad::GetRelBits() const -{ - static const std::vector relBits { - }; - return relBits; -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - diff --git a/services/source/inputinject/test/BUILD.gn b/services/source/inputinject/test/BUILD.gn deleted file mode 100644 index 9d690cb..0000000 --- a/services/source/inputinject/test/BUILD.gn +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -group("test") { - testonly = true - - deps = [ "sourceinjectunittest:sourceinjectunittest" ] -} diff --git a/services/source/inputinject/test/sourceinjectunittest/BUILD.gn b/services/source/inputinject/test/sourceinjectunittest/BUILD.gn deleted file mode 100644 index 1e8fe38..0000000 --- a/services/source/inputinject/test/sourceinjectunittest/BUILD.gn +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/test.gni") -import("//foundation/distributedhardware/distributedinput/distributedinput.gni") -module_out_path = "distributedinput_stander/source_inject" - -group("sourceinjectunittest") { - testonly = true - - deps = [ ":distributed_input_inner_sourceinject_test" ] -} - -## UnitTest distributed_input_manager_service_test {{{ -ohos_unittest("distributed_input_inner_sourceinject_test") { - module_out_path = module_out_path - - include_dirs = [ - "${innerkits_path}/include", - "${innerkits_path}/src", - "${ipc_path}/include", - "${ipc_path}/src", - "//foundation/distributedhardware/distributedinput/services/source/inputinject/include", - "//foundation/distributedhardware/distributedinput/frameworks/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${common_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${service_common}/include", - "//third_party/json/include", - "//foundation/communication/dsoftbus/interfaces/kits/transport", - ] - - sources = [ - "//foundation/distributedhardware/distributedinput/services/source/inputinject/src/distributed_input_inject.cpp", - "//foundation/distributedhardware/distributedinput/services/source/inputinject/src/distributed_input_node_manager.cpp", - "//foundation/distributedhardware/distributedinput/services/source/inputinject/src/virtual_device.cpp", - "//foundation/distributedhardware/distributedinput/services/source/inputinject/src/virtual_keyboard.cpp", - "//foundation/distributedhardware/distributedinput/services/source/inputinject/src/virtual_mouse.cpp", - "//foundation/distributedhardware/distributedinput/services/source/inputinject/src/virtual_touchpad.cpp", - "distributed_input_sourceinject_test.cpp", - ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", - "-Dprivate=public", - "-Dprotected=public", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedinpututtest\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "//foundation/bundlemanager/bundle_framework/interfaces/innerkits/libeventhandler:libeventhandler", - "//utils/native/base:utils", - "${fwk_utils_path}:distributedhardwareutils", - "//foundation/communication/dsoftbus/sdk:softbus_client", - ] - - external_deps = [ - "ipc:ipc_core", - "safwk:system_ability_fwk", - "hiviewdfx_hilog_native:libhilog", - "samgr_standard:samgr_proxy", - ] - - cflags_cc = [ "-DHILOG_ENABLE" ] -} - -## UnitTest distributed_input_manager_service_test }}} diff --git a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp deleted file mode 100644 index 228008c..0000000 --- a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_input_sourceinject_test.h" - -#include -#include -#include -#include -#include - -#include - -#include "event_handler.h" -#include "nlohmann/json.hpp" - -#include "softbus_bus_center.h" - -using namespace testing::ext; -using namespace OHOS::DistributedHardware::DistributedInput; -using namespace std; -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -namespace { -static const uint32_t INPUT_DEVICE_CLASS_KEYBOARD = static_cast(DeviceClasses::INPUT_DEVICE_CLASS_KEYBOARD); -static const uint32_t INPUT_DEVICE_CLASS_CURSOR = static_cast(DeviceClasses::INPUT_DEVICE_CLASS_CURSOR); -static const uint32_t INPUT_DEVICE_CLASS_TOUCH = static_cast(DeviceClasses::INPUT_DEVICE_CLASS_TOUCH); -} -void DistributedInputSourceInjectTest::SetUp() -{ -} - -void DistributedInputSourceInjectTest::TearDown() -{ -} - -void DistributedInputSourceInjectTest::SetUpTestCase() -{ -} - -void DistributedInputSourceInjectTest::TearDownTestCase() -{ -} - -HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedHardware01, testing::ext::TestSize.Level1) -{ - std::cout<< "start"<when = 0; - event->type = EV_KEY; - event->code = KEY_D; - event->value = 1; - event->descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; - event += 1; - - event->when = 1; - event->type = EV_KEY; - event->code = KEY_D; - event->value = 0; - event->descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; - event += 1; - - event->when = 2; - event->type = EV_KEY; - event->code = KEY_D; - event->value = 1; - event->descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; - event += 1; - - event->when = 3; - event->type = EV_KEY; - event->code = KEY_D; - event->value = 0; - event->descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; - - size_t count = (size_t)(sizeof(writeBuffer) / sizeof(RawEvent)); - int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(writeBuffer, count); - std::cout<< "end"<when = 0; - event->type = EV_REL; - event->code = REL_X; - event->value = 2; - event->descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; - event += 1; - - event->when = 1; - event->type = EV_REL; - event->code = REL_Y; - event->value = 2; - event->descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; - event += 1; - - event->when = 2; - event->type = EV_REL; - event->code = REL_X; - event->value = 2; - event->descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; - event += 1; - - event->when = 3; - event->type = EV_REL; - event->code = REL_Y; - event->value = 2; - event->descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; - - event->when = 4; - event->type = EV_SYN; - event->code = SYN_REPORT; - event->value = 0; - event->descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; - - size_t count = (size_t)(sizeof(writeBuffer) / sizeof(RawEvent)); - int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(writeBuffer, count); - std::cout<< "end"<when = 0; - event->type = EV_ABS; - event->code = ABS_X; - event->value = 1; - event->descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - event += 1; - - event->when = 1; - event->type = EV_ABS; - event->code = ABS_X; - event->value = 2; - event->descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - event += 1; - - event->when = 2; - event->type = EV_ABS; - event->code = ABS_X; - event->value = 3; - event->descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - event += 1; - - event->when = 3; - event->type = EV_ABS; - event->code = ABS_X; - event->value = 4; - event->descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - - size_t count = (size_t)(sizeof(writeBuffer) / sizeof(RawEvent)); - int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(writeBuffer, count); - std::cout<< "end"< -#include -#include -#include - -#include - -#include "constants_dinput.h" -#include "distributed_input_inject.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputSourceInjectTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS -#endif // DISRIBUTED_INPUT_INNER_TEST_H diff --git a/services/source/sourcemanager/BUILD.gn b/services/source/sourcemanager/BUILD.gn deleted file mode 100644 index cef38b6..0000000 --- a/services/source/sourcemanager/BUILD.gn +++ /dev/null @@ -1,94 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//foundation/distributedhardware/distributedinput/distributedinput.gni") - -ohos_shared_library("libdinput_source") { - include_dirs = [ - "include", - "${frameworks_path}/include", - "${innerkits_path}/include", - "${innerkits_path}/src", - "${ipc_path}/include", - "${ipc_path}/src", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${common_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${service_common}/include", - "${services_source_path}/inputinject/include", - "${services_source_path}/transport/include", - "//third_party/json/include", - ] - - sources = [ - "src/distributed_input_source_manager.cpp", - "src/distributed_input_source_event_handler.cpp", - "${common_path}/include/white_list_util.cpp", - - "${ipc_path}/src/add_white_list_infos_call_back_proxy.cpp", - "${ipc_path}/src/add_white_list_infos_call_back_stub.cpp", - "${ipc_path}/src/del_white_list_infos_call_back_proxy.cpp", - "${ipc_path}/src/del_white_list_infos_call_back_stub.cpp", - "${ipc_path}/src/distributed_input_sink_proxy.cpp", - "${ipc_path}/src/distributed_input_sink_stub.cpp", - "${ipc_path}/src/distributed_input_source_proxy.cpp", - "${ipc_path}/src/distributed_input_source_stub.cpp", - "${ipc_path}/src/prepare_d_input_call_back_proxy.cpp", - "${ipc_path}/src/prepare_d_input_call_back_stub.cpp", - "${ipc_path}/src/register_d_input_call_back_proxy.cpp", - "${ipc_path}/src/register_d_input_call_back_stub.cpp", - "${ipc_path}/src/start_d_input_call_back_proxy.cpp", - "${ipc_path}/src/start_d_input_call_back_stub.cpp", - "${ipc_path}/src/start_d_input_server_call_back_proxy.cpp", - "${ipc_path}/src/start_d_input_server_call_back_stub.cpp", - "${ipc_path}/src/stop_d_input_call_back_proxy.cpp", - "${ipc_path}/src/stop_d_input_call_back_stub.cpp", - "${ipc_path}/src/unprepare_d_input_call_back_proxy.cpp", - "${ipc_path}/src/unprepare_d_input_call_back_stub.cpp", - "${ipc_path}/src/unregister_d_input_call_back_proxy.cpp", - "${ipc_path}/src/unregister_d_input_call_back_stub.cpp", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedinputmanagerkit\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "//foundation/distributedhardware/distributedinput/interfaces/inner_kits:libdinput_sdk", - "//foundation/bundlemanager/bundle_framework/interfaces/innerkits/libeventhandler:libeventhandler", - "//utils/native/base:utils", - "${fwk_utils_path}:distributedhardwareutils", - "//foundation/distributedhardware/distributedinput/services/source/transport:libdinput_source_trans", - "//foundation/distributedhardware/distributedinput/services/source/inputinject:libdinput_inject", - ] - - external_deps = [ - "ipc:ipc_core", - "safwk:system_ability_fwk", - "hiviewdfx_hilog_native:libhilog", - "samgr_standard:samgr_proxy", - ] - - cflags_cc = [ "-DHILOG_ENABLE" ] - - subsystem_name = "distributedhardware" - - part_name = "distributed_input" -} diff --git a/services/source/sourcemanager/include/distributed_input_source_event_handler.h b/services/source/sourcemanager/include/distributed_input_source_event_handler.h deleted file mode 100644 index 6d819b9..0000000 --- a/services/source/sourcemanager/include/distributed_input_source_event_handler.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISRIBUTED_INPUT_SOURCE_EVENT_HANDLER_H -#define DISRIBUTED_INPUT_SOURCE_EVENT_HANDLER_H - -#include - -#include "event_handler.h" -#include "event_runner.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputSourceEventHandler : public AppExecFwk::EventHandler { -public: - DistributedInputSourceEventHandler(const std::shared_ptr &runner); - virtual ~DistributedInputSourceEventHandler(); - - bool ProxyPostTask(const Callback &callback, int64_t delayTime); - - bool ProxyPostTask(const Callback &callback, const std::string &name = std::string(), int64_t delayTime = 0); - - void ProxyRemoveTask(const std::string &name); - -private: -}; -} // namespace DistributedHardware -} // namespace DistributedInput -} // namespace OHOS -#endif // DISRIBUTED_INPUT_SOURCE_EVENT_HANDLER_H diff --git a/services/source/sourcemanager/include/distributed_input_source_manager.h b/services/source/sourcemanager/include/distributed_input_source_manager.h deleted file mode 100644 index ead26af..0000000 --- a/services/source/sourcemanager/include/distributed_input_source_manager.h +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISRIBUTED_INPUT_SOURCE_MANAGER_SERVICE_H -#define DISRIBUTED_INPUT_SOURCE_MANAGER_SERVICE_H - -#include -#include -#include - -#include -#include - -#include "event_handler.h" -#include "singleton.h" -#include "system_ability.h" - -#include "constants_dinput.h" -#include "dinput_source_trans_callback.h" -#include "distributed_input_source_stub.h" -#include "distributed_input_source_event_handler.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -using EventRunner = OHOS::AppExecFwk::EventRunner; -using EventHandler = OHOS::AppExecFwk::EventHandler; -enum class ServiceSourceRunningState { STATE_NOT_START, STATE_RUNNING }; -const uint32_t DINPUT_SOURCE_MANAGER_RIGISTER_MSG = 1; -const uint32_t DINPUT_SOURCE_MANAGER_UNRIGISTER_MSG = 2; -const uint32_t DINPUT_SOURCE_MANAGER_PREPARE_MSG = 3; -const uint32_t DINPUT_SOURCE_MANAGER_UNPREPARE_MSG = 4; -const uint32_t DINPUT_SOURCE_MANAGER_START_MSG = 5; -const uint32_t DINPUT_SOURCE_MANAGER_STOP_MSG = 6; -const uint32_t DINPUT_SOURCE_MANAGER_RECEIVE_DATA_MSG = 7; -const uint32_t DINPUT_SOURCE_MANAGER_STARTSERVER_MSG = 8; -const std::string INPUT_SOURCEMANAGER_KEY_DEVID = "deviceId"; -const std::string INPUT_SOURCEMANAGER_KEY_HWID = "hardwareId"; -const std::string INPUT_SOURCEMANAGER_KEY_ITP = "inputTypes"; -const std::string INPUT_SOURCEMANAGER_KEY_RESULT = "result"; -const std::string INPUT_SOURCEMANAGER_KEY_WHITELIST = "whitelist"; -const uint32_t DINPUT_SOURCE_SWITCH_OFF = 0; -const uint32_t DINPUT_SOURCE_SWITCH_ON = 1; - -class DistributedInputSourceManager : public SystemAbility, public DistributedInputSourceStub { - DECLARE_SYSTEM_ABILITY(DistributedInputSourceManager) - -typedef struct InputDeviceId { - std::string devId; - std::string dhId; - - bool operator==(const InputDeviceId &inputId) - { - return (devId == inputId.devId) && (dhId == inputId.dhId); - } -} InputDeviceId; - -public: - DistributedInputSourceManager(int32_t saId, bool runOnCreate); - ~DistributedInputSourceManager() = default; - - void OnStart() override; - - void OnStop() override; - - virtual int32_t Init() override; - - virtual int32_t Release() override; - - virtual int32_t RegisterDistributedHardware(const std::string& devId, const std::string& dhId, - const std::string& parameters, sptr callback) override; - - virtual int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId, - sptr callback) override; - - virtual int32_t PrepareRemoteInput(const std::string& deviceId, - sptr callback, sptr addWhiteListCallback) override; - - virtual int32_t UnprepareRemoteInput(const std::string& deviceId, - sptr callback, sptr delWhiteListCallback) override; - - virtual int32_t StartRemoteInput( - const std::string& deviceId, const uint32_t& inputTypes, sptr callback) override; - - virtual int32_t StopRemoteInput( - const std::string& deviceId, const uint32_t& inputTypes, sptr callback) override; - - virtual int32_t IsStartDistributedInput( - const uint32_t& inputType, sptr callback) override; - - class DInputSourceListener : public DInputSourceTransCallback { - public: - DInputSourceListener(DistributedInputSourceManager *manager); - virtual ~DInputSourceListener(); - void onResponseRegisterDistributedHardware(const std::string deviceId, const std::string dhId, bool result); - void onResponsePrepareRemoteInput(const std::string deviceId, bool result, const std::string &object); - void onResponseUnprepareRemoteInput(const std::string deviceId, bool result); - void onResponseStartRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result); - void onResponseStopRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result); - void onReceivedEventRemoteInput(const std::string deviceId, const std::string &event); - - private: - DistributedInputSourceManager *sourceManagerObj_; - }; - - class DInputSourceManagerEventHandler : public AppExecFwk::EventHandler { - public: - DInputSourceManagerEventHandler(const std::shared_ptr &runner, - DistributedInputSourceManager *manager); - ~DInputSourceManagerEventHandler() {} - - void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; - private: - void NotifyRegisterCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyUnregisterCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyPrepareCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyUnprepareCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyStartCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyStopCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyStartServerCallback(const AppExecFwk::InnerEvent::Pointer &event); - - DistributedInputSourceManager *sourceManagerObj_; - }; - - std::shared_ptr GetCallbackEventHandler() - { - return callBackHandler_; - }; - -public: - void RunRegisterCallback( - const std::string& devId, const std::string& dhId, const int32_t& status - ); - void RunUnregisterCallback( - const std::string& devId, const std::string& dhId, const int32_t& status - ); - void RunPrepareCallback( - const std::string& devId, const int32_t& status, const std::string& object - ); - void RunUnprepareCallback( - const std::string& devId, const int32_t& status - ); - void RunStartCallback( - const std::string& devId, const uint32_t& inputTypes, const int32_t& status - ); - void RunStopCallback( - const std::string& devId, const uint32_t& inputTypes, const int32_t& status - ); - - IStartDInputServerCallback* GetStartDInputServerCback(); - DInputServerType GetStartTransFlag(); - void SetStartTransFlag(const DInputServerType flag); - std::vector GetInputDeviceId(); - void RemoveInputDeviceId(const std::string deviceId, const std::string dhId); - void SetDeviceMapValue(const std::string deviceId, int32_t value); - bool GetDeviceMapAllDevSwitchOff(); - int32_t RemoveInputNode(const std::string& devId, const std::string& dhId); - int32_t DeleteDevice(const std::string& devId, const std::string& dhId); - void SetInputTypesMap(const std::string deviceId, int32_t value); - int32_t GetInputTypesMap(const std::string deviceId); - int32_t GetAllInputTypesMap(); - -private: - - struct DInputClientRegistInfo { - std::string devId; - std::string dhId; - sptr callback = nullptr; - }; - - struct DInputClientUnregistInfo { - std::string devId; - std::string dhId; - sptr callback = nullptr; - }; - - struct DInputClientPrepareInfo { - std::string devId; - sptr preCallback = nullptr; - sptr addWhiteListCallback = nullptr; - }; - - struct DInputClientUnprepareInfo { - std::string devId; - sptr unpreCallback = nullptr; - sptr delWhiteListCallback = nullptr; - }; - - struct DInputClientStartInfo { - std::string devId; - uint32_t inputTypes; - sptr callback = nullptr; - }; - - struct DInputClientStopInfo { - std::string devId; - uint32_t inputTypes; - sptr callback = nullptr; - }; - ServiceSourceRunningState serviceRunningState_ = ServiceSourceRunningState::STATE_NOT_START; - DInputServerType isStartTrans_ = DInputServerType::NULL_SERVER_TYPE; - std::shared_ptr statuslistener_; - - std::vector regCallbacks_; - std::vector unregCallbacks_; - std::vector preCallbacks_; - std::vector unpreCallbacks_; - std::vector staCallbacks_; - std::vector stpCallbacks_; - sptr startServerCallback_ = nullptr; - - std::map DeviceMap_; - std::map InputTypesMap_; - std::shared_ptr runner_; - std::shared_ptr handler_; - std::shared_ptr callBackHandler_; - std::vector inputDevice_; - bool InitAuto(); - void handleStartServerCallback(const std::string& devId); -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - -#endif // DISRIBUTED_INPUT_SOURCE_MANAGER_SERVICE_H diff --git a/services/source/sourcemanager/src/distributed_input_source_event_handler.cpp b/services/source/sourcemanager/src/distributed_input_source_event_handler.cpp deleted file mode 100644 index 6007116..0000000 --- a/services/source/sourcemanager/src/distributed_input_source_event_handler.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_input_source_event_handler.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -DistributedInputSourceEventHandler::DistributedInputSourceEventHandler( - const std::shared_ptr &runner) - : AppExecFwk::EventHandler(runner) -{ -} -DistributedInputSourceEventHandler::~DistributedInputSourceEventHandler() = default; - -bool DistributedInputSourceEventHandler::ProxyPostTask(const Callback &callback, int64_t delayTime) -{ - return AppExecFwk::EventHandler::PostTask(callback, delayTime); -} - -bool DistributedInputSourceEventHandler::ProxyPostTask( - const Callback &callback, const std::string &name, int64_t delayTime) -{ - return AppExecFwk::EventHandler::PostTask(callback, name, delayTime); -} - -void DistributedInputSourceEventHandler::ProxyRemoveTask(const std::string &name) -{ - AppExecFwk::EventHandler::RemoveTask(name); -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp deleted file mode 100644 index 5edb3b2..0000000 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ /dev/null @@ -1,1075 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_input_source_manager.h" - -#include - -#include "anonymous_string.h" -#include "distributed_hardware_log.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" -#include "nlohmann/json.hpp" -#include "system_ability_definition.h" - -#include "constants_dinput.h" -#include "dinput_errcode.h" -#include "distributed_input_inject.h" -#include "distributed_input_source_transport.h" -#include "white_list_util.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -REGISTER_SYSTEM_ABILITY_BY_ID(DistributedInputSourceManager, DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, true); - -DistributedInputSourceManager::DistributedInputSourceManager(int32_t saId, bool runOnCreate) - : SystemAbility(saId, runOnCreate) -{ -} - -DistributedInputSourceManager::DInputSourceListener::DInputSourceListener(DistributedInputSourceManager *manager) -{ - sourceManagerObj_ = manager; - DHLOGI("DInputSourceListener init."); -} - -DistributedInputSourceManager::DInputSourceListener::~DInputSourceListener() -{ - sourceManagerObj_ = nullptr; - DHLOGI("DInputSourceListener destory."); -} - -void DistributedInputSourceManager::DInputSourceListener::onResponseRegisterDistributedHardware( - const std::string deviceId, const std::string dhId, bool result) -{ - DHLOGI("onResponseRegisterDistributedHardware called, deviceId: %s, " - "result: %s.", GetAnonyString(deviceId).c_str(), result); - if (sourceManagerObj_ == nullptr) { - DHLOGE("onResponseRegisterDistributedHardware sourceManagerObj_ is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - sourceManagerObj_->RunRegisterCallback(deviceId, dhId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); - DHLOGE("onResponseRegisterDistributedHardware GetCallbackEventHandler is null."); - return; - } - - std::shared_ptr jsonArrayMsg = std::make_shared(); - - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; - tmpJson[INPUT_SOURCEMANAGER_KEY_HWID] = dhId; - tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( - DINPUT_SOURCE_MANAGER_RIGISTER_MSG, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::onResponsePrepareRemoteInput(const std::string deviceId, - bool result, const std::string &object) -{ - DHLOGI("onResponsePrepareRemoteInput called, deviceId: %s, result: %d.", - GetAnonyString(deviceId).c_str(), result); - - if (sourceManagerObj_ == nullptr) { - DHLOGE("onResponsePrepareRemoteInput sourceManagerObj_ is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - sourceManagerObj_->RunPrepareCallback(deviceId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL, object); - DHLOGE("onResponsePrepareRemoteInput GetCallbackEventHandler is null."); - return; - } - std::shared_ptr jsonArrayMsg = std::make_shared(); - - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; - tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; - tmpJson[INPUT_SOURCEMANAGER_KEY_WHITELIST] = object; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( - DINPUT_SOURCE_MANAGER_PREPARE_MSG, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::onResponseUnprepareRemoteInput( - const std::string deviceId, bool result) -{ - DHLOGI("onResponseUnprepareRemoteInput called, deviceId: %s, " - "result: %d.", GetAnonyString(deviceId).c_str(), result); - - if (sourceManagerObj_ == nullptr) { - DHLOGE("onResponseUnprepareRemoteInput sourceManagerObj_ is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - sourceManagerObj_->RunUnprepareCallback(deviceId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); - DHLOGE("onResponseUnprepareRemoteInput GetCallbackEventHandler is null."); - return; - } - std::shared_ptr jsonArrayMsg = std::make_shared(); - - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; - tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( - DINPUT_SOURCE_MANAGER_UNPREPARE_MSG, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::onResponseStartRemoteInput( - const std::string deviceId, const uint32_t inputTypes, bool result) -{ - DHLOGI("onResponseStartRemoteInput called, deviceId: %s, inputTypes: %d, result: %d.", - GetAnonyString(deviceId).c_str(), inputTypes, result); - - if (sourceManagerObj_ == nullptr) { - DHLOGE("onResponseStartRemoteInput sourceManagerObj_ is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - sourceManagerObj_->RunStartCallback(deviceId, inputTypes, - ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); - DHLOGE("onResponseStartRemoteInput GetCallbackEventHandler is null."); - return; - } - if (result) { - sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_ON); - } - - std::shared_ptr jsonArrayMsg = std::make_shared(); - if (jsonArrayMsg == nullptr) { - DHLOGE("onResponseStartRemoteInput jsonArrayMsg is null."); - return; - } - - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; - tmpJson[INPUT_SOURCEMANAGER_KEY_ITP] = inputTypes; - tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( - DINPUT_SOURCE_MANAGER_START_MSG, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::onResponseStopRemoteInput( - const std::string deviceId, const uint32_t inputTypes, bool result) -{ - DHLOGI("onResponseStopRemoteInput called, deviceId: %s, inputTypes: %d, result: %d.", - GetAnonyString(deviceId).c_str(), inputTypes, result); - - if (sourceManagerObj_ == nullptr) { - DHLOGE("onResponseStopRemoteInput sourceManagerObj_ is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - DHLOGE("onResponseStopRemoteInput GetCallbackEventHandler is null."); - sourceManagerObj_->RunStopCallback(deviceId, inputTypes, - ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); - return; - } - std::shared_ptr jsonArrayMsg = std::make_shared(); - - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; - tmpJson[INPUT_SOURCEMANAGER_KEY_ITP] = inputTypes; - tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( - DINPUT_SOURCE_MANAGER_STOP_MSG, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::onReceivedEventRemoteInput( - const std::string deviceId, const std::string &event) -{ - nlohmann::json inputData = nlohmann::json::parse(event); - int jsonSize = inputData.size(); - DHLOGI("onReceivedEventRemoteInput called, deviceId: %s, json size:%d.", - GetAnonyString(deviceId).c_str(), jsonSize); - - RawEvent mEventBuffer[jsonSize]; - int idx = 0; - for (nlohmann::json::iterator it = inputData.begin(); it != inputData.end(); ++it) { - nlohmann::json oneData = (*it); - mEventBuffer[idx].when = oneData[INPUT_KEY_WHEN]; - mEventBuffer[idx].type = oneData[INPUT_KEY_TYPE]; - mEventBuffer[idx].code = oneData[INPUT_KEY_CODE]; - mEventBuffer[idx].value = oneData[INPUT_KEY_VALUE]; - mEventBuffer[idx].descriptor = oneData[INPUT_KEY_DESCRIPTOR]; - std::string path = oneData[INPUT_KEY_PATH]; - mEventBuffer[idx].path = path; - if (oneData[INPUT_KEY_TYPE] == EV_KEY) { - DHLOGD("3.E2E-Test Source softBus receive EV_KEY, Code: %d, Value: %d, Path: %s, When: " PRId64"", - mEventBuffer[idx].code, mEventBuffer[idx].value, path.c_str(), mEventBuffer[idx].when); - } else if (oneData[INPUT_KEY_TYPE] == EV_REL) { - DHLOGD("3.E2E-Test Source softBus receive EV_REL, Code: %d, Value: %d, Path: %s, When: " PRId64"", - mEventBuffer[idx].code, mEventBuffer[idx].value, path.c_str(), mEventBuffer[idx].when); - } else if (oneData[INPUT_KEY_TYPE] == EV_ABS) { - DHLOGD("3.E2E-Test Source softBus receive EV_ABS, Code: %d, Value: %d, Path: %s, When: " PRId64"", - mEventBuffer[idx].code, mEventBuffer[idx].value, path.c_str(), mEventBuffer[idx].when); - } else { - DHLOGW("3.E2E-Test Source softBus receive other type!"); - } - idx++; - } - DistributedInputInject::GetInstance().RegisterDistributedEvent(mEventBuffer, jsonSize); -} - -void DistributedInputSourceManager::OnStart() -{ - if (serviceRunningState_ == ServiceSourceRunningState::STATE_RUNNING) { - DHLOGI("dinput Manager Service has already started."); - return; - } - DHLOGI("dinput Manager Service started."); - if (!InitAuto()) { - DHLOGI("failed to init service."); - return; - } - serviceRunningState_ = ServiceSourceRunningState::STATE_RUNNING; - runner_->Run(); - /* Publish service maybe failed, so we need call this function at the last, - * so it can't affect the TDD test program */ - bool ret = Publish(this); - if (!ret) { - return; - } - - DHLOGI("DistributedInputSourceManager start success."); -} - -bool DistributedInputSourceManager::InitAuto() -{ - runner_ = AppExecFwk::EventRunner::Create(true); - if (runner_ == nullptr) { - return false; - } - - handler_ = std::make_shared(runner_); - - DHLOGI("init success"); - - std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); - callBackHandler_ = std::make_shared(runner, this); - - return true; -} - -DistributedInputSourceManager::DInputSourceManagerEventHandler::DInputSourceManagerEventHandler( - const std::shared_ptr &runner, DistributedInputSourceManager *manager) - : AppExecFwk::EventHandler(runner) -{ - sourceManagerObj_ = manager; -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRegisterCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; - std::string dhId = innerMsg[INPUT_SOURCEMANAGER_KEY_HWID]; - bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - - InputDeviceId inputDeviceId {deviceId, dhId}; - std::vector tmpInputDevId = sourceManagerObj_->GetInputDeviceId(); - // Find out if the dh exists - std::vector::iterator devIt = std::find( - tmpInputDevId.begin(), tmpInputDevId.end(), inputDeviceId); - if (devIt != tmpInputDevId.end()) { - if (result == false) { - sourceManagerObj_->RemoveInputDeviceId(deviceId, dhId); - } - } else { - DHLOGW("ProcessEvent DINPUT_SOURCE_MANAGER_RIGISTER_MSG the " - "devId[%s] dhId[%s] is bad data.", GetAnonyString(deviceId).c_str(), GetAnonyString(dhId).c_str()); - } - - sourceManagerObj_->RunRegisterCallback(deviceId, dhId, - result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_MSG_IS_BAD); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyUnregisterCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; - std::string dhId = innerMsg[INPUT_SOURCEMANAGER_KEY_HWID]; - bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - if (result) { - sourceManagerObj_->SetDeviceMapValue(deviceId, INPUT_TYPE_NULL); - } - sourceManagerObj_->RunUnregisterCallback(deviceId, dhId, - result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_MSG_IS_BAD); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyPrepareCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; - bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - std::string object = innerMsg[INPUT_SOURCEMANAGER_KEY_WHITELIST]; - - sourceManagerObj_->RunPrepareCallback(deviceId, - result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_MSG_IS_BAD, object); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyUnprepareCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; - bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - if (result) { - sourceManagerObj_->SetDeviceMapValue(deviceId, INPUT_TYPE_NULL); - } - sourceManagerObj_->RunUnprepareCallback(deviceId, - result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_MSG_IS_BAD); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStartCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; - uint32_t inputTypes = innerMsg[INPUT_SOURCEMANAGER_KEY_ITP]; - bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - if (result) { - sourceManagerObj_->SetInputTypesMap( - deviceId, sourceManagerObj_->GetInputTypesMap(deviceId) | inputTypes); - } - sourceManagerObj_->SetStartTransFlag((result && (sourceManagerObj_->GetInputTypesMap(deviceId) > 0)) ? - DInputServerType::SOURCE_SERVER_TYPE : DInputServerType::NULL_SERVER_TYPE); - if (sourceManagerObj_->GetStartDInputServerCback() != nullptr) { - sourceManagerObj_->GetStartDInputServerCback()->OnResult( - static_cast(sourceManagerObj_->GetStartTransFlag()), - sourceManagerObj_->GetAllInputTypesMap()); - } else { - DHLOGE("ProcessEvent GetStartDInputServerCback() or is null."); - } - sourceManagerObj_->RunStartCallback(deviceId, inputTypes, - result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStopCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; - uint32_t inputTypes = innerMsg[INPUT_SOURCEMANAGER_KEY_ITP]; - bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - - if (result && (sourceManagerObj_->GetInputTypesMap(deviceId) & inputTypes)) { - sourceManagerObj_->SetInputTypesMap( - deviceId, sourceManagerObj_->GetInputTypesMap(deviceId) - - (sourceManagerObj_->GetInputTypesMap(deviceId) & inputTypes)); - } - - if (sourceManagerObj_->GetInputTypesMap(deviceId) == 0) { - sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_OFF); - } - - // DeviceMap_ all sink device switch is off,call isstart's callback - bool isAllDevSwitchOff = sourceManagerObj_->GetDeviceMapAllDevSwitchOff(); - if (isAllDevSwitchOff) { - sourceManagerObj_->SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE); - } - if (sourceManagerObj_->GetStartDInputServerCback() != nullptr) { - sourceManagerObj_->GetStartDInputServerCback()->OnResult( - static_cast(sourceManagerObj_->GetStartTransFlag()), - sourceManagerObj_->GetAllInputTypesMap()); - } else { - DHLOGE("ProcessEvent GetStartDInputServerCback() is null."); - } - sourceManagerObj_->RunStopCallback(deviceId, inputTypes, - result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStartServerCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - int32_t serType = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - DInputServerType startTransFlag = DInputServerType(serType); - sourceManagerObj_->SetStartTransFlag(startTransFlag); - - if (sourceManagerObj_->GetStartDInputServerCback() != nullptr) { - sourceManagerObj_->GetStartDInputServerCback()->OnResult(serType, INPUT_TYPE_NULL); - } else { - DHLOGE("ProcessEvent GetStartDInputServerCback() is null."); - } -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::ProcessEvent( - const AppExecFwk::InnerEvent::Pointer &event) -{ - switch (event->GetInnerEventId()) { - case DINPUT_SOURCE_MANAGER_RIGISTER_MSG: { - NotifyRegisterCallback(event); - break; - } - case DINPUT_SOURCE_MANAGER_UNRIGISTER_MSG: { - NotifyUnregisterCallback(event); - break; - } - case DINPUT_SOURCE_MANAGER_PREPARE_MSG: { - NotifyPrepareCallback(event); - break; - } - case DINPUT_SOURCE_MANAGER_UNPREPARE_MSG: { - NotifyUnprepareCallback(event); - break; - } - case DINPUT_SOURCE_MANAGER_START_MSG: { - NotifyStartCallback(event); - break; - } - case DINPUT_SOURCE_MANAGER_STOP_MSG: { - NotifyStopCallback(event); - break; - } - case DINPUT_SOURCE_MANAGER_STARTSERVER_MSG: { - NotifyStartServerCallback(event); - break; - } - default:break; - } -} - -void DistributedInputSourceManager::OnStop() -{ - DHLOGI("stop service"); - runner_.reset(); - handler_.reset(); - serviceRunningState_ = ServiceSourceRunningState::STATE_NOT_START; -} - -int32_t DistributedInputSourceManager::Init() -{ - DHLOGI("enter"); - isStartTrans_ = DInputServerType::NULL_SERVER_TYPE; - - // transport init session - int32_t ret = DistributedInputSourceTransport::GetInstance().Init(); - if (ret != DH_SUCCESS) { - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_INIT_FAIL; - } - - statuslistener_ = std::make_shared(this); - DistributedInputSourceTransport::GetInstance().RegisterSourceRespCallback(statuslistener_); - - serviceRunningState_ = ServiceSourceRunningState::STATE_RUNNING; - return DH_SUCCESS; -} - -int32_t DistributedInputSourceManager::Release() -{ - DHLOGI("exit"); - - // 1.remove input node - for (std::vector::iterator iter = inputDevice_.begin(); iter != inputDevice_.end(); ++iter) { - std::string devId = iter->devId; - std::string dhId = iter->dhId; - DHLOGI("Release() devId[%s] dhId[%s]", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); - int32_t ret = DistributedInputInject::GetInstance().UnregisterDistributedHardware(devId, dhId); - if (ret != DH_SUCCESS) { - DHLOGW("%s called, remove node fail.", __func__); - } - } - - // 2.delete all device node data - DHLOGI("Release transport instance"); - DistributedInputSourceTransport::GetInstance().Release(); - - // 3.delete all device node data - inputDevice_.clear(); - DeviceMap_.clear(); - InputTypesMap_.clear(); - - // 4. isStart callback - std::shared_ptr jsonArrayMsg = std::make_shared(); - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = static_cast(DInputServerType::NULL_SERVER_TYPE); - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( - DINPUT_SOURCE_MANAGER_STARTSERVER_MSG, jsonArrayMsg, 0); - - if (callBackHandler_ == nullptr) { - DHLOGE("Release callBackHandler_ is null."); - return ERR_DH_INPUT_SERVER_SOURCE_MANSGER_RELEASE_FAIL; - } - callBackHandler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); - - serviceRunningState_ = ServiceSourceRunningState::STATE_NOT_START; - DHLOGI("exit dinput source sa."); - exit(0); - return DH_SUCCESS; -} - -int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::string& devId, const std::string& dhId, - const std::string& parameters, sptr callback) -{ - DHLOGI("%s called, deviceId: %s, dhId: %s, parameters: %s", - __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), parameters.c_str()); - - if (callback == nullptr) { - DHLOGE( - "%s called, deviceId: %s callback is null.", - __func__, GetAnonyString(devId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL; - } - - DInputClientRegistInfo info; - info.devId = devId; - info.dhId = dhId; - info.callback = callback; - regCallbacks_.push_back(info); - - InputDeviceId inputDeviceId {devId, dhId}; - - // 1.Find out if the dh exists - std::vector::iterator it = std::find(inputDevice_.begin(), inputDevice_.end(), inputDeviceId); - if (it != inputDevice_.end()) { - callback->OnResult(devId, dhId, DH_SUCCESS); - return DH_SUCCESS; - } - - // 2.create input node - int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedHardware(devId, dhId, parameters); - if (ret != DH_SUCCESS) { - DHLOGE("%s called, create node fail.", __func__); - - for (auto iter = regCallbacks_.begin(); iter != regCallbacks_.end(); iter++) { - if (iter->devId == devId && iter->dhId == dhId) { - iter->callback->OnResult(iter->devId, iter->dhId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL); - regCallbacks_.erase(iter); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL; - } - } - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL; - } - - // 3.save device - inputDevice_.push_back(inputDeviceId); - - // 4.notify source distributedfwk register hardware success - callback->OnResult(devId, dhId, DH_SUCCESS); - return DH_SUCCESS; -} - -void DistributedInputSourceManager::handleStartServerCallback(const std::string& devId) -{ - bool isFindDevice = false; - for (std::vector::iterator iter = inputDevice_.begin(); iter != inputDevice_.end(); ++iter) { - if (devId == iter->devId) { - isFindDevice = true; - break; - } - } - if (!isFindDevice) { - DeviceMap_[devId] = DINPUT_SOURCE_SWITCH_OFF; - // DeviceMap_ all sink device switch is off,call isstart's callback - bool isAllDevSwitchOff = true; - for (auto it = DeviceMap_.begin(); it != DeviceMap_.end(); it++) { - if (it->second == DINPUT_SOURCE_SWITCH_ON) { - isAllDevSwitchOff = false; - break; - } - } - if (isAllDevSwitchOff) { - std::shared_ptr jsonArrayMsg = std::make_shared(); - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = static_cast(DInputServerType::NULL_SERVER_TYPE); - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( - DINPUT_SOURCE_MANAGER_STARTSERVER_MSG, jsonArrayMsg, 0); - - if (callBackHandler_ == nullptr) { - DHLOGE("handleStartServerCallback callBackHandler_ is null."); - return; - } - callBackHandler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); - } - } -} - -int32_t DistributedInputSourceManager::RemoveInputNode(const std::string& devId, const std::string& dhId) -{ - int32_t ret = DistributedInputInject::GetInstance().UnregisterDistributedHardware(devId, dhId); - if (ret != DH_SUCCESS) { - DHLOGE("%s called, remove node fail.", __func__); - for (std::vector::iterator iter = - unregCallbacks_.begin(); iter != unregCallbacks_.end(); iter++) { - if (iter->devId == devId && iter->dhId == dhId) { - iter->callback->OnResult(iter->devId, iter->dhId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REMOVE_INPUT_NODE_FAIL); - unregCallbacks_.erase(iter); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REMOVE_INPUT_NODE_FAIL; - } - } - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REMOVE_INPUT_NODE_FAIL; - } - return DH_SUCCESS; -} - -int32_t DistributedInputSourceManager::DeleteDevice(const std::string& devId, const std::string& dhId) -{ - std::shared_ptr jsonArrayMsg = std::make_shared(); - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = devId; - tmpJson[INPUT_SOURCEMANAGER_KEY_HWID] = dhId; - tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = true; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( - DINPUT_SOURCE_MANAGER_UNRIGISTER_MSG, jsonArrayMsg, 0); - - if (callBackHandler_ == nullptr) { - DHLOGE("UnregisterDistributedHardware callBackHandler_ is null."); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_DELETE_DEVICE_FAIL; - } - callBackHandler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); - return DH_SUCCESS; -} - -int32_t DistributedInputSourceManager::UnregisterDistributedHardware(const std::string& devId, const std::string& dhId, - sptr callback) -{ - DHLOGI("%s called, deviceId: %s, dhId: %s", __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); - - if (callback == nullptr) { - DHLOGE("%s called, deviceId: %s callback is null.", __func__, GetAnonyString(devId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL; - } - - DInputClientUnregistInfo info; - info.devId = devId; - info.dhId = dhId; - info.callback = callback; - unregCallbacks_.push_back(info); - - InputDeviceId inputDeviceId {devId, dhId}; - - std::vector::iterator it = std::find(inputDevice_.begin(), inputDevice_.end(), inputDeviceId); - if (it == inputDevice_.end()) { - DHLOGE("%s called, deviceId: %s is not exist.", __func__, GetAnonyString(devId).c_str()); - for (std::vector::iterator iter = - unregCallbacks_.begin(); iter != unregCallbacks_.end(); iter++) { - if (iter->devId == devId && iter->dhId == dhId) { - iter->callback->OnResult(iter->devId, iter->dhId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL); - unregCallbacks_.erase(iter); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL; - } - } - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL; - } - - // 1.remove input node - if (RemoveInputNode(devId, dhId) != DH_SUCCESS) { - callback->OnResult(devId, dhId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL; - } - - // 2.delete device - inputDevice_.erase(it); - if (DeleteDevice(devId, dhId) != DH_SUCCESS) { - callback->OnResult(devId, dhId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL; - } - - // 3.isstart callback - handleStartServerCallback(devId); - return DH_SUCCESS; -} - -int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string& deviceId, - sptr callback, sptr addWhiteListCallback) -{ - DHLOGI("%s called, deviceId: %s", __func__, GetAnonyString(deviceId).c_str()); - if (callback == nullptr) { - DHLOGE("%s called, deviceId: %s callback is null.", __func__, GetAnonyString(deviceId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; - } - - for (auto iter : preCallbacks_) { - if (iter.devId == deviceId) { - callback->OnResult(deviceId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; - } - } - int32_t ret = DistributedInputSourceTransport::GetInstance().OpenInputSoftbus(deviceId); - if (ret != DH_SUCCESS) { - DHLOGE("Open softbus session fail."); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; - } - DInputClientPrepareInfo info; - info.devId = deviceId; - info.preCallback = callback; - info.addWhiteListCallback = addWhiteListCallback; - preCallbacks_.push_back(info); - - ret = DistributedInputSourceTransport::GetInstance().PrepareRemoteInput(deviceId); - if (ret != DH_SUCCESS) { - DHLOGE("Can not send message by softbus, prepare fail."); - for (auto iter = preCallbacks_.begin(); iter != preCallbacks_.end(); iter++) { - if (iter->devId == deviceId) { - iter->preCallback->OnResult(iter->devId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL); - preCallbacks_.erase(iter); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; - } - } - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; - } - - return DH_SUCCESS; -} - -int32_t DistributedInputSourceManager::UnprepareRemoteInput(const std::string& deviceId, - sptr callback, sptr delWhiteListCallback) -{ - DHLOGI("%s called, deviceId: %s", __func__, deviceId.c_str()); - - if (callback == nullptr) { - DHLOGE("%s called, deviceId: %s callback is null.", __func__, GetAnonyString(deviceId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; - } - - for (auto iter : unpreCallbacks_) { - if (iter.devId == deviceId) { - callback->OnResult(deviceId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; - } - } - - DInputClientUnprepareInfo info; - info.devId = deviceId; - info.unpreCallback = callback; - info.delWhiteListCallback = delWhiteListCallback; - unpreCallbacks_.push_back(info); - - int32_t ret = DistributedInputSourceTransport::GetInstance().UnprepareRemoteInput(deviceId); - if (ret != DH_SUCCESS) { - DHLOGE("Can not send message by softbus, unprepare fail."); - for (auto iter = unpreCallbacks_.begin(); iter != unpreCallbacks_.end(); iter++) { - if (iter->devId == deviceId) { - iter->unpreCallback->OnResult(iter->devId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL); - unpreCallbacks_.erase(iter); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; - } - } - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; - } - - return DH_SUCCESS; -} - -int32_t DistributedInputSourceManager::StartRemoteInput( - const std::string& deviceId, const uint32_t& inputTypes, sptr callback) -{ - DHLOGI("%s called, deviceId: %s, inputTypes: %d", __func__, GetAnonyString(deviceId).c_str(), inputTypes); - - if (callback == nullptr) { - DHLOGE("%s called, deviceId: %s callback is null.", __func__, GetAnonyString(deviceId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; - } - - for (auto iter : staCallbacks_) { - if (iter.devId == deviceId && iter.inputTypes == inputTypes) { - callback->OnResult(deviceId, inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; - } - } - - DInputClientStartInfo info; - info.devId = deviceId; - info.inputTypes = inputTypes; - info.callback = callback; - staCallbacks_.push_back(info); - - DeviceMap_[deviceId] = DINPUT_SOURCE_SWITCH_OFF; // when sink device start success,set DINPUT_SOURCE_SWITCH_ON - int32_t ret = DistributedInputSourceTransport::GetInstance().StartRemoteInput(deviceId, inputTypes); - if (ret != DH_SUCCESS) { - DHLOGE("%s called, start fail.", __func__); - for (std::vector::iterator iter = - staCallbacks_.begin(); iter != staCallbacks_.end(); iter++) { - if (iter->devId == deviceId && iter->inputTypes == inputTypes) { - iter->callback->OnResult(iter->devId, iter->inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL); - staCallbacks_.erase(iter); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; - } - } - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; - } - - return DH_SUCCESS; -} - -int32_t DistributedInputSourceManager::StopRemoteInput( - const std::string& deviceId, const uint32_t& inputTypes, sptr callback) -{ - DHLOGI("%s called, deviceId: %s, inputTypes: %d", __func__, GetAnonyString(deviceId).c_str(), inputTypes); - - if (callback == nullptr) { - DHLOGE("%s called, deviceId: %s callback is null.", __func__, GetAnonyString(deviceId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; - } - - for (auto iter : stpCallbacks_) { - if (iter.devId == deviceId && iter.inputTypes == inputTypes) { - callback->OnResult(deviceId, inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; - } - } - - DInputClientStopInfo info; - info.devId = deviceId; - info.inputTypes = inputTypes; - info.callback = callback; - stpCallbacks_.push_back(info); - - int32_t ret = DistributedInputSourceTransport::GetInstance().StopRemoteInput(deviceId, inputTypes); - if (ret != DH_SUCCESS) { - DHLOGE("%s called, stop fail.", __func__); - for (std::vector::iterator iter = - stpCallbacks_.begin(); iter != stpCallbacks_.end(); iter++) { - if (iter->devId == deviceId && iter->inputTypes == inputTypes) { - iter->callback->OnResult(iter->devId, iter->inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL); - stpCallbacks_.erase(iter); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; - } - } - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; - } - - return DH_SUCCESS; -} - -int32_t DistributedInputSourceManager::IsStartDistributedInput( - const uint32_t& inputType, sptr callback) -{ - if (callback != nullptr) { - startServerCallback_ = callback; - } - - if (inputType & GetAllInputTypesMap()) { - return static_cast(isStartTrans_); - } else { - return static_cast(DInputServerType::NULL_SERVER_TYPE); - } -} - -void DistributedInputSourceManager::RunRegisterCallback( - const std::string& devId, const std::string& dhId, const int32_t& status) -{ - for (std::vector::iterator iter = - regCallbacks_.begin(); iter != regCallbacks_.end(); iter++) { - if (iter->devId == devId && iter->dhId == dhId) { - DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_RIGISTER_MSG"); - iter->callback->OnResult(devId, dhId, status); - regCallbacks_.erase(iter); - return; - } - } - - DHLOGE("ProcessEvent registerCallback is null."); -} - -void DistributedInputSourceManager::RunUnregisterCallback( - const std::string& devId, const std::string& dhId, const int32_t& status) -{ - for (std::vector::iterator iter = - unregCallbacks_.begin(); iter != unregCallbacks_.end(); iter++) { - if (iter->devId == devId && iter->dhId == dhId) { - DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_UNRIGISTER_MSG"); - iter->callback->OnResult(devId, dhId, status); - unregCallbacks_.erase(iter); - return; - } - } - - DHLOGE("ProcessEvent unregisterCallback is null."); -} - -void DistributedInputSourceManager::RunPrepareCallback( - const std::string& devId, const int32_t& status, const std::string& object) -{ - for (std::vector::iterator iter = - preCallbacks_.begin(); iter != preCallbacks_.end(); iter++) { - if (iter->devId == devId) { - DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_PREPARE_MSG"); - iter->preCallback->OnResult(devId, status); - iter->addWhiteListCallback->OnResult(devId, object); - preCallbacks_.erase(iter); - return; - } - } - - DHLOGE("ProcessEvent parepareCallback is null."); -} - -void DistributedInputSourceManager::RunUnprepareCallback( - const std::string& devId, const int32_t& status) -{ - for (std::vector::iterator iter = - unpreCallbacks_.begin(); iter != unpreCallbacks_.end(); iter++) { - if (iter->devId == devId) { - DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_UNPREPARE_MSG"); - iter->unpreCallback->OnResult(devId, status); - iter->delWhiteListCallback->OnResult(devId); - unpreCallbacks_.erase(iter); - return; - } - } - - DHLOGE("ProcessEvent unparepareCallback is null."); -} - -void DistributedInputSourceManager::RunStartCallback( - const std::string& devId, const uint32_t& inputTypes, const int32_t& status) -{ - for (std::vector::iterator iter = - staCallbacks_.begin(); iter != staCallbacks_.end(); iter++) { - if (iter->devId == devId && iter->inputTypes == inputTypes) { - DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_START_MSG"); - iter->callback->OnResult(devId, inputTypes, status); - staCallbacks_.erase(iter); - return; - } - } - - DHLOGE("ProcessEvent startCallback is null."); -} - -void DistributedInputSourceManager::RunStopCallback( - const std::string& devId, const uint32_t& inputTypes, const int32_t& status) -{ - for (std::vector::iterator iter = - stpCallbacks_.begin(); iter != stpCallbacks_.end(); iter++) { - if (iter->devId == devId && iter->inputTypes == inputTypes) { - DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_STOP_MSG"); - iter->callback->OnResult(devId, inputTypes, status); - stpCallbacks_.erase(iter); - return; - } - } - - DHLOGE("ProcessEvent stopCallback is null."); -} - -IStartDInputServerCallback* DistributedInputSourceManager::GetStartDInputServerCback() -{ - return startServerCallback_; -} - -DInputServerType DistributedInputSourceManager::GetStartTransFlag() -{ - return isStartTrans_; -} - -void DistributedInputSourceManager::SetStartTransFlag(const DInputServerType flag) -{ - isStartTrans_ = flag; -} - -std::vector DistributedInputSourceManager::GetInputDeviceId() -{ - return inputDevice_; -} - -void DistributedInputSourceManager::RemoveInputDeviceId(const std::string deviceId, const std::string dhId) -{ - InputDeviceId inputDeviceId {deviceId, dhId}; - - std::vector::iterator it = std::find(inputDevice_.begin(), inputDevice_.end(), inputDeviceId); - if (it == inputDevice_.end()) { - return; - } - - // delete device - inputDevice_.erase(it); -} - -bool DistributedInputSourceManager::GetDeviceMapAllDevSwitchOff() -{ - bool isAllDevSwitchOff = true; - for (auto it = DeviceMap_.begin(); it != DeviceMap_.end(); it++) { - if (it->second == DINPUT_SOURCE_SWITCH_ON) { - isAllDevSwitchOff = false; - break; - } - } - return isAllDevSwitchOff; -} - -void DistributedInputSourceManager::SetDeviceMapValue(const std::string deviceId, int32_t value) -{ - DeviceMap_[deviceId] = value; -} - - -int32_t DistributedInputSourceManager::GetInputTypesMap(const std::string deviceId) -{ - std::map::iterator key = InputTypesMap_.find(deviceId); - if (key != InputTypesMap_.end()) { - return InputTypesMap_[deviceId]; - } - return INPUT_TYPE_NULL; -} - -int32_t DistributedInputSourceManager::GetAllInputTypesMap() -{ - int32_t rInputTypes = INPUT_TYPE_NULL; - std::map::iterator iter; - for (iter = InputTypesMap_.begin(); iter != InputTypesMap_.end(); iter++) { - rInputTypes |= iter->second; - } - return rInputTypes; -} - -void DistributedInputSourceManager::SetInputTypesMap(const std::string deviceId, int32_t value) -{ - if (value == INPUT_TYPE_NULL) { - std::map::iterator key = InputTypesMap_.find(deviceId); - if (key != InputTypesMap_.end()) { - InputTypesMap_.erase(key); - return; - } - } - InputTypesMap_[deviceId] = value; -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/source/sourcemanager/test/BUILD.gn b/services/source/sourcemanager/test/BUILD.gn deleted file mode 100644 index fd432a0..0000000 --- a/services/source/sourcemanager/test/BUILD.gn +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -group("test") { - testonly = true - - deps = [ "sourcemanagerunittest:sourcemanagerunittest" ] -} diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn deleted file mode 100644 index 6b6c921..0000000 --- a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn +++ /dev/null @@ -1,119 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/test.gni") -import("//foundation/distributedhardware/distributedinput/distributedinput.gni") -module_out_path = "distributedinput_stander/source_manager" - -group("sourcemanagerunittest") { - testonly = true - - deps = [ ":distributed_input_sourcemanager_test" ] -} - -## UnitTest distributed_input_manager_service_test {{{ -ohos_unittest("distributed_input_sourcemanager_test") { - module_out_path = module_out_path - - include_dirs = [ - "${innerkits_path}/include", - "${innerkits_path}/src", - "${ipc_path}/include", - "${ipc_path}/src", - "//foundation/distributedhardware/distributedinput/services/source/sourcemanager/include", - "//foundation/distributedhardware/distributedinput/frameworks/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${common_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${service_common}/include", - "//third_party/json/include", - "//foundation/communication/dsoftbus/interfaces/kits/transport", - "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp/include", - "${services_source_path}/inputinject/include", - "${services_source_path}/transport/include", - ] - - sources = [ - "//foundation/distributedhardware/distributedinput/services/source/sourcemanager/src/distributed_input_source_manager.cpp", - "//foundation/distributedhardware/distributedinput/services/source/sourcemanager/src/distributed_input_source_event_handler.cpp", - "distributed_input_sourcemanager_test.cpp", - "//foundation/distributedhardware/distributedinput/services/source/inputinject/src/distributed_input_inject.cpp", - "//foundation/distributedhardware/distributedinput/services/source/inputinject/src/distributed_input_node_manager.cpp", - "//foundation/distributedhardware/distributedinput/services/source/inputinject/src/virtual_device.cpp", - "//foundation/distributedhardware/distributedinput/services/source/inputinject/src/virtual_keyboard.cpp", - "//foundation/distributedhardware/distributedinput/services/source/inputinject/src/virtual_mouse.cpp", - "//foundation/distributedhardware/distributedinput/services/source/inputinject/src/virtual_touchpad.cpp", - "//foundation/distributedhardware/distributedinput/services/source/transport/src/distributed_input_source_transport.cpp", - - - "${ipc_path}/src/add_white_list_infos_call_back_proxy.cpp", - "${ipc_path}/src/add_white_list_infos_call_back_stub.cpp", - "${ipc_path}/src/del_white_list_infos_call_back_proxy.cpp", - "${ipc_path}/src/del_white_list_infos_call_back_stub.cpp", - "${ipc_path}/src/distributed_input_sink_proxy.cpp", - "${ipc_path}/src/distributed_input_sink_stub.cpp", - "${ipc_path}/src/distributed_input_source_proxy.cpp", - "${ipc_path}/src/distributed_input_source_stub.cpp", - "${ipc_path}/src/prepare_d_input_call_back_proxy.cpp", - "${ipc_path}/src/prepare_d_input_call_back_stub.cpp", - "${ipc_path}/src/register_d_input_call_back_proxy.cpp", - "${ipc_path}/src/register_d_input_call_back_stub.cpp", - "${ipc_path}/src/start_d_input_call_back_proxy.cpp", - "${ipc_path}/src/start_d_input_call_back_stub.cpp", - "${ipc_path}/src/start_d_input_server_call_back_proxy.cpp", - "${ipc_path}/src/start_d_input_server_call_back_stub.cpp", - "${ipc_path}/src/stop_d_input_call_back_proxy.cpp", - "${ipc_path}/src/stop_d_input_call_back_stub.cpp", - "${ipc_path}/src/unprepare_d_input_call_back_proxy.cpp", - "${ipc_path}/src/unprepare_d_input_call_back_stub.cpp", - "${ipc_path}/src/unregister_d_input_call_back_proxy.cpp", - "${ipc_path}/src/unregister_d_input_call_back_stub.cpp", - ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", - "-Dprivate=public", - "-Dprotected=public", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedinpututtest\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "//foundation/bundlemanager/bundle_framework/interfaces/innerkits/libeventhandler:libeventhandler", - "//utils/native/base:utils", - "${fwk_utils_path}:distributedhardwareutils", - "//foundation/communication/dsoftbus/sdk:softbus_client", - "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", - ] - - external_deps = [ - "ipc:ipc_core", - "safwk:system_ability_fwk", - "hiviewdfx_hilog_native:libhilog", - "samgr_standard:samgr_proxy", - ] - - cflags_cc = [ "-DHILOG_ENABLE" ] -} - -## UnitTest distributed_input_manager_service_test }}} diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp deleted file mode 100644 index 80939a5..0000000 --- a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp +++ /dev/null @@ -1,349 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_input_sourcemanager_test.h" - -#include -#include -#include -#include - -#include - -#include "event_handler.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" -#include "nlohmann/json.hpp" -#include "system_ability_definition.h" - -#include "dinput_errcode.h" - -using namespace testing::ext; -using namespace OHOS::DistributedHardware::DistributedInput; -using namespace std; -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -namespace { - static const uint32_t INPUT_DEVICE_CLASS_KEYBOARD = - static_cast(DeviceClasses::INPUT_DEVICE_CLASS_KEYBOARD); - static const uint32_t INPUT_DEVICE_CLASS_CURSOR = static_cast(DeviceClasses::INPUT_DEVICE_CLASS_CURSOR); - static const uint32_t INPUT_DEVICE_CLASS_TOUCH = static_cast(DeviceClasses::INPUT_DEVICE_CLASS_TOUCH); -} - -void DistributedInputSourceManagerTest::SetUp() -{ - sourceManager_ = new DistributedInputSourceManager(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, true); -} - -void DistributedInputSourceManagerTest::TearDown() -{ -} - -void DistributedInputSourceManagerTest::SetUpTestCase() -{ -} - -void DistributedInputSourceManagerTest::TearDownTestCase() -{ -} - -void DistributedInputSourceManagerTest::TestRegisterDInputCb::OnResult( - const std::string& devId, const std::string& dhId, const int32_t& status) const -{ - return; -} - -void DistributedInputSourceManagerTest::TestUnregisterDInputCb::OnResult( - const std::string& devId, const std::string& dhId, const int32_t& status) const -{ - return; -} - -void DistributedInputSourceManagerTest::TestPrepareDInputCallback::OnResult( - const std::string& deviceId, const int32_t& status) const -{ - return; -} - -void DistributedInputSourceManagerTest::TestUnprepareDInputCallback::OnResult( - const std::string& deviceId, const int32_t& status) const -{ - return; -} - -void DistributedInputSourceManagerTest::TestStartDInputCallback::OnResult( - const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) const -{ - return; -} - -void DistributedInputSourceManagerTest::TestStopDInputCallback::OnResult( - const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) const -{ - return; -} - -void DistributedInputSourceManagerTest::TestAddWhiteListInfosCb::OnResult( - const std::string &deviceId, const std::string &strJson) const -{ - return; -} - -void DistributedInputSourceManagerTest::TestDelWhiteListInfosCb::OnResult( - const std::string& deviceId) const -{ - return; -} - -int32_t DistributedInputSourceManagerTest::StructTransJson(const InputDevice& pBuf, std::string& strDescriptor) const -{ - nlohmann::json tmpJson; - tmpJson["name"] = pBuf.name; - tmpJson["location"] = pBuf.location; - tmpJson["uniqueId"] = pBuf.uniqueId; - tmpJson["bus"] = pBuf.bus; - tmpJson["vendor"] = pBuf.vendor; - tmpJson["product"] = pBuf.product; - tmpJson["version"] = pBuf.version; - tmpJson["descriptor"] = pBuf.descriptor; - tmpJson["nonce"] = pBuf.nonce; - tmpJson["classes"] = pBuf.classes; - - std::ostringstream stream; - stream << tmpJson.dump(); - strDescriptor = stream.str(); - return SUCCESS; -} - -HWTEST_F(DistributedInputSourceManagerTest, Init01, testing::ext::TestSize.Level0) -{ - std::cout << "Init01"<< std::endl; - int32_t ret = sourceManager_->Init(); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, RegisterDistributedHardware01, testing::ext::TestSize.Level0) -{ - InputDevice pBuffer; - pBuffer.name = "uinput_name_touch"; - pBuffer.bus = 0x03; - pBuffer.vendor = 0x1233; - pBuffer.product = 0xfedb; - pBuffer.version = 3; - pBuffer.location = "usb-hiusb-ehci-2.1/input1"; - pBuffer.uniqueId = "3"; - pBuffer.nonce = 0; - pBuffer.classes = INPUT_DEVICE_CLASS_TOUCH; - pBuffer.descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - std::string dhId = pBuffer.descriptor; - std::string parameters; - StructTransJson(pBuffer, parameters); - - sptr callback = new TestRegisterDInputCb(); - int32_t ret = sourceManager_->RegisterDistributedHardware(devId, dhId, parameters, callback); - - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, RegisterDistributedHardware02, testing::ext::TestSize.Level0) -{ - std::cout << "RegisterDistributedHardware1"<< std::endl; - InputDevice pBuffer; - pBuffer.name = "uinput_name_mouse"; - pBuffer.bus = 0x03; - pBuffer.vendor = 0x1222; - pBuffer.product = 0xfeda; - pBuffer.version = 2; - pBuffer.location = "usb-hiusb-ehci-2.1/input1"; - pBuffer.uniqueId = "2"; - pBuffer.nonce = 0; - pBuffer.classes = INPUT_DEVICE_CLASS_CURSOR; - pBuffer.descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; - - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - std::string dhId = pBuffer.descriptor; - std::string parameters; - std::cout << "RegisterDistributedHardware2"<< std::endl; - StructTransJson(pBuffer, parameters); - std::cout << "RegisterDistributedHardware3"<< std::endl; - sptr callback = new TestRegisterDInputCb(); - int32_t ret = sourceManager_->RegisterDistributedHardware(devId, dhId, parameters, callback); - std::cout << "RegisterDistributedHardware4"<< std::endl; - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, RegisterDistributedHardware03, testing::ext::TestSize.Level0) -{ - std::cout << "RegisterDistributedHardware11"<< std::endl; - InputDevice pBuffer; - pBuffer.name = "uinput_name_keyboard"; - pBuffer.bus = 0x03; - pBuffer.vendor = 0x1234; - pBuffer.product = 0xfedc; - pBuffer.version = 1; - pBuffer.location = "usb-hiusb-ehci-2.1/input1"; - pBuffer.uniqueId = "1"; - pBuffer.nonce = 0; - pBuffer.classes = INPUT_DEVICE_CLASS_KEYBOARD; - pBuffer.descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; - - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - std::string dhId = pBuffer.descriptor; - std::string parameters; - std::cout << "RegisterDistributedHardware12"<< std::endl; - StructTransJson(pBuffer, parameters); - std::cout << "RegisterDistributedHardware13"<< std::endl; - sptr callback = new TestRegisterDInputCb(); - int32_t ret = sourceManager_->RegisterDistributedHardware(devId, dhId, parameters, callback); - std::cout << "RegisterDistributedHardware03"<< std::endl; - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, PrepareRemoteInput01, testing::ext::TestSize.Level0) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - sptr callback = new TestPrepareDInputCallback(); - sptr addWhiteListCallback = new TestAddWhiteListInfosCb(); - std::cout << "PrepareRemoteInput011"<< std::endl; - int32_t ret = sourceManager_->PrepareRemoteInput(devId, callback, addWhiteListCallback); - std::cout << "PrepareRemoteInput012"<< std::endl; - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, PrepareRemoteInput02, testing::ext::TestSize.Level0) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - sptr callback; - sptr addWhiteListCallback = new TestAddWhiteListInfosCb(); - int32_t ret = sourceManager_->PrepareRemoteInput(devId, callback, addWhiteListCallback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, PrepareRemoteInput03, testing::ext::TestSize.Level0) -{ - std::string devId = ""; - sptr callback = new TestPrepareDInputCallback(); - sptr addWhiteListCallback = new TestAddWhiteListInfosCb(); - int32_t ret = sourceManager_->PrepareRemoteInput(devId, callback, addWhiteListCallback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput01, testing::ext::TestSize.Level0) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - sptr callback = new TestStartDInputCallback(); - int32_t ret = sourceManager_->StartRemoteInput(devId, INPUT_TYPE_ALL, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput02, testing::ext::TestSize.Level0) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - sptr callback; - int32_t ret = sourceManager_->StartRemoteInput(devId, INPUT_TYPE_ALL, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput03, testing::ext::TestSize.Level0) -{ - std::string devId = ""; - sptr callback = new TestStartDInputCallback(); - int32_t ret = sourceManager_->StartRemoteInput(devId, INPUT_TYPE_ALL, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput01, testing::ext::TestSize.Level0) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - sptr callback = new TestStopDInputCallback(); - int32_t ret = sourceManager_->StopRemoteInput(devId, INPUT_TYPE_ALL, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput02, testing::ext::TestSize.Level0) -{ - std::string devId = ""; - sptr callback = new TestStopDInputCallback(); - int32_t ret = sourceManager_->StopRemoteInput(devId, INPUT_TYPE_ALL, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput03, testing::ext::TestSize.Level0) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - sptr callback; - int32_t ret = sourceManager_->StopRemoteInput(devId, INPUT_TYPE_ALL, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, UnprepareRemoteInput01, testing::ext::TestSize.Level0) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - sptr callback = new TestUnprepareDInputCallback(); - sptr delWhiteListCallback = new TestDelWhiteListInfosCb(); - int32_t ret = sourceManager_->UnprepareRemoteInput(devId, callback, delWhiteListCallback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, UnprepareRemoteInput02, testing::ext::TestSize.Level0) -{ - std::string devId = ""; - sptr callback = new TestUnprepareDInputCallback(); - sptr delWhiteListCallback = new TestDelWhiteListInfosCb(); - int32_t ret = sourceManager_->UnprepareRemoteInput(devId, callback, delWhiteListCallback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, UnprepareRemoteInput03, testing::ext::TestSize.Level0) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - sptr callback; - sptr delWhiteListCallback; - int32_t ret = sourceManager_->UnprepareRemoteInput(devId, callback, delWhiteListCallback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, UnregisterDistributedHardware01, testing::ext::TestSize.Level0) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - std::string dhId = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - sptr callback = new TestUnregisterDInputCb(); - int32_t ret = sourceManager_->UnregisterDistributedHardware(devId, dhId, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, UnregisterDistributedHardware02, testing::ext::TestSize.Level0) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - std::string dhId = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; - sptr callback = new TestUnregisterDInputCb(); - int32_t ret = sourceManager_->UnregisterDistributedHardware(devId, dhId, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, UnregisterDistributedHardware03, testing::ext::TestSize.Level0) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - std::string dhId = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; - sptr callback = new TestUnregisterDInputCb(); - int32_t ret = sourceManager_->UnregisterDistributedHardware(devId, dhId, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL, ret); -} -} -} -} diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h deleted file mode 100644 index 8907868..0000000 --- a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISRIBUTED_INPUT_INNER_TEST_H -#define DISRIBUTED_INPUT_INNER_TEST_H - -#include -#include -#include - -#include -#include - -#include "add_white_list_infos_call_back_stub.h" -#include "constants_dinput.h" -#include "del_white_list_infos_call_back_stub.h" -#include "distributed_input_source_manager.h" -#include "prepare_d_input_call_back_stub.h" -#include "register_d_input_call_back_stub.h" -#include "start_d_input_call_back_stub.h" -#include "stop_d_input_call_back_stub.h" -#include "unprepare_d_input_call_back_stub.h" -#include "unregister_d_input_call_back_stub.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputSourceManagerTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; - - class TestPrepareDInputCallback : public - OHOS::DistributedHardware::DistributedInput::PrepareDInputCallbackStub { - public: - TestPrepareDInputCallback() = default; - virtual ~TestPrepareDInputCallback() = default; - void OnResult(const std::string& deviceId, const int32_t& status) const; - }; - - class TestUnprepareDInputCallback : public - OHOS::DistributedHardware::DistributedInput::UnprepareDInputCallbackStub { - public: - TestUnprepareDInputCallback() = default; - virtual ~TestUnprepareDInputCallback() = default; - void OnResult(const std::string& deviceId, const int32_t& status) const; - }; - - class TestStartDInputCallback : public - OHOS::DistributedHardware::DistributedInput::StartDInputCallbackStub { - public: - TestStartDInputCallback() = default; - virtual ~TestStartDInputCallback() = default; - void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) const; - }; - - class TestStopDInputCallback : public - OHOS::DistributedHardware::DistributedInput::StopDInputCallbackStub { - public: - TestStopDInputCallback() = default; - virtual ~TestStopDInputCallback() = default; - void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) const; - }; - - class TestRegisterDInputCb : public OHOS::DistributedHardware::DistributedInput::RegisterDInputCallbackStub { - public: - TestRegisterDInputCb() = default; - virtual ~TestRegisterDInputCb() = default; - void OnResult(const std::string& devId, const std::string& dhId, const int32_t& status) const; - }; - - class TestUnregisterDInputCb : public OHOS::DistributedHardware::DistributedInput::UnregisterDInputCallbackStub { - public: - TestUnregisterDInputCb() = default; - virtual ~TestUnregisterDInputCb() = default; - void OnResult(const std::string& devId, const std::string& dhId, const int32_t& status) const; - }; - - class TestAddWhiteListInfosCb : public OHOS::DistributedHardware::DistributedInput::AddWhiteListInfosCallbackStub { - public: - TestAddWhiteListInfosCb() = default; - virtual ~TestAddWhiteListInfosCb() = default; - void OnResult(const std::string &deviceId, const std::string &strJson) const; - }; - - class TestDelWhiteListInfosCb : public OHOS::DistributedHardware::DistributedInput::DelWhiteListInfosCallbackStub { - public: - TestDelWhiteListInfosCb() = default; - virtual ~TestDelWhiteListInfosCb() = default; - void OnResult(const std::string &deviceId) const; - }; - -private: - int32_t StructTransJson(const InputDevice& pBuf, std::string& strDescriptor) const; - DistributedInputSourceManager* sourceManager_; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS -#endif // DISRIBUTED_INPUT_INNER_TEST_H diff --git a/services/source/transport/BUILD.gn b/services/source/transport/BUILD.gn deleted file mode 100644 index 405c2d9..0000000 --- a/services/source/transport/BUILD.gn +++ /dev/null @@ -1,66 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//foundation/distributedhardware/distributedinput/distributedinput.gni") - -ohos_shared_library("libdinput_source_trans") { - include_dirs = [ - "include", - "${common_path}/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "//third_party/json/include", - "//foundation/communication/dsoftbus/interfaces/kits/transport", - "${service_common}/include", - "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp/include", - "${services_source_path}/inputinject/include" - ] - - sources = [ - "src/distributed_input_source_transport.cpp" - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedinpusourcetransport\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "//foundation/bundlemanager/bundle_framework/interfaces/innerkits/libeventhandler:libeventhandler", - "//utils/native/base:utils", - "${fwk_utils_path}:distributedhardwareutils", - "//foundation/communication/dsoftbus/sdk:softbus_client", - "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", - "//foundation/distributedhardware/distributedinput/services/source/inputinject:libdinput_inject", - ] - - external_deps = [ - "ipc:ipc_core", - "safwk:system_ability_fwk", - "hiviewdfx_hilog_native:libhilog", - "samgr_standard:samgr_proxy", - ] - - cflags_cc = [ "-DHILOG_ENABLE" ] - - subsystem_name = "distributedhardware" - - part_name = "distributed_input" - -} diff --git a/services/source/transport/include/distributed_input_source_transport.h b/services/source/transport/include/distributed_input_source_transport.h deleted file mode 100644 index c42c51a..0000000 --- a/services/source/transport/include/distributed_input_source_transport.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISTRIBUTED_INPUT_SOURCE_TRANSPORT_H -#define DISTRIBUTED_INPUT_SOURCE_TRANSPORT_H - -#include -#include -#include -#include -#include -#include - -#include "constants.h" -#include "event_handler.h" -#include "nlohmann/json.hpp" -#include "securec.h" - -#include "dinput_source_trans_callback.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputSourceTransport { -public: - static DistributedInputSourceTransport &GetInstance(); - ~DistributedInputSourceTransport(); - - int32_t Init(); - void Release(); - int32_t OpenInputSoftbus(const std::string &remoteDevId); - void CloseInputSoftbus(const std::string &remoteDevId); - void RegisterSourceRespCallback(std::shared_ptr callback); - - int32_t PrepareRemoteInput(const std::string& deviceId); - int32_t UnprepareRemoteInput(const std::string& deviceId); - int32_t StartRemoteInput(const std::string& deviceId, const uint32_t& inputTypes); - int32_t StopRemoteInput(const std::string& deviceId, const uint32_t& inputTypes); - - int32_t OnSessionOpened(int32_t sessionId, int32_t result); - void OnSessionClosed(int32_t sessionId); - void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen); - -private: - std::string FindDeviceBySession(int32_t sessionId); - int32_t SendMsg(int32_t sessionId, std::string &message); - int32_t CheckDeviceSessionState(const std::string &remoteDevId); - void HandleSessionData(int32_t sessionId, const std::string& messageData); - void NotifyResponsePrepareRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); - void NotifyResponseUnprepareRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); - void NotifyResponseStartRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); - void NotifyResponseStopRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); - void NotifyReceivedEventRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); - -private: - std::map sessionDevMap_; - std::map channelStatusMap_; - std::mutex operationMutex_; - std::set sessionIdSet_; - std::shared_ptr callback_; - std::string mySessionName_ = ""; - std::condition_variable openSessionWaitCond_; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - -#endif // DISTRIBUTED_INPUT_SOURCE_TRANSPORT_H diff --git a/services/source/transport/src/distributed_input_source_transport.cpp b/services/source/transport/src/distributed_input_source_transport.cpp deleted file mode 100644 index 1e26404..0000000 --- a/services/source/transport/src/distributed_input_source_transport.cpp +++ /dev/null @@ -1,584 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_input_source_transport.h" - -#include -#include - -#include "anonymous_string.h" -#include "distributed_hardware_log.h" -#include "ipc_skeleton.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" - -#include "constants_dinput.h" -#include "dinput_errcode.h" -#include "dinput_softbus_define.h" -#include "distributed_input_inject.h" -#include "session.h" -#include "softbus_bus_center.h" -#include "softbus_common.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -const int32_t DINPUT_LINK_TYPE_MAX = 4; -static SessionAttribute g_sessionAttr = { - .dataType = SessionType::TYPE_BYTES, - .linkTypeNum = DINPUT_LINK_TYPE_MAX, - .linkType = { - LINK_TYPE_WIFI_WLAN_2G, - LINK_TYPE_WIFI_WLAN_5G, - LINK_TYPE_WIFI_P2P, - LINK_TYPE_BR - } -}; - -DistributedInputSourceTransport::~DistributedInputSourceTransport() -{ - Release(); -} - -static int32_t SessionOpened(int32_t sessionId, int32_t result) -{ - return DistributedInput::DistributedInputSourceTransport::GetInstance().OnSessionOpened(sessionId, result); -} - -static void SessionClosed(int32_t sessionId) -{ - DistributedInput::DistributedInputSourceTransport::GetInstance().OnSessionClosed(sessionId); -} - -static void BytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) -{ - DistributedInput::DistributedInputSourceTransport::GetInstance().OnBytesReceived(sessionId, data, dataLen); -} - -static void MessageReceived(int32_t sessionId, const void *data, uint32_t dataLen) -{ - (void)sessionId; - (void)data; - (void)dataLen; - DHLOGI("sessionId:%s, dataLen:%d", GetAnonyInt32(sessionId).c_str(), dataLen); -} - -static void StreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, - const StreamFrameInfo *param) -{ - (void)sessionId; - (void)data; - (void)ext; - (void)param; - DHLOGI("sessionId:%s", GetAnonyInt32(sessionId).c_str()); -} -DistributedInputSourceTransport &DistributedInputSourceTransport::GetInstance() -{ - static DistributedInputSourceTransport instance; - return instance; -} - -int32_t DistributedInputSourceTransport::Init() -{ - DHLOGI("Init"); - ISessionListener iSessionListener = { - .OnSessionOpened = SessionOpened, - .OnSessionClosed = SessionClosed, - .OnBytesReceived = BytesReceived, - .OnMessageReceived = MessageReceived, - .OnStreamReceived = StreamReceived - }; - - auto localNode = std::make_unique(); - int32_t retCode = GetLocalNodeDeviceInfo(DINPUT_PKG_NAME.c_str(), localNode.get()); - if (retCode != DH_SUCCESS) { - DHLOGE("Init Could not get local device id."); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_INIT_FAIL; - } - std::string networkId = localNode->networkId; - DHLOGI("Init device local networkId is %s", GetAnonyString(networkId).c_str()); - mySessionName_ = SESSION_NAME_SOURCE + networkId.substr(0, INTERCEPT_STRING_LENGTH); - - int32_t ret = CreateSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str(), &iSessionListener); - if (ret != DH_SUCCESS) { - DHLOGE("Init CreateSessionServer failed, error code %d.", ret); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_INIT_FAIL; - } - return DH_SUCCESS; -} - -void DistributedInputSourceTransport::Release() -{ - std::unique_lock sessionLock(operationMutex_); - std::for_each(sessionDevMap_.begin(), sessionDevMap_.end(), [](auto item) { CloseSession(item.second); }); - (void)RemoveSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str()); - sessionDevMap_.clear(); - channelStatusMap_.clear(); - DistributedInputInject::GetInstance().StopInjectThread(); -} - -int32_t DistributedInputSourceTransport::CheckDeviceSessionState(const std::string &devId) -{ - std::unique_lock sessionLock(operationMutex_); - if (sessionDevMap_.count(devId) != 0) { - DHLOGI("CheckDeviceSessionState has opened %s", GetAnonyString(devId).c_str()); - return DH_SUCCESS; - } else { - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_DEVICE_SESSION_STATE; - } -} - -int32_t DistributedInputSourceTransport::OpenInputSoftbus(const std::string &remoteDevId) -{ - int32_t ret = CheckDeviceSessionState(remoteDevId); - if (ret == DH_SUCCESS) { - DHLOGE("Softbus session has already opened, deviceId: %s", GetAnonyString(remoteDevId).c_str()); - return DH_SUCCESS; - } - - std::string peerSessionName = SESSION_NAME_SINK + remoteDevId.substr(0, INTERCEPT_STRING_LENGTH); - DHLOGI("OpenInputSoftbus peerSessionName:%s", peerSessionName.c_str()); - - int sessionId = OpenSession(mySessionName_.c_str(), peerSessionName.c_str(), remoteDevId.c_str(), - GROUP_ID.c_str(), &g_sessionAttr); - if (sessionId < 0) { - DHLOGE("OpenSession fail, remoteDevId: %s, sessionId: %s", - GetAnonyString(remoteDevId).c_str(), GetAnonyInt32(sessionId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_OPEN_SESSION_FAIL; - } - - DHLOGI("Wait for channel session opened."); - { - std::unique_lock waitLock(operationMutex_); - auto status = openSessionWaitCond_.wait_for(waitLock, std::chrono::seconds(SESSION_WAIT_TIMEOUT_SECOND), - [this, remoteDevId] () { return channelStatusMap_[remoteDevId]; }); - if (!status) { - DHLOGE("OpenSession timeout, remoteDevId: %s, sessionId: %s", - GetAnonyString(remoteDevId).c_str(), GetAnonyInt32(sessionId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_OPEN_SESSION_TIMEOUT; - } - } - - DHLOGI("OpenSession success, remoteDevId:%s, sessionId:%s", - GetAnonyString(remoteDevId).c_str(), GetAnonyInt32(sessionId).c_str()); - { - std::unique_lock sessionLock(operationMutex_); - sessionDevMap_[remoteDevId] = sessionId; - } - return DH_SUCCESS; -} - -void DistributedInputSourceTransport::CloseInputSoftbus(const std::string &remoteDevId) -{ - std::unique_lock sessionLock(operationMutex_); - // check this device's all hd is close,this device session close. - - if (sessionDevMap_.count(remoteDevId) == 0) { - DHLOGI("SessionDevIdMap Not find remoteDevId: %s", GetAnonyString(remoteDevId).c_str()); - return; - } - int32_t sessionId = sessionDevMap_[remoteDevId]; - - DHLOGI("RemoteDevId: %s, sessionId: %s", GetAnonyString(remoteDevId).c_str(), GetAnonyInt32(sessionId).c_str()); - CloseSession(sessionId); - sessionDevMap_.erase(remoteDevId); - channelStatusMap_.erase(remoteDevId); - DistributedInputInject::GetInstance().StopInjectThread(); -} - -void DistributedInputSourceTransport::RegisterSourceRespCallback(std::shared_ptr callback) -{ - DHLOGI("RegisterSourceRespCallback"); - callback_ = callback; -} - -/** -* PrepareRemoteInput. -* @param deviceId is remote device -* @return Returns 0 is success, other is fail. -*/ -int32_t DistributedInputSourceTransport::PrepareRemoteInput(const std::string& deviceId) -{ - std::unique_lock sessionLock(operationMutex_); - if (sessionDevMap_.count(deviceId) > 0) { - int32_t sessionId = sessionDevMap_[deviceId]; - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_PREPARE; - jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId; - jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId; - std::string smsg = jsonStr.dump(); - int32_t ret = SendMsg(sessionId, smsg); - if (ret != DH_SUCCESS) { - DHLOGE("PrepareRemoteInput deviceId:%s, sessionId:%s, smsg:%s, SendMsg error, ret:%d.", - GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str(), ret); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_PREPARE_FAIL; - } - DHLOGI("PrepareRemoteInput devId:%s, sessionId:%s, msg:%s.", - GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str()); - return DH_SUCCESS; - } else { - DHLOGE("PrepareRemoteInput error, not find this device:%s.", - GetAnonyString(deviceId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_PREPARE_FAIL; - } -} - -int32_t DistributedInputSourceTransport::UnprepareRemoteInput(const std::string& deviceId) -{ - std::unique_lock sessionLock(operationMutex_); - if (sessionDevMap_.count(deviceId) > 0) { - int32_t sessionId = sessionDevMap_[deviceId]; - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_UNPREPARE; - jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId; - jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId; - std::string smsg = jsonStr.dump(); - int32_t ret = SendMsg(sessionId, smsg); - if (ret != DH_SUCCESS) { - DHLOGE("UnprepareRemoteInput deviceId:%s, sessionId:%s, smsg:%s, SendMsg error, ret:%d.", - GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str(), ret); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_UNPREPARE_FAIL; - } - DHLOGI("UnprepareRemoteInput deviceId:%s, sessionId:%s, smsg:%s.", - GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str()); - return DH_SUCCESS; - } else { - DHLOGE("UnprepareRemoteInput error, not find this device:%s.", - GetAnonyString(deviceId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_UNPREPARE_FAIL; - } -} - -int32_t DistributedInputSourceTransport::StartRemoteInput( - const std::string& deviceId, const uint32_t& inputTypes) -{ - std::unique_lock sessionLock(operationMutex_); - if (sessionDevMap_.count(deviceId) > 0) { - int32_t sessionId = sessionDevMap_[deviceId]; - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_START; - jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId; - jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId; - jsonStr[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - std::string smsg = jsonStr.dump(); - int32_t ret = SendMsg(sessionId, smsg); - if (ret != DH_SUCCESS) { - DHLOGE("StartRemoteInput deviceId:%s, sessionId:%s, smsg:%s, SendMsg error, ret:%d.", - GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str(), ret); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL; - } - DHLOGI("StartRemoteInput deviceId:%s, sessionId:%s, smsg:%s.", - GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str()); - return DH_SUCCESS; - } else { - DHLOGE("StartRemoteInput error, not find this device:%s.", - GetAnonyString(deviceId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL; - } -} - -int32_t DistributedInputSourceTransport::StopRemoteInput( - const std::string& deviceId, const uint32_t& inputTypes) -{ - std::unique_lock sessionLock(operationMutex_); - if (sessionDevMap_.count(deviceId) > 0) { - int32_t sessionId = sessionDevMap_[deviceId]; - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP; - jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId; - jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId; - jsonStr[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - std::string smsg = jsonStr.dump(); - int32_t ret = SendMsg(sessionId, smsg); - if (ret != DH_SUCCESS) { - DHLOGE("StopRemoteInput deviceId:%s, sessionId:%s, smsg:%s, SendMsg error, ret:%d.", - GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str(), ret); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL; - } - DHLOGI("StopRemoteInput deviceId:%s, sessionId:%s, smsg:%s.", - GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str()); - return DH_SUCCESS; - } else { - DHLOGE("StopRemoteInput error, not find this device:%s.", GetAnonyString(deviceId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL; - } -} - -std::string DistributedInputSourceTransport::FindDeviceBySession(int32_t sessionId) -{ - std::unique_lock sessionLock(operationMutex_); - auto find_item = std::find_if(sessionDevMap_.begin(), sessionDevMap_.end(), - [sessionId](const std::map::value_type item) { - return item.second == sessionId; - }); - - std::string devId = ""; - if (find_item != sessionDevMap_.end()) { - devId = (*find_item).first; - } else { - DHLOGE("findKeyByValue error."); - } - return devId; -} - -int32_t DistributedInputSourceTransport::OnSessionOpened(int32_t sessionId, int32_t result) -{ - if (result != DH_SUCCESS) { - std::string deviceId = FindDeviceBySession(sessionId); - DHLOGE("session open failed, sessionId:%s, result:%d, " - "deviceId:%s", GetAnonyInt32(sessionId).c_str(), result, GetAnonyString(deviceId).c_str()); - std::unique_lock sessionLock(operationMutex_); - if (sessionDevMap_.count(deviceId) > 0) { - sessionDevMap_.erase(deviceId); - } - return DH_SUCCESS; - } - - std::string deviceId = FindDeviceBySession(sessionId); - int32_t sessionSide = GetSessionSide(sessionId); - DHLOGI("session open succeed, sessionId:%s, sessionSide:%d(1 is " - "client side), deviceId:%s", GetAnonyInt32(sessionId).c_str(), sessionSide, GetAnonyString(deviceId).c_str()); - - char mySessionName[SESSION_NAME_SIZE_MAX] = ""; - char peerSessionName[SESSION_NAME_SIZE_MAX] = ""; - char peerDevId[DEVICE_ID_SIZE_MAX] = ""; - int ret = GetMySessionName(sessionId, mySessionName, sizeof(mySessionName)); - if (ret != DH_SUCCESS) { - DHLOGI("get my session name failed, session id is %s", GetAnonyInt32(sessionId).c_str()); - } - ret = GetPeerSessionName(sessionId, peerSessionName, sizeof(peerSessionName)); - if (ret != DH_SUCCESS) { - DHLOGI("get peer session name failed, session id is %s", GetAnonyInt32(sessionId).c_str()); - } - ret = GetPeerDeviceId(sessionId, peerDevId, sizeof(peerDevId)); - if (ret != DH_SUCCESS) { - DHLOGI("get peer device id failed, session id is %s", GetAnonyInt32(sessionId).c_str()); - } - DHLOGI("mySessionName:%s, peerSessionName:%s, peerDevId:%s", - mySessionName, peerSessionName, GetAnonyString(peerDevId).c_str()); - { - std::lock_guard notifyLock(operationMutex_); - channelStatusMap_[peerDevId] = true; - openSessionWaitCond_.notify_all(); - } - DistributedInputInject::GetInstance().StartInjectThread(); - return DH_SUCCESS; -} - -void DistributedInputSourceTransport::OnSessionClosed(int32_t sessionId) -{ - std::string deviceId = FindDeviceBySession(sessionId); - DHLOGI("OnSessionClosed, sessionId:%s, deviceId:%s", - GetAnonyInt32(sessionId).c_str(), GetAnonyString(deviceId).c_str()); - std::unique_lock sessionLock(operationMutex_); - if (sessionDevMap_.count(deviceId) > 0) { - sessionDevMap_.erase(deviceId); - } - channelStatusMap_.erase(deviceId); - DistributedInputInject::GetInstance().StopInjectThread(); -} - -void DistributedInputSourceTransport::NotifyResponsePrepareRemoteInput(int32_t sessionId, - const nlohmann::json &recMsg) -{ - DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_ONPREPARE."); - if (!recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE].is_boolean() || - !recMsg[DINPUT_SOFTBUS_KEY_WHITE_LIST].is_string()) { - DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_ONPREPARE, data type is error."); - return; - } - std::string deviceId = FindDeviceBySession(sessionId); - if (deviceId.empty()) { - DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_ONPREPARE, deviceId is error."); - return; - } - callback_->onResponsePrepareRemoteInput(deviceId, recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE], - recMsg[DINPUT_SOFTBUS_KEY_WHITE_LIST]); -} - -void DistributedInputSourceTransport::NotifyResponseUnprepareRemoteInput(int32_t sessionId, - const nlohmann::json &recMsg) -{ - DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_ONUNPREPARE."); - if (!recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE].is_boolean()) { - DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_ONUNPREPARE data type is error."); - return; - } - std::string deviceId = FindDeviceBySession(sessionId); - if (deviceId.empty()) { - DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_ONUNPREPARE, deviceId is error."); - return; - } - callback_->onResponseUnprepareRemoteInput(deviceId, recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE]); - CloseInputSoftbus(deviceId); -} - -void DistributedInputSourceTransport::NotifyResponseStartRemoteInput(int32_t sessionId, const nlohmann::json &recMsg) -{ - DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_ONSTART."); - if (!recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE].is_boolean()) { - DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_ONSTART, data type is error."); - return; - } - std::string deviceId = FindDeviceBySession(sessionId); - if (deviceId.empty()) { - DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_ONSTART, deviceId is error."); - return; - } - callback_->onResponseStartRemoteInput( - deviceId, recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE], recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE]); -} - -void DistributedInputSourceTransport::NotifyResponseStopRemoteInput(int32_t sessionId, const nlohmann::json &recMsg) -{ - DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_ONSTOP."); - if (!recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE].is_boolean()) { - DHLOGE("OnBytesReceived cmdType TRANS_SINK_MSG_ONSTOP data type is error."); - return; - } - std::string deviceId = FindDeviceBySession(sessionId); - if (deviceId.empty()) { - DHLOGE("OnBytesReceived cmdType TRANS_SINK_MSG_ONSTOP, deviceId is error."); - return; - } - callback_->onResponseStopRemoteInput( - deviceId, recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE], recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE]); -} - -void DistributedInputSourceTransport::NotifyReceivedEventRemoteInput(int32_t sessionId, const nlohmann::json &recMsg) -{ - DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_BODY_DATA."); - if (!recMsg[DINPUT_SOFTBUS_KEY_INPUT_DATA].is_string()) { - DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_BODY_DATA, data type is error."); - return; - } - - std::string deviceId = FindDeviceBySession(sessionId); - if (deviceId.empty()) { - DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_BODY_DATA, deviceId is error."); - return; - } - std::string inputDataStr = recMsg[DINPUT_SOFTBUS_KEY_INPUT_DATA]; - callback_->onReceivedEventRemoteInput(deviceId, inputDataStr); -} - -void DistributedInputSourceTransport::HandleSessionData(int32_t sessionId, const std::string& message) -{ - if (callback_ == nullptr) { - DHLOGE("OnBytesReceived the callback_ is null, the message:%s abort.", message.c_str()); - return; - } - nlohmann::json recMsg = nlohmann::json::parse(message); - if (recMsg.is_discarded()) { - DHLOGE("OnBytesReceived jsonStr error."); - return; - } - - if (recMsg.contains(DINPUT_SOFTBUS_KEY_CMD_TYPE) != true) { - DHLOGE("OnBytesReceived message:%s is error, not contain cmdType.", - message.c_str()); - return; - } - - if (recMsg[DINPUT_SOFTBUS_KEY_CMD_TYPE].is_number() != true) { - DHLOGE("OnBytesReceived cmdType is not number type."); - return; - } - - int cmdType = recMsg[DINPUT_SOFTBUS_KEY_CMD_TYPE]; - switch (cmdType) { - case TRANS_SINK_MSG_ONPREPARE: { - NotifyResponsePrepareRemoteInput(sessionId, recMsg); - break; - } - case TRANS_SINK_MSG_ONUNPREPARE: { - NotifyResponseUnprepareRemoteInput(sessionId, recMsg); - break; - } - case TRANS_SINK_MSG_ONSTART: { - NotifyResponseStartRemoteInput(sessionId, recMsg); - break; - } - case TRANS_SINK_MSG_ONSTOP: { - NotifyResponseStopRemoteInput(sessionId, recMsg); - break; - } - case TRANS_SINK_MSG_BODY_DATA: { - NotifyReceivedEventRemoteInput(sessionId, recMsg); - break; - } - default: { - DHLOGE("OnBytesReceived cmdType is undefined."); - break; - } - } -} - -void DistributedInputSourceTransport::OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) -{ - DHLOGI("OnBytesReceived, sessionId:%s, dataLen:%d", GetAnonyInt32(sessionId).c_str(), dataLen); - if (sessionId < 0 || data == nullptr || dataLen <= 0) { - DHLOGE("OnBytesReceived param check failed"); - return; - } - - uint8_t *buf = (uint8_t *)calloc(dataLen + 1, sizeof(uint8_t)); - if (buf == nullptr) { - DHLOGE("OnBytesReceived: malloc memory failed"); - return; - } - - if (memcpy_s(buf, dataLen + 1, (const uint8_t*)data, dataLen) != DH_SUCCESS) { - DHLOGE("OnBytesReceived: memcpy memory failed"); - free(buf); - return; - } - - std::string message = (char *)buf; - DHLOGI("OnBytesReceived message:%s.", message.c_str()); - HandleSessionData(sessionId, message); - - free(buf); - DHLOGI("OnBytesReceived completed"); - return; -} - -// send message by sessionId (channel opened) -int32_t DistributedInputSourceTransport::SendMsg(int32_t sessionId, std::string &message) -{ - DHLOGI("start SendMsg"); - if (message.size() > MSG_MAX_SIZE) { - DHLOGE("SendMessage error: message.size() > MSG_MAX_SIZE"); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE; - } - uint8_t *buf = (uint8_t *)calloc((MSG_MAX_SIZE), sizeof(uint8_t)); - if (buf == nullptr) { - DHLOGE("SendMsg: malloc memory failed"); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE; - } - int32_t outLen = 0; - if (memcpy_s(buf, MSG_MAX_SIZE, (const uint8_t *)message.c_str(), message.size()) != DH_SUCCESS) { - DHLOGE("SendMsg: memcpy memory failed"); - free(buf); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE; - } - outLen = message.size(); - int32_t ret = SendBytes(sessionId, buf, outLen); - free(buf); - return ret; -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/source/transport/test/BUILD.gn b/services/source/transport/test/BUILD.gn deleted file mode 100644 index ad09beb..0000000 --- a/services/source/transport/test/BUILD.gn +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -group("test") { - testonly = true - - deps = [ "sourcetransunittest:sourcetransunittest" ] -} diff --git a/services/source/transport/test/sourcetransunittest/BUILD.gn b/services/source/transport/test/sourcetransunittest/BUILD.gn deleted file mode 100644 index 5ffd837..0000000 --- a/services/source/transport/test/sourcetransunittest/BUILD.gn +++ /dev/null @@ -1,81 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/test.gni") -import("//foundation/distributedhardware/distributedinput/distributedinput.gni") -module_out_path = "distributedinput_stander/source_trans" - -group("sourcetransunittest") { - testonly = true - - deps = [ ":distributed_input_sourcetrans_test" ] -} - -## UnitTest distributed_input_manager_service_test {{{ -ohos_unittest("distributed_input_sourcetrans_test") { - module_out_path = module_out_path - - include_dirs = [ - "//foundation/distributedhardware/distributedinput/services/source/transport/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${common_path}/include", - "//utils/native/base/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${service_common}/include", - "//third_party/json/include", - "${services_source_path}/inputinject/include", - "//foundation/distributedhardware/distributedinput/services/source/transport/test/sourcetransunittest/mock", - ] - - sources = [ - "//foundation/distributedhardware/distributedinput/services/source/transport/src/distributed_input_source_transport.cpp", - "distributed_input_sourcetrans_test.cpp", - ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", - "-Dprivate=public", - "-Dprotected=public", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedinpututtest\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "//foundation/bundlemanager/bundle_framework/interfaces/innerkits/libeventhandler:libeventhandler", - "//utils/native/base:utils", - "${fwk_utils_path}:distributedhardwareutils", - "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", - "//foundation/distributedhardware/distributedinput/services/source/inputinject:libdinput_inject", - ] - - external_deps = [ - "ipc:ipc_core", - "safwk:system_ability_fwk", - "hiviewdfx_hilog_native:libhilog", - "samgr_standard:samgr_proxy", - ] - - cflags_cc = [ "-DHILOG_ENABLE" ] -} - -## UnitTest distributed_input_manager_service_test }}} \ No newline at end of file diff --git a/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.cpp b/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.cpp deleted file mode 100644 index 389173a..0000000 --- a/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "dinput_errcode.h" -#include "distributed_input_sourcetrans_test.h" - -using namespace testing::ext; -using namespace OHOS::DistributedHardware::DistributedInput; -using namespace std; -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -void DistributedInputSourceTransTest::SetUp() -{ -} - -void DistributedInputSourceTransTest::TearDown() -{ -} - -void DistributedInputSourceTransTest::SetUpTestCase() -{ -} - -void DistributedInputSourceTransTest::TearDownTestCase() -{ -} - -HWTEST_F(DistributedInputSourceTransTest, Init, testing::ext::TestSize.Level0) -{ - int32_t ret = DistributedInputSourceTransport::GetInstance().Init(); - - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, OpenInputSoftbus, testing::ext::TestSize.Level0) -{ - std::string remoteDevId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - int32_t ret = DistributedInputSourceTransport::GetInstance().OpenInputSoftbus(remoteDevId); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_OPEN_SESSION_TIMEOUT, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, PrepareRemoteInput01, testing::ext::TestSize.Level0) -{ - std::string deviceId = ""; - int32_t ret = DistributedInputSourceTransport::GetInstance().PrepareRemoteInput(deviceId); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_PREPARE_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, PrepareRemoteInput02, testing::ext::TestSize.Level0) -{ - std::string deviceId = "tttt0001"; - int32_t ret = DistributedInputSourceTransport::GetInstance().PrepareRemoteInput(deviceId); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_PREPARE_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, PrepareRemoteInput03, testing::ext::TestSize.Level1) -{ - std::string deviceId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - int32_t ret = DistributedInputSourceTransport::GetInstance().PrepareRemoteInput(deviceId); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_PREPARE_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, UnprepareRemoteInput01, testing::ext::TestSize.Level0) -{ - std::string deviceId = ""; - int32_t ret = DistributedInputSourceTransport::GetInstance().UnprepareRemoteInput(deviceId); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_UNPREPARE_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, UnprepareRemoteInput02, testing::ext::TestSize.Level0) -{ - std::string deviceId = "tttt0001"; - int32_t ret = DistributedInputSourceTransport::GetInstance().UnprepareRemoteInput(deviceId); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_UNPREPARE_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, UnprepareRemoteInput03, testing::ext::TestSize.Level0) -{ - std::string deviceId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - int32_t ret = DistributedInputSourceTransport::GetInstance().UnprepareRemoteInput(deviceId); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_UNPREPARE_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, StartRemoteInput01, testing::ext::TestSize.Level0) -{ - std::string deviceId = "tttt0001"; - int32_t ret = DistributedInputSourceTransport::GetInstance().StartRemoteInput(deviceId, INPUT_TYPE_ALL); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, StartRemoteInput02, testing::ext::TestSize.Level0) -{ - std::string deviceId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - int32_t ret = DistributedInputSourceTransport::GetInstance().StartRemoteInput(deviceId, INPUT_TYPE_ALL); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, StopRemoteInput01, testing::ext::TestSize.Level0) -{ - std::string deviceId = "tttt0001"; - int32_t ret = DistributedInputSourceTransport::GetInstance().StopRemoteInput(deviceId, INPUT_TYPE_ALL); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, StopRemoteInput02, testing::ext::TestSize.Level0) -{ - std::string deviceId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - int32_t ret = DistributedInputSourceTransport::GetInstance().StopRemoteInput(deviceId, INPUT_TYPE_ALL); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL, ret); - DistributedInputSourceTransport::GetInstance().CloseInputSoftbus(deviceId); -} -} -} -} diff --git a/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.h b/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.h deleted file mode 100644 index f612956..0000000 --- a/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISRIBUTED_INPUT_INNER_TEST_H -#define DISRIBUTED_INPUT_INNER_TEST_H - -#include -#include -#include -#include - -#include - -#include "constants_dinput.h" -#include "distributed_input_source_transport.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputSourceTransTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS -#endif // DISRIBUTED_INPUT_INNER_TEST_H diff --git a/services/source/transport/test/sourcetransunittest/mock/session.h b/services/source/transport/test/sourcetransunittest/mock/session.h deleted file mode 100644 index fe5a96b..0000000 --- a/services/source/transport/test/sourcetransunittest/mock/session.h +++ /dev/null @@ -1,479 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @addtogroup Softbus - * @{ - * - * @brief Provides high-speed, secure communication between devices. - * - * This module implements unified distributed communication capability management between - * nearby devices, and provides link-independent device discovery and transmission interfaces - * to support service publishing and data transmission. - * - * @since 1.0 - * @version 1.0 -*/ - -/** - * @file session.h - * - * @brief Declares unified data transmission interfaces. - * - * This file provides data transmission capabilities, including creating and removing a session server, - * opening and closing sessions, receiving data, and querying basic session information. \n - * After multiple nearby devices are discovered and networked, these interfaces can be used to - * transmit data across devices. \n - * - * @since 1.0 - * @version 1.0 - */ -#ifndef SESSION_H -#define SESSION_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif -/** - * @brief business type of session - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - TYPE_MESSAGE = 1, - TYPE_BYTES, - TYPE_FILE, - TYPE_STREAM, - TYPE_BUTT, -} SessionType; - -typedef enum { - INVALID = -1, - /* - * Send any segment of a frame each time. - */ - RAW_STREAM, - /* - * Send a whole video frame each time. - */ - COMMON_VIDEO_STREAM, - /* - * Send a whole audio frame each time. - */ - COMMON_AUDIO_STREAM, - /* - * Slice frame mode. - */ - VIDEO_SLICE_STREAM, -} StreamType; - -typedef enum { - LINK_TYPE_WIFI_WLAN_5G = 1, - LINK_TYPE_WIFI_WLAN_2G = 2, - LINK_TYPE_WIFI_P2P = 3, - LINK_TYPE_BR = 4, - LINK_TYPE_MAX = 4, -} LinkType; - -/** - * @brief session attribute. - * - * control the attribute of session. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - /** @brief dataType{@link SessionType} */ - int dataType; - int linkTypeNum; - LinkType linkType[LINK_TYPE_MAX]; - union { - struct StreamAttr { - int streamType; - } streamAttr; - } attr; -} SessionAttribute; - -typedef struct { - char *buf; - int bufLen; -} StreamData; - -typedef struct { - int type; - int64_t value; -} TV; - -typedef struct { - int frameType; - int64_t timeStamp; - int seqNum; - int seqSubNum; - int level; - int bitMap; - int tvCount; - TV *tvList; -} StreamFrameInfo; - -typedef enum { - QOS_IMPROVE = 0, - QOS_RECOVER = 1 -} QosQuality; - -typedef enum { - TRANS_STREAM_QUALITY_EVENT = 1, - TRANS_CHANNEL_QUALITY_EVENT, - TRANS_CAN_DELAY_EVENT, - TRANS_CANT_DELAY_EVENT, - QOS_EVENT_MAX -} QosEvent; - -typedef enum { - WIFI_CHANNEL_QUALITY = 1, - FRAME_REALTIME_STATUS = 2, - BANDWIDTH_ESTIMATE_VALUE = 3, - JITTER_DETECTION_VALUE = 4, - STREAM_TRAFFIC_STASTICS = 5, -} TransEnumEventType; - -typedef struct { - int32_t channel; - int32_t score; -} WifiChannelQuality; - -typedef struct { - int32_t streamId; - int32_t seqNum; - int32_t level; - int32_t transStatus; - int32_t interval; -} FrameStatus; - -typedef struct { - uint32_t trend; - uint32_t rate; /* kbps */ -} BandwidthDetection; - -typedef struct { - int32_t jitterLevel; - uint32_t bufferTime; /* ms */ -} JitterEstimation; - -typedef struct { - uint64_t statisticsGotTime; /* time point that stream traficc statistics are obtained (ms) */ - uint64_t periodRecvBits; - uint32_t pktNum; - uint32_t periodRecvPkts; - uint32_t periodRecvPktLoss; - uint32_t periodRecvRate; /* kbps */ - uint64_t periodRecvRateBps; /* bps */ - uint32_t periodRtt; /* ms */ - uint32_t periodRecvPktLossHighPrecision; /* for example when lost rate is 1.10%, then 110 will returned */ - uint32_t periodSendLostPkts; - uint32_t periodSendPkts; - uint32_t periodSendPktLossHighPrecision; /* for example when lost rate is 1.10%, then 110 will returned */ - uint64_t periodSendBits; - uint64_t periodSendRateBps; /* bps */ -} StreamStatistics; - -typedef struct { - TransEnumEventType type; - union { - WifiChannelQuality wifiChannelInfo; - FrameStatus frameStatusInfo; - BandwidthDetection bandwidthInfo; - JitterEstimation jitterInfo; - StreamStatistics appStatistics; - } info; -} QosTv; - -/** - * @brief Defines session callbacks. - * - * When a session is opened or closed, or there is data to process, the related callback is invoked. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - /** - * @brief Called when a session is opened. - * - * This function can be used to verify the session or initialize resources related to the session. - * - * @param sessionId Indicates the session ID. - * @param result 0 if the session is opened successfully, returns an error code otherwise. - * @return Returns 0 if the session connection is accepted; returns a non-zero value - * otherwise (you do not need to call {@link CloseSession} to close the session). - * @since 1.0 - * @version 1.0 - */ - int (*OnSessionOpened)(int sessionId, int result); - - /** - * @brief Called when a session is closed. - * - * This function can be used to release resources related to the session. - * You do not need to call {@link CloseSession}. - * - * @param sessionId Indicates the session ID. - * @since 1.0 - * @version 1.0 - */ - void (*OnSessionClosed)(int sessionId); - - /** - * @brief Called when data is received. - * - * This function is used to notify that data is received. - * - * @param sessionId Indicates the session ID. - * @param data Indicates the pointer to the data received. - * @param dataLen Indicates the length of the data received. - * @since 1.0 - * @version 1.0 - */ - void (*OnBytesReceived)(int sessionId, const void *data, unsigned int dataLen); - - /** - * @brief Called when message is received. - * - * This function is used to notify that message is received. - * - * @param sessionId Indicates the session ID. - * @param data Indicates the pointer to the message data received. - * @param dataLen Indicates the length of the message received. - * @since 1.0 - * @version 1.0 - */ - void (*OnMessageReceived)(int sessionId, const void *data, unsigned int dataLen); - - void (*OnStreamReceived)(int sessionId, const StreamData *data, const StreamData *ext, - const StreamFrameInfo *param); - - /** - * @brief Called when QoS information is retrieved. - * - * This function is used to notify that QoS information is retrieved. - * - * @param sessionId Indicates the session ID. - * @param eventId Indicates the type of QoS information, e.g., channel quality and stream quality - * @param tvCount Indicates the number of structure returned in the fourth parameters, i.e., tvList. - * @param tvList Indicates the detailed information of data transmission. - * @since 1.0 - * @version 1.0 - */ - void (*OnQosEvent)(int sessionId, int eventId, int tvCount, const QosTv *tvList); -} ISessionListener; - -typedef struct { - int (*OnReceiveFileStarted)(int sessionId, const char *files, int fileCnt); - int (*OnReceiveFileProcess)(int sessionId, const char *firstFile, uint64_t bytesUpload, uint64_t bytesTotal); - void (*OnReceiveFileFinished)(int sessionId, const char *files, int fileCnt); - void (*OnFileTransError)(int sessionId); -} IFileReceiveListener; - -typedef struct { - int (*OnSendFileProcess)(int sessionId, uint64_t bytesUpload, uint64_t bytesTotal); - int (*OnSendFileFinished)(int sessionId, const char *firstFile); - void (*OnFileTransError)(int sessionId); -} IFileSendListener; - -/** - * @brief Creates a session server based on a package name and session name. - * - * A maximum of 18 session servers can be created. - * - * @param pkgName Indicates the pointer to the package name, which can be used to check whether the - * session server is in this package. The value cannot be empty and can contain a maximum of 64 characters. - * @param sessionName Indicates the pointer to the session name, which is the unique ID of the session server. - * The value cannot be empty and can contain a maximum of 64 characters. - * @param listener Indicates the pointer to the session callback structure, which cannot be empty. - * @return Returns 0 if the operation is successful; returns -1 otherwise. - * @see RemoveSessionServer - * @since 1.0 - * @version 1.0 - */ -int CreateSessionServer(const char *pkgName, const char *sessionName, const ISessionListener *listener) -{ - return 0; -}; - -/** - * @brief Removes a session server based on a package name and session name. - * - * @param pkgName Indicates the pointer to the name of the registered package, which can be used to check - * whether the session server is in this package. The value cannot be empty and can contain a maximum of 64 characters. - * @param sessionName Indicates the pointer to the session name. The value cannot be empty and can contain - * a maximum of 64 characters. - * @return Returns 0 if the operation is successful, returns -1 otherwise. - * @see CreateSessionServer - * @since 1.0 - * @version 1.0 - */ -int RemoveSessionServer(const char *pkgName, const char *sessionName) -{ - return 0; -}; - -/** - * @brief Initiate a session open request, which is an asynchronous process. - * - * The session connection is opened based on the service name to trigger the first packet interaction process. - * According to the {@link OnSessionOpened} Notify the user whether the session is successfully opened. - * Data can be transmitted only after the session is successfully opened. - * - * @param mySessionName local session name. - * @param peerSessionName remote session name. - * @param peerDeviceId remote device id. - * @param groupId group id. - * @param attr session attribute {@link SessionAttribute}. - * @return return sessionId if the session is opened successfully, returns an error code otherwise. - * @since 1.0 - * @version 1.0 - */ -int OpenSession(const char *mySessionName, const char *peerSessionName, const char *peerDeviceId, - const char *groupId, const SessionAttribute* attr) -{ - return 0; -}; - -/** - * @brief Closes a connected session based on a session ID. - * - * @param sessionId Indicates the session ID. - * @return no return value. - * @since 1.0 - * @version 1.0 - */ -void CloseSession(int sessionId) -{ - return; -}; - -/** - * @brief Sends data based on a session ID. - * - * @param sessionId Indicates the session ID. - * @param data Indicates the pointer to the data to send, which cannot be NULL. - * @param len Indicates the length of the data to send. The maximum length cannot exceed 984 characters. - * @return Returns 0 if the function is called successfully; returns -1 otherwise. - * @since 1.0 - * @version 1.0 - */ -int SendBytes(int sessionId, const void *data, unsigned int len) -{ - return 0; -}; - -/** - * @brief Sends message based on a session ID. - * - * @param sessionId Indicates the session ID. - * @param data Indicates the pointer to the message data to send, which cannot be NULL. - * @param len Indicates the length of the message to send. - * @return Returns 0 if the function is called successfully, returns an error code otherwise. - * @since 1.0 - * @version 1.0 - */ -int SendMessage(int sessionId, const void *data, unsigned int len) -{ - return 0; -}; - -int SendStream(int sessionId, const StreamData *data, const StreamData *ext, const StreamFrameInfo *param) -{ - return 0; -}; - -/** - * @brief Obtains the session name registered by the local device based on the session ID. - * - * @param sessionId Indicates the session ID. - * @param sessionName Indicates the pointer to the buffer for storing the session name. - * @param len Indicates the length of the buffer. - * @return Returns 0 if the operation is successful; returns -1 otherwise. - * @since 1.0 - * @version 1.0 - */ -int GetMySessionName(int sessionId, char *sessionName, unsigned int len) -{ - return 0; -}; - -/** - * @brief Obtains the session name registered by the peer device based on the session ID. - * - * @param sessionId Indicates the session ID. - * @param sessionName Indicates the pointer to the buffer for storing the session name. - * @param len Indicates the length of the buffer. - * @return Returns 0 if the operation is successful; returns -1 otherwise. - * @since 1.0 - * @version 1.0 - */ -int GetPeerSessionName(int sessionId, char *sessionName, unsigned int len) -{ - return 0; -}; - -/** - * @brief Obtains the peer device ID based on a session ID. - * - * @param sessionId Indicates the session ID. - * @param devId Indicates the pointer to the buffer for storing the device ID. - * @param len Indicates the length of the buffer. - * @return Returns 0 if the operation is successful; returns -1 otherwise. - * @since 1.0 - * @version 1.0 - */ -int GetPeerDeviceId(int sessionId, char *devId, unsigned int len) -{ - return 0; -}; - -int GetSessionSide(int sessionId) -{ - return 0; -}; - -int SetFileReceiveListener(const char *pkgName, const char *sessionName, - const IFileReceiveListener *recvListener, const char *rootDir) -{ - return 0; -}; - -int SetFileSendListener(const char *pkgName, const char *sessionName, const IFileSendListener *sendListener) -{ - return 0; -}; - -int SendFile(int sessionId, const char *sFileList[], const char *dFileList[], uint32_t fileCnt) -{ - return 0; -}; - -int32_t QosReport(int32_t sessionId, int32_t appType, int32_t quality) -{ - return 0; -}; - -#ifdef __cplusplus -} -#endif -#endif // SESSION_H diff --git a/services/source/transport/test/sourcetransunittest/mock/softbus_bus_center.h b/services/source/transport/test/sourcetransunittest/mock/softbus_bus_center.h deleted file mode 100644 index c8a5f8c..0000000 --- a/services/source/transport/test/sourcetransunittest/mock/softbus_bus_center.h +++ /dev/null @@ -1,675 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @addtogroup Softbus - * @{ - * - * @brief Provides high-speed, secure communication between devices. - * - * This module implements unified distributed communication capability management between nearby devices, and provides - * link-independent device discovery and transmission interfaces to support service publishing and data transmission. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file softbus_bus_center.h - * - * @brief Declares functions and constants for the bus center of the Intelligent Soft Bus. - * - * The functions are used to perform - * the following operations: \n - *
      - *
    • Adding a device to and removing a device from a LNN
    • - *
    • Listening for device online, offline, and information change events
    • - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef SOFTBUS_BUS_CENTER_H -#define SOFTBUS_BUS_CENTER_H - -#include -#include -#include - -#include "softbus_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Indicates the length of a device name buffer, including the terminating null character \0. - * - * @since 1.0 - * @version 1.0 - */ -#define DEVICE_NAME_BUF_LEN 128 - -/** - * @brief Indicates the mask bit for a device online event. - * If you want to receive such events, set the mask bit in {@link INodeStateCb.events}. - * - * @since 1.0 - * @version 1.0 - */ -#define EVENT_NODE_STATE_ONLINE 0x1 - -/** - * @brief Indicates the mask bit for a device offline event. - * If you want to receive such events, set the mask bit in {@link INodeStateCb.events}. - * - * @since 1.0 - * @version 1.0 - */ -#define EVENT_NODE_STATE_OFFLINE 0x02 - -/** - * @brief Indicates the mask bit for a peer device information change event. - * If you want to receive such events, set the mask bit in {@link INodeStateCb.events}. - * - * @since 1.0 - * @version 1.0 - */ -#define EVENT_NODE_STATE_INFO_CHANGED 0x04 - -/** - * @brief Indicates mask bits for {@link INodeStateCb.events}. - * - * @since 1.0 - * @version 1.0 - */ -#define EVENT_NODE_STATE_MASK 0x07 - -/** - * @brief The maximum length of meta node bypass info {@link MetaNodeConfigInfo.bypassInfo}. - * - * @since 1.0 - * @version 1.0 - */ -#define META_NODE_BYPASS_INFO_LEN 64 - -/** - * @brief The maximum of meta node {@link MetaNodeConfigInfo.bypassInfo}. - * - * @since 1.0 - * @version 1.0 - */ -#define MAX_META_NODE_NUM 3 - -/** - * @brief Enumerates keys for an online device. - * The key can be obtained via {@link GetNodeKeyInfo}. - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - NODE_KEY_UDID = 0, /**< UDID in string format*/ - NODE_KEY_UUID, /**< UUID in string format */ -} NodeDeviceInfoKey; - -/** - * @brief Enumerates accuracy for time synchronize among device. - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - LOW_ACCURACY = 10, - NORMAL_ACCURACY, - HIGH_ACCURACY, - SUPER_HIGH_ACCURACY, - UNAVAIL_ACCURACY = 0xFFFF, -} TimeSyncAccuracy; - -/** - * @brief Enumerates time synchronize period among device. - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - SHORT_PERIOD = 0, - NORMAL_PERIOD, - LONG_PERIOD, -} TimeSyncPeriod; - -/** - * @brief Enumerates time synchronize flag. - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - NODE_SPECIFIC = 0, - ALL_LNN, - WRITE_RTC, -} TimeSyncFlag; - -/** - * @brief Defines the basic information about a device. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - char networkId[NETWORK_ID_BUF_LEN]; /**< Device ID */ - char deviceName[DEVICE_NAME_BUF_LEN]; /**< Device name */ - uint16_t deviceTypeId; -} NodeBasicInfo; - -/** - * @brief Enumerates device information change types. For details, see {@link INodeStateCb.onNodeBasicInfoChanged}. - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - TYPE_NETWORK_ID = 0, /**< Network ID change */ - TYPE_DEVICE_NAME, /**< Device name change */ -} NodeBasicInfoType; - -/** - * @brief time synchronize result. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - int32_t millisecond; - int32_t microsecond; - TimeSyncAccuracy accuracy; -} TimeSyncResult; - -/** - * @brief time synchronize result info. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - TimeSyncResult result; - TimeSyncFlag flag; - union { - char targetNetworkId[NETWORK_ID_BUF_LEN]; - char masterNetworkId[NETWORK_ID_BUF_LEN]; - } target; -} TimeSyncResultInfo; - -/** - * @brief Enumerates error codes for service publishing failures. - * - * The error codes are returned to the caller through IPublishCallback. - * - */ -typedef enum { - /* publish success */ - PUBLISH_LNN_SUCCESS = 0, - /* Unsupported medium */ - PUBLISH_LNN_NOT_SUPPORT_MEDIUM = 1, - /* internal error */ - PUBLISH_LNN_INTERNAL = 2, - /* Unknown reason */ - PUBLISH_LNN_UNKNOWN = 0xFF -} PublishResult; - -/** - * @brief Enumerates error codes for service subscription failures. - * - * The error codes are returned to the caller through IDiscoveryCallback. - * - */ -typedef enum { - /* refresh success */ - REFRESH_LNN_SUCCESS = 0, - /* Unsupported medium */ - REFRESH_LNN_NOT_SUPPORT_MEDIUM = 1, - /* internal error */ - REFRESH_LNN_INTERNAL = 2, - /* Unknown error */ - REFRESH_LNN_UNKNOWN = 0xFF -} RefreshResult; - -/** - * @brief Defines the callbacks for successful and failed service publishing. - * - */ -typedef struct { - /** Callback for publish result */ - void (*OnPublishResult)(int publishId, PublishResult reason); -} IPublishCb; - -/** - * @brief Defines a callback for service subscription. - * - * Three types of callbacks are available. - * - */ -typedef struct { - /** Callback that is invoked when a device is found */ - void (*OnDeviceFound)(const DeviceInfo *device); - /** Callback for a subscription result */ - void (*OnDiscoverResult)(int32_t refreshId, RefreshResult reason); -} IRefreshCallback; - -/** - * @brief Defines a callback that is invoked when the device state or information changes. - * For details, see {@link RegNodeDeviceStateCb}. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - /** - * Mask of an event that is listened for. - * The event can be received only if the corresponding mask bit is set and the callback is specified. - */ - uint32_t events; - /** - * @brief Called when a specified device gets online. - * - * @param info Indicates the pointer to the basic information about the device. - * For details, see {@link NodeBasicInfo}. - * - * @since 1.0 - * @version 1.0 - */ - void (*onNodeOnline)(NodeBasicInfo *info); - /** - * @brief Called when a specified device gets offline. - * - * @param info Indicates the pointer to the basic information about the device. - * For details, see {@link NodeBasicInfo}. - * - * @since 1.0 - * @version 1.0 - */ - void (*onNodeOffline)(NodeBasicInfo *info); - /** - * @brief Called when the basic information of a device changes. - * - * @param type Indicates the device type. For details, see {@link NodeBasicInfoType}. - * @param info Indicates the pointer to the new basic information of the device. - * For details, see {@link NodeBasicInfo}. - * - * @since 1.0 - * @version 1.0 - */ - void (*onNodeBasicInfoChanged)(NodeBasicInfoType type, NodeBasicInfo *info); -} INodeStateCb; - -/** - * @brief Defines a callback that is invoked when the time synchronize has result. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - /** - * @brief Called when the time synchronize has result. - * - * @param info Contains the time synchronize result info, see {@link TimeSyncResultInfo}. - * @param retCode Indicates the result code. Value 0 indicates that the time synchronize is successful and - * result is valid, and any other value indicates the opposite. - * - * @since 1.0 - * @version 1.0 - */ - void (*onTimeSyncResult)(const TimeSyncResultInfo *info, int32_t retCode); -} ITimeSyncCb; - -/** - * @brief Defines a meta node configuration, see {@link ActiveMetaNode}. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - char udid[UDID_BUF_LEN]; - char deviceName[DEVICE_NAME_BUF_LEN]; - uint16_t deviceTypeId; - uint8_t addrNum; - ConnectionAddr addr[CONNECTION_ADDR_MAX]; - char bypassInfo[META_NODE_BYPASS_INFO_LEN]; -} MetaNodeConfigInfo; - -/** - * @brief Defines a meta node infomation, see {@link GetAllMetaNodeInfo}. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - char metaNodeId[NETWORK_ID_BUF_LEN]; - bool isOnline; - MetaNodeConfigInfo configInfo; -} MetaNodeInfo; - -/** - * @brief Called when a device is added to a LNN via {@link JoinLNN}. - * - * @param addr Indicates the pointer to the address of the peer device. - * @param networkId Indicates the pointer to the network ID of the device if it is successfully added to the LNN. - * This parameter makes no sense if the device fails to be added to the LNN. - * @param retCode Indicates the result code. Value 0 indicates that the device is successfully added to the LNN, - * and any other value indicates the opposite. - * - * @since 1.0 - * @version 1.0 - */ -typedef void (*OnJoinLNNResult)(ConnectionAddr *addr, const char *networkId, int32_t retCode); - -/** - * @brief Called when a device is removed from a LNN via {@link LeaveLNN}. - * - * @param networkId Indicates the pointer to the network ID of the device. - * @param retCode Indicates the result code. Value 0 indicates that the device is successfully - * removed from the LNN, and any other value indicates the opposite. - * - * @since 1.0 - * @version 1.0 - */ -typedef void (*OnLeaveLNNResult)(const char *networkId, int32_t retCode); - -/** - * @brief Adds the current device to the LNN where a specified device resides. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param target Indicates the pointer to the address of the specified device. For details, see {@link ConnectionAddr}. - * @param cb Indicates the callback for the result. If you set this parameter to NULL, you will not receive the result. - * - * @return Returns 0 if the request to add the device is accepted, and the result can be obtained from the - * callback; returns any other value if the device fails to be added to the network, in which case you will not receive - * the result. - * - * @since 1.0 - * @version 1.0 - */ -int32_t JoinLNN(const char *pkgName, ConnectionAddr *target, OnJoinLNNResult cb); - -/** - * @brief Removes the current device from the LNN. - * - * @param networkId Indicates the pointer to the network ID that is returned - * after the device is added to the LNN via {@link JoinLNN}. - * @param cb Indicates the callback for the result. If you set this parameter to NULL, - * you will not receive the result. - * - * @return Returns 0 if the request to remove the device is accepted, and the result can be obtained from the - * callback; returns any other value if the device fails to be removed from the network, in which case you will not - * receive the result. - * - * @since 1.0 - * @version 1.0 - */ -int32_t LeaveLNN(const char *pkgName, const char *networkId, OnLeaveLNNResult cb); - -/** - * @brief Registers a callback for device state changes. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param callback Indicates the pointer to the callback to register. For details, see {@link INodeStateCb}. - * - * @return Returns 0 if the registration is successful; returns any other value otherwise. - * - * @since 1.0 - * @version 1.0 - */ -int32_t RegNodeDeviceStateCb(const char *pkgName, INodeStateCb *callback) -{ - (void)pkgName; - (void)callback; - return 0; -}; - -/** - * @brief Unregisters a callback for device state changes. - * - * @param callback Indicates the pointer to the callback to unregister. For details, see {@link INodeStateCb}. - * - * @return Returns 0 if the unregistration is successful; returns any other value otherwise. - * - * @since 1.0 - * @version 1.0 - */ -int32_t UnregNodeDeviceStateCb(INodeStateCb *callback); - -/** - * @brief Obtains basic information about all the online devices. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param info Indicates the double pointer to the memory that stores the obtained basic information. - * @param infoNum Indicates the pointer to the number of devices. - * - * @return Returns 0 if the basic information is obtained, in which case info and infoNum are - * valid; returns any other value otherwise. - * - * @since 1.0 - * @version 1.0 - */ -int32_t GetAllNodeDeviceInfo(const char *pkgName, NodeBasicInfo **info, int32_t *infoNum) -{ - (void)pkgName; - (void)info; - (void)infoNum; - return 0; -}; - -/** - * @brief Releases the memory returned by {@link GetAllNodeDeviceInfo}. - * - * @param info Indicates the pointer to the memory returned by {@link GetAllNodeDeviceInfo}. - * - * @since 1.0 - * @version 1.0 - */ -void FreeNodeInfo(NodeBasicInfo *info); - -/** - * @brief Obtains basic information about the current device. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param info Indicates the double pointer to the memory that stores the obtained basic information. - * - * @return Returns 0 if the basic information is obtained, in which case info is valid; - * returns any other value otherwise. - * - * @since 1.0 - * @version 1.0 - */ -int32_t GetLocalNodeDeviceInfo(const char *pkgName, NodeBasicInfo *info) -{ - strcpy_s(info->networkId, NETWORK_ID_BUF_LEN, "test_networkId"); - strcpy_s(info->deviceName, DEVICE_NAME_BUF_LEN, "test_deviceName"); - info->deviceTypeId = 0; - return 0; -}; - -/** - * @brief Obtains a specified {@link NodeDeviceInfoKey} of an online device. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param networkId Indicates the pointer to the network ID of the device. - * @param key Indicates the key to be obtained. - * @param info Indicates the pointer to the buffer that stores the obtained key. - * @param infoLen Indicates the buffer length. - * - * @return Returns 0 if the {@link NodeDeviceInfoKey} is obtained, in which case info is valid; - * returns any other value otherwise. - * - * @since 1.0 - * @version 1.0 - */ -int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, - NodeDeviceInfoKey key, uint8_t *info, int32_t infoLen) -{ - (void)pkgName; - (void)networkId; - (void)key; - (void)info; - (void)infoLen; - return 0; -}; - -/** - * @brief Start the time synchronize with specific target node. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param targetNetworkId Indicates the pointer to the address of the specified device. - * @param accuracy Time synchronize accuracy. - * @param period Time synchronize period - * @param cb Indicates the callback for the result. - * - * @return Returns 0 if the request is accepted, and the result can be obtained from the - * callback; returns any other value if the request fails, in which case you will not receive - * the result. - * - * @since 1.0 - * @version 1.0 - */ -int32_t StartTimeSync(const char *pkgName, const char *targetNetworkId, TimeSyncAccuracy accuracy, - TimeSyncPeriod period, ITimeSyncCb *cb); - -/** - * @brief Stop the time synchronize with specific target node. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param targetNetworkId Indicates the pointer to the address of the specified device. - * - * @return Returns 0 if the request is removed; returns any other value if the request fails. - * - * @since 1.0 - * @version 1.0 - */ -int32_t StopTimeSync(const char *pkgName, const char *targetNetworkId); - -/** - * @brief Publishes a specified service. - * - * Peer devices in the same LAN as the device that publishes this service can discover this service as needed. - * The service is identified by publicId and pkgName. - * - * @param pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes. - * @param info Indicates the pointer to the service publishing information. For details, see {@link PublishInfo}. - * @param cb Indicates the pointer to the service publishing callback {@link IPublishCallback}. - * @return Returns SOFTBUS_INVALID_PARAM if any parameter is null or invalid. - * @return Returns SOFTBUS_DISCOVER_NOT_INIT if the Intelligent Soft Bus client fails to be initialized. - * @return Returns SOFTBUS_LOCK_ERR if the mutex fails to be locked. - * @return Returns SOFTBUS_OK if the service is successfully published. - */ -int32_t PublishLNN(const char *pkgName, const PublishInfo *info, const IPublishCb *cb); - -/** - * @brief stoppublishes a specified service. - * - * @param pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes. - * @param publishId Indicates the service ID. - * @return Returns SOFTBUS_INVALID_PARAM if pkgName is invalid. - * @return Returns SOFTBUS_DISCOVER_NOT_INIT if the Intelligent Soft Bus client fails to be initialized. - * @return Returns SOFTBUS_OK if the service is successfully unpublished. - */ -int32_t StopPublishLNN(const char *pkgName, int32_t publishId); - -/** - * @brief Subscribes to a specified service. - * - * Information about the device that publishes the service will be reported to the device that subscribes to - * the service. - * The service is identified by subscribeId and pkgName. - * - * @param pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes. - * @param info Indicates the pointer to the service subscription information. For details, see {@link RefreshInfo}. - * @param cb Indicates the service subscription callback {@link IRefreshCallback}. - * @return Returns SOFTBUS_INVALID_PARAM if any parameter is null or invalid. - * @return Returns SOFTBUS_DISCOVER_NOT_INIT if the Intelligent Soft Bus client fails to be initialized. - * @return Returns SOFTBUS_LOCK_ERR if the mutex fails to be locked. - * @return Returns SOFTBUS_OK if the service subscription is successful. - */ -int32_t RefreshLNN(const char *pkgName, const SubscribeInfo *info, const IRefreshCallback *cb); - -/** - * @brief Unsubscribes from a specified service. - * - * @param pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes. - * @param refreshId Indicates the service ID. - * @return Returns SOFTBUS_INVALID_PARAM if pkgName is invalid. - * @return Returns SOFTBUS_DISCOVER_NOT_INIT if the Intelligent Soft Bus client fails to be initialized. - * @return Returns SOFTBUS_OK if the service unsubscription is successful. - */ -int32_t StopRefreshLNN(const char *pkgName, int32_t refreshId); - -/** - * @brief Active meta node. The meta node online status will be notified by {@link INodeStateCb} - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param info Meta node configuration infomation, see {@link MetaNodeConfigInfo}. - * @param metaNodeId Save meta node ID when it is activated successfully, its buffer length must be not - * less then NETWORK_ID_BUF_LEN - * - * @return Returns 0 if the meta node is activated; returns any other value if the request fails. - * - * @since 1.0 - * @version 1.0 - */ -int32_t ActiveMetaNode(const char *pkgName, const MetaNodeConfigInfo *info, char *metaNodeId); - -/** - * @brief Deactive meta node. The meta node will be removed. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param metaNodeId The meta node ID which deactivated, it's obtained by {@link ActiveMetaNode}. - * - * @return Returns 0 if the meta node is deactivated; returns any other value if the request fails. - * - * @since 1.0 - * @version 1.0 - */ -int32_t DeactiveMetaNode(const char *pkgName, const char *metaNodeId); - -/** - * @brief Get all meta node by {@link ActiveMetaNode}. - * - * @param pkgName Indicates the pointer to the caller ID, for example, the package name. - * For the same caller, the value of this parameter must be the same for all functions. - * @param infos The buffer for save meta node info. - * @param infoNum The infos buffer num which maximum is {@link MAX_META_NODE_NUM}. - * - * @return Returns 0 if the call is success; returns any other value if it fails. - * - * @since 1.0 - * @version 1.0 - */ -int32_t GetAllMetaNodeInfo(const char *pkgName, MetaNodeInfo *infos, int32_t *infoNum); - -#ifdef __cplusplus -} -#endif - -#endif -/** @} */ \ No newline at end of file diff --git a/services/source/transport/test/sourcetransunittest/mock/softbus_common.h b/services/source/transport/test/sourcetransunittest/mock/softbus_common.h deleted file mode 100644 index e186fcf..0000000 --- a/services/source/transport/test/sourcetransunittest/mock/softbus_common.h +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @addtogroup SoftBus - * @{ - * - * @brief Provides high-speed, secure communication between devices. - * - * This module implements unified distributed communication capability management between nearby devices, and provides - * link-independent device discovery and transmission interfaces to support service publishing and data transmission. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file softbus_common.h - * - * @brief Declares common APIs for the Intelligent Soft Bus. - * - * This file provides common functions and constants for each submodule of the Intelligent Soft Bus, including: \n - * - *
        - *
      • Constants such as the network ID length
      • - *
      • Functions such as that for initializing the Intelligent Soft Bus client
      • - *
      - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef SOFTBUS_CLIENT_COMMON_H -#define SOFTBUS_CLIENT_COMMON_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Indicates the length of the Bluetooth device MAC address in string format, - * including the terminating null character \0. - * - * @since 1.0 - * @version 1.0 - */ -#define BT_MAC_LEN 18 - -/** - * @brief Indicates the length of the network ID string, including the terminating null character \0. - * - * @since 1.0 - * @version 1.0 - */ -#define NETWORK_ID_BUF_LEN 65 - -/** - * @brief Indicates the length of the UDID string, including the terminating null character \0. - * - * @since 1.0 - * @version 1.0 - */ -#define UDID_BUF_LEN 65 - -/** - * @brief Indicates the length of the UDID hash value. - * - * @since 1.0 - * @version 1.0 - */ -#define UDID_HASH_LEN 32 - -/** - * @brief Indicates the length of the UUID string, including the terminating null character \0. - * - * @since 1.0 - * @version 1.0 - */ -#define UUID_BUF_LEN 65 - -/** - * @brief Indicates the maximum length of an IP address in string format, - * including the terminating null character \0. IPv6 addresses are supported. - * - * @since 1.0 - * @version 1.0 - */ -#define IP_STR_MAX_LEN 46 - -/** - * @brief Indicates the maximum length of the account hash code in IDiscoveryCallback. - * - */ -#define MAX_ACCOUNT_HASH_LEN 96 - -/** - * @brief Indicates the maximum length of the capability data in PublishInfo and SubscribeInfo. - * - */ -#define MAX_CAPABILITYDATA_LEN 513 - -/** - * @brief Indicates the maximum length of the custom data in IDiscoveryCallback. - * - */ -#define DISC_MAX_CUST_DATA_LEN 219 - -/** - * @brief Indicates the maximum number of capabilities contained in the bitmap in IDiscoveryCallback. - * - */ -#define DISC_MAX_CAPABILITY_NUM 2 - -/** - * @brief Indicates the maximum length of the device name in IDiscoveryCallback. - * - */ -#define DISC_MAX_DEVICE_NAME_LEN 65 - -/** - * @brief Indicates the maximum length of the device ID in IDiscoveryCallback. - * - */ -#define DISC_MAX_DEVICE_ID_LEN 96 - -/** - * @brief Enumerates {@link ConnectionAddr} types of a device that is added to a LNN. - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - CONNECTION_ADDR_WLAN = 0, /**< WLAN */ - CONNECTION_ADDR_BR, /**< BR */ - CONNECTION_ADDR_BLE, /**< BLE */ - CONNECTION_ADDR_ETH, /**< Ethernet */ - CONNECTION_ADDR_MAX /**< Invalid type */ -} ConnectionAddrType; -/** - * @brief Defines the address of a device that is added to a LNN. - * For details, see {@link ConnectionAddr}. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - /**< Address type. This field is used to explain the info field. */ - ConnectionAddrType type; - /**< Connection address information */ - union { - /**< BR address */ - struct BrAddr { - char brMac[BT_MAC_LEN]; /**< BR MAC address in string format */ - } br; - /**< BLE address */ - struct BleAddr { - char bleMac[BT_MAC_LEN]; /**< BLE MAC address in string format */ - uint8_t udidHash[UDID_HASH_LEN]; /**< udid hash value */ - } ble; - /**< IPv4 or IPv6 address */ - struct IpAddr { - /** - * IP address in string format. It can be an IPv4 address written in dotted decimal notation - * or an IPv6 address written in hexadecimal colon-separated notation. - */ - char ip[IP_STR_MAX_LEN]; - uint16_t port; /**< Port number represented by the host byte order */ - } ip; - } info; - char peerUid[MAX_ACCOUNT_HASH_LEN]; -} ConnectionAddr; - -/** - * @brief Enumerates the modes in which services are published. - * - */ -typedef enum { - /* Passive */ - DISCOVER_MODE_PASSIVE = 0x55, - /* Proactive */ - DISCOVER_MODE_ACTIVE = 0xAA -} DiscoverMode; - -/** - * @brief Enumerates media, such as Bluetooth, Wi-Fi, and USB, used for publishing services. - * - * Currently, only COAP is supported. - * When AUTO is selected, all the supported media will be called automatically. - */ -typedef enum { - /** Automatic medium selection */ - AUTO = 0, - /** Bluetooth */ - BLE = 1, - /** Wi-Fi */ - COAP = 2, - /** USB */ - USB = 3, - /** HiLink */ - COAP1 = 4, - MEDIUM_BUTT -} ExchanageMedium; - -/** - * @brief Enumerates frequencies for publishing services. - * - * This enumeration applies only to Bluetooth and is not supported currently. - */ -typedef enum { - /** Low */ - LOW = 0, - /** Medium */ - MID = 1, - /** High */ - HIGH = 2, - /** Super-high */ - SUPER_HIGH = 3, - FREQ_BUTT -} ExchangeFreq; - -/** - * @brief Enumerates supported capabilities published by a device. - * - */ -typedef enum { - /** MeeTime */ - HICALL_CAPABILITY_BITMAP = 0, - /** Video reverse connection in the smart domain */ - PROFILE_CAPABILITY_BITMAP = 1, - /** Gallery in Vision */ - HOMEVISIONPIC_CAPABILITY_BITMAP = 2, - /** cast+ */ - CASTPLUS_CAPABILITY_BITMAP, - /** Input method in Vision */ - AA_CAPABILITY_BITMAP, - /** Device virtualization tool package */ - DVKIT_CAPABILITY_BITMAP, - /** Distributed middleware */ - DDMP_CAPABILITY_BITMAP, - /** Osd capability */ - OSD_CAPABILITY_BITMAP -} DataBitMap; - -/** - * @brief Defines the mapping between supported capabilities and bitmaps. - * - */ -typedef struct { - /** Bitmaps. For details, see {@link DataBitMap}. */ - DataBitMap bitmap; - /** Capability. For details, see {@link g_capabilityMap}. */ - char *capability; -} CapabilityMap; - -/** - * @brief Defines the mapping between supported capabilities and bitmaps. - * - */ -static const CapabilityMap g_capabilityMap[] = { - {HICALL_CAPABILITY_BITMAP, (char *)"hicall"}, - {PROFILE_CAPABILITY_BITMAP, (char *)"profile"}, - {HOMEVISIONPIC_CAPABILITY_BITMAP, (char *)"homevisionPic"}, - {CASTPLUS_CAPABILITY_BITMAP, (char *)"castPlus"}, - {AA_CAPABILITY_BITMAP, (char *)"aaCapability"}, - {DVKIT_CAPABILITY_BITMAP, (char *)"dvKit"}, - {DDMP_CAPABILITY_BITMAP, (char *)"ddmpCapability"}, - {OSD_CAPABILITY_BITMAP, (char *)"osdCapability"}, -}; - -/** - * @brief Defines service publishing information. - * - */ -typedef struct { - /** Service ID */ - int publishId; - /** Discovery mode for service publishing. For details, see {@link Discovermode}. */ - DiscoverMode mode; - /** Service publishing medium. For details, see {@link ExchanageMedium}. */ - ExchanageMedium medium; - /** Service publishing frequency. For details, see {@link ExchangeFre}. */ - ExchangeFreq freq; - /** Service publishing capabilities. For details, see {@link g_capabilityMap}. */ - const char *capability; - /** Capability data for service publishing */ - unsigned char *capabilityData; - /** Maximum length of the capability data for service publishing (512 bytes) */ - unsigned int dataLen; -} PublishInfo; - -/** - * @brief Defines service subscription information. - * - */ -typedef struct { - /** Service ID */ - int subscribeId; - /** Discovery mode for service subscription. For details, see {@link Discovermode}. */ - DiscoverMode mode; - /** Service subscription medium. For details, see {@link ExchanageMedium}. */ - ExchanageMedium medium; - /** Service subscription frequency. For details, see {@link ExchangeFre}. */ - ExchangeFreq freq; - /** only find the device with the same account */ - bool isSameAccount; - /** find the sleeping devices */ - bool isWakeRemote; - /** Service subscription capability. For details, see {@link g_capabilityMap}. */ - const char *capability; - /** Capability data for service subscription */ - unsigned char *capabilityData; - /** Maximum length of the capability data for service subscription (512 bytes) */ - unsigned int dataLen; -} SubscribeInfo; - -/** - * @brief Enumerates device types. - * - */ -typedef enum { - /* Smart speaker */ - SMART_SPEAKER = 0x00, - /* PC */ - DESKTOP_PC, - /* Laptop */ - LAPTOP, - /* Mobile phone */ - SMART_PHONE, - /* Tablet */ - SMART_PAD, - /* Smart watch */ - SMART_WATCH, - /* Smart car */ - SMART_CAR, - /* Kids' watch */ - CHILDREN_WATCH, - /* Smart TV */ - SMART_TV, -} DeviceType; - -/** - * @brief Defines the device information returned by IDiscoveryCallback. - * - */ -typedef struct { - /** Device ID. Its maximum length is specified by {@link DISC_MAX_DEVICE_ID_LEN}. */ - char devId[DISC_MAX_DEVICE_ID_LEN]; - /** Account hash code. Its maximum length is specified by {@link MAX_ACCOUNT_HASH_LEN}. */ - char accountHash[MAX_ACCOUNT_HASH_LEN]; - /** Device type. For details, see {@link DeviceType}. */ - DeviceType devType; - /** Device name. Its maximum length is specified by {@link DISC_MAX_DEVICE_NAME_LEN}. */ - char devName[DISC_MAX_DEVICE_NAME_LEN]; - /** Number of available connections */ - unsigned int addrNum; - /** Connection information. For details, see {@link ConnectAddr}. */ - ConnectionAddr addr[CONNECTION_ADDR_MAX]; - /** Number of capabilities */ - unsigned int capabilityBitmapNum; - /** Device capability bitmap. - * The maximum number of capabilities in the bitmap is specified by {@link DISC_MAX_CAPABILITY_NUM}. - */ - unsigned int capabilityBitmap[DISC_MAX_CAPABILITY_NUM]; - /** Custom data. Its length is specified by {@link DISC_MAX_CUST_DATA_LEN}. */ - char custData[DISC_MAX_CUST_DATA_LEN]; -} DeviceInfo; -#ifdef __cplusplus -} -#endif -#endif -/** @} */ diff --git a/sinkhandler/BUILD.gn b/sinkhandler/BUILD.gn deleted file mode 100644 index 1d71eb8..0000000 --- a/sinkhandler/BUILD.gn +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//foundation/distributedhardware/distributedinput/distributedinput.gni") - -ohos_shared_library("libdinput_sink_handler") { - include_dirs = [ - "include", - "${innerkits_path}/include", - "${innerkits_path}/src", - "${ipc_path}/include", - "${ipc_path}/src", - "${services_sink_path}/sinkmanager/include", - "${frameworks_path}/include", - "${service_common}/include", - "${common_path}/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - ] - - sources = [ - "src/distributed_input_sink_handler.cpp", - "src/load_d_input_sink_callback.cpp" - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedinputsinkhandler\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "//foundation/bundlemanager/bundle_framework/interfaces/innerkits/libeventhandler:libeventhandler", - "//utils/native/base:utils", - "${fwk_utils_path}:distributedhardwareutils", - "${innerkits_path}:libdinput_sdk", - "${services_sink_path}/sinkmanager:libdinput_sink", - ] - - external_deps = [ - "ipc:ipc_core", - "safwk:system_ability_fwk", - "hiviewdfx_hilog_native:libhilog", - "samgr_standard:samgr_proxy", - ] - - cflags_cc = [ "-DHILOG_ENABLE" ] - - subsystem_name = "distributedhardware" - - part_name = "distributed_input" - -} diff --git a/sinkhandler/include/distributed_input_sink_handler.h b/sinkhandler/include/distributed_input_sink_handler.h deleted file mode 100644 index 6f27bc9..0000000 --- a/sinkhandler/include/distributed_input_sink_handler.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISTRIBUTED_INPUT_SINK_HANDLER_H -#define DISTRIBUTED_INPUT_SINK_HANDLER_H - -#include -#include -#include - -#include "idistributed_hardware_sink.h" -#include "iservice_registry.h" -#include "single_instance.h" -#include "system_ability_definition.h" -#include "system_ability_load_callback_stub.h" - -#include "distributed_input_client.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputSinkHandler : public IDistributedHardwareSink { -DECLARE_SINGLE_INSTANCE_BASE(DistributedInputSinkHandler); -public: - int32_t InitSink(const std::string& params) override; - int32_t ReleaseSink() override; - int32_t SubscribeLocalHardware(const std::string& dhId, const std::string& parameters) override; - int32_t UnsubscribeLocalHardware(const std::string& dhId) override; - void FinishStartSA(const std::string ¶ms, const sptr &remoteObject); - -public: - class SALoadSinkCb : public OHOS::SystemAbilityLoadCallbackStub { - public: - void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const OHOS::sptr& remoteObject) override; - - void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; - - int32_t GetSystemAbilityId() const - { - return currSystemAbilityId; - } - - OHOS::sptr GetRemoteObject() const - { - return currRemoteObject; - } - private: - int32_t currSystemAbilityId = 0; - OHOS::sptr currRemoteObject; - }; - -private: - DistributedInputSinkHandler() = default; - ~DistributedInputSinkHandler(); - OHOS::sptr sysSinkCallback = nullptr; - - std::mutex proxyMutex_; - std::condition_variable proxyConVar_; -}; - -#ifdef __cplusplus -extern "C" { -#endif -__attribute__((visibility("default"))) IDistributedHardwareSink *GetSinkHardwareHandler(); -#ifdef __cplusplus -} -#endif -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - -#endif // DISTRIBUTED_INPUT_SINK_HANDLER_H diff --git a/sinkhandler/include/load_d_input_sink_callback.h b/sinkhandler/include/load_d_input_sink_callback.h deleted file mode 100644 index 580447a..0000000 --- a/sinkhandler/include/load_d_input_sink_callback.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LOAD_D_INPUT_SOURCE_CALLBACK_H -#define LOAD_D_INPUT_SOURCE_CALLBACK_H - -#include "system_ability_load_callback_stub.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class LoadDInputSinkCallback : public SystemAbilityLoadCallbackStub { -public: - explicit LoadDInputSinkCallback(const std::string ¶ms); - void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const sptr &remoteObject) override; - void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; -private: - std::string params_; -}; -} -} -} -#endif \ No newline at end of file diff --git a/sinkhandler/src/distributed_input_sink_handler.cpp b/sinkhandler/src/distributed_input_sink_handler.cpp deleted file mode 100644 index e0d23fc..0000000 --- a/sinkhandler/src/distributed_input_sink_handler.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_input_sink_handler.h" - -#include "distributed_hardware_log.h" - -#include "dinput_errcode.h" -#include "i_distributed_sink_input.h" -#include "load_d_input_sink_callback.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -IMPLEMENT_SINGLE_INSTANCE(DistributedInputSinkHandler); - -DistributedInputSinkHandler::~DistributedInputSinkHandler() -{ - DHLOGI("~DistributedInputSinkHandler"); -} - -int32_t DistributedInputSinkHandler::InitSink(const std::string ¶ms) -{ - DHLOGD("InitSource"); - std::unique_lock lock(proxyMutex_); - if (!DistributedInputClient::GetInstance().HasDInputSinkProxy()) { - sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (!samgr) { - DHLOGE("Failed to get system ability mgr."); - return ERR_DH_INPUT_SINK_HANDLER_INIT_SINK_SA_FAIL; - } - sptr loadCallback = new LoadDInputSinkCallback(params); - int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID, loadCallback); - if (ret != ERR_OK) { - DHLOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d", - DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID, ret); - return ERR_DH_INPUT_SINK_HANDLER_INIT_SINK_SA_FAIL; - } - } - - auto waitStatus = proxyConVar_.wait_for(lock, std::chrono::milliseconds(INPUT_LOADSA_TIMEOUT_MS), - [this]() { return (DistributedInputClient::GetInstance().HasDInputSinkProxy()); }); - if (!waitStatus) { - DHLOGE("dinput load sa timeout."); - return ERR_DH_INPUT_SINK_HANDLER_INIT_SINK_SA_FAIL; - } - - return DH_SUCCESS; -} - -void DistributedInputSinkHandler::FinishStartSA(const std::string ¶ms, const sptr &remoteObject) -{ - DHLOGD("FinishStartSA"); - std::unique_lock lock(proxyMutex_); - DistributedInputClient::GetInstance().SetDInputSinkProxy(remoteObject); - DistributedInputClient::GetInstance().InitSink(); - proxyConVar_.notify_all(); -} - -int32_t DistributedInputSinkHandler::ReleaseSink() -{ - return DistributedInputClient::GetInstance().ReleaseSink(); -} - -int32_t DistributedInputSinkHandler::SubscribeLocalHardware(const std::string &dhId, const std::string ¶ms) -{ - return DH_SUCCESS; -} - -int32_t DistributedInputSinkHandler::UnsubscribeLocalHardware(const std::string &dhId) -{ - return DH_SUCCESS; -} - -void DistributedInputSinkHandler::SALoadSinkCb::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const OHOS::sptr& remoteObject) -{ - currSystemAbilityId = systemAbilityId; - currRemoteObject = remoteObject; - DHLOGI("DistributedInputSinkHandler OnLoadSystemAbilitySuccess. systemAbilityId=%d", systemAbilityId); -} - -void DistributedInputSinkHandler::SALoadSinkCb::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - currSystemAbilityId = systemAbilityId; - DHLOGE("DistributedInputSinkHandler OnLoadSystemAbilityFail. systemAbilityId=%d", systemAbilityId); -} - -IDistributedHardwareSink *GetSinkHardwareHandler() -{ - return &DistributedInputSinkHandler::GetInstance(); -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/sinkhandler/src/load_d_input_sink_callback.cpp b/sinkhandler/src/load_d_input_sink_callback.cpp deleted file mode 100644 index 82ef4f8..0000000 --- a/sinkhandler/src/load_d_input_sink_callback.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_hardware_log.h" - -#include "distributed_input_sink_handler.h" -#include "load_d_input_sink_callback.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { - LoadDInputSinkCallback::LoadDInputSinkCallback(const std::string ¶ms) : params_(params) {} - -void LoadDInputSinkCallback::OnLoadSystemAbilitySuccess( - int32_t systemAbilityId, const sptr &remoteObject) -{ - DHLOGI("load dinput SA success, systemAbilityId:%d, remoteObject result:%s", - systemAbilityId, (remoteObject != nullptr) ? "true" : "false"); - if (remoteObject == nullptr) { - DHLOGE("remoteObject is nullptr"); - return; - } - DistributedInputSinkHandler::GetInstance().FinishStartSA(params_, remoteObject); -} - -void LoadDInputSinkCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - DHLOGE("load dinput SA failed, systemAbilityId:%d", systemAbilityId); -} -} -} -} diff --git a/sinkhandler/test/BUILD.gn b/sinkhandler/test/BUILD.gn deleted file mode 100644 index e75f084..0000000 --- a/sinkhandler/test/BUILD.gn +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -group("test") { - testonly = true - - deps = [ "unittest:unittest" ] -} diff --git a/sinkhandler/test/unittest/BUILD.gn b/sinkhandler/test/unittest/BUILD.gn deleted file mode 100644 index ecf99cd..0000000 --- a/sinkhandler/test/unittest/BUILD.gn +++ /dev/null @@ -1,86 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/test.gni") -import("//foundation/distributedhardware/distributedinput/distributedinput.gni") -module_out_path = "distributedinput_stander/sink_handler" - -group("unittest") { - testonly = true - - deps = [ ":distributed_input_sink_handler_test" ] -} - -## UnitTest distributed_input_manager_service_test {{{ -ohos_unittest("distributed_input_sink_handler_test") { - module_out_path = module_out_path - - include_dirs = [ - "${distributedinput_path}/sinkhandler/include", - "${innerkits_path}/include", - "${innerkits_path}/src", - "${ipc_path}/include", - "${ipc_path}/src", - "${services_sink_path}/sinkmanager/include", - "${frameworks_path}/include", - "${service_common}/include", - "${common_path}/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "//third_party/json/include", - ] - - sources = [ - "//foundation/distributedhardware/distributedinput/sinkhandler/src/distributed_input_sink_handler.cpp", - "//foundation/distributedhardware/distributedinput/sinkhandler/src/load_d_input_sink_callback.cpp", - "distributed_input_sinkhandler_test.cpp", - "//foundation/distributedhardware/distributedinput/sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp", - ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", - "-Dprivate=public", - "-Dprotected=public", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedinpututtest\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "//foundation/bundlemanager/bundle_framework/interfaces/innerkits/libeventhandler:libeventhandler", - "//utils/native/base:utils", - "${fwk_utils_path}:distributedhardwareutils", - "${innerkits_path}:libdinput_sdk", - "${services_source_path}/sourcemanager:libdinput_source", - ] - - external_deps = [ - "ipc:ipc_core", - "safwk:system_ability_fwk", - "hiviewdfx_hilog_native:libhilog", - "samgr_standard:samgr_proxy", - ] - - cflags_cc = [ "-DHILOG_ENABLE" ] -} - -## UnitTest distributed_input_manager_service_test }}} diff --git a/sinkhandler/test/unittest/distributed_input_sinkhandler_test.cpp b/sinkhandler/test/unittest/distributed_input_sinkhandler_test.cpp deleted file mode 100644 index 8a45bd1..0000000 --- a/sinkhandler/test/unittest/distributed_input_sinkhandler_test.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_input_sinkhandler_test.h" - -using namespace testing::ext; -using namespace OHOS::DistributedHardware::DistributedInput; -using namespace std; - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -void DistributedInputSinkHandlerTest::SetUp() -{ -} - -void DistributedInputSinkHandlerTest::TearDown() -{ -} - -void DistributedInputSinkHandlerTest::SetUpTestCase() -{ -} - -void DistributedInputSinkHandlerTest::TearDownTestCase() -{ -} - -HWTEST_F(DistributedInputSinkHandlerTest, InitSink01, testing::ext::TestSize.Level0) -{ - int32_t ret = DistributedInputSinkHandler::GetInstance().InitSink("params"); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSinkHandlerTest, InitSink02, testing::ext::TestSize.Level0) -{ - std::string params = ""; - int32_t ret = DistributedInputSinkHandler::GetInstance().InitSink(params); - EXPECT_EQ(SUCCESS, ret); -} -HWTEST_F(DistributedInputSinkHandlerTest, InitSink03, testing::ext::TestSize.Level0) -{ - std::string params = "params"; - int32_t ret = DistributedInputSinkHandler::GetInstance().InitSink(params); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSinkHandlerTest, ReleaseSink01, testing::ext::TestSize.Level0) -{ - int32_t ret = DistributedInputSinkHandler::GetInstance().ReleaseSink(); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSinkHandlerTest, SubscribeLocalHardware01, testing::ext::TestSize.Level0) -{ - int32_t ret = DistributedInputSinkHandler::GetInstance().SubscribeLocalHardware("dhId", "params"); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSinkHandlerTest, SubscribeLocalHardware02, testing::ext::TestSize.Level0) -{ - std::string dhId = "SubscribeLocalHardware02"; - std::string params = "test2"; - int32_t ret = DistributedInputSinkHandler::GetInstance().SubscribeLocalHardware(dhId, params); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSinkHandlerTest, SubscribeLocalHardware03, testing::ext::TestSize.Level0) -{ - std::string dhId = "SubscribeLocalHardware03"; - std::string params = "test3"; - int32_t ret = DistributedInputSinkHandler::GetInstance().SubscribeLocalHardware(dhId, params); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSinkHandlerTest, UnsubscribeLocalHardware01, testing::ext::TestSize.Level0) -{ - int32_t ret = DistributedInputSinkHandler::GetInstance().UnsubscribeLocalHardware("dhId"); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSinkHandlerTest, UnsubscribeLocalHardware02, testing::ext::TestSize.Level0) -{ - std::string dhId = "UnsubscribeLocalHardware02"; - int32_t ret = DistributedInputSinkHandler::GetInstance().UnsubscribeLocalHardware(dhId); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSinkHandlerTest, UnsubscribeLocalHardware03, testing::ext::TestSize.Level0) -{ - std::string dhId = "UnsubscribeLocalHardware03"; - int32_t ret = DistributedInputSinkHandler::GetInstance().UnsubscribeLocalHardware(dhId); - EXPECT_EQ(SUCCESS, ret); -} -} -} -} \ No newline at end of file diff --git a/sinkhandler/test/unittest/distributed_input_sinkhandler_test.h b/sinkhandler/test/unittest/distributed_input_sinkhandler_test.h deleted file mode 100644 index 5da4c69..0000000 --- a/sinkhandler/test/unittest/distributed_input_sinkhandler_test.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISRIBUTED_INPUT_SINKHANDLER_TEST_H -#define DISRIBUTED_INPUT_SINKHANDLER_TEST_H - -#include - -#include - -#include "system_ability_load_callback_stub.h" - -#include "constants_dinput.h" -#include "distributed_input_sink_handler.h" -#include "i_distributed_sink_input.h" -#include "register_d_input_call_back_stub.h" -#include "unregister_d_input_call_back_stub.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputSinkHandlerTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; - int32_t CheckSystemAbility(); -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS -#endif // DISRIBUTED_INPUT_SINKHANDLER_TEST_H diff --git a/sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp b/sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp deleted file mode 100644 index f5a9929..0000000 --- a/sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_hardware_log.h" -#include "nlohmann/json.hpp" - -#include "constants_dinput.h" -#include "distributed_input_client.h" -#include "white_list_util.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -DistributedInputClient &DistributedInputClient::GetInstance() -{ - static DistributedInputClient instance; - return instance; -} - -void DistributedInputClient::RegisterDInputCb::OnResult( - const std::string& devId, const std::string& dhId, const int32_t& status) -{ - for (std::vector::iterator iter = - DistributedInputClient::GetInstance().dHardWareFwkRstInfos.begin(); - iter != DistributedInputClient::GetInstance().dHardWareFwkRstInfos.end(); - iter++) { - if (iter->devId == devId && iter->dhId == dhId) { - iter->callback->OnRegisterResult(devId, dhId, status, ""); - DistributedInputClient::GetInstance().dHardWareFwkRstInfos.erase(iter); - return; - } - } -} - -void DistributedInputClient::UnregisterDInputCb::OnResult( - const std::string& devId, const std::string& dhId, const int32_t& status) - -{ - for (std::vector::iterator iter = - DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.begin(); - iter != DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.end(); - iter++) { - if (iter->devId == devId && iter->dhId == dhId) { - iter->callback->OnUnregisterResult(devId, dhId, status, ""); - DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.erase(iter); - return; - } - } -} - -void DistributedInputClient::StartDInputServerCb::OnResult(const int32_t& status, const uint32_t& inputTypes) -{ - if (DInputServerType::SOURCE_SERVER_TYPE == static_cast(status)) { - DistributedInputClient::GetInstance().serverType = DInputServerType::SOURCE_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes = inputTypes; - } else if (DInputServerType::SINK_SERVER_TYPE == static_cast(status)) { - DistributedInputClient::GetInstance().serverType = DInputServerType::SINK_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes = inputTypes; - } else { - DistributedInputClient::GetInstance().serverType = DInputServerType::NULL_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes = INPUT_TYPE_NULL; - } -} - -void DistributedInputClient::AddWhiteListInfosCb::OnResult(const std::string &deviceId, const std::string &strJson) -{ - nlohmann::json inputData = nlohmann::json::parse(strJson); - int jsonSize = inputData.size(); - DHLOGI("AddWhiteListInfosCb OnResult json size:%d.\n", jsonSize); - TYPE_WHITE_LIST_VEC vecWhiteList = inputData; - WhiteListUtil::GetInstance().SyncWhiteList(deviceId, vecWhiteList); -} - -void DistributedInputClient::DelWhiteListInfosCb::OnResult(const std::string& deviceId) -{ - WhiteListUtil::GetInstance().ClearWhiteList(deviceId); -} - -int32_t DistributedInputClient::InitSource() -{ - return SUCCESS; -} - -int32_t DistributedInputClient::InitSink() -{ - return SUCCESS; -} - -int32_t DistributedInputClient::ReleaseSource() -{ - return SUCCESS; -} - -int32_t DistributedInputClient::ReleaseSink() -{ - return SUCCESS; -} - -int32_t DistributedInputClient::RegisterDistributedHardware(const std::string& devId, const std::string& dhId, - const std::string& parameters, const std::shared_ptr& callback) -{ - return SUCCESS; -} - -int32_t DistributedInputClient::UnregisterDistributedHardware(const std::string& devId, const std::string& dhId, - const std::shared_ptr& callback) -{ - return SUCCESS; -} - -int32_t DistributedInputClient::PrepareRemoteInput( - const std::string& deviceId, sptr callback) -{ - return SUCCESS; -} - -int32_t DistributedInputClient::UnprepareRemoteInput( - const std::string& deviceId, sptr callback) -{ - return SUCCESS; -} - -int32_t DistributedInputClient::StartRemoteInput( - const std::string& deviceId, const uint32_t& inputTypes, sptr callback) -{ - return SUCCESS; -} - -int32_t DistributedInputClient::StopRemoteInput( - const std::string& deviceId, const uint32_t& inputTypes, sptr callback) -{ - return SUCCESS; -} - -bool DistributedInputClient::IsNeedFilterOut(const std::string& deviceId, const BusinessEvent& event) -{ - return true; -} - -DInputServerType DistributedInputClient::IsStartDistributedInput(const uint32_t& inputType) -{ - return serverType; -} - -bool DistributedInputClient::GetDInputSourceProxy() -{ - return true; -} - -bool DistributedInputClient::GetDInputSinkProxy() -{ - return true; -} - -bool DistributedInputClient::IsJsonData(std::string strData) const -{ - return true; -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/sourcehandler/BUILD.gn b/sourcehandler/BUILD.gn deleted file mode 100644 index 9433d90..0000000 --- a/sourcehandler/BUILD.gn +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//foundation/distributedhardware/distributedinput/distributedinput.gni") - -ohos_shared_library("libdinput_source_handler") { - include_dirs = [ - "include", - "${innerkits_path}/include", - "${innerkits_path}/src", - "${ipc_path}/include", - "${ipc_path}/src", - "${services_source_path}/sourcemanager/include", - "${frameworks_path}/include", - "${service_common}/include", - "${common_path}/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - ] - - sources = [ - "src/distributed_input_source_handler.cpp", - "src/load_d_input_source_callback.cpp" - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedinputsourcehandler\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "//foundation/bundlemanager/bundle_framework/interfaces/innerkits/libeventhandler:libeventhandler", - "//utils/native/base:utils", - "${fwk_utils_path}:distributedhardwareutils", - "${innerkits_path}:libdinput_sdk", - "${services_source_path}/sourcemanager:libdinput_source", - ] - - external_deps = [ - "ipc:ipc_core", - "safwk:system_ability_fwk", - "hiviewdfx_hilog_native:libhilog", - "samgr_standard:samgr_proxy", - ] - - cflags_cc = [ "-DHILOG_ENABLE" ] - - subsystem_name = "distributedhardware" - - part_name = "distributed_input" - -} diff --git a/sourcehandler/include/distributed_input_source_handler.h b/sourcehandler/include/distributed_input_source_handler.h deleted file mode 100644 index 4b904ab..0000000 --- a/sourcehandler/include/distributed_input_source_handler.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISTRIBUTED_INPUT_SOURCE_HANDLER_H -#define DISTRIBUTED_INPUT_SOURCE_HANDLER_H - -#include -#include -#include - -#include "idistributed_hardware_source.h" -#include "iservice_registry.h" -#include "single_instance.h" -#include "system_ability_load_callback_stub.h" -#include "system_ability_definition.h" - -#include "distributed_input_client.h" -#include "distributed_input_source_manager.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputSourceHandler : public IDistributedHardwareSource { -DECLARE_SINGLE_INSTANCE_BASE(DistributedInputSourceHandler); -public: - int32_t InitSource(const std::string& params) override; - int32_t ReleaseSource() override; - int32_t RegisterDistributedHardware(const std::string& devId, const std::string& dhId, - const EnableParam& param, std::shared_ptr callback) override; - int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId, - std::shared_ptr callback) override; - int32_t ConfigDistributedHardware(const std::string& devId, const std::string& dhId, const std::string& key, - const std::string& value) override; - void FinishStartSA(const std::string ¶ms, const sptr &remoteObject); - -public: - - class SALoadSourceCb : public OHOS::SystemAbilityLoadCallbackStub { - public: - void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const OHOS::sptr& remoteObject) override; - - void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; - - int32_t GetSystemAbilityId() const - { - return currSystemAbilityId; - } - - OHOS::sptr GetRemoteObject() const - { - return currRemoteObject; - } - private: - int32_t currSystemAbilityId = 0; - OHOS::sptr currRemoteObject; - }; -private: - DistributedInputSourceHandler() = default; - ~DistributedInputSourceHandler(); - OHOS::sptr sysSourceCallback = nullptr; - - std::mutex proxyMutex_; - std::condition_variable proxyConVar_; -}; - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus -__attribute__((visibility("default"))) IDistributedHardwareSource *GetSourceHardwareHandler(); -#ifdef __cplusplus -} -#endif // __cplusplus -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - -#endif // DISTRIBUTED_INPUT_SOURCE_HANDLER_H diff --git a/sourcehandler/include/load_d_input_source_callback.h b/sourcehandler/include/load_d_input_source_callback.h deleted file mode 100644 index b14f791..0000000 --- a/sourcehandler/include/load_d_input_source_callback.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LOAD_D_INPUT_SOURCE_CALLBACK_H -#define LOAD_D_INPUT_SOURCE_CALLBACK_H - -#include "system_ability_load_callback_stub.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class LoadDInputSourceCallback : public SystemAbilityLoadCallbackStub { -public: - explicit LoadDInputSourceCallback(const std::string ¶ms); - void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr &remoteObject) override; - void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; -private: - std::string params_; -}; -} -} -} -#endif \ No newline at end of file diff --git a/sourcehandler/src/distributed_input_source_handler.cpp b/sourcehandler/src/distributed_input_source_handler.cpp deleted file mode 100644 index 0e0e27e..0000000 --- a/sourcehandler/src/distributed_input_source_handler.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_input_source_handler.h" - -#include "distributed_hardware_log.h" - -#include "dinput_errcode.h" -#include "i_distributed_source_input.h" -#include "load_d_input_source_callback.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -IMPLEMENT_SINGLE_INSTANCE(DistributedInputSourceHandler); - -DistributedInputSourceHandler::~DistributedInputSourceHandler() -{ -} - -int32_t DistributedInputSourceHandler::InitSource(const std::string ¶ms) -{ - DHLOGD("InitSource"); - std::unique_lock lock(proxyMutex_); - if (!DistributedInputClient::GetInstance().HasDInputSourceProxy()) { - sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (!samgr) { - DHLOGE("Failed to get system ability mgr."); - return ERR_DH_INPUT_SINK_HANDLER_INIT_SOURCE_SA_FAIL; - } - sptr loadCallback = new LoadDInputSourceCallback(params); - int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, loadCallback); - if (ret != ERR_OK) { - DHLOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d", - DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, ret); - return ERR_DH_INPUT_SINK_HANDLER_INIT_SOURCE_SA_FAIL; - } - } - - auto waitStatus = proxyConVar_.wait_for(lock, std::chrono::milliseconds(INPUT_LOADSA_TIMEOUT_MS), - [this]() { return (DistributedInputClient::GetInstance().HasDInputSourceProxy()); }); - if (!waitStatus) { - DHLOGE("dinput load sa timeout."); - return ERR_DH_INPUT_SINK_HANDLER_INIT_SOURCE_SA_FAIL; - } - - return DH_SUCCESS; -} - -void DistributedInputSourceHandler::FinishStartSA(const std::string ¶ms, const sptr &remoteObject) -{ - DHLOGD("FinishStartSA"); - std::unique_lock lock(proxyMutex_); - DistributedInputClient::GetInstance().SetDInputSourceProxy(remoteObject); - DistributedInputClient::GetInstance().InitSource(); - proxyConVar_.notify_all(); -} - -int32_t DistributedInputSourceHandler::ReleaseSource() -{ - return DistributedInputClient::GetInstance().ReleaseSource(); -} - -int32_t DistributedInputSourceHandler::RegisterDistributedHardware(const std::string &devId, - const std::string &dhId, const EnableParam ¶m, std::shared_ptr callback) -{ - return DistributedInputClient::GetInstance().RegisterDistributedHardware(devId, dhId, param.attrs, callback); -} - -int32_t DistributedInputSourceHandler::UnregisterDistributedHardware(const std::string &devId, - const std::string &dhId, std::shared_ptr callback) -{ - return DistributedInputClient::GetInstance().UnregisterDistributedHardware(devId, dhId, callback); -} - -int32_t DistributedInputSourceHandler::ConfigDistributedHardware(const std::string &devId, - const std::string &dhId, const std::string &key, const std::string &value) -{ - return DH_SUCCESS; -} - -void DistributedInputSourceHandler::SALoadSourceCb::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const OHOS::sptr& remoteObject) -{ - currSystemAbilityId = systemAbilityId; - currRemoteObject = remoteObject; - DHLOGI("DistributedInputSourceHandler OnLoadSystemAbilitySuccess. systemAbilityId=%d", systemAbilityId); -} - -void DistributedInputSourceHandler::SALoadSourceCb::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - currSystemAbilityId = systemAbilityId; - DHLOGE("DistributedInputSourceHandler OnLoadSystemAbilityFail. systemAbilityId=%d", systemAbilityId); -} - -IDistributedHardwareSource *GetSourceHardwareHandler() -{ - return &DistributedInputSourceHandler::GetInstance(); -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/sourcehandler/src/load_d_input_source_callback.cpp b/sourcehandler/src/load_d_input_source_callback.cpp deleted file mode 100644 index 815f4da..0000000 --- a/sourcehandler/src/load_d_input_source_callback.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "load_d_input_source_callback.h" - -#include "distributed_hardware_log.h" - -#include "distributed_input_source_handler.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -LoadDInputSourceCallback::LoadDInputSourceCallback(const std::string ¶ms) : params_(params) {} - -void LoadDInputSourceCallback::OnLoadSystemAbilitySuccess( - int32_t systemAbilityId, const sptr &remoteObject) -{ - DHLOGI("load dinput SA success, systemAbilityId:%d, remoteObject result:%s", - systemAbilityId, (remoteObject != nullptr) ? "true" : "false"); - if (remoteObject == nullptr) { - DHLOGE("remoteObject is nullptr"); - return; - } - DistributedInputSourceHandler::GetInstance().FinishStartSA(params_, remoteObject); -} - -void LoadDInputSourceCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - DHLOGE("load dinput SA failed, systemAbilityId:%d", systemAbilityId); -} -} -} -} diff --git a/sourcehandler/test/BUILD.gn b/sourcehandler/test/BUILD.gn deleted file mode 100644 index e75f084..0000000 --- a/sourcehandler/test/BUILD.gn +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -group("test") { - testonly = true - - deps = [ "unittest:unittest" ] -} diff --git a/sourcehandler/test/unittest/BUILD.gn b/sourcehandler/test/unittest/BUILD.gn deleted file mode 100644 index 4168bd4..0000000 --- a/sourcehandler/test/unittest/BUILD.gn +++ /dev/null @@ -1,86 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/test.gni") -import("//foundation/distributedhardware/distributedinput/distributedinput.gni") -module_out_path = "distributedinput_stander/source_handler" - -group("unittest") { - testonly = true - - deps = [ ":distributed_input_source_handler_test" ] -} - -## UnitTest distributed_input_manager_service_test {{{ -ohos_unittest("distributed_input_source_handler_test") { - module_out_path = module_out_path - - include_dirs = [ - "${distributedinput_path}/sourcehandler/include", - "${innerkits_path}/include", - "${innerkits_path}/src", - "${ipc_path}/include", - "${ipc_path}/src", - "${services_source_path}/sourcemanager/include", - "${frameworks_path}/include", - "${service_common}/include", - "${common_path}/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "//third_party/json/include", - ] - - sources = [ - "//foundation/distributedhardware/distributedinput/sourcehandler/src/distributed_input_source_handler.cpp", - "//foundation/distributedhardware/distributedinput/sourcehandler/src/load_d_input_source_callback.cpp", - "distributed_input_sourcehandler_test.cpp", - "//foundation/distributedhardware/distributedinput/sourcehandler/test/unittest/mock/mock_distributed_input_client.cpp", - ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", - "-Dprivate=public", - "-Dprotected=public", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedinpututtest\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "//foundation/bundlemanager/bundle_framework/interfaces/innerkits/libeventhandler:libeventhandler", - "//utils/native/base:utils", - "${fwk_utils_path}:distributedhardwareutils", - "${innerkits_path}:libdinput_sdk", - "${services_source_path}/sourcemanager:libdinput_source", - ] - - external_deps = [ - "ipc:ipc_core", - "safwk:system_ability_fwk", - "hiviewdfx_hilog_native:libhilog", - "samgr_standard:samgr_proxy", - ] - - cflags_cc = [ "-DHILOG_ENABLE" ] -} - -## UnitTest distributed_input_manager_service_test }}} diff --git a/sourcehandler/test/unittest/distributed_input_sourcehandler_test.cpp b/sourcehandler/test/unittest/distributed_input_sourcehandler_test.cpp deleted file mode 100644 index 81bcf97..0000000 --- a/sourcehandler/test/unittest/distributed_input_sourcehandler_test.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_input_sourcehandler_test.h" - -using namespace testing::ext; -using namespace OHOS::DistributedHardware::DistributedInput; -using namespace std; - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -void DistributedInputSourceHandlerTest::SetUp() -{ -} - -void DistributedInputSourceHandlerTest::TearDown() -{ -} - -void DistributedInputSourceHandlerTest::SetUpTestCase() -{ -} - -void DistributedInputSourceHandlerTest::TearDownTestCase() -{ -} - -int32_t DistributedInputSourceHandlerTest::TestRegisterDInputCallback::OnRegisterResult(const std::string &devId, - const std::string &dhId, int32_t status, const std::string &data) -{ - std::cout << "OnRegisterResult" << std::endl; - return SUCCESS; -} - -int32_t DistributedInputSourceHandlerTest::TestUnregisterDInputCallback::OnUnregisterResult(const std::string &devId, - const std::string &dhId, int32_t status, const std::string &data) -{ - std::cout << "OnUnregisterResult" << std::endl; - return SUCCESS; -} - -HWTEST_F(DistributedInputSourceHandlerTest, InitSource01, testing::ext::TestSize.Level0) -{ - int32_t ret = DistributedInputSourceHandler::GetInstance().InitSource(""); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceHandlerTest, InitSource02, testing::ext::TestSize.Level0) -{ - std::string dhId = "test"; - int32_t ret = DistributedInputSourceHandler::GetInstance().InitSource(dhId); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceHandlerTest, ReleaseSource01, testing::ext::TestSize.Level0) -{ - int32_t ret = DistributedInputSourceHandler::GetInstance().ReleaseSource(); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceHandlerTest, RegisterDistributedHardware01, testing::ext::TestSize.Level0) -{ - std::shared_ptr registerCallback = std::make_shared(); - int32_t ret = DistributedInputSourceHandler::GetInstance().RegisterDistributedHardware( - "devId", - "dhId", - OHOS::DistributedHardware::EnableParam { - "version", "attrs" - }, - registerCallback); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceHandlerTest, RegisterDistributedHardware02, testing::ext::TestSize.Level0) -{ - std::cout << "RegisterDistributedHardware02"<< std::endl; - std::shared_ptr registerCallback = nullptr; - std::string devId = ""; - std::string dhId = ""; - int32_t ret = DistributedInputSourceHandler::GetInstance().RegisterDistributedHardware( - devId, dhId, OHOS::DistributedHardware::EnableParam {"version", "attrs" }, registerCallback); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceHandlerTest, RegisterDistributedHardware03, testing::ext::TestSize.Level0) -{ - std::cout << "RegisterDistributedHardware03"<< std::endl; - std::shared_ptr registerCallback = std::make_shared(); - int32_t ret = DistributedInputSourceHandler::GetInstance().RegisterDistributedHardware( - "devId", - "dhId", - OHOS::DistributedHardware::EnableParam { - "version", "attrs" - }, - registerCallback); - EXPECT_EQ(SUCCESS, ret); -} -HWTEST_F(DistributedInputSourceHandlerTest, UnregisterDistributedHardware01, testing::ext::TestSize.Level0) -{ - std::cout << "UnregisterDistributedHardware01"<< std::endl; - std::shared_ptr unregisterDInputCallback = - std::make_shared(); - int32_t ret = DistributedInputSourceHandler::GetInstance().UnregisterDistributedHardware("devId", - "dhId", unregisterDInputCallback); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceHandlerTest, UnregisterDistributedHardware02, testing::ext::TestSize.Level0) -{ - std::shared_ptr unregisterDInputCallback = nullptr; - std::string devId = ""; - std::string dhId = ""; - int32_t ret = DistributedInputSourceHandler::GetInstance().UnregisterDistributedHardware("devId", - "dhId", unregisterDInputCallback); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceHandlerTest, UnregisterDistributedHardware03, testing::ext::TestSize.Level0) -{ - std::shared_ptr unregisterDInputCallback = - std::make_shared(); - - int32_t ret = DistributedInputSourceHandler::GetInstance().UnregisterDistributedHardware("devId", - "dhId", unregisterDInputCallback); - EXPECT_EQ(SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceHandlerTest, ConfigDistributedHardware01, testing::ext::TestSize.Level0) -{ - int32_t ret = DistributedInputSourceHandler::GetInstance().ConfigDistributedHardware("devId", - "dhId", "key", "value"); - EXPECT_EQ(SUCCESS, ret); -} -} -} -} \ No newline at end of file diff --git a/sourcehandler/test/unittest/distributed_input_sourcehandler_test.h b/sourcehandler/test/unittest/distributed_input_sourcehandler_test.h deleted file mode 100644 index 06793be..0000000 --- a/sourcehandler/test/unittest/distributed_input_sourcehandler_test.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISRIBUTED_INPUT_SOURCEHANDLER_TEST_H -#define DISRIBUTED_INPUT_SOURCEHANDLER_TEST_H - -#include -#include -#include - -#include -#include - -#include "idistributed_hardware_source.h" -#include "system_ability_load_callback_stub.h" - -#include "constants_dinput.h" -#include "distributed_input_kit.h" -#include "distributed_input_source_handler.h" -#include "i_distributed_source_input.h" -#include "register_d_input_call_back_stub.h" -#include "unregister_d_input_call_back_stub.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputSourceHandlerTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; - int32_t CheckSystemAbility(); - - class TestRegisterDInputCallback : public OHOS::DistributedHardware::RegisterCallback { - public: - TestRegisterDInputCallback() = default; - virtual ~TestRegisterDInputCallback() = default; - virtual int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status, - const std::string &data) override; - }; - - class TestUnregisterDInputCallback : public OHOS::DistributedHardware::UnregisterCallback { - public: - TestUnregisterDInputCallback() = default; - virtual ~TestUnregisterDInputCallback() = default; - virtual int32_t OnUnregisterResult(const std::string &devId, const std::string &dhId, int32_t status, - const std::string &data) override; - }; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS -#endif // DISRIBUTED_INPUT_SOURCEHANDLER_TEST_H diff --git a/sourcehandler/test/unittest/mock/mock_distributed_input_client.cpp b/sourcehandler/test/unittest/mock/mock_distributed_input_client.cpp deleted file mode 100644 index c12cd15..0000000 --- a/sourcehandler/test/unittest/mock/mock_distributed_input_client.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "nlohmann/json.hpp" -#include "distributed_hardware_log.h" - -#include "constants_dinput.h" -#include "distributed_input_client.h" -#include "white_list_util.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -DistributedInputClient &DistributedInputClient::GetInstance() -{ - static DistributedInputClient instance; - return instance; -} - -void DistributedInputClient::RegisterDInputCb::OnResult( - const std::string& devId, const std::string& dhId, const int32_t& status) -{ - for (std::vector::iterator iter = - DistributedInputClient::GetInstance().dHardWareFwkRstInfos.begin(); - iter != DistributedInputClient::GetInstance().dHardWareFwkRstInfos.end(); - iter++) { - if (iter->devId == devId && iter->dhId == dhId) { - iter->callback->OnRegisterResult(devId, dhId, status, ""); - DistributedInputClient::GetInstance().dHardWareFwkRstInfos.erase(iter); - return; - } - } -} - -void DistributedInputClient::UnregisterDInputCb::OnResult( - const std::string& devId, const std::string& dhId, const int32_t& status) - -{ - for (std::vector::iterator iter = - DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.begin(); - iter != DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.end(); - iter++) { - if (iter->devId == devId && iter->dhId == dhId) { - iter->callback->OnUnregisterResult(devId, dhId, status, ""); - DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.erase(iter); - return; - } - } -} - -void DistributedInputClient::StartDInputServerCb::OnResult(const int32_t& status, const uint32_t& inputTypes) -{ - if (DInputServerType::SOURCE_SERVER_TYPE == static_cast(status)) { - DistributedInputClient::GetInstance().serverType = DInputServerType::SOURCE_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes = inputTypes; - } else if (DInputServerType::SINK_SERVER_TYPE == static_cast(status)) { - DistributedInputClient::GetInstance().serverType = DInputServerType::SINK_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes = inputTypes; - } else { - DistributedInputClient::GetInstance().serverType = DInputServerType::NULL_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes = INPUT_TYPE_NULL; - } -} - -void DistributedInputClient::AddWhiteListInfosCb::OnResult(const std::string &deviceId, const std::string &strJson) -{ - nlohmann::json inputData = nlohmann::json::parse(strJson); - int jsonSize = inputData.size(); - DHLOGI("AddWhiteListInfosCb OnResult json size:%d.\n", jsonSize); - TYPE_WHITE_LIST_VEC vecWhiteList = inputData; - WhiteListUtil::GetInstance().SyncWhiteList(deviceId, vecWhiteList); -} - -void DistributedInputClient::DelWhiteListInfosCb::OnResult(const std::string& deviceId) -{ - WhiteListUtil::GetInstance().ClearWhiteList(deviceId); -} - -int32_t DistributedInputClient::InitSource() -{ - return SUCCESS; -} - -int32_t DistributedInputClient::InitSink() -{ - return SUCCESS; -} - -int32_t DistributedInputClient::ReleaseSource() -{ - return SUCCESS; -} - -int32_t DistributedInputClient::ReleaseSink() -{ - return SUCCESS; -} - -int32_t DistributedInputClient::RegisterDistributedHardware(const std::string& devId, const std::string& dhId, - const std::string& parameters, const std::shared_ptr& callback) -{ - return SUCCESS; -} - -int32_t DistributedInputClient::UnregisterDistributedHardware(const std::string& devId, const std::string& dhId, - const std::shared_ptr& callback) -{ - return SUCCESS; -} - -int32_t DistributedInputClient::PrepareRemoteInput( - const std::string& deviceId, sptr callback) -{ - return SUCCESS; -} - -int32_t DistributedInputClient::UnprepareRemoteInput( - const std::string& deviceId, sptr callback) -{ - return SUCCESS; -} - -int32_t DistributedInputClient::StartRemoteInput( - const std::string& deviceId, const uint32_t& inputTypes, sptr callback) -{ - return SUCCESS; -} - -int32_t DistributedInputClient::StopRemoteInput( - const std::string& deviceId, const uint32_t& inputTypes, sptr callback) -{ - return SUCCESS; -} - -bool DistributedInputClient::IsNeedFilterOut(const std::string& deviceId, const BusinessEvent& event) -{ - return true; -} - -DInputServerType DistributedInputClient::IsStartDistributedInput(const uint32_t& inputType) -{ - return serverType; -} - -bool DistributedInputClient::GetDInputSourceProxy() -{ - return true; -} - -bool DistributedInputClient::GetDInputSinkProxy() -{ - return true; -} - -bool DistributedInputClient::IsJsonData(std::string strData) const -{ - return true; -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS