/* * 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. */ #include "distributed_input_source_stub.h" #include "constants_dinput.h" namespace OHOS { namespace DistributedHardware { namespace DistributedInput { DistributedInputSourceStub::DistributedInputSourceStub() {} DistributedInputSourceStub::~DistributedInputSourceStub() {} int32_t DistributedInputSourceStub::HandleRegisterDistributedHardware(MessageParcel &data, MessageParcel &reply) { std::string devId = data.ReadString(); std::string dhId = data.ReadString(); std::string params = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); int32_t ret = RegisterDistributedHardware(devId, dhId, params, callback); if (!reply.WriteInt32(ret)) { return ERROR; } return NO_ERROR; } int32_t DistributedInputSourceStub::HandleUnregisterDistributedHardware(MessageParcel &data, MessageParcel &reply) { std::string devId = data.ReadString(); std::string dhId = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); int32_t ret = UnregisterDistributedHardware(devId, dhId, callback); if (!reply.WriteInt32(ret)) { return ERROR; } return NO_ERROR; } int32_t DistributedInputSourceStub::HandlePrepareRemoteInput(MessageParcel &data, MessageParcel &reply) { std::string deviceId = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); sptr addCallback = iface_cast(data.ReadRemoteObject()); int32_t ret = PrepareRemoteInput(deviceId, callback, addCallback); if (!reply.WriteInt32(ret)) { return ERROR; } return NO_ERROR; } int32_t DistributedInputSourceStub::HandleUnprepareRemoteInput(MessageParcel &data, MessageParcel &reply) { std::string deviceId = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); sptr delCallback = iface_cast(data.ReadRemoteObject()); int32_t ret = UnprepareRemoteInput(deviceId, callback, delCallback); if (!reply.WriteInt32(ret)) { return ERROR; } return NO_ERROR; } int32_t DistributedInputSourceStub::HandleStartRemoteInput(MessageParcel &data, MessageParcel &reply) { std::string deviceId = data.ReadString(); uint32_t inputTypes = data.ReadUint32(); sptr callback = iface_cast(data.ReadRemoteObject()); int32_t ret = StartRemoteInput(deviceId, inputTypes, callback); if (!reply.WriteInt32(ret)) { return ERROR; } return NO_ERROR; } int32_t DistributedInputSourceStub::HandleStopRemoteInput(MessageParcel &data, MessageParcel &reply) { std::string deviceId = data.ReadString(); uint32_t inputTypes = data.ReadUint32(); sptr callback = iface_cast(data.ReadRemoteObject()); int32_t ret = StopRemoteInput(deviceId, inputTypes, callback); if (!reply.WriteInt32(ret)) { return ERROR; } return NO_ERROR; } int32_t DistributedInputSourceStub::HandleIsStartDistributedInput(MessageParcel &data, MessageParcel &reply) { uint32_t inputType = data.ReadUint32(); sptr callback = iface_cast(data.ReadRemoteObject()); int32_t ret = IsStartDistributedInput(inputType, callback); if (!reply.WriteInt32(ret)) { return ERROR; } return NO_ERROR; } int32_t DistributedInputSourceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { switch (code) { case static_cast(IDistributedSourceInput::MessageCode::INIT): { int32_t ret = Init(); if (!reply.WriteInt32(ret)) { return ERROR; } else { return NO_ERROR; } break; } case static_cast(IDistributedSourceInput::MessageCode::RELEASE): { int32_t ret = Release(); if (!reply.WriteInt32(ret)) { return ERROR; } else { return NO_ERROR; } break; } case static_cast(IDistributedSourceInput::MessageCode::REGISTER_REMOTE_INPUT): { return HandleRegisterDistributedHardware(data, reply); break; } case static_cast(IDistributedSourceInput::MessageCode::UNREGISTER_REMOTE_INPUT): { return HandleUnregisterDistributedHardware(data, reply); break; } case static_cast(IDistributedSourceInput::MessageCode::PREPARE_REMOTE_INPUT): { return HandlePrepareRemoteInput(data, reply); break; } case static_cast(IDistributedSourceInput::MessageCode::UNPREPARE_REMOTE_INPUT): { return HandleUnprepareRemoteInput(data, reply); break; } case static_cast(IDistributedSourceInput::MessageCode::START_REMOTE_INPUT): { return HandleStartRemoteInput(data, reply); break; } case static_cast(IDistributedSourceInput::MessageCode::STOP_REMOTE_INPUT): { return HandleStopRemoteInput(data, reply); break; } case static_cast(IDistributedSourceInput::MessageCode::ISSTART_REMOTE_INPUT): { return HandleIsStartDistributedInput(data, reply); break; } default: return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } } } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS