1 /* 2 * Copyright (C) 2023-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * Description: cast session manager apis. 15 * Author: zhangge 16 * Create: 2022-06-15 17 */ 18 19 #ifndef CAST_SESSION_MANAGER_H 20 #define CAST_SESSION_MANAGER_H 21 22 #include <memory> 23 #include <mutex> 24 #include "system_ability_load_callback_stub.h" 25 #include "cast_engine_common.h" 26 #include "i_cast_session.h" 27 #include "i_cast_session_manager_adaptor.h" 28 #include "i_cast_session_manager_listener.h" 29 #include "iremote_object.h" 30 31 namespace OHOS { 32 namespace CastEngine { 33 namespace CastEngineClient { 34 class EXPORT CastSessionManager { 35 public: 36 static CastSessionManager &GetInstance(); 37 38 CastSessionManager(const CastSessionManager &) = delete; 39 CastSessionManager &operator=(const CastSessionManager &) = delete; 40 CastSessionManager(CastSessionManager &&) = delete; 41 CastSessionManager &operator=(CastSessionManager &&) = delete; 42 ~CastSessionManager() = default; 43 44 int32_t RegisterListener(std::shared_ptr<ICastSessionManagerListener> listener); 45 int32_t UnregisterListener(); 46 int32_t Release(); 47 int32_t SetLocalDevice(const CastLocalDevice &localDevice); 48 int32_t CreateCastSession(const CastSessionProperty &property, std::shared_ptr<ICastSession> &castSession); 49 int32_t SetSinkSessionCapacity(int sessionCapacity); 50 int32_t StartDiscovery(int protocols, std::vector<std::string> drmSchemes); 51 int32_t SetDiscoverable(bool enable); 52 int32_t StopDiscovery(); 53 int32_t StartDeviceLogging(int32_t fd, uint32_t maxSize); 54 int32_t GetCastSession(std::string sessionId, std::shared_ptr<ICastSession> &castSession); 55 private: 56 class CastEngineServiceDeathRecipient : public IRemoteObject::DeathRecipient { 57 public: CastEngineServiceDeathRecipient(std::shared_ptr<ICastSessionManagerListener> listener)58 CastEngineServiceDeathRecipient(std::shared_ptr<ICastSessionManagerListener> listener) 59 : listener_(listener) {}; 60 void OnRemoteDied(const wptr<IRemoteObject> &object) override; GetListener()61 std::shared_ptr<ICastSessionManagerListener> GetListener() 62 { 63 return listener_; 64 } 65 66 private: 67 std::shared_ptr<ICastSessionManagerListener> listener_; 68 }; 69 class CastEngineServiceLoadCallback : public SystemAbilityLoadCallbackStub { 70 public: 71 void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject) override; 72 void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; 73 }; 74 75 CastSessionManager(); 76 void ReleaseServiceDeathRecipient(); 77 void ReleaseClientResources(); 78 std::shared_ptr<ICastSessionManagerAdaptor> GetAdaptor(); 79 void NotifyServiceLoadResult(const sptr<IRemoteObject> &remoteObject); 80 81 std::mutex mutex_; 82 std::condition_variable loadServiceCond_; 83 std::shared_ptr<ICastSessionManagerAdaptor> adaptor_; 84 sptr<CastEngineServiceDeathRecipient> deathRecipient_{ nullptr }; 85 bool isNeedLoadService_{ true }; 86 }; 87 } // namespace CastEngineClient 88 } // namespace CastEngine 89 } // namespace OHOS 90 91 #endif