• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "cast_engine_common.h"
25 #include "i_cast_session.h"
26 #include "i_cast_session_manager_adaptor.h"
27 #include "i_cast_session_manager_listener.h"
28 #include "iremote_object.h"
29 
30 namespace OHOS {
31 namespace CastEngine {
32 namespace CastEngineClient {
33 class EXPORT CastSessionManager {
34 public:
35     static CastSessionManager &GetInstance();
36 
37     CastSessionManager(const CastSessionManager &) = delete;
38     CastSessionManager &operator=(const CastSessionManager &) = delete;
39     CastSessionManager(CastSessionManager &&) = delete;
40     CastSessionManager &operator=(CastSessionManager &&) = delete;
41     ~CastSessionManager() = default;
42 
43     int32_t RegisterListener(std::shared_ptr<ICastSessionManagerListener> listener);
44     int32_t UnregisterListener();
45     int32_t Release();
46     int32_t SetLocalDevice(const CastLocalDevice &localDevice);
47     int32_t CreateCastSession(const CastSessionProperty &property, std::shared_ptr<ICastSession> &castSession);
48     int32_t SetSinkSessionCapacity(int sessionCapacity);
49     int32_t StartDiscovery(int protocols);
50     int32_t SetDiscoverable(bool enable);
51     int32_t StopDiscovery();
52     void ReleaseClientResources();
53 
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 
70     CastSessionManager();
71     void ReleaseServiceDeathRecipient();
72     std::shared_ptr<ICastSessionManagerAdaptor> GetAdaptor();
73 
74     std::mutex mutex_;
75     std::shared_ptr<ICastSessionManagerAdaptor> adaptor_;
76     sptr<CastEngineServiceDeathRecipient> deathRecipient_{ nullptr };
77 };
78 } // namespace CastEngineClient
79 } // namespace CastEngine
80 } // namespace OHOS
81 
82 #endif