1 /* 2 * Copyright (c) 2025 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 #include "remote_file_share.h" 28 29 namespace OHOS { 30 namespace Storage { 31 namespace DistributedFile { 32 class DistributedFileDaemonProxy : public IRemoteProxy<IDaemon> { 33 public: DistributedFileDaemonProxy(const sptr<IRemoteObject> & impl)34 explicit DistributedFileDaemonProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IDaemon>(impl) {} ~DistributedFileDaemonProxy()35 ~DistributedFileDaemonProxy() override {} 36 37 static sptr<IDaemon> GetInstance(); 38 static void InvaildInstance(); 39 40 int32_t OpenP2PConnection(const DistributedHardware::DmDeviceInfo &deviceInfo) override; 41 int32_t CloseP2PConnection(const DistributedHardware::DmDeviceInfo &deviceInfo) override; 42 int32_t OpenP2PConnectionEx(const std::string &networkId, sptr<IFileDfsListener> remoteReverseObj) override; 43 int32_t CloseP2PConnectionEx(const std::string &networkId) override; 44 int32_t PrepareSession(const std::string &srcUri, 45 const std::string &dstUri, 46 const std::string &srcDeviceId, 47 const sptr<IRemoteObject> &listener, 48 HmdfsInfo &info) override; 49 int32_t CancelCopyTask(const std::string &sessionName) override; 50 int32_t CancelCopyTask(const std::string &srcUri, const std::string &dstUri) override; 51 int32_t RequestSendFile(const std::string &srcUri, 52 const std::string &dstPath, 53 const std::string &dstDeviceId, 54 const std::string &sessionName) override; 55 int32_t GetRemoteCopyInfo(const std::string &srcUri, bool &isFile, bool &isDir) override; 56 57 int32_t PushAsset(int32_t userId, 58 const sptr<AssetObj> &assetObj, 59 const sptr<IAssetSendCallback> &sendCallback) override; 60 int32_t RegisterAssetCallback(const sptr<IAssetRecvCallback> &recvCallback) override; 61 int32_t UnRegisterAssetCallback(const sptr<IAssetRecvCallback> &recvCallback) override; 62 int32_t GetDfsUrisDirFromLocal(const std::vector<std::string> &uriList, 63 const int32_t userId, 64 std::unordered_map<std::string, AppFileService::ModuleRemoteFileShare::HmdfsUriInfo> 65 &uriToDfsUriMaps) override; 66 int32_t GetDfsSwitchStatus(const std::string &networkId, int32_t &switchStatus) override; 67 int32_t UpdateDfsSwitchStatus(int32_t switchStatus) override; 68 int32_t GetConnectedDeviceList(std::vector<DfsDeviceInfo> &deviceList) override; 69 private: 70 class DaemonDeathRecipient : public IRemoteObject::DeathRecipient { 71 public: DaemonDeathRecipient()72 DaemonDeathRecipient(){}; 73 ~DaemonDeathRecipient() = default; 74 using RemoteDiedHandler = std::function<void(const wptr<IRemoteObject> &)>; 75 void SetDeathRecipient(RemoteDiedHandler handler); 76 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 77 78 private: 79 RemoteDiedHandler handler_{ nullptr }; 80 }; 81 static void OnRemoteSaDied(const wptr<IRemoteObject> &remote); 82 static inline std::mutex proxyMutex_; 83 static inline sptr<IDaemon> daemonProxy_; 84 static inline BrokerDelegator<DistributedFileDaemonProxy> delegator_; 85 static inline sptr<DaemonDeathRecipient> deathRecipient_; 86 }; 87 88 } // namespace DistributedFile 89 } // namespace Storage 90 } // namespace OHOS 91 #endif // OHOS_STORAGE_DISTRIBUTED_FILE_DAEMON_PROXY_H