• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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_SHARING_INTERACTION_H
17 #define OHOS_SHARING_INTERACTION_H
18 
19 #include "common/identifier.h"
20 #include "event/event_base.h"
21 #include "event/handle_event_base.h"
22 #include "interaction/ipc_codec/ipc_msg.h"
23 #include "interaction/interprocess/ipc_msg_adapter.h"
24 #include "interaction/scene/base_scene.h"
25 
26 namespace OHOS {
27 namespace Sharing {
28 
29 class Interaction final : public HandleEventBase,
30                           public IdentifierInfo,
31                           public ISharingAdapter,
32                           public EventEmitter,
33                           public std::enable_shared_from_this<Interaction> {
34 public:
35     using Ptr = std::shared_ptr<Interaction>;
36 
37     Interaction() = default;
38     virtual ~Interaction();
39 
GetIpcAdapter()40     IpcMsgAdapter::Ptr GetIpcAdapter()
41     {
42         SHARING_LOGD("trace.");
43         return ipcAdapter_;
44     }
45 
SetIpcAdapter(IpcMsgAdapter::Ptr ipcAdapter)46     void SetIpcAdapter(IpcMsgAdapter::Ptr ipcAdapter)
47     {
48         SHARING_LOGD("trace.");
49         ipcAdapter_ = ipcAdapter;
50     }
51 
GetScene()52     BaseScene::Ptr GetScene()
53     {
54         SHARING_LOGD("trace.");
55         return scene_;
56     }
57 
GetRequestId()58     int32_t GetRequestId()
59     {
60         SHARING_LOGD("trace.");
61         return ++requestId_;
62     }
63 
SetRpcKey(const std::string & key)64     void SetRpcKey(const std::string &key)
65     {
66         SHARING_LOGD("trace.");
67         rpcKey_ = key;
68     }
69 
GetRpcKey()70     const std::string &GetRpcKey() const
71     {
72         SHARING_LOGD("trace.");
73         return rpcKey_;
74     }
75 
76 public:
77     void Destroy();
78     bool CreateScene(const std::string &className);
79     int32_t HandleEvent(SharingEvent &event) final;
80 
81     // the two funcs are used to interact with the domain
82     // to determine if they need to be moved to the ISharingAdapter
83     void OnDomainMsg(std::shared_ptr<BaseDomainMsg> &msg);
84     void ForwardDomainMsg(std::shared_ptr<BaseDomainMsg> &msg) override;
85 
86     // impl ISharing about Protocol
87     void ReleaseScene(uint32_t sceneId) override;
88     void OnSceneNotifyDestroyed(uint32_t sceneId) override;
89     int32_t ForwardEvent(uint32_t contextId, uint32_t agentId, SharingEvent &event, bool isSync) override;
90 
91     int32_t CreateContext(uint32_t &contextId) override;
92     int32_t DestroyContext(uint32_t contextId) override;
93     int32_t DestroyAgent(uint32_t contextId, uint32_t agentId) override;
94     int32_t CreateAgent(uint32_t &contextId, uint32_t &agentId, AgentType agentType, std::string sessionName) override;
95 
96     int32_t Stop(uint32_t contextId, uint32_t agentId) override;
97     int32_t Start(uint32_t contextId, uint32_t agentId) override;
98     int32_t Pause(uint32_t contextId, uint32_t agentId, MediaType mediaType) override;
99     int32_t Resume(uint32_t contextId, uint32_t agentId, MediaType mediaType) override;
100 
101     // impl ISharing about play
102     int32_t Play(uint32_t contextId, uint32_t agentId) override;
103     int32_t Close(uint32_t contextId, uint32_t agentId) override;
104     int32_t SetVolume(uint32_t contextId, uint32_t agentId, float volume) override;
105     int32_t SetKeyPlay(uint32_t contextId, uint32_t agentId, uint64_t surfaceId, bool keyFrame) override;
106     int32_t SetKeyRedirect(uint32_t contextId, uint32_t agentId, uint64_t surfaceId, bool keyRedirect) override;
107 
108     int32_t RemoveSurface(uint32_t contextId, uint32_t agentId, uint64_t surfaceId) override;
109     int32_t AppendSurface(uint32_t contextId, uint32_t agentId, sptr<Surface> surface,
110                           SceneType sceneType = FOREGROUND) override;
111 
112     // impl ISharing about window
113     int32_t DestroyWindow(int32_t windowId) override;
114     int32_t CreateWindow(int32_t &windowId, WindowProperty &windowProperty) override;
115 
116     int32_t Hide(int32_t windowId) override;
117     int32_t Show(int32_t windowId) override;
118     int32_t SetFullScreen(int32_t windowId, bool isFull) override;
119     int32_t MoveTo(int32_t windowId, int32_t x, int32_t y) override;
120     int32_t GetSurface(int32_t windowId, sptr<Surface> &surface) override;
121     int32_t ReSize(int32_t windowId, int32_t width, int32_t height) override;
122 
123 private:
124     int32_t NotifyEvent(EventMsg::Ptr eventMsg);
125 
126 private:
127     std::string rpcKey_;
128     std::atomic<int32_t> requestId_ = 0;
129 
130     BaseScene::Ptr scene_ = nullptr;
131     IpcMsgAdapter::Ptr ipcAdapter_ = nullptr;
132 };
133 
134 } // namespace Sharing
135 } // namespace OHOS
136 #endif