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