mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-20 21:41:02 -04:00
Description:fix full-duplex session
Match-id-e1e364652cce610b42c19ef3a81f40c5f81de1d7
This commit is contained in:
@@ -56,6 +56,7 @@
|
||||
"//foundation/distributedhardware/distributed_input/services/sink/sinkmanager:libdinput_sink",
|
||||
"//foundation/distributedhardware/distributed_input/services/sink/transport:libdinput_sink_trans",
|
||||
"//foundation/distributedhardware/distributed_input/services/sink/inputcollector:libdinput_collector",
|
||||
"//foundation/distributedhardware/distributed_input/services/transportbase:libdinput_trans_base",
|
||||
"//foundation/distributedhardware/distributed_input/sourcehandler:libdinput_source_handler",
|
||||
"//foundation/distributedhardware/distributed_input/sinkhandler:libdinput_sink_handler",
|
||||
"//foundation/distributedhardware/distributed_input/inputdevicehandler:libdinput_handler",
|
||||
|
||||
@@ -42,8 +42,7 @@ namespace DistributedInput {
|
||||
const uint32_t INTERCEPT_STRING_LENGTH = 20;
|
||||
|
||||
const std::string DINPUT_PKG_NAME = "ohos.dhardware.dinput";
|
||||
const std::string SESSION_NAME_SOURCE = "ohos.dhardware.dinput.so_";
|
||||
const std::string SESSION_NAME_SINK = "ohos.dhardware.dinput.si_";
|
||||
const std::string SESSION_NAME = "ohos.dhardware.dinput.session";
|
||||
const std::string GROUP_ID = "input_softbus_group_id";
|
||||
|
||||
#define DINPUT_SOFTBUS_KEY_CMD_TYPE "dinput_softbus_key_cmd_type"
|
||||
@@ -61,7 +60,7 @@ namespace DistributedInput {
|
||||
#define DINPUT_SOFTBUS_KEY_SRC_DEV_ID "dinput_softbus_key_src_dev_id"
|
||||
#define DINPUT_SOFTBUS_KEY_SINK_DEV_ID "dinput_softbus_key_sink_dev_id"
|
||||
|
||||
// json value
|
||||
// src will receive
|
||||
const uint32_t TRANS_SINK_MSG_ONPREPARE = 1;
|
||||
const uint32_t TRANS_SINK_MSG_ONUNPREPARE = 2;
|
||||
const uint32_t TRANS_SINK_MSG_ONSTART = 3;
|
||||
@@ -71,45 +70,42 @@ namespace DistributedInput {
|
||||
const uint32_t TRANS_SINK_MSG_DHID_ONSTART = 7;
|
||||
const uint32_t TRANS_SINK_MSG_DHID_ONSTOP = 8;
|
||||
const uint32_t TRANS_SINK_MSG_KEY_STATE = 9;
|
||||
// A device is sinkdev, B device is source
|
||||
const uint32_t TRANS_SINK_MSG_ON_RELAY_PREPARE = 50; // A sink send prepare result to B souce
|
||||
const uint32_t TRANS_SINK_MSG_ON_RELAY_UNPREPARE = 51;
|
||||
const uint32_t TRANS_SINK_MSG_ON_RELAY_STARTDHID = 52;
|
||||
const uint32_t TRANS_SINK_MSG_ON_RELAY_STOPDHID = 53;
|
||||
const uint32_t TRANS_SINK_MSG_ON_RELAY_STARTTYPE = 54;
|
||||
const uint32_t TRANS_SINK_MSG_ON_RELAY_STOPTYPE = 55;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_PREPARE = 10;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_UNPREPARE = 11;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_PREPARE_RESULT = 12;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_UNPREPARE_RESULT = 13;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_START_DHID = 14;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_STOP_DHID = 15;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_START_DHID_RESULT = 16;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_STOP_DHID_RESULT = 17;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_START_TYPE = 18;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_STOP_TYPE = 19;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_START_TYPE_RESULT = 20;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_STOP_TYPE_RESULT = 21;
|
||||
const uint32_t TRANS_SINK_MSG_ON_RELAY_PREPARE = 22;
|
||||
const uint32_t TRANS_SINK_MSG_ON_RELAY_UNPREPARE = 23;
|
||||
const uint32_t TRANS_SINK_MSG_ON_RELAY_STARTDHID = 24;
|
||||
const uint32_t TRANS_SINK_MSG_ON_RELAY_STOPDHID = 25;
|
||||
const uint32_t TRANS_SINK_MSG_ON_RELAY_STARTTYPE = 26;
|
||||
const uint32_t TRANS_SINK_MSG_ON_RELAY_STOPTYPE = 27;
|
||||
|
||||
const uint32_t TRANS_SOURCE_MSG_PREPARE = 11;
|
||||
const uint32_t TRANS_SOURCE_MSG_UNPREPARE = 12;
|
||||
const uint32_t TRANS_SOURCE_MSG_START_TYPE = 13;
|
||||
const uint32_t TRANS_SOURCE_MSG_STOP_TYPE = 14;
|
||||
const uint32_t TRANS_SOURCE_MSG_START_DHID = 15;
|
||||
const uint32_t TRANS_SOURCE_MSG_STOP_DHID = 16;
|
||||
// A mmi call prepare, A souce will relay prepare to B source
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_PREPARE = 17;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_UNPREPARE = 18;
|
||||
// B source relay send prepare to A sink
|
||||
const uint32_t TRANS_SOURCE_MSG_PREPARE_FOR_REL = 19;
|
||||
const uint32_t TRANS_SOURCE_MSG_UNPREPARE_FOR_REL = 20;
|
||||
// B source receive A sink result,then notify A source result
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_PREPARE_RESULT = 21;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_UNPREPARE_RESULT = 22;
|
||||
// src or sink
|
||||
const uint32_t TRANS_MSG_SRC_SINK_SPLIT = 30;
|
||||
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_START_DHID = 23;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_STOP_DHID = 24;
|
||||
const uint32_t TRANS_SOURCE_MSG_START_DHID_FOR_REL = 25;
|
||||
const uint32_t TRANS_SOURCE_MSG_STOP_DHID_FOR_REL = 26;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_START_DHID_RESULT = 27;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_STOP_DHID_RESULT = 28;
|
||||
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_START_TYPE = 29;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_STOP_TYPE = 30;
|
||||
const uint32_t TRANS_SOURCE_MSG_START_TYPE_FOR_REL = 31;
|
||||
const uint32_t TRANS_SOURCE_MSG_STOP_TYPE_FOR_REL = 32;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_START_TYPE_RESULT = 33;
|
||||
const uint32_t TRANS_SOURCE_TO_SOURCE_MSG_STOP_TYPE_RESULT = 34;
|
||||
|
||||
const uint32_t TRANS_SOURCE_MSG_LATENCY = 40;
|
||||
// sink will receive
|
||||
const uint32_t TRANS_SOURCE_MSG_PREPARE = 31;
|
||||
const uint32_t TRANS_SOURCE_MSG_UNPREPARE = 32;
|
||||
const uint32_t TRANS_SOURCE_MSG_START_TYPE = 33;
|
||||
const uint32_t TRANS_SOURCE_MSG_STOP_TYPE = 34;
|
||||
const uint32_t TRANS_SOURCE_MSG_START_DHID = 35;
|
||||
const uint32_t TRANS_SOURCE_MSG_STOP_DHID = 36;
|
||||
const uint32_t TRANS_SOURCE_MSG_LATENCY = 37;
|
||||
const uint32_t TRANS_SOURCE_MSG_START_DHID_FOR_REL = 38;
|
||||
const uint32_t TRANS_SOURCE_MSG_STOP_DHID_FOR_REL = 39;
|
||||
const uint32_t TRANS_SOURCE_MSG_START_TYPE_FOR_REL = 40;
|
||||
const uint32_t TRANS_SOURCE_MSG_STOP_TYPE_FOR_REL = 41;
|
||||
const uint32_t TRANS_SOURCE_MSG_PREPARE_FOR_REL = 42;
|
||||
const uint32_t TRANS_SOURCE_MSG_UNPREPARE_FOR_REL = 43;
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -25,19 +25,22 @@ class DInputSourceTransCallback {
|
||||
public:
|
||||
virtual void onResponseRegisterDistributedHardware(const std::string deviceId, const std::string dhId,
|
||||
bool result) = 0;
|
||||
virtual void onResponsePrepareRemoteInput(const std::string deviceId, bool result, const std::string &object) = 0;
|
||||
virtual void onResponsePrepareRemoteInput(const std::string deviceId, bool result) = 0;
|
||||
virtual void onResponseUnprepareRemoteInput(const std::string deviceId, bool result) = 0;
|
||||
virtual void onResponseStartRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result) = 0;
|
||||
virtual void onResponseStartRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result,
|
||||
const std::string& object) = 0;
|
||||
virtual void onResponseStopRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result) = 0;
|
||||
virtual void onResponseStartRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result) = 0;
|
||||
virtual void onResponseStartRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result,
|
||||
const std::string& object) = 0;
|
||||
virtual void onResponseStopRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result) = 0;
|
||||
virtual void onResponseKeyState(const std::string deviceId, const std::string &dhid, const uint32_t type,
|
||||
const uint32_t code, const uint32_t value) = 0;
|
||||
virtual void onReceivedEventRemoteInput(const std::string deviceId, const std::string &object) = 0;
|
||||
|
||||
virtual void onResponseRelayPrepareRemoteInput(int32_t sessionId, const std::string &deviceId, bool result,
|
||||
const std::string &object) = 0;
|
||||
virtual void onResponseRelayPrepareRemoteInput(int32_t sessionId, const std::string &deviceId, bool result) = 0;
|
||||
virtual void onResponseRelayUnprepareRemoteInput(int32_t sessionId, const std::string &deviceId, bool result) = 0;
|
||||
virtual void onResponseRelayStartDhidRemoteInput(const std::string &deviceId, const std::string &object) = 0;
|
||||
virtual void onResponseRelayStartTypeRemoteInput(const std::string &deviceId, const std::string &object) = 0;
|
||||
|
||||
virtual void onReceiveRelayPrepareResult(int32_t status, const std::string &srcId, const std::string &sinkId) = 0;
|
||||
virtual void onReceiveRelayUnprepareResult(int32_t status, const std::string &srcId, const std::string &sinkId) = 0;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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_INPUT_TRANSBASE_SINK_H
|
||||
#define DISTRIBUTED_INPUT_TRANSBASE_SINK_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class DInputTransbaseSinkCallback {
|
||||
public:
|
||||
virtual void HandleSessionData(int32_t sessionId, const std::string& messageData) = 0;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // DISTRIBUTED_INPUT_TRANSBASE_SINK_H
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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_INPUT_TRANSBASE_SOURCE_H
|
||||
#define DISTRIBUTED_INPUT_TRANSBASE_SOURCE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class DInputTransbaseSourceCallback {
|
||||
public:
|
||||
virtual void HandleSessionData(int32_t sessionId, const std::string& messageData) = 0;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // DISTRIBUTED_INPUT_TRANSBASE_SOURCE_H
|
||||
@@ -76,7 +76,7 @@ bool DistributedInputCollector::InitCollectEventsThread()
|
||||
collectThreadID_ = -1;
|
||||
int32_t ret = pthread_create(&collectThreadID_, &attr, CollectEventsThread, this);
|
||||
if (ret != 0) {
|
||||
DHLOGE("DistributedInputCollector::InitCollectEventsThread create thread failed:%d \n", ret);
|
||||
DHLOGE("DistributedInputCollector::InitCollectEventsThread create thread failed:%d \n", ret);
|
||||
pthread_attr_destroy(&attr);
|
||||
collectThreadID_ = -1;
|
||||
isCollectingEvents_ = false;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "singleton.h"
|
||||
#include "system_ability.h"
|
||||
#include "system_ability_status_change_stub.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_sink_trans_callback.h"
|
||||
@@ -48,6 +49,8 @@ class DistributedInputSinkManager : public SystemAbility, public DistributedInpu
|
||||
DECLARE_SYSTEM_ABILITY(DistributedInputSinkManager)
|
||||
|
||||
public:
|
||||
static DistributedInputSinkManager &GetInstance();
|
||||
DistributedInputSinkManager() = default;
|
||||
DistributedInputSinkManager(int32_t saId, bool runOnCreate);
|
||||
~DistributedInputSinkManager();
|
||||
|
||||
@@ -153,6 +156,8 @@ public:
|
||||
|
||||
int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
|
||||
|
||||
void AddWhiteList(nlohmann::json &jsonStr);
|
||||
|
||||
private:
|
||||
void CleanExceptionalInfo(const SrcScreenInfo& srcScreenInfo);
|
||||
void CallBackScreenInfoChange();
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "distributed_hardware_log.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "screen_manager.h"
|
||||
#include "string_ex.h"
|
||||
#include "system_ability_definition.h"
|
||||
@@ -60,6 +59,12 @@ DistributedInputSinkManager::~DistributedInputSinkManager()
|
||||
projectWindowListener_ = nullptr;
|
||||
}
|
||||
|
||||
DistributedInputSinkManager &DistributedInputSinkManager::GetInstance()
|
||||
{
|
||||
static DistributedInputSinkManager instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
DistributedInputSinkManager::DInputSinkListener::DInputSinkListener(DistributedInputSinkManager *manager)
|
||||
{
|
||||
sinkManagerObj_ = manager;
|
||||
@@ -74,6 +79,28 @@ DistributedInputSinkManager::DInputSinkListener::~DInputSinkListener()
|
||||
DHLOGI("DInputSinkListener destory.");
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::AddWhiteList(nlohmann::json &jsonStr)
|
||||
{
|
||||
TYPE_WHITE_LIST_VEC vecFilter;
|
||||
std::string localNetworkId = GetLocalDeviceInfo().networkId;
|
||||
if (!localNetworkId.empty()) {
|
||||
WhiteListUtil::GetInstance().GetWhiteList(localNetworkId, vecFilter);
|
||||
} else {
|
||||
DHLOGE("query local network id from softbus failed");
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_WHITE_LIST] = "";
|
||||
return;
|
||||
}
|
||||
|
||||
if (vecFilter.empty() || vecFilter[0].empty() || vecFilter[0][0].empty()) {
|
||||
DHLOGE("onStartRemoteInput called, white list is null.");
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_WHITE_LIST] = "";
|
||||
return;
|
||||
}
|
||||
nlohmann::json filterMsg(vecFilter);
|
||||
std::string object = filterMsg.dump();
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_WHITE_LIST] = object;
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::DInputSinkListener::onPrepareRemoteInput(
|
||||
const int32_t& sessionId, const std::string &deviceId)
|
||||
{
|
||||
@@ -81,41 +108,8 @@ void DistributedInputSinkManager::DInputSinkListener::onPrepareRemoteInput(
|
||||
|
||||
nlohmann::json jsonStr;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONPREPARE;
|
||||
std::string smsg = "";
|
||||
int ret = DistributedInputCollector::GetInstance().Init(
|
||||
DistributedInputSinkTransport::GetInstance().GetEventHandler());
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("DInputSinkListener init InputCollector error.");
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = false;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_WHITE_LIST] = "";
|
||||
smsg = jsonStr.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespPrepareRemoteInput(sessionId, smsg);
|
||||
return;
|
||||
}
|
||||
|
||||
DistributedInputSinkSwitch::GetInstance().AddSession(sessionId);
|
||||
|
||||
// send prepare result and if result ok, send white list
|
||||
TYPE_WHITE_LIST_VEC vecFilter;
|
||||
std::string localNetworkId = GetLocalDeviceInfo().networkId;
|
||||
if (!localNetworkId.empty()) {
|
||||
WhiteListUtil::GetInstance().GetWhiteList(localNetworkId, vecFilter);
|
||||
} else {
|
||||
DHLOGE("query local network id from softbus failed");
|
||||
}
|
||||
if (vecFilter.empty() || vecFilter[0].empty() || vecFilter[0][0].empty()) {
|
||||
DHLOGE("onPrepareRemoteInput called, white list is null.");
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_WHITE_LIST] = "";
|
||||
smsg = jsonStr.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespPrepareRemoteInput(sessionId, smsg);
|
||||
return;
|
||||
}
|
||||
nlohmann::json filterMsg(vecFilter);
|
||||
std::string object = filterMsg.dump();
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_WHITE_LIST] = object;
|
||||
smsg = jsonStr.dump();
|
||||
std::string smsg = jsonStr.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespPrepareRemoteInput(sessionId, smsg);
|
||||
}
|
||||
|
||||
@@ -123,7 +117,6 @@ void DistributedInputSinkManager::DInputSinkListener::onUnprepareRemoteInput(con
|
||||
{
|
||||
DHLOGI("onUnprepareRemoteInput called, sessionId: %d", sessionId);
|
||||
onStopRemoteInput(sessionId, static_cast<uint32_t>(DInputDeviceType::ALL));
|
||||
DistributedInputSinkSwitch::GetInstance().RemoveSession(sessionId);
|
||||
|
||||
nlohmann::json jsonStr;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONUNPREPARE;
|
||||
@@ -135,56 +128,23 @@ void DistributedInputSinkManager::DInputSinkListener::onUnprepareRemoteInput(con
|
||||
void DistributedInputSinkManager::DInputSinkListener::onRelayPrepareRemoteInput(const int32_t &toSrcSessionId,
|
||||
const int32_t &toSinkSessionId, const std::string &deviceId)
|
||||
{
|
||||
DHLOGI("toSinkSessionId: %s, devId: %s", GetAnonyInt32(toSinkSessionId).c_str(), GetAnonyString(deviceId).c_str());
|
||||
DHLOGI("onRelayPrepareRemoteInput called, toSinkSessionId: %d, devId: %s", toSinkSessionId,
|
||||
GetAnonyString(deviceId).c_str());
|
||||
|
||||
nlohmann::json jsonStr;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ON_RELAY_PREPARE;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = toSrcSessionId;
|
||||
std::string smsg = "";
|
||||
int ret = DistributedInputCollector::GetInstance().Init(
|
||||
DistributedInputSinkTransport::GetInstance().GetEventHandler());
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("DInputSinkListener init InputCollector error.");
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = false;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_WHITE_LIST] = "";
|
||||
smsg = jsonStr.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespPrepareRemoteInput(toSinkSessionId, smsg);
|
||||
return;
|
||||
}
|
||||
|
||||
DistributedInputSinkSwitch::GetInstance().AddSession(toSinkSessionId);
|
||||
|
||||
// send prepare result and if result ok, send white list
|
||||
TYPE_WHITE_LIST_VEC vecFilter;
|
||||
std::string localNetworkId = GetLocalNetworkId();
|
||||
if (!localNetworkId.empty()) {
|
||||
WhiteListUtil::GetInstance().GetWhiteList(localNetworkId, vecFilter);
|
||||
} else {
|
||||
DHLOGE("query local network id from softbus failed");
|
||||
}
|
||||
if (vecFilter.empty() || vecFilter[0].empty() || vecFilter[0][0].empty()) {
|
||||
DHLOGE("white list is null.");
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_WHITE_LIST] = "";
|
||||
smsg = jsonStr.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespPrepareRemoteInput(toSinkSessionId, smsg);
|
||||
return;
|
||||
}
|
||||
nlohmann::json filterMsg(vecFilter);
|
||||
std::string object = filterMsg.dump();
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_WHITE_LIST] = object;
|
||||
smsg = jsonStr.dump();
|
||||
std::string smsg = jsonStr.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespPrepareRemoteInput(toSinkSessionId, smsg);
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::DInputSinkListener::onRelayUnprepareRemoteInput(const int32_t &toSrcSessionId,
|
||||
const int32_t &toSinkSessionId, const std::string &deviceId)
|
||||
{
|
||||
DHLOGI("toSinkSessionId: %d, devId: %s", toSinkSessionId, GetAnonyString(deviceId).c_str());
|
||||
DistributedInputCollector::GetInstance().SetSharingTypes(false, static_cast<uint32_t>(DInputDeviceType::ALL));
|
||||
DistributedInputSinkSwitch::GetInstance().StopAllSwitch();
|
||||
DistributedInputSinkSwitch::GetInstance().RemoveSession(toSinkSessionId);
|
||||
DHLOGI("onRelayUnprepareRemoteInput called, toSinkSessionId: %d, devId: %s", toSinkSessionId,
|
||||
GetAnonyString(deviceId).c_str());
|
||||
onStopRemoteInput(toSrcSessionId, static_cast<uint32_t>(DInputDeviceType::ALL));
|
||||
|
||||
nlohmann::json jsonStr;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ON_RELAY_UNPREPARE;
|
||||
@@ -197,41 +157,57 @@ void DistributedInputSinkManager::DInputSinkListener::onRelayUnprepareRemoteInpu
|
||||
void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInput(
|
||||
const int32_t& sessionId, const uint32_t& inputTypes)
|
||||
{
|
||||
int32_t curSessionId = DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession();
|
||||
DHLOGI("onStartRemoteInput called, cursessionId: %d, new sessionId: %d", curSessionId, sessionId);
|
||||
// set new session
|
||||
int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(sessionId);
|
||||
|
||||
sinkManagerObj_->SetStartTransFlag((startRes == DH_SUCCESS) ? DInputServerType::SINK_SERVER_TYPE
|
||||
: DInputServerType::NULL_SERVER_TYPE);
|
||||
|
||||
bool result = (startRes == DH_SUCCESS) ? true : false;
|
||||
nlohmann::json jsonStrSta;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONSTART;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_RESP_VALUE] = result;
|
||||
std::string smsgSta = jsonStrSta.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsgSta);
|
||||
|
||||
// add the input type
|
||||
if (startRes == DH_SUCCESS) {
|
||||
sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() | inputTypes);
|
||||
AffectDhIds affDhIds = DistributedInputCollector::GetInstance().SetSharingTypes(true,
|
||||
sinkManagerObj_->GetInputTypes());
|
||||
sinkManagerObj_->StoreStartDhids(sessionId, affDhIds.sharingDhIds);
|
||||
DistributedInputCollector::GetInstance().ReportDhIdSharingState(affDhIds);
|
||||
DHLOGI("onStartRemoteInput called, sessionId: %d, inputTypes: %u.", sessionId, inputTypes);
|
||||
if (sinkManagerObj_ == nullptr) {
|
||||
DHLOGE("sinkManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t ret = DistributedInputCollector::GetInstance().Init(
|
||||
DistributedInputSinkTransport::GetInstance().GetEventHandler());
|
||||
nlohmann::json jsonStrSta;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONSTART;
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("DInputSinkListener init InputCollector error.");
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_RESP_VALUE] = false;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_WHITE_LIST] = "";
|
||||
std::string smsg = jsonStrSta.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsg);
|
||||
return;
|
||||
}
|
||||
DistributedInputSinkManager::GetInstance().AddWhiteList(jsonStrSta);
|
||||
DistributedInputSinkSwitch::GetInstance().AddSession(sessionId);
|
||||
int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(sessionId);
|
||||
sinkManagerObj_->SetStartTransFlag((startRes == DH_SUCCESS) ? DInputServerType::SINK_SERVER_TYPE
|
||||
: DInputServerType::NULL_SERVER_TYPE);
|
||||
bool result = (startRes == DH_SUCCESS);
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_RESP_VALUE] = result;
|
||||
std::string smsg = jsonStrSta.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsg);
|
||||
|
||||
if (startRes != DH_SUCCESS) {
|
||||
DHLOGE("onStartRemoteInput startSwitch error.");
|
||||
return;
|
||||
}
|
||||
|
||||
sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() | inputTypes);
|
||||
AffectDhIds affDhIds = DistributedInputCollector::GetInstance().SetSharingTypes(true,
|
||||
sinkManagerObj_->GetInputTypes());
|
||||
sinkManagerObj_->StoreStartDhids(sessionId, affDhIds.sharingDhIds);
|
||||
DistributedInputCollector::GetInstance().ReportDhIdSharingState(affDhIds);
|
||||
|
||||
bool isMouse = (sinkManagerObj_->GetInputTypes() & static_cast<uint32_t>(DInputDeviceType::MOUSE)) != 0;
|
||||
if (isMouse) {
|
||||
std::map<int32_t, std::string> deviceInfos;
|
||||
DistributedInputCollector::GetInstance().GetDeviceInfoByType(static_cast<uint32_t>(DInputDeviceType::MOUSE),
|
||||
deviceInfos);
|
||||
for (auto deviceInfo : deviceInfos) {
|
||||
DHLOGI("deviceInfo dhId, %s", GetAnonyString(deviceInfo.second).c_str());
|
||||
std::thread(&DistributedInputSinkManager::DInputSinkListener::CheckKeyState, this, sessionId,
|
||||
deviceInfo.second).detach();
|
||||
}
|
||||
if (!isMouse) {
|
||||
return;
|
||||
}
|
||||
std::map<int32_t, std::string> deviceInfos;
|
||||
DistributedInputCollector::GetInstance().GetDeviceInfoByType(static_cast<uint32_t>(DInputDeviceType::MOUSE),
|
||||
deviceInfos);
|
||||
for (auto deviceInfo : deviceInfos) {
|
||||
DHLOGI("deviceInfo dhId, %s", GetAnonyString(deviceInfo.second).c_str());
|
||||
std::thread(&DistributedInputSinkManager::DInputSinkListener::CheckKeyState, this, sessionId,
|
||||
deviceInfo.second).detach();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,6 +216,10 @@ void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInput(
|
||||
{
|
||||
DHLOGI("onStopRemoteInput called, sessionId: %d, inputTypes: %d, curInputTypes: %d",
|
||||
sessionId, inputTypes, sinkManagerObj_->GetInputTypes());
|
||||
if (sinkManagerObj_ == nullptr) {
|
||||
DHLOGE("sinkManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() -
|
||||
(sinkManagerObj_->GetInputTypes() & inputTypes));
|
||||
@@ -266,48 +246,63 @@ void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInput(
|
||||
sinkManagerObj_->SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE);
|
||||
}
|
||||
}
|
||||
DistributedInputSinkSwitch::GetInstance().RemoveSession(sessionId);
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInputDhid(const int32_t &sessionId,
|
||||
const std::string &strDhids)
|
||||
{
|
||||
int32_t curSessionId = DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession();
|
||||
DHLOGE("onStartRemoteInputDhid called, cursessionId: %d, new sessionId: %d",
|
||||
curSessionId, sessionId);
|
||||
// set new session
|
||||
int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(sessionId);
|
||||
bool result = (startRes == DH_SUCCESS) ? true : false;
|
||||
DHLOGI("onStartRemoteInputDhid called, : sessionId: %d", sessionId);
|
||||
if (sinkManagerObj_ == nullptr) {
|
||||
DHLOGE("sinkManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t ret = DistributedInputCollector::GetInstance().Init(
|
||||
DistributedInputSinkTransport::GetInstance().GetEventHandler());
|
||||
nlohmann::json jsonStrSta;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_DHID_ONSTART;
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("DInputSinkListener init InputCollector error.");
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_RESP_VALUE] = false;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_WHITE_LIST] = "";
|
||||
std::string smsg = jsonStrSta.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsg);
|
||||
return;
|
||||
}
|
||||
|
||||
DistributedInputSinkManager::GetInstance().AddWhiteList(jsonStrSta);
|
||||
DistributedInputSinkSwitch::GetInstance().AddSession(sessionId);
|
||||
int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(sessionId);
|
||||
bool result = (startRes == DH_SUCCESS);
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = strDhids;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_RESP_VALUE] = result;
|
||||
std::string smsgSta = jsonStrSta.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsgSta);
|
||||
std::string smsg = jsonStrSta.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsg);
|
||||
|
||||
if (startRes != DH_SUCCESS) {
|
||||
DHLOGE("onStartRemoteInputDhid StartSwitch error.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (curSessionId == ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL) {
|
||||
DHLOGW("onStartRemoteInputDhid called, this is the only session.");
|
||||
}
|
||||
|
||||
std::thread(&DistributedInputSinkManager::DInputSinkListener::CheckKeyState, this, sessionId, strDhids).detach();
|
||||
// add the dhids
|
||||
if (startRes == DH_SUCCESS) {
|
||||
std::vector<std::string> vecStr;
|
||||
StringSplit(strDhids, INPUT_STRING_SPLIT_POINT, vecStr);
|
||||
AffectDhIds affDhIds = DistributedInputCollector::GetInstance().SetSharingDhIds(true, vecStr);
|
||||
sinkManagerObj_->StoreStartDhids(sessionId, affDhIds.sharingDhIds);
|
||||
DistributedInputCollector::GetInstance().ReportDhIdSharingState(affDhIds);
|
||||
}
|
||||
|
||||
std::vector<std::string> vecStr;
|
||||
StringSplit(strDhids, INPUT_STRING_SPLIT_POINT, vecStr);
|
||||
AffectDhIds affDhIds = DistributedInputCollector::GetInstance().SetSharingDhIds(true, vecStr);
|
||||
sinkManagerObj_->StoreStartDhids(sessionId, affDhIds.sharingDhIds);
|
||||
DistributedInputCollector::GetInstance().ReportDhIdSharingState(affDhIds);
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInputDhid(const int32_t &sessionId,
|
||||
const std::string &strDhids)
|
||||
{
|
||||
DHLOGI("onStopRemoteInputDhid called, sessionId: %d", sessionId);
|
||||
if (sinkManagerObj_ == nullptr) {
|
||||
DHLOGE("sinkManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string> stopIndeedDhIds;
|
||||
std::vector<std::string> stopOnCmdDhIds;
|
||||
StringSplit(strDhids, INPUT_STRING_SPLIT_POINT, stopOnCmdDhIds);
|
||||
@@ -335,54 +330,69 @@ void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInputDhid(cons
|
||||
sinkManagerObj_->SetInputTypes(static_cast<uint32_t>(DInputDeviceType::NONE));
|
||||
if (DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession() ==
|
||||
ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL) {
|
||||
DHLOGI("all session is stop.");
|
||||
DHLOGI("onStartRemoteInput called, all session is stop.");
|
||||
sinkManagerObj_->SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE);
|
||||
}
|
||||
}
|
||||
DistributedInputSinkSwitch::GetInstance().RemoveSession(sessionId);
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::DInputSinkListener::onRelayStartDhidRemoteInput(const int32_t &toSrcSessionId,
|
||||
const int32_t &toSinkSessionId, const std::string &deviceId, const std::string &strDhids)
|
||||
{
|
||||
int32_t curSessionId = DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession();
|
||||
DHLOGI("curSessionId:%s, new sessionId: %s", GetAnonyInt32(curSessionId).c_str(),
|
||||
GetAnonyInt32(toSinkSessionId).c_str());
|
||||
// set new session
|
||||
int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(toSinkSessionId);
|
||||
bool result = (startRes == DH_SUCCESS) ? true : false;
|
||||
nlohmann::json jsonStrSta;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ON_RELAY_STARTDHID;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_SESSION_ID] = toSrcSessionId;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = strDhids;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_RESP_VALUE] = result;
|
||||
std::string smsgSta = jsonStrSta.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(toSinkSessionId, smsgSta);
|
||||
|
||||
if (startRes != DH_SUCCESS) {
|
||||
DHLOGE("StartSwitch error.");
|
||||
DHLOGI("onRelayStartDhidRemoteInput called, toSinkSessionId: %d", toSinkSessionId);
|
||||
if (sinkManagerObj_ == nullptr) {
|
||||
DHLOGE("sinkManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (curSessionId == ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL) {
|
||||
DHLOGW("this is the only session.");
|
||||
int32_t ret = DistributedInputCollector::GetInstance().Init(
|
||||
DistributedInputSinkTransport::GetInstance().GetEventHandler());
|
||||
nlohmann::json jsonStrSta;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ON_RELAY_STARTDHID;
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("DInputSinkListener init InputCollector error.");
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_RESP_VALUE] = false;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_WHITE_LIST] = "";
|
||||
std::string smsg = jsonStrSta.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(toSinkSessionId, smsg);
|
||||
return;
|
||||
}
|
||||
|
||||
DistributedInputSinkManager::GetInstance().AddWhiteList(jsonStrSta);
|
||||
DistributedInputSinkSwitch::GetInstance().AddSession(toSinkSessionId);
|
||||
int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(toSinkSessionId);
|
||||
bool result = (startRes == DH_SUCCESS);
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_SESSION_ID] = toSrcSessionId;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = strDhids;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_RESP_VALUE] = result;
|
||||
std::string smsg = jsonStrSta.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(toSinkSessionId, smsg);
|
||||
|
||||
if (startRes != DH_SUCCESS) {
|
||||
DHLOGE("onRelayStartDhidRemoteInput startSwitch error.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::thread(&DistributedInputSinkManager::DInputSinkListener::CheckKeyState, this,
|
||||
toSinkSessionId, strDhids).detach();
|
||||
|
||||
// add the dhids
|
||||
if (startRes == DH_SUCCESS) {
|
||||
std::vector<std::string> vecStr;
|
||||
StringSplit(strDhids, INPUT_STRING_SPLIT_POINT, vecStr);
|
||||
AffectDhIds affDhIds = DistributedInputCollector::GetInstance().SetSharingDhIds(true, vecStr);
|
||||
sinkManagerObj_->StoreStartDhids(toSinkSessionId, affDhIds.sharingDhIds);
|
||||
DistributedInputCollector::GetInstance().ReportDhIdSharingState(affDhIds);
|
||||
}
|
||||
std::vector<std::string> vecStr;
|
||||
StringSplit(strDhids, INPUT_STRING_SPLIT_POINT, vecStr);
|
||||
AffectDhIds affDhIds = DistributedInputCollector::GetInstance().SetSharingDhIds(true, vecStr);
|
||||
sinkManagerObj_->StoreStartDhids(toSinkSessionId, affDhIds.sharingDhIds);
|
||||
DistributedInputCollector::GetInstance().ReportDhIdSharingState(affDhIds);
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::DInputSinkListener::onRelayStopDhidRemoteInput(const int32_t &toSrcSessionId,
|
||||
const int32_t &toSinkSessionId, const std::string &deviceId, const std::string &strDhids)
|
||||
{
|
||||
DHLOGI("toSinkSessionId: %d", toSinkSessionId);
|
||||
DHLOGI("onRelayStopDhidRemoteInput called, toSinkSessionId: %d", toSinkSessionId);
|
||||
if (sinkManagerObj_ == nullptr) {
|
||||
DHLOGE("sinkManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string> stopIndeedDhIds;
|
||||
std::vector<std::string> stopOnCmdDhIds;
|
||||
StringSplit(strDhids, INPUT_STRING_SPLIT_POINT, stopOnCmdDhIds);
|
||||
@@ -415,55 +425,75 @@ void DistributedInputSinkManager::DInputSinkListener::onRelayStopDhidRemoteInput
|
||||
sinkManagerObj_->SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE);
|
||||
}
|
||||
}
|
||||
DistributedInputSinkSwitch::GetInstance().RemoveSession(toSinkSessionId);
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::DInputSinkListener::onRelayStartTypeRemoteInput(const int32_t &toSrcSessionId,
|
||||
const int32_t &toSinkSessionId, const std::string &deviceId, uint32_t inputTypes)
|
||||
{
|
||||
int32_t curSessionId = DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession();
|
||||
DHLOGI("curSessionId:%s, new sessionId: %s",
|
||||
GetAnonyInt32(curSessionId).c_str(), GetAnonyInt32(toSinkSessionId).c_str());
|
||||
// set new session
|
||||
int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(toSinkSessionId);
|
||||
DHLOGI("onRelayStartTypeRemoteInput called, toSinkSessionId: %d", toSinkSessionId);
|
||||
if (sinkManagerObj_ == nullptr) {
|
||||
DHLOGE("sinkManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
sinkManagerObj_->SetStartTransFlag((startRes == DH_SUCCESS) ? DInputServerType::SINK_SERVER_TYPE
|
||||
: DInputServerType::NULL_SERVER_TYPE);
|
||||
|
||||
bool result = (startRes == DH_SUCCESS) ? true : false;
|
||||
int32_t ret = DistributedInputCollector::GetInstance().Init(
|
||||
DistributedInputSinkTransport::GetInstance().GetEventHandler());
|
||||
nlohmann::json jsonStrSta;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ON_RELAY_STARTTYPE;
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("DInputSinkListener init InputCollector error.");
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_RESP_VALUE] = false;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_WHITE_LIST] = "";
|
||||
std::string smsg = jsonStrSta.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(toSinkSessionId, smsg);
|
||||
return;
|
||||
}
|
||||
|
||||
DistributedInputSinkManager::GetInstance().AddWhiteList(jsonStrSta);
|
||||
DistributedInputSinkSwitch::GetInstance().AddSession(toSinkSessionId);
|
||||
int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(toSinkSessionId);
|
||||
sinkManagerObj_->SetStartTransFlag((startRes == DH_SUCCESS) ? DInputServerType::SINK_SERVER_TYPE
|
||||
: DInputServerType::NULL_SERVER_TYPE);
|
||||
bool result = (startRes == DH_SUCCESS);
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_RESP_VALUE] = result;
|
||||
jsonStrSta[DINPUT_SOFTBUS_KEY_SESSION_ID] = toSrcSessionId;
|
||||
std::string smsgSta = jsonStrSta.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(toSinkSessionId, smsgSta);
|
||||
std::string smsg = jsonStrSta.dump();
|
||||
DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(toSinkSessionId, smsg);
|
||||
|
||||
if (startRes != DH_SUCCESS) {
|
||||
DHLOGE("StartSwitch error.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sinkManagerObj_->GetEventHandler() == nullptr) {
|
||||
DHLOGE("eventhandler is null.");
|
||||
return;
|
||||
}
|
||||
sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() | inputTypes);
|
||||
AffectDhIds affDhIds = DistributedInputCollector::GetInstance().SetSharingTypes(true,
|
||||
sinkManagerObj_->GetInputTypes());
|
||||
sinkManagerObj_->StoreStartDhids(toSinkSessionId, affDhIds.sharingDhIds);
|
||||
DistributedInputCollector::GetInstance().ReportDhIdSharingState(affDhIds);
|
||||
|
||||
bool isMouse = (sinkManagerObj_->GetInputTypes() & static_cast<uint32_t>(DInputDeviceType::MOUSE)) != 0;
|
||||
if (isMouse) {
|
||||
std::map<int32_t, std::string> deviceInfos;
|
||||
DistributedInputCollector::GetInstance().GetDeviceInfoByType(static_cast<uint32_t>(DInputDeviceType::MOUSE),
|
||||
deviceInfos);
|
||||
for (auto deviceInfo : deviceInfos) {
|
||||
DHLOGI("deviceInfo dhId, %s", GetAnonyString(deviceInfo.second).c_str());
|
||||
std::thread(&DistributedInputSinkManager::DInputSinkListener::CheckKeyState, this, toSinkSessionId,
|
||||
deviceInfo.second).detach();
|
||||
}
|
||||
if (!isMouse) {
|
||||
return;
|
||||
}
|
||||
std::map<int32_t, std::string> deviceInfos;
|
||||
DistributedInputCollector::GetInstance().GetDeviceInfoByType(static_cast<uint32_t>(DInputDeviceType::MOUSE),
|
||||
deviceInfos);
|
||||
for (auto deviceInfo : deviceInfos) {
|
||||
DHLOGI("deviceInfo dhId, %s", GetAnonyString(deviceInfo.second).c_str());
|
||||
std::thread(&DistributedInputSinkManager::DInputSinkListener::CheckKeyState, this, toSinkSessionId,
|
||||
deviceInfo.second).detach();
|
||||
}
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::DInputSinkListener::onRelayStopTypeRemoteInput(const int32_t &toSrcSessionId,
|
||||
const int32_t &toSinkSessionId, const std::string &deviceId, uint32_t inputTypes)
|
||||
{
|
||||
if (sinkManagerObj_ == nullptr) {
|
||||
DHLOGE("sinkManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
DHLOGI("onStopRemoteInput called, sessionId: %d, inputTypes: %d, curInputTypes: %d",
|
||||
toSinkSessionId, inputTypes, sinkManagerObj_->GetInputTypes());
|
||||
|
||||
@@ -493,6 +523,7 @@ void DistributedInputSinkManager::DInputSinkListener::onRelayStopTypeRemoteInput
|
||||
sinkManagerObj_->SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE);
|
||||
}
|
||||
}
|
||||
DistributedInputSinkSwitch::GetInstance().RemoveSession(toSinkSessionId);
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::DInputSinkListener::StringSplit(const std::string &str, const char split,
|
||||
@@ -1043,7 +1074,7 @@ int32_t DistributedInputSinkManager::Dump(int32_t fd, const std::vector<std::u16
|
||||
return ERR_DH_INPUT_HIDUMP_DUMP_PROCESS_FAIL;
|
||||
}
|
||||
|
||||
int ret = dprintf(fd, "%s\n", result.c_str());
|
||||
int32_t ret = dprintf(fd, "%s\n", result.c_str());
|
||||
if (ret < 0) {
|
||||
DHLOGE("dprintf error.");
|
||||
return ERR_DH_INPUT_HIDUMP_DPRINTF_FAIL;
|
||||
|
||||
@@ -36,6 +36,7 @@ ohos_shared_library("libdinput_sink_trans") {
|
||||
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
|
||||
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"//foundation/distributedhardware/distributed_input/services/transportbase/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -61,6 +62,7 @@ ohos_shared_library("libdinput_sink_trans") {
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//foundation/distributedhardware/distributed_input/services/transportbase:libdinput_trans_base",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#include "dinput_sink_trans_callback.h"
|
||||
#include "dinput_transbase_sink_callback.h"
|
||||
#include "dinput_softbus_define.h"
|
||||
#include "distributed_input_sink_switch.h"
|
||||
|
||||
@@ -38,6 +39,16 @@ public:
|
||||
DistributedInputSinkTransport();
|
||||
~DistributedInputSinkTransport();
|
||||
|
||||
class DInputTransbaseSinkListener : public DInputTransbaseSinkCallback {
|
||||
public:
|
||||
DInputTransbaseSinkListener(DistributedInputSinkTransport *transport);
|
||||
virtual ~DInputTransbaseSinkListener();
|
||||
void HandleSessionData(int32_t sessionId, const std::string& messageData);
|
||||
|
||||
private:
|
||||
DistributedInputSinkTransport *sinkTransportObj_;
|
||||
};
|
||||
|
||||
int32_t Init();
|
||||
|
||||
void RegistSinkRespCallback(std::shared_ptr<DInputSinkTransCallback> callback);
|
||||
@@ -48,10 +59,6 @@ public:
|
||||
int32_t RespLatency(const int32_t sessionId, std::string &smsg);
|
||||
void SendKeyStateNodeMsg(const int32_t sessionId, const std::string& dhId, const uint32_t btnCode);
|
||||
|
||||
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);
|
||||
|
||||
class DInputSinkEventHandler : public AppExecFwk::EventHandler {
|
||||
public:
|
||||
DInputSinkEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner);
|
||||
@@ -63,12 +70,12 @@ public:
|
||||
|
||||
std::shared_ptr<DistributedInputSinkTransport::DInputSinkEventHandler> GetEventHandler();
|
||||
void CloseAllSession();
|
||||
int32_t GetSessionIdByNetId(const std::string &srcId);
|
||||
void GetDeviceIdBySessionId(int32_t sessionId, std::string &srcId);
|
||||
|
||||
private:
|
||||
int32_t SendMessage(int32_t sessionId, std::string &message);
|
||||
void HandleSessionData(int32_t sessionId, const std::string& messageData);
|
||||
void HandleSessionData(int32_t sessionId, const std::string& message);
|
||||
void HandleData(int32_t sessionId, const std::string& message);
|
||||
void RegRespFunMap();
|
||||
void NotifyPrepareRemoteInput(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
void NotifyUnprepareRemoteInput(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
void NotifyStartRemoteInput(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
@@ -84,11 +91,14 @@ private:
|
||||
void NotifyRelayStartTypeRemoteInput(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
void NotifyRelayStopTypeRemoteInput(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
private:
|
||||
std::map<std::string, int32_t> sessionDevMap_; // source networkId, sessionId
|
||||
std::string mySessionName_;
|
||||
|
||||
std::shared_ptr<DistributedInputSinkTransport::DInputSinkEventHandler> eventHandler_;
|
||||
std::shared_ptr<DistributedInputSinkTransport::DInputTransbaseSinkListener> statuslistener_;
|
||||
std::shared_ptr<DInputSinkTransCallback> callback_;
|
||||
|
||||
using SinkTransportFunc = void (DistributedInputSinkTransport::*)(int32_t sessionId,
|
||||
const nlohmann::json &recMsg);
|
||||
std::map<int32_t, SinkTransportFunc> memberFuncMap_;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -32,10 +32,12 @@
|
||||
#include "session.h"
|
||||
#include "softbus_bus_center.h"
|
||||
|
||||
#include "distributed_input_transport_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
DistributedInputSinkTransport::DistributedInputSinkTransport() : sessionDevMap_({}), mySessionName_("")
|
||||
DistributedInputSinkTransport::DistributedInputSinkTransport() : mySessionName_("")
|
||||
{
|
||||
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create(true);
|
||||
eventHandler_ = std::make_shared<DistributedInputSinkTransport::DInputSinkEventHandler>(runner);
|
||||
@@ -45,7 +47,6 @@ DistributedInputSinkTransport::DistributedInputSinkTransport() : sessionDevMap_(
|
||||
DistributedInputSinkTransport::~DistributedInputSinkTransport()
|
||||
{
|
||||
DHLOGI("~DistributedInputSinkTransport");
|
||||
sessionDevMap_.clear();
|
||||
(void)RemoveSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str());
|
||||
}
|
||||
|
||||
@@ -54,38 +55,6 @@ DistributedInputSinkTransport::DInputSinkEventHandler::DInputSinkEventHandler(
|
||||
{
|
||||
}
|
||||
|
||||
static int32_t SessionOpened(int32_t sessionId, int32_t result)
|
||||
{
|
||||
return DistributedInput::DistributedInputSinkTransport::GetInstance().OnSessionOpened(sessionId, result);
|
||||
}
|
||||
|
||||
static void SessionClosed(int32_t sessionId)
|
||||
{
|
||||
DistributedInput::DistributedInputSinkTransport::GetInstance().OnSessionClosed(sessionId);
|
||||
}
|
||||
|
||||
static void BytesReceived(int32_t sessionId, const void *data, uint32_t dataLen)
|
||||
{
|
||||
DistributedInput::DistributedInputSinkTransport::GetInstance().OnBytesReceived(sessionId, data, dataLen);
|
||||
}
|
||||
|
||||
static void MessageReceived(int32_t sessionId, const void *data, uint32_t dataLen)
|
||||
{
|
||||
(void)sessionId;
|
||||
(void)data;
|
||||
(void)dataLen;
|
||||
DHLOGI("sessionId: %d, dataLen:%d", sessionId, dataLen);
|
||||
}
|
||||
|
||||
static void StreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext,
|
||||
const StreamFrameInfo *param)
|
||||
{
|
||||
(void)sessionId;
|
||||
(void)data;
|
||||
(void)ext;
|
||||
(void)param;
|
||||
DHLOGI("sessionId: %d", sessionId);
|
||||
}
|
||||
DistributedInputSinkTransport &DistributedInputSinkTransport::GetInstance()
|
||||
{
|
||||
static DistributedInputSinkTransport instance;
|
||||
@@ -99,10 +68,10 @@ void DistributedInputSinkTransport::DInputSinkEventHandler::ProcessEvent(const A
|
||||
switch (eventId) {
|
||||
case EHandlerMsgType::DINPUT_SINK_EVENT_HANDLER_MSG: {
|
||||
std::shared_ptr<nlohmann::json> innerMsg = event->GetSharedObject<nlohmann::json>();
|
||||
nlohmann::json sendMsg;
|
||||
sendMsg[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_BODY_DATA;
|
||||
sendMsg[DINPUT_SOFTBUS_KEY_INPUT_DATA] = innerMsg->dump();
|
||||
std::string smsg = sendMsg.dump();
|
||||
nlohmann::json jsonStr;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_BODY_DATA;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_INPUT_DATA] = innerMsg->dump();
|
||||
std::string smsg = jsonStr.dump();
|
||||
RecordEventLog(innerMsg);
|
||||
int32_t sessionId = DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession();
|
||||
if (sessionId > 0) {
|
||||
@@ -120,30 +89,18 @@ void DistributedInputSinkTransport::DInputSinkEventHandler::ProcessEvent(const A
|
||||
|
||||
int32_t DistributedInputSinkTransport::Init()
|
||||
{
|
||||
// 1.create session
|
||||
DHLOGI("Init");
|
||||
ISessionListener iSessionListener = {
|
||||
.OnSessionOpened = SessionOpened,
|
||||
.OnSessionClosed = SessionClosed,
|
||||
.OnBytesReceived = BytesReceived,
|
||||
.OnMessageReceived = MessageReceived,
|
||||
.OnStreamReceived = StreamReceived
|
||||
};
|
||||
auto localNode = std::make_unique<NodeBasicInfo>();
|
||||
int32_t retCode = GetLocalNodeDeviceInfo(DINPUT_PKG_NAME.c_str(), localNode.get());
|
||||
if (retCode != DH_SUCCESS) {
|
||||
DHLOGE("Init could not get local device id.");
|
||||
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_INIT_FAIL;
|
||||
}
|
||||
std::string networkId = localNode->networkId;
|
||||
DHLOGI("Init device networkId is %s", GetAnonyString(networkId).c_str());
|
||||
mySessionName_ = SESSION_NAME_SINK + networkId.substr(0, INTERCEPT_STRING_LENGTH);
|
||||
DHLOGI("Init Sink Transport");
|
||||
|
||||
int32_t ret = CreateSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str(), &iSessionListener);
|
||||
int32_t ret = DistributedInputTransportBase::GetInstance().Init();
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("Init CreateSessionServer failed, error code %d.", ret);
|
||||
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_INIT_FAIL;
|
||||
DHLOGE("Init Sink Transport Failed");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_INIT_FAIL;
|
||||
}
|
||||
|
||||
statuslistener_ = std::make_shared<DInputTransbaseSinkListener>(this);
|
||||
DistributedInputTransportBase::GetInstance().RegisterSinkHandleSessionCallback(statuslistener_);
|
||||
|
||||
RegRespFunMap();
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -176,7 +133,8 @@ int32_t DistributedInputSinkTransport::RespPrepareRemoteInput(
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkTransport::RespUnprepareRemoteInput(const int32_t sessionId, std::string &smsg)
|
||||
int32_t DistributedInputSinkTransport::RespUnprepareRemoteInput(
|
||||
const int32_t sessionId, std::string &smsg)
|
||||
{
|
||||
if (sessionId > 0) {
|
||||
DHLOGI("RespUnprepareRemoteInput sessionId: %d, smsg:%s.", sessionId, SetAnonyId(smsg).c_str());
|
||||
@@ -192,7 +150,8 @@ int32_t DistributedInputSinkTransport::RespUnprepareRemoteInput(const int32_t se
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkTransport::RespStartRemoteInput(const int32_t sessionId, std::string &smsg)
|
||||
int32_t DistributedInputSinkTransport::RespStartRemoteInput(
|
||||
const int32_t sessionId, std::string &smsg)
|
||||
{
|
||||
if (sessionId > 0) {
|
||||
DHLOGI("RespStartRemoteInput sessionId: %d, smsg:%s.", sessionId, SetAnonyId(smsg).c_str());
|
||||
@@ -264,141 +223,20 @@ void DistributedInputSinkTransport::SendKeyStateNodeMsg(const int32_t sessionId,
|
||||
|
||||
int32_t DistributedInputSinkTransport::SendMessage(int32_t sessionId, std::string &message)
|
||||
{
|
||||
DHLOGD("start SendMessage");
|
||||
if (message.size() > MSG_MAX_SIZE) {
|
||||
DHLOGE("SendMessage error: message.size() > MSG_MAX_SIZE");
|
||||
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_SENDMESSAGE_FAIL;
|
||||
}
|
||||
uint8_t *buf = reinterpret_cast<uint8_t *>(calloc((MSG_MAX_SIZE), sizeof(uint8_t)));
|
||||
if (buf == nullptr) {
|
||||
DHLOGE("SendMessage: malloc memory failed");
|
||||
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_SENDMESSAGE_FAIL;
|
||||
}
|
||||
int32_t outLen = 0;
|
||||
if (memcpy_s(buf, MSG_MAX_SIZE, reinterpret_cast<const uint8_t *>(message.c_str()), message.size()) != EOK) {
|
||||
DHLOGE("SendMessage: memcpy memory failed");
|
||||
free(buf);
|
||||
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_SENDMESSAGE_FAIL;
|
||||
}
|
||||
outLen = static_cast<int32_t>(message.size());
|
||||
int32_t ret = SendBytes(sessionId, buf, outLen);
|
||||
free(buf);
|
||||
return ret;
|
||||
return DistributedInputTransportBase::GetInstance().SendMsg(sessionId, message);
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkTransport::GetSessionIdByNetId(const std::string &srcId)
|
||||
DistributedInputSinkTransport::DInputTransbaseSinkListener::DInputTransbaseSinkListener(
|
||||
DistributedInputSinkTransport *transport)
|
||||
{
|
||||
std::map<std::string, int32_t>::iterator it = sessionDevMap_.find(srcId);
|
||||
if (it != sessionDevMap_.end()) {
|
||||
return it->second;
|
||||
}
|
||||
DHLOGE("get session id failed, srcId = %s", GetAnonyString(srcId).c_str());
|
||||
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_GET_SESSIONID_FAIL;
|
||||
sinkTransportObj_ = transport;
|
||||
DHLOGI("DInputTransbaseSinkListener init.");
|
||||
}
|
||||
|
||||
void DistributedInputSinkTransport::GetDeviceIdBySessionId(int32_t sessionId, std::string &srcId)
|
||||
DistributedInputSinkTransport::DInputTransbaseSinkListener::~DInputTransbaseSinkListener()
|
||||
{
|
||||
for (auto iter = sessionDevMap_.begin(); iter != sessionDevMap_.end(); iter++) {
|
||||
if (sessionId == iter->second) {
|
||||
srcId = iter->first;
|
||||
return;
|
||||
}
|
||||
}
|
||||
srcId = "";
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkTransport::OnSessionOpened(int32_t sessionId, int32_t result)
|
||||
{
|
||||
if (result != DH_SUCCESS) {
|
||||
DHLOGE("session open failed, sessionId: %d", sessionId);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef DINPUT_LOW_LATENCY
|
||||
DInputLowLatency::GetInstance().EnableSinkLowLatency();
|
||||
#endif
|
||||
|
||||
// return 1 is client
|
||||
int32_t sessionSide = GetSessionSide(sessionId);
|
||||
DHLOGI("session open succeed, sessionId: %d, sessionSide %d", sessionId, sessionSide);
|
||||
|
||||
char mySessionName[SESSION_NAME_SIZE_MAX] = "";
|
||||
char peerSessionName[SESSION_NAME_SIZE_MAX] = "";
|
||||
char peerDevId[DEVICE_ID_SIZE_MAX] = "";
|
||||
int ret = GetMySessionName(sessionId, mySessionName, sizeof(mySessionName));
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("get my session name failed, session id is %d", sessionId);
|
||||
}
|
||||
// get other device session name
|
||||
ret = GetPeerSessionName(sessionId, peerSessionName, sizeof(peerSessionName));
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("get my peer session name failed, session id is %d", sessionId);
|
||||
}
|
||||
|
||||
ret = GetPeerDeviceId(sessionId, peerDevId, sizeof(peerDevId));
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("get my peer device id failed, session id is %d", sessionId);
|
||||
} else {
|
||||
sessionDevMap_[peerDevId] = sessionId;
|
||||
}
|
||||
DHLOGI("mySessionName:%s, peerSessionName:%s, peerDevId:%s",
|
||||
mySessionName, peerSessionName, GetAnonyString(peerDevId).c_str());
|
||||
HiDumper::GetInstance().CreateSessionInfo(std::string(peerDevId), sessionId, mySessionName, peerSessionName,
|
||||
SessionStatus::OPENED);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DistributedInputSinkTransport::OnSessionClosed(int32_t sessionId)
|
||||
{
|
||||
DHLOGI("OnSessionClosed, sessionId: %d", sessionId);
|
||||
|
||||
#ifdef DINPUT_LOW_LATENCY
|
||||
DInputLowLatency::GetInstance().DisableSinkLowLatency();
|
||||
#endif
|
||||
|
||||
char peerDevId[DEVICE_ID_SIZE_MAX] = "";
|
||||
int ret = GetPeerDeviceId(sessionId, peerDevId, sizeof(peerDevId));
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGI("get my peer device id failed, session id is %d", sessionId);
|
||||
}
|
||||
for (auto iter = sessionDevMap_.begin(); iter != sessionDevMap_.end(); iter++) {
|
||||
if (iter->second == sessionId) {
|
||||
sessionDevMap_.erase(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
DistributedInputSinkSwitch::GetInstance().RemoveSession(sessionId);
|
||||
HiDumper::GetInstance().SetSessionStatus(std::string(peerDevId), SessionStatus::CLOSED);
|
||||
HiDumper::GetInstance().DeleteSessionInfo(std::string(peerDevId));
|
||||
}
|
||||
|
||||
void DistributedInputSinkTransport::OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen)
|
||||
{
|
||||
DHLOGI("OnBytesReceived, sessionId: %d, dataLen:%d", sessionId, dataLen);
|
||||
if (sessionId < 0 || data == nullptr || dataLen <= 0 || dataLen > MSG_MAX_SIZE) {
|
||||
DHLOGE("OnBytesReceived param check failed");
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *buf = reinterpret_cast<uint8_t *>(calloc(dataLen + 1, sizeof(uint8_t)));
|
||||
if (buf == nullptr) {
|
||||
DHLOGE("OnBytesReceived: malloc memory failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (memcpy_s(buf, dataLen + 1, reinterpret_cast<const uint8_t *>(data), dataLen) != EOK) {
|
||||
DHLOGE("OnBytesReceived: memcpy memory failed");
|
||||
free(buf);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string message(buf, buf + dataLen);
|
||||
DHLOGI("OnBytesReceived message:%s.", SetAnonyId(message).c_str());
|
||||
HandleSessionData(sessionId, message);
|
||||
|
||||
free(buf);
|
||||
DHLOGI("OnBytesReceived completed");
|
||||
return;
|
||||
sinkTransportObj_ = nullptr;
|
||||
DHLOGI("DInputTransbaseSinkListener destory.");
|
||||
}
|
||||
|
||||
void DistributedInputSinkTransport::NotifyPrepareRemoteInput(int32_t sessionId, const nlohmann::json &recMsg)
|
||||
@@ -630,7 +468,35 @@ void DistributedInputSinkTransport::NotifyRelayStopTypeRemoteInput(int32_t sessi
|
||||
callback_->onRelayStopTypeRemoteInput(toSrcSessionId, sessionId, deviceId, inputTypes);
|
||||
}
|
||||
|
||||
void DistributedInputSinkTransport::HandleSessionData(int32_t sessionId, const std::string& message)
|
||||
void DistributedInputSinkTransport::DInputTransbaseSinkListener::HandleSessionData(int32_t sessionId,
|
||||
const std::string& message)
|
||||
{
|
||||
DistributedInputSinkTransport::GetInstance().HandleData(sessionId, message);
|
||||
}
|
||||
|
||||
void DistributedInputSinkTransport::RegRespFunMap()
|
||||
{
|
||||
memberFuncMap_[TRANS_SOURCE_MSG_PREPARE] = &DistributedInputSinkTransport::NotifyPrepareRemoteInput;
|
||||
memberFuncMap_[TRANS_SOURCE_MSG_UNPREPARE] = &DistributedInputSinkTransport::NotifyUnprepareRemoteInput;
|
||||
memberFuncMap_[TRANS_SOURCE_MSG_START_TYPE] = &DistributedInputSinkTransport::NotifyStartRemoteInput;
|
||||
memberFuncMap_[TRANS_SOURCE_MSG_STOP_TYPE] = &DistributedInputSinkTransport::NotifyStopRemoteInput;
|
||||
memberFuncMap_[TRANS_SOURCE_MSG_LATENCY] = &DistributedInputSinkTransport::NotifyLatency;
|
||||
memberFuncMap_[TRANS_SOURCE_MSG_START_DHID] = &DistributedInputSinkTransport::NotifyStartRemoteInputDhid;
|
||||
memberFuncMap_[TRANS_SOURCE_MSG_STOP_DHID] = &DistributedInputSinkTransport::NotifyStopRemoteInputDhid;
|
||||
memberFuncMap_[TRANS_SOURCE_MSG_PREPARE_FOR_REL] = &DistributedInputSinkTransport::NotifyRelayPrepareRemoteInput;
|
||||
memberFuncMap_[TRANS_SOURCE_MSG_UNPREPARE_FOR_REL] =
|
||||
&DistributedInputSinkTransport::NotifyRelayUnprepareRemoteInput;
|
||||
memberFuncMap_[TRANS_SOURCE_MSG_START_DHID_FOR_REL] =
|
||||
&DistributedInputSinkTransport::NotifyRelayStartDhidRemoteInput;
|
||||
memberFuncMap_[TRANS_SOURCE_MSG_STOP_DHID_FOR_REL] =
|
||||
&DistributedInputSinkTransport::NotifyRelayStopDhidRemoteInput;
|
||||
memberFuncMap_[TRANS_SOURCE_MSG_START_TYPE_FOR_REL] =
|
||||
&DistributedInputSinkTransport::NotifyRelayStartTypeRemoteInput;
|
||||
memberFuncMap_[TRANS_SOURCE_MSG_STOP_TYPE_FOR_REL] =
|
||||
&DistributedInputSinkTransport::NotifyRelayStopTypeRemoteInput;
|
||||
}
|
||||
|
||||
void DistributedInputSinkTransport::HandleData(int32_t sessionId, const std::string& message)
|
||||
{
|
||||
if (callback_ == nullptr) {
|
||||
DHLOGE("OnBytesReceived the callback_ is null, the message:%s abort.", SetAnonyId(message).c_str());
|
||||
@@ -638,79 +504,14 @@ void DistributedInputSinkTransport::HandleSessionData(int32_t sessionId, const s
|
||||
}
|
||||
|
||||
nlohmann::json recMsg = nlohmann::json::parse(message, nullptr, false);
|
||||
if (recMsg.is_discarded()) {
|
||||
DHLOGE("OnBytesReceived jsonStr error.");
|
||||
uint32_t cmdType = recMsg[DINPUT_SOFTBUS_KEY_CMD_TYPE];
|
||||
auto iter = memberFuncMap_.find(cmdType);
|
||||
if (iter == memberFuncMap_.end()) {
|
||||
DHLOGE("OnBytesReceived cmdType %d is undefined.", cmdType);
|
||||
return;
|
||||
}
|
||||
|
||||
if (recMsg.contains(DINPUT_SOFTBUS_KEY_CMD_TYPE) != true) {
|
||||
DHLOGE("OnBytesReceived message:%s is error, not contain cmdType.", SetAnonyId(message).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (recMsg[DINPUT_SOFTBUS_KEY_CMD_TYPE].is_number() != true) {
|
||||
DHLOGE("OnBytesReceived cmdType is not number type.");
|
||||
return;
|
||||
}
|
||||
|
||||
int cmdType = recMsg[DINPUT_SOFTBUS_KEY_CMD_TYPE];
|
||||
switch (cmdType) {
|
||||
case TRANS_SOURCE_MSG_PREPARE: {
|
||||
NotifyPrepareRemoteInput(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SOURCE_MSG_UNPREPARE: {
|
||||
NotifyUnprepareRemoteInput(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SOURCE_MSG_START_TYPE: {
|
||||
NotifyStartRemoteInput(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SOURCE_MSG_STOP_TYPE: {
|
||||
NotifyStopRemoteInput(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SOURCE_MSG_LATENCY: {
|
||||
NotifyLatency(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SOURCE_MSG_START_DHID: {
|
||||
NotifyStartRemoteInputDhid(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SOURCE_MSG_STOP_DHID: {
|
||||
NotifyStopRemoteInputDhid(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SOURCE_MSG_PREPARE_FOR_REL: {
|
||||
NotifyRelayPrepareRemoteInput(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SOURCE_MSG_UNPREPARE_FOR_REL: {
|
||||
NotifyRelayUnprepareRemoteInput(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SOURCE_MSG_START_DHID_FOR_REL: {
|
||||
NotifyRelayStartDhidRemoteInput(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SOURCE_MSG_STOP_DHID_FOR_REL: {
|
||||
NotifyRelayStopDhidRemoteInput(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SOURCE_MSG_START_TYPE_FOR_REL: {
|
||||
NotifyRelayStartTypeRemoteInput(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
case TRANS_SOURCE_MSG_STOP_TYPE_FOR_REL: {
|
||||
NotifyRelayStopTypeRemoteInput(sessionId, recMsg);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
DHLOGE("OnBytesReceived cmdType is undefined.");
|
||||
break;
|
||||
}
|
||||
SinkTransportFunc &func = iter->second;
|
||||
(this->*func)(sessionId, recMsg);
|
||||
}
|
||||
|
||||
void DistributedInputSinkTransport::CloseAllSession()
|
||||
|
||||
@@ -22,6 +22,7 @@ ohos_shared_library("libdinput_inject") {
|
||||
"${frameworks_path}/include",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"${distributedinput_path}/inputdevicehandler/include",
|
||||
"${fwk_common_path}/log/include",
|
||||
"${fwk_common_path}/utils/include",
|
||||
"${fwk_utils_path}/include/log",
|
||||
|
||||
@@ -63,6 +63,7 @@ private:
|
||||
/* the key is dhId, and the value is virtualDevice */
|
||||
std::map<std::string, std::unique_ptr<VirtualDevice>> virtualDeviceMap_;
|
||||
std::mutex virtualDeviceMapMutex_;
|
||||
std::atomic<bool> isInjectThreadCreated_;
|
||||
std::atomic<bool> isInjectThreadRunning_;
|
||||
std::mutex operationMutex_;
|
||||
std::thread eventInjectThread_;
|
||||
|
||||
@@ -38,14 +38,15 @@
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
DistributedInputNodeManager::DistributedInputNodeManager() : isInjectThreadRunning_(false),
|
||||
inputHub_(std::make_unique<InputHub>()), virtualTouchScreenFd_(UN_INIT_FD_VALUE)
|
||||
DistributedInputNodeManager::DistributedInputNodeManager() : isInjectThreadCreated_(false),
|
||||
isInjectThreadRunning_(false), inputHub_(std::make_unique<InputHub>()), virtualTouchScreenFd_(UN_INIT_FD_VALUE)
|
||||
{
|
||||
}
|
||||
|
||||
DistributedInputNodeManager::~DistributedInputNodeManager()
|
||||
{
|
||||
DHLOGI("destructor start");
|
||||
isInjectThreadCreated_.store(false);
|
||||
isInjectThreadRunning_.store(false);
|
||||
if (eventInjectThread_.joinable()) {
|
||||
eventInjectThread_.join();
|
||||
@@ -179,30 +180,37 @@ int32_t DistributedInputNodeManager::getDevice(const std::string& dhId, VirtualD
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(virtualDeviceMapMutex_);
|
||||
auto iter = virtualDeviceMap_.find(dhId);
|
||||
if (iter != virtualDeviceMap_.end()) {
|
||||
device = iter->second.get();
|
||||
return DH_SUCCESS;
|
||||
if (iter == virtualDeviceMap_.end()) {
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_GET_DEVICE_FAIL;
|
||||
}
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_GET_DEVICE_FAIL;
|
||||
device = iter->second.get();
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DistributedInputNodeManager::StartInjectThread()
|
||||
{
|
||||
DHLOGI("start");
|
||||
if (isInjectThreadCreated_.load()) {
|
||||
DHLOGI("InjectThread has been created.");
|
||||
return;
|
||||
}
|
||||
DHLOGI("InjectThread does not created");
|
||||
isInjectThreadCreated_.store(true);
|
||||
isInjectThreadRunning_.store(true);
|
||||
eventInjectThread_ = std::thread(&DistributedInputNodeManager::InjectEvent, this);
|
||||
DHLOGI("end");
|
||||
}
|
||||
|
||||
void DistributedInputNodeManager::StopInjectThread()
|
||||
{
|
||||
DHLOGI("start");
|
||||
if (!isInjectThreadCreated_.load()) {
|
||||
DHLOGI("InjectThread does not created, and not need to stop.");
|
||||
}
|
||||
DHLOGI("InjectThread has been created, and soon will be stopped.");
|
||||
isInjectThreadRunning_.store(false);
|
||||
isInjectThreadCreated_.store(false);
|
||||
conditionVariable_.notify_all();
|
||||
if (eventInjectThread_.joinable()) {
|
||||
eventInjectThread_.join();
|
||||
}
|
||||
DHLOGI("end");
|
||||
}
|
||||
|
||||
void DistributedInputNodeManager::ReportEvent(const RawEvent rawEvent)
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "singleton.h"
|
||||
#include "system_ability.h"
|
||||
#include "system_ability_status_change_stub.h"
|
||||
#include "input_check_param.h"
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_context.h"
|
||||
@@ -73,6 +74,7 @@ const std::string INPUT_SOURCEMANAGER_KEY_DHID = "dhids";
|
||||
const std::string INPUT_SOURCEMANAGER_KEY_TYPE = "type";
|
||||
const std::string INPUT_SOURCEMANAGER_KEY_CODE = "code";
|
||||
const std::string INPUT_SOURCEMANAGER_KEY_VALUE = "value";
|
||||
const std::string INPUT_SOURCEMANAGER_KEY_FROM_START_DHID = "fromStartDhid";
|
||||
const std::string INPUT_SOURCEMANAGER_KEY_RESULT = "result";
|
||||
const std::string INPUT_SOURCEMANAGER_KEY_WHITELIST = "whitelist";
|
||||
const std::string INPUT_SOURCEMANAGER_KEY_SRC_DEVID = "srcId";
|
||||
@@ -188,18 +190,21 @@ public:
|
||||
DInputSourceListener(DistributedInputSourceManager *manager);
|
||||
virtual ~DInputSourceListener();
|
||||
void onResponseRegisterDistributedHardware(const std::string deviceId, const std::string dhId, bool result);
|
||||
void onResponsePrepareRemoteInput(const std::string deviceId, bool result, const std::string &object);
|
||||
void onResponsePrepareRemoteInput(const std::string deviceId, bool result);
|
||||
void onResponseUnprepareRemoteInput(const std::string deviceId, bool result);
|
||||
void onResponseStartRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result);
|
||||
void onResponseStartRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result,
|
||||
const std::string &object);
|
||||
void onResponseStopRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result);
|
||||
void onResponseStartRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result);
|
||||
void onResponseStartRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result,
|
||||
const std::string &object);
|
||||
void onResponseStopRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result);
|
||||
void onResponseKeyState(const std::string deviceId, const std::string &dhid, const uint32_t type,
|
||||
const uint32_t code, const uint32_t value);
|
||||
void onReceivedEventRemoteInput(const std::string deviceId, const std::string &event);
|
||||
void onResponseRelayPrepareRemoteInput(int32_t sessionId, const std::string &deviceId, bool result,
|
||||
const std::string &object);
|
||||
void onResponseRelayPrepareRemoteInput(int32_t sessionId, const std::string &deviceId, bool result);
|
||||
void onResponseRelayUnprepareRemoteInput(int32_t sessionId, const std::string &deviceId, bool result);
|
||||
void onResponseRelayStartDhidRemoteInput(const std::string &deviceId, const std::string &object);
|
||||
void onResponseRelayStartTypeRemoteInput(const std::string &deviceId, const std::string &object);
|
||||
|
||||
void onReceiveRelayPrepareResult(int32_t status, const std::string &srcId, const std::string &sinkId);
|
||||
void onReceiveRelayUnprepareResult(int32_t status, const std::string &srcId, const std::string &sinkId);
|
||||
@@ -304,26 +309,16 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
void RunRegisterCallback(
|
||||
const std::string& devId, const std::string& dhId, const int32_t& status
|
||||
);
|
||||
void RunUnregisterCallback(
|
||||
const std::string& devId, const std::string& dhId, const int32_t& status
|
||||
);
|
||||
void RunPrepareCallback(
|
||||
const std::string& devId, const int32_t& status, const std::string& object
|
||||
);
|
||||
void RunUnprepareCallback(
|
||||
const std::string& devId, const int32_t& status
|
||||
);
|
||||
void RunStartCallback(
|
||||
const std::string& devId, const uint32_t& inputTypes, const int32_t& status
|
||||
);
|
||||
void RunStopCallback(
|
||||
const std::string& devId, const uint32_t& inputTypes, const int32_t& status
|
||||
);
|
||||
void RunRegisterCallback(const std::string& devId, const std::string& dhId, const int32_t& status);
|
||||
void RunUnregisterCallback(const std::string& devId, const std::string& dhId, const int32_t& status);
|
||||
void RunPrepareCallback(const std::string& devId, const int32_t& status);
|
||||
void RunUnprepareCallback(const std::string& devId, const int32_t& status);
|
||||
void RunStartCallback(const std::string& devId, const uint32_t& inputTypes, const int32_t& status,
|
||||
const std::string& object);
|
||||
void RunStopCallback(const std::string& devId, const uint32_t& inputTypes, const int32_t& status);
|
||||
|
||||
void RunStartDhidCallback(const std::string &sinkId, const std::string &dhIds, const int32_t &status);
|
||||
void RunStartDhidCallback(const std::string &sinkId, const std::string &dhIds, const int32_t &status,
|
||||
const std::string& object);
|
||||
void RunStopDhidCallback(const std::string &sinkId, const std::string &dhIds, const int32_t &status);
|
||||
void RunKeyStateCallback(const std::string &sinkId, const std::string &dhId, const uint32_t type,
|
||||
const uint32_t code, const uint32_t value);
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
#include "distributed_input_source_transport.h"
|
||||
#include "hisysevent_util.h"
|
||||
#include "hidumper.h"
|
||||
#include "input_check_param.h"
|
||||
#include "white_list_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
@@ -83,7 +82,7 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseRegisterDist
|
||||
DHLOGI("onResponseRegisterDistributedHardware called, deviceId: %s, "
|
||||
"result: %s.", GetAnonyString(deviceId).c_str(), result ? "success" : "failed");
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("onResponseRegisterDistributedHardware sourceManagerObj_ is null.");
|
||||
DHLOGE("onResponseRegisterDistributedHardware sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
|
||||
@@ -106,27 +105,25 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseRegisterDist
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::DInputSourceListener::onResponsePrepareRemoteInput(const std::string deviceId,
|
||||
bool result, const std::string &object)
|
||||
bool result)
|
||||
{
|
||||
DHLOGI("onResponsePrepareRemoteInput called, deviceId: %s, result: %s.",
|
||||
GetAnonyString(deviceId).c_str(), result ? "success" : "failed");
|
||||
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("onResponsePrepareRemoteInput sourceManagerObj_ is null.");
|
||||
DHLOGE("onResponsePrepareRemoteInput sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
|
||||
sourceManagerObj_->RunPrepareCallback(deviceId,
|
||||
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL, object);
|
||||
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL);
|
||||
DHLOGE("onResponsePrepareRemoteInput GetCallbackEventHandler is null.");
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<nlohmann::json> jsonArrayMsg = std::make_shared<nlohmann::json>();
|
||||
|
||||
nlohmann::json tmpJson;
|
||||
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
|
||||
tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result;
|
||||
tmpJson[INPUT_SOURCEMANAGER_KEY_WHITELIST] = object;
|
||||
jsonArrayMsg->push_back(tmpJson);
|
||||
AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(
|
||||
DINPUT_SOURCE_MANAGER_PREPARE_MSG, jsonArrayMsg, 0);
|
||||
@@ -140,7 +137,7 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseUnprepareRem
|
||||
"result: %s.", GetAnonyString(deviceId).c_str(), result ? "success" : "failed");
|
||||
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("onResponseUnprepareRemoteInput sourceManagerObj_ is null.");
|
||||
DHLOGE("onResponseUnprepareRemoteInput sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
|
||||
@@ -161,11 +158,11 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseUnprepareRem
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::DInputSourceListener::onResponseRelayPrepareRemoteInput(int32_t toSrcSessionId,
|
||||
const std::string &deviceId, bool result, const std::string &object)
|
||||
const std::string &deviceId, bool result)
|
||||
{
|
||||
DHLOGI("deviceId: %s, result: %d.", GetAnonyString(deviceId).c_str(), result);
|
||||
DHLOGI("onResponseRelayPrepareRemoteInput deviceId: %s, result: %d.", GetAnonyString(deviceId).c_str(), result);
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj_ is null.");
|
||||
DHLOGE("onResponseRelayPrepareRemoteInput sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
|
||||
@@ -176,7 +173,6 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseRelayPrepare
|
||||
nlohmann::json tmpJson;
|
||||
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
|
||||
tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result;
|
||||
tmpJson[INPUT_SOURCEMANAGER_KEY_WHITELIST] = object;
|
||||
tmpJson[INPUT_SOURCEMANAGER_KEY_SESSIONID] = toSrcSessionId;
|
||||
jsonArrayMsg->push_back(tmpJson);
|
||||
AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(
|
||||
@@ -187,9 +183,9 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseRelayPrepare
|
||||
void DistributedInputSourceManager::DInputSourceListener::onResponseRelayUnprepareRemoteInput(int32_t toSrcSessionId,
|
||||
const std::string &deviceId, bool result)
|
||||
{
|
||||
DHLOGI("deviceId: %s, result: %d.", GetAnonyString(deviceId).c_str(), result);
|
||||
DHLOGI("onResponseRelayUnprepareRemoteInput deviceId: %s, result: %d.", GetAnonyString(deviceId).c_str(), result);
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj_ is null.");
|
||||
DHLOGE("onResponseRelayUnprepareRemoteInput sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
|
||||
@@ -207,19 +203,41 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseRelayUnprepa
|
||||
sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::DInputSourceListener::onResponseRelayStartDhidRemoteInput(
|
||||
const std::string &deviceId, const std::string &object)
|
||||
{
|
||||
DHLOGI("Device whitelist object: %s", object.c_str());
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
sourceManagerObj_->RunWhiteListCallback(deviceId, object);
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::DInputSourceListener::onResponseRelayStartTypeRemoteInput(
|
||||
const std::string &deviceId, const std::string &object)
|
||||
{
|
||||
DHLOGI("Device whitelist object: %s", object.c_str());
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
sourceManagerObj_->RunWhiteListCallback(deviceId, object);
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::DInputSourceListener::onResponseStartRemoteInput(
|
||||
const std::string deviceId, const uint32_t inputTypes, bool result)
|
||||
const std::string deviceId, const uint32_t inputTypes, bool result, const std::string &object)
|
||||
{
|
||||
DHLOGI("onResponseStartRemoteInput called, deviceId: %s, inputTypes: %d, result: %s.",
|
||||
GetAnonyString(deviceId).c_str(), inputTypes, result ? "success" : "failed");
|
||||
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("onResponseStartRemoteInput sourceManagerObj_ is null.");
|
||||
DHLOGE("onResponseStartRemoteInput sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
|
||||
sourceManagerObj_->RunStartCallback(deviceId, inputTypes,
|
||||
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL);
|
||||
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL, object);
|
||||
DHLOGE("onResponseStartRemoteInput GetCallbackEventHandler is null.");
|
||||
return;
|
||||
}
|
||||
@@ -231,6 +249,7 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseStartRemoteI
|
||||
nlohmann::json tmpJson;
|
||||
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
|
||||
tmpJson[INPUT_SOURCEMANAGER_KEY_ITP] = inputTypes;
|
||||
tmpJson[INPUT_SOURCEMANAGER_KEY_WHITELIST] = object;
|
||||
tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result;
|
||||
jsonArrayMsg->push_back(tmpJson);
|
||||
AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(
|
||||
@@ -245,7 +264,7 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseStopRemoteIn
|
||||
GetAnonyString(deviceId).c_str(), inputTypes, result ? "true" : "failed");
|
||||
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("onResponseStopRemoteInput sourceManagerObj_ is null.");
|
||||
DHLOGE("onResponseStopRemoteInput sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
|
||||
@@ -267,19 +286,19 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseStopRemoteIn
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::DInputSourceListener::onResponseStartRemoteInputDhid(
|
||||
const std::string deviceId, const std::string &dhids, bool result)
|
||||
const std::string deviceId, const std::string &dhids, bool result, const std::string &object)
|
||||
{
|
||||
DHLOGI("onResponseStartRemoteInputDhid called, deviceId: %s, result: %s.",
|
||||
GetAnonyString(deviceId).c_str(), result ? "success" : "failed");
|
||||
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("onResponseStartRemoteInputDhid sourceManagerObj_ is null.");
|
||||
DHLOGE("onResponseStartRemoteInputDhid sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
|
||||
DHLOGE("onResponseStartRemoteInputDhid GetCallbackEventHandler is null.");
|
||||
sourceManagerObj_->RunStartDhidCallback(deviceId, dhids,
|
||||
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL);
|
||||
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL, object);
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
@@ -290,6 +309,7 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseStartRemoteI
|
||||
nlohmann::json tmpJson;
|
||||
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
|
||||
tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhids;
|
||||
tmpJson[INPUT_SOURCEMANAGER_KEY_WHITELIST] = object;
|
||||
tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result;
|
||||
jsonArrayMsg->push_back(tmpJson);
|
||||
AppExecFwk::InnerEvent::Pointer msgEvent =
|
||||
@@ -304,7 +324,7 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseStopRemoteIn
|
||||
GetAnonyString(deviceId).c_str(), result ? "success" : "failed");
|
||||
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("onResponseStopRemoteInputDhid sourceManagerObj_ is null.");
|
||||
DHLOGE("onResponseStopRemoteInputDhid sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
|
||||
@@ -330,7 +350,7 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseKeyState(con
|
||||
DHLOGI("onResponseMouseDown called, deviceId: %s, dhid: %s.", GetAnonyString(deviceId).c_str(),
|
||||
GetAnonyString(dhid).c_str());
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("onResponseMouseDown sourceManagerObj_ is null.");
|
||||
DHLOGE("onResponseMouseDown sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
|
||||
@@ -385,7 +405,7 @@ void DistributedInputSourceManager::DInputSourceListener::onReceiveRelayPrepareR
|
||||
{
|
||||
DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj_ is null.");
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
|
||||
@@ -408,7 +428,7 @@ void DistributedInputSourceManager::DInputSourceListener::onReceiveRelayUnprepar
|
||||
{
|
||||
DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj_ is null.");
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
|
||||
@@ -431,7 +451,7 @@ void DistributedInputSourceManager::DInputSourceListener::onReceiveRelayStartDhi
|
||||
{
|
||||
DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj_ is null.");
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
|
||||
@@ -455,7 +475,7 @@ void DistributedInputSourceManager::DInputSourceListener::onReceiveRelayStopDhid
|
||||
{
|
||||
DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj_ is null.");
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
|
||||
@@ -479,7 +499,7 @@ void DistributedInputSourceManager::DInputSourceListener::onReceiveRelayStartTyp
|
||||
{
|
||||
DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj_ is null.");
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
|
||||
@@ -503,7 +523,7 @@ void DistributedInputSourceManager::DInputSourceListener::onReceiveRelayStopType
|
||||
{
|
||||
DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj_ is null.");
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
|
||||
@@ -608,6 +628,11 @@ DistributedInputSourceManager::DInputSourceManagerEventHandler::~DInputSourceMan
|
||||
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRegisterCallback(
|
||||
const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
|
||||
auto it = dataMsg->begin();
|
||||
nlohmann::json innerMsg = *(it);
|
||||
@@ -635,6 +660,11 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRegis
|
||||
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyUnregisterCallback(
|
||||
const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
|
||||
auto it = dataMsg->begin();
|
||||
nlohmann::json innerMsg = *(it);
|
||||
@@ -651,20 +681,29 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyUnreg
|
||||
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyPrepareCallback(
|
||||
const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
|
||||
auto it = dataMsg->begin();
|
||||
nlohmann::json innerMsg = *(it);
|
||||
std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID];
|
||||
bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
|
||||
std::string object = innerMsg[INPUT_SOURCEMANAGER_KEY_WHITELIST];
|
||||
|
||||
sourceManagerObj_->RunPrepareCallback(deviceId,
|
||||
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_MSG_IS_BAD, object);
|
||||
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_MSG_IS_BAD);
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyUnprepareCallback(
|
||||
const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
|
||||
auto it = dataMsg->begin();
|
||||
nlohmann::json innerMsg = *(it);
|
||||
@@ -680,11 +719,17 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyUnpre
|
||||
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStartCallback(
|
||||
const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
|
||||
auto it = dataMsg->begin();
|
||||
nlohmann::json innerMsg = *(it);
|
||||
std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID];
|
||||
uint32_t inputTypes = innerMsg[INPUT_SOURCEMANAGER_KEY_ITP];
|
||||
std::string object = innerMsg[INPUT_SOURCEMANAGER_KEY_WHITELIST];
|
||||
bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
|
||||
DHLOGI("Start DInput Recv Callback ret: %s, devId: %s, inputTypes: %d",
|
||||
result ? "true" : "false", GetAnonyString(deviceId).c_str(), inputTypes);
|
||||
@@ -695,12 +740,17 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStart
|
||||
sourceManagerObj_->SetStartTransFlag((result && (sourceManagerObj_->GetInputTypesMap(deviceId) > 0)) ?
|
||||
DInputServerType::SOURCE_SERVER_TYPE : DInputServerType::NULL_SERVER_TYPE);
|
||||
sourceManagerObj_->RunStartCallback(deviceId, inputTypes,
|
||||
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD);
|
||||
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD, object);
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStopCallback(
|
||||
const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
|
||||
auto it = dataMsg->begin();
|
||||
nlohmann::json innerMsg = *(it);
|
||||
@@ -733,6 +783,11 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStopC
|
||||
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStartDhidCallback(
|
||||
const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
DHLOGI("ProcessEvent NotifyStartDhidCallback()");
|
||||
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
|
||||
auto it = dataMsg->begin();
|
||||
@@ -740,16 +795,20 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStart
|
||||
std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID];
|
||||
std::string dhidStr = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID];
|
||||
bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
|
||||
std::string object = innerMsg[INPUT_SOURCEMANAGER_KEY_WHITELIST];
|
||||
|
||||
if (sourceManagerObj_ != nullptr) {
|
||||
sourceManagerObj_->RunStartDhidCallback(deviceId, dhidStr,
|
||||
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD);
|
||||
}
|
||||
sourceManagerObj_->RunStartDhidCallback(deviceId, dhidStr,
|
||||
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD, object);
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStopDhidCallback(
|
||||
const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
DHLOGI("ProcessEvent NotifyStopDhidCallback()");
|
||||
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
|
||||
auto it = dataMsg->begin();
|
||||
@@ -758,15 +817,18 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStopD
|
||||
std::string dhidStr = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID];
|
||||
bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
|
||||
|
||||
if (sourceManagerObj_ != nullptr) {
|
||||
sourceManagerObj_->RunStopDhidCallback(deviceId, dhidStr,
|
||||
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD);
|
||||
}
|
||||
sourceManagerObj_->RunStopDhidCallback(deviceId, dhidStr,
|
||||
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD);
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyKeyStateCallback(
|
||||
const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
DHLOGI("ProcessEvent NotifyKeyStateCallback()");
|
||||
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
|
||||
auto it = dataMsg->begin();
|
||||
@@ -776,19 +838,24 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyKeySt
|
||||
uint32_t keyType = innerMsg[INPUT_SOURCEMANAGER_KEY_TYPE];
|
||||
uint32_t keyCode = innerMsg[INPUT_SOURCEMANAGER_KEY_CODE];
|
||||
uint32_t keyValue = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE];
|
||||
if (sourceManagerObj_ != nullptr) {
|
||||
sourceManagerObj_->RunKeyStateCallback(deviceId, dhid, keyType, keyCode, keyValue);
|
||||
}
|
||||
|
||||
sourceManagerObj_->RunKeyStateCallback(deviceId, dhid, keyType, keyCode, keyValue);
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStartServerCallback(
|
||||
const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
|
||||
auto it = dataMsg->begin();
|
||||
nlohmann::json innerMsg = *(it);
|
||||
int32_t serType = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
|
||||
DInputServerType startTransFlag = DInputServerType(serType);
|
||||
|
||||
sourceManagerObj_->SetStartTransFlag(startTransFlag);
|
||||
}
|
||||
|
||||
@@ -796,6 +863,11 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStart
|
||||
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelayPrepareCallback(
|
||||
const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
|
||||
nlohmann::json::iterator it = dataMsg->begin();
|
||||
nlohmann::json innerMsg = *(it);
|
||||
@@ -809,6 +881,11 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelay
|
||||
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelayUnprepareCallback(
|
||||
const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
|
||||
nlohmann::json::iterator it = dataMsg->begin();
|
||||
nlohmann::json innerMsg = *(it);
|
||||
@@ -827,9 +904,7 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelay
|
||||
nlohmann::json innerMsg = *(it);
|
||||
std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID];
|
||||
bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
|
||||
std::string object = innerMsg[INPUT_SOURCEMANAGER_KEY_WHITELIST];
|
||||
int32_t toSrcSessionId = innerMsg[INPUT_SOURCEMANAGER_KEY_SESSIONID];
|
||||
DHLOGI("Device whitelist object: %s", object.c_str());
|
||||
std::string localNetworkId = GetLocalNetworkId();
|
||||
if (localNetworkId.empty()) {
|
||||
return;
|
||||
@@ -842,7 +917,6 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelay
|
||||
DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_TO_ORIGIN notify is fail.");
|
||||
return;
|
||||
}
|
||||
sourceManagerObj_->RunWhiteListCallback(deviceId, object);
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelayUnprepareRemoteInput(
|
||||
@@ -871,6 +945,11 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelay
|
||||
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelayStartDhidCallback(
|
||||
const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
|
||||
nlohmann::json::iterator it = dataMsg->begin();
|
||||
nlohmann::json innerMsg = *(it);
|
||||
@@ -885,6 +964,11 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelay
|
||||
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelayStopDhidCallback(
|
||||
const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
|
||||
nlohmann::json::iterator it = dataMsg->begin();
|
||||
nlohmann::json innerMsg = *(it);
|
||||
@@ -899,6 +983,11 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelay
|
||||
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelayStartTypeCallback(
|
||||
const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
|
||||
nlohmann::json::iterator it = dataMsg->begin();
|
||||
nlohmann::json innerMsg = *(it);
|
||||
@@ -913,6 +1002,11 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelay
|
||||
void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelayStopTypeCallback(
|
||||
const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
if (sourceManagerObj_ == nullptr) {
|
||||
DHLOGE("sourceManagerObj is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
|
||||
nlohmann::json::iterator it = dataMsg->begin();
|
||||
nlohmann::json innerMsg = *(it);
|
||||
@@ -1584,7 +1678,7 @@ int32_t DistributedInputSourceManager::RelayStartRemoteInputByType(const std::st
|
||||
int32_t ret = DistributedInputSourceTransport::GetInstance().SendRelayStartTypeRequest(srcId, sinkId, inputTypes);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("Can not send message by softbus, start fail.");
|
||||
for (auto iter = relayStaTypeCallbacks_.begin(); iter != relayStaTypeCallbacks_.end(); iter++) {
|
||||
for (auto iter = relayStaTypeCallbacks_.begin(); iter != relayStaTypeCallbacks_.end(); ++iter) {
|
||||
if (iter->srcId == srcId && iter->sinkId == sinkId && iter->inputTypes == inputTypes) {
|
||||
relayStaTypeCallbacks_.erase(iter);
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL;
|
||||
@@ -1613,7 +1707,7 @@ int32_t DistributedInputSourceManager::RelayStopRemoteInputByType(
|
||||
int32_t ret = DistributedInputSourceTransport::GetInstance().SendRelayStopTypeRequest(srcId, sinkId, inputTypes);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("Can not send message by softbus, start fail.");
|
||||
for (auto iter = relayStpTypeCallbacks_.begin(); iter != relayStpTypeCallbacks_.end(); iter++) {
|
||||
for (auto iter = relayStpTypeCallbacks_.begin(); iter != relayStpTypeCallbacks_.end(); ++iter) {
|
||||
if (iter->srcId == srcId && iter->sinkId == sinkId && iter->inputTypes == inputTypes) {
|
||||
relayStpTypeCallbacks_.erase(iter);
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL;
|
||||
@@ -2038,7 +2132,7 @@ int32_t DistributedInputSourceManager::RelayPrepareRemoteInput(const std::string
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ret = DistributedInputSourceTransport::GetInstance().OpenInputSoftbusForRelay(srcId);
|
||||
int32_t ret = DistributedInputSourceTransport::GetInstance().OpenInputSoftbus(srcId);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("Open softbus session fail.");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL;
|
||||
@@ -2049,7 +2143,7 @@ int32_t DistributedInputSourceManager::RelayPrepareRemoteInput(const std::string
|
||||
ret = DistributedInputSourceTransport::GetInstance().SendRelayPrepareRequest(srcId, sinkId);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("Can not send message by softbus, prepare fail.");
|
||||
for (auto iter = relayPreCallbacks_.begin(); iter != relayPreCallbacks_.end(); iter++) {
|
||||
for (auto iter = relayPreCallbacks_.begin(); iter != relayPreCallbacks_.end(); ++iter) {
|
||||
if (iter->srcId == srcId && iter->sinkId == sinkId) {
|
||||
relayPreCallbacks_.erase(iter);
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL;
|
||||
@@ -2078,7 +2172,7 @@ int32_t DistributedInputSourceManager::RelayUnprepareRemoteInput(const std::stri
|
||||
int32_t ret = DistributedInputSourceTransport::GetInstance().SendRelayUnprepareRequest(srcId, sinkId);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("Can not send message by softbus, prepare fail.");
|
||||
for (auto iter = relayUnpreCallbacks_.begin(); iter != relayUnpreCallbacks_.end(); iter++) {
|
||||
for (auto iter = relayUnpreCallbacks_.begin(); iter != relayUnpreCallbacks_.end(); ++iter) {
|
||||
if (iter->srcId == srcId && iter->sinkId == sinkId) {
|
||||
relayUnpreCallbacks_.erase(iter);
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL;
|
||||
@@ -2107,7 +2201,7 @@ int32_t DistributedInputSourceManager::RelayStartRemoteInputByDhid(const std::st
|
||||
int32_t ret = DistributedInputSourceTransport::GetInstance().SendRelayStartDhidRequest(srcId, sinkId, dhIds);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("Can not send message by softbus, start fail.");
|
||||
for (auto iter = relayStaDhidCallbacks_.begin(); iter != relayStaDhidCallbacks_.end(); iter++) {
|
||||
for (auto iter = relayStaDhidCallbacks_.begin(); iter != relayStaDhidCallbacks_.end(); ++iter) {
|
||||
if (iter->srcId == srcId && iter->sinkId == sinkId && IsStringDataSame(iter->dhIds, dhIds)) {
|
||||
relayStaDhidCallbacks_.erase(iter);
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL;
|
||||
@@ -2136,7 +2230,7 @@ int32_t DistributedInputSourceManager::RelayStopRemoteInputByDhid(const std::str
|
||||
int32_t ret = DistributedInputSourceTransport::GetInstance().SendRelayStopDhidRequest(srcId, sinkId, dhIds);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("Can not send message by softbus, stop fail.");
|
||||
for (auto iter = relayStpDhidCallbacks_.begin(); iter != relayStpDhidCallbacks_.end(); iter++) {
|
||||
for (auto iter = relayStpDhidCallbacks_.begin(); iter != relayStpDhidCallbacks_.end(); ++iter) {
|
||||
if (iter->srcId == srcId && iter->sinkId == sinkId && IsStringDataSame(iter->dhIds, dhIds)) {
|
||||
relayStpDhidCallbacks_.erase(iter);
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL;
|
||||
@@ -2181,7 +2275,7 @@ void DistributedInputSourceManager::RunUnregisterCallback(
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::RunPrepareCallback(
|
||||
const std::string& devId, const int32_t& status, const std::string& object)
|
||||
const std::string& devId, const int32_t& status)
|
||||
{
|
||||
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_PREPARE_START, DINPUT_PREPARE_TASK);
|
||||
for (auto iter = preCallbacks_.begin(); iter != preCallbacks_.end(); ++iter) {
|
||||
@@ -2189,7 +2283,6 @@ void DistributedInputSourceManager::RunPrepareCallback(
|
||||
DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_PREPARE_MSG");
|
||||
iter->preCallback->OnResult(devId, status);
|
||||
preCallbacks_.erase(iter);
|
||||
RunWhiteListCallback(devId, object);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -2213,7 +2306,7 @@ void DistributedInputSourceManager::RunRelayPrepareCallback(const std::string &s
|
||||
const int32_t &status)
|
||||
{
|
||||
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_PREPARE_START, DINPUT_PREPARE_TASK);
|
||||
for (auto iter = relayPreCallbacks_.begin(); iter != relayPreCallbacks_.end(); iter++) {
|
||||
for (auto iter = relayPreCallbacks_.begin(); iter != relayPreCallbacks_.end(); ++iter) {
|
||||
if (iter->srcId == srcId && iter->sinkId == sinkId) {
|
||||
DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_MMI");
|
||||
iter->preCallback->OnResult(sinkId, status);
|
||||
@@ -2228,7 +2321,7 @@ void DistributedInputSourceManager::RunRelayUnprepareCallback(const std::string
|
||||
const int32_t &status)
|
||||
{
|
||||
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_UNPREPARE_START, DINPUT_UNPREPARE_TASK);
|
||||
for (auto iter = relayUnpreCallbacks_.begin(); iter != relayUnpreCallbacks_.end(); iter++) {
|
||||
for (auto iter = relayUnpreCallbacks_.begin(); iter != relayUnpreCallbacks_.end(); ++iter) {
|
||||
if (iter->srcId == srcId && iter->sinkId == sinkId) {
|
||||
DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_MMI");
|
||||
iter->unpreCallback->OnResult(sinkId, status);
|
||||
@@ -2263,7 +2356,7 @@ void DistributedInputSourceManager::RunUnprepareCallback(const std::string &devI
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::RunStartCallback(
|
||||
const std::string& devId, const uint32_t& inputTypes, const int32_t& status)
|
||||
const std::string& devId, const uint32_t& inputTypes, const int32_t& status, const std::string& object)
|
||||
{
|
||||
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK);
|
||||
for (auto iter = staCallbacks_.begin(); iter != staCallbacks_.end(); ++iter) {
|
||||
@@ -2271,6 +2364,7 @@ void DistributedInputSourceManager::RunStartCallback(
|
||||
DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_START_MSG");
|
||||
iter->callback->OnResult(devId, inputTypes, status);
|
||||
staCallbacks_.erase(iter);
|
||||
RunWhiteListCallback(devId, object);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2291,7 +2385,7 @@ void DistributedInputSourceManager::RunStopCallback(
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::RunStartDhidCallback(const std::string &sinkId, const std::string &dhIds,
|
||||
const int32_t &status)
|
||||
const int32_t &status, const std::string& object)
|
||||
{
|
||||
std::vector<std::string> dhidsVec;
|
||||
StringSplitToVector(dhIds, INPUT_STRING_SPLIT_POINT, dhidsVec);
|
||||
@@ -2308,6 +2402,7 @@ void DistributedInputSourceManager::RunStartDhidCallback(const std::string &sink
|
||||
}
|
||||
iter->callback->OnResultDhids(sinkId, status);
|
||||
staStringCallbacks_.erase(iter);
|
||||
RunWhiteListCallback(sinkId, object);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ ohos_shared_library("libdinput_source_trans") {
|
||||
"${distributedinput_path}/inputdevicehandler/include",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
|
||||
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"//foundation/distributedhardware/distributed_input/services/transportbase/include",
|
||||
]
|
||||
|
||||
sources = [ "src/distributed_input_source_transport.cpp" ]
|
||||
@@ -60,6 +61,7 @@ ohos_shared_library("libdinput_source_trans") {
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject",
|
||||
"//foundation/distributedhardware/distributed_input/services/transportbase:libdinput_trans_base",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
#define DISTRIBUTED_INPUT_SOURCE_TRANSPORT_H
|
||||
|
||||
#include <condition_variable>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "securec.h"
|
||||
|
||||
#include "dinput_source_trans_callback.h"
|
||||
#include "dinput_transbase_source_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
@@ -39,23 +40,28 @@ public:
|
||||
static DistributedInputSourceTransport &GetInstance();
|
||||
~DistributedInputSourceTransport();
|
||||
|
||||
class DInputTransbaseSourceListener : public DInputTransbaseSourceCallback {
|
||||
public:
|
||||
DInputTransbaseSourceListener(DistributedInputSourceTransport *transport);
|
||||
virtual ~DInputTransbaseSourceListener();
|
||||
void HandleSessionData(int32_t sessionId, const std::string& messageData);
|
||||
|
||||
private:
|
||||
DistributedInputSourceTransport *sourceTransportObj_;
|
||||
};
|
||||
|
||||
int32_t Init();
|
||||
void Release();
|
||||
// this open deviceA.sourceSa ----> deviceB.sinkSa softbus.
|
||||
|
||||
int32_t OpenInputSoftbus(const std::string &remoteDevId);
|
||||
void CloseInputSoftbus(const int32_t sessionId);
|
||||
// this open deviceA.sourceSa ----> deviceB.sourceSa softbus.
|
||||
int32_t OpenInputSoftbusForRelay(const std::string &srcId);
|
||||
void CloseInputSoftbus(const std::string &remoteDevId);
|
||||
|
||||
void RegisterSourceRespCallback(std::shared_ptr<DInputSourceTransCallback> callback);
|
||||
|
||||
int32_t PrepareRemoteInput(const std::string& deviceId);
|
||||
int32_t UnprepareRemoteInput(const std::string& deviceId);
|
||||
int32_t StartRemoteInput(const std::string& deviceId, const uint32_t& inputTypes);
|
||||
int32_t StopRemoteInput(const std::string& deviceId, const uint32_t& inputTypes);
|
||||
int32_t LatencyCount(const std::string& deviceId);
|
||||
void StartLatencyCount(const std::string& deviceId);
|
||||
void StartLatencyThread(const std::string& deviceId);
|
||||
void StopLatencyThread();
|
||||
|
||||
int32_t StartRemoteInput(const std::string &deviceId, const std::vector<std::string> &dhids);
|
||||
int32_t StopRemoteInput(const std::string &deviceId, const std::vector<std::string> &dhids);
|
||||
@@ -82,12 +88,9 @@ public:
|
||||
int32_t GetCurrentSessionId();
|
||||
|
||||
private:
|
||||
std::string FindDeviceBySession(int32_t sessionId);
|
||||
int32_t FindSessionIdByDevId(bool isToSrc, const std::string &deviceId);
|
||||
int32_t SendMsg(int32_t sessionId, std::string &message);
|
||||
int32_t CheckDeviceSessionState(bool isToSrcSa, const std::string &remoteDevId);
|
||||
int32_t SendMessage(int32_t sessionId, std::string &message);
|
||||
void HandleData(int32_t sessionId, const std::string& message);
|
||||
void HandleSessionData(int32_t sessionId, const std::string& messageData);
|
||||
bool CheckRecivedData(const std::string& messageData);
|
||||
void NotifyResponsePrepareRemoteInput(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
void NotifyResponseUnprepareRemoteInput(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
void NotifyResponseStartRemoteInput(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
@@ -128,13 +131,6 @@ private:
|
||||
int32_t status, uint32_t inputTypes);
|
||||
void ReceiveRelayStartTypeResult(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
void ReceiveRelayStopTypeResult(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
|
||||
struct DInputSessionInfo {
|
||||
bool isToSrcSa; // [true] is session to source_sa, [false] is session to sink_sa
|
||||
std::string remoteId; // networkId
|
||||
};
|
||||
|
||||
void CalculateLatency(int32_t sessionId, const nlohmann::json &recMsg);
|
||||
std::string JointDhIds(const std::vector<std::string> &dhids);
|
||||
void RegRespFunMap();
|
||||
|
||||
@@ -142,19 +138,11 @@ private:
|
||||
std::mutex operationMutex_;
|
||||
std::set<int32_t> sessionIdSet_;
|
||||
std::shared_ptr<DInputSourceTransCallback> callback_;
|
||||
std::shared_ptr<DistributedInputSourceTransport::DInputTransbaseSourceListener> statuslistener_;
|
||||
std::string mySessionName_ = "";
|
||||
std::condition_variable openSessionWaitCond_;
|
||||
std::map<int32_t, DInputSessionInfo> sessionDevMap_; // [sessionId, DInputSessionInfo]
|
||||
std::map<int32_t, bool> channelStatusMap_; // [sessionId, bool]
|
||||
uint64_t deltaTime_ = 0;
|
||||
uint64_t deltaTimeAll_ = 0;
|
||||
uint64_t sendTime_ = 0;
|
||||
uint32_t sendNum_ = 0;
|
||||
uint32_t recvNum_ = 0;
|
||||
std::atomic<bool> isLatencyThreadRunning_ = false;
|
||||
std::thread latencyThread_;
|
||||
std::string eachLatencyDetails_ = "";
|
||||
int32_t sessionId_ = 0;
|
||||
|
||||
using SourceTransportFunc = void (DistributedInputSourceTransport::*)(int32_t sessionId,
|
||||
const nlohmann::json &recMsg);
|
||||
std::map<int32_t, SourceTransportFunc> memberFuncMap_;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,80 @@
|
||||
# Copyright (c) 2021-2022 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import(
|
||||
"//foundation/distributedhardware/distributed_input/distributedinput.gni")
|
||||
|
||||
ohos_shared_library("libdinput_trans_base") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${common_path}/include",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"${fwk_common_path}/log/include",
|
||||
"${fwk_common_path}/utils/include",
|
||||
"${fwk_utils_path}/include/log",
|
||||
"${fwk_utils_path}/include",
|
||||
"//third_party/json/include",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/transport",
|
||||
"${service_common}/include",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"${low_latency_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
|
||||
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"//foundation/distributedhardware/distributed_input/services/transportbase/include",
|
||||
"${distributedinput_path}/services/source/inputinject/include",
|
||||
"${distributedinput_path}/inputdevicehandler/include",
|
||||
"${frameworks_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"src/distributed_input_transport_base.cpp",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"HI_LOG_ENABLE",
|
||||
"DH_LOG_TAG=\"distributedinputtransportbase\"",
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
if (distributed_input_low_latency) {
|
||||
defines += [ "DINPUT_LOW_LATENCY" ]
|
||||
}
|
||||
|
||||
deps = [
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${fwk_utils_path}:distributedhardwareutils",
|
||||
"${low_latency_path}:libdinput_low_latency",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject",
|
||||
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hitrace_native:hitrace_meter",
|
||||
]
|
||||
|
||||
cflags_cc = [ "-DHILOG_ENABLE" ]
|
||||
|
||||
subsystem_name = "distributedhardware"
|
||||
|
||||
part_name = "distributed_input"
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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_INPUT_TRANSPORT_BASE_H
|
||||
#define DISTRIBUTED_INPUT_TRANSPORT_BASE_H
|
||||
|
||||
#include <condition_variable>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "constants.h"
|
||||
#include "event_handler.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "securec.h"
|
||||
|
||||
#include "dinput_transbase_source_callback.h"
|
||||
#include "dinput_transbase_sink_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class DistributedInputTransportBase {
|
||||
public:
|
||||
static DistributedInputTransportBase &GetInstance();
|
||||
~DistributedInputTransportBase();
|
||||
|
||||
int32_t Init();
|
||||
void Release();
|
||||
|
||||
int32_t StartSession(const std::string &remoteDevId);
|
||||
void StopSession(const std::string &remoteDevId);
|
||||
|
||||
void RegisterSrcHandleSessionCallback(std::shared_ptr<DInputTransbaseSourceCallback> callback);
|
||||
void RegisterSinkHandleSessionCallback(std::shared_ptr<DInputTransbaseSinkCallback> callback);
|
||||
|
||||
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);
|
||||
|
||||
int32_t GetCurrentSessionId();
|
||||
int32_t CountSession(const std::string &remoteDevId);
|
||||
void EraseSessionId(const std::string &remoteDevId);
|
||||
int32_t GetSessionIdByDeviceId(const std::string &srcId);
|
||||
std::string FindDeviceBySession(int32_t sessionId);
|
||||
int32_t SendMsg(int32_t sessionId, std::string &message);
|
||||
|
||||
int32_t LatencyCount(const std::string& deviceId);
|
||||
void StartLatencyCount(const std::string& deviceId);
|
||||
void StartLatencyThread(const std::string& deviceId);
|
||||
void StopLatencyThread();
|
||||
void CalculateLatency(int32_t sessionId);
|
||||
|
||||
private:
|
||||
int32_t CheckDeviceSessionState(const std::string &remoteDevId);
|
||||
bool CheckRecivedData(const std::string& message);
|
||||
void HandleSession(int32_t sessionId, const std::string& message);
|
||||
|
||||
private:
|
||||
std::mutex operationMutex_;
|
||||
std::string remoteDeviceId_;
|
||||
std::map<std::string, int32_t> remoteDevSessionMap_;
|
||||
std::map<std::string, bool> channelStatusMap_;
|
||||
std::condition_variable openSessionWaitCond_;
|
||||
std::string mySessionName_ = "";
|
||||
int32_t sessionId_ = 0;
|
||||
|
||||
std::atomic<bool> isLatencyThreadRunning_ = false;
|
||||
std::thread latencyThread_;
|
||||
std::string eachLatencyDetails_ = "";
|
||||
|
||||
uint64_t deltaTime_ = 0;
|
||||
uint64_t deltaTimeAll_ = 0;
|
||||
uint64_t sendTime_ = 0;
|
||||
uint32_t sendNum_ = 0;
|
||||
uint32_t recvNum_ = 0;
|
||||
|
||||
std::shared_ptr<DInputTransbaseSourceCallback> srcCallback_;
|
||||
std::shared_ptr<DInputTransbaseSinkCallback> sinkCallback_;
|
||||
};
|
||||
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // DISTRIBUTED_INPUT_TRANSPORT_BASE_H
|
||||
@@ -0,0 +1,510 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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_transport_base.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
#include "anonymous_string.h"
|
||||
#include "distributed_hardware_log.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_errcode.h"
|
||||
#include "dinput_hitrace.h"
|
||||
#include "dinput_low_latency.h"
|
||||
#include "dinput_softbus_define.h"
|
||||
#include "dinput_utils_tool.h"
|
||||
#include "distributed_input_inject.h"
|
||||
#include "hidumper.h"
|
||||
#include "session.h"
|
||||
#include "softbus_bus_center.h"
|
||||
#include "softbus_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
const int32_t DINPUT_LINK_TYPE_MAX = 4;
|
||||
static SessionAttribute g_sessionAttr = {
|
||||
.dataType = SessionType::TYPE_BYTES,
|
||||
.linkTypeNum = DINPUT_LINK_TYPE_MAX,
|
||||
.linkType = {
|
||||
LINK_TYPE_WIFI_P2P,
|
||||
LINK_TYPE_WIFI_WLAN_2G,
|
||||
LINK_TYPE_WIFI_WLAN_5G,
|
||||
LINK_TYPE_BR
|
||||
}
|
||||
};
|
||||
|
||||
DistributedInputTransportBase &DistributedInputTransportBase::GetInstance()
|
||||
{
|
||||
static DistributedInputTransportBase instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
DistributedInputTransportBase::~DistributedInputTransportBase()
|
||||
{
|
||||
DHLOGI("Release Transport Session");
|
||||
Release();
|
||||
}
|
||||
|
||||
static int32_t SessionOpened(int32_t sessionId, int32_t result)
|
||||
{
|
||||
return DistributedInput::DistributedInputTransportBase::GetInstance().OnSessionOpened(sessionId, result);
|
||||
}
|
||||
|
||||
static void SessionClosed(int32_t sessionId)
|
||||
{
|
||||
DistributedInput::DistributedInputTransportBase::GetInstance().OnSessionClosed(sessionId);
|
||||
}
|
||||
|
||||
static void BytesReceived(int32_t sessionId, const void *data, uint32_t dataLen)
|
||||
{
|
||||
DistributedInput::DistributedInputTransportBase::GetInstance().OnBytesReceived(sessionId, data, dataLen);
|
||||
}
|
||||
|
||||
static void MessageReceived(int32_t sessionId, const void *data, uint32_t dataLen)
|
||||
{
|
||||
(void)sessionId;
|
||||
(void)data;
|
||||
(void)dataLen;
|
||||
DHLOGI("sessionId: %d, dataLen:%d", sessionId, dataLen);
|
||||
}
|
||||
|
||||
static void StreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext,
|
||||
const StreamFrameInfo *param)
|
||||
{
|
||||
(void)sessionId;
|
||||
(void)data;
|
||||
(void)ext;
|
||||
(void)param;
|
||||
DHLOGI("sessionId: %d", sessionId);
|
||||
}
|
||||
|
||||
int32_t DistributedInputTransportBase::Init()
|
||||
{
|
||||
DHLOGI("Init Transport Base Session");
|
||||
ISessionListener iSessionListener = {
|
||||
.OnSessionOpened = SessionOpened,
|
||||
.OnSessionClosed = SessionClosed,
|
||||
.OnBytesReceived = BytesReceived,
|
||||
.OnMessageReceived = MessageReceived,
|
||||
.OnStreamReceived = StreamReceived
|
||||
};
|
||||
|
||||
auto localNode = std::make_unique<NodeBasicInfo>();
|
||||
int32_t retCode = GetLocalNodeDeviceInfo(DINPUT_PKG_NAME.c_str(), localNode.get());
|
||||
if (retCode != DH_SUCCESS) {
|
||||
DHLOGE("Init Could not get local device id.");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_INIT_FAIL;
|
||||
}
|
||||
std::string networkId = localNode->networkId;
|
||||
DHLOGI("Init device local networkId is %s", GetAnonyString(networkId).c_str());
|
||||
|
||||
mySessionName_ = SESSION_NAME + networkId.substr(0, INTERCEPT_STRING_LENGTH);
|
||||
|
||||
int32_t ret = CreateSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str(), &iSessionListener);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("Init CreateSessionServer failed, error code %d.", ret);
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_INIT_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DistributedInputTransportBase::Release()
|
||||
{
|
||||
std::unique_lock<std::mutex> sessionLock(operationMutex_);
|
||||
auto iter = remoteDevSessionMap_.begin();
|
||||
for (; iter != remoteDevSessionMap_.end(); ++iter) {
|
||||
CloseSession(iter->second);
|
||||
}
|
||||
(void)RemoveSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str());
|
||||
remoteDevSessionMap_.clear();
|
||||
channelStatusMap_.clear();
|
||||
}
|
||||
|
||||
int32_t DistributedInputTransportBase::CheckDeviceSessionState(const std::string &remoteDevId)
|
||||
{
|
||||
std::unique_lock<std::mutex> sessionLock(operationMutex_);
|
||||
if (remoteDevSessionMap_.find(remoteDevId) == remoteDevSessionMap_.end()) {
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_DEVICE_SESSION_STATE;
|
||||
}
|
||||
DHLOGI("CheckDeviceSessionState has opened %s", GetAnonyString(remoteDevId).c_str());
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
std::string DistributedInputTransportBase::FindDeviceBySession(int32_t sessionId)
|
||||
{
|
||||
std::unique_lock<std::mutex> sessionLock(operationMutex_);
|
||||
std::string devId = "";
|
||||
auto iter = remoteDevSessionMap_.begin();
|
||||
for (; iter != remoteDevSessionMap_.end(); ++iter) {
|
||||
if (iter->second == sessionId) {
|
||||
devId = iter->first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (iter == remoteDevSessionMap_.end()) {
|
||||
DHLOGE("findKeyByValue error.");
|
||||
}
|
||||
return devId;
|
||||
}
|
||||
|
||||
int32_t DistributedInputTransportBase::StartSession(const std::string &remoteDevId)
|
||||
{
|
||||
int32_t ret = CheckDeviceSessionState(remoteDevId);
|
||||
if (ret == DH_SUCCESS) {
|
||||
DHLOGE("Softbus session has already opened, deviceId: %s", GetAnonyString(remoteDevId).c_str());
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
std::string peerSessionName = SESSION_NAME + remoteDevId.substr(0, INTERCEPT_STRING_LENGTH);
|
||||
DHLOGI("OpenInputSoftbus peerSessionName:%s", peerSessionName.c_str());
|
||||
|
||||
StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_OPEN_SESSION_START, DINPUT_OPEN_SESSION_TASK);
|
||||
int32_t sessionId = OpenSession(mySessionName_.c_str(), peerSessionName.c_str(), remoteDevId.c_str(),
|
||||
GROUP_ID.c_str(), &g_sessionAttr);
|
||||
if (sessionId < 0) {
|
||||
DHLOGE("OpenSession fail, remoteDevId: %s, sessionId: %d", GetAnonyString(remoteDevId).c_str(), sessionId);
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_OPEN_SESSION_FAIL;
|
||||
}
|
||||
|
||||
HiDumper::GetInstance().CreateSessionInfo(remoteDevId, sessionId, mySessionName_, peerSessionName,
|
||||
SessionStatus::OPENING);
|
||||
|
||||
DHLOGI("Wait for channel session opened.");
|
||||
{
|
||||
std::unique_lock<std::mutex> waitLock(operationMutex_);
|
||||
auto status = openSessionWaitCond_.wait_for(waitLock, std::chrono::seconds(SESSION_WAIT_TIMEOUT_SECOND),
|
||||
[this, remoteDevId] () { return channelStatusMap_[remoteDevId]; });
|
||||
if (!status) {
|
||||
DHLOGE("OpenSession timeout, remoteDevId: %s, sessionId: %d",
|
||||
GetAnonyString(remoteDevId).c_str(), sessionId);
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_OPEN_SESSION_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
DHLOGI("OpenSession success, remoteDevId:%s, sessionId: %d", GetAnonyString(remoteDevId).c_str(), sessionId);
|
||||
sessionId_ = sessionId;
|
||||
|
||||
StartLatencyThread(remoteDevId);
|
||||
|
||||
#ifdef DINPUT_LOW_LATENCY
|
||||
DInputLowLatency::GetInstance().EnableSourceLowLatency();
|
||||
#endif
|
||||
|
||||
HiDumper::GetInstance().SetSessionStatus(remoteDevId, SessionStatus::OPENED);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DistributedInputTransportBase::StopSession(const std::string &remoteDevId)
|
||||
{
|
||||
std::unique_lock<std::mutex> sessionLock(operationMutex_);
|
||||
// check this device's all hd is close,this device session close.
|
||||
|
||||
if (remoteDevSessionMap_.count(remoteDevId) == 0) {
|
||||
DHLOGI("SessionDevIdMap Not find remoteDevId: %s", GetAnonyString(remoteDevId).c_str());
|
||||
return;
|
||||
}
|
||||
int32_t sessionId = remoteDevSessionMap_[remoteDevId];
|
||||
|
||||
StopLatencyThread();
|
||||
|
||||
DHLOGI("RemoteDevId: %s, sessionId: %d", GetAnonyString(remoteDevId).c_str(), sessionId);
|
||||
HiDumper::GetInstance().SetSessionStatus(remoteDevId, SessionStatus::CLOSING);
|
||||
CloseSession(sessionId);
|
||||
remoteDevSessionMap_.erase(remoteDevId);
|
||||
channelStatusMap_.erase(remoteDevId);
|
||||
|
||||
#ifdef DINPUT_LOW_LATENCY
|
||||
DInputLowLatency::GetInstance().DisableSourceLowLatency();
|
||||
#endif
|
||||
|
||||
HiDumper::GetInstance().SetSessionStatus(remoteDevId, SessionStatus::CLOSED);
|
||||
HiDumper::GetInstance().DeleteSessionInfo(remoteDevId);
|
||||
}
|
||||
|
||||
void DistributedInputTransportBase::RegisterSrcHandleSessionCallback(
|
||||
std::shared_ptr<DInputTransbaseSourceCallback> callback)
|
||||
{
|
||||
DHLOGI("RegisterTransbaseSourceRespCallback");
|
||||
srcCallback_ = callback;
|
||||
}
|
||||
|
||||
void DistributedInputTransportBase::RegisterSinkHandleSessionCallback(
|
||||
std::shared_ptr<DInputTransbaseSinkCallback> callback)
|
||||
{
|
||||
DHLOGI("RegisterTransbaseSinkRespCallback");
|
||||
sinkCallback_ = callback;
|
||||
}
|
||||
|
||||
int32_t DistributedInputTransportBase::CountSession(const std::string &remoteDevId)
|
||||
{
|
||||
return remoteDevSessionMap_.count(remoteDevId);
|
||||
}
|
||||
|
||||
void DistributedInputTransportBase::EraseSessionId(const std::string &remoteDevId)
|
||||
{
|
||||
remoteDevSessionMap_.erase(remoteDevId);
|
||||
}
|
||||
|
||||
int32_t DistributedInputTransportBase::OnSessionOpened(int32_t sessionId, int32_t result)
|
||||
{
|
||||
if (result != DH_SUCCESS) {
|
||||
DHLOGE("session open failed, sessionId: %d", sessionId);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
char mySessionName[SESSION_NAME_SIZE_MAX] = {0};
|
||||
char peerSessionName[SESSION_NAME_SIZE_MAX] = {0};
|
||||
char peerDevId[DEVICE_ID_SIZE_MAX] = {0};
|
||||
int32_t ret = GetMySessionName(sessionId, mySessionName, sizeof(mySessionName));
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGI("get my session name failed, session id is %d", sessionId);
|
||||
}
|
||||
ret = GetPeerSessionName(sessionId, peerSessionName, sizeof(peerSessionName));
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGI("get peer session name failed, session id is %d", sessionId);
|
||||
}
|
||||
ret = GetPeerDeviceId(sessionId, peerDevId, sizeof(peerDevId));
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGI("get peer device id failed, session id is %d", sessionId);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> sessionLock(operationMutex_);
|
||||
remoteDevSessionMap_[peerDevId] = sessionId;
|
||||
}
|
||||
|
||||
int32_t sessionSide = GetSessionSide(sessionId);
|
||||
DHLOGI("session open succeed, sessionId: %d, sessionSide:%d(1 is "
|
||||
"client side), deviceId:%s", sessionId, sessionSide, GetAnonyString(peerDevId).c_str());
|
||||
|
||||
DHLOGI("mySessionName:%s, peerSessionName:%s, peerDevId:%s",
|
||||
mySessionName, peerSessionName, GetAnonyString(peerDevId).c_str());
|
||||
{
|
||||
std::lock_guard<std::mutex> notifyLock(operationMutex_);
|
||||
channelStatusMap_[peerDevId] = true;
|
||||
openSessionWaitCond_.notify_all();
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DistributedInputTransportBase::OnSessionClosed(int32_t sessionId)
|
||||
{
|
||||
std::string deviceId = FindDeviceBySession(sessionId);
|
||||
DHLOGI("OnSessionClosed, sessionId: %d, deviceId:%s", sessionId, GetAnonyString(deviceId).c_str());
|
||||
{
|
||||
std::unique_lock<std::mutex> sessionLock(operationMutex_);
|
||||
if (CountSession(deviceId) > 0) {
|
||||
EraseSessionId(deviceId);
|
||||
}
|
||||
}
|
||||
channelStatusMap_.erase(deviceId);
|
||||
DistributedInputInject::GetInstance().StopInjectThread();
|
||||
DHLOGI("StopInjectThread successed");
|
||||
}
|
||||
|
||||
bool DistributedInputTransportBase::CheckRecivedData(const std::string& message)
|
||||
{
|
||||
nlohmann::json recMsg = nlohmann::json::parse(message, nullptr, false);
|
||||
if (recMsg.is_discarded()) {
|
||||
DHLOGE("OnBytesReceived jsonStr error.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (recMsg.contains(DINPUT_SOFTBUS_KEY_CMD_TYPE) != true) {
|
||||
DHLOGE("OnBytesReceived message:%s is error, not contain cmdType.", SetAnonyId(message).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (recMsg[DINPUT_SOFTBUS_KEY_CMD_TYPE].is_number() != true) {
|
||||
DHLOGE("OnBytesReceived cmdType is not number type.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DistributedInputTransportBase::OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen)
|
||||
{
|
||||
DHLOGI("OnBytesReceived, sessionId: %d, dataLen:%d", sessionId, dataLen);
|
||||
if (sessionId < 0 || data == nullptr || dataLen <= 0) {
|
||||
DHLOGE("OnBytesReceived param check failed");
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *buf = reinterpret_cast<uint8_t *>(calloc(dataLen + 1, sizeof(uint8_t)));
|
||||
if (buf == nullptr) {
|
||||
DHLOGE("OnBytesReceived: malloc memory failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (memcpy_s(buf, dataLen + 1, reinterpret_cast<const uint8_t *>(data), dataLen) != EOK) {
|
||||
DHLOGE("OnBytesReceived: memcpy memory failed");
|
||||
free(buf);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string message(buf, buf + dataLen);
|
||||
DHLOGI("OnBytesReceived message:%s.", SetAnonyId(message).c_str());
|
||||
HandleSession(sessionId, message);
|
||||
|
||||
free(buf);
|
||||
DHLOGI("OnBytesReceived completed");
|
||||
return;
|
||||
}
|
||||
|
||||
void DistributedInputTransportBase::HandleSession(int32_t sessionId, const std::string& message)
|
||||
{
|
||||
if (CheckRecivedData(message) != true) {
|
||||
return;
|
||||
}
|
||||
nlohmann::json recMsg = nlohmann::json::parse(message, nullptr, false);
|
||||
uint32_t cmdType = recMsg[DINPUT_SOFTBUS_KEY_CMD_TYPE];
|
||||
if (cmdType == TRANS_SINK_MSG_LATENCY) {
|
||||
CalculateLatency(sessionId);
|
||||
return;
|
||||
}
|
||||
if (cmdType < TRANS_MSG_SRC_SINK_SPLIT) {
|
||||
srcCallback_->HandleSessionData(sessionId, message);
|
||||
return;
|
||||
}
|
||||
if (cmdType > TRANS_MSG_SRC_SINK_SPLIT) {
|
||||
sinkCallback_->HandleSessionData(sessionId, message);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DistributedInputTransportBase::LatencyCount(const std::string& deviceId)
|
||||
{
|
||||
std::unique_lock<std::mutex> sessionLock(operationMutex_);
|
||||
if (CountSession(deviceId) <= 0) {
|
||||
DHLOGE("LatencyCount error, not find this device:%s.", GetAnonyString(deviceId).c_str());
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_LATENCY_FAIL;
|
||||
}
|
||||
|
||||
int32_t sessionId = GetSessionIdByDeviceId(deviceId);
|
||||
nlohmann::json jsonStr;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_LATENCY;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId;
|
||||
std::string smsg = jsonStr.dump();
|
||||
int32_t ret = SendMsg(sessionId, smsg);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("LatencyCount deviceId:%s, sessionId: %d, smsg:%s, SendMsg error, ret:%d.",
|
||||
GetAnonyString(deviceId).c_str(), sessionId, SetAnonyId(smsg).c_str(), ret);
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_LATENCY_FAIL;
|
||||
}
|
||||
|
||||
DHLOGI("LatencyCount deviceId:%s, sessionId: %d, smsg:%s.",
|
||||
GetAnonyString(deviceId).c_str(), sessionId, SetAnonyId(smsg).c_str());
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DistributedInputTransportBase::StartLatencyCount(const std::string& deviceId)
|
||||
{
|
||||
DHLOGI("start");
|
||||
while (isLatencyThreadRunning_.load()) {
|
||||
if (sendNum_ >= INPUT_LATENCY_DELAY_TIMES) {
|
||||
uint64_t latency = (uint64_t)(deltaTimeAll_ / 2 / INPUT_LATENCY_DELAY_TIMES);
|
||||
DHLOGI("LatencyCount average single-channel latency is %d us, send times is %d, recive times is %d, " +
|
||||
"each RTT latency details is %s", latency, sendNum_, recvNum_, eachLatencyDetails_.c_str());
|
||||
deltaTimeAll_ = 0;
|
||||
sendNum_ = 0;
|
||||
recvNum_ = 0;
|
||||
eachLatencyDetails_ = "";
|
||||
}
|
||||
sendTime_ = GetCurrentTime();
|
||||
LatencyCount(deviceId);
|
||||
sendNum_ += 1;
|
||||
usleep(INPUT_LATENCY_DELAYTIME_US);
|
||||
}
|
||||
DHLOGI("end");
|
||||
}
|
||||
|
||||
void DistributedInputTransportBase::StartLatencyThread(const std::string& deviceId)
|
||||
{
|
||||
DHLOGI("start");
|
||||
isLatencyThreadRunning_.store(true);
|
||||
latencyThread_ = std::thread(&DistributedInputTransportBase::StartLatencyCount, this, deviceId);
|
||||
DHLOGI("end");
|
||||
}
|
||||
|
||||
void DistributedInputTransportBase::StopLatencyThread()
|
||||
{
|
||||
DHLOGI("start");
|
||||
isLatencyThreadRunning_.store(false);
|
||||
if (latencyThread_.joinable()) {
|
||||
latencyThread_.join();
|
||||
}
|
||||
DHLOGI("end");
|
||||
}
|
||||
|
||||
void DistributedInputTransportBase::CalculateLatency(int32_t sessionId)
|
||||
{
|
||||
DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_LATENCY.");
|
||||
std::string deviceId = FindDeviceBySession(sessionId);
|
||||
if (deviceId.empty()) {
|
||||
DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_LATENCY, deviceId is error.");
|
||||
return;
|
||||
}
|
||||
|
||||
deltaTime_ = GetCurrentTime() - sendTime_;
|
||||
deltaTimeAll_ += deltaTime_;
|
||||
recvNum_ += 1;
|
||||
eachLatencyDetails_ += (std::to_string(deltaTime_) + DINPUT_SPLIT_COMMA);
|
||||
}
|
||||
|
||||
// send message by sessionId (channel opened)
|
||||
int32_t DistributedInputTransportBase::SendMsg(int32_t sessionId, std::string &message)
|
||||
{
|
||||
DHLOGD("start SendMsg");
|
||||
if (message.size() > MSG_MAX_SIZE) {
|
||||
DHLOGE("SendMessage error: message.size() > MSG_MAX_SIZE");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE;
|
||||
}
|
||||
uint8_t *buf = reinterpret_cast<uint8_t *>(calloc((MSG_MAX_SIZE), sizeof(uint8_t)));
|
||||
if (buf == nullptr) {
|
||||
DHLOGE("SendMsg: malloc memory failed");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE;
|
||||
}
|
||||
int32_t outLen = 0;
|
||||
if (memcpy_s(buf, MSG_MAX_SIZE, reinterpret_cast<const uint8_t *>(message.c_str()), message.size()) != EOK) {
|
||||
DHLOGE("SendMsg: memcpy memory failed");
|
||||
free(buf);
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE;
|
||||
}
|
||||
outLen = static_cast<int32_t>(message.size());
|
||||
int32_t ret = SendBytes(sessionId, buf, outLen);
|
||||
free(buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DistributedInputTransportBase::GetSessionIdByDeviceId(const std::string &srcId)
|
||||
{
|
||||
std::map<std::string, int32_t>::iterator it = remoteDevSessionMap_.find(srcId);
|
||||
if (it != remoteDevSessionMap_.end()) {
|
||||
return it->second;
|
||||
}
|
||||
DHLOGE("get session id failed, srcId = %s", GetAnonyString(srcId).c_str());
|
||||
return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_GET_SESSIONID_FAIL;
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
Reference in New Issue
Block a user