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 FILE_ACCESS_SERVICE_PROXY_H 17 #define FILE_ACCESS_SERVICE_PROXY_H 18 19 #include "ifile_access_service_base.h" 20 #include "iremote_proxy.h" 21 #include "system_ability_load_callback_stub.h" 22 23 namespace OHOS { 24 namespace FileAccessFwk { 25 class FileAccessServiceProxy : public IRemoteProxy<IFileAccessServiceBase> { 26 public: FileAccessServiceProxy(const sptr<IRemoteObject> & impl)27 explicit FileAccessServiceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IFileAccessServiceBase>(impl) {} 28 ~FileAccessServiceProxy() = default; 29 static sptr<IFileAccessServiceBase> GetInstance(); 30 int32_t OnChange(Uri uri, NotifyType notifyType) override; 31 int32_t RegisterNotify(Uri uri, bool notifyForDescendants, const sptr<IFileAccessObserver> &observer) override; 32 int32_t UnregisterNotify(Uri uri, const sptr<IFileAccessObserver> &observer) override; 33 34 class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub { 35 public: 36 void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject) override; 37 void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; 38 std::condition_variable proxyConVar_; 39 std::atomic<bool> isLoadSuccess_{false}; 40 }; 41 42 private: 43 int32_t UnregisterNotifyInternal(MessageParcel &data); 44 static inline std::mutex proxyMutex_; 45 static inline sptr<IFileAccessServiceBase> serviceProxy_; 46 static inline BrokerDelegator<FileAccessServiceProxy> delegator_; 47 }; 48 } // namespace FileAccessFwk 49 } // namespace OHOS 50 #endif // FILE_ACCESS_SERVICE_PROXY_H