Description:fix errno

Match-id-be63bb08bc704af2922d63718808cf11a8213b6a
This commit is contained in:
xxxx
2022-05-23 11:07:55 +08:00
parent 5e4da24c12
commit 081bf1ec11
28 changed files with 501 additions and 366 deletions
+121
View File
@@ -0,0 +1,121 @@
/*
* 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_ERRCODE_H
#define OHOS_DINPUT_ERRCODE_H
#include <cstdint>
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
constexpr int32_t DH_SUCCESS = 0;
constexpr int32_t ERR_DH_INPUT_HUB_EPOLL_INIT_FAIL = -60000;
constexpr int32_t ERR_DH_INPUT_HUB_EPOLL_WAIT_TIMEOUT = -60001;
constexpr int32_t ERR_DH_INPUT_HUB_OPEN_DEVICEPATH_FAIL = -60002;
constexpr int32_t ERR_DH_INPUT_HUB_MAKE_INPUT_DEVICE_FAIL = -60003;
constexpr int32_t ERR_DH_INPUT_HUB_MAKE_DEVICE_FAIL = -60004;
constexpr int32_t ERR_DH_INPUT_HUB_UNREGISTER_FD_FAIL = -60005;
constexpr int32_t ERR_DH_INPUT_HUB_GET_EVENT_FAIL = -60006;
constexpr int32_t ERR_DH_INPUT_HUB_DEVICE_ENABLE_FAIL = -60007;
// whilte list error code
constexpr int32_t ERR_DH_INPUT_WHILTELIST_INIT_FAIL = -61001;
constexpr int32_t ERR_DH_INPUT_WHILTELIST_GET_WHILTELIST_FAIL = -61002;
// handler error code
constexpr int32_t ERR_DH_INPUT_HANDLER_GET_DEVICE_ID_FAIL = -63000;
// service sink error code
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_COLLECTOR_INIT_FAIL = -64000;
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_MANAGER_INIT_FAIL = -64001;
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_START_SWITCH_FAIL = -64002;
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL = -64003;
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_INIT_FAIL = -64004;
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPPREPARE_FAIL = 64005;
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPUNPREPARE_FAIL = -64006;
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPSTART_FAIL = -64007;
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPSTOP_FAIL = -64008;
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_SENDMESSAGE_FAIL = -64009;
// service source error code
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_INJECT_REGISTER_FAIL = -65000;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_INJECT_UNREGISTER_FAIL = -65001;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_INJECT_PREPARE_FAIL = -65002;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL = -65003;//
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_OPEN_DEVICE_NODE_FAIL = -65004;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL = -65005;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_CLOSE_DEVICE_FAIL = -65006;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_GET_DEVICE_FAIL = -65007;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_INIT_FAIL = -65008;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANSGER_RELEASE_FAIL = -65009;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL = -65010;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL = -65011;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REMOVE_INPUT_NODE_FAIL = -65012;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_DELETE_DEVICE_FAIL = -65013;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL = -65014;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL = -65015;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL = -65016;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL = -65017;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_INIT_FAIL = -65018;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_DEVICE_SESSION_STATE = -65019;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_OPEN_SESSION_FAIL = -65020;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_OPEN_SESSION_TIMEOUT = -65021;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_PREPARE_FAIL = -65022;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_UNPREPARE_FAIL = -65023;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL = -65024;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL = -65025;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE = -65026;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL = -65027;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_MSG_IS_BAD = -65028;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_MSG_IS_BAD = -65029;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_MSG_IS_BAD = -65030;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_MSG_IS_BAD = -65031;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD = -65032;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD = -65033;
// handler error code
constexpr int32_t ERR_DH_INPUT_SINK_HANDLER_INIT_SINK_SA_FAIL = -66000;
constexpr int32_t ERR_DH_INPUT_SINK_HANDLER_INIT_SOURCE_SA_FAIL = -66001;
// interface error code
constexpr int32_t ERR_DH_INPUT_IPC_INVALID_DESCRIPTOR = -67000;
constexpr int32_t ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL = -67001;
constexpr int32_t ERR_DH_INPUT_CLIENT_GET_SINK_PROXY_FAIL = -67002;
constexpr int32_t ERR_DH_INPUT_CLIENT_REGISTER_FAIL = -67003;
constexpr int32_t ERR_DH_INPUT_CLIENT_UNREGISTER_FAIL = -67004;
constexpr int32_t ERR_DH_INPUT_CLIENT_PREPARE_FAIL = -67005;
constexpr int32_t ERR_DH_INPUT_CLIENT_UNPREPARE_FAIL = -67006;
constexpr int32_t ERR_DH_INPUT_CLIENT_START_FAIL = -67007;
constexpr int32_t ERR_DH_INPUT_CLIENT_STOP_FAIL = -67008;
constexpr int32_t ERR_DH_INPUT_SINK_PROXY_INIT_FAIL = -67009;
constexpr int32_t ERR_DH_INPUT_SINK_PROXY_RELEASE_FAIL = -67010;
constexpr int32_t ERR_DH_INPUT_SINK_PROXY_IS_START_INPUT_FAIL = -67011;
constexpr int32_t ERR_DH_INPUT_SINK_STUB_ON_REMOTE_REQUEST_FAIL = -67012;
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_INIT_FAIL = -67013;
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_RELEASE_FAIL = -67014;
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_REGISTER_WRITE_MSG_FAIL = -67015;
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_REGISTER_FAIL = -67016;
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_WRITE_MSG_FAIL = -67017;
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_FAIL = -67018;
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_PREPARE_WRITE_MSG_FAIL = -67019;
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_PREPARE_FAIL = -67020;
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_WRITE_MSG_FAIL = -67021;
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_FAIL = -67022;
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_START_WRITE_MSG_FAIL = -67023;
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_START_FAIL = -67024;
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_STOP_WRITE_MSG_FAIL = -67025;
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL = -67026;
constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_IS_START_INPUT_FAIL = -67027;
constexpr int32_t ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL = -67028;
}
}
}
#endif
+34 -33
View File
@@ -27,6 +27,7 @@
#include <unistd.h>
#include "distributed_hardware_log.h"
#include "dinput_errcode.h"
#include "sys/stat.h"
namespace OHOS {
@@ -56,7 +57,7 @@ int32_t InputHub::Initialize()
epollFd_ = epoll_create1(EPOLL_CLOEXEC);
if (epollFd_ < 0) {
DHLOGE("Could not create epoll instance: %s", strerror(errno));
return FAILURE;
return ERR_DH_INPUT_HUB_EPOLL_INIT_FAIL;
}
iNotifyFd_ = inotify_init();
@@ -64,7 +65,7 @@ int32_t InputHub::Initialize()
if (inputWd_ < 0) {
DHLOGE(
"Could not register INotify for %s: %s", DEVICE_PATH, strerror(errno));
return FAILURE;
return ERR_DH_INPUT_HUB_EPOLL_INIT_FAIL;
}
struct epoll_event eventItem = {};
@@ -73,10 +74,10 @@ int32_t InputHub::Initialize()
int result = epoll_ctl(epollFd_, EPOLL_CTL_ADD, iNotifyFd_, &eventItem);
if (result != 0) {
DHLOGE("Could not add INotify to epoll instance. errno=%d", errno);
return FAILURE;
return ERR_DH_INPUT_HUB_EPOLL_INIT_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
}
int32_t InputHub::Release()
@@ -85,7 +86,7 @@ int32_t InputHub::Release()
::close(epollFd_);
::close(iNotifyFd_);
return SUCCESS;
return DH_SUCCESS;
}
size_t InputHub::CollectInputEvents(RawEvent* buffer, size_t bufferSize)
@@ -332,7 +333,7 @@ int32_t InputHub::RefreshEpollItem()
if (pollResult == 0) {
// Timed out.
pendingEventCount_ = 0;
return FAILURE;
return ERR_DH_INPUT_HUB_EPOLL_WAIT_TIMEOUT;
}
if (pollResult < 0) {
@@ -349,7 +350,7 @@ int32_t InputHub::RefreshEpollItem()
// Some events occurred.
pendingEventCount_ = size_t(pollResult);
}
return SUCCESS;
return DH_SUCCESS;
}
std::vector<InputDevice> InputHub::GetAllInputDevices()
@@ -400,7 +401,7 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string& devicePath)
std::unique_lock<std::mutex> deviceLock(visitMutex_);
for (const auto& [deviceId, device] : devices_) {
if (device->path == devicePath) {
return SUCCESS; // device was already registered
return DH_SUCCESS; // device was already registered
}
}
}
@@ -411,12 +412,12 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string& devicePath)
int fd = open(devicePath.c_str(), O_RDWR | O_CLOEXEC | O_NONBLOCK);
if (fd < 0) {
DHLOGE("could not open %s, %s\n", devicePath.c_str(), strerror(errno));
return FAILURE;
return ERR_DH_INPUT_HUB_OPEN_DEVICEPATH_FAIL;
}
InputDevice identifier;
if (MakeInputDevice(fd, identifier) < 0) {
return FAILURE;
return ERR_DH_INPUT_HUB_MAKE_INPUT_DEVICE_FAIL;
}
AssignDescriptorLocked(identifier);
@@ -436,10 +437,10 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string& devicePath)
DHLOGI(" descriptor: \"%s\"\n", identifier.descriptor.c_str());
if (MakeDevice(fd, std::move(device)) < 0) {
return FAILURE;
return ERR_DH_INPUT_HUB_MAKE_DEVICE_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
}
int32_t InputHub::MakeInputDevice(int fd, InputDevice& identifier)
@@ -456,21 +457,21 @@ int32_t InputHub::MakeInputDevice(int fd, InputDevice& identifier)
// If the device is already a virtual device, don't monitor it.
if (identifier.name.find(VIRTUAL_DEVICE_NAME) != std::string::npos) {
return FAILURE;
return ERR_DH_INPUT_HUB_MAKE_INPUT_DEVICE_FAIL;
}
// Get device driver version.
int driverVersion;
if (ioctl(fd, EVIOCGVERSION, &driverVersion)) {
DHLOGE("could not get driver version for %s\n", strerror(errno));
close(fd);
return FAILURE;
return ERR_DH_INPUT_HUB_MAKE_INPUT_DEVICE_FAIL;
}
// Get device identifier.
struct input_id inputId;
if (ioctl(fd, EVIOCGID, &inputId)) {
DHLOGE("could not get device input id for %s\n", strerror(errno));
close(fd);
return FAILURE;
return ERR_DH_INPUT_HUB_MAKE_INPUT_DEVICE_FAIL;
}
identifier.bus = inputId.bustype;
identifier.product = inputId.product;
@@ -495,7 +496,7 @@ int32_t InputHub::MakeInputDevice(int fd, InputDevice& identifier)
(driverVersion >> DRIVER_VERSION_MOVE) & DRIVER_VERSION_MAX,
driverVersion & DRIVER_VERSION_MAX);
return SUCCESS;
return DH_SUCCESS;
}
int32_t InputHub::MakeDevice(int fd, std::unique_ptr<Device> device)
@@ -521,18 +522,18 @@ int32_t InputHub::MakeDevice(int fd, std::unique_ptr<Device> device)
// If the device isn't recognized as something we handle, don't monitor it.
if (device->classes == 0) {
DHLOGI("Dropping device: name='%s'", device->identifier.name.c_str());
return FAILURE;
return ERR_DH_INPUT_HUB_MAKE_DEVICE_FAIL;
}
if (RegisterDeviceForEpollLocked(*device) != SUCCESS) {
return FAILURE;
if (RegisterDeviceForEpollLocked(*device) != DH_SUCCESS) {
return ERR_DH_INPUT_HUB_MAKE_DEVICE_FAIL;
}
DHLOGI("New device: fd=%d, name='%s', classes=0x%x,",
fd, device->identifier.name.c_str(), device->classes);
device->identifier.classes = device->classes;
AddDeviceLocked(std::move(device));
return SUCCESS;
return DH_SUCCESS;
}
void InputHub::AssignDescriptorLocked(InputDevice& identifier)
@@ -561,7 +562,7 @@ std::string InputHub::StringPrintf(const char* format, ...) const
va_start(ap, format);
std::string result;
int ret = vsnprintf_s(space, sizeof(space), sizeof(space) - 1, format, ap);
if (ret > ERROR && ret < sizeof(space)) {
if (ret >= DH_SUCCESS && ret < sizeof(space)) {
result = space;
} else {
return "the buffer is overflow!";
@@ -618,7 +619,7 @@ std::string InputHub::GenerateDescriptor(InputDevice& identifier) const
int32_t InputHub::RegisterDeviceForEpollLocked(const Device& device)
{
int32_t result = RegisterFdForEpoll(device.fd);
if (result != SUCCESS) {
if (result != DH_SUCCESS) {
DHLOGE("Could not add input device fd to epoll for device %d", device.id);
return result;
}
@@ -635,7 +636,7 @@ int32_t InputHub::RegisterFdForEpoll(int fd)
"Could not add fd to epoll instance: %s", strerror(errno));
return -errno;
}
return SUCCESS;
return DH_SUCCESS;
}
void InputHub::AddDeviceLocked(std::unique_ptr<Device> device)
@@ -662,13 +663,13 @@ int32_t InputHub::UnregisterDeviceFromEpollLocked(const Device& device) const
{
if (device.HasValidFd()) {
int32_t result = UnregisterFdFromEpoll(device.fd);
if (result != SUCCESS) {
if (result != DH_SUCCESS) {
DHLOGE(
"Could not remove input device fd from epoll for device %d", device.id);
return result;
}
}
return SUCCESS;
return DH_SUCCESS;
}
int32_t InputHub::UnregisterFdFromEpoll(int fd) const
@@ -676,9 +677,9 @@ int32_t InputHub::UnregisterFdFromEpoll(int fd) const
if (epoll_ctl(epollFd_, EPOLL_CTL_DEL, fd, nullptr)) {
DHLOGE(
"Could not remove fd from epoll instance: %s", strerror(errno));
return FAILURE;
return ERR_DH_INPUT_HUB_UNREGISTER_FD_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
}
int32_t InputHub::ReadNotifyLocked()
@@ -693,9 +694,9 @@ int32_t InputHub::ReadNotifyLocked()
res = read(iNotifyFd_, event_buf, sizeof(event_buf));
if (res < (int)sizeof(*event)) {
if (errno == EINTR)
return SUCCESS;
return DH_SUCCESS;
DHLOGE("could not get event, %s\n", strerror(errno));
return FAILURE;
return ERR_DH_INPUT_HUB_GET_EVENT_FAIL;
}
while (res >= (int) sizeof(*event)) {
@@ -705,7 +706,7 @@ int32_t InputHub::ReadNotifyLocked()
res -= event_size;
event_pos += event_size;
}
return SUCCESS;
return DH_SUCCESS;
}
void InputHub::JudgeDeviceOpenOrClose(const inotify_event& event)
@@ -859,17 +860,17 @@ int32_t InputHub::Device::Enable()
if (fd < 0) {
DHLOGE(
"could not open %s, %s\n", path.c_str(), strerror(errno));
return FAILURE;
return ERR_DH_INPUT_HUB_DEVICE_ENABLE_FAIL;
}
enabled = true;
return SUCCESS;
return DH_SUCCESS;
}
int32_t InputHub::Device::Disable()
{
Close();
enabled = false;
return SUCCESS;
return DH_SUCCESS;
}
bool InputHub::Device::HasValidFd() const
+10 -9
View File
@@ -20,6 +20,7 @@
#include <sstream>
#include "distributed_hardware_log.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -52,14 +53,14 @@ int32_t WhiteListUtil::Init(const std::string &deviceId)
if (deviceId.empty()) {
// device id error
DHLOGE("%s error, deviceId empty", __func__);
return FAILURE;
return ERR_DH_INPUT_WHILTELIST_INIT_FAIL;
}
std::ifstream inFile(g_filepath, std::ios::in | std::ios::binary);
if (!inFile.is_open()) {
// file open error
DHLOGE("%s error, file open fail path=%s", __func__, g_filepath);
return FAILURE;
return ERR_DH_INPUT_WHILTELIST_INIT_FAIL;
}
TYPE_KEY_CODE_VEC vecKeyCode;
@@ -107,14 +108,14 @@ int32_t WhiteListUtil::Init(const std::string &deviceId)
DHLOGI("%s called success, deviceId=%s", __func__, deviceId.c_str());
PrintWhiteList();
return SUCCESS;
return DH_SUCCESS;
}
int32_t WhiteListUtil::UnInit(void)
{
DHLOGI("%s called", __func__);
ClearWhiteList();
return SUCCESS;
return DH_SUCCESS;
}
void WhiteListUtil::ReadLineDataStepOne(std::string &column, TYPE_KEY_CODE_VEC &vecKeyCode,
@@ -155,7 +156,7 @@ int32_t WhiteListUtil::SyncWhiteList(const std::string &deviceId, const TYPE_WHI
std::lock_guard<std::mutex> lock(mutex_);
mapDeviceWhiteList_[deviceId] = vecWhiteList;
PrintWhiteList();
return SUCCESS;
return DH_SUCCESS;
}
int32_t WhiteListUtil::ClearWhiteList(const std::string &deviceId)
@@ -165,14 +166,14 @@ int32_t WhiteListUtil::ClearWhiteList(const std::string &deviceId)
std::lock_guard<std::mutex> lock(mutex_);
mapDeviceWhiteList_.erase(deviceId);
return SUCCESS;
return DH_SUCCESS;
}
int32_t WhiteListUtil::ClearWhiteList(void)
{
std::lock_guard<std::mutex> lock(mutex_);
TYPE_DEVICE_WHITE_LIST_MAP().swap(mapDeviceWhiteList_);
return SUCCESS;
return DH_SUCCESS;
}
int32_t WhiteListUtil::GetWhiteList(const std::string &deviceId, TYPE_WHITE_LIST_VEC &vecWhiteList)
@@ -186,12 +187,12 @@ int32_t WhiteListUtil::GetWhiteList(const std::string &deviceId, TYPE_WHITE_LIST
vecWhiteList = iter->second;
DHLOGI("%s called success, deviceId=%s",
__func__, deviceId.c_str());
return SUCCESS;
return DH_SUCCESS;
}
DHLOGE("%s called failure, deviceId=%s",
__func__, deviceId.c_str());
return FAILURE;
return ERR_DH_INPUT_WHILTELIST_GET_WHILTELIST_FAIL;
}
bool WhiteListUtil::CheckSubVecData(const TYPE_COMBINATION_KEY_VEC::iterator &iter2,
@@ -28,6 +28,7 @@
#include "nlohmann/json.hpp"
#include "sys/stat.h"
#include "distributed_hardware_log.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -74,7 +75,7 @@ int32_t DistributedInputHandler::Initialize()
InitCollectEventsThread();
isStartCollectEventThread = true;
}
return SUCCESS;
return DH_SUCCESS;
}
std::vector<DHItem> DistributedInputHandler::Query()
@@ -119,12 +120,12 @@ int32_t DistributedInputHandler::GetDeviceInfo(std::string& deviceId)
int32_t retCode = GetLocalNodeDeviceInfo("ohos.distributedhardware.devicemanager", localNode.get());
if (retCode != 0) {
DHLOGE("Could not get device id.");
return FAILURE;
return ERR_DH_INPUT_HANDLER_GET_DEVICE_ID_FAIL;
}
deviceId = localNode->networkId;
DHLOGI("device id is %s", deviceId.c_str());
return SUCCESS;
return DH_SUCCESS;
}
bool DistributedInputHandler::InitCollectEventsThread()
@@ -16,6 +16,7 @@
#include "add_white_list_infos_call_back_stub.h"
#include "string_ex.h"
#include "constants_dinput.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -33,7 +34,7 @@ int32_t AddWhiteListInfosCallbackStub::OnRemoteRequest(
{
std::u16string descriptor = data.ReadInterfaceToken();
if (descriptor != IAddWhiteListInfosCallback::GetDescriptor()) {
return ERROR;
return ERR_DH_INPUT_IPC_INVALID_DESCRIPTOR;
}
IAddWhiteListInfosCallback::Message msgCode = static_cast<IAddWhiteListInfosCallback::Message>(code);
switch (msgCode) {
@@ -46,7 +47,7 @@ int32_t AddWhiteListInfosCallbackStub::OnRemoteRequest(
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
return NO_ERROR;
return DH_SUCCESS;
}
} // namespace DistributedHardware
} // namespace DistributedInput
@@ -16,6 +16,7 @@
#include "del_white_list_infos_call_back_stub.h"
#include "string_ex.h"
#include "constants_dinput.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -33,7 +34,7 @@ int32_t DelWhiteListInfosCallbackStub::OnRemoteRequest(
{
std::u16string descriptor = data.ReadInterfaceToken();
if (descriptor != IDelWhiteListInfosCallback::GetDescriptor()) {
return ERROR;
return ERR_DH_INPUT_IPC_INVALID_DESCRIPTOR;
}
IDelWhiteListInfosCallback::Message msgCode = static_cast<IDelWhiteListInfosCallback::Message>(code);
switch (msgCode) {
@@ -45,7 +46,7 @@ int32_t DelWhiteListInfosCallbackStub::OnRemoteRequest(
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
return NO_ERROR;
return DH_SUCCESS;
}
} // namespace DistributedHardware
} // namespace DistributedInput
+20 -19
View File
@@ -19,6 +19,7 @@
#include "constants_dinput.h"
#include "white_list_util.h"
#include "distributed_hardware_log.h"
#include "dinput_errcode.h"
#include "nlohmann/json.hpp"
#include "softbus_bus_center.h"
@@ -97,7 +98,7 @@ void DistributedInputClient::DelWhiteListInfosCb::OnResult(const std::string& de
int32_t DistributedInputClient::InitSource()
{
if (!GetDInputSourceProxy()) {
return FAILURE_DIS;
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
return dInputSourceProxy_->Init();
}
@@ -105,7 +106,7 @@ int32_t DistributedInputClient::InitSource()
int32_t DistributedInputClient::InitSink()
{
if (!GetDInputSinkProxy()) {
return FAILURE_DIS;
return ERR_DH_INPUT_CLIENT_GET_SINK_PROXY_FAIL;
}
return dInputSinkProxy_->Init();
}
@@ -113,7 +114,7 @@ int32_t DistributedInputClient::InitSink()
int32_t DistributedInputClient::ReleaseSource()
{
if (!GetDInputSourceProxy()) {
return FAILURE_DIS;
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
serverType = DInputServerType::NULL_SERVER_TYPE;
@@ -132,7 +133,7 @@ int32_t DistributedInputClient::ReleaseSource()
int32_t DistributedInputClient::ReleaseSink()
{
if (!GetDInputSinkProxy()) {
return FAILURE_DIS;
return ERR_DH_INPUT_CLIENT_GET_SINK_PROXY_FAIL;
}
serverType = DInputServerType::NULL_SERVER_TYPE;
inputTypes = INPUT_TYPE_NULL;
@@ -150,16 +151,16 @@ int32_t DistributedInputClient::RegisterDistributedHardware(const std::string& d
if (!GetDInputSourceProxy()) {
DHLOGE("RegisterDistributedHardware client fail");
return FAILURE_DIS;
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (devId.empty() || dhId.empty() || parameters.empty() || !IsJsonData(parameters) || callback == nullptr) {
return FAILURE;
return ERR_DH_INPUT_CLIENT_REGISTER_FAIL;
}
for (auto iter : dHardWareFwkRstInfos) {
if (iter.devId == devId && iter.dhId == dhId) {
return FAILURE_REGISTING;
return ERR_DH_INPUT_CLIENT_REGISTER_FAIL;
}
}
@@ -180,16 +181,16 @@ int32_t DistributedInputClient::UnregisterDistributedHardware(const std::string&
if (!GetDInputSourceProxy()) {
DHLOGE("UnregisterDistributedHardware client fail");
return FAILURE_DIS;
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (devId.empty() || dhId.empty() || callback == nullptr) {
return FAILURE;
return ERR_DH_INPUT_CLIENT_UNREGISTER_FAIL;
}
for (auto iter : dHardWareFwkUnRstInfos) {
if (iter.devId == devId && iter.dhId == dhId) {
return FAILURE_UNREGISTING;
return ERR_DH_INPUT_CLIENT_UNREGISTER_FAIL;
}
}
@@ -210,11 +211,11 @@ int32_t DistributedInputClient::PrepareRemoteInput(
if (!GetDInputSourceProxy()) {
DHLOGE("PrepareRemoteInput client fail");
return FAILURE_DIS;
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (deviceId.empty() || callback == nullptr) {
return FAILURE;
return ERR_DH_INPUT_CLIENT_PREPARE_FAIL;
}
addWhiteListCallback = new(std::nothrow) AddWhiteListInfosCb();
@@ -228,11 +229,11 @@ int32_t DistributedInputClient::UnprepareRemoteInput(
if (!GetDInputSourceProxy()) {
DHLOGE("PrepareRemoteInput client fail");
return FAILURE_DIS;
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (deviceId.empty() || callback == nullptr) {
return FAILURE;
return ERR_DH_INPUT_CLIENT_UNPREPARE_FAIL;
}
delWhiteListCallback = new(std::nothrow) DelWhiteListInfosCb();
@@ -246,13 +247,13 @@ int32_t DistributedInputClient::StartRemoteInput(
if (!GetDInputSourceProxy()) {
DHLOGE("StartRemoteInput client fail");
return FAILURE_DIS;
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (deviceId.empty() || callback == nullptr ||
inputTypes > INPUT_TYPE_ALL || inputTypes == INPUT_TYPE_NULL ||
!(inputTypes & INPUT_TYPE_ALL)) {
return FAILURE;
return ERR_DH_INPUT_CLIENT_START_FAIL;
}
return dInputSourceProxy_->StartRemoteInput(deviceId, inputTypes, callback);
@@ -265,13 +266,13 @@ int32_t DistributedInputClient::StopRemoteInput(
if (!GetDInputSourceProxy()) {
DHLOGE("StopRemoteInput client fail");
return FAILURE_DIS;
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (deviceId.empty() || callback == nullptr ||
inputTypes > INPUT_TYPE_ALL || inputTypes == INPUT_TYPE_NULL ||
!(inputTypes & INPUT_TYPE_ALL)) {
return FAILURE;
return ERR_DH_INPUT_CLIENT_STOP_FAIL;
}
return dInputSourceProxy_->StopRemoteInput(deviceId, inputTypes, callback);
@@ -290,7 +291,7 @@ bool DistributedInputClient::IsNeedFilterOut(const std::string& deviceId, const
return WhiteListUtil::GetInstance().IsNeedFilterOut(localDevId_, event);
}
if (SUCCESS != WhiteListUtil::GetInstance().Init(localDevId_)) {
if (WhiteListUtil::GetInstance().Init(localDevId_) != DH_SUCCESS) {
return true;
}
m_bIsAlreadyInitWhiteList = true;
@@ -14,6 +14,7 @@
*/
#include "distributed_input_sink_proxy.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -29,7 +30,7 @@ int32_t DistributedInputSinkProxy::Init()
{
MessageParcel data;
MessageParcel reply;
int32_t result = ERROR;
int32_t result = ERR_DH_INPUT_SINK_PROXY_INIT_FAIL;
bool ret = SendRequest(IDistributedSinkInput::MessageCode::INIT, data, reply);
if (ret) {
result = reply.ReadInt32();
@@ -41,7 +42,7 @@ int32_t DistributedInputSinkProxy::Release()
{
MessageParcel data;
MessageParcel reply;
int32_t result = ERROR;
int32_t result = ERR_DH_INPUT_SINK_PROXY_RELEASE_FAIL;
bool ret = SendRequest(IDistributedSinkInput::MessageCode::RELEASE, data, reply);
if (ret) {
result = reply.ReadInt32();
@@ -60,7 +61,7 @@ int32_t DistributedInputSinkProxy::IsStartDistributedInput(
return static_cast<int32_t>(DInputServerType::NULL_SERVER_TYPE);
}
MessageParcel reply;
int32_t result = ERROR;
int32_t result = ERR_DH_INPUT_SINK_PROXY_IS_START_INPUT_FAIL;
bool ret = SendRequest(IDistributedSinkInput::MessageCode::ISSTART_REMOTE_INPUT, data, reply);
if (ret) {
result = reply.ReadInt32();
@@ -77,7 +78,7 @@ bool DistributedInputSinkProxy::SendRequest(
}
MessageOption option(MessageOption::TF_SYNC);
int32_t result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
if (result != OHOS::NO_ERROR) {
if (result != DH_SUCCESS) {
return false;
}
return true;
@@ -15,6 +15,7 @@
#include "distributed_input_sink_stub.h"
#include "constants_dinput.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -32,7 +33,7 @@ int32_t DistributedInputSinkStub::OnRemoteRequest(uint32_t code, MessageParcel &
case static_cast<uint32_t>(IDistributedSinkInput::MessageCode::INIT): {
int32_t ret = Init();
if (!reply.WriteInt32(ret)) {
return ERROR;
return ERR_DH_INPUT_SINK_STUB_ON_REMOTE_REQUEST_FAIL;
}
break;
}
@@ -40,7 +41,7 @@ int32_t DistributedInputSinkStub::OnRemoteRequest(uint32_t code, MessageParcel &
case static_cast<uint32_t>(IDistributedSinkInput::MessageCode::RELEASE): {
int32_t ret = Release();
if (!reply.WriteInt32(ret)) {
return ERROR;
return ERR_DH_INPUT_SINK_STUB_ON_REMOTE_REQUEST_FAIL;
}
break;
}
@@ -51,14 +52,14 @@ int32_t DistributedInputSinkStub::OnRemoteRequest(uint32_t code, MessageParcel &
iface_cast<IStartDInputServerCallback>(data.ReadRemoteObject());
int32_t ret = IsStartDistributedInput(inputType, callback);
if (!reply.WriteInt32(ret)) {
return ERROR;
return ERR_DH_INPUT_SINK_STUB_ON_REMOTE_REQUEST_FAIL;
}
break;
}
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
return NO_ERROR;
return DH_SUCCESS;
}
} // namespace DistributedInput
} // namespace DistributedHardware
@@ -14,12 +14,11 @@
*/
#include "distributed_input_source_proxy.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
const int32_t DISTRIBUTED_INPUT_DENIED = -1;
DistributedInputSourceProxy::DistributedInputSourceProxy(const sptr<IRemoteObject> &object)
: IRemoteProxy<IDistributedSourceInput>(object)
{}
@@ -31,7 +30,7 @@ int32_t DistributedInputSourceProxy::Init()
{
MessageParcel data;
MessageParcel reply;
int32_t result = ERROR;
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_INIT_FAIL;
bool ret = SendRequest(IDistributedSourceInput::MessageCode::INIT, data, reply);
if (ret) {
result = reply.ReadInt32();
@@ -43,7 +42,7 @@ int32_t DistributedInputSourceProxy::Release()
{
MessageParcel data;
MessageParcel reply;
int32_t result = ERROR;
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_RELEASE_FAIL;
bool ret = SendRequest(IDistributedSourceInput::MessageCode::RELEASE, data, reply);
if (ret) {
result = reply.ReadInt32();
@@ -56,19 +55,19 @@ int32_t DistributedInputSourceProxy::RegisterDistributedHardware(const std::stri
{
MessageParcel data;
if (!data.WriteString(devId)) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_REGISTER_WRITE_MSG_FAIL;
}
if (!data.WriteString(dhId)) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_REGISTER_WRITE_MSG_FAIL;
}
if (!data.WriteString(parameters)) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_REGISTER_WRITE_MSG_FAIL;
}
if (!data.WriteRemoteObject(callback->AsObject())) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_REGISTER_WRITE_MSG_FAIL;
}
MessageParcel reply;
int32_t result = ERROR;
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_FAIL;
bool ret = SendRequest(IDistributedSourceInput::MessageCode::REGISTER_REMOTE_INPUT, data, reply);
if (ret) {
result = reply.ReadInt32();
@@ -81,16 +80,16 @@ int32_t DistributedInputSourceProxy::UnregisterDistributedHardware(const std::st
{
MessageParcel data;
if (!data.WriteString(devId)) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_WRITE_MSG_FAIL;
}
if (!data.WriteString(dhId)) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_WRITE_MSG_FAIL;
}
if (!data.WriteRemoteObject(callback->AsObject())) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_WRITE_MSG_FAIL;
}
MessageParcel reply;
int32_t result = ERROR;
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_FAIL;
bool ret = SendRequest(IDistributedSourceInput::MessageCode::UNREGISTER_REMOTE_INPUT, data, reply);
if (ret) {
result = reply.ReadInt32();
@@ -104,16 +103,16 @@ int32_t DistributedInputSourceProxy::PrepareRemoteInput(
{
MessageParcel data;
if (!data.WriteString(deviceId)) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_PREPARE_WRITE_MSG_FAIL;
}
if (!data.WriteRemoteObject(callback->AsObject())) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_PREPARE_WRITE_MSG_FAIL;
}
if (!data.WriteRemoteObject(addWhiteListCallback->AsObject())) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_PREPARE_WRITE_MSG_FAIL;
}
MessageParcel reply;
int32_t result = ERROR;
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();
@@ -127,16 +126,16 @@ int32_t DistributedInputSourceProxy::UnprepareRemoteInput(
{
MessageParcel data;
if (!data.WriteString(deviceId)) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_WRITE_MSG_FAIL;
}
if (!data.WriteRemoteObject(callback->AsObject())) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_WRITE_MSG_FAIL;
}
if (!data.WriteRemoteObject(delWhiteListCallback->AsObject())) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_WRITE_MSG_FAIL;
}
MessageParcel reply;
int32_t result = ERROR;
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_FAIL;
bool ret = SendRequest(IDistributedSourceInput::MessageCode::UNPREPARE_REMOTE_INPUT, data, reply);
if (ret) {
result = reply.ReadInt32();
@@ -149,16 +148,16 @@ int32_t DistributedInputSourceProxy::StartRemoteInput(
{
MessageParcel data;
if (!data.WriteString(deviceId)) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_START_WRITE_MSG_FAIL;
}
if (!data.WriteUint32(inputTypes)) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_START_WRITE_MSG_FAIL;
}
if (!data.WriteRemoteObject(callback->AsObject())) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_START_WRITE_MSG_FAIL;
}
MessageParcel reply;
int32_t result = ERROR;
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL;
bool ret = SendRequest(IDistributedSourceInput::MessageCode::START_REMOTE_INPUT, data, reply);
if (ret) {
result = reply.ReadInt32();
@@ -171,16 +170,16 @@ int32_t DistributedInputSourceProxy::StopRemoteInput(
{
MessageParcel data;
if (!data.WriteString(deviceId)) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_STOP_WRITE_MSG_FAIL;
}
if (!data.WriteUint32(inputTypes)) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_STOP_WRITE_MSG_FAIL;
}
if (!data.WriteRemoteObject(callback->AsObject())) {
return DISTRIBUTED_INPUT_DENIED;
return ERR_DH_INPUT_SOURCE_PROXY_STOP_WRITE_MSG_FAIL;
}
MessageParcel reply;
int32_t result = ERROR;
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL;
bool ret = SendRequest(IDistributedSourceInput::MessageCode::STOP_REMOTE_INPUT, data, reply);
if (ret) {
result = reply.ReadInt32();
@@ -199,7 +198,7 @@ int32_t DistributedInputSourceProxy::IsStartDistributedInput(
return static_cast<int32_t>(DInputServerType::NULL_SERVER_TYPE);
}
MessageParcel reply;
int32_t result = ERROR;
int32_t result = ERR_DH_INPUT_SOURCE_PROXY_IS_START_INPUT_FAIL;
bool ret = SendRequest(IDistributedSourceInput::MessageCode::ISSTART_REMOTE_INPUT, data, reply);
if (ret) {
result = reply.ReadInt32();
@@ -216,7 +215,7 @@ bool DistributedInputSourceProxy::SendRequest(
}
MessageOption option(MessageOption::TF_SYNC);
int32_t result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
if (result != OHOS::NO_ERROR) {
if (result != DH_SUCCESS) {
return false;
}
return true;
@@ -15,6 +15,7 @@
#include "distributed_input_source_stub.h"
#include "constants_dinput.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -33,9 +34,9 @@ int32_t DistributedInputSourceStub::HandleRegisterDistributedHardware(MessagePar
sptr<IRegisterDInputCallback> callback = iface_cast<IRegisterDInputCallback>(data.ReadRemoteObject());
int32_t ret = RegisterDistributedHardware(devId, dhId, params, callback);
if (!reply.WriteInt32(ret)) {
return ERROR;
return ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL;
}
return NO_ERROR;
return DH_SUCCESS;
}
int32_t DistributedInputSourceStub::HandleUnregisterDistributedHardware(MessageParcel &data, MessageParcel &reply)
@@ -45,9 +46,9 @@ int32_t DistributedInputSourceStub::HandleUnregisterDistributedHardware(MessageP
sptr<IUnregisterDInputCallback> callback = iface_cast<IUnregisterDInputCallback>(data.ReadRemoteObject());
int32_t ret = UnregisterDistributedHardware(devId, dhId, callback);
if (!reply.WriteInt32(ret)) {
return ERROR;
return ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL;
}
return NO_ERROR;
return DH_SUCCESS;
}
int32_t DistributedInputSourceStub::HandlePrepareRemoteInput(MessageParcel &data, MessageParcel &reply)
@@ -59,9 +60,9 @@ int32_t DistributedInputSourceStub::HandlePrepareRemoteInput(MessageParcel &data
iface_cast<IAddWhiteListInfosCallback>(data.ReadRemoteObject());
int32_t ret = PrepareRemoteInput(deviceId, callback, addCallback);
if (!reply.WriteInt32(ret)) {
return ERROR;
return ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL;
}
return NO_ERROR;
return DH_SUCCESS;
}
int32_t DistributedInputSourceStub::HandleUnprepareRemoteInput(MessageParcel &data, MessageParcel &reply)
@@ -73,9 +74,9 @@ int32_t DistributedInputSourceStub::HandleUnprepareRemoteInput(MessageParcel &da
iface_cast<IDelWhiteListInfosCallback>(data.ReadRemoteObject());
int32_t ret = UnprepareRemoteInput(deviceId, callback, delCallback);
if (!reply.WriteInt32(ret)) {
return ERROR;
return ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL;
}
return NO_ERROR;
return DH_SUCCESS;
}
int32_t DistributedInputSourceStub::HandleStartRemoteInput(MessageParcel &data, MessageParcel &reply)
@@ -85,9 +86,9 @@ int32_t DistributedInputSourceStub::HandleStartRemoteInput(MessageParcel &data,
sptr<IStartDInputCallback> callback = iface_cast<IStartDInputCallback>(data.ReadRemoteObject());
int32_t ret = StartRemoteInput(deviceId, inputTypes, callback);
if (!reply.WriteInt32(ret)) {
return ERROR;
return ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL;
}
return NO_ERROR;
return DH_SUCCESS;
}
int32_t DistributedInputSourceStub::HandleStopRemoteInput(MessageParcel &data, MessageParcel &reply)
@@ -97,9 +98,9 @@ int32_t DistributedInputSourceStub::HandleStopRemoteInput(MessageParcel &data, M
sptr<IStopDInputCallback> callback = iface_cast<IStopDInputCallback>(data.ReadRemoteObject());
int32_t ret = StopRemoteInput(deviceId, inputTypes, callback);
if (!reply.WriteInt32(ret)) {
return ERROR;
return ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL;
}
return NO_ERROR;
return DH_SUCCESS;
}
int32_t DistributedInputSourceStub::HandleIsStartDistributedInput(MessageParcel &data, MessageParcel &reply)
@@ -108,9 +109,9 @@ int32_t DistributedInputSourceStub::HandleIsStartDistributedInput(MessageParcel
sptr<IStartDInputServerCallback> callback = iface_cast<IStartDInputServerCallback>(data.ReadRemoteObject());
int32_t ret = IsStartDistributedInput(inputType, callback);
if (!reply.WriteInt32(ret)) {
return ERROR;
return ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL;
}
return NO_ERROR;
return DH_SUCCESS;
}
int32_t DistributedInputSourceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
@@ -120,18 +121,18 @@ int32_t DistributedInputSourceStub::OnRemoteRequest(uint32_t code, MessageParcel
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::INIT): {
int32_t ret = Init();
if (!reply.WriteInt32(ret)) {
return ERROR;
return ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL;
} else {
return NO_ERROR;
return DH_SUCCESS;
}
break;
}
case static_cast<uint32_t>(IDistributedSourceInput::MessageCode::RELEASE): {
int32_t ret = Release();
if (!reply.WriteInt32(ret)) {
return ERROR;
return ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL;
} else {
return NO_ERROR;
return DH_SUCCESS;
}
break;
}
@@ -16,6 +16,7 @@
#include "prepare_d_input_call_back_stub.h"
#include "string_ex.h"
#include "constants_dinput.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -33,7 +34,7 @@ int32_t PrepareDInputCallbackStub::OnRemoteRequest(
{
std::u16string descriptor = data.ReadInterfaceToken();
if (descriptor != IPrepareDInputCallback::GetDescriptor()) {
return ERROR;
return ERR_DH_INPUT_IPC_INVALID_DESCRIPTOR;
}
IPrepareDInputCallback::Message msgCode = static_cast<IPrepareDInputCallback::Message>(code);
switch (msgCode) {
@@ -46,7 +47,7 @@ int32_t PrepareDInputCallbackStub::OnRemoteRequest(
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
return NO_ERROR;
return DH_SUCCESS;
}
} // namespace DistributedHardware
} // namespace DistributedInput
@@ -16,6 +16,7 @@
#include "register_d_input_call_back_stub.h"
#include "string_ex.h"
#include "constants_dinput.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -33,7 +34,7 @@ int32_t RegisterDInputCallbackStub::OnRemoteRequest(
{
std::u16string descriptor = data.ReadInterfaceToken();
if (descriptor != IRegisterDInputCallback::GetDescriptor()) {
return ERROR;
return ERR_DH_INPUT_IPC_INVALID_DESCRIPTOR;
}
IRegisterDInputCallback::Message msgCode = static_cast<IRegisterDInputCallback::Message>(code);
switch (msgCode) {
@@ -47,7 +48,7 @@ int32_t RegisterDInputCallbackStub::OnRemoteRequest(
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
return NO_ERROR;
return DH_SUCCESS;
}
} // namespace DistributedHardware
} // namespace DistributedInput
@@ -16,6 +16,7 @@
#include "start_d_input_call_back_stub.h"
#include "string_ex.h"
#include "constants_dinput.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -33,7 +34,7 @@ int32_t StartDInputCallbackStub::OnRemoteRequest(
{
std::u16string descriptor = data.ReadInterfaceToken();
if (descriptor != IStartDInputCallback::GetDescriptor()) {
return ERROR;
return ERR_DH_INPUT_IPC_INVALID_DESCRIPTOR;
}
IStartDInputCallback::Message msgCode = static_cast<IStartDInputCallback::Message>(code);
switch (msgCode) {
@@ -47,7 +48,7 @@ int32_t StartDInputCallbackStub::OnRemoteRequest(
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
return NO_ERROR;
return DH_SUCCESS;
}
} // namespace DistributedHardware
} // namespace DistributedInput
@@ -16,6 +16,7 @@
#include "start_d_input_server_call_back_stub.h"
#include "string_ex.h"
#include "constants_dinput.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -33,7 +34,7 @@ int32_t StartDInputServerCallbackStub::OnRemoteRequest(
{
std::u16string descriptor = data.ReadInterfaceToken();
if (descriptor != IStartDInputServerCallback::GetDescriptor()) {
return ERROR;
return ERR_DH_INPUT_IPC_INVALID_DESCRIPTOR;
}
IStartDInputServerCallback::Message msgCode = static_cast<IStartDInputServerCallback::Message>(code);
switch (msgCode) {
@@ -46,7 +47,7 @@ int32_t StartDInputServerCallbackStub::OnRemoteRequest(
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
return NO_ERROR;
return DH_SUCCESS;
}
} // namespace DistributedHardware
} // namespace DistributedInput
@@ -16,6 +16,7 @@
#include "stop_d_input_call_back_stub.h"
#include "string_ex.h"
#include "constants_dinput.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -33,7 +34,7 @@ int32_t StopDInputCallbackStub::OnRemoteRequest(
{
std::u16string descriptor = data.ReadInterfaceToken();
if (descriptor != IStopDInputCallback::GetDescriptor()) {
return ERROR;
return ERR_DH_INPUT_IPC_INVALID_DESCRIPTOR;
}
IStopDInputCallback::Message msgCode = static_cast<IStopDInputCallback::Message>(code);
switch (msgCode) {
@@ -47,7 +48,7 @@ int32_t StopDInputCallbackStub::OnRemoteRequest(
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
return NO_ERROR;
return DH_SUCCESS;
}
} // namespace DistributedHardware
} // namespace DistributedInput
@@ -16,6 +16,7 @@
#include "unprepare_d_input_call_back_stub.h"
#include "string_ex.h"
#include "constants_dinput.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -33,7 +34,7 @@ int32_t UnprepareDInputCallbackStub::OnRemoteRequest(
{
std::u16string descriptor = data.ReadInterfaceToken();
if (descriptor != IUnprepareDInputCallback::GetDescriptor()) {
return ERROR;
return ERR_DH_INPUT_IPC_INVALID_DESCRIPTOR;
}
IUnprepareDInputCallback::Message msgCode = static_cast<IUnprepareDInputCallback::Message>(code);
switch (msgCode) {
@@ -46,7 +47,7 @@ int32_t UnprepareDInputCallbackStub::OnRemoteRequest(
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
return NO_ERROR;
return DH_SUCCESS;
}
} // namespace DistributedHardware
} // namespace DistributedInput
@@ -16,6 +16,7 @@
#include "unregister_d_input_call_back_stub.h"
#include "string_ex.h"
#include "constants_dinput.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -33,7 +34,7 @@ int32_t UnregisterDInputCallbackStub::OnRemoteRequest(
{
std::u16string descriptor = data.ReadInterfaceToken();
if (descriptor != IUnregisterDInputCallback::GetDescriptor()) {
return ERROR;
return ERR_DH_INPUT_IPC_INVALID_DESCRIPTOR;
}
IUnregisterDInputCallback::Message msgCode = static_cast<IUnregisterDInputCallback::Message>(code);
switch (msgCode) {
@@ -47,7 +48,7 @@ int32_t UnregisterDInputCallbackStub::OnRemoteRequest(
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
return NO_ERROR;
return DH_SUCCESS;
}
} // namespace DistributedHardware
} // namespace DistributedInput
@@ -25,6 +25,7 @@
#include "sys/stat.h"
#include "nlohmann/json.hpp"
#include "distributed_hardware_log.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -57,13 +58,13 @@ int32_t DistributedInputCollector::Init(std::shared_ptr<AppExecFwk::EventHandler
sinkHandler_ = sinkHandler;
if (sinkHandler_ == nullptr) {
DHLOGE("DistributedInputCollector::Init sinkHandler_ failed \n");
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_COLLECTOR_INIT_FAIL;
}
if (!isStartGetDeviceHandlerThread) {
InitCollectEventsThread();
isStartGetDeviceHandlerThread = true;
}
return SUCCESS;
return DH_SUCCESS;
}
bool DistributedInputCollector::InitCollectEventsThread()
@@ -23,6 +23,7 @@
#include "distributed_input_collector.h"
#include "distributed_input_sink_switch.h"
#include "distributed_hardware_log.h"
#include "dinput_errcode.h"
#include "white_list_util.h"
namespace OHOS {
@@ -60,7 +61,7 @@ void DistributedInputSinkManager::DInputSinkListener::onPrepareRemoteInput(
std::string smsg = "";
int ret = DistributedInputCollector::GetInstance().Init(
DistributedInputSinkTransport::GetInstance().GetEventHandler());
if (ret != SUCCESS) {
if (ret != DH_SUCCESS) {
DHLOGE("DInputSinkListener init InputCollector error.");
jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = false;
jsonStr[DINPUT_SOFTBUS_KEY_WHITE_LIST] = "";
@@ -74,7 +75,7 @@ void DistributedInputSinkManager::DInputSinkListener::onPrepareRemoteInput(
// send prepare result and if result ok, send white list
TYPE_WHITE_LIST_VEC vecFilter;
if (sinkManagerObj_->GetInitWhiteListFlag() == false) {
if (SUCCESS != WhiteListUtil::GetInstance().Init(deviceId)) {
if (WhiteListUtil::GetInstance().Init(deviceId) != DH_SUCCESS) {
DHLOGE("%s called, init white list fail!", __func__);
jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = false;
jsonStr[DINPUT_SOFTBUS_KEY_WHITE_LIST] = "";
@@ -124,11 +125,11 @@ void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInput(
// set new session
int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(sessionId);
sinkManagerObj_->SetStartTransFlag((startRes == SUCCESS) ?
sinkManagerObj_->SetStartTransFlag((startRes == DH_SUCCESS) ?
DInputServerType::SINK_SERVER_TYPE :
DInputServerType::NULL_SERVER_TYPE);
bool result = (startRes == SUCCESS) ? true : false;
bool result = (startRes == DH_SUCCESS) ? true : false;
nlohmann::json jsonStrSta;
jsonStrSta[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONSTART;
jsonStrSta[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes;
@@ -138,7 +139,7 @@ void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInput(
DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsgSta);
// Notify the interrupted master status
if (FAILURE == curSessionId) {
if (curSessionId == ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL) {
DHLOGI("onStartRemoteInput called, this is the only session.");
} else if (result) {
DHLOGI("onStartRemoteInput called, notify curSessionId:%d Interrupted.", curSessionId);
@@ -155,7 +156,7 @@ void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInput(
}
// add the input type
if (startRes == SUCCESS) {
if (startRes == DH_SUCCESS) {
sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() | inputTypes);
DistributedInputCollector::GetInstance().SetInputTypes(sinkManagerObj_->GetInputTypes());
}
@@ -187,7 +188,8 @@ void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInput(
if (sinkManagerObj_->GetInputTypes() == INPUT_TYPE_NULL) {
DistributedInputSinkSwitch::GetInstance().StopSwitch(sessionId);
if (DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession() == FAILURE) {
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);
}
@@ -261,8 +263,8 @@ int32_t DistributedInputSinkManager::Init()
isStartTrans_ = DInputServerType::NULL_SERVER_TYPE;
// transport init session
int32_t ret = DistributedInputSinkTransport::GetInstance().Init();
if (SUCCESS != ret) {
return FAILURE;
if (ret != DH_SUCCESS) {
return ERR_DH_INPUT_SERVER_SINK_MANAGER_INIT_FAIL;
}
statuslistener_ = std::make_shared<DInputSinkListener>(this);
@@ -270,7 +272,7 @@ int32_t DistributedInputSinkManager::Init()
serviceRunningState_ = ServiceSinkRunningState::STATE_RUNNING;
return SUCCESS;
return DH_SUCCESS;
}
int32_t DistributedInputSinkManager::Release()
@@ -297,7 +299,7 @@ int32_t DistributedInputSinkManager::Release()
DHLOGI("exit dinput sink sa.");
exit(0);
return SUCCESS;
return DH_SUCCESS;
}
int32_t DistributedInputSinkManager::IsStartDistributedInput(
@@ -17,6 +17,7 @@
#include "constants_dinput.h"
#include "distributed_hardware_log.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -50,7 +51,7 @@ int32_t DistributedInputSinkSwitch::StartSwitch(int32_t sessionId)
std::unique_lock<std::mutex> switchLock(operationMutex_);
if (switchVector_.empty()) {
DHLOGE("StartSwitch sessionId:%d fail,switchVector_ is null.", sessionId);
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_START_SWITCH_FAIL;
} else {
bool findOld = false;
for (std::vector<SwitchStateData>::iterator it = switchVector_.begin(); it < switchVector_.end(); it++) {
@@ -63,10 +64,10 @@ int32_t DistributedInputSinkSwitch::StartSwitch(int32_t sessionId)
if (findOld) {
DHLOGI("StartSwitch sessionId:%d is find.", sessionId);
return SUCCESS;
return DH_SUCCESS;
} else {
DHLOGE("StartSwitch sessionId:%d fail, not found.", sessionId);
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_START_SWITCH_FAIL;
}
}
}
@@ -174,7 +175,7 @@ int32_t DistributedInputSinkSwitch::GetSwitchOpenedSession()
std::unique_lock<std::mutex> switchLock(operationMutex_);
if (switchVector_.empty()) {
DHLOGE("GetSwitchOpenedSession error, no data.");
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL;
}
for (std::vector<SwitchStateData>::iterator it = switchVector_.begin(); it < switchVector_.end(); it++) {
if ((*it).switchState == true) {
@@ -182,7 +183,7 @@ int32_t DistributedInputSinkSwitch::GetSwitchOpenedSession()
}
}
DHLOGE("GetSwitchOpenedSession no session is open.");
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL;
}
} // namespace DistributedInput
} // namespace DistributedHardware
@@ -22,6 +22,7 @@
#include "constants_dinput.h"
#include "distributed_hardware_log.h"
#include "dinput_errcode.h"
#include "session.h"
#include "softbus_bus_center.h"
@@ -97,7 +98,6 @@ void DistributedInputSinkTransport::DInputSinkEventHandler::ProcessEvent(const A
sendMsg[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_BODY_DATA;
sendMsg[DINPUT_SOFTBUS_KEY_INPUT_DATA] = innerMsg->dump();
std::string smsg = sendMsg.dump();
for (nlohmann::json::iterator it = innerMsg->begin(); it != innerMsg->end(); ++it) {
nlohmann::json oneData = *it;
int32_t code = oneData[INPUT_KEY_CODE];
@@ -144,20 +144,20 @@ int32_t DistributedInputSinkTransport::Init()
};
auto localNode = std::make_unique<NodeBasicInfo>();
int32_t retCode = GetLocalNodeDeviceInfo(DINPUT_PKG_NAME.c_str(), localNode.get());
if (retCode != SUCCESS) {
if (retCode != DH_SUCCESS) {
DHLOGE("Init could not get local device id.");
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_INIT_FAIL;
}
std::string networkId = localNode->networkId;
DHLOGI("Init device networkId is %s", networkId.c_str());
mySessionName_ = SESSION_NAME_SINK + networkId.substr(0, INTERCEPT_STRING_LENGTH);
int32_t ret = CreateSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str(), &iSessionListener);
if (ret != SUCCESS) {
if (ret != DH_SUCCESS) {
DHLOGE("Init CreateSessionServer failed, error code %d.", ret);
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_INIT_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
}
std::shared_ptr<DistributedInputSinkTransport::DInputSinkEventHandler> DistributedInputSinkTransport::GetEventHandler()
@@ -178,14 +178,14 @@ int32_t DistributedInputSinkTransport::RespPrepareRemoteInput(
if (sessionId > 0) {
DHLOGI("RespPrepareRemoteInput session:%d, smsg:%s.", sessionId, smsg.c_str());
int32_t ret = SendMessage(sessionId, smsg);
if (ret != SUCCESS) {
if (ret != DH_SUCCESS) {
DHLOGE("RespPrepareRemoteInput error, SendMessage fail.");
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPPREPARE_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
} else {
DHLOGE("RespPrepareRemoteInput error, sessionId <= 0.");
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPPREPARE_FAIL;
}
}
@@ -195,14 +195,14 @@ int32_t DistributedInputSinkTransport::RespUnprepareRemoteInput(
if (sessionId > 0) {
DHLOGI("RespUnprepareRemoteInput sessionId:%d, smsg:%s.", sessionId, smsg.c_str());
int32_t ret = SendMessage(sessionId, smsg);
if (ret != SUCCESS) {
if (ret != DH_SUCCESS) {
DHLOGE("RespUnprepareRemoteInput error, SendMessage fail.");
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPUNPREPARE_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
} else {
DHLOGE("RespUnprepareRemoteInput error, sessionId <= 0.");
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPUNPREPARE_FAIL;
}
}
@@ -212,14 +212,14 @@ int32_t DistributedInputSinkTransport::RespStartRemoteInput(
if (sessionId > 0) {
DHLOGI("RespStartRemoteInput sessionId:%d, result:%d, smsg:%s.", sessionId, smsg.c_str());
int32_t ret = SendMessage(sessionId, smsg);
if (ret != SUCCESS) {
if (ret != DH_SUCCESS) {
DHLOGE("RespStartRemoteInput error, SendMessage fail.");
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPSTART_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
} else {
DHLOGE("RespStartRemoteInput error, sessionId <= 0.");
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPSTART_FAIL;
}
}
@@ -229,14 +229,14 @@ int32_t DistributedInputSinkTransport::RespStopRemoteInput(
if (sessionId > 0) {
DHLOGI("RespStopRemoteInput sessionId:%d, smsg:%s.", sessionId, smsg.c_str());
int32_t ret = SendMessage(sessionId, smsg);
if (ret != SUCCESS) {
if (ret != DH_SUCCESS) {
DHLOGE("RespStopRemoteInput error, SendMessage fail.");
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPSTOP_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
} else {
DHLOGE("RespStopRemoteInput error, sessionId <= 0.");
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPSTOP_FAIL;
}
}
@@ -245,18 +245,18 @@ int32_t DistributedInputSinkTransport::SendMessage(int32_t sessionId, std::strin
DHLOGI("start SendMessage");
if (message.size() > MSG_MAX_SIZE) {
DHLOGE("SendMessage error: message.size() > MSG_MAX_SIZE");
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_SENDMESSAGE_FAIL;
}
uint8_t *buf = (uint8_t *)calloc((MSG_MAX_SIZE), sizeof(uint8_t));
if (buf == nullptr) {
DHLOGE("SendMessage: malloc memory failed");
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_SENDMESSAGE_FAIL;
}
int32_t outLen = 0;
if (memcpy_s(buf, MSG_MAX_SIZE, (const uint8_t *)message.c_str(), message.size()) != SUCCESS) {
if (memcpy_s(buf, MSG_MAX_SIZE, (const uint8_t *)message.c_str(), message.size()) != DH_SUCCESS) {
DHLOGE("SendMessage: memcpy memory failed");
free(buf);
return FAILURE;
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_SENDMESSAGE_FAIL;
}
outLen = message.size();
int32_t ret = SendBytes(sessionId, buf, outLen);
@@ -266,12 +266,12 @@ int32_t DistributedInputSinkTransport::SendMessage(int32_t sessionId, std::strin
int32_t DistributedInputSinkTransport::OnSessionOpened(int32_t sessionId, int32_t result)
{
if (result != SUCCESS) {
if (result != DH_SUCCESS) {
DHLOGE("session open failed, sessionId %d", sessionId);
if (sessionIdSet_.count(sessionId) > 0) {
sessionIdSet_.erase(sessionId);
}
return SUCCESS;
return DH_SUCCESS;
}
// return 1 is client
@@ -282,23 +282,23 @@ int32_t DistributedInputSinkTransport::OnSessionOpened(int32_t sessionId, int32_
char peerSessionName[SESSION_NAME_SIZE_MAX] = "";
char peerDevId[DEVICE_ID_SIZE_MAX] = "";
int ret = GetMySessionName(sessionId, mySessionName, sizeof(mySessionName));
if (ret != SUCCESS) {
if (ret != DH_SUCCESS) {
DHLOGI("get my session name failed, session id is %d.", sessionId);
}
// get other device session name
ret = GetPeerSessionName(sessionId, peerSessionName, sizeof(peerSessionName));
if (ret != SUCCESS) {
if (ret != DH_SUCCESS) {
DHLOGI("get my peer session name failed, session id is %d.", sessionId);
}
ret = GetPeerDeviceId(sessionId, peerDevId, sizeof(peerDevId));
if (ret != SUCCESS) {
if (ret != DH_SUCCESS) {
DHLOGI("get my peer device id failed, session id is %d.", sessionId);
}
DHLOGI("mySessionName:%s, peerSessionName:%s, peerDevId:%s.",
mySessionName, peerSessionName, peerDevId);
return SUCCESS;
return DH_SUCCESS;
}
void DistributedInputSinkTransport::OnSessionClosed(int32_t sessionId)
@@ -325,7 +325,7 @@ void DistributedInputSinkTransport::OnBytesReceived(int32_t sessionId, const voi
return;
}
if (memcpy_s(buf, dataLen + 1, (const uint8_t*)data, dataLen) != SUCCESS) {
if (memcpy_s(buf, dataLen + 1, (const uint8_t*)data, dataLen) != DH_SUCCESS) {
DHLOGE("OnBytesReceived: memcpy memory failed");
free(buf);
return;
@@ -18,6 +18,7 @@
#include <sstream>
#include "nlohmann/json.hpp"
#include "distributed_hardware_log.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -48,13 +49,13 @@ int32_t DistributedInputInject::RegisterDistributedHardware(const std::string& d
if (inputNodeManager_ == nullptr) {
DHLOGE("the DistributedInputNodeManager is null\n");
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL;
}
if (inputNodeManager_->openDevicesNode(devId, dhId, parameters) < 0) {
DHLOGE("create virtual device error\n");
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_INJECT_REGISTER_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
}
int32_t DistributedInputInject::UnregisterDistributedHardware(const std::string& devId, const std::string& dhId)
@@ -63,13 +64,13 @@ int32_t DistributedInputInject::UnregisterDistributedHardware(const std::string&
__func__, devId.c_str(), dhId.c_str());
if (inputNodeManager_ == nullptr) {
DHLOGE("the DistributedInputNodeManager is null\n");
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL;
}
if (inputNodeManager_->CloseDeviceLocked(dhId) < 0) {
DHLOGE("delete virtual device error\n");
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_INJECT_UNREGISTER_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
}
int32_t DistributedInputInject::StructTransJson(const InputDevice& pBuf, std::string& strDescriptor)
@@ -92,20 +93,20 @@ int32_t DistributedInputInject::StructTransJson(const InputDevice& pBuf, std::st
std::ostringstream stream;
stream << tmpJson.dump();
strDescriptor = stream.str();
return SUCCESS;
return DH_SUCCESS;
}
int32_t DistributedInputInject::RegisterDistributedEvent(RawEvent* buffer, size_t bufferSize)
{
if (inputNodeManager_ == nullptr) {
DHLOGE("the DistributedInputNodeManager is null\n");
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL;
}
DHLOGE("RegisterDistributedEvent start %zu\n", bufferSize);
for (size_t i = 0; i < bufferSize; i++) {
inputNodeManager_->ReportEvent(buffer[i]);
}
return SUCCESS;
return DH_SUCCESS;
}
void DistributedInputInject::StartInjectThread()
@@ -21,6 +21,7 @@
#include <unistd.h>
#include "distributed_hardware_log.h"
#include "dinput_errcode.h"
#include "nlohmann/json.hpp"
#include "virtual_keyboard.h"
#include "virtual_mouse.h"
@@ -54,10 +55,10 @@ int32_t DistributedInputNodeManager::openDevicesNode(const std::string& devId, c
InputDevice event;
stringTransJsonTransStruct(parameters, event);
if (CreateHandle(event, devId) < 0) {
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_OPEN_DEVICE_NODE_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
}
void DistributedInputNodeManager::stringTransJsonTransStruct(const std::string& str, InputDevice& pBuf)
@@ -87,22 +88,22 @@ int32_t DistributedInputNodeManager::CreateHandle(InputDevice event, const std::
device = std::make_unique<VirtualTouchpad>(event.name, event.bus, event.vendor, event.product, event.version);
} else {
DHLOGW("could not find the deviceType\n");
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL;
}
if (device == nullptr) {
DHLOGE("could not create new virtual device == null\n");
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL;
}
device->SetNetWorkId(devId);
if (!device->SetUp()) {
DHLOGE("could not create new virtual device\n");
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL;
}
AddDeviceLocked(event.descriptor, std::move(device));
return SUCCESS;
return DH_SUCCESS;
}
void DistributedInputNodeManager::AddDeviceLocked(const std::string& dhId, std::unique_ptr<VirtualDevice> device)
@@ -119,10 +120,10 @@ int32_t DistributedInputNodeManager::CloseDeviceLocked(const std::string &dhId)
std::map<std::string, std::unique_ptr<VirtualDevice>>::iterator iter = devices_.find(dhId);
if (iter != devices_.end()) {
devices_.erase(iter);
return SUCCESS;
return DH_SUCCESS;
}
DHLOGE("%s called failure, dhId=%s", __func__, dhId.c_str());
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_CLOSE_DEVICE_FAIL;
}
void DistributedInputNodeManager::CloseAllDevicesLocked()
@@ -134,13 +135,13 @@ void DistributedInputNodeManager::CloseAllDevicesLocked()
int32_t DistributedInputNodeManager::getDevice(const std::string& dhId, VirtualDevice*& device)
{
for (const auto & [id, virDevice] : devices_) {
for (const auto& [id, virdevice] : devices_) {
if (id == dhId) {
device = virDevice.get();
return SUCCESS;
device = virdevice.get();
return DH_SUCCESS;
}
}
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_GET_DEVICE_FAIL;
}
void DistributedInputNodeManager::StartInjectThread()
@@ -22,6 +22,7 @@
#include "constants_dinput.h"
#include "distributed_hardware_log.h"
#include "dinput_errcode.h"
#include "distributed_input_inject.h"
#include "distributed_input_source_transport.h"
#include "nlohmann/json.hpp"
@@ -59,17 +60,13 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseRegisterDist
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
sourceManagerObj_->RunRegisterCallback(deviceId, dhId, FAILURE);
sourceManagerObj_->RunRegisterCallback(deviceId, dhId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL);
DHLOGE("onResponseRegisterDistributedHardware GetCallbackEventHandler is null.");
return;
}
std::shared_ptr<nlohmann::json> jsonArrayMsg = std::make_shared<nlohmann::json>();
if (jsonArrayMsg == nullptr) {
sourceManagerObj_->RunRegisterCallback(deviceId, dhId, FAILURE);
DHLOGE("onResponseRegisterDistributedHardware jsonArrayMsg is null.");
return;
}
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
@@ -92,16 +89,12 @@ void DistributedInputSourceManager::DInputSourceListener::onResponsePrepareRemot
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
sourceManagerObj_->RunPrepareCallback(deviceId, FAILURE, object);
sourceManagerObj_->RunPrepareCallback(deviceId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL, object);
DHLOGE("onResponsePrepareRemoteInput GetCallbackEventHandler is null.");
return;
}
std::shared_ptr<nlohmann::json> jsonArrayMsg = std::make_shared<nlohmann::json>();
if (jsonArrayMsg == nullptr) {
sourceManagerObj_->RunPrepareCallback(deviceId, FAILURE, object);
DHLOGE("onResponsePrepareRemoteInput jsonArrayMsg is null.");
return;
}
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
@@ -124,16 +117,12 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseUnprepareRem
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
sourceManagerObj_->RunUnprepareCallback(deviceId, FAILURE);
sourceManagerObj_->RunUnprepareCallback(deviceId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL);
DHLOGE("onResponseUnprepareRemoteInput GetCallbackEventHandler is null.");
return;
}
std::shared_ptr<nlohmann::json> jsonArrayMsg = std::make_shared<nlohmann::json>();
if (jsonArrayMsg == nullptr) {
sourceManagerObj_->RunUnprepareCallback(deviceId, FAILURE);
DHLOGE("onResponseUnprepareRemoteInput jsonArrayMsg is null.");
return;
}
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
@@ -155,7 +144,8 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseStartRemoteI
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
sourceManagerObj_->RunStartCallback(deviceId, inputTypes, FAILURE);
sourceManagerObj_->RunStartCallback(deviceId, inputTypes,
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL);
DHLOGE("onResponseStartRemoteInput GetCallbackEventHandler is null.");
return;
}
@@ -191,15 +181,11 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseStopRemoteIn
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
DHLOGE("onResponseStopRemoteInput GetCallbackEventHandler is null.");
sourceManagerObj_->RunStopCallback(deviceId, inputTypes, FAILURE);
sourceManagerObj_->RunStopCallback(deviceId, inputTypes,
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL);
return;
}
std::shared_ptr<nlohmann::json> jsonArrayMsg = std::make_shared<nlohmann::json>();
if (jsonArrayMsg == nullptr) {
DHLOGE("onResponseStopRemoteInput jsonArrayMsg is null.");
sourceManagerObj_->RunStopCallback(deviceId, inputTypes, FAILURE);
return;
}
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
@@ -318,7 +304,8 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRegis
"devId[%s] dhId[%s] is bad data.", deviceId.c_str(), dhId.c_str());
}
sourceManagerObj_->RunRegisterCallback(deviceId, dhId, result ? SUCCESS : FAILURE);
sourceManagerObj_->RunRegisterCallback(deviceId, dhId,
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_MSG_IS_BAD);
}
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyUnregisterCallback(
@@ -333,7 +320,8 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyUnreg
if (result) {
sourceManagerObj_->SetDeviceMapValue(deviceId, INPUT_TYPE_NULL);
}
sourceManagerObj_->RunUnregisterCallback(deviceId, dhId, result ? SUCCESS : FAILURE);
sourceManagerObj_->RunUnregisterCallback(deviceId, dhId,
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_MSG_IS_BAD);
}
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyPrepareCallback(
@@ -346,7 +334,8 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyPrepa
bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
std::string object = innerMsg[INPUT_SOURCEMANAGER_KEY_WHITELIST];
sourceManagerObj_->RunPrepareCallback(deviceId, result ? SUCCESS : FAILURE, object);
sourceManagerObj_->RunPrepareCallback(deviceId,
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_MSG_IS_BAD, object);
}
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyUnprepareCallback(
@@ -360,7 +349,8 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyUnpre
if (result) {
sourceManagerObj_->SetDeviceMapValue(deviceId, INPUT_TYPE_NULL);
}
sourceManagerObj_->RunUnprepareCallback(deviceId, result ? SUCCESS : FAILURE);
sourceManagerObj_->RunUnprepareCallback(deviceId,
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_MSG_IS_BAD);
}
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStartCallback(
@@ -385,7 +375,8 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStart
} else {
DHLOGE("ProcessEvent GetStartDInputServerCback() or is null.");
}
sourceManagerObj_->RunStartCallback(deviceId, inputTypes, result ? SUCCESS : FAILURE);
sourceManagerObj_->RunStartCallback(deviceId, inputTypes,
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD);
}
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStopCallback(
@@ -420,7 +411,8 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStopC
} else {
DHLOGE("ProcessEvent GetStartDInputServerCback() is null.");
}
sourceManagerObj_->RunStopCallback(deviceId, inputTypes, result ? SUCCESS : FAILURE);
sourceManagerObj_->RunStopCallback(deviceId, inputTypes,
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD);
}
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStartServerCallback(
@@ -491,34 +483,33 @@ int32_t DistributedInputSourceManager::Init()
// transport init session
int32_t ret = DistributedInputSourceTransport::GetInstance().Init();
if (SUCCESS != ret) {
return FAILURE;
if (ret != DH_SUCCESS) {
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_INIT_FAIL;
}
statuslistener_ = std::make_shared<DInputSourceListener>(this);
DistributedInputSourceTransport::GetInstance().RegisterSourceRespCallback(statuslistener_);
serviceRunningState_ = ServiceSourceRunningState::STATE_RUNNING;
return SUCCESS;
return DH_SUCCESS;
}
int32_t DistributedInputSourceManager::Release()
{
DHLOGI("exit");
int32_t ret = FAILURE;
// 1.remove input node
for (std::vector<InputDeviceId>::iterator iter = inputDevice_.begin(); iter != inputDevice_.end(); ++iter) {
std::string devId = iter->devId;
std::string dhId = iter->dhId;
DHLOGI("Release() devId[%s] dhId[%s]", devId.c_str(), dhId.c_str());
ret = DistributedInputInject::GetInstance().UnregisterDistributedHardware(devId, dhId);
if (FAILURE == ret) {
int32_t ret = DistributedInputInject::GetInstance().UnregisterDistributedHardware(devId, dhId);
if (ret != DH_SUCCESS) {
DHLOGW("%s called, remove node fail.", __func__);
}
}
// 2.transport unInit session
// 2.delete all device node data
DHLOGI("Release transport instance");
DistributedInputSourceTransport::GetInstance().Release();
@@ -537,14 +528,14 @@ int32_t DistributedInputSourceManager::Release()
if (callBackHandler_ == nullptr) {
DHLOGE("Release callBackHandler_ is null.");
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANSGER_RELEASE_FAIL;
}
callBackHandler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
serviceRunningState_ = ServiceSourceRunningState::STATE_NOT_START;
DHLOGI("exit dinput source sa.");
exit(0);
return SUCCESS;
return DH_SUCCESS;
}
int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::string& devId, const std::string& dhId,
@@ -557,7 +548,7 @@ int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::st
DHLOGE(
"%s called, deviceId: %s callback is null.",
__func__, devId.c_str());
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL;
}
DInputClientRegistInfo info;
@@ -571,31 +562,31 @@ int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::st
// 1.Find out if the dh exists
std::vector<InputDeviceId>::iterator it = std::find(inputDevice_.begin(), inputDevice_.end(), inputDeviceId);
if (it != inputDevice_.end()) {
callback->OnResult(devId, dhId, SUCCESS);
return SUCCESS;
callback->OnResult(devId, dhId, DH_SUCCESS);
return DH_SUCCESS;
}
// 2.create input node
int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedHardware(devId, dhId, parameters);
if (FAILURE == ret) {
if (ret != DH_SUCCESS) {
DHLOGE("%s called, create node fail.", __func__);
for (auto iter = regCallbacks_.begin(); iter != regCallbacks_.end(); iter++) {
if (iter->devId == devId && iter->dhId == dhId) {
iter->callback->OnResult(iter->devId, iter->dhId, FAILURE);
iter->callback->OnResult(iter->devId, iter->dhId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL);
regCallbacks_.erase(iter);
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL;
}
}
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL;
}
// 3.save device
inputDevice_.push_back(inputDeviceId);
// 4.notify source distributedfwk register hardware success
callback->OnResult(devId, dhId, SUCCESS);
return SUCCESS;
callback->OnResult(devId, dhId, DH_SUCCESS);
return DH_SUCCESS;
}
void DistributedInputSourceManager::handleStartServerCallback(const std::string& devId)
@@ -637,19 +628,20 @@ void DistributedInputSourceManager::handleStartServerCallback(const std::string&
int32_t DistributedInputSourceManager::RemoveInputNode(const std::string& devId, const std::string& dhId)
{
int32_t ret = DistributedInputInject::GetInstance().UnregisterDistributedHardware(devId, dhId);
if (FAILURE == ret) {
if (ret != DH_SUCCESS) {
DHLOGE("%s called, remove node fail.", __func__);
for (std::vector<DInputClientUnregistInfo>::iterator iter =
unregCallbacks_.begin(); iter != unregCallbacks_.end(); iter++) {
if (iter->devId == devId && iter->dhId == dhId) {
iter->callback->OnResult(iter->devId, iter->dhId, FAILURE);
iter->callback->OnResult(iter->devId, iter->dhId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REMOVE_INPUT_NODE_FAIL);
unregCallbacks_.erase(iter);
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REMOVE_INPUT_NODE_FAIL;
}
}
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REMOVE_INPUT_NODE_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
}
int32_t DistributedInputSourceManager::DeleteDevice(const std::string& devId, const std::string& dhId)
@@ -665,10 +657,10 @@ int32_t DistributedInputSourceManager::DeleteDevice(const std::string& devId, co
if (callBackHandler_ == nullptr) {
DHLOGE("UnregisterDistributedHardware callBackHandler_ is null.");
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_DELETE_DEVICE_FAIL;
}
callBackHandler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
return SUCCESS;
return DH_SUCCESS;
}
int32_t DistributedInputSourceManager::UnregisterDistributedHardware(const std::string& devId, const std::string& dhId,
@@ -678,7 +670,7 @@ int32_t DistributedInputSourceManager::UnregisterDistributedHardware(const std::
if (callback == nullptr) {
DHLOGE("%s called, deviceId: %s callback is null.", __func__, devId.c_str());
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL;
}
DInputClientUnregistInfo info;
@@ -695,30 +687,30 @@ int32_t DistributedInputSourceManager::UnregisterDistributedHardware(const std::
for (std::vector<DInputClientUnregistInfo>::iterator iter =
unregCallbacks_.begin(); iter != unregCallbacks_.end(); iter++) {
if (iter->devId == devId && iter->dhId == dhId) {
iter->callback->OnResult(iter->devId, iter->dhId, FAILURE);
iter->callback->OnResult(iter->devId, iter->dhId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL);
unregCallbacks_.erase(iter);
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL;
}
}
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL;
}
// 1.remove input node
if (FAILURE == RemoveInputNode(devId, dhId)) {
callback->OnResult(devId, dhId, FAILURE);
return FAILURE;
if (DeleteDevice(devId, dhId) != DH_SUCCESS) {
callback->OnResult(devId, dhId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL;
}
// 2.delete device
inputDevice_.erase(it);
if (FAILURE == DeleteDevice(devId, dhId)) {
callback->OnResult(devId, dhId, FAILURE);
return FAILURE;
if (DeleteDevice(devId, dhId) != DH_SUCCESS) {
callback->OnResult(devId, dhId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL;
}
// 3.isstart callback
handleStartServerCallback(devId);
return SUCCESS;
return DH_SUCCESS;
}
int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string& deviceId,
@@ -727,22 +719,20 @@ int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string& dev
DHLOGI("%s called, deviceId: %s", __func__, deviceId.c_str());
if (callback == nullptr) {
DHLOGE("%s called, deviceId: %s callback is null.", __func__, deviceId.c_str());
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL;
}
for (auto iter : preCallbacks_) {
if (iter.devId == deviceId) {
callback->OnResult(deviceId, FAILURE);
return FAILURE;
callback->OnResult(deviceId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL;
}
}
int32_t ret = DistributedInputSourceTransport::GetInstance().OpenInputSoftbus(deviceId);
if (FAILURE == ret) {
if (ret != DH_SUCCESS) {
DHLOGE("Open softbus session fail.");
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL;
}
DInputClientPrepareInfo info;
info.devId = deviceId;
info.preCallback = callback;
@@ -750,19 +740,19 @@ int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string& dev
preCallbacks_.push_back(info);
ret = DistributedInputSourceTransport::GetInstance().PrepareRemoteInput(deviceId);
if (FAILURE == ret) {
if (ret != DH_SUCCESS) {
DHLOGE("Can not send message by softbus, prepare fail.");
for (auto iter = preCallbacks_.begin(); iter != preCallbacks_.end(); iter++) {
if (iter->devId == deviceId) {
iter->preCallback->OnResult(iter->devId, FAILURE);
iter->preCallback->OnResult(iter->devId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL);
preCallbacks_.erase(iter);
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL;
}
}
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
}
int32_t DistributedInputSourceManager::UnprepareRemoteInput(const std::string& deviceId,
@@ -772,13 +762,13 @@ int32_t DistributedInputSourceManager::UnprepareRemoteInput(const std::string& d
if (callback == nullptr) {
DHLOGE("%s called, deviceId: %s callback is null.", __func__, deviceId.c_str());
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL;
}
for (auto iter : unpreCallbacks_) {
if (iter.devId == deviceId) {
callback->OnResult(deviceId, FAILURE);
return FAILURE;
callback->OnResult(deviceId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL;
}
}
@@ -789,19 +779,19 @@ int32_t DistributedInputSourceManager::UnprepareRemoteInput(const std::string& d
unpreCallbacks_.push_back(info);
int32_t ret = DistributedInputSourceTransport::GetInstance().UnprepareRemoteInput(deviceId);
if (FAILURE == ret) {
if (ret != DH_SUCCESS) {
DHLOGE("Can not send message by softbus, unprepare fail.");
for (auto iter = unpreCallbacks_.begin(); iter != unpreCallbacks_.end(); iter++) {
if (iter->devId == deviceId) {
iter->unpreCallback->OnResult(iter->devId, FAILURE);
iter->unpreCallback->OnResult(iter->devId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL);
unpreCallbacks_.erase(iter);
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL;
}
}
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
}
int32_t DistributedInputSourceManager::StartRemoteInput(
@@ -811,13 +801,13 @@ int32_t DistributedInputSourceManager::StartRemoteInput(
if (callback == nullptr) {
DHLOGE("%s called, deviceId: %s callback is null.", __func__, deviceId.c_str());
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL;
}
for (auto iter : staCallbacks_) {
if (iter.devId == deviceId && iter.inputTypes == inputTypes) {
callback->OnResult(deviceId, inputTypes, FAILURE);
return FAILURE;
callback->OnResult(deviceId, inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL;
}
}
@@ -829,20 +819,20 @@ int32_t DistributedInputSourceManager::StartRemoteInput(
DeviceMap_[deviceId] = DINPUT_SOURCE_SWITCH_OFF; // when sink device start success,set DINPUT_SOURCE_SWITCH_ON
int32_t ret = DistributedInputSourceTransport::GetInstance().StartRemoteInput(deviceId, inputTypes);
if (FAILURE == ret) {
if (ret != DH_SUCCESS) {
DHLOGE("%s called, start fail.", __func__);
for (std::vector<DInputClientStartInfo>::iterator iter =
staCallbacks_.begin(); iter != staCallbacks_.end(); iter++) {
if (iter->devId == deviceId && iter->inputTypes == inputTypes) {
iter->callback->OnResult(iter->devId, iter->inputTypes, FAILURE);
iter->callback->OnResult(iter->devId, iter->inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL);
staCallbacks_.erase(iter);
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL;
}
}
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
}
int32_t DistributedInputSourceManager::StopRemoteInput(
@@ -852,13 +842,13 @@ int32_t DistributedInputSourceManager::StopRemoteInput(
if (callback == nullptr) {
DHLOGE("%s called, deviceId: %s callback is null.", __func__, deviceId.c_str());
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL;
}
for (auto iter : stpCallbacks_) {
if (iter.devId == deviceId && iter.inputTypes == inputTypes) {
callback->OnResult(deviceId, inputTypes, FAILURE);
return FAILURE;
callback->OnResult(deviceId, inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL;
}
}
@@ -869,20 +859,20 @@ int32_t DistributedInputSourceManager::StopRemoteInput(
stpCallbacks_.push_back(info);
int32_t ret = DistributedInputSourceTransport::GetInstance().StopRemoteInput(deviceId, inputTypes);
if (FAILURE == ret) {
if (ret != DH_SUCCESS) {
DHLOGE("%s called, stop fail.", __func__);
for (std::vector<DInputClientStopInfo>::iterator iter =
stpCallbacks_.begin(); iter != stpCallbacks_.end(); iter++) {
if (iter->devId == deviceId && iter->inputTypes == inputTypes) {
iter->callback->OnResult(iter->devId, iter->inputTypes, FAILURE);
iter->callback->OnResult(iter->devId, iter->inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL);
stpCallbacks_.erase(iter);
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL;
}
}
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
}
int32_t DistributedInputSourceManager::IsStartDistributedInput(
@@ -19,6 +19,7 @@
#include <cstring>
#include "distributed_hardware_log.h"
#include "dinput_errcode.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
#include "session.h"
@@ -101,20 +102,20 @@ int32_t DistributedInputSourceTransport::Init()
auto localNode = std::make_unique<NodeBasicInfo>();
int32_t retCode = GetLocalNodeDeviceInfo(DINPUT_PKG_NAME.c_str(), localNode.get());
if (retCode != SUCCESS) {
if (retCode != DH_SUCCESS) {
DHLOGE("Init Could not get local device id.");
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_INIT_FAIL;
}
std::string networkId = localNode->networkId;
DHLOGI("Init device local networkId is %s", networkId.c_str());
mySessionName_ = SESSION_NAME_SOURCE + networkId.substr(0, INTERCEPT_STRING_LENGTH);
int32_t ret = CreateSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str(), &iSessionListener);
if (ret != SUCCESS) {
if (ret != DH_SUCCESS) {
DHLOGE("Init CreateSessionServer failed, error code %d.", ret);
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_INIT_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
}
void DistributedInputSourceTransport::Release()
@@ -132,28 +133,28 @@ int32_t DistributedInputSourceTransport::CheckDeviceSessionState(const std::stri
std::unique_lock<std::mutex> sessionLock(operationMutex_);
if (sessionDevMap_.count(devId) != 0) {
DHLOGI("CheckDeviceSessionState has opened %s", devId.c_str());
return SUCCESS;
return DH_SUCCESS;
} else {
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_DEVICE_SESSION_STATE;
}
}
int32_t DistributedInputSourceTransport::OpenInputSoftbus(const std::string &remoteDevId)
{
int32_t ret = CheckDeviceSessionState(remoteDevId);
if (ret == SUCCESS) {
if (ret == DH_SUCCESS) {
DHLOGE("Softbus session has already opened, deviceId: %s", remoteDevId.c_str());
return SUCCESS;
return DH_SUCCESS;
}
std::string peerSessionName = SESSION_NAME_SINK + remoteDevId.substr(0, INTERCEPT_STRING_LENGTH);
DHLOGI("peerSessionName:%s", peerSessionName.c_str());
DHLOGI("OpenInputSoftbus peerSessionName:%s", peerSessionName.c_str());
int sessionId = OpenSession(mySessionName_.c_str(), peerSessionName.c_str(), remoteDevId.c_str(),
GROUP_ID.c_str(), &g_sessionAttr);
if (sessionId < 0) {
DHLOGE("OpenSession fail, remoteDevId: %s, sessionId: %d", remoteDevId.c_str(), sessionId);
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_OPEN_SESSION_FAIL;
}
DHLOGI("Wait for channel session opened.");
@@ -163,7 +164,7 @@ int32_t DistributedInputSourceTransport::OpenInputSoftbus(const std::string &rem
[this, remoteDevId] () { return channelStatusMap_[remoteDevId]; });
if (!status) {
DHLOGE("OpenSession timeout, remoteDevId: %s, sessionId: %d", remoteDevId.c_str(), sessionId);
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_OPEN_SESSION_TIMEOUT;
}
}
@@ -172,7 +173,7 @@ int32_t DistributedInputSourceTransport::OpenInputSoftbus(const std::string &rem
std::unique_lock<std::mutex> sessionLock(operationMutex_);
sessionDevMap_[remoteDevId] = sessionId;
}
return SUCCESS;
return DH_SUCCESS;
}
void DistributedInputSourceTransport::CloseInputSoftbus(const std::string &remoteDevId)
@@ -215,18 +216,18 @@ int32_t DistributedInputSourceTransport::PrepareRemoteInput(const std::string& d
jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId;
std::string smsg = jsonStr.dump();
int32_t ret = SendMsg(sessionId, smsg);
if (ret != SUCCESS) {
if (ret != DH_SUCCESS) {
DHLOGE("PrepareRemoteInput deviceId:%s, sessionId:%d, smsg:%s, SendMsg error, ret:%d.",
deviceId.c_str(), sessionId, smsg.c_str(), ret);
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_PREPARE_FAIL;
}
DHLOGI("PrepareRemoteInput devId:%s, sessionId:%d, msg:%s.",
deviceId.c_str(), sessionId, smsg.c_str());
return SUCCESS;
return DH_SUCCESS;
} else {
DHLOGE("PrepareRemoteInput error, not find this device:%s.",
deviceId.c_str());
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_PREPARE_FAIL;
}
}
@@ -241,18 +242,18 @@ int32_t DistributedInputSourceTransport::UnprepareRemoteInput(const std::string&
jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId;
std::string smsg = jsonStr.dump();
int32_t ret = SendMsg(sessionId, smsg);
if (ret != SUCCESS) {
if (ret != DH_SUCCESS) {
DHLOGE("UnprepareRemoteInput deviceId:%s, sessionId:%d, smsg:%s, SendMsg error, ret:%d.",
deviceId.c_str(), sessionId, smsg.c_str(), ret);
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_UNPREPARE_FAIL;
}
DHLOGI("UnprepareRemoteInput deviceId:%s, sessionId:%d, smsg:%s.",
deviceId.c_str(), sessionId, smsg.c_str());
return SUCCESS;
return DH_SUCCESS;
} else {
DHLOGE("UnprepareRemoteInput error, not find this device:%s.",
deviceId.c_str());
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_UNPREPARE_FAIL;
}
}
@@ -269,17 +270,17 @@ int32_t DistributedInputSourceTransport::StartRemoteInput(
jsonStr[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes;
std::string smsg = jsonStr.dump();
int32_t ret = SendMsg(sessionId, smsg);
if (ret != SUCCESS) {
if (ret != DH_SUCCESS) {
DHLOGE("StartRemoteInput deviceId:%s, sessionId:%d, smsg:%s, SendMsg error, ret:%d.",
deviceId.c_str(), sessionId, smsg.c_str(), ret);
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL;
}
DHLOGI("StartRemoteInput deviceId:%s, sessionId:%d, smsg:%s.", deviceId.c_str(), sessionId, smsg.c_str());
return SUCCESS;
return DH_SUCCESS;
} else {
DHLOGE("StartRemoteInput error, not find this device:%s.",
deviceId.c_str());
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL;
}
}
@@ -296,16 +297,16 @@ int32_t DistributedInputSourceTransport::StopRemoteInput(
jsonStr[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes;
std::string smsg = jsonStr.dump();
int32_t ret = SendMsg(sessionId, smsg);
if (ret != SUCCESS) {
if (ret != DH_SUCCESS) {
DHLOGE("StopRemoteInput deviceId:%s, sessionId:%d, smsg:%s, SendMsg error, ret:%d.",
deviceId.c_str(), sessionId, smsg.c_str(), ret);
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL;
}
DHLOGI("StopRemoteInput deviceId:%s, sessionId:%d, smsg:%s.", deviceId.c_str(), sessionId, smsg.c_str());
return SUCCESS;
return DH_SUCCESS;
} else {
DHLOGE("StopRemoteInput error, not find this device:%s.", deviceId.c_str());
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL;
}
}
@@ -328,7 +329,7 @@ std::string DistributedInputSourceTransport::FindDeviceBySession(int32_t session
int32_t DistributedInputSourceTransport::OnSessionOpened(int32_t sessionId, int32_t result)
{
if (result != SUCCESS) {
if (result != DH_SUCCESS) {
std::string deviceId = FindDeviceBySession(sessionId);
DHLOGE("session open failed, sessionId:%d, result:%d, "
"deviceId:%s", sessionId, result, deviceId.c_str());
@@ -336,7 +337,7 @@ int32_t DistributedInputSourceTransport::OnSessionOpened(int32_t sessionId, int3
if (sessionDevMap_.count(deviceId) > 0) {
sessionDevMap_.erase(deviceId);
}
return SUCCESS;
return DH_SUCCESS;
}
std::string deviceId = FindDeviceBySession(sessionId);
@@ -348,15 +349,15 @@ int32_t DistributedInputSourceTransport::OnSessionOpened(int32_t sessionId, int3
char peerSessionName[SESSION_NAME_SIZE_MAX] = "";
char peerDevId[DEVICE_ID_SIZE_MAX] = "";
int ret = GetMySessionName(sessionId, mySessionName, sizeof(mySessionName));
if (ret != SUCCESS) {
if (ret != DH_SUCCESS) {
DHLOGI("get my session name failed, session id is %d.", sessionId);
}
ret = GetPeerSessionName(sessionId, peerSessionName, sizeof(peerSessionName));
if (ret != SUCCESS) {
if (ret != DH_SUCCESS) {
DHLOGI("get peer session name failed, session id is %d.", sessionId);
}
ret = GetPeerDeviceId(sessionId, peerDevId, sizeof(peerDevId));
if (ret != SUCCESS) {
if (ret != DH_SUCCESS) {
DHLOGI("get peer device id failed, session id is %d.", sessionId);
}
DHLOGI("mySessionName:%s, peerSessionName:%s, peerDevId:%s.",
@@ -367,7 +368,7 @@ int32_t DistributedInputSourceTransport::OnSessionOpened(int32_t sessionId, int3
openSessionWaitCond_.notify_all();
}
DistributedInputInject::GetInstance().StartInjectThread();
return SUCCESS;
return DH_SUCCESS;
}
void DistributedInputSourceTransport::OnSessionClosed(int32_t sessionId)
@@ -533,7 +534,7 @@ void DistributedInputSourceTransport::OnBytesReceived(int32_t sessionId, const v
return;
}
if (memcpy_s(buf, dataLen + 1, (const uint8_t*)data, dataLen) != SUCCESS) {
if (memcpy_s(buf, dataLen + 1, (const uint8_t*)data, dataLen) != DH_SUCCESS) {
DHLOGE("OnBytesReceived: memcpy memory failed");
free(buf);
return;
@@ -554,18 +555,18 @@ int32_t DistributedInputSourceTransport::SendMsg(int32_t sessionId, std::string
DHLOGI("start SendMsg");
if (message.size() > MSG_MAX_SIZE) {
DHLOGE("SendMessage error: message.size() > MSG_MAX_SIZE");
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE;
}
uint8_t *buf = (uint8_t *)calloc((MSG_MAX_SIZE), sizeof(uint8_t));
if (buf == nullptr) {
DHLOGE("SendMsg: malloc memory failed");
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE;
}
int32_t outLen = 0;
if (memcpy_s(buf, MSG_MAX_SIZE, (const uint8_t *)message.c_str(), message.size()) != SUCCESS) {
if (memcpy_s(buf, MSG_MAX_SIZE, (const uint8_t *)message.c_str(), message.size()) != DH_SUCCESS) {
DHLOGE("SendMsg: memcpy memory failed");
free(buf);
return FAILURE;
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE;
}
outLen = message.size();
int32_t ret = SendBytes(sessionId, buf, outLen);
@@ -574,4 +575,4 @@ int32_t DistributedInputSourceTransport::SendMsg(int32_t sessionId, std::string
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
} // namespace OHOS
@@ -17,6 +17,7 @@
#include "i_distributed_sink_input.h"
#include "load_d_input_sink_callback.h"
#include "distributed_hardware_log.h"
#include "dinput_errcode.h"
namespace OHOS {
namespace DistributedHardware {
@@ -36,14 +37,14 @@ int32_t DistributedInputSinkHandler::InitSink(const std::string &params)
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (!samgr) {
DHLOGE("Failed to get system ability mgr.");
return FAILURE_DIS;
return ERR_DH_INPUT_SINK_HANDLER_INIT_SINK_SA_FAIL;
}
sptr<LoadDInputSinkCallback> loadCallback = new LoadDInputSinkCallback(params);
int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID, loadCallback);
if (ret != ERR_OK) {
DHLOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d",
DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID, ret);
return FAILURE_DIS;
return ERR_DH_INPUT_SINK_HANDLER_INIT_SINK_SA_FAIL;
}
}
@@ -51,10 +52,10 @@ int32_t DistributedInputSinkHandler::InitSink(const std::string &params)
[this]() { return (DistributedInputClient::GetInstance().HasDInputSinkProxy()); });
if (!waitStatus) {
DHLOGE("dinput load sa timeout.");
return FAILURE_DIS;
return ERR_DH_INPUT_SINK_HANDLER_INIT_SINK_SA_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
}
void DistributedInputSinkHandler::FinishStartSA(const std::string &params, const sptr<IRemoteObject> &remoteObject)
@@ -73,12 +74,12 @@ int32_t DistributedInputSinkHandler::ReleaseSink()
int32_t DistributedInputSinkHandler::SubscribeLocalHardware(const std::string &dhId, const std::string &params)
{
return SUCCESS;
return DH_SUCCESS;
}
int32_t DistributedInputSinkHandler::UnsubscribeLocalHardware(const std::string &dhId)
{
return SUCCESS;
return DH_SUCCESS;
}
void DistributedInputSinkHandler::SALoadSinkCb::OnLoadSystemAbilitySuccess(int32_t systemAbilityId,
@@ -16,6 +16,7 @@
#include "distributed_input_source_handler.h"
#include "distributed_hardware_log.h"
#include "dinput_errcode.h"
#include "i_distributed_source_input.h"
#include "load_d_input_source_callback.h"
@@ -36,14 +37,14 @@ int32_t DistributedInputSourceHandler::InitSource(const std::string &params)
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (!samgr) {
DHLOGE("Failed to get system ability mgr.");
return FAILURE_DIS;
return ERR_DH_INPUT_SINK_HANDLER_INIT_SOURCE_SA_FAIL;
}
sptr<LoadDInputSourceCallback> loadCallback = new LoadDInputSourceCallback(params);
int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, loadCallback);
if (ret != ERR_OK) {
DHLOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d",
DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, ret);
return FAILURE_DIS;
return ERR_DH_INPUT_SINK_HANDLER_INIT_SOURCE_SA_FAIL;
}
}
@@ -51,10 +52,10 @@ int32_t DistributedInputSourceHandler::InitSource(const std::string &params)
[this]() { return (DistributedInputClient::GetInstance().HasDInputSourceProxy()); });
if (!waitStatus) {
DHLOGE("dinput load sa timeout.");
return FAILURE_DIS;
return ERR_DH_INPUT_SINK_HANDLER_INIT_SOURCE_SA_FAIL;
}
return SUCCESS;
return DH_SUCCESS;
}
void DistributedInputSourceHandler::FinishStartSA(const std::string &params, const sptr<IRemoteObject> &remoteObject)
@@ -86,7 +87,7 @@ int32_t DistributedInputSourceHandler::UnregisterDistributedHardware(const std::
int32_t DistributedInputSourceHandler::ConfigDistributedHardware(const std::string &devId,
const std::string &dhId, const std::string &key, const std::string &value)
{
return SUCCESS;
return DH_SUCCESS;
}
void DistributedInputSourceHandler::SALoadSourceCb::OnLoadSystemAbilitySuccess(int32_t systemAbilityId,