1 /* 2 * Copyright (c) 2021 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_AAFWK_DATAOBS_MANAGER_CLIENT_H 17 #define OHOS_AAFWK_DATAOBS_MANAGER_CLIENT_H 18 19 #include <mutex> 20 21 #include "data_ability_observer_interface.h" 22 #include "dataobs_mgr_errors.h" 23 #include "dataobs_mgr_interface.h" 24 #include "uri.h" 25 26 #include "iremote_object.h" 27 28 namespace OHOS { 29 namespace AAFwk { 30 /** 31 * @class DataObsMgrClient 32 * DataObsMgrClient is used to access dataobs manager services. 33 */ 34 class DataObsMgrClient { 35 public: 36 DataObsMgrClient(); 37 virtual ~DataObsMgrClient(); 38 static std::shared_ptr<DataObsMgrClient> GetInstance(); 39 40 /** 41 * Registers an observer to DataObsMgr specified by the given Uri. 42 * 43 * @param uri, Indicates the path of the data to operate. 44 * @param dataObserver, Indicates the IDataAbilityObserver object. 45 * 46 * @return Returns ERR_OK on success, others on failure. 47 */ 48 ErrCode RegisterObserver(const Uri &uri, const sptr<IDataAbilityObserver> &dataObserver); 49 50 /** 51 * Deregisters an observer used for DataObsMgr specified by the given Uri. 52 * 53 * @param uri, Indicates the path of the data to operate. 54 * @param dataObserver, Indicates the IDataAbilityObserver object. 55 * 56 * @return Returns ERR_OK on success, others on failure. 57 */ 58 ErrCode UnregisterObserver(const Uri &uri, const sptr<IDataAbilityObserver> &dataObserver); 59 60 /** 61 * Notifies the registered observers of a change to the data resource specified by Uri. 62 * 63 * @param uri, Indicates the path of the data to operate. 64 * 65 * @return Returns ERR_OK on success, others on failure. 66 */ 67 ErrCode NotifyChange(const Uri &uri); 68 69 private: 70 /** 71 * Connect dataobs manager service. 72 * 73 * @return Returns ERR_OK on success, others on failure. 74 */ 75 ErrCode Connect(); 76 77 static std::mutex mutex_; 78 static std::shared_ptr<DataObsMgrClient> instance_; 79 sptr<IRemoteObject> remoteObject_; 80 }; 81 } // namespace AAFwk 82 } // namespace OHOS 83 #endif // OHOS_AAFWK_DATAOBS_MANAGER_CLIENT_H 84