1 /*
2  * Copyright (c) 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  */
15 
16 #ifndef OHOS_ROSEN_WINDOW_SCENE_SCREEN_SESSION_MANAGER_LITE_H
17 #define OHOS_ROSEN_WINDOW_SCENE_SCREEN_SESSION_MANAGER_LITE_H
18 
19 #include <shared_mutex>
20 
21 #include "dm_common.h"
22 #include "zidl/screen_session_manager_lite_stub.h"
23 #include "wm_single_instance.h"
24 #include "zidl/screen_session_manager_interface.h"
25 
26 namespace OHOS::Rosen {
27 class ScreenSMDeathRecipient : public IRemoteObject::DeathRecipient {
28 public:
29     virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override;
30 };
31 
32 class ScreenSessionManagerLite : public ScreenSessionManagerLiteStub {
33 WM_DECLARE_SINGLE_INSTANCE_BASE(ScreenSessionManagerLite)
34 
35 public:
36     void Clear();
37 
38     virtual DMError RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
39         DisplayManagerAgentType type) override;
40     virtual DMError UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
41         DisplayManagerAgentType type) override;
42 
43     FoldDisplayMode GetFoldDisplayMode() override;
44     void SetFoldDisplayMode(const FoldDisplayMode displayMode) override;
45     bool IsFoldable() override;
46     FoldStatus GetFoldStatus() override;
47     sptr<DisplayInfo> GetDefaultDisplayInfo() override;
48     virtual sptr<DisplayInfo> GetDisplayInfoById(DisplayId displayId) override;
49     sptr<CutoutInfo> GetCutoutInfo(DisplayId displayId) override;
50 protected:
51     ScreenSessionManagerLite() = default;
52     virtual ~ScreenSessionManagerLite();
53 
54 private:
55     void ConnectToServer();
56     sptr<IScreenSessionManager> screenSessionManager_;
57     std::recursive_mutex mutex_;
58     sptr<ScreenSMDeathRecipient> ssmDeath_ = nullptr;
59     bool destroyed_ = false;
60 };
61 } // namespace OHOS::Rosen
62 
63 #endif // OHOS_ROSEN_WINDOW_SCENE_SCREEN_SESSION_MANAGER_LITE_H
64