diff --git a/services/dtbschedmgr/include/continue/dsched_continue.h b/services/dtbschedmgr/include/continue/dsched_continue.h index d95e521b..a51d90d7 100644 --- a/services/dtbschedmgr/include/continue/dsched_continue.h +++ b/services/dtbschedmgr/include/continue/dsched_continue.h @@ -209,6 +209,8 @@ private: void UpdateState(DSchedContinueStateType stateType); private: + static constexpr int32_t INVALID_SESSION_ID = -1; + std::shared_ptr stateMachine_; std::shared_ptr eventHandler_; std::condition_variable eventCon_; @@ -221,7 +223,7 @@ private: int32_t direction_ = 0; DSchedContinueInfo continueInfo_; bool isSourceExit_ = true; - int32_t softbusSessionId_ = 0; + int32_t softbusSessionId_ = INVALID_SESSION_ID; sptr callback_ = nullptr; EventNotify eventData_; }; diff --git a/services/dtbschedmgr/include/softbus_adapter/transport/dsched_transport_softbus_adapter.h b/services/dtbschedmgr/include/softbus_adapter/transport/dsched_transport_softbus_adapter.h index b56b97d0..0e2f70f3 100644 --- a/services/dtbschedmgr/include/softbus_adapter/transport/dsched_transport_softbus_adapter.h +++ b/services/dtbschedmgr/include/softbus_adapter/transport/dsched_transport_softbus_adapter.h @@ -47,7 +47,7 @@ class DSchedTransportSoftbusAdapter { DECLARE_SINGLE_INSTANCE_BASE(DSchedTransportSoftbusAdapter); public: int32_t InitChannel(); - int32_t ConnectDevice(const std::string &peerDeviceId); + int32_t ConnectDevice(const std::string &peerDeviceId, int32_t &sessionId); void DisconnectDevice(const std::string &peerDeviceId); int32_t ReleaseChannel(); int32_t SendData(int32_t sessionId, int32_t dataType, std::shared_ptr dataBuffer); diff --git a/services/dtbschedmgr/src/continue/dsched_continue.cpp b/services/dtbschedmgr/src/continue/dsched_continue.cpp index 661e12ce..2eb688c1 100644 --- a/services/dtbschedmgr/src/continue/dsched_continue.cpp +++ b/services/dtbschedmgr/src/continue/dsched_continue.cpp @@ -462,17 +462,17 @@ int32_t DSchedContinue::ExecuteContinueReq(std::shared_ptr(); - int32_t ret = PackStartCmd(startCmd, wantParams); + ret = PackStartCmd(startCmd, wantParams); if (ret != ERR_OK) { HILOGE("ExecuteContinueReq pack start cmd failed, ret %{public}d", ret); return ret; diff --git a/services/dtbschedmgr/src/softbus_adapter/transport/dsched_transport_softbus_adapter.cpp b/services/dtbschedmgr/src/softbus_adapter/transport/dsched_transport_softbus_adapter.cpp index 4551776b..5a7824d3 100644 --- a/services/dtbschedmgr/src/softbus_adapter/transport/dsched_transport_softbus_adapter.cpp +++ b/services/dtbschedmgr/src/softbus_adapter/transport/dsched_transport_softbus_adapter.cpp @@ -109,7 +109,7 @@ int32_t DSchedTransportSoftbusAdapter::CreateServerSocket() return socket; } -int32_t DSchedTransportSoftbusAdapter::ConnectDevice(const std::string &peerDeviceId) +int32_t DSchedTransportSoftbusAdapter::ConnectDevice(const std::string &peerDeviceId, int32_t &sessionId) { HILOGI("try to connect peer: %{public}s.", GetAnonymStr(peerDeviceId).c_str()); { @@ -119,7 +119,8 @@ int32_t DSchedTransportSoftbusAdapter::ConnectDevice(const std::string &peerDevi if (iter->second != nullptr && peerDeviceId == iter->second->GetPeerDeviceId()) { HILOGI("peer device already connected"); iter->second->OnConnect(); - return iter->first; + sessionId = iter->first; + return ERR_OK; } } } @@ -132,7 +133,8 @@ int32_t DSchedTransportSoftbusAdapter::ConnectDevice(const std::string &peerDevi ret = DSchedAllConnectManager::GetInstance().ApplyAdvanceResource(peerDeviceId, reqInfoSets); if (ret != ERR_OK) { HILOGE("Apply advance resource fail, ret: %{public}d.", ret); - return INVALID_SESSION_ID; + sessionId = INVALID_SESSION_ID; + return ret; } ret = DSchedAllConnectManager::GetInstance().PublishServiceState(peerDeviceId, "", SCM_PREPARE); @@ -142,12 +144,11 @@ int32_t DSchedTransportSoftbusAdapter::ConnectDevice(const std::string &peerDevi } #endif - int32_t sessionId = INVALID_SESSION_ID; ret = AddNewPeerSession(peerDeviceId, sessionId); if (ret != ERR_OK || sessionId <= 0) { HILOGE("Add new peer connect session fail, ret: %{public}d, sessionId: %{public}d.", ret, sessionId); } - return sessionId; + return ret; } int32_t DSchedTransportSoftbusAdapter::AddNewPeerSession(const std::string &peerDeviceId, int32_t &sessionId)