diff --git a/common/include/dinput_errcode.h b/common/include/dinput_errcode.h index b19237e2f39cd2a27f85248316c8d6ffa0da792c..c02dc2823c182babe5ba990e36c51e9a532f8616 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 be71e68c37aad4a43d2b186a78442b961ee8eda5..e49f127d174ff72f50461f1222950f6ce298db3d 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 = 0xf01aU, + UNREGISTER_SESSION_STATE_CB = 0xf01bU, }; /* SAID: 4810 */ diff --git a/frameworks/include/i_distributed_source_input.h b/frameworks/include/i_distributed_source_input.h index 5df88433d659004d8de11c751fd6a5b0414eeff0..fbe654a81dd73ac7bfbb0e9f93a5f33dbbf322d3 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 0000000000000000000000000000000000000000..48b6d0b62cc4d3672bbb011e82058ceb98215b19 --- /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 8bb8c1f38f4360d9fb09389a2c4927a20846b5be..9ee637c8b72c03b0ca2048de146db28db590cbaa 100644 --- a/interfaces/inner_kits/BUILD.gn +++ b/interfaces/inner_kits/BUILD.gn @@ -12,8 +12,7 @@ # limitations under the License. import("//build/ohos.gni") -import( - "//foundation/distributedhardware/distributed_input/distributedinput.gni") +import("../../distributedinput.gni") config("input_sdk_public_config") { include_dirs = [ @@ -57,6 +56,8 @@ ohos_shared_library("libdinput_sdk") { "${ipc_path}/src/prepare_d_input_call_back_stub.cpp", "${ipc_path}/src/register_d_input_call_back_proxy.cpp", "${ipc_path}/src/register_d_input_call_back_stub.cpp", + "${ipc_path}/src/register_session_state_callback_proxy.cpp", + "${ipc_path}/src/register_session_state_callback_stub.cpp", "${ipc_path}/src/sharing_dhid_listener_proxy.cpp", "${ipc_path}/src/sharing_dhid_listener_stub.cpp", "${ipc_path}/src/simulation_event_listener_proxy.cpp", diff --git a/interfaces/inner_kits/include/distributed_input_kit.h b/interfaces/inner_kits/include/distributed_input_kit.h index 172a5e23353ef7f21917484256dba41ca01b6543..e0ec4399e50b4e7cb7afe51b8db31c54e4a08b50 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 6c88b714f8a513fcccd374d2e731dc1967b425b6..2cdd7741bfaba747acd866cb4c60b66eef2d86d8 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 cd0adfe81516cd21bd8fa5d2ae827698ca284d7a..c4449ec18454c7bf0c2972456e1624295d419b0e 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 13707117f6800ff310f1178eb6e74df8fd3cf840..4824e308cc8e8164d733fba3b6bbc7461bbee201 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 c79d918d699b05b55a69739802b825d71c538546..eca2be520b8a9ed7284564a58224350a53241861 100644 --- a/interfaces/ipc/include/distributed_input_source_stub.h +++ b/interfaces/ipc/include/distributed_input_source_stub.h @@ -59,6 +59,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 0000000000000000000000000000000000000000..41b4a111bad4a109fd94d51fb29c23fad26d1b33 --- /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 0000000000000000000000000000000000000000..2e4755b683e3e1bcd7ca5bf7b34b4fdd00c2ef5f --- /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 8b00a9d63c815e5d4481e33b7884c9d111f9fbd6..4b5ca096bb2993ff8ee73a847f257fca216d332b 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 c3274070beef74f3ce7d277b7fe7f1c9044da9ab..8bd4d5d01c68323c8041adcbf8c63e8f62912518 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 eaed63f723c3a0f7ae05fcfcbf5551287b9eb5b2..fc08cb902ce7791ec70d852ff4ad1f3e3e2969d8 100644 --- a/interfaces/ipc/src/distributed_input_source_stub.cpp +++ b/interfaces/ipc/src/distributed_input_source_stub.cpp @@ -77,6 +77,10 @@ void DistributedInputSourceStub::RegRespFunMap() &DistributedInputSourceStub::HandleUnregisterSimulationEventListener; memberFuncMap_[static_cast(IDInputSourceInterfaceCode::SYNC_NODE_INFO_REMOTE_INPUT)] = &DistributedInputSourceStub::HandleSyncNodeInfoRemoteInput; + memberFuncMap_[static_cast(IDInputSourceInterfaceCode::REGISTER_SESSION_STATE_CB)] = + &DistributedInputSourceStub::HandleRegisterSessionStateCb; + memberFuncMap_[static_cast(IDInputSourceInterfaceCode::UNREGISTER_SESSION_STATE_CB)] = + &DistributedInputSourceStub::HandleUnregisterSessionStateCb; } int32_t DistributedInputSourceStub::HandleInitDistributedHardware(MessageParcel &reply) { @@ -523,6 +527,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) { 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 0000000000000000000000000000000000000000..f2d6783c82c9688a40b1949800b6a416e8c3c9e4 --- /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 0000000000000000000000000000000000000000..7455a663f6c2e78a4abb307731bcb64fd17a5bde --- /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/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp index a8bcb509ac206e64053dab6111c123348664d9e0..121b29e7645d0322747aab70d72af6ddcc2021e7 100644 --- a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp +++ b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp @@ -239,6 +239,19 @@ int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::UnregisterSimula return DH_SUCCESS; } +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::RegisterSessionStateCb( + sptr callback) +{ + (void)callback; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::UnregisterSessionStateCb() +{ + return DH_SUCCESS; +} + + int32_t UnregisterSessionStateCb(); void DInputSourceCallBackTest::TestDInputSourceCallBackStub::OnResult(const std::string &deviceId, const std::string &strJson) { diff --git a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.h b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.h index b5305338f76e8e3cb25430e22f07a9af76a05ec6..115babd4018818d51db4960267eb434f8a66937a 100644 --- a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.h +++ b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.h @@ -33,6 +33,7 @@ #include "start_stop_d_inputs_call_back_stub.h" #include "start_stop_result_call_back_stub.h" #include "simulation_event_listener_stub.h" +#include "register_session_state_callback_stub.h" namespace OHOS { namespace DistributedHardware { @@ -104,6 +105,8 @@ public: const std::string &nodeDesc); int32_t RegisterSimulationEventListener(sptr listener); int32_t UnregisterSimulationEventListener(sptr listener); + int32_t RegisterSessionStateCb(sptr callback); + int32_t UnregisterSessionStateCb(); void OnResult(const std::string &deviceId, const std::string &strJson); std::string deviceId_; std::string strJson_; diff --git a/services/source/sourcemanager/BUILD.gn b/services/source/sourcemanager/BUILD.gn index ae0609f24922cfe20fa736ad433f402cfe9d147b..457afcb467e076e5d7600dfd68ffaf33ba753925 100644 --- a/services/source/sourcemanager/BUILD.gn +++ b/services/source/sourcemanager/BUILD.gn @@ -12,8 +12,7 @@ # limitations under the License. import("//build/ohos.gni") -import( - "//foundation/distributedhardware/distributed_input/distributedinput.gni") +import("../../../distributedinput.gni") ohos_shared_library("libdinput_source") { include_dirs = [ @@ -60,6 +59,8 @@ ohos_shared_library("libdinput_source") { "${ipc_path}/src/prepare_d_input_call_back_stub.cpp", "${ipc_path}/src/register_d_input_call_back_proxy.cpp", "${ipc_path}/src/register_d_input_call_back_stub.cpp", + "${ipc_path}/src/register_session_state_callback_proxy.cpp", + "${ipc_path}/src/register_session_state_callback_stub.cpp", "${ipc_path}/src/sharing_dhid_listener_proxy.cpp", "${ipc_path}/src/sharing_dhid_listener_stub.cpp", "${ipc_path}/src/simulation_event_listener_proxy.cpp", diff --git a/services/source/sourcemanager/include/distributed_input_source_manager.h b/services/source/sourcemanager/include/distributed_input_source_manager.h index a888addd895cf909ba38562073050f7207fa5782..b7913377e94228db79f5c9cdd57e75781bf60f7a 100644 --- a/services/source/sourcemanager/include/distributed_input_source_manager.h +++ b/services/source/sourcemanager/include/distributed_input_source_manager.h @@ -179,6 +179,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 452ca1d7c2c485312da47cd4d0f8d0bc982fd863..ab0839ce3bf2bda5c2279427871f5706e8321263 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -2064,6 +2064,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 4f560d6bcbb7ba8e67633d9d9acf3bb7564fc922..cfba4e7a90b623e3a8443d44f05144a9534fb208 100644 --- a/services/transportbase/include/distributed_input_transport_base.h +++ b/services/transportbase/include/distributed_input_transport_base.h @@ -33,6 +33,7 @@ #include "dinput_source_manager_callback.h" #include "dinput_transbase_source_callback.h" #include "dinput_transbase_sink_callback.h" +#include "i_session_state_callback.h" namespace OHOS { namespace DistributedHardware { @@ -50,7 +51,8 @@ public: void RegisterSrcHandleSessionCallback(std::shared_ptr callback); void RegisterSinkHandleSessionCallback(std::shared_ptr callback); void RegisterSourceManagerCallback(std::shared_ptr callback); - + void RegisterSessionStateCb(sptr callback); + void UnregisterSessionStateCb(); 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); @@ -67,6 +69,7 @@ private: bool CheckRecivedData(const std::string &message); void HandleSession(int32_t sessionId, const std::string &message); void Release(); + void RunSessionStateCallback(const std::string &remoteDevId, const uint32_t sessionState); private: std::atomic isSessSerCreateFlag_ = false; @@ -82,6 +85,7 @@ private: std::shared_ptr srcCallback_; std::shared_ptr sinkCallback_; std::shared_ptr srcMgrCallback_; + 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 db55e96d74430c7de1cf3721533f970229f1b995..49cf6073139ffdf01a629f97a878f111e3486606 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, @@ -284,6 +286,29 @@ void DistributedInputTransportBase::RegisterSourceManagerCallback( srcMgrCallback_ = 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); @@ -346,7 +371,7 @@ int32_t DistributedInputTransportBase::OnSessionOpened(int32_t sessionId, int32_ channelStatusMap_[peerDevId] = true; openSessionWaitCond_.notify_all(); } - + RunSessionStateCallback(peerDevId, SESSION_STATUS_OPENED); return DH_SUCCESS; } @@ -354,6 +379,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) {