From 350fbd9e0ed58591db3d7828b75905863b31e04f Mon Sep 17 00:00:00 2001 From: litiangang4 Date: Tue, 22 Aug 2023 14:09:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0session=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E5=9B=9E=E8=B0=83=E7=BB=99=E9=94=AE=E9=BC=A0?= =?UTF-8?q?=E7=A9=BF=E8=B6=8A=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: litiangang4 --- common/include/dinput_errcode.h | 5 ++ common/include/dinput_ipc_interface_code.h | 2 + .../include/i_distributed_source_input.h | 3 + frameworks/include/i_session_state_callback.h | 40 ++++++++++++ interfaces/inner_kits/BUILD.gn | 2 + .../include/distributed_input_kit.h | 4 ++ .../inner_kits/src/distributed_input_kit.cpp | 9 +++ .../ipc/include/distributed_input_client.h | 3 + .../include/distributed_input_source_proxy.h | 3 + .../include/distributed_input_source_stub.h | 2 + .../register_session_state_callback_proxy.h | 42 +++++++++++++ .../register_session_state_callback_stub.h | 42 +++++++++++++ .../ipc/src/distributed_input_client.cpp | 22 +++++++ .../src/distributed_input_source_proxy.cpp | 41 ++++++++++++ .../ipc/src/distributed_input_source_stub.cpp | 33 ++++++++++ .../register_session_state_callback_proxy.cpp | 63 +++++++++++++++++++ .../register_session_state_callback_stub.cpp | 57 +++++++++++++++++ services/source/sourcemanager/BUILD.gn | 4 ++ .../distributed_input_source_manager.h | 4 ++ .../src/distributed_input_source_manager.cpp | 16 +++++ .../distributed_input_transport_base.h | 7 +++ .../src/distributed_input_transport_base.cpp | 28 ++++++++- 22 files changed, 431 insertions(+), 1 deletion(-) create mode 100644 frameworks/include/i_session_state_callback.h create mode 100644 interfaces/ipc/include/register_session_state_callback_proxy.h create mode 100644 interfaces/ipc/include/register_session_state_callback_stub.h create mode 100644 interfaces/ipc/src/register_session_state_callback_proxy.cpp create mode 100644 interfaces/ipc/src/register_session_state_callback_stub.cpp diff --git a/common/include/dinput_errcode.h b/common/include/dinput_errcode.h index b19237e..c02dc28 100644 --- a/common/include/dinput_errcode.h +++ b/common/include/dinput_errcode.h @@ -109,6 +109,7 @@ namespace DistributedInput { constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_SIMULATION_EVENT_CALLBACK_ERR = -65037; constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_DH_FWK_KIT_IS_NULL = -65038; constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_NODE_LISTENER_CALLBACK_ERR = -65039; + constexpr int32_t ERR_DH_INPUT_SRC_MGR_SESSION_STATE_CB_IS_NULL = -65040; // handler error code constexpr int32_t ERR_DH_INPUT_SINK_HANDLER_INIT_SINK_SA_FAIL = -66000; @@ -172,6 +173,10 @@ namespace DistributedInput { constexpr int32_t ERR_DH_INPUT_SINK_PROXY_REGISTER_SHARING_DHID_LISTENER_FAIL = -67054; constexpr int32_t ERR_DH_INPUT_SINK_STUB_REGISTER_SHARING_DHID_LISTENER_FAIL = -67055; constexpr int32_t ERR_DH_INPUT_SINK_PROXY_REGISTER_GETSINKSCREENINFOS_FAIL = -67056; + constexpr int32_t ERR_DH_INPUT_CLIENT_REGISTER_SESSION_STATE_FAIL = -67057; + constexpr int32_t ERR_DH_INPUT_CLIENT_UNREGISTER_SESSION_STATE_FAIL = -67058; + constexpr int32_t ERR_DH_INPUT_SRC_STUB_REGISTER_SESSION_STATE_FAIL = -67059; + constexpr int32_t ERR_DH_INPUT_SRC_STUB_UNREGISTER_SESSION_STATE_FAIL = -67060; // Hidump Helper error code constexpr int32_t ERR_DH_INPUT_HIDUMP_INVALID_ARGS = -68000; diff --git a/common/include/dinput_ipc_interface_code.h b/common/include/dinput_ipc_interface_code.h index be71e68..f12059c 100644 --- a/common/include/dinput_ipc_interface_code.h +++ b/common/include/dinput_ipc_interface_code.h @@ -45,6 +45,8 @@ enum class IDInputSourceInterfaceCode : uint32_t { REGISTER_SIMULATION_EVENT_LISTENER = 0xf017U, UNREGISTER_SIMULATION_EVENT_LISTENER = 0xf018U, SYNC_NODE_INFO_REMOTE_INPUT = 0xf019U, + REGISTER_SESSION_STATE_CB = 0xf020U, + UNREGISTER_SESSION_STATE_CB = 0xf021U, }; /* SAID: 4810 */ diff --git a/frameworks/include/i_distributed_source_input.h b/frameworks/include/i_distributed_source_input.h index 5df8843..fbe654a 100644 --- a/frameworks/include/i_distributed_source_input.h +++ b/frameworks/include/i_distributed_source_input.h @@ -35,6 +35,7 @@ #include "i_unregister_d_input_call_back.h" #include "i_input_node_listener.h" #include "i_simulation_event_listener.h" +#include "i_session_state_callback.h" namespace OHOS { namespace DistributedHardware { @@ -98,6 +99,8 @@ public: const std::string &nodeDesc) = 0; virtual int32_t RegisterSimulationEventListener(sptr listener) = 0; virtual int32_t UnregisterSimulationEventListener(sptr listener) = 0; + virtual int32_t RegisterSessionStateCb(sptr callback) = 0; + virtual int32_t UnregisterSessionStateCb() = 0; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/frameworks/include/i_session_state_callback.h b/frameworks/include/i_session_state_callback.h new file mode 100644 index 0000000..be6e42c --- /dev/null +++ b/frameworks/include/i_session_state_callback.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef I_REGISTER_SESSION_STATE_CALLBACK_H +#define I_REGISTER_SESSION_STATE_CALLBACK_H + +#include + +#include + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class ISessionStateCallback : public IRemoteBroker { +public: + virtual void OnResult(const std::string &devId, const uint32_t &status) = 0; + + enum class Message { + RESULT, + }; + + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.ISessionStateCallback"); +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // I_REGISTER_SESSION_STATE_CALLBACK_H \ No newline at end of file diff --git a/interfaces/inner_kits/BUILD.gn b/interfaces/inner_kits/BUILD.gn index 8bb8c1f..cc6d316 100644 --- a/interfaces/inner_kits/BUILD.gn +++ b/interfaces/inner_kits/BUILD.gn @@ -73,6 +73,8 @@ ohos_shared_library("libdinput_sdk") { "${ipc_path}/src/unprepare_d_input_call_back_stub.cpp", "${ipc_path}/src/unregister_d_input_call_back_proxy.cpp", "${ipc_path}/src/unregister_d_input_call_back_stub.cpp", + "${ipc_path}/src/register_session_state_callback_proxy.cpp", + "${ipc_path}/src/register_session_state_callback_stub.cpp", ] deps = [ diff --git a/interfaces/inner_kits/include/distributed_input_kit.h b/interfaces/inner_kits/include/distributed_input_kit.h index 172a5e2..e0ec439 100644 --- a/interfaces/inner_kits/include/distributed_input_kit.h +++ b/interfaces/inner_kits/include/distributed_input_kit.h @@ -30,6 +30,7 @@ #include "i_start_stop_result_call_back.h" #include "i_unregister_d_input_call_back.h" #include "i_unprepare_d_input_call_back.h" +#include "i_session_state_callback.h" namespace OHOS { namespace DistributedHardware { @@ -80,6 +81,9 @@ public: static int32_t UnregisterInputNodeListener(sptr listener); static int32_t RegisterSimulationEventListener(sptr listener); static int32_t UnregisterSimulationEventListener(sptr listener); + + static int32_t RegisterSessionStateCb(sptr callback); + static int32_t UnregisterSessionStateCb(); }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/interfaces/inner_kits/src/distributed_input_kit.cpp b/interfaces/inner_kits/src/distributed_input_kit.cpp index 6c88b71..2cdd774 100644 --- a/interfaces/inner_kits/src/distributed_input_kit.cpp +++ b/interfaces/inner_kits/src/distributed_input_kit.cpp @@ -129,6 +129,15 @@ int32_t DistributedInputKit::UnregisterSimulationEventListener(sptr callback) +{ + return DistributedInputClient::GetInstance().RegisterSessionStateCb(callback); +} +int32_t DistributedInputKit::UnregisterSessionStateCb() +{ + return DistributedInputClient::GetInstance().UnregisterSessionStateCb(); +} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/ipc/include/distributed_input_client.h b/interfaces/ipc/include/distributed_input_client.h index cd0adfe..c4449ec 100644 --- a/interfaces/ipc/include/distributed_input_client.h +++ b/interfaces/ipc/include/distributed_input_client.h @@ -107,6 +107,9 @@ public: int32_t RegisterSimulationEventListener(sptr listener); int32_t UnregisterSimulationEventListener(sptr listener); + int32_t RegisterSessionStateCb(sptr callback); + int32_t UnregisterSessionStateCb(); + void CheckSourceRegisterCallback(); void CheckWhiteListCallback(); void CheckNodeMonitorCallback(); diff --git a/interfaces/ipc/include/distributed_input_source_proxy.h b/interfaces/ipc/include/distributed_input_source_proxy.h index 1370711..4824e30 100644 --- a/interfaces/ipc/include/distributed_input_source_proxy.h +++ b/interfaces/ipc/include/distributed_input_source_proxy.h @@ -84,6 +84,9 @@ public: int32_t RegisterSimulationEventListener(sptr listener) override; int32_t UnregisterSimulationEventListener(sptr listener) override; + int32_t RegisterSessionStateCb(sptr callback) override; + int32_t UnregisterSessionStateCb() override; + private: bool SendRequest(const uint32_t code, MessageParcel &data, MessageParcel &reply); diff --git a/interfaces/ipc/include/distributed_input_source_stub.h b/interfaces/ipc/include/distributed_input_source_stub.h index 8f40adb..da6741f 100644 --- a/interfaces/ipc/include/distributed_input_source_stub.h +++ b/interfaces/ipc/include/distributed_input_source_stub.h @@ -58,6 +58,8 @@ private: int32_t HandleSyncNodeInfoRemoteInput(MessageParcel &data, MessageParcel &reply); int32_t HandleRegisterSimulationEventListener(MessageParcel &data, MessageParcel &reply); int32_t HandleUnregisterSimulationEventListener(MessageParcel &data, MessageParcel &reply); + int32_t HandleRegisterSessionStateCb(MessageParcel &data, MessageParcel &reply); + int32_t HandleUnregisterSessionStateCb(MessageParcel &data, MessageParcel &reply); DISALLOW_COPY_AND_MOVE(DistributedInputSourceStub); private: std::atomic sourceManagerInitFlag_ {false}; diff --git a/interfaces/ipc/include/register_session_state_callback_proxy.h b/interfaces/ipc/include/register_session_state_callback_proxy.h new file mode 100644 index 0000000..65f572d --- /dev/null +++ b/interfaces/ipc/include/register_session_state_callback_proxy.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 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 REGISTER_SESSION_STATE_CALLBACK_PROXY_H +#define REGISTER_SESSION_STATE_CALLBACK_PROXY_H + +#include "i_session_state_callback.h" + +#include + +#include "iremote_proxy.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class RegisterSessionStateCallbackProxy : public IRemoteProxy { +public: + explicit RegisterSessionStateCallbackProxy(const sptr &object); + ~RegisterSessionStateCallbackProxy() override; + + void OnResult(const std::string &deviceId, const uint32_t &status) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // REGISTER_SESSION_STATE_CALLBACK_PROXY_H diff --git a/interfaces/ipc/include/register_session_state_callback_stub.h b/interfaces/ipc/include/register_session_state_callback_stub.h new file mode 100644 index 0000000..2e4755b --- /dev/null +++ b/interfaces/ipc/include/register_session_state_callback_stub.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 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 REGISTER_SESSION_STATE_CALLBACK_STUB_H +#define REGISTER_SESSION_STATE_CALLBACK_STUB_H + +#include "i_session_state_callback.h" + +#include + +#include "iremote_stub.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class RegisterSessionStateCallbackStub : public IRemoteStub { +public: + RegisterSessionStateCallbackStub(); + ~RegisterSessionStateCallbackStub() override; + + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + DISALLOW_COPY_AND_MOVE(RegisterSessionStateCallbackStub); +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // REGISTER_SESSION_STATE_CALLBACK_STUB_H diff --git a/interfaces/ipc/src/distributed_input_client.cpp b/interfaces/ipc/src/distributed_input_client.cpp index 8b00a9d..4b5ca09 100644 --- a/interfaces/ipc/src/distributed_input_client.cpp +++ b/interfaces/ipc/src/distributed_input_client.cpp @@ -796,6 +796,28 @@ sptr DistributedInputClient::GetRemoteDInput(const std::s } return iface_cast(object); } + +int32_t DistributedInputClient::RegisterSessionStateCb(sptr callback) +{ + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("DinputStart client fail."); + return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; + } + if (callback == nullptr) { + DHLOGE("RegisterSessionStateCb callback is null."); + return ERR_DH_INPUT_CLIENT_REGISTER_SESSION_STATE_FAIL; + } + return DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSessionStateCb(callback); +} + +int32_t DistributedInputClient::UnregisterSessionStateCb() +{ + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("DinputStart client fail."); + return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; + } + return DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterSessionStateCb(); +} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/ipc/src/distributed_input_source_proxy.cpp b/interfaces/ipc/src/distributed_input_source_proxy.cpp index c327407..8bd4d5d 100644 --- a/interfaces/ipc/src/distributed_input_source_proxy.cpp +++ b/interfaces/ipc/src/distributed_input_source_proxy.cpp @@ -702,6 +702,47 @@ int32_t DistributedInputSourceProxy::UnregisterSimulationEventListener(sptr callback) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + DHLOGE("RegisterSessionStateCb write token valid failed"); + return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + } + + if (!data.WriteRemoteObject(callback->AsObject())) { + DHLOGE("RegisterSessionStateCb write callback failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + + MessageParcel reply; + int32_t result = ERR_DH_INPUT_SRC_STUB_REGISTER_SESSION_STATE_FAIL; + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::REGISTER_SESSION_STATE_CB), + data, reply); + if (ret) { + result = reply.ReadInt32(); + } + return result; +} + +int32_t DistributedInputSourceProxy::UnregisterSessionStateCb() +{ + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + DHLOGE("UnregisterSessionStateCb write token valid failed"); + return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + } + + MessageParcel reply; + int32_t result = ERR_DH_INPUT_SRC_STUB_UNREGISTER_SESSION_STATE_FAIL; + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::UNREGISTER_SESSION_STATE_CB), + data, reply); + if (ret) { + result = reply.ReadInt32(); + } + return result; +} + bool DistributedInputSourceProxy::SendRequest(const uint32_t code, MessageParcel &data, MessageParcel &reply) { sptr remote = Remote(); diff --git a/interfaces/ipc/src/distributed_input_source_stub.cpp b/interfaces/ipc/src/distributed_input_source_stub.cpp index 5b7a959..d5379f9 100644 --- a/interfaces/ipc/src/distributed_input_source_stub.cpp +++ b/interfaces/ipc/src/distributed_input_source_stub.cpp @@ -474,6 +474,33 @@ int32_t DistributedInputSourceStub::HandleUnregisterSimulationEventListener(Mess return DH_SUCCESS; } +int32_t DistributedInputSourceStub::HandleRegisterSessionStateCb(MessageParcel &data, MessageParcel &reply) +{ + sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleRegisterSessionStateCb failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } + int32_t ret = RegisterSessionStateCb(callback); + if (!reply.WriteInt32(ret)) { + DHLOGE("HandleRegisterSessionStateCb write ret failed, ret = %d", ret); + return ERR_DH_INPUT_SRC_STUB_REGISTER_SESSION_STATE_FAIL; + } + + return DH_SUCCESS; +} + +int32_t DistributedInputSourceStub::HandleUnregisterSessionStateCb(MessageParcel &data, MessageParcel &reply) +{ + int32_t ret = UnregisterSessionStateCb(); + if (!reply.WriteInt32(ret)) { + DHLOGE("HandleUnregisterSessionStateCb write ret failed, ret = %d", ret); + return ERR_DH_INPUT_SRC_STUB_UNREGISTER_SESSION_STATE_FAIL; + } + + return DH_SUCCESS; +} + int32_t DistributedInputSourceStub::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { @@ -551,6 +578,12 @@ int32_t DistributedInputSourceStub::OnRemoteRequest( case static_cast(IDInputSourceInterfaceCode::SYNC_NODE_INFO_REMOTE_INPUT): { return HandleSyncNodeInfoRemoteInput(data, reply); } + case static_cast(IDInputSourceInterfaceCode::REGISTER_SESSION_STATE_CB): { + return HandleRegisterSessionStateCb(data, reply); + } + case static_cast(IDInputSourceInterfaceCode::UNREGISTER_SESSION_STATE_CB): { + return HandleUnregisterSessionStateCb(data, reply); + } default: return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } diff --git a/interfaces/ipc/src/register_session_state_callback_proxy.cpp b/interfaces/ipc/src/register_session_state_callback_proxy.cpp new file mode 100644 index 0000000..ff22cf6 --- /dev/null +++ b/interfaces/ipc/src/register_session_state_callback_proxy.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2023 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 "register_session_state_callback_proxy.h" + +#include "ipc_types.h" +#include "parcel.h" + +#include "dinput_log.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +RegisterSessionStateCallbackProxy::RegisterSessionStateCallbackProxy(const sptr &object) + : IRemoteProxy(object) +{ +} + +RegisterSessionStateCallbackProxy::~RegisterSessionStateCallbackProxy() +{ +} + +void RegisterSessionStateCallbackProxy::OnResult(const std::string &deviceId, const uint32_t &status) +{ + sptr remote = Remote(); + if (remote == nullptr) { + return; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + DHLOGE("RegisterSessionStateCallbackProxy write token valid failed"); + return; + } + if (!data.WriteString(deviceId)) { + return; + } + if (!data.WriteUint32(status)) { + return; + } + int32_t ret = remote->SendRequest( + static_cast(ISessionStateCallback::Message::RESULT), data, reply, option); + if (ret != 0) { + return; + } +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/ipc/src/register_session_state_callback_stub.cpp b/interfaces/ipc/src/register_session_state_callback_stub.cpp new file mode 100644 index 0000000..7455a66 --- /dev/null +++ b/interfaces/ipc/src/register_session_state_callback_stub.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2023 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 "register_session_state_callback_stub.h" + +#include "string_ex.h" + +#include "constants_dinput.h" +#include "dinput_errcode.h" +#include "dinput_log.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +RegisterSessionStateCallbackStub::RegisterSessionStateCallbackStub() +{ +} + +RegisterSessionStateCallbackStub::~RegisterSessionStateCallbackStub() +{ +} + +int32_t RegisterSessionStateCallbackStub::OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + if (data.ReadInterfaceToken() != GetDescriptor()) { + DHLOGE("RegisterSessionStateCallbackStub read token valid failed"); + return ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL; + } + ISessionStateCallback::Message msgCode = static_cast(code); + switch (msgCode) { + case ISessionStateCallback::Message::RESULT: { + std::string deviceId = data.ReadString(); + uint32_t status = data.ReadUint32(); + OnResult(deviceId, status); + break; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return DH_SUCCESS; +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/source/sourcemanager/BUILD.gn b/services/source/sourcemanager/BUILD.gn index 1ef4428..dc4a3b1 100644 --- a/services/source/sourcemanager/BUILD.gn +++ b/services/source/sourcemanager/BUILD.gn @@ -38,6 +38,7 @@ ohos_shared_library("libdinput_source") { "${fwk_interfaces_path}/include/ipc", "${distributedinput_path}/inputdevicehandler/include", "${distributedinput_path}/services/state/include", + "${distributedinput_path}/services/transportbase/include", ] sources = [ @@ -75,6 +76,8 @@ ohos_shared_library("libdinput_source") { "${ipc_path}/src/unprepare_d_input_call_back_stub.cpp", "${ipc_path}/src/unregister_d_input_call_back_proxy.cpp", "${ipc_path}/src/unregister_d_input_call_back_stub.cpp", + "${ipc_path}/src/register_session_state_callback_proxy.cpp", + "${ipc_path}/src/register_session_state_callback_stub.cpp", "src/distributed_input_source_event_handler.cpp", "src/distributed_input_source_manager.cpp", "src/distributed_input_source_sa_cli_mgr.cpp", @@ -92,6 +95,7 @@ ohos_shared_library("libdinput_source") { "${innerkits_path}:libdinput_sdk", "${services_source_path}/inputinject:libdinput_inject", "${services_source_path}/transport:libdinput_source_trans", + "${distributedinput_path}/services/transportbase:libdinput_trans_base", "${utils_path}:libdinput_utils", "//third_party/libevdev:libevdev", ] diff --git a/services/source/sourcemanager/include/distributed_input_source_manager.h b/services/source/sourcemanager/include/distributed_input_source_manager.h index d38ea60..9f1fdf3 100644 --- a/services/source/sourcemanager/include/distributed_input_source_manager.h +++ b/services/source/sourcemanager/include/distributed_input_source_manager.h @@ -178,6 +178,10 @@ public: const std::string &nodeDesc) override; int32_t RegisterSimulationEventListener(sptr listener) override; int32_t UnregisterSimulationEventListener(sptr listener) override; + + int32_t RegisterSessionStateCb(sptr callback) override; + int32_t UnregisterSessionStateCb() override; + bool CheckRegisterParam(const std::string &devId, const std::string &dhId, const std::string ¶meters, sptr callback); bool CheckUnregisterParam(const std::string &devId, const std::string &dhId, diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index f682e5d..cc17f94 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -40,6 +40,7 @@ #include "distributed_input_inject.h" #include "distributed_input_source_proxy.h" #include "distributed_input_source_transport.h" +#include "distributed_input_transport_base.h" #include "hisysevent_util.h" #include "hidumper.h" #include "input_check_param.h" @@ -2038,6 +2039,21 @@ int32_t DistributedInputSourceManager::UnregisterSimulationEventListener(sptr callback) +{ + if (callback == nullptr) { + DHLOGE("RegisterSessionStateCb callback is null."); + return ERR_DH_INPUT_CLIENT_UNREGISTER_SESSION_STATE_FAIL; + } + DistributedInputTransportBase::GetInstance().RegisterSessionStateCb(callback); + return DH_SUCCESS; +} +int32_t DistributedInputSourceManager::UnregisterSessionStateCb() +{ + DistributedInputTransportBase::GetInstance().UnregisterSessionStateCb(); + return DH_SUCCESS; +} + int32_t DistributedInputSourceManager::SyncNodeInfoRemoteInput(const std::string &userDevId, const std::string &dhId, const std::string &nodeDesc) { diff --git a/services/transportbase/include/distributed_input_transport_base.h b/services/transportbase/include/distributed_input_transport_base.h index e6eebfc..b67ac8b 100644 --- a/services/transportbase/include/distributed_input_transport_base.h +++ b/services/transportbase/include/distributed_input_transport_base.h @@ -32,6 +32,7 @@ #include "dinput_transbase_source_callback.h" #include "dinput_transbase_sink_callback.h" +#include "i_session_state_callback.h" namespace OHOS { namespace DistributedHardware { @@ -49,6 +50,10 @@ public: void RegisterSrcHandleSessionCallback(std::shared_ptr callback); void RegisterSinkHandleSessionCallback(std::shared_ptr callback); + void RegisterSessionStateCb(sptr callback); + void UnregisterSessionStateCb(); + void RunSessionStateCallback(const std::string &remoteDevId, const uint32_t &sessionState); + int32_t OnSessionOpened(int32_t sessionId, int32_t result); void OnSessionClosed(int32_t sessionId); void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen); @@ -79,6 +84,8 @@ private: std::shared_ptr srcCallback_; std::shared_ptr sinkCallback_; + + sptr SessionStateCallback_; }; } // namespace DistributedInput diff --git a/services/transportbase/src/distributed_input_transport_base.cpp b/services/transportbase/src/distributed_input_transport_base.cpp index bd29f77..14b46a4 100644 --- a/services/transportbase/src/distributed_input_transport_base.cpp +++ b/services/transportbase/src/distributed_input_transport_base.cpp @@ -51,6 +51,8 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { const int32_t DINPUT_LINK_TYPE_MAX = 4; +const int32_t SESSION_STATUS_OPENED = 0; +const int32_t SESSION_STATUS_CLOSED = 1; static SessionAttribute g_sessionAttr = { .dataType = SessionType::TYPE_BYTES, .linkTypeNum = DINPUT_LINK_TYPE_MAX, @@ -277,6 +279,29 @@ void DistributedInputTransportBase::RegisterSinkHandleSessionCallback( sinkCallback_ = callback; } +void DistributedInputTransportBase::RegisterSessionStateCb(sptr callback) +{ + DHLOGI("RegisterSessionStateCb"); + SessionStateCallback_ = callback; +} + +void DistributedInputTransportBase::UnregisterSessionStateCb() +{ + DHLOGI("UnregisterSessionStateCb"); + SessionStateCallback_ = nullptr; +} + +void DistributedInputTransportBase::RunSessionStateCallback(const std::string &remoteDevId, + const uint32_t &sessionState) +{ + DHLOGI("RunSessionStateCallback start."); + if (SessionStateCallback_ != nullptr) { + SessionStateCallback_->OnResult(remoteDevId, sessionState); + return; + } + DHLOGI("RunSessionStateCallback SessionStateCallback_ is null."); +} + int32_t DistributedInputTransportBase::CountSession(const std::string &remoteDevId) { return remoteDevSessionMap_.count(remoteDevId); @@ -339,7 +364,7 @@ int32_t DistributedInputTransportBase::OnSessionOpened(int32_t sessionId, int32_ channelStatusMap_[peerDevId] = true; openSessionWaitCond_.notify_all(); } - + RunSessionStateCallback(peerDevId, SESSION_STATUS_OPENED); return DH_SUCCESS; } @@ -347,6 +372,7 @@ void DistributedInputTransportBase::OnSessionClosed(int32_t sessionId) { std::string deviceId = GetDevIdBySessionId(sessionId); DHLOGI("OnSessionClosed, sessionId: %d, deviceId:%s", sessionId, GetAnonyString(deviceId).c_str()); + RunSessionStateCallback(deviceId, SESSION_STATUS_CLOSED); std::shared_ptr dhFwkKit = DInputContext::GetInstance().GetDHFwkKit(); if (dhFwkKit != nullptr) { -- Gitee