1 /* 2 * Copyright (c) 2021-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_ABILITY_RUNTIME_DATAOBS_MGR_PROXY_H 17 #define OHOS_ABILITY_RUNTIME_DATAOBS_MGR_PROXY_H 18 19 #include "dataobs_mgr_interface.h" 20 #include "iremote_proxy.h" 21 #include "dataobs_mgr_errors.h" 22 23 namespace OHOS { 24 namespace AAFwk { 25 /** 26 * @class DataObsManagerProxy 27 * DataObsManagerProxy. 28 */ 29 class DataObsManagerProxy : public IRemoteProxy<IDataObsMgr> { 30 public: DataObsManagerProxy(const sptr<IRemoteObject> & impl)31 explicit DataObsManagerProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IDataObsMgr>(impl) 32 {} 33 ~DataObsManagerProxy()34 virtual ~DataObsManagerProxy() 35 {} 36 37 /** 38 * Registers an observer to DataObsMgr specified by the given Uri. 39 * 40 * @param uri, Indicates the path of the data to operate. 41 * @param dataObserver, Indicates the IDataAbilityObserver object. 42 * 43 * @return Returns ERR_OK on success, others on failure. 44 */ 45 46 virtual int RegisterObserver(const Uri &uri, sptr<IDataAbilityObserver> dataObserver) override; 47 48 /** 49 * Deregisters an observer used for DataObsMgr specified by the given Uri. 50 * 51 * @param uri, Indicates the path of the data to operate. 52 * @param dataObserver, Indicates the IDataAbilityObserver object. 53 * 54 * @return Returns ERR_OK on success, others on failure. 55 */ 56 virtual int UnregisterObserver(const Uri &uri, sptr<IDataAbilityObserver> dataObserver) override; 57 58 /** 59 * Notifies the registered observers of a change to the data resource specified by Uri. 60 * 61 * @param uri, Indicates the path of the data to operate. 62 * 63 * @return Returns ERR_OK on success, others on failure. 64 */ 65 virtual int NotifyChange(const Uri &uri) override; 66 67 /** 68 * Registers an observer to DataObsMgr specified by the given Uri. 69 * 70 * @param uri, Indicates the path of the data to operate. 71 * @param dataObserver, Indicates the IDataAbilityObserver object. 72 * @param isDescendants, Indicates the Whether to note the change of descendants. 73 * 74 * @return Returns SUCCESS on success, others on failure. 75 */ 76 virtual Status RegisterObserverExt(const Uri &uri, sptr<IDataAbilityObserver> dataObserver, 77 bool isDescendants) override; 78 79 /** 80 * Deregisters an observer used for DataObsMgr specified by the given Uri. 81 * 82 * @param uri, Indicates the path of the data to operate. 83 * @param dataObserver, Indicates the IDataAbilityObserver object. 84 * 85 * @return Returns SUCCESS on success, others on failure. 86 */ 87 virtual Status UnregisterObserverExt(const Uri &uri, sptr<IDataAbilityObserver> dataObserver) override; 88 89 /** 90 * Deregisters dataObserver used for DataObsMgr specified 91 * 92 * @param dataObserver, Indicates the IDataAbilityObserver object. 93 * 94 * @return Returns SUCCESS on success, others on failure. 95 */ 96 virtual Status UnregisterObserverExt(sptr<IDataAbilityObserver> dataObserver) override; 97 98 /** 99 * Notifies the registered observers of a change to the data resource specified by Uris. 100 * 101 * @param changeInfo Indicates the info of the data to operate. 102 * 103 * @return Returns SUCCESS on success, others on failure. 104 */ 105 virtual Status NotifyChangeExt(const ChangeInfo &changeInfo) override; 106 107 private: 108 bool WriteInterfaceToken(MessageParcel &data); 109 bool WriteParam(MessageParcel &data, const Uri &uri, sptr<IDataAbilityObserver> dataObserver); 110 int SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 111 112 private: 113 static inline BrokerDelegator<DataObsManagerProxy> delegator_; 114 }; 115 } // namespace AAFwk 116 } // namespace OHOS 117 #endif // OHOS_ABILITY_RUNTIME_DATAOBS_MGR_PROXY_H 118