From bab9ddff502df69ac8a15690a0ef03920aeef9f8 Mon Sep 17 00:00:00 2001 From: LongestDistance Date: Fri, 8 Nov 2024 15:06:47 +0800 Subject: [PATCH] =?UTF-8?q?TicketNo:#IB2R8O=20Description:=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=20Signed-off-by:=20LongestDistance=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/cast_session_impl_proxy.cpp | 96 +++++------ client/src/mirror_player.cpp | 53 +++--- client/src/mirror_player_impl_proxy.cpp | 154 +++++++++--------- .../include/cast_session_manager_service.h | 8 + service/src/cast_session_manager_service.cpp | 26 +++ .../src/cast_session_manager_service_stub.cpp | 24 ++- .../include/connection_manager.h | 27 +-- .../include}/connection_manager_listener.h | 87 ++++++---- 8 files changed, 265 insertions(+), 210 deletions(-) rename {common/include/private => service/src/device_manager/include}/connection_manager_listener.h (60%) diff --git a/client/src/cast_session_impl_proxy.cpp b/client/src/cast_session_impl_proxy.cpp index 1e41e6f..55f5b73 100644 --- a/client/src/cast_session_impl_proxy.cpp +++ b/client/src/cast_session_impl_proxy.cpp @@ -157,6 +157,29 @@ int32_t CastSessionImplProxy::StartAuth(const AuthInfo &authInfo) return reply.ReadInt32(); } +int32_t CastSessionImplProxy::Release() +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(GetDescriptor())) { + CLOGE("Failed to write the interface token"); + return CAST_ENGINE_ERROR; + } + + int32_t ret = Remote()->SendRequest(RELEASE, data, reply, option); + if (ret == ERR_UNKNOWN_TRANSACTION) { + CLOGE("No permission when releasing the cast session"); + return ERR_NO_PERMISSION; + } else if (ret != ERR_NONE) { + CLOGE("Failed to send ipc request when releasing the cast session"); + return CAST_ENGINE_ERROR; + } + + return reply.ReadInt32(); +} + int32_t CastSessionImplProxy::GetSessionId(std::string &sessionId) { MessageParcel data, reply; @@ -284,6 +307,31 @@ int32_t CastSessionImplProxy::SetSessionProperty(const CastSessionProperty &prop return reply.ReadInt32(); } +int32_t CastSessionImplProxy::SetCastMode(CastMode mode, std::string &jsonParam) +{ + MessageParcel data, reply; + MessageOption option; + + if (!data.WriteInterfaceToken(GetDescriptor())) { + CLOGE("Failed to write the interface token"); + return CAST_ENGINE_ERROR; + } + if (!data.WriteInt32(static_cast(mode))) { + CLOGE("Failed to write cast mode"); + return CAST_ENGINE_ERROR; + } + if (!data.WriteString(jsonParam)) { + CLOGE("Failed to write json param"); + return CAST_ENGINE_ERROR; + } + if (Remote()->SendRequest(SET_CAST_MODE, data, reply, option) != ERR_NONE) { + CLOGE("Failed to send ipc request when set cast mode"); + return CAST_ENGINE_ERROR; + } + + return reply.ReadInt32(); +} + int32_t CastSessionImplProxy::CreateMirrorPlayer(sptr &mirrorPlayer) { MessageParcel data; @@ -348,54 +396,6 @@ int32_t CastSessionImplProxy::CreateStreamPlayer(sptr &streamP return errorCode; } -int32_t CastSessionImplProxy::Release() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(GetDescriptor())) { - CLOGE("Failed to write the interface token"); - return CAST_ENGINE_ERROR; - } - - int32_t ret = Remote()->SendRequest(RELEASE, data, reply, option); - if (ret == ERR_UNKNOWN_TRANSACTION) { - CLOGE("No permission when releasing the cast session"); - return ERR_NO_PERMISSION; - } else if (ret != ERR_NONE) { - CLOGE("Failed to send ipc request when releasing the cast session"); - return CAST_ENGINE_ERROR; - } - - return reply.ReadInt32(); -} - -int32_t CastSessionImplProxy::SetCastMode(CastMode mode, std::string &jsonParam) -{ - MessageParcel data, reply; - MessageOption option; - - if (!data.WriteInterfaceToken(GetDescriptor())) { - CLOGE("Failed to write the interface token"); - return CAST_ENGINE_ERROR; - } - if (!data.WriteInt32(static_cast(mode))) { - CLOGE("Failed to write cast mode"); - return CAST_ENGINE_ERROR; - } - if (!data.WriteString(jsonParam)) { - CLOGE("Failed to write json param"); - return CAST_ENGINE_ERROR; - } - if (Remote()->SendRequest(SET_CAST_MODE, data, reply, option) != ERR_NONE) { - CLOGE("Failed to send ipc request when set cast mode"); - return CAST_ENGINE_ERROR; - } - - return reply.ReadInt32(); -} - int32_t CastSessionImplProxy::NotifyEvent(EventId eventId, std::string &jsonParam) { MessageParcel data, reply; diff --git a/client/src/mirror_player.cpp b/client/src/mirror_player.cpp index 6c6bb9f..1882018 100644 --- a/client/src/mirror_player.cpp +++ b/client/src/mirror_player.cpp @@ -49,31 +49,6 @@ int32_t MirrorPlayer::Pause(const std::string &deviceId) return proxy_ ? proxy_->Pause(deviceId) : CAST_ENGINE_ERROR; } -int32_t MirrorPlayer::SetSurface(const std::string &surfaceId) -{ - errno = 0; - uint64_t surfaceUniqueId = static_cast(std::strtoll(surfaceId.c_str(), nullptr, 10)); - if (errno == ERANGE) { - return ERR_INVALID_PARAM; - } - - sptr surface = SurfaceUtils::GetInstance()->GetSurface(surfaceUniqueId); - if (!surface) { - return CAST_ENGINE_ERROR; - } - sptr producer = surface->GetProducer(); - if (!producer) { - CLOGE("producer is null"); - return CAST_ENGINE_ERROR; - } - return proxy_ ? proxy_->SetSurface(producer) : CAST_ENGINE_ERROR; -} - -int32_t MirrorPlayer::SetAppInfo(const AppInfo &appInfo) -{ - return proxy_ ? proxy_->SetAppInfo(appInfo) : CAST_ENGINE_ERROR; -} - int32_t MirrorPlayer::DeliverInputEvent(OHRemoteControlEvent event) { return proxy_ ? proxy_->DeliverInputEvent(event) : CAST_ENGINE_ERROR; @@ -99,6 +74,34 @@ int32_t MirrorPlayer::GetDisplayId(std::string &displayId) return proxy_ ? proxy_->GetDisplayId(displayId) : CAST_ENGINE_ERROR; } +int32_t MirrorPlayer::SetAppInfo(const AppInfo &appInfo) +{ + return proxy_ ? proxy_->SetAppInfo(appInfo) : CAST_ENGINE_ERROR; +} + +int32_t MirrorPlayer::SetSurface(const std::string &surfaceId) +{ + errno = 0; + char *end = nullptr; + uint64_t surfaceUniqueId = static_cast(std::strtoll(surfaceId.c_str(), &end, 10)); + if (errno == ERANGE || (surfaceUniqueId == 0 && *end != '\0')) { + CLOGE("Failed to strtoll, errno: %{public}d", errno); + return ERR_INVALID_PARAM; + } + + sptr surface = SurfaceUtils::GetInstance()->GetSurface(surfaceUniqueId); + if (!surface) { + CLOGE("surface is null, surface uniqueId %{public}" PRIu64, surfaceUniqueId); + return CAST_ENGINE_ERROR; + } + sptr producer = surface->GetProducer(); + if (!producer) { + CLOGE("producer is null"); + return CAST_ENGINE_ERROR; + } + return proxy_ ? proxy_->SetSurface(producer) : CAST_ENGINE_ERROR; +} + } // namespace CastEngineClient } // namespace CastEngine } // namespace OHOS \ No newline at end of file diff --git a/client/src/mirror_player_impl_proxy.cpp b/client/src/mirror_player_impl_proxy.cpp index f48b65c..28a07fd 100644 --- a/client/src/mirror_player_impl_proxy.cpp +++ b/client/src/mirror_player_impl_proxy.cpp @@ -89,58 +89,6 @@ int32_t MirrorPlayerImplProxy::Pause(const std::string &deviceId) return reply.ReadInt32(); } -int32_t MirrorPlayerImplProxy::SetSurface(sptr producer) -{ - MessageParcel data, reply; - MessageOption option; - - if (!data.WriteInterfaceToken(GetDescriptor())) { - CLOGE("Failed to write the interface token"); - return CAST_ENGINE_ERROR; - } - if (!data.WriteRemoteObject(producer->AsObject())) { - CLOGE("Failed to write surface producer"); - return CAST_ENGINE_ERROR; - } - - int32_t ret = Remote()->SendRequest(SET_SURFACE, data, reply, option); - if (ret == ERR_UNKNOWN_TRANSACTION) { - CLOGE("No permission when setting surface"); - return ERR_NO_PERMISSION; - } else if (ret != ERR_NONE) { - CLOGE("Failed to send ipc request when setting surface"); - return CAST_ENGINE_ERROR; - } - - return reply.ReadInt32(); -} - -int32_t MirrorPlayerImplProxy::SetAppInfo(const AppInfo &appInfo) -{ - MessageParcel data, reply; - MessageOption option; - - if (!data.WriteInterfaceToken(GetDescriptor())) { - CLOGE("Failed to write the interface token"); - return CAST_ENGINE_ERROR; - } - if (!data.WriteInt32(appInfo.appUid) || !data.WriteUint32(appInfo.appTokenId) || - !data.WriteInt32(appInfo.appPid)) { - CLOGE("Failed to write appInfo"); - return CAST_ENGINE_ERROR; - } - CLOGI("start set app info impl proxy"); - int32_t ret = Remote()->SendRequest(SET_APP_INFO, data, reply, option); - if (ret == ERR_UNKNOWN_TRANSACTION) { - CLOGE("No permission when setting surface"); - return ERR_NO_PERMISSION; - } else if (ret != ERR_NONE) { - CLOGE("Failed to send ipc request when setting surface"); - return CAST_ENGINE_ERROR; - } - return reply.ReadInt32(); -} - int32_t MirrorPlayerImplProxy::DeliverInputEvent(const OHRemoteControlEvent &event) { MessageParcel data, reply; @@ -227,30 +175,6 @@ int32_t MirrorPlayerImplProxy::Release() return reply.ReadInt32(); } -int32_t MirrorPlayerImplProxy::GetDisplayId(std::string &displayId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - displayId = std::string{}; - if (!data.WriteInterfaceToken(GetDescriptor())) { - CLOGE("Failed to write the interface token"); - return CAST_ENGINE_ERROR; - } - - int32_t ret = Remote()->SendRequest(GET_DISPLAYID, data, reply, option); - if (ret == ERR_UNKNOWN_TRANSACTION) { - CLOGE("No permission when getDisplayId"); - return ERR_NO_PERMISSION; - } else if (ret != ERR_NONE) { - CLOGE("Failed to send ipc request when getDisplayId"); - return CAST_ENGINE_ERROR; - } - int32_t errorCode = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(errorCode != CAST_ENGINE_SUCCESS, errorCode, "CastEngine Errors"); - displayId = reply.ReadString(); - return errorCode; -} int32_t MirrorPlayerImplProxy::ResizeVirtualScreen(uint32_t width, uint32_t height) { @@ -277,6 +201,84 @@ int32_t MirrorPlayerImplProxy::ResizeVirtualScreen(uint32_t width, uint32_t heig return reply.ReadInt32(); } + +int32_t MirrorPlayerImplProxy::GetDisplayId(std::string &displayId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + displayId = std::string{}; + if (!data.WriteInterfaceToken(GetDescriptor())) { + CLOGE("Failed to write the interface token"); + return CAST_ENGINE_ERROR; + } + + int32_t ret = Remote()->SendRequest(GET_DISPLAYID, data, reply, option); + if (ret == ERR_NO_PERMISSION) { + CLOGE("No permission when getDisplayId"); + return ERR_NO_PERMISSION; + } else if (ret != ERR_NONE) { + CLOGE("Failed to send ipc request when getDisplayId"); + return CAST_ENGINE_ERROR; + } + int32_t errorCode = reply.ReadInt32(); + CHECK_AND_RETURN_RET_LOG(errorCode != CAST_ENGINE_SUCCESS, errorCode, "CastEngine Errors"); + displayId = reply.ReadString(); + return errorCode; +} + +int32_t MirrorPlayerImplProxy::SetAppInfo(const AppInfo &appInfo) +{ + MessageParcel data, reply; + MessageOption option; + + if (!data.WriteInterfaceToken(GetDescriptor())) { + CLOGE("Failed to write the interface token"); + return CAST_ENGINE_ERROR; + } + if (!data.WriteInt32(appInfo.appUid) || !data.WriteUint32(appInfo.appTokenId) || + !data.WriteInt32(appInfo.appPid)) { + CLOGE("Failed to write appInfo"); + return CAST_ENGINE_ERROR; + } + CLOGI("start set app info impl proxy"); + int32_t ret = Remote()->SendRequest(SET_APP_INFO, data, reply, option); + if (ret == ERR_NO_PERMISSION) { + CLOGE("No permission when setting surface"); + return ERR_NO_PERMISSION; + } else if (ret != ERR_NONE) { + CLOGE("Failed to send ipc request when setting surface"); + return CAST_ENGINE_ERROR; + } + return reply.ReadInt32(); +} + +int32_t MirrorPlayerImplProxy::SetSurface(sptr producer) +{ + MessageParcel data, reply; + MessageOption option; + + if (!data.WriteInterfaceToken(GetDescriptor())) { + CLOGE("Failed to write the interface token"); + return CAST_ENGINE_ERROR; + } + if (!data.WriteRemoteObject(producer->AsObject())) { + CLOGE("Failed to write surface producer"); + return CAST_ENGINE_ERROR; + } + + int32_t ret = Remote()->SendRequest(SET_SURFACE, data, reply, option); + if (ret == ERR_NO_PERMISSION) { + CLOGE("No permission when setting surface"); + return ERR_NO_PERMISSION; + } else if (ret != ERR_NONE) { + CLOGE("Failed to send ipc request when setting surface"); + return CAST_ENGINE_ERROR; + } + + return reply.ReadInt32(); +} + } // namespace CastEngineClient } // namespace CastEngine } // namespace OHOS diff --git a/service/include/cast_session_manager_service.h b/service/include/cast_session_manager_service.h index 15d9552..22c58cc 100644 --- a/service/include/cast_session_manager_service.h +++ b/service/include/cast_session_manager_service.h @@ -25,7 +25,9 @@ #include #include "cast_session_manager_service_stub.h" +#include "connection_manager_listener.h" #include "session.h" +#include "system_ability_load_callback_stub.h" #include "system_ability.h" using SharedRLock = std::shared_lock; @@ -64,6 +66,12 @@ public: void ReportDeviceOffline(const std::string &deviceId); sptr GetCastSessionInner(std::string sessionId); + class CastServiceLoadCallback : public SystemAbilityLoadCallbackStub { + public: + void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr &remoteObject) override; + void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; + }; + private: class CastEngineClientDeathRecipient : public IRemoteObject::DeathRecipient { public: diff --git a/service/src/cast_session_manager_service.cpp b/service/src/cast_session_manager_service.cpp index 6c54ba9..d290e86 100644 --- a/service/src/cast_session_manager_service.cpp +++ b/service/src/cast_session_manager_service.cpp @@ -760,6 +760,32 @@ void CastSessionManagerService::CastEngineClientDeathRecipient::OnRemoteDied(con } service->ReleaseServiceResources(pid_, uid_); } + +void CastSessionManagerService::CastServiceLoadCallback::OnLoadSystemAbilitySuccess( + int32_t systemAbilityId, const sptr &remoteObject) +{ + CLOGI("In systemAbilityId: %d", systemAbilityId); + + if (systemAbilityId != CAST_ENGINE_SA_ID) { + CLOGE("Start aystemabilityId is not sinkSAId!"); + return; + } + + if (remoteObject == nullptr) { + CLOGE("RemoteObject is nullptr."); + return; + } +} + +void CastSessionManagerService::CastServiceLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) +{ + CLOGI("In systemAbilityId: %d.", systemAbilityId); + + if (systemAbilityId != CAST_ENGINE_SA_ID) { + CLOGE("Start aystemabilityId is not sinkSAId!"); + return; + } +} } // namespace CastEngineService } // namespace CastEngine } // namespace OHOS diff --git a/service/src/cast_session_manager_service_stub.cpp b/service/src/cast_session_manager_service_stub.cpp index aeba17e..af7ee22 100644 --- a/service/src/cast_session_manager_service_stub.cpp +++ b/service/src/cast_session_manager_service_stub.cpp @@ -94,7 +94,9 @@ int32_t CastSessionManagerServiceStub::DoReleaseTask(MessageParcel &data, Messag { static_cast(data); - if (!Permission::CheckMirrorPermission() && !Permission::CheckStreamPermission()) { + if ((!Permission::CheckMirrorPermission() && + !Permission::CheckStreamPermission()) || + !Permission::CheckPidPermission()) { return ERR_NO_PERMISSION; } @@ -108,7 +110,7 @@ int32_t CastSessionManagerServiceStub::DoReleaseTask(MessageParcel &data, Messag int32_t CastSessionManagerServiceStub::DoSetLocalDeviceTask(MessageParcel &data, MessageParcel &reply) { - if (!Permission::CheckMirrorPermission()) { + if (!Permission::CheckMirrorPermission() || !Permission::CheckPidPermission()) { return ERR_NO_PERMISSION; } @@ -127,7 +129,9 @@ int32_t CastSessionManagerServiceStub::DoSetLocalDeviceTask(MessageParcel &data, int32_t CastSessionManagerServiceStub::DoCreateCastSessionTask(MessageParcel &data, MessageParcel &reply) { - if (!Permission::CheckMirrorPermission() && !Permission::CheckStreamPermission()) { + if ((!Permission::CheckMirrorPermission() && + !Permission::CheckStreamPermission()) || + !Permission::CheckPidPermission()) { return ERR_NO_PERMISSION; } @@ -158,7 +162,7 @@ int32_t CastSessionManagerServiceStub::DoSetSinkSessionCapacityTask(MessageParce { static_cast(reply); - if (!Permission::CheckMirrorPermission()) { + if (!Permission::CheckMirrorPermission() || !Permission::CheckPidPermission()) { return ERR_NO_PERMISSION; } @@ -174,7 +178,9 @@ int32_t CastSessionManagerServiceStub::DoSetSinkSessionCapacityTask(MessageParce int32_t CastSessionManagerServiceStub::DoStartDiscoveryTask(MessageParcel &data, MessageParcel &reply) { - if (!Permission::CheckMirrorPermission() && !Permission::CheckStreamPermission()) { + if ((!Permission::CheckMirrorPermission() && + !Permission::CheckStreamPermission()) || + !Permission::CheckPidPermission()) { return ERR_NO_PERMISSION; } @@ -197,7 +203,9 @@ int32_t CastSessionManagerServiceStub::DoStartDiscoveryTask(MessageParcel &data, int32_t CastSessionManagerServiceStub::DoSetDiscoverableTask(MessageParcel &data, MessageParcel &reply) { - if (!Permission::CheckMirrorPermission() && !Permission::CheckStreamPermission()) { + if ((!Permission::CheckMirrorPermission() && + !Permission::CheckStreamPermission()) || + !Permission::CheckPidPermission()) { return ERR_NO_PERMISSION; } @@ -211,7 +219,9 @@ int32_t CastSessionManagerServiceStub::DoSetDiscoverableTask(MessageParcel &data int32_t CastSessionManagerServiceStub::DoStopDiscoveryTask(MessageParcel &data, MessageParcel &reply) { - if (!Permission::CheckMirrorPermission() && !Permission::CheckStreamPermission()) { + if ((!Permission::CheckMirrorPermission() && + !Permission::CheckStreamPermission()) || + !Permission::CheckPidPermission()) { return ERR_NO_PERMISSION; } diff --git a/service/src/device_manager/include/connection_manager.h b/service/src/device_manager/include/connection_manager.h index e2a0eb3..a2ba27e 100644 --- a/service/src/device_manager/include/connection_manager.h +++ b/service/src/device_manager/include/connection_manager.h @@ -62,20 +62,6 @@ public: void OnUnbindResult(const PeerTargetId &targetId, int32_t result, std::string content) override; }; -class IConnectionManagerListener { -public: - IConnectionManagerListener() = default; - virtual ~IConnectionManagerListener() = default; - - virtual int NotifySessionIsReady() = 0; - virtual void NotifyDeviceIsOffline(const std::string &deviceId) = 0; - virtual bool NotifyRemoteDeviceIsReady(int castSessionId, const CastInnerRemoteDevice &device) = 0; - virtual void OnEvent(const std::string &deviceId, ReasonCode currentEventCode) = 0; - virtual void GrabDevice(int32_t sessionId) = 0; - virtual int32_t GetSessionProtocolType(int sessionId, ProtocolType &protocolType) = 0; - virtual int32_t SetSessionProtocolType(int sessionId, ProtocolType protocolType) = 0; -}; - class ConnectionManager { public: static ConnectionManager &GetInstance(); @@ -108,13 +94,15 @@ public: void ReportErrorByListener(const std::string &deviceId, ReasonCode currentEventCode); void UpdateGrabState(bool changeState, int32_t sessionId); void SetSessionListener(std::shared_ptr listener); + int32_t GetSessionProtocolType(int sessionId, ProtocolType &protocolType); int32_t SetSessionProtocolType(int sessionId, ProtocolType protocolType); + void SetRTSPPort(int port); + void SendConsultInfo(const std::string &deviceId, int port); bool IsSingle(const CastInnerRemoteDevice &device); bool IsHuaweiDevice(const CastInnerRemoteDevice &device); bool IsThirdDevice(const CastInnerRemoteDevice &device); - void SendConsultInfo(const std::string &deviceId, int port); std::map isBindTargetMap_; @@ -122,23 +110,26 @@ private: bool BindTarget(const CastInnerRemoteDevice &dev); bool BuildBindParam(const CastInnerRemoteDevice &device, std::map &bindParam); std::string GetAuthVersion(const CastInnerRemoteDevice &device); - void SendConsultData(const CastInnerRemoteDevice &device, int port); + bool QueryP2PIp(const CastInnerRemoteDevice &device); + void SendConsultData(const CastInnerRemoteDevice &device, int port); std::string GetConsultationData(const CastInnerRemoteDevice &device, int port, json &body); + void EncryptPort(int port, const uint8_t *sessionKey, json &body); - std::string convLatin1ToUTF8(std::string &latin1); void EncryptIp(const std::string &ip, const std::string &key, const uint8_t *sessionKey, json &body); std::unique_ptr intToByteArray(int32_t num); + std::string convLatin1ToUTF8(std::string &latin1); void DestroyConsulationSession(const std::string &deviceId); int GetCastSessionId(int transportId); + std::unique_ptr GetRemoteFromJsonData(const std::string &Data); + int GetRTSPPort(); void SetListener(std::shared_ptr listener); bool HasListener(); void ResetListener(); - int GetRTSPPort(); std::mutex mutex_; int protocolType_ = 0; diff --git a/common/include/private/connection_manager_listener.h b/service/src/device_manager/include/connection_manager_listener.h similarity index 60% rename from common/include/private/connection_manager_listener.h rename to service/src/device_manager/include/connection_manager_listener.h index b4251c8..87b3ecd 100644 --- a/common/include/private/connection_manager_listener.h +++ b/service/src/device_manager/include/connection_manager_listener.h @@ -1,37 +1,52 @@ -/* - * Copyright (C) 2023-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. - * Description: connection manager session listener - * Author: jiangfan - * Create: 2023-11-08 - */ -#ifndef LIBCASTENGINE_CONNECTMANAGER_LISTENER_H -#define LIBCASTENGINE_CONNECTMANAGER_LISTENER_H - -#include "cast_engine_common.h" - -namespace OHOS { -namespace CastEngine { -namespace CastEngineService { - -class IConnectManagerSessionListener { -public: - virtual ~IConnectManagerSessionListener() {} - - virtual void NotifyConnectStage(const std::string &deviceId, int result, int32_t reasonCode) = 0; -}; -} // namespace CastEngineService -} // namespace CastEngine -} // namespace OHOS - +/* + * Copyright (C) 2023-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. + * Description: connection manager session listener + * Author: jiangfan + * Create: 2023-11-08 + */ + +#ifndef LIBCASTENGINE_CONNECTMANAGER_LISTENER_H +#define LIBCASTENGINE_CONNECTMANAGER_LISTENER_H + +#include "cast_engine_common.h" + +namespace OHOS { +namespace CastEngine { +namespace CastEngineService { + +class IConnectionManagerListener { +public: + IConnectionManagerListener() = default; + virtual ~IConnectionManagerListener() = default; + + virtual int NotifySessionIsReady() = 0; + virtual void NotifyDeviceIsOffline(const std::string &deviceId) = 0; + virtual bool NotifyRemoteDeviceIsReady(int castSessionId, const CastInnerRemoteDevice &device) = 0; + virtual void OnEvent(const std::string &deviceId, ReasonCode currentEventCode) = 0; + virtual void GrabDevice(int32_t sessionId) = 0; + virtual int32_t GetSessionProtocolType(int sessionId, ProtocolType &protocolType) = 0; + virtual int32_t SetSessionProtocolType(int sessionId, ProtocolType protocolType) = 0; +}; + +class IConnectManagerSessionListener { +public: + virtual ~IConnectManagerSessionListener() {} + + virtual void NotifyConnectStage(const std::string &deviceId, int result, int32_t reasonCode) = 0; +}; +} // namespace CastEngineService +} // namespace CastEngine +} // namespace OHOS + #endif // LIBCASTENGINE_CONNECTMANAGER_LISTENER_H \ No newline at end of file