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 FILE_ACCESS_SERVICE_CLIENT_H 17 #define FILE_ACCESS_SERVICE_CLIENT_H 18 19 #include "ifile_access_service_base.h" 20 #include "iremote_proxy.h" 21 #include "system_ability_load_callback_stub.h" 22 #include "file_access_service_base_proxy.h" 23 24 namespace OHOS { 25 namespace FileAccessFwk { 26 class FileAccessServiceClient { 27 public: 28 29 ~FileAccessServiceClient() = default; 30 static sptr<IFileAccessServiceBase> GetInstance(); 31 static void InvaildInstance(); 32 33 class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub { 34 public: 35 void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject) override; 36 void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; 37 std::condition_variable proxyConVar_; 38 std::atomic<bool> isLoadSuccess_{false}; 39 }; 40 41 private: 42 class ProxyDeathRecipient : public IRemoteObject::DeathRecipient { 43 public: ProxyDeathRecipient(std::function<void (const wptr<IRemoteObject> &)> functor)44 explicit ProxyDeathRecipient(std::function<void(const wptr<IRemoteObject> &)> functor) : functor_(functor) {}; 45 virtual ~ProxyDeathRecipient() = default; 46 public: OnRemoteDied(const wptr<IRemoteObject> & object)47 void OnRemoteDied(const wptr<IRemoteObject> &object) override 48 { 49 auto ptr = object.promote(); 50 if (!ptr) { 51 HILOG_ERROR("remote object is nullptr"); 52 return; 53 } 54 ptr->RemoveDeathRecipient(this); 55 functor_(ptr); 56 }; 57 private: 58 std::function<void(const wptr<IRemoteObject> &)> functor_; 59 }; 60 int32_t UnregisterNotifyInternal(MessageParcel &data); 61 static inline std::mutex proxyMutex_; 62 static inline sptr<IFileAccessServiceBase> serviceProxy_; 63 }; 64 } // namespace FileAccessFwk 65 } // namespace OHOS 66 #endif // FILE_ACCESS_SERVICE_CLIENT_H 67