diff --git a/services/common/include/dinput_source_manager_callback.h b/services/common/include/dinput_source_manager_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..feb89e43df55b922832b8ec0f28f22b251b62efe --- /dev/null +++ b/services/common/include/dinput_source_manager_callback.h @@ -0,0 +1,32 @@ +/* + * 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 DISTRIBUTED_SOURCE_MANAGER_CALLBACK_H +#define DISTRIBUTED_SOURCE_MANAGER_CALLBACK_H + +#include + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class DInputSourceManagerCallback { +public: + virtual void ResetSrcMgrResStatus() = 0; +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // DISTRIBUTED_SOURCE_MANAGER_CALLBACK_H diff --git a/services/source/sourcemanager/BUILD.gn b/services/source/sourcemanager/BUILD.gn index 1ef442860401210d8ca0a616ab582e2aa8cbc886..ae0609f24922cfe20fa736ad433f402cfe9d147b 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 = [ @@ -89,6 +90,7 @@ ohos_shared_library("libdinput_source") { deps = [ "${dfx_utils_path}:libdinput_dfx_utils", "${distributedinput_path}/services/state:libdinput_state", + "${distributedinput_path}/services/transportbase:libdinput_trans_base", "${innerkits_path}:libdinput_sdk", "${services_source_path}/inputinject:libdinput_inject", "${services_source_path}/transport:libdinput_source_trans", diff --git a/services/source/sourcemanager/include/distributed_input_source_manager.h b/services/source/sourcemanager/include/distributed_input_source_manager.h index d38ea606b04c79df5a3babfead30c2e2a00d567c..a888addd895cf909ba38562073050f7207fa5782 100644 --- a/services/source/sourcemanager/include/distributed_input_source_manager.h +++ b/services/source/sourcemanager/include/distributed_input_source_manager.h @@ -32,6 +32,7 @@ #include "constants_dinput.h" #include "dinput_context.h" +#include "dinput_source_manager_callback.h" #include "dinput_source_trans_callback.h" #include "distributed_input_node_manager.h" #include "distributed_input_source_event_handler.h" @@ -220,6 +221,15 @@ public: DistributedInputSourceManager *sourceManagerObj_; }; + class DInputSrcMgrListener : public DInputSourceManagerCallback { + public: + explicit DInputSrcMgrListener(DistributedInputSourceManager *manager); + virtual ~DInputSrcMgrListener(); + void ResetSrcMgrResStatus() override; + private: + DistributedInputSourceManager *sourceManagerObj_; + }; + class DInputSourceManagerEventHandler : public AppExecFwk::EventHandler { public: DInputSourceManagerEventHandler(const std::shared_ptr &runner, @@ -333,6 +343,7 @@ public: void SetInputTypesMap(const std::string deviceId, uint32_t value); uint32_t GetInputTypesMap(const std::string deviceId); uint32_t GetAllInputTypesMap(); + void ClearResourcesStatus(); private: struct DInputClientRegistInfo { @@ -427,6 +438,7 @@ private: ServiceSourceRunningState serviceRunningState_ = ServiceSourceRunningState::STATE_NOT_START; DInputServerType isStartTrans_ = DInputServerType::NULL_SERVER_TYPE; std::shared_ptr statuslistener_; + std::shared_ptr srcMgrListener_; std::vector regCallbacks_; std::vector unregCallbacks_; diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index f682e5d681277e256ae7da174e6011f0deca9c0c..452ca1d7c2c485312da47cd4d0f8d0bc982fd863 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" @@ -534,6 +535,28 @@ void DistributedInputSourceManager::DInputSourceListener::OnReceiveRelayStopType sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); } +DistributedInputSourceManager::DInputSrcMgrListener::DInputSrcMgrListener(DistributedInputSourceManager *manager) +{ + sourceManagerObj_ = manager; + DHLOGI("DInputSrcMgrListener init."); +} + +DistributedInputSourceManager::DInputSrcMgrListener::~DInputSrcMgrListener() +{ + sourceManagerObj_ = nullptr; + DHLOGI("DInputSrcMgrListener destory."); +} + +void DistributedInputSourceManager::DInputSrcMgrListener::ResetSrcMgrResStatus() +{ + DHLOGI("DInputSrcMgrListener ResetSrcMgrResStatus."); + if (sourceManagerObj_ == nullptr) { + DHLOGE("ResetSrcMgrResStatus sourceManagerObj is null."); + return; + } + sourceManagerObj_->ClearResourcesStatus(); +} + void DistributedInputSourceManager::OnStart() { if (serviceRunningState_ == ServiceSourceRunningState::STATE_RUNNING) { @@ -962,6 +985,9 @@ int32_t DistributedInputSourceManager::Init() statuslistener_ = std::make_shared(this); DistributedInputSourceTransport::GetInstance().RegisterSourceRespCallback(statuslistener_); + srcMgrListener_ = std::make_shared(this); + DistributedInputTransportBase::GetInstance().RegisterSourceManagerCallback(srcMgrListener_); + serviceRunningState_ = ServiceSourceRunningState::STATE_RUNNING; std::shared_ptr dhFwkKit = DInputContext::GetInstance().GetDHFwkKit(); @@ -2527,6 +2553,13 @@ uint32_t DistributedInputSourceManager::GetAllInputTypesMap() return rInputTypes; } +void DistributedInputSourceManager::ClearResourcesStatus() +{ + std::lock_guard lock(mutex_); + relayPreCallbacks_.clear(); + relayUnpreCallbacks_.clear(); +} + void DistributedInputSourceManager::SetInputTypesMap(const std::string deviceId, uint32_t value) { if (value == static_cast(DInputDeviceType::NONE)) { diff --git a/services/transportbase/include/distributed_input_transport_base.h b/services/transportbase/include/distributed_input_transport_base.h index e6eebfcbe9a27fec1d3c7c04188e41c554cb0027..4f560d6bcbb7ba8e67633d9d9acf3bb7564fc922 100644 --- a/services/transportbase/include/distributed_input_transport_base.h +++ b/services/transportbase/include/distributed_input_transport_base.h @@ -30,6 +30,7 @@ #include "nlohmann/json.hpp" #include "securec.h" +#include "dinput_source_manager_callback.h" #include "dinput_transbase_source_callback.h" #include "dinput_transbase_sink_callback.h" @@ -48,6 +49,7 @@ public: void RegisterSrcHandleSessionCallback(std::shared_ptr callback); void RegisterSinkHandleSessionCallback(std::shared_ptr callback); + void RegisterSourceManagerCallback(std::shared_ptr callback); int32_t OnSessionOpened(int32_t sessionId, int32_t result); void OnSessionClosed(int32_t sessionId); @@ -79,6 +81,7 @@ private: std::shared_ptr srcCallback_; std::shared_ptr sinkCallback_; + std::shared_ptr srcMgrCallback_; }; } // namespace DistributedInput diff --git a/services/transportbase/src/distributed_input_transport_base.cpp b/services/transportbase/src/distributed_input_transport_base.cpp index bd29f77f601a4161a51564ccf2c92d955babcba9..db55e96d74430c7de1cf3721533f970229f1b995 100644 --- a/services/transportbase/src/distributed_input_transport_base.cpp +++ b/services/transportbase/src/distributed_input_transport_base.cpp @@ -277,6 +277,13 @@ void DistributedInputTransportBase::RegisterSinkHandleSessionCallback( sinkCallback_ = callback; } +void DistributedInputTransportBase::RegisterSourceManagerCallback( + std::shared_ptr callback) +{ + DHLOGI("RegisterSourceManagerCallback"); + srcMgrCallback_ = callback; +} + int32_t DistributedInputTransportBase::CountSession(const std::string &remoteDevId) { return remoteDevSessionMap_.count(remoteDevId); @@ -372,6 +379,12 @@ void DistributedInputTransportBase::OnSessionClosed(int32_t sessionId) return; } srcCallback_->NotifySessionClosed(); + + if (srcMgrCallback_ == nullptr) { + DHLOGE("srcMgrCallback is nullptr."); + return; + } + srcMgrCallback_->ResetSrcMgrResStatus(); } }