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_DOMAIN_DEF_H 17 #define OHOS_SHARING_DOMAIN_DEF_H 18 19 #include "common/identifier.h" 20 #include "common/sharing_log.h" 21 #include "ipc_msg.h" 22 #include "interaction/scene/scene_format.h" 23 #include "iremote_object.h" 24 #include "singleton.h" 25 26 namespace OHOS { 27 namespace Sharing { 28 29 enum DomainType { DOMAIN_TYPE_RPC = 0, DOMAIN_TYPE_DBUS, DOMAIN_TYPE_SOCKET, DOMAIN_TYPE_MAX }; 30 31 class IDomainPeerListener { 32 public: 33 IDomainPeerListener() = default; 34 virtual ~IDomainPeerListener() = default; 35 36 virtual void OnPeerConnected(std::string remoteId) = 0; 37 virtual void OnPeerDisconnected(std::string remoteId) = 0; 38 virtual void OnDomainRequest(std::string remoteId, std::shared_ptr<BaseDomainMsg> BaseMsg) = 0; 39 }; 40 41 class IDomainPeer { 42 public: 43 enum DomainPeerType { REMOTE_CALLER_SERVER = 0, REMOTE_CALLER_CLIENT }; 44 45 virtual ~IDomainPeer() = default; 46 IDomainPeer(DomainPeerType type)47 explicit IDomainPeer(DomainPeerType type) 48 { 49 SHARING_LOGD("trace."); 50 peerType_ = type; 51 } 52 GetPeerType()53 DomainPeerType GetPeerType() 54 { 55 SHARING_LOGD("trace."); 56 return peerType_; 57 } 58 GetRemoteId()59 std::string GetRemoteId() 60 { 61 SHARING_LOGD("trace."); 62 return remoteId_; 63 } 64 SetRemoteId(std::string remoteId)65 void SetRemoteId(std::string remoteId) 66 { 67 SHARING_LOGD("trace."); 68 remoteId_ = remoteId; 69 } 70 GetDomainType()71 DomainType GetDomainType() 72 { 73 SHARING_LOGD("trace."); 74 return domainType_; 75 } 76 77 public: 78 virtual void SetPeerListener(std::weak_ptr<IDomainPeerListener> listener) = 0; 79 virtual int32_t SendDomainRequest(std::string remoteId, std::shared_ptr<BaseDomainMsg> BaseMsg) = 0; 80 81 protected: 82 std::string remoteId_; 83 std::weak_ptr<IDomainPeerListener> peerListener_; 84 85 DomainType domainType_; 86 DomainPeerType peerType_; 87 }; 88 89 class ITransmitMgr; 90 91 class ITransmitMgrListener { 92 public: 93 ITransmitMgrListener() = default; 94 virtual ~ITransmitMgrListener() = default; 95 96 virtual int32_t DelPeer(std::string remoteId) = 0; 97 virtual int32_t AddPeer(std::shared_ptr<ITransmitMgr> mgr, std::shared_ptr<IDomainPeer> caller) = 0; 98 virtual void OnDomainRequest(std::string remoteId, std::shared_ptr<BaseDomainMsg> BaseMsg) = 0; 99 }; 100 101 class ITransmitMgr : public IDomainPeerListener, 102 public IdentifierInfo { 103 public: GetDomainType()104 DomainType GetDomainType() 105 { 106 SHARING_LOGD("trace."); 107 return domainType_; 108 } 109 SetListener(std::weak_ptr<ITransmitMgrListener> listener)110 void SetListener(std::weak_ptr<ITransmitMgrListener> listener) 111 { 112 SHARING_LOGD("trace."); 113 transMgrListener_ = listener; 114 } 115 116 public: 117 virtual bool IsPeerExist(std::string remoteId) = 0; 118 virtual int32_t SendDomainRequest(std::string remoteId, std::shared_ptr<BaseDomainMsg> BaseMsg) = 0; 119 120 protected: 121 DomainType domainType_; 122 std::weak_ptr<ITransmitMgrListener> transMgrListener_; 123 }; 124 125 } // namespace Sharing 126 } // namespace OHOS 127 #endif