mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-19 17:43:35 -04:00
@@ -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 <string>
|
||||
|
||||
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
|
||||
@@ -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",
|
||||
|
||||
@@ -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<AppExecFwk::EventRunner> &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<DistributedInputSourceManager::DInputSourceListener> statuslistener_;
|
||||
std::shared_ptr<DistributedInputSourceManager::DInputSrcMgrListener> srcMgrListener_;
|
||||
|
||||
std::vector<DInputClientRegistInfo> regCallbacks_;
|
||||
std::vector<DInputClientUnregistInfo> unregCallbacks_;
|
||||
|
||||
@@ -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<DInputSourceListener>(this);
|
||||
DistributedInputSourceTransport::GetInstance().RegisterSourceRespCallback(statuslistener_);
|
||||
|
||||
srcMgrListener_ = std::make_shared<DInputSrcMgrListener>(this);
|
||||
DistributedInputTransportBase::GetInstance().RegisterSourceManagerCallback(srcMgrListener_);
|
||||
|
||||
serviceRunningState_ = ServiceSourceRunningState::STATE_RUNNING;
|
||||
|
||||
std::shared_ptr<DistributedHardwareFwkKit> dhFwkKit = DInputContext::GetInstance().GetDHFwkKit();
|
||||
@@ -2527,6 +2553,13 @@ uint32_t DistributedInputSourceManager::GetAllInputTypesMap()
|
||||
return rInputTypes;
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::ClearResourcesStatus()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
relayPreCallbacks_.clear();
|
||||
relayUnpreCallbacks_.clear();
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::SetInputTypesMap(const std::string deviceId, uint32_t value)
|
||||
{
|
||||
if (value == static_cast<uint32_t>(DInputDeviceType::NONE)) {
|
||||
|
||||
@@ -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<DInputTransbaseSourceCallback> callback);
|
||||
void RegisterSinkHandleSessionCallback(std::shared_ptr<DInputTransbaseSinkCallback> callback);
|
||||
void RegisterSourceManagerCallback(std::shared_ptr<DInputSourceManagerCallback> callback);
|
||||
|
||||
int32_t OnSessionOpened(int32_t sessionId, int32_t result);
|
||||
void OnSessionClosed(int32_t sessionId);
|
||||
@@ -79,6 +81,7 @@ private:
|
||||
|
||||
std::shared_ptr<DInputTransbaseSourceCallback> srcCallback_;
|
||||
std::shared_ptr<DInputTransbaseSinkCallback> sinkCallback_;
|
||||
std::shared_ptr<DInputSourceManagerCallback> srcMgrCallback_;
|
||||
};
|
||||
|
||||
} // namespace DistributedInput
|
||||
|
||||
@@ -277,6 +277,13 @@ void DistributedInputTransportBase::RegisterSinkHandleSessionCallback(
|
||||
sinkCallback_ = callback;
|
||||
}
|
||||
|
||||
void DistributedInputTransportBase::RegisterSourceManagerCallback(
|
||||
std::shared_ptr<DInputSourceManagerCallback> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user