mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-18 16:04:40 -04:00
Description: add input funcs part II
Match-id-29b54c981942d34dd7daee7e9130d99a158def3f
This commit is contained in:
@@ -31,7 +31,13 @@ namespace DistributedInput {
|
||||
#define INPUT_KEY_PATH "path"
|
||||
|
||||
#define VIRTUAL_DEVICE_NAME "Hos Distributed Virtual Device "
|
||||
#define LONG_BITS (sizeof(long) * 8)
|
||||
#define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS)
|
||||
|
||||
const char INPUT_STRING_SPLIT_POINT = '.';
|
||||
const uint32_t KEY_DOWN_STATE = 1;
|
||||
const uint32_t READ_SLEEP_TIME_MS = 50;
|
||||
const uint32_t READ_RETRY_MAX = 5;
|
||||
/*
|
||||
* Device Type definitions
|
||||
*/
|
||||
|
||||
@@ -59,7 +59,11 @@ namespace DistributedInput {
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_SENDMESSAGE_FAIL = -64009;
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESP_LATENCY_FAIL = -64010;
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_SCREEN_INFO_IS_EMPTY = -64011;
|
||||
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_GET_SESSIONID_FAIL = -64012;
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANS_START_FAIL = -64013;
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANS_STOP_FAIL = -64014;
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_MANAGER_START_MSG_IS_BAD = -64015;
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_MANAGER_STOP_MSG_IS_BAD = -64016;
|
||||
// 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;
|
||||
@@ -97,6 +101,9 @@ namespace DistributedInput {
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD = -65033;
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_LATENCY_FAIL = -65034;
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_VIRTUAL_SCREEN_NODE_IS_INVALID = -65035;
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REG_CALLBACK_ERR = -65036;
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_SIMULATION_EVENT_CALLBACK_ERR = -65037;
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_DH_FWK_KIT_IS_NULL = -65038;
|
||||
|
||||
// handler error code
|
||||
constexpr int32_t ERR_DH_INPUT_SINK_HANDLER_INIT_SINK_SA_FAIL = -66000;
|
||||
@@ -112,33 +119,51 @@ namespace DistributedInput {
|
||||
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;
|
||||
constexpr int32_t ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL = -67029;
|
||||
constexpr int32_t ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL = -67030;
|
||||
constexpr int32_t ERR_DH_INPUT_RPC_GET_REMOTE_DINPUT_FAIL = -67035;
|
||||
constexpr int32_t ERR_DH_INPUT_NOTIFY_START_DSCREEN_FAIL = -67036;
|
||||
constexpr int32_t ERR_DH_INPUT_NOTIFY_STOP_DSCREEN_FAIL = -67037;
|
||||
constexpr int32_t ERR_DH_INPUT_RPC_REPLY_FAIL = -67038;
|
||||
constexpr int32_t ERR_DH_INPUT_SA_REQUEST_CODE_INVALID = -67039;
|
||||
constexpr int32_t ERR_DH_INPUT_CLIENT_REG_START_STOP_CB_FAIL = -67009;
|
||||
constexpr int32_t ERR_DH_INPUT_CLIENT_UNREG_START_STOP_CB_FAIL = -67010;
|
||||
constexpr int32_t ERR_DH_INPUT_CLIENT_REG_NODE_CB_FAIL = -67011;
|
||||
constexpr int32_t ERR_DH_INPUT_CLIENT_UNREG_NODE_CB_FAIL = -67012;
|
||||
constexpr int32_t ERR_DH_INPUT_CLIENT_REG_UNREG_KEY_STATE_FAIL = -67013;
|
||||
constexpr int32_t ERR_DH_INPUT_SINK_PROXY_INIT_FAIL = -67014;
|
||||
constexpr int32_t ERR_DH_INPUT_SINK_PROXY_RELEASE_FAIL = -67015;
|
||||
constexpr int32_t ERR_DH_INPUT_SINK_PROXY_IS_START_INPUT_FAIL = -67016;
|
||||
constexpr int32_t ERR_DH_INPUT_SINK_STUB_ON_REMOTE_REQUEST_FAIL = -67017;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_INIT_FAIL = -67018;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_RELEASE_FAIL = -67019;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_REGISTER_WRITE_MSG_FAIL = -67020;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_REGISTER_FAIL = -67021;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_WRITE_MSG_FAIL = -67022;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_FAIL = -67023;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_PREPARE_WRITE_MSG_FAIL = -67024;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_PREPARE_FAIL = -67025;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_WRITE_MSG_FAIL = -67026;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_FAIL = -67027;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_START_WRITE_MSG_FAIL = -67028;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_START_FAIL = -67029;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_STOP_WRITE_MSG_FAIL = -67030;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL = -67031;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_IS_START_INPUT_FAIL = -67032;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_REGISTER_WHITELIST_FAIL = -67033;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_WHITELIST_FAIL = -67034;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_REGISTER_NODE_LISTENER_FAIL = -67035;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_NODE_LISTENER_FAIL = -67036;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_REGISTER_SIMULATION_LISTENER_FAIL = -67037;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_SIMULATION_LISTENER_FAIL = -67038;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_SYNC_NODE_FAIL = -67039;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_STUB_REGISTER_NODE_LISTENER_FAIL = -67040;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_STUB_UNREGISTER_NODE_LISTENER_FAIL = -67041;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_STUB_REGISTER_SIMULATION_EVENT_LISTENER_FAIL = -67042;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_STUB_UNREGISTER_SIMULATION_EVENT_LISTENER_FAIL = -67043;
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL = -67044;
|
||||
constexpr int32_t ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL = -67045;
|
||||
constexpr int32_t ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL = -67046;
|
||||
constexpr int32_t ERR_DH_INPUT_IPC_READ_VALID_FAIL = -67047;
|
||||
constexpr int32_t ERR_DH_INPUT_IPC_WRITE_VALID_FAIL = -67048;
|
||||
constexpr int32_t ERR_DH_INPUT_RPC_GET_REMOTE_DINPUT_FAIL = -67049;
|
||||
constexpr int32_t ERR_DH_INPUT_NOTIFY_START_DSCREEN_FAIL = -67050;
|
||||
constexpr int32_t ERR_DH_INPUT_NOTIFY_STOP_DSCREEN_FAIL = -67051;
|
||||
constexpr int32_t ERR_DH_INPUT_RPC_REPLY_FAIL = -67052;
|
||||
constexpr int32_t ERR_DH_INPUT_SA_REQUEST_CODE_INVALID = -67053;
|
||||
|
||||
// Hidump Helper error code
|
||||
constexpr int32_t ERR_DH_INPUT_HIDUMP_INVALID_ARGS = -68000;
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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 "dinput_struct_data.h"
|
||||
#include "distributed_hardware_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
StringDeviceData::StringDeviceData() : dhname_(""), status(0) {}
|
||||
|
||||
bool StringDeviceData::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!parcel.WriteString(dhname_)) {
|
||||
DHLOGE("StringDeviceData-Marshalling write dhname_ failed");
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt32(status)) {
|
||||
DHLOGE("StringDeviceData-Marshalling write status failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
sptr<StringDeviceData> StringDeviceData::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
sptr<StringDeviceData> ptr = (std::make_unique<StringDeviceData>()).release();
|
||||
if (ptr == nullptr) {
|
||||
DHLOGE("StringDeviceData-Unmarshalling create ptr is null.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!parcel.ReadString(ptr->dhname_)) {
|
||||
DHLOGE("StringDeviceData-Unmarshalling read dhname_ failed.");
|
||||
return nullptr;
|
||||
}
|
||||
if (!parcel.ReadInt32(ptr->status)) {
|
||||
DHLOGE("StringDeviceData-Unmarshalling read status failed.");
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 D_INPUT_STRUCT_DATA_H
|
||||
#define D_INPUT_STRUCT_DATA_H
|
||||
|
||||
#include <string>
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class StringDeviceData : public Parcelable {
|
||||
public:
|
||||
std::string dhname_;
|
||||
int32_t status; // 0 is success, -1 is error.
|
||||
StringDeviceData();
|
||||
~StringDeviceData() = default;
|
||||
bool Marshalling(Parcel &parcel) const override;
|
||||
static sptr<StringDeviceData> Unmarshalling(Parcel &parcel);
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // D_INPUT_STRUCT_DATA_H
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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_DBG_ITF_H
|
||||
#define OHOS_DINPUT_DBG_ITF_H
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
const std::string GET_DBG_ITF_FUNC = "GetDBGItf";
|
||||
class IDInputDBGItf {
|
||||
public:
|
||||
virtual int32_t Init() = 0;
|
||||
};
|
||||
extern "C" __attribute__((visibility("default"))) IDInputDBGItf* GetDBGItf();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+122
-11
@@ -184,6 +184,9 @@ size_t InputHub::GetEvents(RawEvent* buffer, size_t bufferSize)
|
||||
if (!device) {
|
||||
continue;
|
||||
}
|
||||
if (!device->isShare) {
|
||||
continue;
|
||||
}
|
||||
if (eventItem.events & EPOLLIN) {
|
||||
event += CollectEvent(event, capacity, device, readBuffer, count);
|
||||
|
||||
@@ -204,7 +207,7 @@ size_t InputHub::CollectEvent(RawEvent* buffer, size_t& capacity, Device* device
|
||||
const size_t count)
|
||||
{
|
||||
std::vector<bool> needFilted(capacity, false);
|
||||
if (device->classes == INPUT_DEVICE_CLASS_TOUCH_MT) {
|
||||
if ((device->classes & INPUT_DEVICE_CLASS_TOUCH_MT) || (device->classes & INPUT_DEVICE_CLASS_TOUCH)) {
|
||||
HandleTouchScreenEvent(readBuffer, count, needFilted, device);
|
||||
}
|
||||
|
||||
@@ -551,11 +554,16 @@ int32_t InputHub::MakeDevice(int fd, std::unique_ptr<Device> device)
|
||||
ioctl(fd, EVIOCGBIT(EV_REL, sizeof(device->relBitmask)), device->relBitmask);
|
||||
|
||||
// See if this is a multi-touch touchscreen device.
|
||||
if (TestBit(BTN_TOUCH, device->keyBitmask)
|
||||
&& TestBit(ABS_MT_POSITION_X, device->absBitmask)
|
||||
&& TestBit(ABS_MT_POSITION_Y, device->absBitmask)) {
|
||||
if (TestBit(BTN_TOUCH, device->keyBitmask) &&
|
||||
TestBit(ABS_MT_POSITION_X, device->absBitmask) &&
|
||||
TestBit(ABS_MT_POSITION_Y, device->absBitmask)) {
|
||||
QueryLocalTouchScreenInfo(fd);
|
||||
device->classes |= INPUT_DEVICE_CLASS_TOUCH_MT;
|
||||
device->classes |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT;
|
||||
} else if (TestBit(BTN_TOUCH, device->keyBitmask) &&
|
||||
TestBit(ABS_X, device->absBitmask) &&
|
||||
TestBit(ABS_Y, device->absBitmask)) {
|
||||
QueryLocalTouchScreenInfo(fd);
|
||||
device->classes |= INPUT_DEVICE_CLASS_TOUCH;
|
||||
}
|
||||
|
||||
// See if this is a cursor device such as a trackball or mouse.
|
||||
@@ -585,9 +593,14 @@ int32_t InputHub::MakeDevice(int fd, std::unique_ptr<Device> device)
|
||||
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;
|
||||
if (device->classes & inputTypes_) {
|
||||
device->isShare = true;
|
||||
}
|
||||
DHLOGI("inputType=%d", inputTypes_.load());
|
||||
DHLOGI("New device: fd=%d, name='%s', classes=0x%x, isShare=%d",
|
||||
fd, device->identifier.name.c_str(), device->classes, device->isShare);
|
||||
|
||||
AddDeviceLocked(std::move(device));
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
@@ -883,9 +896,7 @@ InputHub::Device* InputHub::GetSupportDeviceByFd(int fd)
|
||||
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
|
||||
for (const auto& [id, device] : devices_) {
|
||||
if (device->fd == fd) {
|
||||
if (IsSupportInputTypes(device->classes)) {
|
||||
return device.get();
|
||||
}
|
||||
return device.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
@@ -926,10 +937,110 @@ bool InputHub::IsSupportInputTypes(uint32_t classes)
|
||||
{
|
||||
return classes & inputTypes_;
|
||||
}
|
||||
void InputHub::SetSupportInputType(const uint32_t& inputTypes)
|
||||
|
||||
void InputHub::SetSupportInputType(const uint32_t &inputTypes)
|
||||
{
|
||||
inputTypes_ = inputTypes;
|
||||
DHLOGI("SetSupportInputType: inputTypes=0x%x,", inputTypes_.load());
|
||||
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
|
||||
for (const auto &[id, device] : devices_) {
|
||||
if (device->classes & inputTypes_) {
|
||||
device->isShare = true;
|
||||
} else {
|
||||
device->isShare = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InputHub::GetDeviceDhIdByFd(int32_t fd, std::string &dhId)
|
||||
{
|
||||
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
|
||||
for (const auto &[id, device] : devices_) {
|
||||
if (device->fd == fd) {
|
||||
dhId = device->identifier.descriptor;
|
||||
return;
|
||||
}
|
||||
}
|
||||
dhId.clear();
|
||||
}
|
||||
|
||||
void InputHub::SetSharingDevices(bool enabled, std::vector<std::string> dhIds)
|
||||
{
|
||||
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
|
||||
for (auto dhId : dhIds) {
|
||||
for (const auto &[id, device] : devices_) {
|
||||
if (device->identifier.descriptor == dhId) {
|
||||
device->isShare = enabled;
|
||||
DHLOGW("dhid:%s, isshare:%d,", device->identifier.descriptor.c_str(), enabled);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InputHub::GetShareMousePathByDhId(std::vector<std::string> dhIds, std::string &path, std::string &dhId)
|
||||
{
|
||||
DHLOGI("GetShareMousePathByDhId: devices_.size:%d,", devices_.size());
|
||||
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
|
||||
for (auto dhId_ : dhIds) {
|
||||
for (const auto &[id, device] : devices_) {
|
||||
DHLOGI("descriptor:%s, isShare[%d], type[%d]", device->identifier.descriptor.c_str(),
|
||||
device->isShare, device->classes);
|
||||
if ((device->identifier.descriptor == dhId_) &&
|
||||
((device->classes & INPUT_DEVICE_CLASS_CURSOR) != 0)) {
|
||||
dhId = dhId_;
|
||||
path = device->path;
|
||||
return; // return First shared mouse
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InputHub::GetDevicesInfoByType(int32_t inputTypes, std::map<int32_t, std::string> &datas)
|
||||
{
|
||||
uint32_t input_types_ = 0;
|
||||
|
||||
if ((inputTypes & static_cast<uint32_t>(DInputDeviceType::MOUSE)) != 0) {
|
||||
input_types_ |= INPUT_DEVICE_CLASS_CURSOR;
|
||||
}
|
||||
|
||||
if ((inputTypes & static_cast<uint32_t>(DInputDeviceType::KEYBOARD)) != 0) {
|
||||
input_types_ |= INPUT_DEVICE_CLASS_KEYBOARD;
|
||||
}
|
||||
|
||||
if ((inputTypes & static_cast<uint32_t>(DInputDeviceType::TOUCHSCREEN)) != 0) {
|
||||
input_types_ |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT;
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
|
||||
for (const auto &[id, device] : devices_) {
|
||||
if (device->classes & input_types_) {
|
||||
datas.insert(std::pair<int32_t, std::string>(device->fd, device->identifier.descriptor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InputHub::GetDevicesInfoByDhId(std::vector<std::string> dhidsVec, std::map<int32_t, std::string> &datas)
|
||||
{
|
||||
for (auto dhId : dhidsVec) {
|
||||
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
|
||||
for (const auto &[id, device] : devices_) {
|
||||
if (device->identifier.descriptor == dhId) {
|
||||
datas.insert(std::pair<int32_t, std::string>(device->fd, dhId));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool InputHub::GetAllDevicesStoped()
|
||||
{
|
||||
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
|
||||
for (const auto &[id, device] : devices_) {
|
||||
if (device->isShare) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void InputHub::RecordEventLog(const RawEvent* event)
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <sys/epoll.h>
|
||||
@@ -40,8 +41,15 @@ public:
|
||||
void StopCollectInputHandler();
|
||||
size_t DeviceIsExists(InputDeviceEvent* event, size_t capacity);
|
||||
std::vector<InputDevice> GetAllInputDevices();
|
||||
void SetSupportInputType(const uint32_t& inputType);
|
||||
void SetSupportInputType(const uint32_t &inputType);
|
||||
void SetSharingDevices(bool enabled, std::vector<std::string> dhIds);
|
||||
void GetDeviceDhIdByFd(int32_t fd, std::string &dhId);
|
||||
void GetDevicesInfoByType(int32_t inputTypes, std::map<int32_t, std::string> &datas);
|
||||
void GetDevicesInfoByDhId(std::vector<std::string> dhidsVec, std::map<int32_t, std::string> &datas);
|
||||
void GetShareMousePathByDhId(std::vector<std::string> dhIds, std::string &path, std::string &dhId);
|
||||
bool GetAllDevicesStoped();
|
||||
void ScanInputDevices(const std::string& dirname);
|
||||
|
||||
private:
|
||||
struct Device {
|
||||
Device* next;
|
||||
@@ -54,11 +62,11 @@ private:
|
||||
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(int fd, int32_t id, const std::string& path, const InputDevice& identifier);
|
||||
~Device();
|
||||
void Close();
|
||||
bool enabled; // initially true
|
||||
bool isShare;
|
||||
int32_t Enable();
|
||||
int32_t Disable();
|
||||
bool HasValidFd() const;
|
||||
@@ -104,7 +112,9 @@ private:
|
||||
|
||||
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"
|
||||
|
||||
/*
|
||||
* 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)
|
||||
|
||||
@@ -60,7 +60,7 @@ int32_t WhiteListUtil::Init()
|
||||
std::ifstream inFile(whiteListFilePath, std::ios::in | std::ios::binary);
|
||||
if (!inFile.is_open()) {
|
||||
// file open error
|
||||
DHLOGE("%s error, file open fail path=%s", __func__, whiteListFilePath);
|
||||
DHLOGE("WhiteListUtil Init error, file open fail path=%s", whiteListFilePath);
|
||||
return ERR_DH_INPUT_WHILTELIST_INIT_FAIL;
|
||||
}
|
||||
|
||||
@@ -70,8 +70,7 @@ int32_t WhiteListUtil::Init()
|
||||
|
||||
std::string line;
|
||||
while (getline(inFile, line)) {
|
||||
DHLOGI("%s called success, line=%s", __func__, line.c_str());
|
||||
|
||||
DHLOGI("read whitelist cfg, line=%s", line.c_str());
|
||||
vecKeyCode.clear();
|
||||
vecCombinationKey.clear();
|
||||
|
||||
@@ -117,7 +116,7 @@ int32_t WhiteListUtil::Init()
|
||||
|
||||
int32_t WhiteListUtil::UnInit(void)
|
||||
{
|
||||
DHLOGI("%s called", __func__);
|
||||
DHLOGI("WhiteListUtil UnInit called");
|
||||
ClearWhiteList();
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
@@ -230,7 +229,7 @@ int32_t WhiteListUtil::ClearWhiteList(void)
|
||||
|
||||
int32_t WhiteListUtil::GetWhiteList(const std::string &deviceId, TYPE_WHITE_LIST_VEC &vecWhiteList)
|
||||
{
|
||||
DHLOGI("start, deviceId=%s", GetAnonyString(deviceId).c_str());
|
||||
DHLOGI("GetWhiteList start, deviceId=%s", GetAnonyString(deviceId).c_str());
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
TYPE_DEVICE_WHITE_LIST_MAP::const_iterator iter = mapDeviceWhiteList_.find(deviceId);
|
||||
@@ -271,17 +270,17 @@ std::string WhiteListUtil::GetBusinessEventHash(const BusinessEvent &event)
|
||||
|
||||
bool WhiteListUtil::IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event)
|
||||
{
|
||||
DHLOGI("start, deviceId=%s", GetAnonyString(deviceId).c_str());
|
||||
DHLOGI("IsNeedFilterOut start, deviceId=%s", GetAnonyString(deviceId).c_str());
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (combKeysHashMap_.empty()) {
|
||||
DHLOGE("%s called, white list is empty!", __func__);
|
||||
DHLOGE("IsNeedFilterOut error, white list is empty!");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto iter = combKeysHashMap_.find(deviceId);
|
||||
if (iter == combKeysHashMap_.end()) {
|
||||
DHLOGE("%s called, not find by deviceId!", __func__);
|
||||
DHLOGE("IsNeedFilterOut error, not find by deviceId!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ ohos_shared_library("libdinput_dfx_utils") {
|
||||
"${fwk_utils_path}/include",
|
||||
"${frameworks_path}/include",
|
||||
"${dfx_utils_path}/include",
|
||||
"${service_common}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "distributed_hardware_log.h"
|
||||
|
||||
#include "dinput_errcode.h"
|
||||
#include "dinput_softbus_define.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
@@ -28,7 +29,6 @@ namespace {
|
||||
const std::string ARGS_HELP = "-h";
|
||||
const std::string ARGS_NODE_INFO = "-nodeinfo";
|
||||
const std::string ARGS_SESSION_INFO = "-sessioninfo";
|
||||
const std::string DINPUT_PKG_NAME = "ohos.dhardware.dinput";
|
||||
|
||||
const std::map<std::string, HiDumperFlag> ARGS_MAP = {
|
||||
{ARGS_HELP, HiDumperFlag::GET_HELP},
|
||||
@@ -129,7 +129,7 @@ void HiDumper::DeleteNodeInfo(const std::string& deviceId, const std::string& dh
|
||||
}
|
||||
}
|
||||
|
||||
int32_t HiDumper::GetSessionInfo(std::string &result)
|
||||
int32_t HiDumper::GetSessionInfo(std::string& result)
|
||||
{
|
||||
DHLOGI("GetSessionInfo Dump.");
|
||||
std::lock_guard<std::mutex> lock(sessionMutex_);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#define I_DISTRIBUTED_SOURCE_INPUT_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_object.h"
|
||||
@@ -29,8 +30,12 @@
|
||||
#include "i_start_d_input_call_back.h"
|
||||
#include "i_start_d_input_server_call_back.h"
|
||||
#include "i_stop_d_input_call_back.h"
|
||||
#include "i_start_stop_d_inputs_call_back.h"
|
||||
#include "i_start_stop_result_call_back.h"
|
||||
#include "i_unprepare_d_input_call_back.h"
|
||||
#include "i_unregister_d_input_call_back.h"
|
||||
#include "i_input_node_listener.h"
|
||||
#include "i_simulation_event_listener.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
@@ -51,13 +56,9 @@ public:
|
||||
const std::string& devId, const std::string& dhId,
|
||||
sptr<IUnregisterDInputCallback> callback) = 0;
|
||||
|
||||
virtual int32_t PrepareRemoteInput(
|
||||
const std::string& deviceId, sptr<IPrepareDInputCallback> callback,
|
||||
sptr<IAddWhiteListInfosCallback> addWhiteListCallback) = 0;
|
||||
virtual int32_t PrepareRemoteInput(const std::string &deviceId, sptr<IPrepareDInputCallback> callback) = 0;
|
||||
|
||||
virtual int32_t UnprepareRemoteInput(
|
||||
const std::string& deviceId, sptr<IUnprepareDInputCallback> callback,
|
||||
sptr<IDelWhiteListInfosCallback> delWhiteListCallback) = 0;
|
||||
virtual int32_t UnprepareRemoteInput(const std::string &deviceId, sptr<IUnprepareDInputCallback> callback) = 0;
|
||||
|
||||
virtual int32_t StartRemoteInput(
|
||||
const std::string& deviceId, const uint32_t& inputTypes, sptr<IStartDInputCallback> callback) = 0;
|
||||
@@ -65,9 +66,43 @@ public:
|
||||
virtual int32_t StopRemoteInput(
|
||||
const std::string& deviceId, const uint32_t& inputTypes, sptr<IStopDInputCallback> callback) = 0;
|
||||
|
||||
virtual int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes,
|
||||
sptr<IStartDInputCallback> callback) = 0;
|
||||
|
||||
virtual int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes,
|
||||
sptr<IStopDInputCallback> callback) = 0;
|
||||
|
||||
virtual int32_t PrepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IPrepareDInputCallback> callback) = 0;
|
||||
|
||||
virtual int32_t UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IUnprepareDInputCallback> callback) = 0;
|
||||
|
||||
virtual int32_t StartRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback) = 0;
|
||||
|
||||
virtual int32_t StopRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback) = 0;
|
||||
|
||||
virtual int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback) = 0;
|
||||
|
||||
virtual int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback) = 0;
|
||||
|
||||
virtual int32_t IsStartDistributedInput(
|
||||
const uint32_t& inputType, sptr<IStartDInputServerCallback> callback) = 0;
|
||||
|
||||
virtual int32_t RegisterAddWhiteListCallback(sptr<IAddWhiteListInfosCallback> addWhiteListCallback) = 0;
|
||||
virtual int32_t RegisterDelWhiteListCallback(sptr<IDelWhiteListInfosCallback> delWhiteListCallback) = 0;
|
||||
virtual int32_t RegisterInputNodeListener(sptr<InputNodeListener> listener) = 0;
|
||||
virtual int32_t UnregisterInputNodeListener(sptr<InputNodeListener> listener) = 0;
|
||||
|
||||
virtual int32_t SyncNodeInfoRemoteInput(const std::string &userDevId, const std::string &dhid,
|
||||
const std::string &nodeDesc) = 0;
|
||||
virtual int32_t RegisterSimulationEventListener(sptr<ISimulationEventListener> listener) = 0;
|
||||
virtual int32_t UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener) = 0;
|
||||
|
||||
enum class MessageCode {
|
||||
INIT = 0xf001,
|
||||
RELEASE = 0xf002,
|
||||
@@ -78,6 +113,21 @@ public:
|
||||
START_REMOTE_INPUT = 0xf007,
|
||||
STOP_REMOTE_INPUT = 0xf008,
|
||||
ISSTART_REMOTE_INPUT = 0xf009,
|
||||
PREPARE_RELAY_REMOTE_INPUT = 0xf00a,
|
||||
UNPREPARE_RELAY_REMOTE_INPUT = 0xf00b,
|
||||
START_RELAY_TYPE_REMOTE_INPUT = 0xf00c,
|
||||
STOP_RELAY_TYPE_REMOTE_INPUT = 0xf00d,
|
||||
START_DHID_REMOTE_INPUT = 0xf00e,
|
||||
STOP_DHID_REMOTE_INPUT = 0xf00f,
|
||||
START_RELAY_DHID_REMOTE_INPUT = 0xf010,
|
||||
STOP_RELAY_DHID_REMOTE_INPUT = 0xf011,
|
||||
REGISTER_ADD_WHITE_LIST_CB_REMOTE_INPUT = 0xf013,
|
||||
REGISTER_DEL_WHITE_LIST_CB_REMOTE_INPUT = 0xf014,
|
||||
REGISTER_NODE_LISTENER = 0xf015,
|
||||
UNREGISTER_NODE_LISTENER = 0xf016,
|
||||
REGISTER_SIMULATION_EVENT_LISTENER = 0xf017,
|
||||
UNREGISTER_SIMULATION_EVENT_LISTENER = 0xf018,
|
||||
SYNC_NODE_INFO_REMOTE_INPUT = 0xf019,
|
||||
};
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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 I_INPUT_NODE_LISTENER_H
|
||||
#define I_INPUT_NODE_LISTENER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <iremote_broker.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class InputNodeListener : public IRemoteBroker {
|
||||
public:
|
||||
virtual void OnNodeOnLine(const std::string srcDevId, const std::string sinkDevId,
|
||||
const std::string sinkNodeId, const std::string sinkNodeDesc) = 0;
|
||||
|
||||
virtual void OnNodeOffLine(const std::string srcDevId, const std::string sinkDevId,
|
||||
const std::string sinkNodeId) = 0;
|
||||
|
||||
enum class Message { RESULT_ON, RESULT_OFF };
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.InputNodeListener");
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // I_INPUT_NODE_LISTENER_H
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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 I_SIMULATION_EVENT_LISTENER_H
|
||||
#define I_SIMULATION_EVENT_LISTENER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <iremote_broker.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class ISimulationEventListener : public IRemoteBroker {
|
||||
public:
|
||||
virtual int32_t OnSimulationEvent(uint32_t type, uint32_t code, int32_t value) = 0;
|
||||
|
||||
enum class Message {
|
||||
RESULT_ON,
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.ISimulationEventListener");
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // I_SIMULATION_EVENT_LISTENER_H
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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 I_START_STOP_D_INPUTS_CALL_BACK_H
|
||||
#define I_START_STOP_D_INPUTS_CALL_BACK_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iremote_broker.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class IStartStopDInputsCallback : public IRemoteBroker {
|
||||
public:
|
||||
virtual void OnResultDhids(const std::string &devId, const int32_t &status) = 0;
|
||||
|
||||
enum class Message {
|
||||
RESULT_STRING,
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.IStartStopDInputsCallback");
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // I_START_STOP_D_INPUTS_CALL_BACK_H
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 I_START_STOP_RESULT_CALL_BACK_H
|
||||
#define I_START_STOP_RESULT_CALL_BACK_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iremote_broker.h>
|
||||
#include "dinput_struct_data.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class IStartStopResultCallback : public IRemoteBroker {
|
||||
public:
|
||||
virtual void OnStart(const std::string &srcId, const std::string &sinkId,
|
||||
std::vector<std::string> &dhIds) = 0;
|
||||
virtual void OnStop(const std::string &srcId, const std::string &sinkId,
|
||||
std::vector<std::string> &dhIds) = 0;
|
||||
|
||||
enum class Message {
|
||||
RESULT_START,
|
||||
RESULT_STOP,
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.IStartStopResultCallback");
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // I_START_STOP_RESULT_CALL_BACK_H
|
||||
@@ -25,6 +25,7 @@ ohos_shared_library("libdinput_handler") {
|
||||
"${fwk_common_path}/utils/include",
|
||||
"${fwk_utils_path}/include/log",
|
||||
"${fwk_utils_path}/include",
|
||||
"${service_common}/include",
|
||||
"${frameworks_path}/include",
|
||||
"${utils_path}/include",
|
||||
"//third_party/json/include",
|
||||
|
||||
@@ -30,19 +30,25 @@
|
||||
#include "constants_dinput.h"
|
||||
#include "input_hub.h"
|
||||
|
||||
#ifndef API_EXPORT
|
||||
#define API_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class DistributedInputHandler : public IHardwareHandler {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(DistributedInputHandler);
|
||||
public:
|
||||
virtual int32_t Initialize() override;
|
||||
virtual std::vector<DHItem> Query() override;
|
||||
virtual std::map<std::string, std::string> QueryExtraInfo() override;
|
||||
virtual bool IsSupportPlugin() override;
|
||||
virtual void RegisterPluginListener(std::shared_ptr<PluginListener> listener) override;
|
||||
virtual void UnRegisterPluginListener() override;
|
||||
API_EXPORT virtual int32_t Initialize() override;
|
||||
API_EXPORT virtual std::vector<DHItem> Query() override;
|
||||
API_EXPORT virtual std::map<std::string, std::string> QueryExtraInfo() override;
|
||||
API_EXPORT virtual bool IsSupportPlugin() override;
|
||||
API_EXPORT virtual void RegisterPluginListener(std::shared_ptr<PluginListener> listener) override;
|
||||
API_EXPORT virtual void UnRegisterPluginListener() override;
|
||||
|
||||
API_EXPORT void FindDevicesInfoByType(int32_t inputTypes, std::map<int32_t, std::string> &datas);
|
||||
API_EXPORT void FindDevicesInfoByDhId(std::vector<std::string> dhidsVec, std::map<int32_t, std::string> &datas);
|
||||
private:
|
||||
DistributedInputHandler();
|
||||
~DistributedInputHandler();
|
||||
@@ -69,7 +75,7 @@ private:
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
__attribute__((visibility("default"))) IHardwareHandler* GetHardwareHandler();
|
||||
API_EXPORT IHardwareHandler* GetHardwareHandler();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_errcode.h"
|
||||
#include "dinput_softbus_define.h"
|
||||
#include "softbus_bus_center.h"
|
||||
|
||||
namespace OHOS {
|
||||
@@ -40,8 +41,7 @@ namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
IMPLEMENT_SINGLE_INSTANCE(DistributedInputHandler);
|
||||
DistributedInputHandler::DistributedInputHandler()
|
||||
: collectThreadID_(-1), isCollectingEvents_(false),
|
||||
isStartCollectEventThread(false)
|
||||
: collectThreadID_(-1), isCollectingEvents_(false), isStartCollectEventThread(false)
|
||||
{
|
||||
inputHub_ = std::make_unique<InputHub>();
|
||||
this->m_listener = nullptr;
|
||||
@@ -82,15 +82,33 @@ int32_t DistributedInputHandler::Initialize()
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DistributedInputHandler::FindDevicesInfoByType(int32_t inputTypes, std::map<int32_t, std::string> &datas)
|
||||
{
|
||||
if (inputHub_ != nullptr) {
|
||||
inputHub_->GetDevicesInfoByType(inputTypes, datas);
|
||||
}
|
||||
}
|
||||
|
||||
void DistributedInputHandler::FindDevicesInfoByDhId(
|
||||
std::vector<std::string> dhidsVec, std::map<int32_t, std::string> &datas)
|
||||
{
|
||||
if (inputHub_ != nullptr) {
|
||||
inputHub_->GetDevicesInfoByDhId(dhidsVec, datas);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<DHItem> DistributedInputHandler::Query()
|
||||
{
|
||||
std::vector<DHItem> retInfos;
|
||||
std::vector<InputDevice> vecInput = inputHub_->GetAllInputDevices();
|
||||
for (auto iter : vecInput) {
|
||||
DHItem item;
|
||||
item.dhId = iter.descriptor;
|
||||
StructTransJson(iter, item.attrs);
|
||||
retInfos.push_back(item);
|
||||
|
||||
if (inputHub_ != nullptr) {
|
||||
std::vector<InputDevice> vecInput = inputHub_->GetAllInputDevices();
|
||||
for (auto iter : vecInput) {
|
||||
DHItem item;
|
||||
item.dhId = iter.descriptor;
|
||||
StructTransJson(iter, item.attrs);
|
||||
retInfos.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
return retInfos;
|
||||
@@ -142,8 +160,7 @@ bool DistributedInputHandler::InitCollectEventsThread()
|
||||
collectThreadID_ = -1;
|
||||
int32_t ret = pthread_create(&collectThreadID_, &attr, CollectEventsThread, this);
|
||||
if (ret != 0) {
|
||||
DHLOGE(
|
||||
"DistributedInputHandler::InitCollectEventsThread create thread failed:%d \n", ret);
|
||||
DHLOGE("DistributedInputHandler::InitCollectEventsThread create thread failed:%d \n", ret);
|
||||
pthread_attr_destroy(&attr);
|
||||
collectThreadID_ = -1;
|
||||
isCollectingEvents_ = false;
|
||||
@@ -165,6 +182,10 @@ void *DistributedInputHandler::CollectEventsThread(void *param)
|
||||
|
||||
void DistributedInputHandler::StartInputMonitorDeviceThread(const std::string deviceId)
|
||||
{
|
||||
if (inputHub_ == nullptr) {
|
||||
DHLOGE("inputHub_ not initialized");
|
||||
return;
|
||||
}
|
||||
while (isCollectingEvents_) {
|
||||
size_t count = inputHub_->StartCollectInputHandler(mEventBuffer, INPUT_DEVICE_BUFFER_SIZE);
|
||||
if (count > 0) {
|
||||
|
||||
@@ -34,8 +34,10 @@ ohos_shared_library("libdinput_sdk") {
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"${common_path}/include/white_list_util.cpp",
|
||||
"${common_path}/include/dinput_struct_data.cpp",
|
||||
"${innerkits_path}/src/distributed_input_kit.cpp",
|
||||
"${ipc_path}/src/add_white_list_infos_call_back_proxy.cpp",
|
||||
"${ipc_path}/src/add_white_list_infos_call_back_stub.cpp",
|
||||
@@ -47,6 +49,10 @@ ohos_shared_library("libdinput_sdk") {
|
||||
"${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/input_node_listener_proxy.cpp",
|
||||
"${ipc_path}/src/input_node_listener_stub.cpp",
|
||||
"${ipc_path}/src/simulation_event_listener_proxy.cpp",
|
||||
"${ipc_path}/src/simulation_event_listener_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",
|
||||
@@ -55,6 +61,10 @@ ohos_shared_library("libdinput_sdk") {
|
||||
"${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/start_stop_d_inputs_call_back_proxy.cpp",
|
||||
"${ipc_path}/src/start_stop_d_inputs_call_back_stub.cpp",
|
||||
"${ipc_path}/src/start_stop_result_call_back_proxy.cpp",
|
||||
"${ipc_path}/src/start_stop_result_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",
|
||||
@@ -64,6 +74,7 @@ ohos_shared_library("libdinput_sdk") {
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"${fwk_utils_path}:distributedhardwareutils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#define DISTRIBUTED_INPUT_KIT_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "distributed_hardware_log.h"
|
||||
|
||||
@@ -25,6 +26,8 @@
|
||||
#include "i_register_d_input_call_back.h"
|
||||
#include "i_start_d_input_call_back.h"
|
||||
#include "i_stop_d_input_call_back.h"
|
||||
#include "i_start_stop_d_inputs_call_back.h"
|
||||
#include "i_start_stop_result_call_back.h"
|
||||
#include "i_unregister_d_input_call_back.h"
|
||||
#include "i_prepare_d_input_call_back.h"
|
||||
#include "i_unprepare_d_input_call_back.h"
|
||||
@@ -35,21 +38,43 @@ namespace DistributedInput {
|
||||
class DistributedInputKit {
|
||||
public:
|
||||
|
||||
static int32_t PrepareRemoteInput(const std::string& deviceId, sptr<IPrepareDInputCallback> callback);
|
||||
static int32_t PrepareRemoteInput(const std::string& sinkId, sptr<IPrepareDInputCallback> callback);
|
||||
static int32_t UnprepareRemoteInput(const std::string& sinkId, sptr<IUnprepareDInputCallback> callback);
|
||||
|
||||
static int32_t UnprepareRemoteInput(const std::string& deviceId, sptr<IUnprepareDInputCallback> callback);
|
||||
static int32_t PrepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IPrepareDInputCallback> callback);
|
||||
static int32_t UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IUnprepareDInputCallback> callback);
|
||||
|
||||
static int32_t StartRemoteInput(
|
||||
const std::string& deviceId, const uint32_t& inputTypes, sptr<IStartDInputCallback> callback);
|
||||
|
||||
const std::string& sinkId, const uint32_t& inputTypes, sptr<IStartDInputCallback> callback);
|
||||
static int32_t StopRemoteInput(
|
||||
const std::string& deviceId, const uint32_t& inputTypes, sptr<IStopDInputCallback> callback);
|
||||
const std::string& sinkId, const uint32_t& inputTypes, sptr<IStopDInputCallback> callback);
|
||||
|
||||
static bool IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event);
|
||||
static int32_t StartRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback);
|
||||
static int32_t StopRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback);
|
||||
|
||||
static int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes,
|
||||
sptr<IStartDInputCallback> callback);
|
||||
static int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes,
|
||||
sptr<IStopDInputCallback> callback);
|
||||
|
||||
static int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback);
|
||||
static int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback);
|
||||
|
||||
static bool IsNeedFilterOut(const std::string &sinkId, const BusinessEvent &event);
|
||||
static bool IsTouchEventNeedFilterOut(const TouchScreenEvent &event);
|
||||
|
||||
static DInputServerType IsStartDistributedInput(const uint32_t& inputType);
|
||||
|
||||
static int32_t RegisterInputNodeListener(sptr<InputNodeListener> listener);
|
||||
static int32_t UnregisterInputNodeListener(sptr<InputNodeListener> listener);
|
||||
static int32_t RegisterSimulationEventListener(sptr<ISimulationEventListener> listener);
|
||||
static int32_t UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener);
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -19,32 +19,44 @@ namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
int32_t DistributedInputKit::PrepareRemoteInput(
|
||||
const std::string& deviceId, sptr<IPrepareDInputCallback> callback)
|
||||
const std::string& sinkId, sptr<IPrepareDInputCallback> callback)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().PrepareRemoteInput(deviceId, callback);
|
||||
return DistributedInputClient::GetInstance().PrepareRemoteInput(sinkId, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputKit::UnprepareRemoteInput(
|
||||
const std::string& deviceId, sptr<IUnprepareDInputCallback> callback)
|
||||
const std::string& sinkId, sptr<IUnprepareDInputCallback> callback)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().UnprepareRemoteInput(deviceId, callback);
|
||||
return DistributedInputClient::GetInstance().UnprepareRemoteInput(sinkId, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputKit::StartRemoteInput(
|
||||
const std::string& deviceId, const uint32_t& inputTypes, sptr<IStartDInputCallback> callback)
|
||||
const std::string& sinkId, const uint32_t& inputTypes, sptr<IStartDInputCallback> callback)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().StartRemoteInput(deviceId, inputTypes, callback);
|
||||
return DistributedInputClient::GetInstance().StartRemoteInput(sinkId, inputTypes, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputKit::StopRemoteInput(
|
||||
const std::string& deviceId, const uint32_t& inputTypes, sptr<IStopDInputCallback> callback)
|
||||
const std::string& sinkId, const uint32_t& inputTypes, sptr<IStopDInputCallback> callback)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().StopRemoteInput(deviceId, inputTypes, callback);
|
||||
return DistributedInputClient::GetInstance().StopRemoteInput(sinkId, inputTypes, callback);
|
||||
}
|
||||
|
||||
bool DistributedInputKit::IsNeedFilterOut(const std::string& deviceId, const BusinessEvent& event)
|
||||
int32_t DistributedInputKit::StartRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const uint32_t &inputTypes, sptr<IStartDInputCallback> callback)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().IsNeedFilterOut(deviceId, event);
|
||||
return DistributedInputClient::GetInstance().StartRemoteInput(srcId, sinkId, inputTypes, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputKit::StopRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const uint32_t &inputTypes, sptr<IStopDInputCallback> callback)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().StopRemoteInput(srcId, sinkId, inputTypes, callback);
|
||||
}
|
||||
|
||||
bool DistributedInputKit::IsNeedFilterOut(const std::string& sinkId, const BusinessEvent& event)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().IsNeedFilterOut(sinkId, event);
|
||||
}
|
||||
|
||||
bool DistributedInputKit::IsTouchEventNeedFilterOut(const TouchScreenEvent &event)
|
||||
@@ -56,6 +68,62 @@ DInputServerType DistributedInputKit::IsStartDistributedInput(const uint32_t& in
|
||||
{
|
||||
return DistributedInputClient::GetInstance().IsStartDistributedInput(inputType);
|
||||
}
|
||||
|
||||
int32_t DistributedInputKit::PrepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IPrepareDInputCallback> callback)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().PrepareRemoteInput(srcId, sinkId, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputKit::UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IUnprepareDInputCallback> callback)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().UnprepareRemoteInput(srcId, sinkId, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputKit::StartRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().StartRemoteInput(sinkId, dhIds, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputKit::StopRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().StopRemoteInput(sinkId, dhIds, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputKit::StartRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().StartRemoteInput(srcId, sinkId, dhIds, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputKit::StopRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().StopRemoteInput(srcId, sinkId, dhIds, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputKit::RegisterInputNodeListener(sptr<InputNodeListener> listener)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().RegisterInputNodeListener(listener);
|
||||
}
|
||||
|
||||
int32_t DistributedInputKit::UnregisterInputNodeListener(sptr<InputNodeListener> listener)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().UnregisterInputNodeListener(listener);
|
||||
}
|
||||
|
||||
int32_t DistributedInputKit::RegisterSimulationEventListener(sptr<ISimulationEventListener> listener)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().RegisterSimulationEventListener(listener);
|
||||
}
|
||||
|
||||
int32_t DistributedInputKit::UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().UnregisterSimulationEventListener(listener);
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -49,18 +49,27 @@ ohos_unittest("distributed_input_inner_test") {
|
||||
|
||||
sources = [
|
||||
"${common_path}/include/white_list_util.cpp",
|
||||
"${common_path}/include/dinput_struct_data.cpp",
|
||||
"${innerkits_path}/src/distributed_input_kit.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_source_proxy.cpp",
|
||||
"${ipc_path}/src/input_node_listener_proxy.cpp",
|
||||
"${ipc_path}/src/input_node_listener_stub.cpp",
|
||||
"${ipc_path}/src/simulation_event_listener_proxy.cpp",
|
||||
"${ipc_path}/src/simulation_event_listener_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_stop_d_inputs_call_back_proxy.cpp",
|
||||
"${ipc_path}/src/start_stop_d_inputs_call_back_stub.cpp",
|
||||
"${ipc_path}/src/start_stop_result_call_back_proxy.cpp",
|
||||
"${ipc_path}/src/start_stop_result_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",
|
||||
|
||||
@@ -224,6 +224,46 @@ HWTEST_F(DistributedInputInnerTest, StartRemoteInput04, testing::ext::TestSize.L
|
||||
EXPECT_EQ(DH_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputInnerTest, StartRemoteInput05, testing::ext::TestSize.Level0)
|
||||
{
|
||||
string srcId = "StartRemoteInput01-src";
|
||||
string sinkId = "StartRemoteInput01-sink";
|
||||
sptr<TestStartDInputCallback> callback = new TestStartDInputCallback();
|
||||
int32_t ret =
|
||||
DistributedInputKit::StartRemoteInput(srcId, sinkId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
|
||||
EXPECT_EQ(DH_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputInnerTest, StartRemoteInput06, testing::ext::TestSize.Level0)
|
||||
{
|
||||
string srcId = "";
|
||||
string sinkId = "";
|
||||
sptr<TestStartDInputCallback> callback = new TestStartDInputCallback();
|
||||
int32_t ret =
|
||||
DistributedInputKit::StartRemoteInput(srcId, sinkId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
|
||||
EXPECT_EQ(DH_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputInnerTest, StartRemoteInput07, testing::ext::TestSize.Level0)
|
||||
{
|
||||
string srcId = "StartRemoteInput03-src";
|
||||
string sinkId = "StartRemoteInput03-sink";
|
||||
sptr<TestStartDInputCallback> callback = nullptr;
|
||||
int32_t ret =
|
||||
DistributedInputKit::StartRemoteInput(srcId, sinkId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
|
||||
EXPECT_EQ(DH_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputInnerTest, StartRemoteInput08, testing::ext::TestSize.Level0)
|
||||
{
|
||||
string srcId = "";
|
||||
string sinkId = "";
|
||||
sptr<TestStartDInputCallback> callback = nullptr;
|
||||
int32_t ret =
|
||||
DistributedInputKit::StartRemoteInput(srcId, sinkId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
|
||||
EXPECT_EQ(DH_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputInnerTest, StopRemoteInput01, testing::ext::TestSize.Level0)
|
||||
{
|
||||
string deviceId = "StopRemoteInput01";
|
||||
@@ -260,6 +300,46 @@ HWTEST_F(DistributedInputInnerTest, StopRemoteInput04, testing::ext::TestSize.Le
|
||||
EXPECT_EQ(DH_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputInnerTest, StopRemoteInput05, testing::ext::TestSize.Level0)
|
||||
{
|
||||
string srcId = "StopRemoteInput03-src";
|
||||
string sinkId = "StopRemoteInput03-sink";
|
||||
sptr<TestStopDInputCallback> callback = new TestStopDInputCallback();
|
||||
int32_t ret =
|
||||
DistributedInputKit::StopRemoteInput(srcId, sinkId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
|
||||
EXPECT_EQ(DH_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputInnerTest, StopRemoteInput06, testing::ext::TestSize.Level0)
|
||||
{
|
||||
string srcId = "";
|
||||
string sinkId = "";
|
||||
sptr<TestStopDInputCallback> callback = new TestStopDInputCallback();
|
||||
int32_t ret =
|
||||
DistributedInputKit::StopRemoteInput(srcId, sinkId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
|
||||
EXPECT_EQ(DH_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputInnerTest, StopRemoteInput07, testing::ext::TestSize.Level0)
|
||||
{
|
||||
string srcId = "StopRemoteInput03-src";
|
||||
string sinkId = "StopRemoteInput03-sink";
|
||||
sptr<TestStopDInputCallback> callback = nullptr;
|
||||
int32_t ret =
|
||||
DistributedInputKit::StopRemoteInput(srcId, sinkId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
|
||||
EXPECT_EQ(DH_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputInnerTest, StopRemoteInput08, testing::ext::TestSize.Level0)
|
||||
{
|
||||
string srcId = "";
|
||||
string sinkId = "";
|
||||
sptr<TestStopDInputCallback> callback = nullptr;
|
||||
int32_t ret =
|
||||
DistributedInputKit::StopRemoteInput(srcId, sinkId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
|
||||
EXPECT_EQ(DH_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputInnerTest, IsNeedFilterOut01, testing::ext::TestSize.Level0)
|
||||
{
|
||||
string deviceId = "IsNeedFilterOut01";
|
||||
|
||||
@@ -149,6 +149,18 @@ int32_t DistributedInputClient::StopRemoteInput(
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::StartRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const uint32_t &inputTypes, sptr<IStartDInputCallback> callback)
|
||||
{
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::StopRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const uint32_t &inputTypes, sptr<IStopDInputCallback> callback)
|
||||
{
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
bool DistributedInputClient::IsNeedFilterOut(const std::string& deviceId, const BusinessEvent& event)
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -26,10 +26,12 @@
|
||||
|
||||
#include "idistributed_hardware_source.h"
|
||||
#include "idistributed_hardware_sink.h"
|
||||
#include "event_handler.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
const uint32_t DINPUT_CLIENT_CHECK_CALLBACK_REGISTER_MSG = 1;
|
||||
class DInputSAManager {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(DInputSAManager);
|
||||
public:
|
||||
@@ -40,12 +42,13 @@ public:
|
||||
bool GetDInputSinkProxy();
|
||||
bool HasDInputSinkProxy();
|
||||
bool SetDInputSinkProxy(const sptr<IRemoteObject> &remoteObject);
|
||||
void RegisterEventHandler(std::shared_ptr<AppExecFwk::EventHandler> handler);
|
||||
|
||||
public:
|
||||
class SystemAbilityListener : public SystemAbilityStatusChangeStub {
|
||||
public:
|
||||
void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
|
||||
void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
|
||||
class SystemAbilityListener : public SystemAbilityStatusChangeStub {
|
||||
public:
|
||||
void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
|
||||
void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
|
||||
};
|
||||
|
||||
private:
|
||||
@@ -59,10 +62,13 @@ public:
|
||||
std::atomic<bool> isSubscribeSinkSAChangeListener = false;
|
||||
std::mutex sinkMutex_;
|
||||
std::mutex sourceMutex_;
|
||||
std::mutex handlerMutex_;
|
||||
|
||||
sptr<IDistributedSourceInput> dInputSourceProxy_ = nullptr;
|
||||
sptr<IDistributedSinkInput> dInputSinkProxy_ = nullptr;
|
||||
sptr<SystemAbilityListener> saListenerCallback = nullptr;
|
||||
|
||||
std::shared_ptr<AppExecFwk::EventHandler> eventHandler_;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -28,10 +28,12 @@
|
||||
#include "register_d_input_call_back_stub.h"
|
||||
#include "start_d_input_server_call_back_stub.h"
|
||||
#include "unregister_d_input_call_back_stub.h"
|
||||
#include "start_stop_d_inputs_call_back_stub.h"
|
||||
|
||||
#include "dinput_sa_manager.h"
|
||||
#include "idistributed_hardware_source.h"
|
||||
#include "idistributed_hardware_sink.h"
|
||||
#include "event_handler.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
@@ -66,16 +68,47 @@ public:
|
||||
int32_t StopRemoteInput(
|
||||
const std::string& deviceId, const uint32_t& inputTypes, sptr<IStopDInputCallback> callback);
|
||||
|
||||
bool IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event);
|
||||
int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes,
|
||||
sptr<IStartDInputCallback> callback);
|
||||
|
||||
int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes,
|
||||
sptr<IStopDInputCallback> callback);
|
||||
|
||||
int32_t PrepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IPrepareDInputCallback> callback);
|
||||
int32_t UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IUnprepareDInputCallback> callback);
|
||||
|
||||
int32_t StartRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback);
|
||||
int32_t StopRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback);
|
||||
|
||||
int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback);
|
||||
int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback);
|
||||
|
||||
bool IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event);
|
||||
bool IsTouchEventNeedFilterOut(const TouchScreenEvent &event);
|
||||
|
||||
DInputServerType IsStartDistributedInput(const uint32_t& inputType);
|
||||
|
||||
int32_t NotifyStartDScreen(const std::string &networkId, const std::string& srcDevId, const uint64_t srcWinId);
|
||||
|
||||
int32_t NotifyStopDScreen(const std::string &networkId, const std::string& srcScreenInfoKey);
|
||||
|
||||
int32_t RegisterInputNodeListener(sptr<InputNodeListener> listener);
|
||||
int32_t UnregisterInputNodeListener(sptr<InputNodeListener> listener);
|
||||
|
||||
int32_t RegisterSimulationEventListener(sptr<ISimulationEventListener> listener);
|
||||
int32_t UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener);
|
||||
|
||||
void CheckRegisterCallback();
|
||||
void CheckWhiteListCallback();
|
||||
void CheckNodeMonitorCallback();
|
||||
void CheckKeyStateCallback();
|
||||
void CheckStartStopResultCallback();
|
||||
|
||||
public:
|
||||
class RegisterDInputCb : public OHOS::DistributedHardware::DistributedInput::RegisterDInputCallbackStub {
|
||||
public:
|
||||
@@ -112,6 +145,14 @@ public:
|
||||
void OnResult(const std::string &deviceId);
|
||||
};
|
||||
|
||||
class DInputClientEventHandler : public AppExecFwk::EventHandler {
|
||||
public:
|
||||
DInputClientEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner);
|
||||
~DInputClientEventHandler() {}
|
||||
|
||||
void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
|
||||
};
|
||||
|
||||
private:
|
||||
DistributedInputClient();
|
||||
bool IsJsonData(std::string strData) const;
|
||||
@@ -127,8 +168,21 @@ private:
|
||||
|
||||
sptr<StartDInputServerCb> sinkTypeCallback = nullptr;
|
||||
sptr<StartDInputServerCb> sourceTypeCallback = nullptr;
|
||||
sptr<AddWhiteListInfosCb> addWhiteListCallback = nullptr;
|
||||
sptr<DelWhiteListInfosCb> delWhiteListCallback = nullptr;
|
||||
sptr<AddWhiteListInfosCb> addWhiteListCallback_ = nullptr;
|
||||
sptr<DelWhiteListInfosCb> delWhiteListCallback_ = nullptr;
|
||||
sptr<InputNodeListener> regNodeListener_ = nullptr;
|
||||
sptr<InputNodeListener> unregNodeListener_ = nullptr;
|
||||
sptr<ISimulationEventListener> regSimulationEventListener_ = nullptr;
|
||||
sptr<ISimulationEventListener> unregSimulationEventListener_ = nullptr;
|
||||
|
||||
std::shared_ptr<DistributedInputClient::DInputClientEventHandler> eventHandler_;
|
||||
|
||||
bool isAddWhiteListCbReg;
|
||||
bool isDelWhiteListCbReg;
|
||||
bool isNodeMonitorCbReg;
|
||||
bool isNodeMonitorCbUnreg;
|
||||
bool isSimulationEventCbReg;
|
||||
bool isSimulationEventCbUnreg;
|
||||
|
||||
struct DHardWareFwkRegistInfo {
|
||||
std::string devId;
|
||||
|
||||
@@ -40,7 +40,6 @@ public:
|
||||
const uint32_t& inputType, sptr<IStartDInputServerCallback> callback) override;
|
||||
|
||||
virtual int32_t NotifyStartDScreen(const SrcScreenInfo& srcScreenRemoteCtrlInfo) override;
|
||||
|
||||
virtual int32_t NotifyStopDScreen(const std::string& srcScreenInfoKey) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -42,11 +42,9 @@ public:
|
||||
virtual int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId,
|
||||
sptr<IUnregisterDInputCallback> callback) override;
|
||||
|
||||
virtual int32_t PrepareRemoteInput(const std::string& deviceId,
|
||||
sptr<IPrepareDInputCallback> callback, sptr<IAddWhiteListInfosCallback> addWhiteListCallback) override;
|
||||
virtual int32_t PrepareRemoteInput(const std::string &deviceId, sptr<IPrepareDInputCallback> callback) override;
|
||||
|
||||
virtual int32_t UnprepareRemoteInput(const std::string& deviceId,
|
||||
sptr<IUnprepareDInputCallback> callback, sptr<IDelWhiteListInfosCallback> delWhiteListCallback) override;
|
||||
virtual int32_t UnprepareRemoteInput(const std::string &deviceId, sptr<IUnprepareDInputCallback> callback) override;
|
||||
|
||||
virtual int32_t StartRemoteInput(
|
||||
const std::string& deviceId, const uint32_t& inputTypes, sptr<IStartDInputCallback> callback) override;
|
||||
@@ -54,9 +52,43 @@ public:
|
||||
virtual int32_t StopRemoteInput(
|
||||
const std::string& deviceId, const uint32_t& inputTypes, sptr<IStopDInputCallback> callback) override;
|
||||
|
||||
virtual int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes,
|
||||
sptr<IStartDInputCallback> callback) override;
|
||||
|
||||
virtual int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes,
|
||||
sptr<IStopDInputCallback> callback) override;
|
||||
|
||||
virtual int32_t PrepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IPrepareDInputCallback> callback) override;
|
||||
|
||||
virtual int32_t UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IUnprepareDInputCallback> callback) override;
|
||||
|
||||
virtual int32_t StartRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback) override;
|
||||
|
||||
virtual int32_t StopRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback) override;
|
||||
|
||||
virtual int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback) override;
|
||||
|
||||
virtual int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback) override;
|
||||
|
||||
virtual int32_t IsStartDistributedInput(
|
||||
const uint32_t& inputType, sptr<IStartDInputServerCallback> callback) override;
|
||||
|
||||
virtual int32_t RegisterAddWhiteListCallback(sptr<IAddWhiteListInfosCallback> addWhiteListCallback) override;
|
||||
virtual int32_t RegisterDelWhiteListCallback(sptr<IDelWhiteListInfosCallback> delWhiteListCallback) override;
|
||||
virtual int32_t RegisterInputNodeListener(sptr<InputNodeListener> listener) override;
|
||||
virtual int32_t UnregisterInputNodeListener(sptr<InputNodeListener> listener) override;
|
||||
|
||||
virtual int32_t SyncNodeInfoRemoteInput(const std::string &userDevId, const std::string &dhid,
|
||||
const std::string &nodeDesc) override;
|
||||
virtual int32_t RegisterSimulationEventListener(sptr<ISimulationEventListener> listener) override;
|
||||
virtual int32_t UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener) override;
|
||||
|
||||
private:
|
||||
bool SendRequest(const IDistributedSourceInput::MessageCode code, MessageParcel &data, MessageParcel &reply);
|
||||
|
||||
|
||||
@@ -42,7 +42,22 @@ private:
|
||||
int32_t HandleUnprepareRemoteInput(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleStartRemoteInput(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleStopRemoteInput(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleStartRelayTypeRemoteInput(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleStopRelayTypeRemoteInput(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandlePrepareRelayRemoteInput(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleUnprepareRelayRemoteInput(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleStartDhidRemoteInput(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleStopDhidRemoteInput(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleStartRelayDhidRemoteInput(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleStopRelayDhidRemoteInput(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleIsStartDistributedInput(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleRegisterAddWhiteListCallback(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleRegisterDelWhiteListCallback(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleRegisterInputNodeListener(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleUnRegisterInputNodeListener(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleSyncNodeInfoRemoteInput(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleRegisterSimulationEventListener(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleUnregisterSimulationEventListener(MessageParcel &data, MessageParcel &reply);
|
||||
DISALLOW_COPY_AND_MOVE(DistributedInputSourceStub);
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 INPUT_NODE_LISTENER_PROXY_H
|
||||
#define INPUT_NODE_LISTENER_PROXY_H
|
||||
|
||||
#include "i_input_node_listener.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "iremote_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class InputNodeListenerProxy : public IRemoteProxy<InputNodeListener> {
|
||||
public:
|
||||
explicit InputNodeListenerProxy(const sptr<IRemoteObject> &object);
|
||||
|
||||
virtual ~InputNodeListenerProxy() override;
|
||||
|
||||
virtual void OnNodeOnLine(const std::string srcDevId, const std::string sinkDevId,
|
||||
const std::string sinkNodeId, const std::string sinkNodeDesc) override;
|
||||
|
||||
virtual void OnNodeOffLine(const std::string srcDevId, const std::string sinkDevId,
|
||||
const std::string sinkNodeId) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<InputNodeListenerProxy> delegator_;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INPUT_NODE_LISTENER_PROXY_H
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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 INPUT_NODE_LISTENER_STUB_H
|
||||
#define INPUT_NODE_LISTENER_STUB_H
|
||||
|
||||
#include "i_input_node_listener.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "iremote_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class InputNodeListenerStub : public IRemoteStub<InputNodeListener> {
|
||||
public:
|
||||
InputNodeListenerStub();
|
||||
virtual ~InputNodeListenerStub() override;
|
||||
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_MOVE(InputNodeListenerStub);
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INPUT_NODE_LISTENER_STUB_H
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 SIMULATION_EVENT_LISTENER_PROXY_H
|
||||
#define SIMULATION_EVENT_LISTENER_PROXY_H
|
||||
|
||||
#include "i_simulation_event_listener.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "iremote_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class SimulationEventListenerProxy : public IRemoteProxy<ISimulationEventListener> {
|
||||
public:
|
||||
explicit SimulationEventListenerProxy(const sptr<IRemoteObject> &object);
|
||||
|
||||
virtual ~SimulationEventListenerProxy() override;
|
||||
|
||||
virtual int32_t OnSimulationEvent(uint32_t type, uint32_t code, int32_t value) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<SimulationEventListenerProxy> delegator_;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // SIMULATION_EVENT_LISTENER_PROXY_H
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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 SIMULATION_EVENT_LISTENER_STUB_H
|
||||
#define SIMULATION_EVENT_LISTENER_STUB_H
|
||||
|
||||
#include "i_simulation_event_listener.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "iremote_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class SimulationEventListenerStub : public IRemoteStub<ISimulationEventListener> {
|
||||
public:
|
||||
SimulationEventListenerStub();
|
||||
virtual ~SimulationEventListenerStub() override;
|
||||
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_MOVE(SimulationEventListenerStub);
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // SIMULATION_EVENT_LISTENER_STUB_H
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 START_STOP_D_INPUTS_CALL_BACK_PROXY_H
|
||||
#define START_STOP_D_INPUTS_CALL_BACK_PROXY_H
|
||||
|
||||
#include "i_start_stop_d_inputs_call_back.h"
|
||||
|
||||
#include <string>
|
||||
#include "iremote_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class StartStopDInputsCallbackProxy : public IRemoteProxy<IStartStopDInputsCallback> {
|
||||
public:
|
||||
explicit StartStopDInputsCallbackProxy(const sptr<IRemoteObject> &object);
|
||||
virtual ~StartStopDInputsCallbackProxy() override;
|
||||
|
||||
virtual void OnResultDhids(const std::string &devId, const int32_t &status) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<StartStopDInputsCallbackProxy> delegator_;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // START_STOP_D_INPUTS_CALL_BACK_PROXY_H
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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 START_STOP_D_INPUTS_CALL_BACK_STUB_H
|
||||
#define START_STOP_D_INPUTS_CALL_BACK_STUB_H
|
||||
|
||||
#include "i_start_stop_d_inputs_call_back.h"
|
||||
|
||||
#include <string>
|
||||
#include "iremote_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class StartStopDInputsCallbackStub : public IRemoteStub<IStartStopDInputsCallback> {
|
||||
public:
|
||||
StartStopDInputsCallbackStub();
|
||||
virtual ~StartStopDInputsCallbackStub() override;
|
||||
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_MOVE(StartStopDInputsCallbackStub);
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif // START_STOP_D_INPUTS_CALL_BACK_STUB_H
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 START_STOP_RESULT_CALL_BACK_PROXY_H
|
||||
#define START_STOP_RESULT_CALL_BACK_PROXY_H
|
||||
|
||||
#include "i_start_stop_result_call_back.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "iremote_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class StartStopResultCallbackProxy : public IRemoteProxy<IStartStopResultCallback> {
|
||||
public:
|
||||
explicit StartStopResultCallbackProxy(const sptr<IRemoteObject> &object);
|
||||
virtual ~StartStopResultCallbackProxy() override;
|
||||
|
||||
virtual void OnStart(const std::string &srcId, const std::string &sinkId,
|
||||
std::vector<std::string> &dhIds) override;
|
||||
virtual void OnStop(const std::string &srcId, const std::string &sinkId,
|
||||
std::vector<std::string> &dhIds) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<StartStopResultCallbackProxy> delegator_;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // START_STOP_RESULT_CALL_BACK_PROXY_H
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 START_STOP_RESULT_CALL_BACK_STUB_H
|
||||
#define START_STOP_RESULT_CALL_BACK_STUB_H
|
||||
|
||||
#include "i_start_stop_result_call_back.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "iremote_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class StartStopResultCallbackStub : public IRemoteStub<IStartStopResultCallback> {
|
||||
public:
|
||||
StartStopResultCallbackStub();
|
||||
virtual ~StartStopResultCallbackStub() override;
|
||||
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_MOVE(StartStopResultCallbackStub);
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif // START_STOP_RESULT_CALL_BACK_STUB_H
|
||||
@@ -26,7 +26,7 @@ namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
IMPLEMENT_SINGLE_INSTANCE(DInputSAManager);
|
||||
|
||||
const uint32_t DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME = 50; // million seconds
|
||||
void DInputSAManager::SystemAbilityListener::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId)
|
||||
{
|
||||
if (systemAbilityId == DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID) {
|
||||
@@ -45,6 +45,14 @@ void DInputSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAb
|
||||
{
|
||||
if (systemAbilityId == DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID) {
|
||||
DInputSAManager::GetInstance().dInputSourceSAOnline.store(true);
|
||||
std::lock_guard<std::mutex> lock(DInputSAManager::GetInstance().handlerMutex_);
|
||||
if (DInputSAManager::GetInstance().eventHandler_ != nullptr) {
|
||||
DHLOGI("SendEvent DINPUT_CLIENT_CHECK_CALLBACK_REGISTER_MSG");
|
||||
AppExecFwk::InnerEvent::Pointer msgEvent =
|
||||
AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CHECK_CALLBACK_REGISTER_MSG, systemAbilityId);
|
||||
DInputSAManager::GetInstance().eventHandler_->SendEvent(msgEvent, DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME,
|
||||
AppExecFwk::EventQueue::Priority::IMMEDIATE);
|
||||
}
|
||||
} else if (systemAbilityId == DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID) {
|
||||
DInputSAManager::GetInstance().dInputSinkSAOnline.store(true);
|
||||
}
|
||||
@@ -85,6 +93,12 @@ void DInputSAManager::Init()
|
||||
}
|
||||
}
|
||||
|
||||
void DInputSAManager::RegisterEventHandler(std::shared_ptr<AppExecFwk::EventHandler> handler)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(handlerMutex_);
|
||||
eventHandler_ = handler;
|
||||
}
|
||||
|
||||
bool DInputSAManager::GetDInputSourceProxy()
|
||||
{
|
||||
if (!isSubscribeSrcSAChangeListener.load()) {
|
||||
@@ -116,12 +130,12 @@ bool DInputSAManager::GetDInputSourceProxy()
|
||||
}
|
||||
sptr<ISystemAbilityManager> systemAbilityManager =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
|
||||
if (!systemAbilityManager) {
|
||||
DHLOGE("get system ability manager failed.");
|
||||
return false;
|
||||
}
|
||||
DHLOGI("%s try get sa: %d", __func__, DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID);
|
||||
|
||||
DHLOGI("try get sa: %d", DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID);
|
||||
sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(
|
||||
DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID);
|
||||
if (!remoteObject) {
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "dinput_context.h"
|
||||
#include "dinput_errcode.h"
|
||||
#include "dinput_utils_tool.h"
|
||||
#include "distributed_input_source_proxy.h"
|
||||
#include "softbus_bus_center.h"
|
||||
#include "white_list_util.h"
|
||||
|
||||
@@ -32,10 +33,16 @@ namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
std::shared_ptr<DistributedInputClient> DistributedInputClient::instance(new DistributedInputClient());
|
||||
|
||||
DistributedInputClient::DistributedInputClient()
|
||||
DistributedInputClient::DistributedInputClient() : isAddWhiteListCbReg(false), isDelWhiteListCbReg(false),
|
||||
isNodeMonitorCbReg(false), isNodeMonitorCbUnreg(false),
|
||||
isSimulationEventCbReg(false), isSimulationEventCbUnreg(false)
|
||||
{
|
||||
DHLOGI("DistributedInputClient init start");
|
||||
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create(true);
|
||||
eventHandler_ = std::make_shared<DistributedInputClient::DInputClientEventHandler>(runner);
|
||||
DInputSAManager::GetInstance().RegisterEventHandler(eventHandler_);
|
||||
DInputSAManager::GetInstance().Init();
|
||||
DHLOGI("DistributedInputClient init end.");
|
||||
}
|
||||
|
||||
DistributedInputClient &DistributedInputClient::GetInstance()
|
||||
@@ -102,6 +109,104 @@ void DistributedInputClient::DelWhiteListInfosCb::OnResult(const std::string& de
|
||||
DistributedInputClient::GetInstance().DelWhiteListInfos(deviceId);
|
||||
}
|
||||
|
||||
DistributedInputClient::DInputClientEventHandler::DInputClientEventHandler(
|
||||
const std::shared_ptr<AppExecFwk::EventRunner> &runner)
|
||||
: AppExecFwk::EventHandler(runner)
|
||||
{
|
||||
}
|
||||
|
||||
void DistributedInputClient::DInputClientEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
uint32_t eventId = event->GetInnerEventId();
|
||||
DHLOGI("DInputClientEventHandler ProcessEvent start eventId:%d.", eventId);
|
||||
if (eventId == DINPUT_CLIENT_CHECK_CALLBACK_REGISTER_MSG) {
|
||||
DistributedInputClient::GetInstance().CheckRegisterCallback();
|
||||
} else {
|
||||
DHLOGE("DInputClientEventHandler ProcessEvent error, because eventId is unkonwn.");
|
||||
}
|
||||
DHLOGI("DInputClientEventHandler ProcessEvent end");
|
||||
}
|
||||
|
||||
void DistributedInputClient::CheckRegisterCallback()
|
||||
{
|
||||
DHLOGI("CheckRegisterCallback called, awl[%d], dwl[%d], rnm[%d], unm[%d], rmd[%d], umd[%d]",
|
||||
isAddWhiteListCbReg, isDelWhiteListCbReg, isNodeMonitorCbReg, isNodeMonitorCbUnreg, isSimulationEventCbReg,
|
||||
isSimulationEventCbUnreg);
|
||||
|
||||
CheckWhiteListCallback();
|
||||
CheckNodeMonitorCallback();
|
||||
CheckKeyStateCallback();
|
||||
}
|
||||
|
||||
void DistributedInputClient::CheckWhiteListCallback()
|
||||
{
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("CheckWhiteListCallback client get source proxy fail");
|
||||
return;
|
||||
}
|
||||
if (!isAddWhiteListCbReg) {
|
||||
if (addWhiteListCallback_ == nullptr) {
|
||||
addWhiteListCallback_ = new (std::nothrow) AddWhiteListInfosCb();
|
||||
}
|
||||
int32_t ret =
|
||||
DInputSAManager::GetInstance().dInputSourceProxy_->RegisterAddWhiteListCallback(addWhiteListCallback_);
|
||||
if (ret == DH_SUCCESS) {
|
||||
isAddWhiteListCbReg = true;
|
||||
} else {
|
||||
DHLOGE("CheckWhiteListCallback client RegisterAddWhiteListCallback fail");
|
||||
}
|
||||
}
|
||||
if (!isDelWhiteListCbReg) {
|
||||
if (delWhiteListCallback_ == nullptr) {
|
||||
delWhiteListCallback_ = new (std::nothrow) DelWhiteListInfosCb();
|
||||
}
|
||||
int32_t ret =
|
||||
DInputSAManager::GetInstance().dInputSourceProxy_->RegisterDelWhiteListCallback(delWhiteListCallback_);
|
||||
if (ret == DH_SUCCESS) {
|
||||
isDelWhiteListCbReg = true;
|
||||
} else {
|
||||
DHLOGE("CheckWhiteListCallback client RegisterDelWhiteListCallback fail");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DistributedInputClient::CheckNodeMonitorCallback()
|
||||
{
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("CheckNodeMonitorCallback client get source proxy fail");
|
||||
return;
|
||||
}
|
||||
if (!isNodeMonitorCbReg && regNodeListener_ != nullptr) {
|
||||
DHLOGI("CheckNodeMonitorCallback need continue register regNodeListener_.");
|
||||
DInputSAManager::GetInstance().dInputSourceProxy_->RegisterInputNodeListener(regNodeListener_);
|
||||
isNodeMonitorCbReg = true;
|
||||
}
|
||||
|
||||
if (!isNodeMonitorCbUnreg && unregNodeListener_ != nullptr) {
|
||||
DHLOGI("CheckNodeMonitorCallback need continue register unregNodeListener_.");
|
||||
DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterInputNodeListener(unregNodeListener_);
|
||||
isNodeMonitorCbUnreg = true;
|
||||
}
|
||||
}
|
||||
|
||||
void DistributedInputClient::CheckKeyStateCallback()
|
||||
{
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("CheckKeyStateCallback client get source proxy fail");
|
||||
return;
|
||||
}
|
||||
if (!isSimulationEventCbReg && regSimulationEventListener_ != nullptr) {
|
||||
DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(regSimulationEventListener_);
|
||||
isSimulationEventCbReg = true;
|
||||
}
|
||||
|
||||
if (!isSimulationEventCbUnreg && unregSimulationEventListener_ != nullptr) {
|
||||
DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterSimulationEventListener(
|
||||
unregSimulationEventListener_);
|
||||
isSimulationEventCbUnreg = true;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::InitSource()
|
||||
{
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
@@ -128,9 +233,14 @@ int32_t DistributedInputClient::ReleaseSource()
|
||||
inputTypes_ = DInputDeviceType::NONE;
|
||||
sinkTypeCallback = nullptr;
|
||||
sourceTypeCallback = nullptr;
|
||||
addWhiteListCallback = nullptr;
|
||||
delWhiteListCallback = nullptr;
|
||||
addWhiteListCallback_ = nullptr;
|
||||
delWhiteListCallback_ = nullptr;
|
||||
regNodeListener_ = nullptr;
|
||||
unregNodeListener_ = nullptr;
|
||||
regSimulationEventListener_ = nullptr;
|
||||
unregSimulationEventListener_ = nullptr;
|
||||
WhiteListUtil::GetInstance().ClearWhiteList();
|
||||
|
||||
return DInputSAManager::GetInstance().dInputSourceProxy_->Release();
|
||||
}
|
||||
|
||||
@@ -149,8 +259,8 @@ int32_t DistributedInputClient::ReleaseSink()
|
||||
int32_t DistributedInputClient::RegisterDistributedHardware(const std::string& devId, const std::string& dhId,
|
||||
const std::string& parameters, const std::shared_ptr<RegisterCallback>& callback)
|
||||
{
|
||||
DHLOGI("%s called, deviceId: %s, dhId: %s, parameters: %s",
|
||||
__func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), SetAnonyId(parameters).c_str());
|
||||
DHLOGI("RegisterDistributedHardware called, deviceId: %s, dhId: %s, parameters: %s",
|
||||
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), SetAnonyId(parameters).c_str());
|
||||
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("RegisterDistributedHardware client fail");
|
||||
@@ -183,7 +293,8 @@ int32_t DistributedInputClient::RegisterDistributedHardware(const std::string& d
|
||||
int32_t DistributedInputClient::UnregisterDistributedHardware(const std::string& devId, const std::string& dhId,
|
||||
const std::shared_ptr<UnregisterCallback>& callback)
|
||||
{
|
||||
DHLOGI("%s called, deviceId: %s, dhId: %s", __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
|
||||
DHLOGI("UnregisterDistributedHardware called, deviceId: %s, dhId: %s",
|
||||
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
|
||||
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("UnregisterDistributedHardware client fail");
|
||||
@@ -216,7 +327,7 @@ int32_t DistributedInputClient::UnregisterDistributedHardware(const std::string&
|
||||
int32_t DistributedInputClient::PrepareRemoteInput(
|
||||
const std::string& deviceId, sptr<IPrepareDInputCallback> callback)
|
||||
{
|
||||
DHLOGI("%s called, deviceId: %s", __func__, GetAnonyString(deviceId).c_str());
|
||||
DHLOGI("PrepareRemoteInput called, deviceId: %s", GetAnonyString(deviceId).c_str());
|
||||
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("PrepareRemoteInput client fail");
|
||||
@@ -227,15 +338,13 @@ int32_t DistributedInputClient::PrepareRemoteInput(
|
||||
return ERR_DH_INPUT_CLIENT_PREPARE_FAIL;
|
||||
}
|
||||
|
||||
addWhiteListCallback = new(std::nothrow) AddWhiteListInfosCb();
|
||||
return DInputSAManager::GetInstance().dInputSourceProxy_->PrepareRemoteInput(deviceId, callback,
|
||||
addWhiteListCallback);
|
||||
return DInputSAManager::GetInstance().dInputSourceProxy_->PrepareRemoteInput(deviceId, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::UnprepareRemoteInput(const std::string& deviceId,
|
||||
sptr<IUnprepareDInputCallback> callback)
|
||||
{
|
||||
DHLOGI("%s called, deviceId: %s", __func__, GetAnonyString(deviceId).c_str());
|
||||
DHLOGI("UnprepareRemoteInput called, deviceId: %s", GetAnonyString(deviceId).c_str());
|
||||
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("PrepareRemoteInput client fail");
|
||||
@@ -243,19 +352,18 @@ int32_t DistributedInputClient::UnprepareRemoteInput(const std::string& deviceId
|
||||
}
|
||||
|
||||
if (deviceId.empty() || callback == nullptr) {
|
||||
DHLOGE("UnprepareRemoteInput param error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_UNPREPARE_FAIL;
|
||||
}
|
||||
|
||||
delWhiteListCallback = new(std::nothrow) DelWhiteListInfosCb();
|
||||
return DInputSAManager::GetInstance().dInputSourceProxy_->UnprepareRemoteInput(deviceId, callback,
|
||||
delWhiteListCallback);
|
||||
return DInputSAManager::GetInstance().dInputSourceProxy_->UnprepareRemoteInput(deviceId, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::StartRemoteInput(
|
||||
const std::string& deviceId, const uint32_t& inputTypes, sptr<IStartDInputCallback> callback)
|
||||
{
|
||||
DHLOGI("%s called, deviceId: %s, inputTypes: %d", __func__, GetAnonyString(deviceId).c_str(), inputTypes);
|
||||
|
||||
DHLOGI("StartRemoteInput called, deviceId: %s, inputTypes: %d",
|
||||
GetAnonyString(deviceId).c_str(), inputTypes);
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("StartRemoteInput client fail");
|
||||
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
|
||||
@@ -265,17 +373,17 @@ int32_t DistributedInputClient::StartRemoteInput(
|
||||
inputTypes > static_cast<uint32_t>(DInputDeviceType::ALL) ||
|
||||
inputTypes == static_cast<uint32_t>(DInputDeviceType::NONE) ||
|
||||
!(inputTypes & static_cast<uint32_t>(DInputDeviceType::ALL))) {
|
||||
DHLOGE("StartRemoteInput param error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_START_FAIL;
|
||||
}
|
||||
|
||||
return DInputSAManager::GetInstance().dInputSourceProxy_->StartRemoteInput(deviceId, inputTypes, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::StopRemoteInput(const std::string& deviceId, const uint32_t& inputTypes,
|
||||
sptr<IStopDInputCallback> callback)
|
||||
{
|
||||
DHLOGI("%s called, deviceId: %s, inputTypes: %d", __func__, GetAnonyString(deviceId).c_str(), inputTypes);
|
||||
|
||||
DHLOGI("StopRemoteInput called, deviceId: %s, inputTypes: %d",
|
||||
GetAnonyString(deviceId).c_str(), inputTypes);
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("StopRemoteInput client fail");
|
||||
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
|
||||
@@ -285,15 +393,168 @@ int32_t DistributedInputClient::StopRemoteInput(const std::string& deviceId, con
|
||||
inputTypes > static_cast<uint32_t>(DInputDeviceType::ALL) ||
|
||||
inputTypes == static_cast<uint32_t>(DInputDeviceType::NONE) ||
|
||||
!(inputTypes & static_cast<uint32_t>(DInputDeviceType::ALL))) {
|
||||
DHLOGE("StopRemoteInput param error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_STOP_FAIL;
|
||||
}
|
||||
|
||||
return DInputSAManager::GetInstance().dInputSourceProxy_->StopRemoteInput(deviceId, inputTypes, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::StartRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const uint32_t &inputTypes, sptr<IStartDInputCallback> callback)
|
||||
{
|
||||
DHLOGI("StartRemoteInput relay by type called, srcId: %s, sinkId: %s, inputTypes: %d",
|
||||
GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str(), inputTypes);
|
||||
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("StartRemoteInput relay type client fail");
|
||||
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
|
||||
}
|
||||
|
||||
if (srcId.empty() || sinkId.empty() || callback == nullptr ||
|
||||
inputTypes > static_cast<uint32_t>(DInputDeviceType::ALL) ||
|
||||
inputTypes == static_cast<uint32_t>(DInputDeviceType::NONE) ||
|
||||
!(inputTypes & static_cast<uint32_t>(DInputDeviceType::ALL))) {
|
||||
DHLOGE("StartRemoteInput relay type param error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_START_FAIL;
|
||||
}
|
||||
|
||||
return DInputSAManager::GetInstance().dInputSourceProxy_->StartRemoteInput(srcId, sinkId, inputTypes, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::StopRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const uint32_t &inputTypes, sptr<IStopDInputCallback> callback)
|
||||
{
|
||||
DHLOGI("StopRemoteInput relay by type called, srcId: %s, sinkId: %s, inputTypes: %d",
|
||||
GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str(), inputTypes);
|
||||
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("StopRemoteInput relay type client fail");
|
||||
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
|
||||
}
|
||||
|
||||
if (srcId.empty() || sinkId.empty() || callback == nullptr ||
|
||||
inputTypes > static_cast<uint32_t>(DInputDeviceType::ALL) ||
|
||||
inputTypes == static_cast<uint32_t>(DInputDeviceType::NONE) ||
|
||||
!(inputTypes & static_cast<uint32_t>(DInputDeviceType::ALL))) {
|
||||
DHLOGE("StopRemoteInput relay type param error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_STOP_FAIL;
|
||||
}
|
||||
|
||||
return DInputSAManager::GetInstance().dInputSourceProxy_->StopRemoteInput(srcId, sinkId, inputTypes, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::PrepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IPrepareDInputCallback> callback)
|
||||
{
|
||||
DHLOGI("PrepareRemoteInput relay called, srcId: %s, sinkId: %s",
|
||||
GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("PrepareRemoteInput relay proxy error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
|
||||
}
|
||||
if (srcId.empty() || sinkId.empty() || callback == nullptr) {
|
||||
DHLOGE("PrepareRemoteInput relay param error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_PREPARE_FAIL;
|
||||
}
|
||||
return DInputSAManager::GetInstance().dInputSourceProxy_->PrepareRemoteInput(srcId, sinkId, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IUnprepareDInputCallback> callback)
|
||||
{
|
||||
DHLOGI("UnprepareRemoteInput relay called, srcId: %s, sinkId: %s",
|
||||
GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
|
||||
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("UnprepareRemoteInput relay proxy error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
|
||||
}
|
||||
|
||||
if (srcId.empty() || sinkId.empty() || callback == nullptr) {
|
||||
DHLOGE("UnprepareRemoteInput relay param error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_UNPREPARE_FAIL;
|
||||
}
|
||||
return DInputSAManager::GetInstance().dInputSourceProxy_->UnprepareRemoteInput(srcId, sinkId, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::StartRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback)
|
||||
{
|
||||
DHLOGI("StartRemoteInput relay by dhid called, sinkId: %s", GetAnonyString(sinkId).c_str());
|
||||
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("StartRemoteInput dhid proxy error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
|
||||
}
|
||||
|
||||
if (sinkId.empty() || callback == nullptr || (dhIds.size() <= 0)) {
|
||||
DHLOGE("StartRemoteInput dhid param error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_START_FAIL;
|
||||
}
|
||||
|
||||
return DInputSAManager::GetInstance().dInputSourceProxy_->StartRemoteInput(sinkId, dhIds, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::StopRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback)
|
||||
{
|
||||
DHLOGI("StopRemoteInput relay by dhid called, sinkId: %s", GetAnonyString(sinkId).c_str());
|
||||
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("StopRemoteInput dhid proxy error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
|
||||
}
|
||||
|
||||
if (sinkId.empty() || callback == nullptr || (dhIds.size() <= 0)) {
|
||||
DHLOGE("StopRemoteInput dhid param error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_STOP_FAIL;
|
||||
}
|
||||
|
||||
return DInputSAManager::GetInstance().dInputSourceProxy_->StopRemoteInput(sinkId, dhIds, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::StartRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback)
|
||||
{
|
||||
DHLOGI("StartRemoteInput relay by dhid called, srcId: %s, sinkId: %s",
|
||||
GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
|
||||
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("StartRemoteInput proxy error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
|
||||
}
|
||||
|
||||
if (srcId.empty() || sinkId.empty() || callback == nullptr || (dhIds.size() <= 0)) {
|
||||
DHLOGE("StartRemoteInput param error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_START_FAIL;
|
||||
}
|
||||
|
||||
return DInputSAManager::GetInstance().dInputSourceProxy_->StartRemoteInput(srcId, sinkId, dhIds, callback);
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::StopRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback)
|
||||
{
|
||||
DHLOGI("StopRemoteInput relay by dhid called, srcId: %s, sinkId: %s",
|
||||
GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
|
||||
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("StopRemoteInput proxy error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
|
||||
}
|
||||
|
||||
if (srcId.empty() || sinkId.empty() || callback == nullptr || (dhIds.size() <= 0)) {
|
||||
DHLOGE("StopRemoteInput param error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_STOP_FAIL;
|
||||
}
|
||||
|
||||
return DInputSAManager::GetInstance().dInputSourceProxy_->StopRemoteInput(srcId, sinkId, dhIds, callback);
|
||||
}
|
||||
|
||||
bool DistributedInputClient::IsNeedFilterOut(const std::string& deviceId, const BusinessEvent& event)
|
||||
{
|
||||
DHLOGI("%s called, deviceId: %s", __func__, GetAnonyString(deviceId).c_str());
|
||||
DHLOGI("IsNeedFilterOut called, deviceId: %s", GetAnonyString(deviceId).c_str());
|
||||
return WhiteListUtil::GetInstance().IsNeedFilterOut(deviceId, event);
|
||||
}
|
||||
|
||||
@@ -313,7 +574,8 @@ bool DistributedInputClient::IsTouchEventNeedFilterOut(const TouchScreenEvent &e
|
||||
|
||||
DInputServerType DistributedInputClient::IsStartDistributedInput(const uint32_t& inputType)
|
||||
{
|
||||
DHLOGI("%s called, inputType: %d, inputTypes: %d, ", __func__, inputType, static_cast<uint32_t>(inputTypes_));
|
||||
DHLOGI("IsStartDistributedInput called, inputType: %d, current inputTypes: %d",
|
||||
inputType, static_cast<uint32_t>(inputTypes_));
|
||||
int32_t retSource = 0;
|
||||
int32_t retSink = 0;
|
||||
|
||||
@@ -343,6 +605,106 @@ DInputServerType DistributedInputClient::IsStartDistributedInput(const uint32_t&
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::RegisterInputNodeListener(sptr<InputNodeListener> listener)
|
||||
{
|
||||
DHLOGI("RegisterInputNodeListener called");
|
||||
if (listener == nullptr) {
|
||||
DHLOGE("RegisterInputNodeListener param error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_REG_NODE_CB_FAIL;
|
||||
}
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("RegisterInputNodeListener proxy error, client fail");
|
||||
isNodeMonitorCbReg = false;
|
||||
regNodeListener_ = listener;
|
||||
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
|
||||
}
|
||||
|
||||
int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterInputNodeListener(listener);
|
||||
if (ret == DH_SUCCESS) {
|
||||
isNodeMonitorCbReg = true;
|
||||
} else {
|
||||
isNodeMonitorCbReg = false;
|
||||
regNodeListener_ = listener;
|
||||
DHLOGE("RegisterInputNodeListener Failed, ret = %d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::UnregisterInputNodeListener(sptr<InputNodeListener> listener)
|
||||
{
|
||||
DHLOGI("UnregisterInputNodeListener called");
|
||||
if (listener == nullptr) {
|
||||
DHLOGE("UnregisterInputNodeListener param error, client fail");
|
||||
return ERR_DH_INPUT_CLIENT_UNREG_NODE_CB_FAIL;
|
||||
}
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("UnregisterInputNodeListener proxy error, client fail");
|
||||
isNodeMonitorCbUnreg = false;
|
||||
unregNodeListener_ = listener;
|
||||
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
|
||||
}
|
||||
|
||||
int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterInputNodeListener(listener);
|
||||
if (ret == DH_SUCCESS) {
|
||||
isNodeMonitorCbUnreg = true;
|
||||
} else {
|
||||
isNodeMonitorCbUnreg = false;
|
||||
unregNodeListener_ = listener;
|
||||
DHLOGE("DInputSAManager UnregisterInputNodeListener Failed, ret = %d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::RegisterSimulationEventListener(sptr<ISimulationEventListener> listener)
|
||||
{
|
||||
DHLOGI("RegisterSimulationEventListener called Simulation Event Listener Register.");
|
||||
if (listener == nullptr) {
|
||||
DHLOGE("RegisterSimulationEventListener param error");
|
||||
return ERR_DH_INPUT_CLIENT_REG_UNREG_KEY_STATE_FAIL;
|
||||
}
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("RegisterSimulationEventListener proxy error, client fail");
|
||||
isSimulationEventCbReg = false;
|
||||
regSimulationEventListener_ = listener;
|
||||
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
|
||||
}
|
||||
|
||||
int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(listener);
|
||||
if (ret == DH_SUCCESS) {
|
||||
isSimulationEventCbReg = true;
|
||||
} else {
|
||||
isSimulationEventCbReg = false;
|
||||
regSimulationEventListener_ = listener;
|
||||
DHLOGE("RegisterSimulationEventListener Failed, ret = %d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener)
|
||||
{
|
||||
DHLOGI("UnregisterSimulationEventListener called Simulation Event Listener UnRegister.");
|
||||
if (listener == nullptr) {
|
||||
DHLOGE("UnregisterSimulationEventListener param error");
|
||||
return ERR_DH_INPUT_CLIENT_REG_UNREG_KEY_STATE_FAIL;
|
||||
}
|
||||
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
|
||||
DHLOGE("UnregisterSimulationEventListener proxy error, client fail");
|
||||
isSimulationEventCbUnreg = false;
|
||||
unregSimulationEventListener_ = listener;
|
||||
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
|
||||
}
|
||||
|
||||
int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterSimulationEventListener(listener);
|
||||
if (ret == DH_SUCCESS) {
|
||||
isSimulationEventCbUnreg = true;
|
||||
} else {
|
||||
isSimulationEventCbUnreg = false;
|
||||
unregSimulationEventListener_ = listener;
|
||||
DHLOGE("UnregisterSimulationEventListener Failed, ret = %d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool DistributedInputClient::IsJsonData(std::string strData) const
|
||||
{
|
||||
if (strData[0] != '{') {
|
||||
@@ -419,7 +781,7 @@ int32_t DistributedInputClient::NotifyStopDScreen(const std::string &networkId,
|
||||
|
||||
sptr<IDistributedSinkInput> DistributedInputClient::GetRemoteDInput(const std::string &networkId) const
|
||||
{
|
||||
DHLOGI("start, networkId = %s", GetAnonyString(networkId).c_str());
|
||||
DHLOGI("GetRemoteDInput start, networkId = %s", GetAnonyString(networkId).c_str());
|
||||
if (networkId.empty()) {
|
||||
DHLOGE("networkId is empty");
|
||||
return nullptr;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "distributed_hardware_log.h"
|
||||
|
||||
#include "dinput_errcode.h"
|
||||
#include "dinput_utils_tool.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
|
||||
@@ -58,7 +58,7 @@ int32_t DistributedInputSinkStub::OnRemoteRequest(uint32_t code, MessageParcel &
|
||||
|
||||
int32_t DistributedInputSinkStub::InitInner(MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
DHLOGI("start");
|
||||
DHLOGI("DistributedInputSinkStub InitInner start");
|
||||
int32_t ret = Init();
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("DistributedInputSinkStub write ret failed");
|
||||
|
||||
@@ -71,19 +71,19 @@ int32_t DistributedInputSourceProxy::RegisterDistributedHardware(const std::stri
|
||||
}
|
||||
if (!data.WriteString(devId)) {
|
||||
DHLOGE("DistributedInputSourceProxy write devId failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(dhId)) {
|
||||
DHLOGE("DistributedInputSourceProxy write dhId failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(parameters)) {
|
||||
DHLOGE("DistributedInputSourceProxy write parameters failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
DHLOGE("DistributedInputSourceProxy write callback failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_FAIL;
|
||||
@@ -104,15 +104,15 @@ int32_t DistributedInputSourceProxy::UnregisterDistributedHardware(const std::st
|
||||
}
|
||||
if (!data.WriteString(devId)) {
|
||||
DHLOGE("DistributedInputSourceProxy write devId failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(dhId)) {
|
||||
DHLOGE("DistributedInputSourceProxy write dhId failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
DHLOGE("DistributedInputSourceProxy write callback failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_FAIL;
|
||||
@@ -124,8 +124,7 @@ int32_t DistributedInputSourceProxy::UnregisterDistributedHardware(const std::st
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::PrepareRemoteInput(
|
||||
const std::string& deviceId, sptr<IPrepareDInputCallback> callback,
|
||||
sptr<IAddWhiteListInfosCallback> addWhiteListCallback)
|
||||
const std::string &deviceId, sptr<IPrepareDInputCallback> callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
@@ -134,28 +133,25 @@ int32_t DistributedInputSourceProxy::PrepareRemoteInput(
|
||||
}
|
||||
if (!data.WriteString(deviceId)) {
|
||||
DHLOGE("DistributedInputSourceProxy write deviceId failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
DHLOGE("DistributedInputSourceProxy write callback failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(addWhiteListCallback->AsObject())) {
|
||||
DHLOGE("DistributedInputSourceProxy write addWhiteListCallback failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_PREPARE_FAIL;
|
||||
bool ret = SendRequest(IDistributedSourceInput::MessageCode::PREPARE_REMOTE_INPUT, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
DHLOGI("PrepareRemoteInput end, result:%d", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::UnprepareRemoteInput(
|
||||
const std::string& deviceId, sptr<IUnprepareDInputCallback> callback,
|
||||
sptr<IDelWhiteListInfosCallback> delWhiteListCallback)
|
||||
int32_t DistributedInputSourceProxy::UnprepareRemoteInput(const std::string &deviceId,
|
||||
sptr<IUnprepareDInputCallback> callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
@@ -164,15 +160,11 @@ int32_t DistributedInputSourceProxy::UnprepareRemoteInput(
|
||||
}
|
||||
if (!data.WriteString(deviceId)) {
|
||||
DHLOGE("DistributedInputSourceProxy write deviceId failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
DHLOGE("DistributedInputSourceProxy write callback failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(delWhiteListCallback->AsObject())) {
|
||||
DHLOGE("DistributedInputSourceProxy write delWhiteListCallback failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_FAIL;
|
||||
@@ -180,12 +172,14 @@ int32_t DistributedInputSourceProxy::UnprepareRemoteInput(
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
DHLOGE("UnprepareRemoteInput end, result=%d", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::StartRemoteInput(
|
||||
const std::string& deviceId, const uint32_t& inputTypes, sptr<IStartDInputCallback> callback)
|
||||
{
|
||||
DHLOGI("source proxy StartRemoteInput start");
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("DistributedInputSourceProxy write token valid failed");
|
||||
@@ -193,15 +187,15 @@ int32_t DistributedInputSourceProxy::StartRemoteInput(
|
||||
}
|
||||
if (!data.WriteString(deviceId)) {
|
||||
DHLOGE("DistributedInputSourceProxy write deviceId failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteUint32(inputTypes)) {
|
||||
DHLOGE("DistributedInputSourceProxy write inputTypes failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
DHLOGE("DistributedInputSourceProxy write callback failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL;
|
||||
@@ -209,6 +203,7 @@ int32_t DistributedInputSourceProxy::StartRemoteInput(
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
DHLOGI("source proxy StartRemoteInput end, result:%d.", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -222,15 +217,15 @@ int32_t DistributedInputSourceProxy::StopRemoteInput(
|
||||
}
|
||||
if (!data.WriteString(deviceId)) {
|
||||
DHLOGE("DistributedInputSourceProxy write deviceId failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteUint32(inputTypes)) {
|
||||
DHLOGE("DistributedInputSourceProxy write inputTypes failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
DHLOGE("DistributedInputSourceProxy write callback failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL;
|
||||
@@ -241,6 +236,295 @@ int32_t DistributedInputSourceProxy::StopRemoteInput(
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string& srcId, const std::string& sinkId,
|
||||
const uint32_t& inputTypes, sptr<IStartDInputCallback> callback)
|
||||
{
|
||||
DHLOGI("source proxy StartRemoteInput start");
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("DistributedInputSourceProxy write token valid failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(srcId)) {
|
||||
DHLOGE("DistributedInputSourceProxy write srcId failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(sinkId)) {
|
||||
DHLOGE("DistributedInputSourceProxy write sinkId failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteUint32(inputTypes)) {
|
||||
DHLOGE("DistributedInputSourceProxy write inputTypes failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
DHLOGE("DistributedInputSourceProxy write callback failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL;
|
||||
bool ret = SendRequest(IDistributedSourceInput::MessageCode::START_RELAY_TYPE_REMOTE_INPUT, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
DHLOGI("source proxy StartRemoteInput end, result:%d.", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string& srcId, const std::string& sinkId,
|
||||
const uint32_t& inputTypes, sptr<IStopDInputCallback> callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("DistributedInputSourceProxy write token valid failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(srcId)) {
|
||||
DHLOGE("DistributedInputSourceProxy write srcId failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(sinkId)) {
|
||||
DHLOGE("DistributedInputSourceProxy write sinkId failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteUint32(inputTypes)) {
|
||||
DHLOGE("DistributedInputSourceProxy write inputTypes failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
DHLOGE("DistributedInputSourceProxy write callback failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL;
|
||||
bool ret = SendRequest(IDistributedSourceInput::MessageCode::STOP_RELAY_TYPE_REMOTE_INPUT, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::PrepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IPrepareDInputCallback> callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("DistributedInputSourceProxy write token valid failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(srcId)) {
|
||||
DHLOGE("Write PrepareRemoteInput relay srcid to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(sinkId)) {
|
||||
DHLOGE("Write PrepareRemoteInput relay sinkid to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
DHLOGE("Write PrepareRemoteInput relay callback to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_PREPARE_FAIL;
|
||||
bool ret = SendRequest(IDistributedSourceInput::MessageCode::PREPARE_RELAY_REMOTE_INPUT, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
DHLOGI("PrepareRemoteInput relay result:%d", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IUnprepareDInputCallback> callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("DistributedInputSourceProxy write token valid failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(srcId)) {
|
||||
DHLOGE("Write UnprepareRemoteInput relay srcid to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(sinkId)) {
|
||||
DHLOGE("Write UnprepareRemoteInput relay sinkid to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
DHLOGE("Write UnprepareRemoteInput relay callback to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_FAIL;
|
||||
bool ret = SendRequest(IDistributedSourceInput::MessageCode::UNPREPARE_RELAY_REMOTE_INPUT, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
DHLOGI("UnprepareRemoteInput relay result:%d", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("DistributedInputSourceProxy write token valid failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(sinkId)) {
|
||||
DHLOGE("Write StartRemoteInput dhid sinkId to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(dhIds.size())) {
|
||||
DHLOGE("Write StartRemoteInput dhid size to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
for (auto it = dhIds.begin(); it != dhIds.end(); ++it) {
|
||||
if (!data.WriteString(*it)) {
|
||||
DHLOGE("Write StartRemoteInput dhid dhid to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
DHLOGE("Write StartRemoteInput dhid callback to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL;
|
||||
bool ret = SendRequest(IDistributedSourceInput::MessageCode::START_DHID_REMOTE_INPUT, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
DHLOGI("Source proxy StartRemoteInput dhid end, result:%d.", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("DistributedInputSourceProxy write token valid failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(sinkId)) {
|
||||
DHLOGE("Write StopRemoteInput dhid sinkId to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(dhIds.size())) {
|
||||
DHLOGE("Write StopRemoteInput dhid size to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
for (auto it = dhIds.begin(); it != dhIds.end(); ++it) {
|
||||
if (!data.WriteString(*it)) {
|
||||
DHLOGE("Write StopRemoteInput dhid dhid to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
DHLOGE("Write StopRemoteInput dhid callback to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL;
|
||||
bool ret = SendRequest(IDistributedSourceInput::MessageCode::STOP_DHID_REMOTE_INPUT, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
DHLOGI("Source proxy StopRemoteInput dhid end, result:%d.", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("DistributedInputSourceProxy relay dhid write token valid failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(srcId)) {
|
||||
DHLOGE("Write StartRemoteInput relay dhid srcId to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(sinkId)) {
|
||||
DHLOGE("Write StartRemoteInput relay dhid sinkId to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(dhIds.size())) {
|
||||
DHLOGE("Write StartRemoteInput relay dhid size to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
for (auto it = dhIds.begin(); it != dhIds.end(); ++it) {
|
||||
if (!data.WriteString(*it)) {
|
||||
DHLOGE("Write StartRemoteInput relay dhid dhid to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
DHLOGE("Write StartRemoteInput relay dhid callback to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL;
|
||||
bool ret = SendRequest(IDistributedSourceInput::MessageCode::START_RELAY_DHID_REMOTE_INPUT, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
DHLOGI("Source proxy StartRemoteInput relay dhid end, result:%d.", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("DistributedInputSourceProxy write token valid failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(srcId)) {
|
||||
DHLOGE("Write StopRemoteInput relay dhid srcId to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(sinkId)) {
|
||||
DHLOGE("Write StopRemoteInput relay dhid sinkId to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(dhIds.size())) {
|
||||
DHLOGE("Write StopRemoteInput relay dhid size to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
for (auto it = dhIds.begin(); it != dhIds.end(); ++it) {
|
||||
if (!data.WriteString(*it)) {
|
||||
DHLOGE("Write StopRemoteInput relay dhid dhid to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
DHLOGE("Write StopRemoteInput relay dhid callback to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL;
|
||||
bool ret = SendRequest(IDistributedSourceInput::MessageCode::STOP_RELAY_DHID_REMOTE_INPUT, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
DHLOGI("Source proxy StopRemoteInput relay dhid end, result:%d.", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::IsStartDistributedInput(
|
||||
const uint32_t& inputType, sptr<IStartDInputServerCallback> callback)
|
||||
{
|
||||
@@ -251,11 +535,11 @@ int32_t DistributedInputSourceProxy::IsStartDistributedInput(
|
||||
}
|
||||
if (!data.WriteUint32(inputType)) {
|
||||
DHLOGE("DistributedInputSourceProxy write inputType failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
DHLOGE("DistributedInputSourceProxy write callback failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_IS_START_INPUT_FAIL;
|
||||
@@ -266,16 +550,183 @@ int32_t DistributedInputSourceProxy::IsStartDistributedInput(
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DistributedInputSourceProxy::SendRequest(
|
||||
const IDistributedSourceInput::MessageCode code, MessageParcel &data, MessageParcel &reply)
|
||||
int32_t DistributedInputSourceProxy::RegisterAddWhiteListCallback(sptr<IAddWhiteListInfosCallback> addWhiteListCallback)
|
||||
{
|
||||
if (addWhiteListCallback == nullptr) {
|
||||
DHLOGE("DistributedInputSourceProxy addWhiteListCallback is null.");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("DistributedInputSourceProxy write token valid failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(addWhiteListCallback->AsObject())) {
|
||||
DHLOGE("DistributedInputSourceProxy write callback failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_WHITELIST_FAIL;
|
||||
bool ret = SendRequest(IDistributedSourceInput::MessageCode::REGISTER_ADD_WHITE_LIST_CB_REMOTE_INPUT, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::RegisterDelWhiteListCallback(sptr<IDelWhiteListInfosCallback> delWhiteListCallback)
|
||||
{
|
||||
if (delWhiteListCallback == nullptr) {
|
||||
DHLOGE("DistributedInputSourceProxy delWhiteListCallback is null.");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("DistributedInputSourceProxy write token valid failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(delWhiteListCallback->AsObject())) {
|
||||
DHLOGE("DistributedInputSourceProxy write callback failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_WHITELIST_FAIL;
|
||||
bool ret = SendRequest(IDistributedSourceInput::MessageCode::REGISTER_DEL_WHITE_LIST_CB_REMOTE_INPUT, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::RegisterInputNodeListener(sptr<InputNodeListener> listener)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("DistributedInputSourceProxy write token valid failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(listener->AsObject())) {
|
||||
DHLOGE("DistributedInputSourceProxy write callback failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_NODE_LISTENER_FAIL;
|
||||
bool ret = SendRequest(IDistributedSourceInput::MessageCode::REGISTER_NODE_LISTENER, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::UnregisterInputNodeListener(sptr<InputNodeListener> listener)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("DistributedInputSourceProxy write token valid failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
|
||||
if (!data.WriteRemoteObject(listener->AsObject())) {
|
||||
DHLOGE("DistributedInputSourceProxy write callback failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_NODE_LISTENER_FAIL;
|
||||
bool ret = SendRequest(IDistributedSourceInput::MessageCode::UNREGISTER_NODE_LISTENER, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::SyncNodeInfoRemoteInput(const std::string &userDevId, const std::string &dhid,
|
||||
const std::string &nodeDesc)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("DistributedInputSourceProxy write token valid failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(userDevId)) {
|
||||
DHLOGE("write SyncNodeInfoRemoteInput userDevId to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(dhid)) {
|
||||
DHLOGE("write SyncNodeInfoRemoteInput dhid to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(nodeDesc)) {
|
||||
DHLOGE("write SyncNodeInfoRemoteInput nodeDesc to parcel failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_SYNC_NODE_FAIL;
|
||||
bool ret = SendRequest(IDistributedSourceInput::MessageCode::SYNC_NODE_INFO_REMOTE_INPUT, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
DHLOGI("SyncNodeInfoRemoteInput end, result=%d", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::RegisterSimulationEventListener(sptr<ISimulationEventListener> listener)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("RegisterSimulationEventListener write token valid failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
|
||||
if (!data.WriteRemoteObject(listener->AsObject())) {
|
||||
DHLOGE("RegisterSimulationEventListener write callback failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_SIMULATION_LISTENER_FAIL;
|
||||
bool ret = SendRequest(IDistributedSourceInput::MessageCode::REGISTER_SIMULATION_EVENT_LISTENER, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceProxy::UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("UnregisterSimulationEventListener write token valid failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
|
||||
if (!data.WriteRemoteObject(listener->AsObject())) {
|
||||
DHLOGE("UnregisterSimulationEventListener write callback failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_SIMULATION_LISTENER_FAIL;
|
||||
bool ret = SendRequest(IDistributedSourceInput::MessageCode::UNREGISTER_SIMULATION_EVENT_LISTENER, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DistributedInputSourceProxy::SendRequest(const IDistributedSourceInput::MessageCode code, MessageParcel &data,
|
||||
MessageParcel &reply)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
DHLOGE("DistributedInputSourceProxy SendRequest remote is null.");
|
||||
return false;
|
||||
}
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
int32_t result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
|
||||
if (result != DH_SUCCESS) {
|
||||
DHLOGE("DistributedInputSourceProxy SendRequest error, result:%d.", result);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -79,13 +79,10 @@ int32_t DistributedInputSourceStub::HandleUnregisterDistributedHardware(MessageP
|
||||
int32_t DistributedInputSourceStub::HandlePrepareRemoteInput(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::string deviceId = data.ReadString();
|
||||
sptr<IPrepareDInputCallback> callback =
|
||||
iface_cast<IPrepareDInputCallback>(data.ReadRemoteObject());
|
||||
sptr<IAddWhiteListInfosCallback> addCallback =
|
||||
iface_cast<IAddWhiteListInfosCallback>(data.ReadRemoteObject());
|
||||
int32_t ret = PrepareRemoteInput(deviceId, callback, addCallback);
|
||||
sptr<IPrepareDInputCallback> callback = iface_cast<IPrepareDInputCallback>(data.ReadRemoteObject());
|
||||
int32_t ret = PrepareRemoteInput(deviceId, callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("DistributedInputSourceStub prepareRemoteInput write ret failed");
|
||||
DHLOGE("HandlePrepareRemoteInput write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
@@ -94,14 +91,11 @@ int32_t DistributedInputSourceStub::HandlePrepareRemoteInput(MessageParcel &data
|
||||
int32_t DistributedInputSourceStub::HandleUnprepareRemoteInput(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::string deviceId = data.ReadString();
|
||||
sptr<IUnprepareDInputCallback> callback =
|
||||
iface_cast<IUnprepareDInputCallback>(data.ReadRemoteObject());
|
||||
sptr<IDelWhiteListInfosCallback> delCallback =
|
||||
iface_cast<IDelWhiteListInfosCallback>(data.ReadRemoteObject());
|
||||
int32_t ret = UnprepareRemoteInput(deviceId, callback, delCallback);
|
||||
sptr<IUnprepareDInputCallback> callback = iface_cast<IUnprepareDInputCallback>(data.ReadRemoteObject());
|
||||
int32_t ret = UnprepareRemoteInput(deviceId, callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("DistributedInputSourceStub unprepareRemoteInput write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
DHLOGE("HandleUnprepareRemoteInput write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
@@ -114,7 +108,7 @@ int32_t DistributedInputSourceStub::HandleStartRemoteInput(MessageParcel &data,
|
||||
int32_t ret = StartRemoteInput(deviceId, inputTypes, callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("DistributedInputSourceStub startRemoteInput write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
@@ -127,7 +121,143 @@ int32_t DistributedInputSourceStub::HandleStopRemoteInput(MessageParcel &data, M
|
||||
int32_t ret = StopRemoteInput(deviceId, inputTypes, callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("DistributedInputSourceStub stopRemoteInput write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceStub::HandleStartRelayTypeRemoteInput(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::string srcId = data.ReadString();
|
||||
std::string sinkId = data.ReadString();
|
||||
uint32_t inputTypes = data.ReadUint32();
|
||||
sptr<IStartDInputCallback> callback = iface_cast<IStartDInputCallback>(data.ReadRemoteObject());
|
||||
int32_t ret = StartRemoteInput(srcId, sinkId, inputTypes, callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("DistributedInputSourceStub write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceStub::HandleStopRelayTypeRemoteInput(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::string srcId = data.ReadString();
|
||||
std::string sinkId = data.ReadString();
|
||||
uint32_t inputTypes = data.ReadUint32();
|
||||
sptr<IStopDInputCallback> callback = iface_cast<IStopDInputCallback>(data.ReadRemoteObject());
|
||||
int32_t ret = StopRemoteInput(srcId, sinkId, inputTypes, callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("DistributedInputSourceStub write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceStub::HandlePrepareRelayRemoteInput(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::string srcId = data.ReadString();
|
||||
std::string sinkId = data.ReadString();
|
||||
sptr<IPrepareDInputCallback> callback = iface_cast<IPrepareDInputCallback>(data.ReadRemoteObject());
|
||||
int32_t ret = PrepareRemoteInput(srcId, sinkId, callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("HandlePrepareRelayRemoteInput write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceStub::HandleUnprepareRelayRemoteInput(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::string srcId = data.ReadString();
|
||||
std::string sinkId = data.ReadString();
|
||||
sptr<IUnprepareDInputCallback> callback = iface_cast<IUnprepareDInputCallback>(data.ReadRemoteObject());
|
||||
int32_t ret = UnprepareRemoteInput(srcId, sinkId, callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("HandleUnprepareRelayRemoteInput write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceStub::HandleStartDhidRemoteInput(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::string sinkId = data.ReadString();
|
||||
|
||||
std::vector<std::string> tempVector;
|
||||
uint32_t vecSize = data.ReadUint32();
|
||||
for (uint32_t i = 0; i < vecSize; i++) {
|
||||
std::string dhid = data.ReadString();
|
||||
tempVector.push_back(dhid);
|
||||
}
|
||||
|
||||
sptr<IStartStopDInputsCallback> callback = iface_cast<IStartStopDInputsCallback>(data.ReadRemoteObject());
|
||||
int32_t ret = StartRemoteInput(sinkId, tempVector, callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("HandleStartDhidRemoteInput write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceStub::HandleStopDhidRemoteInput(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::string sinkId = data.ReadString();
|
||||
|
||||
std::vector<std::string> tempVector;
|
||||
uint32_t vecSize = data.ReadUint32();
|
||||
for (uint32_t i = 0; i < vecSize; i++) {
|
||||
std::string dhid = data.ReadString();
|
||||
tempVector.push_back(dhid);
|
||||
}
|
||||
|
||||
sptr<IStartStopDInputsCallback> callback = iface_cast<IStartStopDInputsCallback>(data.ReadRemoteObject());
|
||||
int32_t ret = StopRemoteInput(sinkId, tempVector, callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("HandleStopDhidRemoteInput write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceStub::HandleStartRelayDhidRemoteInput(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::string srcId = data.ReadString();
|
||||
std::string sinkId = data.ReadString();
|
||||
|
||||
std::vector<std::string> tempVector;
|
||||
uint32_t vecSize = data.ReadUint32();
|
||||
for (uint32_t i = 0; i < vecSize; i++) {
|
||||
std::string dhid = data.ReadString();
|
||||
tempVector.push_back(dhid);
|
||||
}
|
||||
|
||||
sptr<IStartStopDInputsCallback> callback = iface_cast<IStartStopDInputsCallback>(data.ReadRemoteObject());
|
||||
int32_t ret = StartRemoteInput(srcId, sinkId, tempVector, callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("HandleStartRelayDhidRemoteInput write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceStub::HandleStopRelayDhidRemoteInput(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::string srcId = data.ReadString();
|
||||
std::string sinkId = data.ReadString();
|
||||
|
||||
std::vector<std::string> tempVector;
|
||||
uint32_t vecSize = data.ReadUint32();
|
||||
for (uint32_t i = 0; i < vecSize; i++) {
|
||||
std::string dhid = data.ReadString();
|
||||
tempVector.push_back(dhid);
|
||||
}
|
||||
|
||||
sptr<IStartStopDInputsCallback> callback = iface_cast<IStartStopDInputsCallback>(data.ReadRemoteObject());
|
||||
int32_t ret = StopRemoteInput(srcId, sinkId, tempVector, callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("HandleStopRelayDhidRemoteInput write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
@@ -139,13 +269,101 @@ int32_t DistributedInputSourceStub::HandleIsStartDistributedInput(MessageParcel
|
||||
int32_t ret = IsStartDistributedInput(inputType, callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("DistributedInputSourceStub isStartDistributedInput write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
int32_t DistributedInputSourceStub::HandleSyncNodeInfoRemoteInput(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::string userDevId = data.ReadString();
|
||||
std::string dhid = data.ReadString();
|
||||
std::string nodeDesc = data.ReadString();
|
||||
|
||||
int32_t ret = SyncNodeInfoRemoteInput(userDevId, dhid, nodeDesc);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("HandleSyncNodeInfoRemoteInput write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceStub::HandleRegisterAddWhiteListCallback(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
sptr<IAddWhiteListInfosCallback> callback = iface_cast<IAddWhiteListInfosCallback>(data.ReadRemoteObject());
|
||||
int32_t ret = RegisterAddWhiteListCallback(callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("HandleRegisterAddWhiteListCallback write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceStub::HandleRegisterDelWhiteListCallback(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
sptr<IDelWhiteListInfosCallback> callback = iface_cast<IDelWhiteListInfosCallback>(data.ReadRemoteObject());
|
||||
if (callback == nullptr) {
|
||||
DHLOGI("HandleRegisterDelWhiteListCallback callback is null");
|
||||
}
|
||||
|
||||
int32_t ret = RegisterDelWhiteListCallback(callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("HandleRegisterDelWhiteListCallback write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceStub::HandleRegisterInputNodeListener(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
sptr<InputNodeListener> callback = iface_cast<InputNodeListener>(data.ReadRemoteObject());
|
||||
int32_t ret = RegisterInputNodeListener(callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("HandleRegisterInputNodeListener write ret failed");
|
||||
return ERR_DH_INPUT_SOURCE_STUB_REGISTER_NODE_LISTENER_FAIL;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceStub::HandleUnRegisterInputNodeListener(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
sptr<InputNodeListener> callback = iface_cast<InputNodeListener>(data.ReadRemoteObject());
|
||||
int32_t ret = RegisterInputNodeListener(callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("HandleUnRegisterInputNodeListener write ret failed");
|
||||
return ERR_DH_INPUT_SOURCE_STUB_UNREGISTER_NODE_LISTENER_FAIL;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceStub::HandleRegisterSimulationEventListener(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
sptr<ISimulationEventListener> callback = iface_cast<ISimulationEventListener>(data.ReadRemoteObject());
|
||||
int32_t ret = RegisterSimulationEventListener(callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("HandleRegisterSimulationEventListener write ret failed, ret = %d", ret);
|
||||
return ERR_DH_INPUT_SOURCE_STUB_REGISTER_SIMULATION_EVENT_LISTENER_FAIL;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceStub::HandleUnregisterSimulationEventListener(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
sptr<ISimulationEventListener> callback = iface_cast<ISimulationEventListener>(data.ReadRemoteObject());
|
||||
int32_t ret = UnregisterSimulationEventListener(callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("HandleUnregisterSimulationEventListener write ret failed, ret = %d", ret);
|
||||
return ERR_DH_INPUT_SOURCE_STUB_UNREGISTER_SIMULATION_EVENT_LISTENER_FAIL;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceStub::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
if (data.ReadInterfaceToken() != GetDescriptor()) {
|
||||
DHLOGE("DistributedInputSourceStub read token valid failed");
|
||||
@@ -176,6 +394,51 @@ int32_t DistributedInputSourceStub::OnRemoteRequest(uint32_t code, MessageParcel
|
||||
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::STOP_REMOTE_INPUT): {
|
||||
return HandleStopRemoteInput(data, reply);
|
||||
}
|
||||
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::START_RELAY_TYPE_REMOTE_INPUT): {
|
||||
return HandleStartRelayTypeRemoteInput(data, reply);
|
||||
}
|
||||
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::STOP_RELAY_TYPE_REMOTE_INPUT): {
|
||||
return HandleStopRelayTypeRemoteInput(data, reply);
|
||||
}
|
||||
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::PREPARE_RELAY_REMOTE_INPUT): {
|
||||
return HandlePrepareRelayRemoteInput(data, reply);
|
||||
}
|
||||
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::UNPREPARE_RELAY_REMOTE_INPUT): {
|
||||
return HandleUnprepareRelayRemoteInput(data, reply);
|
||||
}
|
||||
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::START_DHID_REMOTE_INPUT): {
|
||||
return HandleStartDhidRemoteInput(data, reply);
|
||||
}
|
||||
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::STOP_DHID_REMOTE_INPUT): {
|
||||
return HandleStopDhidRemoteInput(data, reply);
|
||||
}
|
||||
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::START_RELAY_DHID_REMOTE_INPUT): {
|
||||
return HandleStartRelayDhidRemoteInput(data, reply);
|
||||
}
|
||||
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::STOP_RELAY_DHID_REMOTE_INPUT): {
|
||||
return HandleStopRelayDhidRemoteInput(data, reply);
|
||||
}
|
||||
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::REGISTER_ADD_WHITE_LIST_CB_REMOTE_INPUT): {
|
||||
return HandleRegisterAddWhiteListCallback(data, reply);
|
||||
}
|
||||
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::REGISTER_DEL_WHITE_LIST_CB_REMOTE_INPUT): {
|
||||
return HandleRegisterDelWhiteListCallback(data, reply);
|
||||
}
|
||||
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::REGISTER_NODE_LISTENER): {
|
||||
return HandleRegisterInputNodeListener(data, reply);
|
||||
}
|
||||
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::UNREGISTER_NODE_LISTENER): {
|
||||
return HandleUnRegisterInputNodeListener(data, reply);
|
||||
}
|
||||
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::REGISTER_SIMULATION_EVENT_LISTENER): {
|
||||
return HandleRegisterSimulationEventListener(data, reply);
|
||||
}
|
||||
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::UNREGISTER_SIMULATION_EVENT_LISTENER): {
|
||||
return HandleUnregisterSimulationEventListener(data, reply);
|
||||
}
|
||||
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::SYNC_NODE_INFO_REMOTE_INPUT): {
|
||||
return HandleSyncNodeInfoRemoteInput(data, reply);
|
||||
}
|
||||
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::ISSTART_REMOTE_INPUT): {
|
||||
return HandleIsStartDistributedInput(data, reply);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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 "input_node_listener_proxy.h"
|
||||
|
||||
#include "distributed_hardware_log.h"
|
||||
#include "ipc_types.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
InputNodeListenerProxy::InputNodeListenerProxy(const sptr<IRemoteObject> &object)
|
||||
: IRemoteProxy<InputNodeListener>(object)
|
||||
{
|
||||
}
|
||||
|
||||
InputNodeListenerProxy::~InputNodeListenerProxy() {}
|
||||
|
||||
void InputNodeListenerProxy::OnNodeOnLine(const std::string srcDevId, const std::string sinkDevId,
|
||||
const std::string sinkNodeId, const std::string sinkNodeDesc)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("InputNodeListenerProxy write token valid failed");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteString(srcDevId)) {
|
||||
DHLOGE("InputNodeListenerProxy write srcDevId failed");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteString(sinkDevId)) {
|
||||
DHLOGE("InputNodeListenerProxy write sinkDevId failed");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteString(sinkNodeId)) {
|
||||
DHLOGE("InputNodeListenerProxy write sinkNodeId failed");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteString(sinkNodeDesc)) {
|
||||
DHLOGE("InputNodeListenerProxy write sinkNodeDesc failed");
|
||||
return;
|
||||
}
|
||||
int32_t ret = remote->SendRequest(static_cast<int32_t>(InputNodeListener::Message::RESULT_ON), data, reply, option);
|
||||
if (ret != 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void InputNodeListenerProxy::OnNodeOffLine(const std::string srcDevId, const std::string sinkDevId,
|
||||
const std::string sinkNodeId)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("InputNodeListenerProxy write token valid failed");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteString(srcDevId)) {
|
||||
DHLOGE("InputNodeListenerProxy write srcDevId failed");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteString(sinkDevId)) {
|
||||
DHLOGE("InputNodeListenerProxy write sinkDevId failed");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteString(sinkNodeId)) {
|
||||
DHLOGE("InputNodeListenerProxy write sinkNodeId failed");
|
||||
return;
|
||||
}
|
||||
int32_t ret =
|
||||
remote->SendRequest(static_cast<int32_t>(InputNodeListener::Message::RESULT_OFF), data, reply, option);
|
||||
if (ret != 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 "input_node_listener_stub.h"
|
||||
|
||||
#include "distributed_hardware_log.h"
|
||||
#include "string_ex.h"
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_errcode.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
InputNodeListenerStub::InputNodeListenerStub() {}
|
||||
|
||||
InputNodeListenerStub::~InputNodeListenerStub() {}
|
||||
|
||||
int32_t InputNodeListenerStub::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
if (data.ReadInterfaceToken() != GetDescriptor()) {
|
||||
DHLOGE("InputNodeListenerStub read token valid failed");
|
||||
return ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL;
|
||||
}
|
||||
InputNodeListener::Message msgCode = static_cast<InputNodeListener::Message>(code);
|
||||
switch (msgCode) {
|
||||
case InputNodeListener::Message::RESULT_ON: {
|
||||
std::string srcDevId = data.ReadString();
|
||||
std::string sinkDevId = data.ReadString();
|
||||
std::string sinkNodeId = data.ReadString();
|
||||
std::string sinkNodeDesc = data.ReadString();
|
||||
OnNodeOnLine(srcDevId, sinkDevId, sinkNodeId, sinkNodeDesc);
|
||||
break;
|
||||
}
|
||||
case InputNodeListener::Message::RESULT_OFF: {
|
||||
std::string srcDevId = data.ReadString();
|
||||
std::string sinkDevId = data.ReadString();
|
||||
std::string sinkNodeId = data.ReadString();
|
||||
OnNodeOffLine(srcDevId, sinkDevId, sinkNodeId);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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 "simulation_event_listener_proxy.h"
|
||||
|
||||
#include "distributed_hardware_log.h"
|
||||
#include "dinput_errcode.h"
|
||||
#include "ipc_types.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
SimulationEventListenerProxy::SimulationEventListenerProxy(const sptr<IRemoteObject> &object)
|
||||
: IRemoteProxy<ISimulationEventListener>(object)
|
||||
{
|
||||
}
|
||||
|
||||
SimulationEventListenerProxy::~SimulationEventListenerProxy() {}
|
||||
|
||||
int32_t SimulationEventListenerProxy::OnSimulationEvent(uint32_t type, uint32_t code, int32_t value)
|
||||
{
|
||||
int32_t result = ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
DHLOGE("SimulationEventListenerProxy get remote failed");
|
||||
return result;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("SimulationEventListenerProxy write token valid failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteInt32(type)) {
|
||||
DHLOGE("SimulationEventListenerProxy write type failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteInt32(code)) {
|
||||
DHLOGE("SimulationEventListenerProxy write code failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteInt32(value)) {
|
||||
DHLOGE("SimulationEventListenerProxy write value failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
int32_t ret =
|
||||
remote->SendRequest(static_cast<int32_t>(ISimulationEventListener::Message::RESULT_ON), data, reply, option);
|
||||
if (ret == DH_SUCCESS) {
|
||||
result = reply.ReadInt32();
|
||||
} else {
|
||||
DHLOGE("SimulationEventListenerProxy SendRequest error:%d", ret);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 "simulation_event_listener_stub.h"
|
||||
|
||||
#include "distributed_hardware_log.h"
|
||||
#include "string_ex.h"
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_errcode.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
SimulationEventListenerStub::SimulationEventListenerStub() {}
|
||||
|
||||
SimulationEventListenerStub::~SimulationEventListenerStub() {}
|
||||
|
||||
int32_t SimulationEventListenerStub::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
if (data.ReadInterfaceToken() != GetDescriptor()) {
|
||||
DHLOGE("SimulationEventListenerStub read token valid failed");
|
||||
return ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL;
|
||||
}
|
||||
ISimulationEventListener::Message msgCode = static_cast<ISimulationEventListener::Message>(code);
|
||||
switch (msgCode) {
|
||||
case ISimulationEventListener::Message::RESULT_ON: {
|
||||
uint32_t eventType = data.ReadInt32();
|
||||
uint32_t eventCode = data.ReadInt32();
|
||||
int32_t eventValue = data.ReadInt32();
|
||||
int32_t ret = OnSimulationEvent(eventType, eventCode, eventValue);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("DistributedInputSourceStub write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 "start_stop_d_inputs_call_back_proxy.h"
|
||||
|
||||
#include "ipc_types.h"
|
||||
#include "parcel.h"
|
||||
|
||||
#include "distributed_hardware_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
StartStopDInputsCallbackProxy::StartStopDInputsCallbackProxy(const sptr<IRemoteObject> &object)
|
||||
: IRemoteProxy<IStartStopDInputsCallback>(object)
|
||||
{
|
||||
}
|
||||
|
||||
StartStopDInputsCallbackProxy::~StartStopDInputsCallbackProxy() {}
|
||||
|
||||
void StartStopDInputsCallbackProxy::OnResultDhids(const std::string &devId, const int32_t &status)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("StartStopDInputsCallbackProxy write token valid failed");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteString(devId)) {
|
||||
DHLOGE("StartStopDInputsCallbackProxy write devId valid failed");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteInt32(status)) {
|
||||
DHLOGE("StartStopDInputsCallbackProxy write status valid failed");
|
||||
return;
|
||||
}
|
||||
int32_t ret = remote->SendRequest(static_cast<int32_t>(IStartStopDInputsCallback::Message::RESULT_STRING),
|
||||
data, reply, option);
|
||||
if (ret != 0) {
|
||||
DHLOGE("OnResultDhids error, ret = %d", ret);
|
||||
return;
|
||||
}
|
||||
DHLOGE("OnResultDhids success.");
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 "start_stop_d_inputs_call_back_stub.h"
|
||||
|
||||
#include "string_ex.h"
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_errcode.h"
|
||||
#include "distributed_hardware_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
StartStopDInputsCallbackStub::StartStopDInputsCallbackStub() {}
|
||||
|
||||
StartStopDInputsCallbackStub::~StartStopDInputsCallbackStub() {}
|
||||
|
||||
int32_t StartStopDInputsCallbackStub::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
std::u16string descriptor = data.ReadInterfaceToken();
|
||||
if (descriptor != IStartStopDInputsCallback::GetDescriptor()) {
|
||||
return ERR_DH_INPUT_IPC_INVALID_DESCRIPTOR;
|
||||
}
|
||||
IStartStopDInputsCallback::Message msgCode = static_cast<IStartStopDInputsCallback::Message>(code);
|
||||
switch (msgCode) {
|
||||
case IStartStopDInputsCallback::Message::RESULT_STRING: {
|
||||
std::string devId = data.ReadString();
|
||||
int32_t status = data.ReadInt32();
|
||||
DHLOGW("OnResultDhids received.");
|
||||
OnResultDhids(devId, status);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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 "ipc_types.h"
|
||||
#include "parcel.h"
|
||||
|
||||
#include "dinput_errcode.h"
|
||||
#include "distributed_hardware_log.h"
|
||||
#include "start_stop_result_call_back_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
StartStopResultCallbackProxy::StartStopResultCallbackProxy(const sptr<IRemoteObject> &object)
|
||||
: IRemoteProxy<IStartStopResultCallback>(object)
|
||||
{
|
||||
}
|
||||
|
||||
StartStopResultCallbackProxy::~StartStopResultCallbackProxy() {}
|
||||
|
||||
void StartStopResultCallbackProxy::OnStart(
|
||||
const std::string &srcId, const std::string &sinkId, std::vector<std::string> &dhIds)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
DHLOGE("StartStopResultCallbackProxy get IRemoteObject failed");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("StartStopResultCallbackProxy write token valid failed");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteString(srcId)) {
|
||||
DHLOGE("StartStopResultCallbackProxy write srcId valid failed");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteString(sinkId)) {
|
||||
DHLOGE("StartStopResultCallbackProxy write sinkId valid failed");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint32(dhIds.size())) {
|
||||
DHLOGE("StartStopResultCallbackProxy write devData size valid failed");
|
||||
return;
|
||||
}
|
||||
for (auto it = dhIds.begin(); it != dhIds.end(); ++it) {
|
||||
if (!data.WriteString(*it)) {
|
||||
DHLOGE("StartStopResultCallbackProxy write devData valid failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ret =
|
||||
remote->SendRequest(static_cast<int32_t>(IStartStopResultCallback::Message::RESULT_START), data, reply, option);
|
||||
if (ret != 0) {
|
||||
DHLOGE("StartStopResultCallbackProxy SendRequest errno:%d", ret);
|
||||
return;
|
||||
}
|
||||
DHLOGE("OnStart success.");
|
||||
}
|
||||
|
||||
void StartStopResultCallbackProxy::OnStop(
|
||||
const std::string &srcId, const std::string &sinkId, std::vector<std::string> &dhIds)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
DHLOGE("StartStopResultCallbackProxy get IRemoteObject failed");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("StartStopResultCallbackProxy write token valid failed");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteString(srcId)) {
|
||||
DHLOGE("StartStopResultCallbackProxy write srcId valid failed");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteString(sinkId)) {
|
||||
DHLOGE("StartStopResultCallbackProxy write sinkId valid failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(dhIds.size())) {
|
||||
DHLOGE("StartStopResultCallbackProxy write devData size valid failed");
|
||||
return;
|
||||
}
|
||||
for (auto it = dhIds.begin(); it != dhIds.end(); ++it) {
|
||||
if (!data.WriteString(*it)) {
|
||||
DHLOGE("StartStopResultCallbackProxy write devData valid failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ret =
|
||||
remote->SendRequest(static_cast<int32_t>(IStartStopResultCallback::Message::RESULT_STOP), data, reply, option);
|
||||
if (ret != 0) {
|
||||
DHLOGE("StartStopResultCallbackProxy SendRequest errno:%d", ret);
|
||||
return;
|
||||
}
|
||||
DHLOGE("OnStop success.");
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 "start_stop_result_call_back_stub.h"
|
||||
|
||||
#include "string_ex.h"
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_errcode.h"
|
||||
#include "distributed_hardware_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
StartStopResultCallbackStub::StartStopResultCallbackStub() {}
|
||||
|
||||
StartStopResultCallbackStub::~StartStopResultCallbackStub() {}
|
||||
|
||||
int32_t StartStopResultCallbackStub::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
std::u16string descriptor = data.ReadInterfaceToken();
|
||||
if (descriptor != IStartStopResultCallback::GetDescriptor()) {
|
||||
return ERR_DH_INPUT_IPC_INVALID_DESCRIPTOR;
|
||||
}
|
||||
IStartStopResultCallback::Message msgCode = static_cast<IStartStopResultCallback::Message>(code);
|
||||
switch (msgCode) {
|
||||
case IStartStopResultCallback::Message::RESULT_START: {
|
||||
std::string srcId = data.ReadString();
|
||||
std::string sinkId = data.ReadString();
|
||||
|
||||
uint32_t size = data.ReadUint32();
|
||||
std::vector<std::string> dhIds;
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
std::string dhId = data.ReadString();
|
||||
dhIds.push_back(dhId);
|
||||
}
|
||||
DHLOGW("OnStart received.");
|
||||
OnStart(srcId, sinkId, dhIds);
|
||||
break;
|
||||
}
|
||||
case IStartStopResultCallback::Message::RESULT_STOP: {
|
||||
std::string srcId = data.ReadString();
|
||||
std::string sinkId = data.ReadString();
|
||||
uint32_t size = data.ReadUint32();
|
||||
std::vector<std::string> dhIds;
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
std::string dhId = data.ReadString();
|
||||
dhIds.push_back(dhId);
|
||||
}
|
||||
DHLOGW("OnStop received.");
|
||||
OnStop(srcId, sinkId, dhIds);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -27,6 +27,9 @@ public:
|
||||
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 void onStartRemoteInputDhid(const int32_t &sessionId, const std::string &strDhids) = 0;
|
||||
virtual void onStopRemoteInputDhid(const int32_t &sessionId, const std::string &strDhids) = 0;
|
||||
virtual ~DInputSinkTransCallback() {}
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
|
||||
@@ -50,9 +50,14 @@ namespace DistributedInput {
|
||||
#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_VECTOR_DHID "dinput_softbus_key_vector_dhid"
|
||||
#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"
|
||||
#define DINPUT_SOFTBUS_KEY_KEYSTATE_DHID "dinput_softbus_key_keystate_dhid"
|
||||
#define DINPUT_SOFTBUS_KEY_KEYSTATE_TYPE "dinput_softbus_key_keystate_type"
|
||||
#define DINPUT_SOFTBUS_KEY_KEYSTATE_CODE "dinput_softbus_key_keystate_code"
|
||||
#define DINPUT_SOFTBUS_KEY_KEYSTATE_VALUE "dinput_softbus_key_keystate_value"
|
||||
|
||||
// json value
|
||||
const uint32_t TRANS_SINK_MSG_ONPREPARE = 1;
|
||||
@@ -61,11 +66,17 @@ namespace DistributedInput {
|
||||
const uint32_t TRANS_SINK_MSG_ONSTOP = 4;
|
||||
const uint32_t TRANS_SINK_MSG_BODY_DATA = 5;
|
||||
const uint32_t TRANS_SINK_MSG_LATENCY = 6;
|
||||
const uint32_t TRANS_SINK_MSG_DHID_ONSTART = 7;
|
||||
const uint32_t TRANS_SINK_MSG_DHID_ONSTOP = 8;
|
||||
const uint32_t TRANS_SINK_MSG_KEY_STATE = 9;
|
||||
|
||||
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;
|
||||
const uint32_t TRANS_SOURCE_MSG_LATENCY = 15;
|
||||
const uint32_t TRANS_SOURCE_MSG_START_TYPE = 13;
|
||||
const uint32_t TRANS_SOURCE_MSG_STOP_TYPE = 14;
|
||||
const uint32_t TRANS_SOURCE_MSG_START_DHID = 15;
|
||||
const uint32_t TRANS_SOURCE_MSG_STOP_DHID = 16;
|
||||
const uint32_t TRANS_SOURCE_MSG_LATENCY = 17;
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -29,6 +29,10 @@ public:
|
||||
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 onResponseStartRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result) = 0;
|
||||
virtual void onResponseStopRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result) = 0;
|
||||
virtual void onResponseKeyState(const std::string deviceId, const std::string &dhid, const uint32_t type,
|
||||
const uint32_t code, const uint32_t value) = 0;
|
||||
virtual void onReceivedEventRemoteInput(const std::string deviceId, const std::string &object) = 0;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
|
||||
@@ -37,7 +37,10 @@ public:
|
||||
static DistributedInputCollector &GetInstance();
|
||||
int32_t Init(std::shared_ptr<AppExecFwk::EventHandler> sinkHandler);
|
||||
void Release();
|
||||
void SetInputTypes(const uint32_t& inputType);
|
||||
void SetSharingTypes(const uint32_t &inputType);
|
||||
void SetSharingDhIds(bool enabled, std::vector<std::string> dhIds);
|
||||
void GetMouseNodePath(std::vector<std::string> dhIds, std::string &mouseNodePath, std::string &dhid);
|
||||
bool GetAllDevicesStoped();
|
||||
|
||||
private:
|
||||
DistributedInputCollector();
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <securec.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <openssl/sha.h>
|
||||
@@ -95,6 +96,7 @@ void *DistributedInputCollector::CollectEventsThread(void *param)
|
||||
void DistributedInputCollector::StartCollectEventsThread()
|
||||
{
|
||||
while (isCollectingEvents_) {
|
||||
memset_s(&mEventBuffer, sizeof(mEventBuffer), 0, sizeof(mEventBuffer));
|
||||
size_t count = inputHub_->StartCollectInputEvents(mEventBuffer, INPUT_EVENT_BUFFER_SIZE);
|
||||
if (count > 0) {
|
||||
DHLOGI("Count: %zu", count);
|
||||
@@ -138,7 +140,7 @@ void DistributedInputCollector::StopCollectEventsThread()
|
||||
DHLOGW("DistributedInputCollector::StopCollectEventsThread exit!");
|
||||
}
|
||||
|
||||
void DistributedInputCollector::SetInputTypes(const uint32_t& inputType)
|
||||
void DistributedInputCollector::SetSharingTypes(const uint32_t &inputType)
|
||||
{
|
||||
inputTypes_ = 0;
|
||||
if ((inputType & static_cast<uint32_t>(DInputDeviceType::MOUSE)) != 0) {
|
||||
@@ -148,7 +150,7 @@ void DistributedInputCollector::SetInputTypes(const uint32_t& inputType)
|
||||
inputTypes_ |= INPUT_DEVICE_CLASS_KEYBOARD;
|
||||
}
|
||||
if ((inputType & static_cast<uint32_t>(DInputDeviceType::TOUCHSCREEN)) != 0) {
|
||||
inputTypes_ |= INPUT_DEVICE_CLASS_TOUCH_MT;
|
||||
inputTypes_ |= INPUT_DEVICE_CLASS_TOUCH_MT | INPUT_DEVICE_CLASS_TOUCH;
|
||||
}
|
||||
|
||||
inputHub_->SetSupportInputType(inputTypes_);
|
||||
@@ -158,6 +160,22 @@ void DistributedInputCollector::Release()
|
||||
{
|
||||
StopCollectEventsThread();
|
||||
}
|
||||
|
||||
void DistributedInputCollector::SetSharingDhIds(bool enabled, std::vector<std::string> dhIds)
|
||||
{
|
||||
inputHub_->SetSharingDevices(enabled, dhIds);
|
||||
}
|
||||
|
||||
void DistributedInputCollector::GetMouseNodePath(
|
||||
std::vector<std::string> dhIds, std::string &mouseNodePath, std::string &dhid)
|
||||
{
|
||||
inputHub_->GetShareMousePathByDhId(dhIds, mouseNodePath, dhid);
|
||||
}
|
||||
|
||||
bool DistributedInputCollector::GetAllDevicesStoped()
|
||||
{
|
||||
return inputHub_->GetAllDevicesStoped();
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <set>
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -54,8 +55,18 @@ public:
|
||||
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);
|
||||
void onStartRemoteInputDhid(const int32_t &sessionId, const std::string &strDhids);
|
||||
void onStopRemoteInputDhid(const int32_t &sessionId, const std::string &strDhids);
|
||||
|
||||
private:
|
||||
DistributedInputSinkManager *sinkManagerObj_;
|
||||
static inline int bit_is_set(const unsigned long *array, int bit)
|
||||
{
|
||||
return !!(array[bit / LONG_BITS] & (1LL << (bit % LONG_BITS)));
|
||||
}
|
||||
void SleepTimeMs();
|
||||
void StringSplitToSet(const std::string &str, const char split, std::set<std::string> &vecStr);
|
||||
void CheckKeyState(const int32_t &sessionId, const std::string &strDhids);
|
||||
};
|
||||
|
||||
class ProjectWindowListener : public PublisherListenerStub {
|
||||
@@ -123,9 +134,15 @@ private:
|
||||
|
||||
std::shared_ptr<AppExecFwk::EventRunner> runner_;
|
||||
std::shared_ptr<DistributedInputSinkEventHandler> handler_;
|
||||
std::mutex mutex_;
|
||||
bool InitAuto();
|
||||
DInputDeviceType inputTypes_;
|
||||
sptr<ProjectWindowListener> projectWindowListener_ = nullptr;
|
||||
std::set<std::string> sharingDhIds_;
|
||||
std::map<int32_t, std::set<std::string>> sharingDhIdsMap_;
|
||||
void StoreStartDhids(int32_t sessionId, const std::set<std::string> &dhIds);
|
||||
void DeleteStopDhids(int32_t sessionId, const std::set<std::string> delDhIds, std::vector<std::string> &stopDhIds);
|
||||
bool IsDeleteDhidExist(int32_t sessionId, const std::string &delstr);
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -15,9 +15,16 @@
|
||||
|
||||
#include "distributed_input_sink_manager.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <fcntl.h>
|
||||
#include <thread>
|
||||
#include <linux/input.h>
|
||||
|
||||
#include "anonymous_string.h"
|
||||
#include "dinput_softbus_define.h"
|
||||
#include "distributed_hardware_fwk_kit.h"
|
||||
#include "distributed_hardware_log.h"
|
||||
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
@@ -132,30 +139,11 @@ void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInput(
|
||||
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);
|
||||
|
||||
int32_t startRes = DH_SUCCESS;
|
||||
if (curSessionId == sessionId) {
|
||||
DHLOGI("sessionId switch state is true, need not switch");
|
||||
} else {
|
||||
DHLOGI("sessionId switch state is false, need to switch");
|
||||
int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(sessionId);
|
||||
|
||||
sinkManagerObj_->SetStartTransFlag((startRes == DH_SUCCESS) ?
|
||||
DInputServerType::SINK_SERVER_TYPE :
|
||||
DInputServerType::NULL_SERVER_TYPE);
|
||||
|
||||
if ((curSessionId != ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL) && (startRes == DH_SUCCESS)) {
|
||||
DHLOGI("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(static_cast<uint32_t>(DInputDeviceType::NONE));
|
||||
DistributedInputCollector::GetInstance().SetInputTypes(sinkManagerObj_->GetInputTypes());
|
||||
}
|
||||
}
|
||||
sinkManagerObj_->SetStartTransFlag((startRes == DH_SUCCESS) ? DInputServerType::SINK_SERVER_TYPE
|
||||
: DInputServerType::NULL_SERVER_TYPE);
|
||||
|
||||
bool result = (startRes == DH_SUCCESS) ? true : false;
|
||||
nlohmann::json jsonStrSta;
|
||||
@@ -163,13 +151,12 @@ void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInput(
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_RESP_VALUE] = result;
|
||||
std::string smsgSta = jsonStrSta.dump();
|
||||
|
||||
DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsgSta);
|
||||
|
||||
// add the input type
|
||||
if (startRes == DH_SUCCESS) {
|
||||
sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() | inputTypes);
|
||||
DistributedInputCollector::GetInstance().SetInputTypes(sinkManagerObj_->GetInputTypes());
|
||||
DistributedInputCollector::GetInstance().SetSharingTypes(sinkManagerObj_->GetInputTypes());
|
||||
}
|
||||
|
||||
IStartDInputServerCallback *startServerCB = sinkManagerObj_->GetStartDInputServerCback();
|
||||
@@ -189,7 +176,7 @@ void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInput(
|
||||
|
||||
sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() -
|
||||
(sinkManagerObj_->GetInputTypes() & inputTypes));
|
||||
DistributedInputCollector::GetInstance().SetInputTypes(sinkManagerObj_->GetInputTypes());
|
||||
DistributedInputCollector::GetInstance().SetSharingTypes(sinkManagerObj_->GetInputTypes());
|
||||
|
||||
nlohmann::json jsonStr;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONSTOP;
|
||||
@@ -198,8 +185,9 @@ void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInput(
|
||||
std::string smsg = jsonStr.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(sessionId, smsg);
|
||||
|
||||
if (sinkManagerObj_->GetInputTypes() == static_cast<uint32_t>(DInputDeviceType::NONE)) {
|
||||
DistributedInputSinkSwitch::GetInstance().StopSwitch(sessionId);
|
||||
bool isAllClosed = DistributedInputCollector::GetInstance().GetAllDevicesStoped();
|
||||
if (isAllClosed) {
|
||||
DistributedInputSinkSwitch::GetInstance().StopAllSwitch();
|
||||
if (DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession() ==
|
||||
ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL) {
|
||||
DHLOGI("all session is stop.");
|
||||
@@ -216,6 +204,219 @@ void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInput(
|
||||
}
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInputDhid(const int32_t &sessionId,
|
||||
const std::string &strDhids)
|
||||
{
|
||||
int32_t curSessionId = DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession();
|
||||
DHLOGE("onStartRemoteInputDhid called, curSessionId:%s, new sessionId: %s",
|
||||
GetAnonyInt32(curSessionId).c_str(), GetAnonyInt32(sessionId).c_str());
|
||||
// set new session
|
||||
int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(sessionId);
|
||||
bool result = (startRes == DH_SUCCESS) ? true : false;
|
||||
nlohmann::json jsonStrSta;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_DHID_ONSTART;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = strDhids;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_RESP_VALUE] = result;
|
||||
std::string smsgSta = jsonStrSta.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsgSta);
|
||||
|
||||
if (startRes != DH_SUCCESS) {
|
||||
DHLOGE("onStartRemoteInputDhid StartSwitch error.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (curSessionId == ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL) {
|
||||
DHLOGW("onStartRemoteInputDhid called, this is the only session.");
|
||||
}
|
||||
|
||||
CheckKeyState(sessionId, strDhids);
|
||||
// add the dhids
|
||||
if (startRes == DH_SUCCESS) {
|
||||
std::set<std::string> setStr;
|
||||
StringSplitToSet(strDhids, INPUT_STRING_SPLIT_POINT, setStr);
|
||||
sinkManagerObj_->StoreStartDhids(sessionId, setStr);
|
||||
std::vector<std::string> vecStr;
|
||||
vecStr.assign(setStr.begin(), setStr.end());
|
||||
DistributedInputCollector::GetInstance().SetSharingDhIds(true, vecStr);
|
||||
}
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInputDhid(const int32_t &sessionId,
|
||||
const std::string &strDhids)
|
||||
{
|
||||
DHLOGI("onStopRemoteInputDhid called, sessionId: %s", GetAnonyInt32(sessionId).c_str());
|
||||
std::vector<std::string> stopStr;
|
||||
std::set<std::string> setStr;
|
||||
StringSplitToSet(strDhids, INPUT_STRING_SPLIT_POINT, setStr);
|
||||
sinkManagerObj_->DeleteStopDhids(sessionId, setStr, stopStr);
|
||||
DistributedInputCollector::GetInstance().SetSharingDhIds(false, stopStr);
|
||||
DHLOGE("onStopRemoteInputDhid called, sessionId: %d is closed.", sessionId);
|
||||
DistributedInputSinkSwitch::GetInstance().StopSwitch(sessionId);
|
||||
|
||||
nlohmann::json jsonStr;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_DHID_ONSTOP;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = strDhids;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true;
|
||||
std::string smsg = jsonStr.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(sessionId, smsg);
|
||||
|
||||
bool isAllClosed = DistributedInputCollector::GetInstance().GetAllDevicesStoped();
|
||||
if (isAllClosed) {
|
||||
DistributedInputSinkSwitch::GetInstance().StopAllSwitch();
|
||||
sinkManagerObj_->SetInputTypes(static_cast<uint32_t>(DInputDeviceType::NONE));
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::DInputSinkListener::StringSplitToSet(const std::string &str, const char split,
|
||||
std::set<std::string> &vecStr)
|
||||
{
|
||||
if (str.empty()) {
|
||||
DHLOGE("param str is error.");
|
||||
return;
|
||||
}
|
||||
std::string strTmp = str + split;
|
||||
size_t pos = strTmp.find(split);
|
||||
while (pos != strTmp.npos) {
|
||||
std::string matchTmp = strTmp.substr(0, pos);
|
||||
vecStr.insert(matchTmp);
|
||||
strTmp = strTmp.substr(pos + 1, strTmp.size());
|
||||
pos = strTmp.find(split);
|
||||
}
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::DInputSinkListener::SleepTimeMs()
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(READ_SLEEP_TIME_MS));
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::DInputSinkListener::CheckKeyState(const int32_t &sessionId,
|
||||
const std::string &strDhids)
|
||||
{
|
||||
std::set<std::string> setStr;
|
||||
StringSplitToSet(strDhids, INPUT_STRING_SPLIT_POINT, setStr);
|
||||
std::string mouseNodePath;
|
||||
std::string dhid;
|
||||
std::vector<std::string> vecStr;
|
||||
vecStr.assign(setStr.begin(), setStr.end());
|
||||
DistributedInputCollector::GetInstance().GetMouseNodePath(vecStr, mouseNodePath, dhid);
|
||||
if (mouseNodePath.empty()) {
|
||||
DHLOGE("mouse Node Path is empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
int fd = open(mouseNodePath.c_str(), O_RDONLY | O_NONBLOCK);
|
||||
if (fd < 0) {
|
||||
DHLOGE("open mouse Node Path error:", errno);
|
||||
return;
|
||||
}
|
||||
DHLOGI("mouse Node Path fd: %d", fd);
|
||||
|
||||
uint32_t count = 0;
|
||||
int rc = 0;
|
||||
int keyVal = 0;
|
||||
unsigned long keystate[NLONGS(KEY_CNT)] = { 0 };
|
||||
while (true) {
|
||||
if (count > READ_RETRY_MAX) {
|
||||
break;
|
||||
}
|
||||
// Query all key state
|
||||
rc = ioctl(fd, EVIOCGKEY(sizeof(keystate)), keystate);
|
||||
if (rc < 0) {
|
||||
DHLOGE("read all key state failed, rc: ", rc);
|
||||
SleepTimeMs();
|
||||
continue;
|
||||
}
|
||||
|
||||
keyVal = bit_is_set(keystate, BTN_LEFT);
|
||||
if (keyVal != 0) {
|
||||
DHLOGI("mouse left button is down.");
|
||||
nlohmann::json jsonStr;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_KEY_STATE;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_KEYSTATE_DHID] = dhid;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_KEYSTATE_TYPE] = EV_KEY;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_KEYSTATE_CODE] = BTN_LEFT;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_KEYSTATE_VALUE] = KEY_DOWN_STATE;
|
||||
std::string smsg = jsonStr.dump();
|
||||
DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, smsg);
|
||||
break;
|
||||
}
|
||||
SleepTimeMs();
|
||||
count += 1;
|
||||
}
|
||||
if (fd > 0) {
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
bool DistributedInputSinkManager::IsDeleteDhidExist(int32_t sessionId, const std::string &delstr)
|
||||
{
|
||||
for (auto sessionDhid : sharingDhIdsMap_) {
|
||||
if (sessionDhid.first == sessionId) {
|
||||
DHLOGW("IsDeleteDhidExist sessionId=%d is self, ignore.", sessionId);
|
||||
continue;
|
||||
}
|
||||
for (auto dhid : sessionDhid.second) {
|
||||
if (delstr == dhid) {
|
||||
DHLOGI("IsDeleteDhidExist delstr=%s is find.", delstr.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
DHLOGW("IsDeleteDhidExist delstr=%s is not find.", delstr.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::DeleteStopDhids(int32_t sessionId, const std::set<std::string> delDhIds,
|
||||
std::vector<std::string> &stopDhIds)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (sharingDhIdsMap_.count(sessionId) <= 0) {
|
||||
DHLOGE("DeleteStopDhids sessionId:%d is not exist.", sessionId);
|
||||
return;
|
||||
}
|
||||
DHLOGI("DeleteStopDhids sessionId=%d before has dhid.size=%d, delDhIds.size=%d.", sessionId,
|
||||
sharingDhIdsMap_[sessionId].size(), delDhIds.size());
|
||||
for (auto delstr : delDhIds) {
|
||||
sharingDhIdsMap_[sessionId].erase(delstr);
|
||||
}
|
||||
if (sharingDhIdsMap_[sessionId].size() == 0) {
|
||||
sharingDhIdsMap_.erase(sessionId);
|
||||
DHLOGI("DeleteStopDhids sessionId=%d is delete.", sessionId);
|
||||
} else {
|
||||
DHLOGI("DeleteStopDhids sessionId=%d after has dhid.size=%d.", sessionId, sharingDhIdsMap_[sessionId].size());
|
||||
}
|
||||
// find which dhid can be stop
|
||||
bool isFind = false;
|
||||
for (auto tmp : delDhIds) {
|
||||
isFind = IsDeleteDhidExist(sessionId, tmp);
|
||||
if (!isFind) {
|
||||
stopDhIds.push_back(tmp);
|
||||
sharingDhIds_.erase(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::StoreStartDhids(int32_t sessionId, const std::set<std::string> &dhIds)
|
||||
{
|
||||
std::set<std::string> tmpDhids;
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (sharingDhIdsMap_.count(sessionId) > 0) {
|
||||
tmpDhids = sharingDhIdsMap_[sessionId];
|
||||
}
|
||||
DHLOGI("StoreStartDhids start tmpDhids.size=%d, add dhIds.size=%d.", tmpDhids.size(), dhIds.size());
|
||||
for (auto iter : dhIds) {
|
||||
tmpDhids.insert(iter);
|
||||
sharingDhIds_.insert(iter);
|
||||
}
|
||||
sharingDhIdsMap_[sessionId] = tmpDhids;
|
||||
DHLOGI("StoreStartDhids end tmpDhids.size=%d", tmpDhids.size());
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::OnStart()
|
||||
{
|
||||
if (serviceRunningState_ == ServiceSinkRunningState::STATE_RUNNING) {
|
||||
@@ -229,7 +430,9 @@ void DistributedInputSinkManager::OnStart()
|
||||
}
|
||||
serviceRunningState_ = ServiceSinkRunningState::STATE_RUNNING;
|
||||
runner_->Run();
|
||||
/* Publish service maybe failed, so we need call this function at the last,
|
||||
|
||||
/*
|
||||
* 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);
|
||||
@@ -304,6 +507,12 @@ int32_t DistributedInputSinkManager::Release()
|
||||
// 2.close all session
|
||||
DistributedInputSinkTransport::GetInstance().CloseAllSession();
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
sharingDhIds_.clear();
|
||||
sharingDhIdsMap_.clear();
|
||||
}
|
||||
|
||||
// 3.notify callback servertype
|
||||
SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE);
|
||||
IStartDInputServerCallback *startServerCB = GetStartDInputServerCback();
|
||||
@@ -389,6 +598,11 @@ DistributedInputSinkManager::ProjectWindowListener::~ProjectWindowListener()
|
||||
|
||||
void DistributedInputSinkManager::ProjectWindowListener::OnMessage(const DHTopic topic, const std::string& message)
|
||||
{
|
||||
DHLOGI("ProjectWindowListener OnMessage!");
|
||||
if (topic != DHTopic::TOPIC_SINK_PROJECT_WINDOW_INFO) {
|
||||
DHLOGE("this topic is wrong, %d", static_cast<uint32_t>(topic));
|
||||
return;
|
||||
}
|
||||
std::string srcDeviceId = "";
|
||||
uint64_t srcWinId = 0;
|
||||
SinkScreenInfo sinkScreenInfo = {};
|
||||
|
||||
+7
@@ -19,6 +19,7 @@
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
#include "dinput_errcode.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::DistributedHardware::DistributedInput;
|
||||
@@ -42,6 +43,12 @@ void DistributedInputSinkManagerTest::SetUpTestCase()
|
||||
void DistributedInputSinkManagerTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSinkManagerTest, Init01, testing::ext::TestSize.Level0)
|
||||
{
|
||||
int32_t ret = sinkManager_->Init();
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SINK_MANAGER_INIT_FAIL, ret);
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -46,6 +46,7 @@ public:
|
||||
int32_t RespStartRemoteInput(const int32_t sessionId, std::string &smsg);
|
||||
int32_t RespStopRemoteInput(const int32_t sessionId, std::string &smsg);
|
||||
int32_t RespLatency(const int32_t sessionId, std::string &smsg);
|
||||
void SendKeyStateNodeMsg(const int32_t sessionId, std::string &smsg);
|
||||
|
||||
int32_t OnSessionOpened(int32_t sessionId, int32_t result);
|
||||
void OnSessionClosed(int32_t sessionId);
|
||||
@@ -62,6 +63,8 @@ public:
|
||||
|
||||
std::shared_ptr<DistributedInputSinkTransport::DInputSinkEventHandler> GetEventHandler();
|
||||
void CloseAllSession();
|
||||
int32_t GetSessionIdByNetId(const std::string &srcId);
|
||||
void GetDeviceIdBySessionId(int32_t sessionId, std::string &srcId);
|
||||
|
||||
private:
|
||||
int32_t SendMessage(int32_t sessionId, std::string &message);
|
||||
@@ -71,9 +74,11 @@ private:
|
||||
void NotifyStartRemoteInput(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
void NotifyStopRemoteInput(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
void NotifyLatency(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
void NotifyStartRemoteInputDhid(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
void NotifyStopRemoteInputDhid(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
|
||||
private:
|
||||
std::string deviceId_;
|
||||
std::map<std::string, int32_t> sessionDevMap_; // source networkId, sessionId
|
||||
std::string mySessionName_;
|
||||
|
||||
std::shared_ptr<DistributedInputSinkTransport::DInputSinkEventHandler> eventHandler_;
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_errcode.h"
|
||||
#include "dinput_low_latency.h"
|
||||
#include "dinput_softbus_define.h"
|
||||
#include "dinput_utils_tool.h"
|
||||
#include "hidumper.h"
|
||||
#include "session.h"
|
||||
@@ -34,17 +35,17 @@
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
DistributedInputSinkTransport::DistributedInputSinkTransport()
|
||||
DistributedInputSinkTransport::DistributedInputSinkTransport() : sessionDevMap_({}), mySessionName_("")
|
||||
{
|
||||
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create(true);
|
||||
eventHandler_ = std::make_shared<DistributedInputSinkTransport::DInputSinkEventHandler>(runner);
|
||||
mySessionName_ = "";
|
||||
DHLOGI("DistributedInputSinkTransport eventHandler_");
|
||||
}
|
||||
|
||||
DistributedInputSinkTransport::~DistributedInputSinkTransport()
|
||||
{
|
||||
DHLOGI("~DistributedInputSinkTransport");
|
||||
sessionDevMap_.clear();
|
||||
(void)RemoveSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str());
|
||||
}
|
||||
|
||||
@@ -209,8 +210,7 @@ int32_t DistributedInputSinkTransport::RespStartRemoteInput(
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkTransport::RespStopRemoteInput(
|
||||
const int32_t sessionId, std::string &smsg)
|
||||
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());
|
||||
@@ -243,9 +243,22 @@ int32_t DistributedInputSinkTransport::RespLatency(const int32_t sessionId, std:
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DistributedInputSinkTransport::SendKeyStateNodeMsg(const int32_t sessionId, std::string &smsg)
|
||||
{
|
||||
if (sessionId <= 0) {
|
||||
DHLOGE("SendKeyStateNodeMsg error, sessionId <= 0.");
|
||||
return;
|
||||
}
|
||||
DHLOGI("SendKeyStateNodeMsg sessionId:%s, smsg:%s.", GetAnonyInt32(sessionId).c_str(), smsg.c_str());
|
||||
int32_t ret = SendMessage(sessionId, smsg);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("SendKeyStateNodeMsg error, SendMessage fail.");
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkTransport::SendMessage(int32_t sessionId, std::string &message)
|
||||
{
|
||||
DHLOGI("start SendMessage");
|
||||
DHLOGD("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;
|
||||
@@ -267,6 +280,27 @@ int32_t DistributedInputSinkTransport::SendMessage(int32_t sessionId, std::strin
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkTransport::GetSessionIdByNetId(const std::string &srcId)
|
||||
{
|
||||
std::map<std::string, int32_t>::iterator it = sessionDevMap_.find(srcId);
|
||||
if (it != sessionDevMap_.end()) {
|
||||
return it->second;
|
||||
}
|
||||
DHLOGE("get session id failed, srcId = %s", GetAnonyString(srcId).c_str());
|
||||
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_GET_SESSIONID_FAIL;
|
||||
}
|
||||
|
||||
void DistributedInputSinkTransport::GetDeviceIdBySessionId(int32_t sessionId, std::string &srcId)
|
||||
{
|
||||
for (auto iter = sessionDevMap_.begin(); iter != sessionDevMap_.end(); iter++) {
|
||||
if (sessionId == iter->second) {
|
||||
srcId = iter->first;
|
||||
return;
|
||||
}
|
||||
}
|
||||
srcId = "";
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkTransport::OnSessionOpened(int32_t sessionId, int32_t result)
|
||||
{
|
||||
if (result != DH_SUCCESS) {
|
||||
@@ -287,17 +321,19 @@ int32_t DistributedInputSinkTransport::OnSessionOpened(int32_t sessionId, int32_
|
||||
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());
|
||||
DHLOGE("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());
|
||||
DHLOGE("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());
|
||||
DHLOGE("get my peer device id failed, session id is %s", GetAnonyInt32(sessionId).c_str());
|
||||
} else {
|
||||
sessionDevMap_[peerDevId] = sessionId;
|
||||
}
|
||||
DHLOGI("mySessionName:%s, peerSessionName:%s, peerDevId:%s",
|
||||
mySessionName, peerSessionName, GetAnonyString(peerDevId).c_str());
|
||||
@@ -319,6 +355,12 @@ void DistributedInputSinkTransport::OnSessionClosed(int32_t sessionId)
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGI("get my peer device id failed, session id is %s", GetAnonyInt32(sessionId).c_str());
|
||||
}
|
||||
for (auto iter = sessionDevMap_.begin(); iter != sessionDevMap_.end(); iter++) {
|
||||
if (iter->second == sessionId) {
|
||||
sessionDevMap_.erase(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
DistributedInputSinkSwitch::GetInstance().RemoveSession(sessionId);
|
||||
HiDumper::GetInstance().SetSessionStatus(std::string(peerDevId), SessionStatus::CLOSED);
|
||||
HiDumper::GetInstance().DeleteSessionInfo(std::string(peerDevId));
|
||||
@@ -381,12 +423,12 @@ void DistributedInputSinkTransport::NotifyUnprepareRemoteInput(int32_t 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.");
|
||||
DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_START_TYPE, 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 .",
|
||||
DHLOGI("OnBytesRecei,ved cmdType is TRANS_SOURCE_MSG_START_TYPE deviceId:%s inputTypes:%d .",
|
||||
GetAnonyString(deviceId).c_str(), inputTypes);
|
||||
callback_->onStartRemoteInput(sessionId, inputTypes);
|
||||
}
|
||||
@@ -394,12 +436,12 @@ void DistributedInputSinkTransport::NotifyStartRemoteInput(int32_t sessionId, co
|
||||
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.");
|
||||
DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_STOP_TYPE, 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());
|
||||
DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_STOP_TYPE deviceId:%s.", GetAnonyString(deviceId).c_str());
|
||||
callback_->onStopRemoteInput(sessionId, inputTypes);
|
||||
}
|
||||
|
||||
@@ -422,6 +464,44 @@ void DistributedInputSinkTransport::NotifyLatency(int32_t sessionId, const nlohm
|
||||
RespLatency(sessionId, smsg);
|
||||
}
|
||||
|
||||
void DistributedInputSinkTransport::NotifyStartRemoteInputDhid(int32_t sessionId, const nlohmann::json &recMsg)
|
||||
{
|
||||
if (!recMsg.contains(DINPUT_SOFTBUS_KEY_DEVICE_ID) ||
|
||||
!recMsg.contains(DINPUT_SOFTBUS_KEY_VECTOR_DHID)) {
|
||||
DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_START_DHID, key not exist.");
|
||||
return;
|
||||
}
|
||||
if (!recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID].is_string() ||
|
||||
!recMsg[DINPUT_SOFTBUS_KEY_VECTOR_DHID].is_string()) {
|
||||
DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_START_DHID, data type error.");
|
||||
return;
|
||||
}
|
||||
std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID];
|
||||
std::string strTmp = recMsg[DINPUT_SOFTBUS_KEY_VECTOR_DHID];
|
||||
DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_START_DHID deviceId:%s .",
|
||||
GetAnonyString(deviceId).c_str());
|
||||
callback_->onStartRemoteInputDhid(sessionId, strTmp);
|
||||
}
|
||||
|
||||
void DistributedInputSinkTransport::NotifyStopRemoteInputDhid(int32_t sessionId, const nlohmann::json &recMsg)
|
||||
{
|
||||
if (!recMsg.contains(DINPUT_SOFTBUS_KEY_DEVICE_ID) ||
|
||||
!recMsg.contains(DINPUT_SOFTBUS_KEY_VECTOR_DHID)) {
|
||||
DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_STOP_DHID, key not exist.");
|
||||
return;
|
||||
}
|
||||
if (!recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID].is_string() ||
|
||||
!recMsg[DINPUT_SOFTBUS_KEY_VECTOR_DHID].is_string()) {
|
||||
DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_STOP_DHID, data type is error.");
|
||||
return;
|
||||
}
|
||||
std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID];
|
||||
std::string strTmp = recMsg[DINPUT_SOFTBUS_KEY_VECTOR_DHID];
|
||||
DHLOGE("OnBytesReceived cmdType is TRANS_SOURCE_MSG_STOP_DHID deviceId:%s.",
|
||||
GetAnonyString(deviceId).c_str());
|
||||
callback_->onStopRemoteInputDhid(sessionId, strTmp);
|
||||
}
|
||||
|
||||
void DistributedInputSinkTransport::HandleSessionData(int32_t sessionId, const std::string& message)
|
||||
{
|
||||
if (callback_ == nullptr) {
|
||||
@@ -455,11 +535,11 @@ void DistributedInputSinkTransport::HandleSessionData(int32_t sessionId, const s
|
||||
NotifyUnprepareRemoteInput(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SOURCE_MSG_START: {
|
||||
case TRANS_SOURCE_MSG_START_TYPE: {
|
||||
NotifyStartRemoteInput(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SOURCE_MSG_STOP: {
|
||||
case TRANS_SOURCE_MSG_STOP_TYPE: {
|
||||
NotifyStopRemoteInput(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
@@ -467,6 +547,14 @@ void DistributedInputSinkTransport::HandleSessionData(int32_t sessionId, const s
|
||||
NotifyLatency(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SOURCE_MSG_START_DHID: {
|
||||
NotifyStartRemoteInputDhid(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SOURCE_MSG_STOP_DHID: {
|
||||
NotifyStopRemoteInputDhid(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
DHLOGE("OnBytesReceived cmdType is undefined.");
|
||||
break;
|
||||
|
||||
@@ -38,6 +38,12 @@ void DistributedInputSinkTransTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSinkTransTest, Init, testing::ext::TestSize.Level0)
|
||||
{
|
||||
int32_t ret = DistributedInputSinkTransport::GetInstance().Init();
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SINK_TRANSPORT_INIT_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSinkTransTest, RespPrepareRemoteInput01, testing::ext::TestSize.Level1)
|
||||
{
|
||||
int32_t sessionId = -1;
|
||||
|
||||
@@ -19,17 +19,20 @@ ohos_shared_library("libdinput_inject") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${common_path}/include",
|
||||
"${frameworks_path}/include",
|
||||
"//commonlibrary/c_utils/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",
|
||||
"${service_common}/include",
|
||||
"//third_party/json/include",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
"${distributedinput_path}/inputdevicehandler/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -41,6 +44,7 @@ ohos_shared_library("libdinput_inject") {
|
||||
"src/virtual_mouse.cpp",
|
||||
"src/virtual_touchpad.cpp",
|
||||
"src/virtual_touchscreen.cpp",
|
||||
"${common_path}/include/dinput_struct_data.cpp",
|
||||
]
|
||||
|
||||
defines = [
|
||||
@@ -56,6 +60,7 @@ ohos_shared_library("libdinput_inject") {
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
"${distributedinput_path}/inputdevicehandler:libdinput_handler",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
@@ -64,6 +69,8 @@ ohos_shared_library("libdinput_inject") {
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
"dsoftbus:softbus_client",
|
||||
"eventhandler:libeventhandler",
|
||||
]
|
||||
|
||||
cflags_cc = [ "-DHILOG_ENABLE" ]
|
||||
|
||||
@@ -17,10 +17,14 @@
|
||||
#define DISTRIBUTED_INPUT_INJECT_H
|
||||
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "distributed_input_handler.h"
|
||||
#include "distributed_input_node_manager.h"
|
||||
#include "dinput_struct_data.h"
|
||||
#include "i_input_node_listener.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
@@ -43,12 +47,24 @@ public:
|
||||
int32_t RemoveVirtualTouchScreenNode(const std::string& dhId);
|
||||
int32_t GetVirtualTouchScreenFd();
|
||||
|
||||
int32_t RegisterInputNodeListener(sptr<InputNodeListener> listener);
|
||||
int32_t UnregisterInputNodeListener(sptr<InputNodeListener> listener);
|
||||
|
||||
int32_t GetDhIdsByInputType(const std::string &devId, const uint32_t &inputTypes, std::vector<std::string> &dhIds);
|
||||
|
||||
void InputDeviceEventInject(const std::shared_ptr<RawEvent> &rawEvent);
|
||||
void SyncNodeOnlineInfo(const std::string &srcDevId, const std::string &sinkDevId, const std::string &sinkNodeId,
|
||||
const std::string &sinkNodeDesc);
|
||||
void SyncNodeOfflineInfo(const std::string &srcDevId, const std::string &sinkDevId, const std::string &sinkNodeId);
|
||||
|
||||
private:
|
||||
DistributedInputInject();
|
||||
~DistributedInputInject();
|
||||
|
||||
std::unique_ptr<DistributedInputNodeManager> inputNodeManager_;
|
||||
std::mutex inputNodeManagerMutex_;
|
||||
std::set<sptr<InputNodeListener>> inputNodeListeners_;
|
||||
std::mutex inputNodeListenersMutex_;
|
||||
|
||||
// The event queue.
|
||||
static const int EVENT_BUFFER_SIZE = 16;
|
||||
|
||||
@@ -49,12 +49,16 @@ public:
|
||||
int32_t RemoveVirtualTouchScreenNode(const std::string& dhId);
|
||||
int32_t GetVirtualTouchScreenFd();
|
||||
|
||||
int32_t GetDeviceInfo(std::string &deviceId);
|
||||
void GetDevicesInfoByType(const std::string &networkId, int32_t inputTypes, std::map<int32_t, std::string> &datas);
|
||||
void GetDevicesInfoByDhId(std::vector<std::string> dhidsVec, std::map<int32_t, std::string> &datas);
|
||||
void ProcessInjectEvent(const std::shared_ptr<RawEvent> &rawEvent);
|
||||
|
||||
private:
|
||||
void AddDeviceLocked(const std::string& dhId, std::unique_ptr<VirtualDevice> device);
|
||||
int32_t CreateHandle(InputDevice event, const std::string& devId, const std::string& dhId);
|
||||
void stringTransJsonTransStruct(const std::string& str, InputDevice& pBuf);
|
||||
void InjectEvent();
|
||||
void ProcessInjectEvent(const std::shared_ptr<RawEvent> &rawEvent);
|
||||
|
||||
/* the key is dhId, and the value is virtualDevice */
|
||||
std::map<std::string, std::unique_ptr<VirtualDevice>> virtualDeviceMap_;
|
||||
|
||||
@@ -38,11 +38,14 @@ public:
|
||||
virtual ~VirtualDevice();
|
||||
bool DoIoctl(int32_t fd, int32_t request, const uint32_t value);
|
||||
bool CreateKey();
|
||||
bool SetPhys(const std::string deviceName);
|
||||
bool SetUp(const std::string& devId, const std::string& dhId);
|
||||
bool InjectInputEvent(const input_event& event);
|
||||
bool SetPhys(const std::string deviceName, std::string dhId);
|
||||
bool SetUp(const std::string &devId, const std::string &dhId);
|
||||
bool InjectInputEvent(const input_event &event);
|
||||
void SetNetWorkId(const std::string netWorkId);
|
||||
int32_t GetFd();
|
||||
std::string GetNetWorkId();
|
||||
|
||||
int32_t GetDeviceFd();
|
||||
int32_t GetDeviceType();
|
||||
|
||||
protected:
|
||||
VirtualDevice();
|
||||
@@ -59,6 +62,7 @@ protected:
|
||||
const uint16_t vendorId_;
|
||||
const uint16_t productId_;
|
||||
const uint16_t version_;
|
||||
const uint16_t classes_;
|
||||
struct uinput_user_dev dev_ {};
|
||||
struct uinput_abs_setup absTemp_ = {};
|
||||
std::vector<uinput_abs_setup> absInit_;
|
||||
|
||||
@@ -51,8 +51,8 @@ DistributedInputInject &DistributedInputInject::GetInstance()
|
||||
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(), SetAnonyId(parameters).c_str());
|
||||
DHLOGI("RegisterDistributedHardware called, deviceId: %s, dhId: %s, parameters: %s",
|
||||
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), SetAnonyId(parameters).c_str());
|
||||
std::lock_guard<std::mutex> lock(inputNodeManagerMutex_);
|
||||
if (inputNodeManager_ == nullptr) {
|
||||
DHLOGE("the DistributedInputNodeManager is null\n");
|
||||
@@ -62,13 +62,20 @@ int32_t DistributedInputInject::RegisterDistributedHardware(const std::string& d
|
||||
DHLOGE("create virtual device error\n");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_INJECT_REGISTER_FAIL;
|
||||
}
|
||||
|
||||
std::string srcDevId;
|
||||
inputNodeManager_->GetDeviceInfo(srcDevId);
|
||||
DHLOGI("RegisterDistributedHardware called, device type = source, source networkId = %s, sink networkId = %s",
|
||||
GetAnonyString(srcDevId).c_str(), GetAnonyString(devId).c_str());
|
||||
|
||||
SyncNodeOnlineInfo(srcDevId, devId, dhId, GetNodeDesc(parameters));
|
||||
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());
|
||||
DHLOGI("UnregisterDistributedHardware called, deviceId: %s, dhId: %s",
|
||||
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
|
||||
std::lock_guard<std::mutex> lock(inputNodeManagerMutex_);
|
||||
if (inputNodeManager_ == nullptr) {
|
||||
DHLOGE("the DistributedInputNodeManager is null\n");
|
||||
@@ -78,10 +85,48 @@ int32_t DistributedInputInject::UnregisterDistributedHardware(const std::string&
|
||||
DHLOGE("delete virtual device error\n");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_INJECT_UNREGISTER_FAIL;
|
||||
}
|
||||
|
||||
std::string srcDevId;
|
||||
inputNodeManager_->GetDeviceInfo(srcDevId);
|
||||
|
||||
DHLOGI("UnregisterDistributedHardware called, device = %s, dhId = %s, OnNodeOffLine",
|
||||
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
|
||||
SyncNodeOfflineInfo(srcDevId, devId, dhId);
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputInject::StructTransJson(const InputDevice& pBuf, std::string& strDescriptor)
|
||||
int32_t DistributedInputInject::RegisterInputNodeListener(sptr<InputNodeListener> listener)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(inputNodeListenersMutex_);
|
||||
this->inputNodeListeners_.insert(listener);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputInject::UnregisterInputNodeListener(sptr<InputNodeListener> listener)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(inputNodeListenersMutex_);
|
||||
this->inputNodeListeners_.erase(listener);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputInject::GetDhIdsByInputType(const std::string &devId, const uint32_t &inputTypes,
|
||||
std::vector<std::string> &dhIds)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(inputNodeManagerMutex_);
|
||||
if (inputNodeManager_ == nullptr) {
|
||||
DHLOGE("the inputNodeListener is nullptr");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL;
|
||||
}
|
||||
std::map<int32_t, std::string> datas;
|
||||
inputNodeManager_->GetDevicesInfoByType(devId, inputTypes, datas);
|
||||
for (const auto &data_ : datas) {
|
||||
dhIds.push_back(data_.second);
|
||||
}
|
||||
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,
|
||||
GetAnonyString(pBuf.descriptor).c_str());
|
||||
@@ -102,7 +147,43 @@ int32_t DistributedInputInject::StructTransJson(const InputDevice& pBuf, std::st
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputInject::RegisterDistributedEvent(RawEvent* buffer, size_t bufferSize)
|
||||
void DistributedInputInject::InputDeviceEventInject(const std::shared_ptr<RawEvent> &rawEvent)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(inputNodeManagerMutex_);
|
||||
if (inputNodeManager_ == nullptr) {
|
||||
DHLOGE("the inputNodeListener is nullptr");
|
||||
return;
|
||||
}
|
||||
if (rawEvent == nullptr) {
|
||||
DHLOGE("the rawEvent is nullptr");
|
||||
return;
|
||||
}
|
||||
inputNodeManager_->ProcessInjectEvent(rawEvent);
|
||||
}
|
||||
|
||||
void DistributedInputInject::SyncNodeOnlineInfo(const std::string &srcDevId,
|
||||
const std::string &sinkDevId, const std::string &sinkNodeId, const std::string &sinkNodeDesc)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(inputNodeListenersMutex_);
|
||||
DHLOGI("SyncVirNodeOnlineInfo, srcId: %s, sinkId: %s, dhId: %s", GetAnonyString(srcDevId).c_str(),
|
||||
GetAnonyString(sinkDevId).c_str(), GetAnonyString(sinkNodeId).c_str());
|
||||
for (const auto &listener : inputNodeListeners_) {
|
||||
listener->OnNodeOnLine(srcDevId, sinkDevId, sinkNodeId, sinkNodeDesc);
|
||||
}
|
||||
}
|
||||
|
||||
void DistributedInputInject::SyncNodeOfflineInfo(const std::string &srcDevId,
|
||||
const std::string &sinkDevId, const std::string &sinkNodeId)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(inputNodeListenersMutex_);
|
||||
DHLOGI("SyncVirNodeOfflineInfo, srcId: %s, sinkId: %s, dhId: %s", GetAnonyString(srcDevId).c_str(),
|
||||
GetAnonyString(sinkDevId).c_str(), GetAnonyString(sinkNodeId).c_str());
|
||||
for (const auto &listener : inputNodeListeners_) {
|
||||
listener->OnNodeOffLine(srcDevId, sinkDevId, sinkNodeId);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DistributedInputInject::RegisterDistributedEvent(RawEvent *buffer, size_t bufferSize)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(inputNodeManagerMutex_);
|
||||
if (inputNodeManager_ == nullptr) {
|
||||
|
||||
@@ -25,8 +25,11 @@
|
||||
#include "distributed_hardware_log.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#include "softbus_bus_center.h"
|
||||
|
||||
#include "dinput_context.h"
|
||||
#include "dinput_errcode.h"
|
||||
#include "dinput_softbus_define.h"
|
||||
#include "virtual_keyboard.h"
|
||||
#include "virtual_mouse.h"
|
||||
#include "virtual_touchpad.h"
|
||||
@@ -88,12 +91,12 @@ int32_t DistributedInputNodeManager::CreateHandle(InputDevice event, const std::
|
||||
device = std::make_unique<VirtualKeyboard>(event);
|
||||
} else if (event.classes & INPUT_DEVICE_CLASS_CURSOR) {
|
||||
device = std::make_unique<VirtualMouse>(event);
|
||||
} else if (event.classes & INPUT_DEVICE_CLASS_TOUCH) {
|
||||
device = std::make_unique<VirtualTouchpad>(event);
|
||||
} else if (event.classes & INPUT_DEVICE_CLASS_TOUCH_MT) {
|
||||
inputHub_->ScanInputDevices(DEVICE_PATH);
|
||||
LocalAbsInfo info = DInputContext::GetInstance().GetLocalTouchScreenInfo().localAbsInfo;
|
||||
device = std::make_unique<VirtualTouchScreen>(event, info, info.absMtPositionXMax, info.absMtPositionYMax);
|
||||
} else if (event.classes & INPUT_DEVICE_CLASS_TOUCH) {
|
||||
device = std::make_unique<VirtualTouchpad>(event);
|
||||
} else {
|
||||
DHLOGW("could not find the deviceType\n");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL;
|
||||
@@ -132,7 +135,7 @@ int32_t DistributedInputNodeManager::CreateVirtualTouchScreenNode(const std::str
|
||||
GetAnonyString(dhId).c_str());
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL;
|
||||
}
|
||||
virtualTouchScreenFd_ = device->GetFd();
|
||||
virtualTouchScreenFd_ = device->GetDeviceFd();
|
||||
AddDeviceLocked(dhId, std::move(device));
|
||||
DHLOGI("CreateVirtualTouchScreenNode end, dhId: %s", GetAnonyString(dhId).c_str());
|
||||
return DH_SUCCESS;
|
||||
@@ -160,15 +163,15 @@ void DistributedInputNodeManager::AddDeviceLocked(const std::string& dhId, std::
|
||||
|
||||
int32_t DistributedInputNodeManager::CloseDeviceLocked(const std::string &dhId)
|
||||
{
|
||||
DHLOGI("%s called, dhId=%s", __func__, GetAnonyString(dhId).c_str());
|
||||
DHLOGI("CloseDeviceLocked called, dhId=%s", GetAnonyString(dhId).c_str());
|
||||
std::lock_guard<std::mutex> lock(virtualDeviceMapMutex_);
|
||||
std::map<std::string, std::unique_ptr<VirtualDevice>>::iterator iter = virtualDeviceMap_.find(dhId);
|
||||
if (iter != virtualDeviceMap_.end()) {
|
||||
DHLOGI("%s called success, dhId=%s", __func__, GetAnonyString(dhId).c_str());
|
||||
DHLOGI("CloseDeviceLocked called success, dhId=%s", GetAnonyString(dhId).c_str());
|
||||
virtualDeviceMap_.erase(iter);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
DHLOGE("%s called failure, dhId=%s", __func__, GetAnonyString(dhId).c_str());
|
||||
DHLOGE("CloseDeviceLocked called failure, dhId=%s", GetAnonyString(dhId).c_str());
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_CLOSE_DEVICE_FAIL;
|
||||
}
|
||||
|
||||
@@ -255,6 +258,60 @@ void DistributedInputNodeManager::ProcessInjectEvent(const std::shared_ptr<RawEv
|
||||
device->InjectInputEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DistributedInputNodeManager::GetDeviceInfo(std::string &deviceId)
|
||||
{
|
||||
std::unique_lock<std::mutex> my_lock(operationMutex_);
|
||||
auto localNode = std::make_unique<NodeBasicInfo>();
|
||||
int32_t retCode = GetLocalNodeDeviceInfo(DINPUT_PKG_NAME.c_str(), localNode.get());
|
||||
if (retCode != 0) {
|
||||
DHLOGE("Could not get device id.");
|
||||
return ERR_DH_INPUT_HANDLER_GET_DEVICE_ID_FAIL;
|
||||
}
|
||||
|
||||
deviceId = localNode->networkId;
|
||||
DHLOGI("device id is %s", GetAnonyString(deviceId).c_str());
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DistributedInputNodeManager::GetDevicesInfoByType(const std::string &networkId, int32_t inputTypes,
|
||||
std::map<int32_t, std::string> &datas)
|
||||
{
|
||||
uint32_t input_types_ = 0;
|
||||
|
||||
if ((inputTypes & static_cast<uint32_t>(DInputDeviceType::MOUSE)) != 0) {
|
||||
input_types_ |= INPUT_DEVICE_CLASS_CURSOR;
|
||||
}
|
||||
|
||||
if ((inputTypes & static_cast<uint32_t>(DInputDeviceType::KEYBOARD)) != 0) {
|
||||
input_types_ |= INPUT_DEVICE_CLASS_KEYBOARD;
|
||||
}
|
||||
|
||||
if ((inputTypes & static_cast<uint32_t>(DInputDeviceType::MOUSE)) != 0) {
|
||||
input_types_ |= INPUT_DEVICE_CLASS_TOUCH;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(virtualDeviceMapMutex_);
|
||||
for (const auto &[id, virdevice] : virtualDeviceMap_) {
|
||||
if ((virdevice->GetDeviceType() & input_types_) && (virdevice->GetNetWorkId() == networkId)) {
|
||||
datas.insert(std::pair<int32_t, std::string>(virdevice->GetDeviceFd(), id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DistributedInputNodeManager::GetDevicesInfoByDhId(
|
||||
std::vector<std::string> dhidsVec, std::map<int32_t, std::string> &datas)
|
||||
{
|
||||
for (auto dhId : dhidsVec) {
|
||||
std::lock_guard<std::mutex> lock(virtualDeviceMapMutex_);
|
||||
for (const auto &[id, virdevice] : virtualDeviceMap_) {
|
||||
if (id == dhId) {
|
||||
datas.insert(std::pair<int32_t, std::string>(virdevice->GetDeviceFd(), id));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -20,18 +20,19 @@
|
||||
#include "anonymous_string.h"
|
||||
#include "distributed_hardware_log.h"
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "hidumper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
VirtualDevice::VirtualDevice()
|
||||
: deviceName_(""), netWorkId_(""), busType_(0), vendorId_(0), productId_(0), version_(0)
|
||||
: deviceName_(""), netWorkId_(""), busType_(0), vendorId_(0), productId_(0), version_(0), classes_(0)
|
||||
{
|
||||
}
|
||||
|
||||
VirtualDevice::VirtualDevice(const InputDevice& event) : deviceName_(
|
||||
event.name), busType_(event.bus), vendorId_(event.vendor), productId_(event.product), version_(event.version)
|
||||
VirtualDevice::VirtualDevice(const InputDevice& event) : deviceName_(event.name), busType_(event.bus),
|
||||
vendorId_(event.vendor), productId_(event.product), version_(event.version), classes_(event.classes)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -48,7 +49,7 @@ 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__);
|
||||
DHLOGE("ioctl failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -59,8 +60,7 @@ bool VirtualDevice::CreateKey()
|
||||
auto fun = [&](int32_t uiSet, const std::vector<uint32_t>& list) -> bool {
|
||||
for (uint32_t evt_type : list) {
|
||||
if (!DoIoctl(fd_, uiSet, evt_type)) {
|
||||
DHLOGE(
|
||||
"%s Error setting event type: %u", __func__, evt_type);
|
||||
DHLOGE("Error setting event type: %u", evt_type);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -82,10 +82,11 @@ bool VirtualDevice::CreateKey()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VirtualDevice::SetPhys(const std::string deviceName)
|
||||
bool VirtualDevice::SetPhys(const std::string deviceName, std::string dhId)
|
||||
{
|
||||
std::string phys;
|
||||
phys.append(deviceName).append(pid_).append("/").append(pid_).append("|").append(netWorkId_);
|
||||
phys.append(deviceName).append(pid_).append("/").append(pid_).append("|")
|
||||
.append(netWorkId_).append("|").append(dhId);
|
||||
|
||||
if (ioctl(fd_, UI_SET_PHYS, phys.c_str()) < 0) {
|
||||
return false;
|
||||
@@ -96,34 +97,33 @@ bool VirtualDevice::SetPhys(const std::string deviceName)
|
||||
bool VirtualDevice::SetUp(const std::string& devId, const std::string& dhId)
|
||||
{
|
||||
fd_ = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
|
||||
DHLOGI("open fd %d", fd_);
|
||||
if (fd_ < 0) {
|
||||
DHLOGE("Failed to open uinput %s", __func__);
|
||||
DHLOGE("Failed to open uinput");
|
||||
return false;
|
||||
}
|
||||
|
||||
deviceName_ = VIRTUAL_DEVICE_NAME + deviceName_;
|
||||
if (strncpy_s(dev_.name, sizeof(dev_.name), deviceName_.c_str(), deviceName_.size()) != 0) {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
HiDumper::GetInstance().SaveNodeInfo(devId, deviceName_, dhId);
|
||||
dev_.id.bustype = busType_;
|
||||
dev_.id.vendor = vendorId_;
|
||||
dev_.id.product = productId_;
|
||||
dev_.id.version = version_;
|
||||
|
||||
if (!SetPhys(deviceName_)) {
|
||||
DHLOGE("Failed to set PHYS! %s", __func__);
|
||||
if (!SetPhys(deviceName_, dhId)) {
|
||||
DHLOGE("Failed to set PHYS!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CreateKey()) {
|
||||
DHLOGE("Failed to create KeyValue %s", __func__);
|
||||
DHLOGE("Failed to create KeyValue");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (write(fd_, &dev_, sizeof(dev_)) < 0) {
|
||||
DHLOGE("Unable to set input device info: %s", __func__);
|
||||
DHLOGE("Unable to set input device info");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -131,14 +131,14 @@ bool VirtualDevice::SetUp(const std::string& devId, const std::string& dhId)
|
||||
DHLOGE(
|
||||
"fd = %d, ioctl(fd_, UI_DEV_CREATE) = %d",
|
||||
fd_, ioctl(fd_, UI_DEV_CREATE));
|
||||
DHLOGE("Unable to create input device : %s", __func__);
|
||||
DHLOGE("Unable to create input device");
|
||||
return false;
|
||||
}
|
||||
DHLOGI("create fd %d", fd_);
|
||||
|
||||
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__);
|
||||
DHLOGE("Unable to get input device name");
|
||||
}
|
||||
DHLOGI("get input device name: %s, fd: %d", GetAnonyString(sysfs_device_name).c_str(), fd_);
|
||||
return true;
|
||||
@@ -161,12 +161,12 @@ bool VirtualDevice::InjectInputEvent(const input_event& event)
|
||||
void VirtualDevice::SetNetWorkId(const std::string netWorkId)
|
||||
{
|
||||
DHLOGI("SetNetWorkId %s\n", GetAnonyString(netWorkId).c_str());
|
||||
netWorkId_.append(netWorkId);
|
||||
netWorkId_ = netWorkId;
|
||||
}
|
||||
|
||||
int32_t VirtualDevice::GetFd()
|
||||
std::string VirtualDevice::GetNetWorkId()
|
||||
{
|
||||
return fd_;
|
||||
return netWorkId_;
|
||||
}
|
||||
|
||||
void VirtualDevice::RecordEventLog(const input_event& event)
|
||||
@@ -189,6 +189,16 @@ void VirtualDevice::RecordEventLog(const input_event& event)
|
||||
DHLOGD("4.E2E-Test Source write event into input driver, EventType: %s, Code: %d, Value: %d, Sec: %ld, Sec1: %ld",
|
||||
eventType.c_str(), event.code, event.value, event.input_event_sec, event.input_event_usec);
|
||||
}
|
||||
|
||||
int32_t VirtualDevice::GetDeviceFd()
|
||||
{
|
||||
return fd_;
|
||||
}
|
||||
|
||||
int32_t VirtualDevice::GetDeviceType()
|
||||
{
|
||||
return classes_;
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -47,6 +47,7 @@ ohos_unittest("distributed_input_inner_sourceinject_test") {
|
||||
"${utils_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
"${distributedinput_path}/inputdevicehandler/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -83,6 +84,7 @@ ohos_unittest("distributed_input_inner_sourceinject_test") {
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
"${distributedinput_path}/inputdevicehandler:libdinput_handler",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -41,10 +41,12 @@ ohos_shared_library("libdinput_source") {
|
||||
"${low_latency_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
"${distributedinput_path}/inputdevicehandler/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"${common_path}/include/white_list_util.cpp",
|
||||
"${common_path}/include/dinput_struct_data.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",
|
||||
@@ -63,12 +65,21 @@ ohos_shared_library("libdinput_source") {
|
||||
"${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/start_stop_d_inputs_call_back_proxy.cpp",
|
||||
"${ipc_path}/src/start_stop_d_inputs_call_back_stub.cpp",
|
||||
"${ipc_path}/src/start_stop_result_call_back_proxy.cpp",
|
||||
"${ipc_path}/src/start_stop_result_call_back_stub.cpp",
|
||||
"${ipc_path}/src/input_node_listener_proxy.cpp",
|
||||
"${ipc_path}/src/input_node_listener_stub.cpp",
|
||||
"${ipc_path}/src/simulation_event_listener_proxy.cpp",
|
||||
"${ipc_path}/src/simulation_event_listener_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",
|
||||
"src/distributed_input_source_event_handler.cpp",
|
||||
"src/distributed_input_source_manager.cpp",
|
||||
"src/distributed_input_source_sa_cli_mgr.cpp",
|
||||
]
|
||||
|
||||
defines = [
|
||||
@@ -94,13 +105,17 @@ ohos_shared_library("libdinput_source") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"hitrace_native:hitrace_meter",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
"dsoftbus:softbus_client",
|
||||
]
|
||||
|
||||
cflags_cc = [ "-DHILOG_ENABLE" ]
|
||||
|
||||
@@ -33,8 +33,10 @@
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_source_trans_callback.h"
|
||||
#include "distributed_input_node_manager.h"
|
||||
#include "distributed_input_source_stub.h"
|
||||
#include "distributed_input_source_event_handler.h"
|
||||
#include "distributed_input_source_sa_cli_mgr.h"
|
||||
#include "distributed_input_source_stub.h"
|
||||
#include "idinput_dbg_itf.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
@@ -48,15 +50,44 @@ 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 uint32_t DINPUT_SOURCE_MANAGER_START_DHID_MSG = 7;
|
||||
const uint32_t DINPUT_SOURCE_MANAGER_STOP_DHID_MSG = 8;
|
||||
const uint32_t DINPUT_SOURCE_MANAGER_RECEIVE_DATA_MSG = 9;
|
||||
const uint32_t DINPUT_SOURCE_MANAGER_STARTSERVER_MSG = 10;
|
||||
const uint32_t DINPUT_SOURCE_MANAGER_KEY_STATE_MSG = 11;
|
||||
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_DHID = "dhids";
|
||||
const std::string INPUT_SOURCEMANAGER_KEY_TYPE = "type";
|
||||
const std::string INPUT_SOURCEMANAGER_KEY_CODE = "code";
|
||||
const std::string INPUT_SOURCEMANAGER_KEY_VALUE = "value";
|
||||
const std::string INPUT_SOURCEMANAGER_KEY_FROM_START_DHID = "fromStartDhid";
|
||||
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;
|
||||
const uint32_t DINPUT_SOURCE_WRITE_EVENT_SIZE = 1;
|
||||
|
||||
// Node Info that registerd by remote node
|
||||
typedef struct BeRegNodeInfo {
|
||||
// source node network id
|
||||
std::string srcId;
|
||||
// sink node dh id
|
||||
std::string dhId;
|
||||
// node desc on sink node
|
||||
std::string nodeDesc;
|
||||
|
||||
bool operator==(const BeRegNodeInfo &node)
|
||||
{
|
||||
return (srcId == node.srcId) && (dhId == node.dhId) && (nodeDesc == node.nodeDesc);
|
||||
}
|
||||
|
||||
bool operator<(const BeRegNodeInfo &node) const
|
||||
{
|
||||
return (srcId + dhId + nodeDesc).compare(node.srcId + node.dhId + node.nodeDesc) < 0;
|
||||
}
|
||||
} BeRegNodeInfo;
|
||||
|
||||
class DistributedInputSourceManager : public SystemAbility, public DistributedInputSourceStub {
|
||||
DECLARE_SYSTEM_ABILITY(DistributedInputSourceManager)
|
||||
@@ -64,10 +95,11 @@ class DistributedInputSourceManager : public SystemAbility, public DistributedIn
|
||||
typedef struct InputDeviceId {
|
||||
std::string devId;
|
||||
std::string dhId;
|
||||
std::string nodeDesc;
|
||||
|
||||
bool operator==(const InputDeviceId &inputId)
|
||||
{
|
||||
return (devId == inputId.devId) && (dhId == inputId.dhId);
|
||||
return (devId == inputId.devId) && (dhId == inputId.dhId) && (nodeDesc == inputId.nodeDesc);
|
||||
}
|
||||
} InputDeviceId;
|
||||
|
||||
@@ -89,11 +121,9 @@ public:
|
||||
virtual int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId,
|
||||
sptr<IUnregisterDInputCallback> callback) override;
|
||||
|
||||
virtual int32_t PrepareRemoteInput(const std::string& deviceId,
|
||||
sptr<IPrepareDInputCallback> callback, sptr<IAddWhiteListInfosCallback> addWhiteListCallback) override;
|
||||
virtual int32_t PrepareRemoteInput(const std::string &deviceId, sptr<IPrepareDInputCallback> callback) override;
|
||||
|
||||
virtual int32_t UnprepareRemoteInput(const std::string& deviceId,
|
||||
sptr<IUnprepareDInputCallback> callback, sptr<IDelWhiteListInfosCallback> delWhiteListCallback) override;
|
||||
virtual int32_t UnprepareRemoteInput(const std::string &deviceId, sptr<IUnprepareDInputCallback> callback) override;
|
||||
|
||||
virtual int32_t StartRemoteInput(
|
||||
const std::string& deviceId, const uint32_t& inputTypes, sptr<IStartDInputCallback> callback) override;
|
||||
@@ -101,8 +131,41 @@ public:
|
||||
virtual int32_t StopRemoteInput(
|
||||
const std::string& deviceId, const uint32_t& inputTypes, sptr<IStopDInputCallback> callback) override;
|
||||
|
||||
virtual int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes,
|
||||
sptr<IStartDInputCallback> callback) override;
|
||||
|
||||
virtual int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes,
|
||||
sptr<IStopDInputCallback> callback) override;
|
||||
|
||||
virtual int32_t PrepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IPrepareDInputCallback> callback) override;
|
||||
|
||||
virtual int32_t UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IUnprepareDInputCallback> callback) override;
|
||||
|
||||
virtual int32_t StartRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback) override;
|
||||
|
||||
virtual int32_t StopRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
|
||||
sptr<IStartStopDInputsCallback> callback) override;
|
||||
|
||||
virtual int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback) override;
|
||||
|
||||
virtual int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback) override;
|
||||
|
||||
virtual int32_t IsStartDistributedInput(
|
||||
const uint32_t& inputType, sptr<IStartDInputServerCallback> callback) override;
|
||||
virtual int32_t RegisterAddWhiteListCallback(sptr<IAddWhiteListInfosCallback> addWhiteListCallback) override;
|
||||
virtual int32_t RegisterDelWhiteListCallback(sptr<IDelWhiteListInfosCallback> delWhiteListCallback) override;
|
||||
virtual int32_t RegisterInputNodeListener(sptr<InputNodeListener> listener) override;
|
||||
virtual int32_t UnregisterInputNodeListener(sptr<InputNodeListener> listener) override;
|
||||
|
||||
virtual int32_t SyncNodeInfoRemoteInput(const std::string &userDevId, const std::string &dhId,
|
||||
const std::string &nodeDesc) override;
|
||||
virtual int32_t RegisterSimulationEventListener(sptr<ISimulationEventListener> listener) override;
|
||||
virtual int32_t UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener) override;
|
||||
|
||||
int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
|
||||
|
||||
@@ -115,6 +178,10 @@ public:
|
||||
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 onResponseStartRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result);
|
||||
void onResponseStopRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result);
|
||||
void onResponseKeyState(const std::string deviceId, const std::string &dhid, const uint32_t type,
|
||||
const uint32_t code, const uint32_t value);
|
||||
void onReceivedEventRemoteInput(const std::string deviceId, const std::string &event);
|
||||
void RecordEventLog(int64_t when, int32_t type, int32_t code, int32_t value, const std::string& path);
|
||||
|
||||
@@ -136,6 +203,9 @@ public:
|
||||
void NotifyUnprepareCallback(const AppExecFwk::InnerEvent::Pointer &event);
|
||||
void NotifyStartCallback(const AppExecFwk::InnerEvent::Pointer &event);
|
||||
void NotifyStopCallback(const AppExecFwk::InnerEvent::Pointer &event);
|
||||
void NotifyStartDhidCallback(const AppExecFwk::InnerEvent::Pointer &event);
|
||||
void NotifyStopDhidCallback(const AppExecFwk::InnerEvent::Pointer &event);
|
||||
void NotifyKeyStateCallback(const AppExecFwk::InnerEvent::Pointer &event);
|
||||
void NotifyStartServerCallback(const AppExecFwk::InnerEvent::Pointer &event);
|
||||
|
||||
DistributedInputSourceManager *sourceManagerObj_;
|
||||
@@ -162,6 +232,19 @@ public:
|
||||
int32_t ParseMessage(const std::string& message, std::string& sinkDevId, uint64_t& sourceWinId);
|
||||
};
|
||||
|
||||
class DeviceOfflineListener : public PublisherListenerStub {
|
||||
public:
|
||||
DeviceOfflineListener(DistributedInputSourceManager* srcManagerContext);
|
||||
~DeviceOfflineListener();
|
||||
void OnMessage(const DHTopic topic, const std::string &message);
|
||||
|
||||
private:
|
||||
void DeleteNodeInfoAndNotify(const std::string& offlineDevId);
|
||||
|
||||
private:
|
||||
DistributedInputSourceManager* sourceManagerContext_;
|
||||
};
|
||||
|
||||
std::shared_ptr<DInputSourceManagerEventHandler> GetCallbackEventHandler()
|
||||
{
|
||||
return callBackHandler_;
|
||||
@@ -187,6 +270,11 @@ public:
|
||||
const std::string& devId, const uint32_t& inputTypes, const int32_t& status
|
||||
);
|
||||
|
||||
void RunStartDhidCallback(const std::string &sinkId, const std::string &dhIds, const int32_t &status);
|
||||
void RunStopDhidCallback(const std::string &sinkId, const std::string &dhIds, const int32_t &status);
|
||||
void RunKeyStateCallback(const std::string &sinkId, const std::string &dhId, const uint32_t type,
|
||||
const uint32_t code, const uint32_t value);
|
||||
|
||||
IStartDInputServerCallback* GetStartDInputServerCback();
|
||||
DInputServerType GetStartTransFlag();
|
||||
void SetStartTransFlag(const DInputServerType flag);
|
||||
@@ -201,7 +289,6 @@ public:
|
||||
uint32_t GetAllInputTypesMap();
|
||||
|
||||
private:
|
||||
|
||||
struct DInputClientRegistInfo {
|
||||
std::string devId;
|
||||
std::string dhId;
|
||||
@@ -217,30 +304,45 @@ private:
|
||||
struct DInputClientPrepareInfo {
|
||||
std::string devId;
|
||||
sptr<IPrepareDInputCallback> preCallback = nullptr;
|
||||
sptr<IAddWhiteListInfosCallback> addWhiteListCallback = nullptr;
|
||||
|
||||
DInputClientPrepareInfo(std::string deviceId, sptr<IPrepareDInputCallback> prepareCallback,
|
||||
sptr<IAddWhiteListInfosCallback> addWhiteListCallback) : devId(deviceId), preCallback(prepareCallback),
|
||||
addWhiteListCallback(addWhiteListCallback) {}
|
||||
DInputClientPrepareInfo(std::string deviceId, sptr<IPrepareDInputCallback> prepareCallback)
|
||||
: devId(deviceId), preCallback(prepareCallback) {}
|
||||
};
|
||||
|
||||
struct DInputClientUnprepareInfo {
|
||||
std::string devId;
|
||||
sptr<IUnprepareDInputCallback> unpreCallback = nullptr;
|
||||
sptr<IDelWhiteListInfosCallback> delWhiteListCallback = nullptr;
|
||||
};
|
||||
|
||||
struct DInputClientStartInfo {
|
||||
std::string devId;
|
||||
uint32_t inputTypes;
|
||||
sptr<IStartDInputCallback> callback = nullptr;
|
||||
DInputClientStartInfo(std::string deviceId, uint32_t types, sptr<IStartDInputCallback> cb)
|
||||
: devId(deviceId), inputTypes(types), callback(cb) {}
|
||||
};
|
||||
|
||||
struct DInputClientStopInfo {
|
||||
std::string devId;
|
||||
uint32_t inputTypes;
|
||||
sptr<IStopDInputCallback> callback = nullptr;
|
||||
DInputClientStopInfo(std::string deviceId, uint32_t types, sptr<IStopDInputCallback> cb)
|
||||
: devId(deviceId), inputTypes(types), callback(cb) {}
|
||||
};
|
||||
// add new prepare/start function
|
||||
struct DInputClientStartDhidInfo {
|
||||
std::string srcId;
|
||||
std::string sinkId;
|
||||
std::vector<std::string> dhIds;
|
||||
sptr<IStartStopDInputsCallback> callback = nullptr;
|
||||
};
|
||||
struct DInputClientStopDhidInfo {
|
||||
std::string srcId;
|
||||
std::string sinkId;
|
||||
std::vector<std::string> dhIds;
|
||||
sptr<IStartStopDInputsCallback> callback = nullptr;
|
||||
};
|
||||
|
||||
ServiceSourceRunningState serviceRunningState_ = ServiceSourceRunningState::STATE_NOT_START;
|
||||
DInputServerType isStartTrans_ = DInputServerType::NULL_SERVER_TYPE;
|
||||
std::shared_ptr<DistributedInputSourceManager::DInputSourceListener> statuslistener_;
|
||||
@@ -253,6 +355,13 @@ private:
|
||||
std::vector<DInputClientStopInfo> stpCallbacks_;
|
||||
sptr<IStartDInputServerCallback> startServerCallback_ = nullptr;
|
||||
|
||||
std::vector<DInputClientStartDhidInfo> staStringCallbacks_;
|
||||
std::vector<DInputClientStopDhidInfo> stpStringCallbacks_;
|
||||
|
||||
sptr<IAddWhiteListInfosCallback> addWhiteListCallback_ = nullptr;
|
||||
sptr<IDelWhiteListInfosCallback> delWhiteListCallback_ = nullptr;
|
||||
std::set<sptr<ISimulationEventListener>> simulationEventCallbacks_;
|
||||
|
||||
std::map<std::string, int32_t> DeviceMap_;
|
||||
std::map<std::string, uint32_t> InputTypesMap_;
|
||||
std::shared_ptr<AppExecFwk::EventRunner> runner_;
|
||||
@@ -261,9 +370,38 @@ private:
|
||||
std::vector<InputDeviceId> inputDevice_;
|
||||
bool InitAuto();
|
||||
void handleStartServerCallback(const std::string& devId);
|
||||
std::mutex mutex_;
|
||||
std::mutex operationMutex_;
|
||||
sptr<StartDScreenListener> startDScreenListener_ = nullptr;
|
||||
sptr<StopDScreenListener> stopDScreenListener_ = nullptr;
|
||||
sptr<DeviceOfflineListener> deviceOfflineListener_ = nullptr;
|
||||
|
||||
std::mutex valMutex_;
|
||||
std::mutex syncNodeInfoMutex_;
|
||||
std::map<std::string, std::set<BeRegNodeInfo>> syncNodeInfoMap_;
|
||||
int32_t RelayStartRemoteInputByType(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes,
|
||||
sptr<IStartDInputCallback> callback);
|
||||
int32_t RelayStopRemoteInputByType(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes,
|
||||
sptr<IStopDInputCallback> callback);
|
||||
int32_t RelayPrepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IPrepareDInputCallback> callback);
|
||||
int32_t RelayUnprepareRemoteInput(const std::string &srcId, const std::string &sinkId,
|
||||
sptr<IUnprepareDInputCallback> callback);
|
||||
int32_t RelayStartRemoteInputByDhid(const std::string &srcId, const std::string &sinkId,
|
||||
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback);
|
||||
int32_t RelayStopRemoteInputByDhid(const std::string &srcId, const std::string &sinkId,
|
||||
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback);
|
||||
bool IsStringDataSame(const std::vector<std::string> &oldDhIds, std::vector<std::string> newDhIds);
|
||||
void StringSplitToVector(const std::string &str, const char split, std::vector<std::string> &vecStr);
|
||||
void DeleteNodeInfoAndNotify(const std::string& offlineDevId);
|
||||
void SendExistVirNodeInfos(sptr<InputNodeListener> listener);
|
||||
std::set<BeRegNodeInfo> GetSyncNodeInfo(const std::string& devId);
|
||||
void UpdateSyncNodeInfo(const std::string& devId, const std::string& dhId, const std::string &nodeDesc);
|
||||
void DeleteSyncNodeInfo(const std::string& devId);
|
||||
|
||||
private:
|
||||
IDInputDBGItf* dinputDbgItfPtr_ = nullptr;
|
||||
void InitDinputDBG();
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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_SA_CLI_MGR_H
|
||||
#define OHOS_DISTRIBUTED_INPUT_SOURCE_SA_CLI_MGR_H
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include "event_handler.h"
|
||||
|
||||
#include "i_distributed_source_input.h"
|
||||
#include "single_instance.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class DInputSourceSACliMgr {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(DInputSourceSACliMgr);
|
||||
public:
|
||||
DInputSourceSACliMgr();
|
||||
virtual ~DInputSourceSACliMgr();
|
||||
|
||||
sptr<IDistributedSourceInput> GetRemoteCli(const std::string &deviceId);
|
||||
|
||||
private:
|
||||
class RemoteCliDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
|
||||
};
|
||||
sptr<RemoteCliDeathRecipient> remoteCliDeathRcv;
|
||||
sptr<IDistributedSourceInput> GetRemoteCliFromCache(const std::string &devId);
|
||||
void AddRemoteCli(const std::string &devId, sptr<IRemoteObject> object);
|
||||
void DeleteRemoteCli(const std::string &devId);
|
||||
void DeleteRemoteCli(const sptr<IRemoteObject> object);
|
||||
void ProcRemoteCliDied(const sptr<IRemoteObject>& remote);
|
||||
|
||||
private:
|
||||
std::mutex remoteCliLock;
|
||||
std::map<std::string, sptr<IDistributedSourceInput>> remoteCliMap;
|
||||
std::shared_ptr<AppExecFwk::EventHandler> dinputMgrHandler_;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 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_source_sa_cli_mgr.h"
|
||||
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
#include "distributed_hardware_log.h"
|
||||
#include "anonymous_string.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
IMPLEMENT_SINGLE_INSTANCE(DInputSourceSACliMgr);
|
||||
DInputSourceSACliMgr::DInputSourceSACliMgr()
|
||||
{
|
||||
DHLOGI("Ctor DInputSourceSACliMgr");
|
||||
remoteCliDeathRcv = new RemoteCliDeathRecipient();
|
||||
|
||||
auto dinputMgrRunner = AppExecFwk::EventRunner::Create("DInputMgrHandler");
|
||||
if (!dinputMgrRunner) {
|
||||
DHLOGE("DInputSourceSACliMgr, dinputMgrRunner is null!");
|
||||
return;
|
||||
}
|
||||
dinputMgrHandler_ = std::make_shared<AppExecFwk::EventHandler>(dinputMgrRunner);
|
||||
if (!dinputMgrHandler_) {
|
||||
DHLOGE("DInputSourceSACliMgr, dinputMgrHandler_ is null!");
|
||||
}
|
||||
}
|
||||
|
||||
DInputSourceSACliMgr::~DInputSourceSACliMgr()
|
||||
{
|
||||
DHLOGI("Dtor DInputSourceSACliMgr");
|
||||
}
|
||||
|
||||
void DInputSourceSACliMgr::RemoteCliDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
|
||||
{
|
||||
DHLOGI("RemoteCliDeathRecipient::OnRemoteDied received died notify!");
|
||||
sptr<IRemoteObject> diedRemote = remote.promote();
|
||||
if (diedRemote == nullptr) {
|
||||
DHLOGE("RemoteCliDeathRecipient::OnRemoteDied promote failedy!");
|
||||
return;
|
||||
}
|
||||
|
||||
DInputSourceSACliMgr::GetInstance().ProcRemoteCliDied(diedRemote);
|
||||
}
|
||||
|
||||
sptr<IDistributedSourceInput> DInputSourceSACliMgr::GetRemoteCli(const std::string &deviceId)
|
||||
{
|
||||
if (deviceId.empty()) {
|
||||
DHLOGE("DInputSourceSACliMgr::GetRemoteCli deviceId is empty");
|
||||
return nullptr;
|
||||
}
|
||||
DHLOGI("DInputSourceSACliMgr::GetRemoteCli remote deviceid is %{public}s", GetAnonyString(deviceId).c_str());
|
||||
auto remoteCli = GetRemoteCliFromCache(deviceId);
|
||||
if (remoteCli != nullptr) {
|
||||
DHLOGD("VirtualHardwareManager::GetRemoteCli get from cache!");
|
||||
return remoteCli;
|
||||
}
|
||||
|
||||
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (samgr == nullptr) {
|
||||
DHLOGE("GetRemoteCli failed to connect to systemAbilityMgr!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto object = samgr->CheckSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, deviceId);
|
||||
if (object == nullptr) {
|
||||
DHLOGE("GetRemoteCli failed get remote Cli %{public}s", GetAnonyString(deviceId).c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AddRemoteCli(deviceId, object);
|
||||
return iface_cast<IDistributedSourceInput>(object);
|
||||
}
|
||||
|
||||
sptr<IDistributedSourceInput> DInputSourceSACliMgr::GetRemoteCliFromCache(const std::string &devId)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(remoteCliLock);
|
||||
auto iter = remoteCliMap.find(devId);
|
||||
if (iter != remoteCliMap.end()) {
|
||||
return iter->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void DInputSourceSACliMgr::AddRemoteCli(const std::string &devId, sptr<IRemoteObject> object)
|
||||
{
|
||||
if (devId.empty() || (object == nullptr)) {
|
||||
DHLOGW("DInputSourceSACliMgr::AddRemoteCli param error! devId=%{public}s", GetAnonyString(devId).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
DHLOGI("DInputSourceSACliMgr::AddRemoteCli devId=%{public}s", GetAnonyString(devId).c_str());
|
||||
object->AddDeathRecipient(remoteCliDeathRcv);
|
||||
|
||||
std::lock_guard<std::mutex> lock(remoteCliLock);
|
||||
auto item = remoteCliMap.find(devId);
|
||||
if ((item != remoteCliMap.end()) && item->second != nullptr) {
|
||||
item->second->AsObject()->RemoveDeathRecipient(remoteCliDeathRcv);
|
||||
}
|
||||
remoteCliMap[devId] = iface_cast<IDistributedSourceInput>(object);
|
||||
}
|
||||
|
||||
void DInputSourceSACliMgr::DeleteRemoteCli(const std::string &devId)
|
||||
{
|
||||
DHLOGI("DInputSourceSACliMgr::DeleteRemoteCli devId=%{public}s", GetAnonyString(devId).c_str());
|
||||
std::lock_guard<std::mutex> lock(remoteCliLock);
|
||||
auto item = remoteCliMap.find(devId);
|
||||
if (item == remoteCliMap.end()) {
|
||||
DHLOGI("DInputSourceSACliMgr::DeleteRemoteCli not found device");
|
||||
return;
|
||||
}
|
||||
|
||||
if (item->second != nullptr) {
|
||||
item->second->AsObject()->RemoveDeathRecipient(remoteCliDeathRcv);
|
||||
}
|
||||
remoteCliMap.erase(item);
|
||||
}
|
||||
|
||||
void DInputSourceSACliMgr::DeleteRemoteCli(const sptr<IRemoteObject> remote)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(remoteCliLock);
|
||||
auto iter = std::find_if(remoteCliMap.begin(), remoteCliMap.end(), [&](
|
||||
const std::pair<std::string, sptr<IDistributedSourceInput>> &item)->bool {
|
||||
return item.second->AsObject() == remote;
|
||||
});
|
||||
if (iter == remoteCliMap.end()) {
|
||||
DHLOGI("VirtualHardwareManager::DeleteRemoteCli not found remote object");
|
||||
return;
|
||||
}
|
||||
|
||||
DHLOGI("VirtualHardwareManager::DeleteRemoteCli remote.devId=%{public}s", GetAnonyString(iter->first).c_str());
|
||||
if (iter->second != nullptr) {
|
||||
iter->second->AsObject()->RemoveDeathRecipient(remoteCliDeathRcv);
|
||||
}
|
||||
remoteCliMap.erase(iter);
|
||||
}
|
||||
|
||||
void DInputSourceSACliMgr::ProcRemoteCliDied(const sptr<IRemoteObject>& remote)
|
||||
{
|
||||
auto remoteCliDiedProc = [this, remote]() {
|
||||
DeleteRemoteCli(remote);
|
||||
};
|
||||
if (!(dinputMgrHandler_ && dinputMgrHandler_->PostTask(remoteCliDiedProc))) {
|
||||
DHLOGE("DInputSourceSACliMgr::OnRemoteDied PostTask fail");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ ohos_unittest("distributed_input_sourcemanager_test") {
|
||||
"${ipc_path}/src",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/sourcemanager/include",
|
||||
"//foundation/distributedhardware/distributed_input/frameworks/include",
|
||||
"//foundation/distributedhardware/distributed_input/inputdevicehandler/include",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"${common_path}/include",
|
||||
@@ -56,6 +57,7 @@ ohos_unittest("distributed_input_sourcemanager_test") {
|
||||
]
|
||||
|
||||
sources = [
|
||||
"${common_path}/include/dinput_struct_data.cpp",
|
||||
"${common_path}/include/input_hub.cpp",
|
||||
"${ipc_path}/src/add_white_list_infos_call_back_proxy.cpp",
|
||||
"${ipc_path}/src/add_white_list_infos_call_back_stub.cpp",
|
||||
@@ -88,6 +90,7 @@ ohos_unittest("distributed_input_sourcemanager_test") {
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_touchscreen.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/sourcemanager/src/distributed_input_source_event_handler.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/sourcemanager/src/distributed_input_source_manager.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/sourcemanager/src/distributed_input_source_sa_cli_mgr.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/transport/src/distributed_input_source_transport.cpp",
|
||||
"distributed_input_sourcemanager_test.cpp",
|
||||
]
|
||||
@@ -121,6 +124,7 @@ ohos_unittest("distributed_input_sourcemanager_test") {
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
"${innerkits_path}:libdinput_sdk",
|
||||
"${distributedinput_path}/inputdevicehandler:libdinput_handler",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
+280
-15
@@ -105,6 +105,14 @@ void DistributedInputSourceManagerTest::TestStopDInputCallback::OnResult(
|
||||
return;
|
||||
}
|
||||
|
||||
void DistributedInputSourceManagerTest::TestStartStopVectorCallbackStub::OnResultDhids(const std::string &devId,
|
||||
const int32_t &status)
|
||||
{
|
||||
(void)devId;
|
||||
(void)status;
|
||||
return;
|
||||
}
|
||||
|
||||
void DistributedInputSourceManagerTest::TestAddWhiteListInfosCb::OnResult(
|
||||
const std::string &deviceId, const std::string &strJson)
|
||||
{
|
||||
@@ -120,6 +128,43 @@ void DistributedInputSourceManagerTest::TestDelWhiteListInfosCb::OnResult(
|
||||
return;
|
||||
}
|
||||
|
||||
void DistributedInputSourceManagerTest::TestStartStopResultCb::OnStart(const std::string &srcId,
|
||||
const std::string &sinkId, std::vector<std::string> &devData)
|
||||
{
|
||||
(void)srcId;
|
||||
(void)sinkId;
|
||||
(void)devData;
|
||||
return;
|
||||
}
|
||||
|
||||
void DistributedInputSourceManagerTest::TestStartStopResultCb::OnStop(const std::string &srcId,
|
||||
const std::string &sinkId, std::vector<std::string> &devData)
|
||||
{
|
||||
(void)srcId;
|
||||
(void)sinkId;
|
||||
(void)devData;
|
||||
return;
|
||||
}
|
||||
|
||||
void DistributedInputSourceManagerTest::TestInputNodeListenerCb::OnNodeOnLine(const std::string srcDevId,
|
||||
const std::string sinkDevId, const std::string sinkNodeId, const std::string sinkNodeDesc)
|
||||
{
|
||||
(void)srcDevId;
|
||||
(void)sinkDevId;
|
||||
(void)sinkNodeId;
|
||||
(void)sinkNodeDesc;
|
||||
return;
|
||||
}
|
||||
|
||||
void DistributedInputSourceManagerTest::TestInputNodeListenerCb::OnNodeOffLine(const std::string srcDevId,
|
||||
const std::string sinkDevId, const std::string sinkNodeId)
|
||||
{
|
||||
(void)srcDevId;
|
||||
(void)sinkDevId;
|
||||
(void)sinkNodeId;
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceManagerTest::StructTransJson(const InputDevice& pBuf, std::string& strDescriptor) const
|
||||
{
|
||||
nlohmann::json tmpJson;
|
||||
@@ -139,6 +184,12 @@ int32_t DistributedInputSourceManagerTest::StructTransJson(const InputDevice& pB
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, Init01, testing::ext::TestSize.Level0)
|
||||
{
|
||||
int32_t ret = sourceManager_->Init();
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_INIT_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, RegisterDistributedHardware01, testing::ext::TestSize.Level0)
|
||||
{
|
||||
InputDevice pBuffer;
|
||||
@@ -211,8 +262,7 @@ HWTEST_F(DistributedInputSourceManagerTest, PrepareRemoteInput01, testing::ext::
|
||||
{
|
||||
std::string devId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
sptr<TestPrepareDInputCallback> callback = new TestPrepareDInputCallback();
|
||||
sptr<TestAddWhiteListInfosCb> addWhiteListCallback = new TestAddWhiteListInfosCb();
|
||||
int32_t ret = sourceManager_->PrepareRemoteInput(devId, callback, addWhiteListCallback);
|
||||
int32_t ret = sourceManager_->PrepareRemoteInput(devId, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, ret);
|
||||
}
|
||||
|
||||
@@ -220,8 +270,7 @@ HWTEST_F(DistributedInputSourceManagerTest, PrepareRemoteInput02, testing::ext::
|
||||
{
|
||||
std::string devId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
sptr<TestPrepareDInputCallback> callback;
|
||||
sptr<TestAddWhiteListInfosCb> addWhiteListCallback = new TestAddWhiteListInfosCb();
|
||||
int32_t ret = sourceManager_->PrepareRemoteInput(devId, callback, addWhiteListCallback);
|
||||
int32_t ret = sourceManager_->PrepareRemoteInput(devId, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, ret);
|
||||
}
|
||||
|
||||
@@ -229,8 +278,34 @@ HWTEST_F(DistributedInputSourceManagerTest, PrepareRemoteInput03, testing::ext::
|
||||
{
|
||||
std::string devId = "";
|
||||
sptr<TestPrepareDInputCallback> callback = new TestPrepareDInputCallback();
|
||||
sptr<TestAddWhiteListInfosCb> addWhiteListCallback = new TestAddWhiteListInfosCb();
|
||||
int32_t ret = sourceManager_->PrepareRemoteInput(devId, callback, addWhiteListCallback);
|
||||
int32_t ret = sourceManager_->PrepareRemoteInput(devId, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, PrepareRemoteInput04, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "umkyu1b165e1be98151891erbe8r91eb";
|
||||
std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
sptr<TestPrepareDInputCallback> callback = new TestPrepareDInputCallback();
|
||||
int32_t ret = sourceManager_->PrepareRemoteInput(srcId, sinkId, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, PrepareRemoteInput05, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "umkyu1b165e1be98151891erbe8r91eb";
|
||||
std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
sptr<TestPrepareDInputCallback> callback;
|
||||
int32_t ret = sourceManager_->PrepareRemoteInput(srcId, sinkId, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, PrepareRemoteInput06, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "";
|
||||
std::string sinkId = "";
|
||||
sptr<TestPrepareDInputCallback> callback = new TestPrepareDInputCallback();
|
||||
int32_t ret = sourceManager_->PrepareRemoteInput(srcId, sinkId, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, ret);
|
||||
}
|
||||
|
||||
@@ -258,6 +333,68 @@ HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput03, testing::ext::Te
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput04, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "umkyu1b165e1be98151891erbe8r91eb";
|
||||
std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
sptr<TestStartDInputCallback> callback = new TestStartDInputCallback();
|
||||
int32_t ret =
|
||||
sourceManager_->StartRemoteInput(srcId, sinkId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput05, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "umkyu1b165e1be98151891erbe8r91eb";
|
||||
std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
sptr<TestStartDInputCallback> callback;
|
||||
int32_t ret =
|
||||
sourceManager_->StartRemoteInput(srcId, sinkId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput06, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "";
|
||||
std::string sinkId = "";
|
||||
sptr<TestStartDInputCallback> callback = new TestStartDInputCallback();
|
||||
int32_t ret =
|
||||
sourceManager_->StartRemoteInput(srcId, sinkId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput10, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "umkyu1b165e1be98151891erbe8r91eb";
|
||||
std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
std::vector<std::string> dhIds;
|
||||
dhIds.push_back("Input_slkdiek3kddkeojfe");
|
||||
sptr<TestStartStopVectorCallbackStub> callback = new TestStartStopVectorCallbackStub();
|
||||
int32_t ret = sourceManager_->StartRemoteInput(srcId, sinkId, dhIds, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput11, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "umkyu1b165e1be98151891erbe8r91eb";
|
||||
std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
std::vector<std::string> dhIds;
|
||||
sptr<TestStartStopVectorCallbackStub> callback;
|
||||
int32_t ret = sourceManager_->StartRemoteInput(srcId, sinkId, dhIds, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput12, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "";
|
||||
std::string sinkId = "";
|
||||
std::vector<std::string> dhIds;
|
||||
dhIds.push_back("Input_sldkjfldsjf234mdwswo");
|
||||
sptr<TestStartStopVectorCallbackStub> callback = new TestStartStopVectorCallbackStub();
|
||||
int32_t ret = sourceManager_->StartRemoteInput(srcId, sinkId, dhIds, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput01, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string devId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
@@ -282,12 +419,73 @@ HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput03, testing::ext::Tes
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput04, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
sptr<TestStopDInputCallback> callback = new TestStopDInputCallback();
|
||||
int32_t ret =
|
||||
sourceManager_->StopRemoteInput(srcId, sinkId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput05, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "";
|
||||
std::string sinkId = "";
|
||||
sptr<TestStopDInputCallback> callback = new TestStopDInputCallback();
|
||||
int32_t ret =
|
||||
sourceManager_->StopRemoteInput(srcId, sinkId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput06, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
sptr<TestStopDInputCallback> callback;
|
||||
int32_t ret =
|
||||
sourceManager_->StopRemoteInput(srcId, sinkId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput10, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "umkyu1b165e1be98151891erbe8r91eb";
|
||||
std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
std::vector<std::string> dhIds;
|
||||
dhIds.push_back("Input_slkdiek3kddkeojfe");
|
||||
sptr<TestStartStopVectorCallbackStub> callback = new TestStartStopVectorCallbackStub();
|
||||
int32_t ret = sourceManager_->StopRemoteInput(srcId, sinkId, dhIds, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput11, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "umkyu1b165e1be98151891erbe8r91eb";
|
||||
std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
std::vector<std::string> dhIds;
|
||||
sptr<TestStartStopVectorCallbackStub> callback;
|
||||
int32_t ret = sourceManager_->StopRemoteInput(srcId, sinkId, dhIds, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput12, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "";
|
||||
std::string sinkId = "";
|
||||
std::vector<std::string> dhIds;
|
||||
dhIds.push_back("Input_sldkjfldsjf234mdwswo");
|
||||
sptr<TestStartStopVectorCallbackStub> callback = new TestStartStopVectorCallbackStub();
|
||||
int32_t ret = sourceManager_->StopRemoteInput(srcId, sinkId, dhIds, 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<TestUnprepareDInputCallback> callback = new TestUnprepareDInputCallback();
|
||||
sptr<TestDelWhiteListInfosCb> delWhiteListCallback = new TestDelWhiteListInfosCb();
|
||||
int32_t ret = sourceManager_->UnprepareRemoteInput(devId, callback, delWhiteListCallback);
|
||||
int32_t ret = sourceManager_->UnprepareRemoteInput(devId, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret);
|
||||
}
|
||||
|
||||
@@ -295,8 +493,7 @@ HWTEST_F(DistributedInputSourceManagerTest, UnprepareRemoteInput02, testing::ext
|
||||
{
|
||||
std::string devId = "";
|
||||
sptr<TestUnprepareDInputCallback> callback = new TestUnprepareDInputCallback();
|
||||
sptr<TestDelWhiteListInfosCb> delWhiteListCallback = new TestDelWhiteListInfosCb();
|
||||
int32_t ret = sourceManager_->UnprepareRemoteInput(devId, callback, delWhiteListCallback);
|
||||
int32_t ret = sourceManager_->UnprepareRemoteInput(devId, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret);
|
||||
}
|
||||
|
||||
@@ -304,8 +501,34 @@ HWTEST_F(DistributedInputSourceManagerTest, UnprepareRemoteInput03, testing::ext
|
||||
{
|
||||
std::string devId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
sptr<TestUnprepareDInputCallback> callback;
|
||||
sptr<TestDelWhiteListInfosCb> delWhiteListCallback;
|
||||
int32_t ret = sourceManager_->UnprepareRemoteInput(devId, callback, delWhiteListCallback);
|
||||
int32_t ret = sourceManager_->UnprepareRemoteInput(devId, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, UnprepareRemoteInput04, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "umkyu1b165e1be98151891erbe8r91eb";
|
||||
std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
sptr<TestUnprepareDInputCallback> callback = new TestUnprepareDInputCallback();
|
||||
int32_t ret = sourceManager_->UnprepareRemoteInput(srcId, sinkId, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, UnprepareRemoteInput05, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "";
|
||||
std::string sinkId = "";
|
||||
sptr<TestUnprepareDInputCallback> callback = new TestUnprepareDInputCallback();
|
||||
int32_t ret = sourceManager_->UnprepareRemoteInput(srcId, sinkId, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, UnprepareRemoteInput06, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string srcId = "umkyu1b165e1be98151891erbe8r91eb";
|
||||
std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev";
|
||||
sptr<TestUnprepareDInputCallback> callback;
|
||||
int32_t ret = sourceManager_->UnprepareRemoteInput(srcId, sinkId, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret);
|
||||
}
|
||||
|
||||
@@ -335,6 +558,48 @@ HWTEST_F(DistributedInputSourceManagerTest, UnregisterDistributedHardware03, tes
|
||||
int32_t ret = sourceManager_->UnregisterDistributedHardware(devId, dhId, callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL, ret);
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, RegisterAddWhiteListCallback01, testing::ext::TestSize.Level0)
|
||||
{
|
||||
sptr<TestAddWhiteListInfosCb> callback;
|
||||
int32_t ret = sourceManager_->RegisterAddWhiteListCallback(callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REG_CALLBACK_ERR, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, RegisterAddWhiteListCallback02, testing::ext::TestSize.Level0)
|
||||
{
|
||||
sptr<TestAddWhiteListInfosCb> callback = new TestAddWhiteListInfosCb();
|
||||
int32_t ret = sourceManager_->RegisterAddWhiteListCallback(callback);
|
||||
EXPECT_EQ(DH_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, RegisterDelWhiteListCallback01, testing::ext::TestSize.Level0)
|
||||
{
|
||||
sptr<TestDelWhiteListInfosCb> callback;
|
||||
int32_t ret = sourceManager_->RegisterDelWhiteListCallback(callback);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REG_CALLBACK_ERR, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, RegisterDelWhiteListCallback02, testing::ext::TestSize.Level0)
|
||||
{
|
||||
sptr<TestDelWhiteListInfosCb> callback = new TestDelWhiteListInfosCb();
|
||||
int32_t ret = sourceManager_->RegisterDelWhiteListCallback(callback);
|
||||
EXPECT_EQ(DH_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, RegisterInputNodeListener01, testing::ext::TestSize.Level0)
|
||||
{
|
||||
sptr<TestInputNodeListenerCb> callback = new TestInputNodeListenerCb();
|
||||
int32_t ret = sourceManager_->RegisterInputNodeListener(callback);
|
||||
EXPECT_EQ(DH_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceManagerTest, UnRegisterInputNodeListener01, testing::ext::TestSize.Level0)
|
||||
{
|
||||
sptr<TestInputNodeListenerCb> callback = new TestInputNodeListenerCb();
|
||||
int32_t ret = sourceManager_->UnregisterInputNodeListener(callback);
|
||||
EXPECT_EQ(DH_SUCCESS, ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+30
@@ -33,6 +33,9 @@
|
||||
#include "stop_d_input_call_back_stub.h"
|
||||
#include "unprepare_d_input_call_back_stub.h"
|
||||
#include "unregister_d_input_call_back_stub.h"
|
||||
#include "start_stop_d_inputs_call_back_stub.h"
|
||||
#include "start_stop_result_call_back_stub.h"
|
||||
#include "input_node_listener_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
@@ -76,6 +79,14 @@ public:
|
||||
void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status);
|
||||
};
|
||||
|
||||
class TestStartStopVectorCallbackStub
|
||||
: public OHOS::DistributedHardware::DistributedInput::StartStopDInputsCallbackStub {
|
||||
public:
|
||||
TestStartStopVectorCallbackStub() = default;
|
||||
virtual ~TestStartStopVectorCallbackStub() = default;
|
||||
void OnResultDhids(const std::string &devId, const int32_t &status);
|
||||
};
|
||||
|
||||
class TestRegisterDInputCb : public OHOS::DistributedHardware::DistributedInput::RegisterDInputCallbackStub {
|
||||
public:
|
||||
TestRegisterDInputCb() = default;
|
||||
@@ -104,6 +115,25 @@ public:
|
||||
void OnResult(const std::string &deviceId);
|
||||
};
|
||||
|
||||
class TestStartStopResultCb : public OHOS::DistributedHardware::DistributedInput::StartStopResultCallbackStub {
|
||||
public:
|
||||
TestStartStopResultCb() = default;
|
||||
virtual ~TestStartStopResultCb() = default;
|
||||
void OnStart(const std::string &srcId, const std::string &sinkId, std::vector<std::string> &devData);
|
||||
void OnStop(const std::string &srcId, const std::string &sinkId, std::vector<std::string> &devData);
|
||||
};
|
||||
|
||||
class TestInputNodeListenerCb : public OHOS::DistributedHardware::DistributedInput::InputNodeListenerStub {
|
||||
public:
|
||||
TestInputNodeListenerCb() = default;
|
||||
virtual ~TestInputNodeListenerCb() = default;
|
||||
void OnNodeOnLine(const std::string srcDevId, const std::string sinkDevId,
|
||||
const std::string sinkNodeId, const std::string sinkNodeDesc);
|
||||
|
||||
void OnNodeOffLine(const std::string srcDevId, const std::string sinkDevId,
|
||||
const std::string sinkNodeId);
|
||||
};
|
||||
|
||||
private:
|
||||
int32_t StructTransJson(const InputDevice& pBuf, std::string& strDescriptor) const;
|
||||
DistributedInputSourceManager* sourceManager_;
|
||||
|
||||
@@ -34,6 +34,8 @@ ohos_shared_library("libdinput_source_trans") {
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"${low_latency_path}/include",
|
||||
"${frameworks_path}/include",
|
||||
"${distributedinput_path}/inputdevicehandler/include",
|
||||
]
|
||||
|
||||
sources = [ "src/distributed_input_source_transport.cpp" ]
|
||||
@@ -57,6 +59,7 @@ ohos_shared_library("libdinput_source_trans") {
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp:devicemanagersdk",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject",
|
||||
"${distributedinput_path}/inputdevicehandler:libdinput_handler",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -54,6 +54,9 @@ public:
|
||||
void StartLatencyThread(const std::string& deviceId);
|
||||
void StopLatencyThread();
|
||||
|
||||
int32_t StartRemoteInput(const std::string &deviceId, const std::vector<std::string> &dhids);
|
||||
int32_t StopRemoteInput(const std::string &deviceId, const std::vector<std::string> &dhids);
|
||||
|
||||
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);
|
||||
@@ -69,6 +72,9 @@ private:
|
||||
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 NotifyResponseStartRemoteInputDhid(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
void NotifyResponseStopRemoteInputDhid(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
void NotifyResponseKeyState(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
void NotifyReceivedEventRemoteInput(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
void CalculateLatency(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
|
||||
|
||||
@@ -297,7 +297,7 @@ int32_t DistributedInputSourceTransport::StartRemoteInput(
|
||||
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_CMD_TYPE] = TRANS_SOURCE_MSG_START_TYPE;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes;
|
||||
@@ -325,7 +325,7 @@ int32_t DistributedInputSourceTransport::StopRemoteInput(
|
||||
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_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_TYPE;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes;
|
||||
@@ -410,6 +410,72 @@ void DistributedInputSourceTransport::StopLatencyThread()
|
||||
DHLOGI("end");
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceTransport::StartRemoteInput(const std::string &deviceId,
|
||||
const std::vector<std::string> &dhids)
|
||||
{
|
||||
std::unique_lock<std::mutex> sessionLock(operationMutex_);
|
||||
if (sessionDevMap_.count(deviceId) == 0) {
|
||||
DHLOGE("StartRemoteInput error, not find this device:%s.", GetAnonyString(deviceId).c_str());
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL;
|
||||
}
|
||||
int32_t sessionId = sessionDevMap_[deviceId];
|
||||
nlohmann::json jsonStr;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_START_DHID;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId;
|
||||
std::string strTmp = "";
|
||||
for (auto iter : dhids) {
|
||||
strTmp = strTmp + iter + ".";
|
||||
}
|
||||
if (!strTmp.empty()) {
|
||||
strTmp.erase(strTmp.end() - 1); // delete the last '.' char
|
||||
}
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = strTmp;
|
||||
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;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceTransport::StopRemoteInput(const std::string &deviceId,
|
||||
const std::vector<std::string> &dhids)
|
||||
{
|
||||
std::unique_lock<std::mutex> sessionLock(operationMutex_);
|
||||
if (sessionDevMap_.count(deviceId) == 0) {
|
||||
DHLOGE("StopRemoteInput error, not find this device:%s.", GetAnonyString(deviceId).c_str());
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL;
|
||||
}
|
||||
int32_t sessionId = sessionDevMap_[deviceId];
|
||||
nlohmann::json jsonStr;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_DHID;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId;
|
||||
std::string strTmp = "";
|
||||
for (auto iter : dhids) {
|
||||
strTmp = strTmp + iter + ".";
|
||||
}
|
||||
if (!strTmp.empty()) {
|
||||
strTmp.erase(strTmp.end() - 1); // delete the last '.' char
|
||||
}
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = strTmp;
|
||||
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;
|
||||
}
|
||||
|
||||
std::string DistributedInputSourceTransport::FindDeviceBySession(int32_t sessionId)
|
||||
{
|
||||
std::unique_lock<std::mutex> sessionLock(operationMutex_);
|
||||
@@ -553,6 +619,52 @@ void DistributedInputSourceTransport::NotifyResponseStopRemoteInput(int32_t sess
|
||||
deviceId, recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE], recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE]);
|
||||
}
|
||||
|
||||
void DistributedInputSourceTransport::NotifyResponseStartRemoteInputDhid(int32_t sessionId,
|
||||
const nlohmann::json &recMsg)
|
||||
{
|
||||
DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_DHID_ONSTART.");
|
||||
if (!recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE].is_boolean()) {
|
||||
DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_DHID_ONSTART, data type is error.");
|
||||
return;
|
||||
}
|
||||
std::string deviceId = FindDeviceBySession(sessionId);
|
||||
if (deviceId.empty()) {
|
||||
DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_DHID_ONSTART, deviceId is error.");
|
||||
return;
|
||||
}
|
||||
callback_->onResponseStartRemoteInputDhid(
|
||||
deviceId, recMsg[DINPUT_SOFTBUS_KEY_VECTOR_DHID], recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE]);
|
||||
}
|
||||
|
||||
void DistributedInputSourceTransport::NotifyResponseStopRemoteInputDhid(int32_t sessionId, const nlohmann::json &recMsg)
|
||||
{
|
||||
DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_DHID_ONSTOP.");
|
||||
if (!recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE].is_boolean()) {
|
||||
DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_DHID_ONSTOP, data type is error.");
|
||||
return;
|
||||
}
|
||||
std::string deviceId = FindDeviceBySession(sessionId);
|
||||
if (deviceId.empty()) {
|
||||
DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_DHID_ONSTOP, deviceId is error.");
|
||||
return;
|
||||
}
|
||||
callback_->onResponseStopRemoteInputDhid(
|
||||
deviceId, recMsg[DINPUT_SOFTBUS_KEY_VECTOR_DHID], recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE]);
|
||||
}
|
||||
|
||||
void DistributedInputSourceTransport::NotifyResponseKeyState(int32_t sessionId, const nlohmann::json &recMsg)
|
||||
{
|
||||
DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_KEY_STATE.");
|
||||
std::string deviceId = FindDeviceBySession(sessionId);
|
||||
if (deviceId.empty()) {
|
||||
DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_KEY_STATE, deviceId is error.");
|
||||
return;
|
||||
}
|
||||
callback_->onResponseKeyState(deviceId, recMsg[DINPUT_SOFTBUS_KEY_KEYSTATE_DHID],
|
||||
recMsg[DINPUT_SOFTBUS_KEY_KEYSTATE_TYPE], recMsg[DINPUT_SOFTBUS_KEY_KEYSTATE_CODE],
|
||||
recMsg[DINPUT_SOFTBUS_KEY_KEYSTATE_VALUE]);
|
||||
}
|
||||
|
||||
void DistributedInputSourceTransport::NotifyReceivedEventRemoteInput(int32_t sessionId, const nlohmann::json &recMsg)
|
||||
{
|
||||
DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_BODY_DATA.");
|
||||
@@ -622,6 +734,18 @@ void DistributedInputSourceTransport::HandleSessionData(int32_t sessionId, const
|
||||
CalculateLatency(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SINK_MSG_DHID_ONSTART: {
|
||||
NotifyResponseStartRemoteInputDhid(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SINK_MSG_DHID_ONSTOP: {
|
||||
NotifyResponseStopRemoteInputDhid(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SINK_MSG_KEY_STATE: {
|
||||
NotifyResponseKeyState(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
DHLOGE("OnBytesReceived cmdType is undefined.");
|
||||
break;
|
||||
@@ -688,7 +812,7 @@ int32_t DistributedInputSourceTransport::GetCurrentSessionId()
|
||||
// send message by sessionId (channel opened)
|
||||
int32_t DistributedInputSourceTransport::SendMsg(int32_t sessionId, std::string &message)
|
||||
{
|
||||
DHLOGI("start SendMsg");
|
||||
DHLOGD("start SendMsg");
|
||||
if (message.size() > MSG_MAX_SIZE) {
|
||||
DHLOGE("SendMessage error: message.size() > MSG_MAX_SIZE");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE;
|
||||
|
||||
@@ -43,6 +43,8 @@ ohos_unittest("distributed_input_sourcetrans_test") {
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"${low_latency_path}/include",
|
||||
"${frameworks_path}/include",
|
||||
"${distributedinput_path}/inputdevicehandler/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -73,6 +75,7 @@ ohos_unittest("distributed_input_sourcetrans_test") {
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp:devicemanagersdk",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject",
|
||||
"${distributedinput_path}/inputdevicehandler:libdinput_handler",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
+6
@@ -38,6 +38,12 @@ void DistributedInputSourceTransTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceTransTest, Init, testing::ext::TestSize.Level0)
|
||||
{
|
||||
int32_t ret = DistributedInputSourceTransport::GetInstance().Init();
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_INIT_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputSourceTransTest, PrepareRemoteInput01, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string deviceId = "";
|
||||
|
||||
@@ -85,6 +85,21 @@ public:
|
||||
};
|
||||
};
|
||||
|
||||
class TestIStartStopDInputsCallback : public OHOS::DistributedHardware
|
||||
::DistributedInput::IStartStopDInputsCallback {
|
||||
public:
|
||||
virtual void OnResultDhids(const std::string &devId, const int32_t &status) override
|
||||
{
|
||||
(void)devId;
|
||||
(void)status;
|
||||
};
|
||||
|
||||
virtual sptr<IRemoteObject> AsObject() override
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
void PrepareInputFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size <= 0)) {
|
||||
@@ -105,13 +120,16 @@ void StartRemoteInputFuzzTest(const uint8_t* data, size_t size)
|
||||
return;
|
||||
}
|
||||
|
||||
std::string dhId(reinterpret_cast<const char*>(data), size);
|
||||
std::string srcId = "123";
|
||||
std::string sinkId = "456";
|
||||
uint32_t inputTypes = *(reinterpret_cast<const uint32_t*>(data));
|
||||
|
||||
OHOS::sptr<TestStartDInputCallback> startCb = new(std::nothrow) TestStartDInputCallback();
|
||||
OHOS::sptr<TestStopDInputCallback> stopCb = new(std::nothrow) TestStopDInputCallback();
|
||||
DistributedInput::DistributedInputKit::StartRemoteInput(dhId, inputTypes, startCb);
|
||||
DistributedInput::DistributedInputKit::StopRemoteInput(dhId, inputTypes, stopCb);
|
||||
std::vector<std::string> dhIds= {};
|
||||
OHOS::sptr<TestStartDInputCallback> startCb = new (std::nothrow) TestStartDInputCallback();
|
||||
OHOS::sptr<TestStopDInputCallback> stopCb = new (std::nothrow) TestStopDInputCallback();
|
||||
DistributedInput::DistributedInputKit::StartRemoteInput(srcId, sinkId, inputTypes, startCb);
|
||||
DistributedInput::DistributedInputKit::StopRemoteInput(srcId, sinkId, inputTypes, stopCb);
|
||||
OHOS::sptr<TestIStartStopDInputsCallback> callback = new (std::nothrow) TestIStartStopDInputsCallback();
|
||||
DistributedInput::DistributedInputKit::StartRemoteInput(sinkId, dhIds, callback);
|
||||
}
|
||||
|
||||
void IsNeedFilterOutFuzzTest(const uint8_t* data, size_t size)
|
||||
@@ -131,6 +149,23 @@ void IsNeedFilterOutFuzzTest(const uint8_t* data, size_t size)
|
||||
|
||||
DistributedInput::DistributedInputKit::IsNeedFilterOut(deviceId, event);
|
||||
}
|
||||
void StopRemoteInputFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size <= 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string srcId = "123";
|
||||
std::string sinkId = "456";
|
||||
uint32_t inputTypes = *(reinterpret_cast<const uint32_t*>(data));
|
||||
std::vector<std::string> dhIds = {};
|
||||
OHOS::sptr<TestStartDInputCallback> startCb = new (std::nothrow) TestStartDInputCallback();
|
||||
OHOS::sptr<TestStopDInputCallback> stopCb = new (std::nothrow) TestStopDInputCallback();
|
||||
DistributedInput::DistributedInputKit::StopRemoteInput(sinkId, inputTypes, stopCb);
|
||||
DistributedInput::DistributedInputKit::StopRemoteInput(srcId, sinkId, inputTypes, stopCb);
|
||||
OHOS::sptr<TestIStartStopDInputsCallback> callback = new (std::nothrow) TestIStartStopDInputsCallback();
|
||||
DistributedInput::DistributedInputKit::StopRemoteInput(sinkId, dhIds, callback);
|
||||
}
|
||||
|
||||
void IsTouchEventNeedFilterOutFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
@@ -156,6 +191,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
OHOS::DistributedHardware::PrepareInputFuzzTest(data, size);
|
||||
OHOS::DistributedHardware::StartRemoteInputFuzzTest(data, size);
|
||||
OHOS::DistributedHardware::IsNeedFilterOutFuzzTest(data, size);
|
||||
OHOS::DistributedHardware::StopRemoteInputFuzzTest(data, size);
|
||||
OHOS::DistributedHardware::IsTouchEventNeedFilterOutFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
@@ -41,6 +41,8 @@ ohos_fuzztest("DistributedInputSourceTransportFuzzTest") {
|
||||
"${utils_path}/include",
|
||||
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter",
|
||||
"${low_latency_path}/include",
|
||||
"${frameworks_path}/include",
|
||||
"${distributedinput_path}/inputdevicehandler/include",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
@@ -64,6 +66,7 @@ ohos_fuzztest("DistributedInputSourceTransportFuzzTest") {
|
||||
"//foundation/distributedhardware/distributed_input/interfaces/inner_kits:libdinput_sdk",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/transport:libdinput_source_trans",
|
||||
"${distributedinput_path}/inputdevicehandler:libdinput_handler",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -41,6 +41,7 @@ bool IsString(const nlohmann::json& jsonObj, const std::string& key);
|
||||
bool IsInt32(const nlohmann::json& jsonObj, const std::string& key);
|
||||
bool IsUint32(const nlohmann::json& jsonObj, const std::string& key);
|
||||
bool IsUint64(const nlohmann::json& jsonObj, const std::string& key);
|
||||
std::string GetNodeDesc(std::string parameters);
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -49,7 +49,7 @@ void SetSinkProcessExit()
|
||||
#ifdef DINPUT_LOW_LATENCY
|
||||
DInputLowLatency::GetInstance().DisableSinkLowLatency();
|
||||
#endif
|
||||
exit(0);
|
||||
_Exit(0);
|
||||
}
|
||||
|
||||
void SetSourceProcessExit()
|
||||
@@ -66,7 +66,7 @@ void SetSourceProcessExit()
|
||||
#ifdef DINPUT_LOW_LATENCY
|
||||
DInputLowLatency::GetInstance().DisableSourceLowLatency();
|
||||
#endif
|
||||
exit(0);
|
||||
_Exit(0);
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -127,6 +127,18 @@ bool IsUint64(const nlohmann::json& jsonObj, const std::string& key)
|
||||
DHLOGI("the key %s in json is %s", key.c_str(), res ? "valid" : "invalid");
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string GetNodeDesc(std::string parameters)
|
||||
{
|
||||
nlohmann::json parObj = nlohmann::json::parse(parameters);
|
||||
std::string nodeName = "N/A";
|
||||
int32_t classes = -1;
|
||||
if (parObj.find("name") != parObj.end() && parObj.find("classes") != parObj.end()) {
|
||||
nodeName = parObj.at("name").get<std::string>();
|
||||
classes = parObj.at("classes").get<int32_t>();
|
||||
}
|
||||
return "{ NodeName: " + nodeName + ", classes: " + std::to_string(classes) + " }";
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
Reference in New Issue
Block a user