增加sessionsatate回调

Signed-off-by: litiangang4 <litiangang4@huawei.com>
This commit is contained in:
litiangang4
2023-08-25 11:31:19 +08:00
parent 5bed52aaaa
commit 56df04c600
24 changed files with 442 additions and 6 deletions
+5
View File
@@ -109,6 +109,7 @@ namespace DistributedInput {
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_SIMULATION_EVENT_CALLBACK_ERR = -65037;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_DH_FWK_KIT_IS_NULL = -65038;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_NODE_LISTENER_CALLBACK_ERR = -65039;
constexpr int32_t ERR_DH_INPUT_SRC_MGR_SESSION_STATE_CB_IS_NULL = -65040;
// handler error code
constexpr int32_t ERR_DH_INPUT_SINK_HANDLER_INIT_SINK_SA_FAIL = -66000;
@@ -172,6 +173,10 @@ namespace DistributedInput {
constexpr int32_t ERR_DH_INPUT_SINK_PROXY_REGISTER_SHARING_DHID_LISTENER_FAIL = -67054;
constexpr int32_t ERR_DH_INPUT_SINK_STUB_REGISTER_SHARING_DHID_LISTENER_FAIL = -67055;
constexpr int32_t ERR_DH_INPUT_SINK_PROXY_REGISTER_GETSINKSCREENINFOS_FAIL = -67056;
constexpr int32_t ERR_DH_INPUT_CLIENT_REGISTER_SESSION_STATE_FAIL = -67057;
constexpr int32_t ERR_DH_INPUT_CLIENT_UNREGISTER_SESSION_STATE_FAIL = -67058;
constexpr int32_t ERR_DH_INPUT_SRC_STUB_REGISTER_SESSION_STATE_FAIL = -67059;
constexpr int32_t ERR_DH_INPUT_SRC_STUB_UNREGISTER_SESSION_STATE_FAIL = -67060;
// Hidump Helper error code
constexpr int32_t ERR_DH_INPUT_HIDUMP_INVALID_ARGS = -68000;
@@ -45,6 +45,8 @@ enum class IDInputSourceInterfaceCode : uint32_t {
REGISTER_SIMULATION_EVENT_LISTENER = 0xf017U,
UNREGISTER_SIMULATION_EVENT_LISTENER = 0xf018U,
SYNC_NODE_INFO_REMOTE_INPUT = 0xf019U,
REGISTER_SESSION_STATE_CB = 0xf01aU,
UNREGISTER_SESSION_STATE_CB = 0xf01bU,
};
/* SAID: 4810 */
@@ -35,6 +35,7 @@
#include "i_unregister_d_input_call_back.h"
#include "i_input_node_listener.h"
#include "i_simulation_event_listener.h"
#include "i_session_state_callback.h"
namespace OHOS {
namespace DistributedHardware {
@@ -98,6 +99,8 @@ public:
const std::string &nodeDesc) = 0;
virtual int32_t RegisterSimulationEventListener(sptr<ISimulationEventListener> listener) = 0;
virtual int32_t UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener) = 0;
virtual int32_t RegisterSessionStateCb(sptr<ISessionStateCallback> callback) = 0;
virtual int32_t UnregisterSessionStateCb() = 0;
};
} // namespace DistributedInput
} // namespace DistributedHardware
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef I_REGISTER_SESSION_STATE_CALLBACK_H
#define I_REGISTER_SESSION_STATE_CALLBACK_H
#include <string>
#include <iremote_broker.h>
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
class ISessionStateCallback : public IRemoteBroker {
public:
virtual void OnResult(const std::string &devId, const uint32_t status) = 0;
enum class Message {
RESULT,
};
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.ISessionStateCallback");
};
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
#endif // I_REGISTER_SESSION_STATE_CALLBACK_H
+3 -2
View File
@@ -12,8 +12,7 @@
# limitations under the License.
import("//build/ohos.gni")
import(
"//foundation/distributedhardware/distributed_input/distributedinput.gni")
import("../../distributedinput.gni")
config("input_sdk_public_config") {
include_dirs = [
@@ -57,6 +56,8 @@ ohos_shared_library("libdinput_sdk") {
"${ipc_path}/src/prepare_d_input_call_back_stub.cpp",
"${ipc_path}/src/register_d_input_call_back_proxy.cpp",
"${ipc_path}/src/register_d_input_call_back_stub.cpp",
"${ipc_path}/src/register_session_state_callback_proxy.cpp",
"${ipc_path}/src/register_session_state_callback_stub.cpp",
"${ipc_path}/src/sharing_dhid_listener_proxy.cpp",
"${ipc_path}/src/sharing_dhid_listener_stub.cpp",
"${ipc_path}/src/simulation_event_listener_proxy.cpp",
@@ -30,6 +30,7 @@
#include "i_start_stop_result_call_back.h"
#include "i_unregister_d_input_call_back.h"
#include "i_unprepare_d_input_call_back.h"
#include "i_session_state_callback.h"
namespace OHOS {
namespace DistributedHardware {
@@ -80,6 +81,9 @@ public:
static int32_t UnregisterInputNodeListener(sptr<InputNodeListener> listener);
static int32_t RegisterSimulationEventListener(sptr<ISimulationEventListener> listener);
static int32_t UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener);
static int32_t RegisterSessionStateCb(sptr<ISessionStateCallback> callback);
static int32_t UnregisterSessionStateCb();
};
} // namespace DistributedInput
} // namespace DistributedHardware
@@ -129,6 +129,15 @@ int32_t DistributedInputKit::UnregisterSimulationEventListener(sptr<ISimulationE
{
return DistributedInputClient::GetInstance().UnregisterSimulationEventListener(listener);
}
int32_t DistributedInputKit::RegisterSessionStateCb(sptr<ISessionStateCallback> callback)
{
return DistributedInputClient::GetInstance().RegisterSessionStateCb(callback);
}
int32_t DistributedInputKit::UnregisterSessionStateCb()
{
return DistributedInputClient::GetInstance().UnregisterSessionStateCb();
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
@@ -107,6 +107,9 @@ public:
int32_t RegisterSimulationEventListener(sptr<ISimulationEventListener> listener);
int32_t UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener);
int32_t RegisterSessionStateCb(sptr<ISessionStateCallback> callback);
int32_t UnregisterSessionStateCb();
void CheckSourceRegisterCallback();
void CheckWhiteListCallback();
void CheckNodeMonitorCallback();
@@ -84,6 +84,9 @@ public:
int32_t RegisterSimulationEventListener(sptr<ISimulationEventListener> listener) override;
int32_t UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener) override;
int32_t RegisterSessionStateCb(sptr<ISessionStateCallback> callback) override;
int32_t UnregisterSessionStateCb() override;
private:
bool SendRequest(const uint32_t code, MessageParcel &data, MessageParcel &reply);
@@ -59,6 +59,8 @@ private:
int32_t HandleSyncNodeInfoRemoteInput(MessageParcel &data, MessageParcel &reply);
int32_t HandleRegisterSimulationEventListener(MessageParcel &data, MessageParcel &reply);
int32_t HandleUnregisterSimulationEventListener(MessageParcel &data, MessageParcel &reply);
int32_t HandleRegisterSessionStateCb(MessageParcel &data, MessageParcel &reply);
int32_t HandleUnregisterSessionStateCb(MessageParcel &data, MessageParcel &reply);
DISALLOW_COPY_AND_MOVE(DistributedInputSourceStub);
private:
std::atomic<bool> sourceManagerInitFlag_ {false};
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef REGISTER_SESSION_STATE_CALLBACK_PROXY_H
#define REGISTER_SESSION_STATE_CALLBACK_PROXY_H
#include "i_session_state_callback.h"
#include <string>
#include "iremote_proxy.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
class RegisterSessionStateCallbackProxy : public IRemoteProxy<ISessionStateCallback> {
public:
explicit RegisterSessionStateCallbackProxy(const sptr<IRemoteObject> &object);
~RegisterSessionStateCallbackProxy() override;
void OnResult(const std::string &deviceId, const uint32_t status) override;
private:
static inline BrokerDelegator<RegisterSessionStateCallbackProxy> delegator_;
};
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
#endif // REGISTER_SESSION_STATE_CALLBACK_PROXY_H
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef REGISTER_SESSION_STATE_CALLBACK_STUB_H
#define REGISTER_SESSION_STATE_CALLBACK_STUB_H
#include "i_session_state_callback.h"
#include <string>
#include "iremote_stub.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
class RegisterSessionStateCallbackStub : public IRemoteStub<ISessionStateCallback> {
public:
RegisterSessionStateCallbackStub();
~RegisterSessionStateCallbackStub() override;
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
private:
DISALLOW_COPY_AND_MOVE(RegisterSessionStateCallbackStub);
};
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
#endif // REGISTER_SESSION_STATE_CALLBACK_STUB_H
@@ -796,6 +796,28 @@ sptr<IDistributedSinkInput> DistributedInputClient::GetRemoteDInput(const std::s
}
return iface_cast<IDistributedSinkInput>(object);
}
int32_t DistributedInputClient::RegisterSessionStateCb(sptr<ISessionStateCallback> callback)
{
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("DinputStart client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (callback == nullptr) {
DHLOGE("RegisterSessionStateCb callback is null.");
return ERR_DH_INPUT_CLIENT_REGISTER_SESSION_STATE_FAIL;
}
return DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSessionStateCb(callback);
}
int32_t DistributedInputClient::UnregisterSessionStateCb()
{
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("DinputStart client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
return DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterSessionStateCb();
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
@@ -702,6 +702,47 @@ int32_t DistributedInputSourceProxy::UnregisterSimulationEventListener(sptr<ISim
return result;
}
int32_t DistributedInputSourceProxy::RegisterSessionStateCb(sptr<ISessionStateCallback> callback)
{
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
DHLOGE("RegisterSessionStateCb write token valid failed");
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
}
if (!data.WriteRemoteObject(callback->AsObject())) {
DHLOGE("RegisterSessionStateCb write callback failed");
return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
}
MessageParcel reply;
int32_t result = ERR_DH_INPUT_SRC_STUB_REGISTER_SESSION_STATE_FAIL;
bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::REGISTER_SESSION_STATE_CB),
data, reply);
if (ret) {
result = reply.ReadInt32();
}
return result;
}
int32_t DistributedInputSourceProxy::UnregisterSessionStateCb()
{
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
DHLOGE("UnregisterSessionStateCb write token valid failed");
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
}
MessageParcel reply;
int32_t result = ERR_DH_INPUT_SRC_STUB_UNREGISTER_SESSION_STATE_FAIL;
bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::UNREGISTER_SESSION_STATE_CB),
data, reply);
if (ret) {
result = reply.ReadInt32();
}
return result;
}
bool DistributedInputSourceProxy::SendRequest(const uint32_t code, MessageParcel &data, MessageParcel &reply)
{
sptr<IRemoteObject> remote = Remote();
@@ -77,6 +77,10 @@ void DistributedInputSourceStub::RegRespFunMap()
&DistributedInputSourceStub::HandleUnregisterSimulationEventListener;
memberFuncMap_[static_cast<uint32_t>(IDInputSourceInterfaceCode::SYNC_NODE_INFO_REMOTE_INPUT)] =
&DistributedInputSourceStub::HandleSyncNodeInfoRemoteInput;
memberFuncMap_[static_cast<uint32_t>(IDInputSourceInterfaceCode::REGISTER_SESSION_STATE_CB)] =
&DistributedInputSourceStub::HandleRegisterSessionStateCb;
memberFuncMap_[static_cast<uint32_t>(IDInputSourceInterfaceCode::UNREGISTER_SESSION_STATE_CB)] =
&DistributedInputSourceStub::HandleUnregisterSessionStateCb;
}
int32_t DistributedInputSourceStub::HandleInitDistributedHardware(MessageParcel &reply)
{
@@ -523,6 +527,33 @@ int32_t DistributedInputSourceStub::HandleUnregisterSimulationEventListener(Mess
return DH_SUCCESS;
}
int32_t DistributedInputSourceStub::HandleRegisterSessionStateCb(MessageParcel &data, MessageParcel &reply)
{
sptr<ISessionStateCallback> callback = iface_cast<ISessionStateCallback>(data.ReadRemoteObject());
if (callback == nullptr) {
DHLOGE("HandleRegisterSessionStateCb failed, callback is nullptr.");
return ERR_DH_INPUT_POINTER_NULL;
}
int32_t ret = RegisterSessionStateCb(callback);
if (!reply.WriteInt32(ret)) {
DHLOGE("HandleRegisterSessionStateCb write ret failed, ret = %d", ret);
return ERR_DH_INPUT_SRC_STUB_REGISTER_SESSION_STATE_FAIL;
}
return DH_SUCCESS;
}
int32_t DistributedInputSourceStub::HandleUnregisterSessionStateCb(MessageParcel &data, MessageParcel &reply)
{
int32_t ret = UnregisterSessionStateCb();
if (!reply.WriteInt32(ret)) {
DHLOGE("HandleUnregisterSessionStateCb write ret failed, ret = %d", ret);
return ERR_DH_INPUT_SRC_STUB_UNREGISTER_SESSION_STATE_FAIL;
}
return DH_SUCCESS;
}
int32_t DistributedInputSourceStub::OnRemoteRequest(
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "register_session_state_callback_proxy.h"
#include "ipc_types.h"
#include "parcel.h"
#include "dinput_log.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
RegisterSessionStateCallbackProxy::RegisterSessionStateCallbackProxy(const sptr<IRemoteObject> &object)
: IRemoteProxy<ISessionStateCallback>(object)
{
}
RegisterSessionStateCallbackProxy::~RegisterSessionStateCallbackProxy()
{
}
void RegisterSessionStateCallbackProxy::OnResult(const std::string &deviceId, const uint32_t status)
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
return;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
DHLOGE("RegisterSessionStateCallbackProxy write token valid failed");
return;
}
if (!data.WriteString(deviceId)) {
return;
}
if (!data.WriteUint32(status)) {
return;
}
int32_t ret = remote->SendRequest(
static_cast<uint32_t>(ISessionStateCallback::Message::RESULT), data, reply, option);
if (ret != 0) {
return;
}
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "register_session_state_callback_stub.h"
#include "string_ex.h"
#include "constants_dinput.h"
#include "dinput_errcode.h"
#include "dinput_log.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
RegisterSessionStateCallbackStub::RegisterSessionStateCallbackStub()
{
}
RegisterSessionStateCallbackStub::~RegisterSessionStateCallbackStub()
{
}
int32_t RegisterSessionStateCallbackStub::OnRemoteRequest(
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
if (data.ReadInterfaceToken() != GetDescriptor()) {
DHLOGE("RegisterSessionStateCallbackStub read token valid failed");
return ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL;
}
ISessionStateCallback::Message msgCode = static_cast<ISessionStateCallback::Message>(code);
switch (msgCode) {
case ISessionStateCallback::Message::RESULT: {
std::string deviceId = data.ReadString();
uint32_t status = data.ReadUint32();
OnResult(deviceId, status);
break;
}
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
return DH_SUCCESS;
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
@@ -239,6 +239,19 @@ int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::UnregisterSimula
return DH_SUCCESS;
}
int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::RegisterSessionStateCb(
sptr<ISessionStateCallback> callback)
{
(void)callback;
return DH_SUCCESS;
}
int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::UnregisterSessionStateCb()
{
return DH_SUCCESS;
}
int32_t UnregisterSessionStateCb();
void DInputSourceCallBackTest::TestDInputSourceCallBackStub::OnResult(const std::string &deviceId,
const std::string &strJson)
{
@@ -33,6 +33,7 @@
#include "start_stop_d_inputs_call_back_stub.h"
#include "start_stop_result_call_back_stub.h"
#include "simulation_event_listener_stub.h"
#include "register_session_state_callback_stub.h"
namespace OHOS {
namespace DistributedHardware {
@@ -104,6 +105,8 @@ public:
const std::string &nodeDesc);
int32_t RegisterSimulationEventListener(sptr<ISimulationEventListener> listener);
int32_t UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener);
int32_t RegisterSessionStateCb(sptr<ISessionStateCallback> callback);
int32_t UnregisterSessionStateCb();
void OnResult(const std::string &deviceId, const std::string &strJson);
std::string deviceId_;
std::string strJson_;
+3 -2
View File
@@ -12,8 +12,7 @@
# limitations under the License.
import("//build/ohos.gni")
import(
"//foundation/distributedhardware/distributed_input/distributedinput.gni")
import("../../../distributedinput.gni")
ohos_shared_library("libdinput_source") {
include_dirs = [
@@ -60,6 +59,8 @@ ohos_shared_library("libdinput_source") {
"${ipc_path}/src/prepare_d_input_call_back_stub.cpp",
"${ipc_path}/src/register_d_input_call_back_proxy.cpp",
"${ipc_path}/src/register_d_input_call_back_stub.cpp",
"${ipc_path}/src/register_session_state_callback_proxy.cpp",
"${ipc_path}/src/register_session_state_callback_stub.cpp",
"${ipc_path}/src/sharing_dhid_listener_proxy.cpp",
"${ipc_path}/src/sharing_dhid_listener_stub.cpp",
"${ipc_path}/src/simulation_event_listener_proxy.cpp",
@@ -179,6 +179,10 @@ public:
const std::string &nodeDesc) override;
int32_t RegisterSimulationEventListener(sptr<ISimulationEventListener> listener) override;
int32_t UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener) override;
int32_t RegisterSessionStateCb(sptr<ISessionStateCallback> callback) override;
int32_t UnregisterSessionStateCb() override;
bool CheckRegisterParam(const std::string &devId, const std::string &dhId,
const std::string &parameters, sptr<IRegisterDInputCallback> callback);
bool CheckUnregisterParam(const std::string &devId, const std::string &dhId,
@@ -2064,6 +2064,21 @@ int32_t DistributedInputSourceManager::UnregisterSimulationEventListener(sptr<IS
return DH_SUCCESS;
}
int32_t DistributedInputSourceManager::RegisterSessionStateCb(sptr<ISessionStateCallback> callback)
{
if (callback == nullptr) {
DHLOGE("RegisterSessionStateCb callback is null.");
return ERR_DH_INPUT_CLIENT_UNREGISTER_SESSION_STATE_FAIL;
}
DistributedInputTransportBase::GetInstance().RegisterSessionStateCb(callback);
return DH_SUCCESS;
}
int32_t DistributedInputSourceManager::UnregisterSessionStateCb()
{
DistributedInputTransportBase::GetInstance().UnregisterSessionStateCb();
return DH_SUCCESS;
}
int32_t DistributedInputSourceManager::SyncNodeInfoRemoteInput(const std::string &userDevId, const std::string &dhId,
const std::string &nodeDesc)
{
@@ -33,6 +33,7 @@
#include "dinput_source_manager_callback.h"
#include "dinput_transbase_source_callback.h"
#include "dinput_transbase_sink_callback.h"
#include "i_session_state_callback.h"
namespace OHOS {
namespace DistributedHardware {
@@ -50,7 +51,8 @@ public:
void RegisterSrcHandleSessionCallback(std::shared_ptr<DInputTransbaseSourceCallback> callback);
void RegisterSinkHandleSessionCallback(std::shared_ptr<DInputTransbaseSinkCallback> callback);
void RegisterSourceManagerCallback(std::shared_ptr<DInputSourceManagerCallback> callback);
void RegisterSessionStateCb(sptr<ISessionStateCallback> callback);
void UnregisterSessionStateCb();
int32_t OnSessionOpened(int32_t sessionId, int32_t result);
void OnSessionClosed(int32_t sessionId);
void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen);
@@ -67,6 +69,7 @@ private:
bool CheckRecivedData(const std::string &message);
void HandleSession(int32_t sessionId, const std::string &message);
void Release();
void RunSessionStateCallback(const std::string &remoteDevId, const uint32_t sessionState);
private:
std::atomic<bool> isSessSerCreateFlag_ = false;
@@ -82,6 +85,7 @@ private:
std::shared_ptr<DInputTransbaseSourceCallback> srcCallback_;
std::shared_ptr<DInputTransbaseSinkCallback> sinkCallback_;
std::shared_ptr<DInputSourceManagerCallback> srcMgrCallback_;
sptr<ISessionStateCallback> SessionStateCallback_;
};
} // namespace DistributedInput
@@ -51,6 +51,8 @@ namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
const int32_t DINPUT_LINK_TYPE_MAX = 4;
const int32_t SESSION_STATUS_OPENED = 0;
const int32_t SESSION_STATUS_CLOSED = 1;
static SessionAttribute g_sessionAttr = {
.dataType = SessionType::TYPE_BYTES,
.linkTypeNum = DINPUT_LINK_TYPE_MAX,
@@ -284,6 +286,29 @@ void DistributedInputTransportBase::RegisterSourceManagerCallback(
srcMgrCallback_ = callback;
}
void DistributedInputTransportBase::RegisterSessionStateCb(sptr<ISessionStateCallback> callback)
{
DHLOGI("RegisterSessionStateCb");
SessionStateCallback_ = callback;
}
void DistributedInputTransportBase::UnregisterSessionStateCb()
{
DHLOGI("UnregisterSessionStateCb");
SessionStateCallback_ = nullptr;
}
void DistributedInputTransportBase::RunSessionStateCallback(const std::string &remoteDevId,
const uint32_t sessionState)
{
DHLOGI("RunSessionStateCallback start.");
if (SessionStateCallback_ != nullptr) {
SessionStateCallback_->OnResult(remoteDevId, sessionState);
return;
}
DHLOGI("RunSessionStateCallback SessionStateCallback_ is null.");
}
int32_t DistributedInputTransportBase::CountSession(const std::string &remoteDevId)
{
return remoteDevSessionMap_.count(remoteDevId);
@@ -346,7 +371,7 @@ int32_t DistributedInputTransportBase::OnSessionOpened(int32_t sessionId, int32_
channelStatusMap_[peerDevId] = true;
openSessionWaitCond_.notify_all();
}
RunSessionStateCallback(peerDevId, SESSION_STATUS_OPENED);
return DH_SUCCESS;
}
@@ -354,6 +379,7 @@ void DistributedInputTransportBase::OnSessionClosed(int32_t sessionId)
{
std::string deviceId = GetDevIdBySessionId(sessionId);
DHLOGI("OnSessionClosed, sessionId: %d, deviceId:%s", sessionId, GetAnonyString(deviceId).c_str());
RunSessionStateCallback(deviceId, SESSION_STATUS_CLOSED);
std::shared_ptr<DistributedHardwareFwkKit> dhFwkKit = DInputContext::GetInstance().GetDHFwkKit();
if (dhFwkKit != nullptr) {