1 /* 2 * Copyright (c) 2023 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 "dm_device_info.h" 22 #include "ipc/i_daemon.h" 23 #include "iremote_proxy.h" 24 25 26 namespace OHOS { 27 namespace Storage { 28 namespace DistributedFile { 29 class DistributedFileDaemonProxy : public IRemoteProxy<IDaemon> { 30 public: DistributedFileDaemonProxy(const sptr<IRemoteObject> & impl)31 explicit DistributedFileDaemonProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IDaemon>(impl) {} ~DistributedFileDaemonProxy()32 ~DistributedFileDaemonProxy() override {} 33 34 static sptr<IDaemon> GetInstance(); 35 static void InvaildInstance(); 36 37 int32_t OpenP2PConnection(const DistributedHardware::DmDeviceInfo &deviceInfo) override; 38 int32_t CloseP2PConnection(const DistributedHardware::DmDeviceInfo &deviceInfo) override; 39 int32_t PrepareSession(const std::string &srcUri, 40 const std::string &dstUri, 41 const std::string &srcDeviceId, 42 const sptr<IRemoteObject> &listener) override; 43 int32_t RequestSendFile(const std::string &srcUri, 44 const std::string &dstPath, 45 const std::string &dstDeviceId, 46 const std::string &sessionName) override; 47 48 private: 49 class DaemonDeathRecipient : public IRemoteObject::DeathRecipient { 50 public: DaemonDeathRecipient()51 DaemonDeathRecipient(){}; 52 ~DaemonDeathRecipient() = default; 53 using RemoteDiedHandler = std::function<void(const wptr<IRemoteObject> &)>; 54 void SetDeathRecipient(RemoteDiedHandler handler); 55 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 56 57 private: 58 RemoteDiedHandler handler_{ nullptr }; 59 }; 60 static void OnRemoteSaDied(const wptr<IRemoteObject> &remote); 61 static inline std::mutex proxyMutex_; 62 static inline sptr<IDaemon> daemonProxy_; 63 static inline BrokerDelegator<DistributedFileDaemonProxy> delegator_; 64 static inline sptr<DaemonDeathRecipient> deathRecipient_; 65 }; 66 67 } // namespace DistributedFile 68 } // namespace Storage 69 } // namespace OHOS 70 #endif // OHOS_STORAGE_DISTRIBUTED_FILE_DAEMON_PROXY_H