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