1 /* 2 * Copyright (c) 2023-2024 Huawei Device 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_STORAGE_DISTRIBUTED_FILE_DAEMON_PROXY_H 17 #define OHOS_STORAGE_DISTRIBUTED_FILE_DAEMON_PROXY_H 18 19 #include <cstdint> 20 21 #include "asset/asset_obj.h" 22 #include "asset/i_asset_recv_callback.h" 23 #include "asset/i_asset_send_callback.h" 24 #include "dm_device_info.h" 25 #include "ipc/i_daemon.h" 26 #include "iremote_proxy.h" 27 28 namespace OHOS { 29 namespace Storage { 30 namespace DistributedFile { 31 class DistributedFileDaemonProxy : public IRemoteProxy<IDaemon> { 32 public: DistributedFileDaemonProxy(const sptr<IRemoteObject> & impl)33 explicit DistributedFileDaemonProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IDaemon>(impl) {} ~DistributedFileDaemonProxy()34 ~DistributedFileDaemonProxy() override {} 35 36 static sptr<IDaemon> GetInstance(); 37 static void InvaildInstance(); 38 39 int32_t OpenP2PConnection(const DistributedHardware::DmDeviceInfo &deviceInfo) override; 40 int32_t CloseP2PConnection(const DistributedHardware::DmDeviceInfo &deviceInfo) override; 41 int32_t OpenP2PConnectionEx(const std::string &networkId, sptr<IFileDfsListener> remoteReverseObj) override; 42 int32_t CloseP2PConnectionEx(const std::string &networkId) override; 43 int32_t PrepareSession(const std::string &srcUri, 44 const std::string &dstUri, 45 const std::string &srcDeviceId, 46 const sptr<IRemoteObject> &listener, 47 HmdfsInfo &info) override; 48 int32_t CancelCopyTask(const std::string &sessionName) override; 49 int32_t RequestSendFile(const std::string &srcUri, 50 const std::string &dstPath, 51 const std::string &dstDeviceId, 52 const std::string &sessionName) override; 53 int32_t GetRemoteCopyInfo(const std::string &srcUri, bool &isFile, bool &isDir) override; 54 55 int32_t PushAsset(int32_t userId, 56 const sptr<AssetObj> &assetObj, 57 const sptr<IAssetSendCallback> &sendCallback) override; 58 int32_t RegisterAssetCallback(const sptr<IAssetRecvCallback> &recvCallback) override; 59 int32_t UnRegisterAssetCallback(const sptr<IAssetRecvCallback> &recvCallback) override; 60 private: 61 class DaemonDeathRecipient : public IRemoteObject::DeathRecipient { 62 public: DaemonDeathRecipient()63 DaemonDeathRecipient(){}; 64 ~DaemonDeathRecipient() = default; 65 using RemoteDiedHandler = std::function<void(const wptr<IRemoteObject> &)>; 66 void SetDeathRecipient(RemoteDiedHandler handler); 67 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 68 69 private: 70 RemoteDiedHandler handler_{ nullptr }; 71 }; 72 static void OnRemoteSaDied(const wptr<IRemoteObject> &remote); 73 static inline std::mutex proxyMutex_; 74 static inline sptr<IDaemon> daemonProxy_; 75 static inline BrokerDelegator<DistributedFileDaemonProxy> delegator_; 76 static inline sptr<DaemonDeathRecipient> deathRecipient_; 77 }; 78 79 } // namespace DistributedFile 80 } // namespace Storage 81 } // namespace OHOS 82 #endif // OHOS_STORAGE_DISTRIBUTED_FILE_DAEMON_PROXY_H