1e0e9324cSopenharmony_ci/*
2e0e9324cSopenharmony_ci * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3e0e9324cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e0e9324cSopenharmony_ci * you may not use this file except in compliance with the License.
5e0e9324cSopenharmony_ci * You may obtain a copy of the License at
6e0e9324cSopenharmony_ci *
7e0e9324cSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e0e9324cSopenharmony_ci *
9e0e9324cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e0e9324cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e0e9324cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e0e9324cSopenharmony_ci * See the License for the specific language governing permissions and
13e0e9324cSopenharmony_ci * limitations under the License.
14e0e9324cSopenharmony_ci */
15e0e9324cSopenharmony_ci
16e0e9324cSopenharmony_ci#ifndef OHOS_SHARING_INTERACTION_H
17e0e9324cSopenharmony_ci#define OHOS_SHARING_INTERACTION_H
18e0e9324cSopenharmony_ci
19e0e9324cSopenharmony_ci#include "common/identifier.h"
20e0e9324cSopenharmony_ci#include "event/event_base.h"
21e0e9324cSopenharmony_ci#include "event/handle_event_base.h"
22e0e9324cSopenharmony_ci#include "interaction/ipc_codec/ipc_msg.h"
23e0e9324cSopenharmony_ci#include "interaction/interprocess/ipc_msg_adapter.h"
24e0e9324cSopenharmony_ci#include "interaction/scene/base_scene.h"
25e0e9324cSopenharmony_ci
26e0e9324cSopenharmony_cinamespace OHOS {
27e0e9324cSopenharmony_cinamespace Sharing {
28e0e9324cSopenharmony_ci
29e0e9324cSopenharmony_ciclass Interaction final : public HandleEventBase,
30e0e9324cSopenharmony_ci                          public IdentifierInfo,
31e0e9324cSopenharmony_ci                          public ISharingAdapter,
32e0e9324cSopenharmony_ci                          public EventEmitter,
33e0e9324cSopenharmony_ci                          public std::enable_shared_from_this<Interaction> {
34e0e9324cSopenharmony_cipublic:
35e0e9324cSopenharmony_ci    using Ptr = std::shared_ptr<Interaction>;
36e0e9324cSopenharmony_ci
37e0e9324cSopenharmony_ci    Interaction() = default;
38e0e9324cSopenharmony_ci    virtual ~Interaction();
39e0e9324cSopenharmony_ci
40e0e9324cSopenharmony_ci    IpcMsgAdapter::Ptr GetIpcAdapter()
41e0e9324cSopenharmony_ci    {
42e0e9324cSopenharmony_ci        SHARING_LOGD("trace.");
43e0e9324cSopenharmony_ci        return ipcAdapter_;
44e0e9324cSopenharmony_ci    }
45e0e9324cSopenharmony_ci
46e0e9324cSopenharmony_ci    void SetIpcAdapter(IpcMsgAdapter::Ptr ipcAdapter)
47e0e9324cSopenharmony_ci    {
48e0e9324cSopenharmony_ci        SHARING_LOGD("trace.");
49e0e9324cSopenharmony_ci        ipcAdapter_ = ipcAdapter;
50e0e9324cSopenharmony_ci    }
51e0e9324cSopenharmony_ci
52e0e9324cSopenharmony_ci    BaseScene::Ptr GetScene()
53e0e9324cSopenharmony_ci    {
54e0e9324cSopenharmony_ci        SHARING_LOGD("trace.");
55e0e9324cSopenharmony_ci        return scene_;
56e0e9324cSopenharmony_ci    }
57e0e9324cSopenharmony_ci
58e0e9324cSopenharmony_ci    int32_t GetRequestId()
59e0e9324cSopenharmony_ci    {
60e0e9324cSopenharmony_ci        SHARING_LOGD("trace.");
61e0e9324cSopenharmony_ci        return ++requestId_;
62e0e9324cSopenharmony_ci    }
63e0e9324cSopenharmony_ci
64e0e9324cSopenharmony_ci    void SetRpcKey(const std::string &key)
65e0e9324cSopenharmony_ci    {
66e0e9324cSopenharmony_ci        SHARING_LOGD("trace.");
67e0e9324cSopenharmony_ci        rpcKey_ = key;
68e0e9324cSopenharmony_ci    }
69e0e9324cSopenharmony_ci
70e0e9324cSopenharmony_ci    const std::string &GetRpcKey() const
71e0e9324cSopenharmony_ci    {
72e0e9324cSopenharmony_ci        SHARING_LOGD("trace.");
73e0e9324cSopenharmony_ci        return rpcKey_;
74e0e9324cSopenharmony_ci    }
75e0e9324cSopenharmony_ci
76e0e9324cSopenharmony_cipublic:
77e0e9324cSopenharmony_ci    void Destroy();
78e0e9324cSopenharmony_ci    bool CreateScene(const std::string &className);
79e0e9324cSopenharmony_ci    int32_t HandleEvent(SharingEvent &event) final;
80e0e9324cSopenharmony_ci
81e0e9324cSopenharmony_ci    // the two funcs are used to interact with the domain
82e0e9324cSopenharmony_ci    // to determine if they need to be moved to the ISharingAdapter
83e0e9324cSopenharmony_ci    void OnDomainMsg(std::shared_ptr<BaseDomainMsg> &msg);
84e0e9324cSopenharmony_ci    void ForwardDomainMsg(std::shared_ptr<BaseDomainMsg> &msg) override;
85e0e9324cSopenharmony_ci
86e0e9324cSopenharmony_ci    // impl ISharing about Protocol
87e0e9324cSopenharmony_ci    void ReleaseScene(uint32_t sceneId) override;
88e0e9324cSopenharmony_ci    void OnSceneNotifyDestroyed(uint32_t sceneId) override;
89e0e9324cSopenharmony_ci    int32_t ForwardEvent(uint32_t contextId, uint32_t agentId, SharingEvent &event, bool isSync) override;
90e0e9324cSopenharmony_ci
91e0e9324cSopenharmony_ci    int32_t CreateContext(uint32_t &contextId) override;
92e0e9324cSopenharmony_ci    int32_t DestroyContext(uint32_t contextId) override;
93e0e9324cSopenharmony_ci    int32_t DestroyAgent(uint32_t contextId, uint32_t agentId) override;
94e0e9324cSopenharmony_ci    int32_t CreateAgent(uint32_t &contextId, uint32_t &agentId, AgentType agentType, std::string sessionName) override;
95e0e9324cSopenharmony_ci
96e0e9324cSopenharmony_ci    int32_t Stop(uint32_t contextId, uint32_t agentId) override;
97e0e9324cSopenharmony_ci    int32_t Start(uint32_t contextId, uint32_t agentId) override;
98e0e9324cSopenharmony_ci    int32_t Pause(uint32_t contextId, uint32_t agentId, MediaType mediaType) override;
99e0e9324cSopenharmony_ci    int32_t Resume(uint32_t contextId, uint32_t agentId, MediaType mediaType) override;
100e0e9324cSopenharmony_ci
101e0e9324cSopenharmony_ci    // impl ISharing about play
102e0e9324cSopenharmony_ci    int32_t Play(uint32_t contextId, uint32_t agentId) override;
103e0e9324cSopenharmony_ci    int32_t Close(uint32_t contextId, uint32_t agentId) override;
104e0e9324cSopenharmony_ci    int32_t SetVolume(uint32_t contextId, uint32_t agentId, float volume) override;
105e0e9324cSopenharmony_ci    int32_t SetKeyPlay(uint32_t contextId, uint32_t agentId, uint64_t surfaceId, bool keyFrame) override;
106e0e9324cSopenharmony_ci    int32_t SetKeyRedirect(uint32_t contextId, uint32_t agentId, uint64_t surfaceId, bool keyRedirect) override;
107e0e9324cSopenharmony_ci
108e0e9324cSopenharmony_ci    int32_t RemoveSurface(uint32_t contextId, uint32_t agentId, uint64_t surfaceId) override;
109e0e9324cSopenharmony_ci    int32_t AppendSurface(uint32_t contextId, uint32_t agentId, sptr<Surface> surface,
110e0e9324cSopenharmony_ci                          SceneType sceneType = FOREGROUND) override;
111e0e9324cSopenharmony_ci
112e0e9324cSopenharmony_ci    // impl ISharing about window
113e0e9324cSopenharmony_ci    int32_t DestroyWindow(int32_t windowId) override;
114e0e9324cSopenharmony_ci    int32_t CreateWindow(int32_t &windowId, WindowProperty &windowProperty) override;
115e0e9324cSopenharmony_ci
116e0e9324cSopenharmony_ci    int32_t Hide(int32_t windowId) override;
117e0e9324cSopenharmony_ci    int32_t Show(int32_t windowId) override;
118e0e9324cSopenharmony_ci    int32_t SetFullScreen(int32_t windowId, bool isFull) override;
119e0e9324cSopenharmony_ci    int32_t MoveTo(int32_t windowId, int32_t x, int32_t y) override;
120e0e9324cSopenharmony_ci    int32_t GetSurface(int32_t windowId, sptr<Surface> &surface) override;
121e0e9324cSopenharmony_ci    int32_t ReSize(int32_t windowId, int32_t width, int32_t height) override;
122e0e9324cSopenharmony_ci
123e0e9324cSopenharmony_ciprivate:
124e0e9324cSopenharmony_ci    int32_t NotifyEvent(EventMsg::Ptr eventMsg);
125e0e9324cSopenharmony_ci
126e0e9324cSopenharmony_ciprivate:
127e0e9324cSopenharmony_ci    std::string rpcKey_;
128e0e9324cSopenharmony_ci    std::atomic<int32_t> requestId_ = 0;
129e0e9324cSopenharmony_ci
130e0e9324cSopenharmony_ci    BaseScene::Ptr scene_ = nullptr;
131e0e9324cSopenharmony_ci    IpcMsgAdapter::Ptr ipcAdapter_ = nullptr;
132e0e9324cSopenharmony_ci};
133e0e9324cSopenharmony_ci
134e0e9324cSopenharmony_ci} // namespace Sharing
135e0e9324cSopenharmony_ci} // namespace OHOS
136e0e9324cSopenharmony_ci#endif