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_BASE_SCENE_H
17e0e9324cSopenharmony_ci#define OHOS_SHARING_BASE_SCENE_H
18e0e9324cSopenharmony_ci
19e0e9324cSopenharmony_ci#include "common/identifier.h"
20e0e9324cSopenharmony_ci#include "common/object.h"
21e0e9324cSopenharmony_ci#include "common/sharing_log.h"
22e0e9324cSopenharmony_ci#include "interaction/interprocess/ipc_msg_adapter.h"
23e0e9324cSopenharmony_ci#include "interaction/ipc_codec/ipc_msg.h"
24e0e9324cSopenharmony_ci#include "interaction/sharing_adapter.h"
25e0e9324cSopenharmony_ci
26e0e9324cSopenharmony_cinamespace OHOS {
27e0e9324cSopenharmony_cinamespace Sharing {
28e0e9324cSopenharmony_ci
29e0e9324cSopenharmony_ciclass BaseScene : public Object,
30e0e9324cSopenharmony_ci                  public MsgAdapterListener,
31e0e9324cSopenharmony_ci                  public IdentifierInfo {
32e0e9324cSopenharmony_cipublic:
33e0e9324cSopenharmony_ci    using Ptr = std::shared_ptr<BaseScene>;
34e0e9324cSopenharmony_ci
35e0e9324cSopenharmony_ci    virtual ~BaseScene()
36e0e9324cSopenharmony_ci    {
37e0e9324cSopenharmony_ci        SHARING_LOGD("~BaseScene.");
38e0e9324cSopenharmony_ci        auto sharingAdapter = sharingAdapter_.lock();
39e0e9324cSopenharmony_ci        if (sharingAdapter) {
40e0e9324cSopenharmony_ci            sharingAdapter->OnSceneNotifyDestroyed(GetId());
41e0e9324cSopenharmony_ci        }
42e0e9324cSopenharmony_ci    }
43e0e9324cSopenharmony_ci
44e0e9324cSopenharmony_ci    uint32_t GetInteractionId()
45e0e9324cSopenharmony_ci    {
46e0e9324cSopenharmony_ci        SHARING_LOGD("trace.");
47e0e9324cSopenharmony_ci        return interactionId_;
48e0e9324cSopenharmony_ci    }
49e0e9324cSopenharmony_ci
50e0e9324cSopenharmony_ci    void SetInteractionId(uint32_t interactionId)
51e0e9324cSopenharmony_ci    {
52e0e9324cSopenharmony_ci        SHARING_LOGD("trace.");
53e0e9324cSopenharmony_ci        interactionId_ = interactionId;
54e0e9324cSopenharmony_ci    }
55e0e9324cSopenharmony_ci
56e0e9324cSopenharmony_ci    void SetSharingAdapter(std::weak_ptr<ISharingAdapter> sharingAdapter)
57e0e9324cSopenharmony_ci    {
58e0e9324cSopenharmony_ci        SHARING_LOGD("trace.");
59e0e9324cSopenharmony_ci        sharingAdapter_ = sharingAdapter;
60e0e9324cSopenharmony_ci    }
61e0e9324cSopenharmony_ci
62e0e9324cSopenharmony_cipublic:
63e0e9324cSopenharmony_ci    virtual void Initialize() = 0;
64e0e9324cSopenharmony_ci    virtual void OnInnerEvent(SharingEvent &event) = 0;
65e0e9324cSopenharmony_ci    virtual void OnDomainMsg(std::shared_ptr<BaseDomainMsg> &msg) = 0;
66e0e9324cSopenharmony_ci    virtual void SetIpcAdapter(const std::weak_ptr<IpcMsgAdapter> &adapter) = 0;
67e0e9324cSopenharmony_ci    virtual void OnInnerDestroy(uint32_t contextId, uint32_t agentId, AgentType agentType) = 0;
68e0e9324cSopenharmony_ci    virtual void OnInnerError(uint32_t contextId, uint32_t agentId, SharingErrorCode errorCode,
69e0e9324cSopenharmony_ci                              std::string message = "inner error") = 0;
70e0e9324cSopenharmony_ci
71e0e9324cSopenharmony_ciprotected:
72e0e9324cSopenharmony_ci    uint32_t interactionId_ = -1;
73e0e9324cSopenharmony_ci
74e0e9324cSopenharmony_ci    std::weak_ptr<IpcMsgAdapter> ipcAdapter_;
75e0e9324cSopenharmony_ci    std::weak_ptr<ISharingAdapter> sharingAdapter_;
76e0e9324cSopenharmony_ci};
77e0e9324cSopenharmony_ci
78e0e9324cSopenharmony_ci} // namespace Sharing
79e0e9324cSopenharmony_ci} // namespace OHOS
80e0e9324cSopenharmony_ci#endif