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 GENERAL_CONTROLLER_H 17 #define GENERAL_CONTROLLER_H 18 19 #include <memory> 20 #include <string_ex.h> 21 22 #include "data_ability_observer_interface.h" 23 #include "datashare_business_error.h" 24 #include "datashare_errno.h" 25 #include "datashare_predicates.h" 26 #include "datashare_result_set.h" 27 #include "datashare_values_bucket.h" 28 #include "uri.h" 29 30 namespace OHOS { 31 namespace AAFwk { 32 class IDataAbilityObserver; 33 } 34 35 namespace DataShare { 36 using ChangeInfo = AAFwk::ChangeInfo; 37 class GeneralController { 38 public: 39 virtual ~GeneralController() = default; 40 41 virtual int Insert(const Uri &uri, const DataShareValuesBucket &value) = 0; 42 43 virtual int Update(const Uri &uri, const DataSharePredicates &predicates, const DataShareValuesBucket &value) = 0; 44 45 virtual int Delete(const Uri &uri, const DataSharePredicates &predicates) = 0; 46 47 virtual std::shared_ptr<DataShareResultSet> Query(const Uri &uri, const DataSharePredicates &predicates, 48 std::vector<std::string> &columns, DatashareBusinessError &businessError, DataShareOption &option) = 0; 49 50 virtual int RegisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver) = 0; 51 52 virtual int UnregisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver) = 0; 53 54 virtual void NotifyChange(const Uri &uri) = 0; 55 56 /** 57 * Registers an observer specified by the given Uri to the provider. This function is supported only when using 58 * non-silent DataShareHelper, and there is no default implemention in the provider side. It needs to be handled by 59 * the user. Otherwise, the provider side will do nothing but simply return error. 60 */ 61 virtual int RegisterObserverExtProvider(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver, 62 bool isDescendants) = 0; 63 64 /** 65 * Deregisters an observer specified by the given Uri to the provider. This function is supported only when using 66 * non-silent DataShareHelper, and there is no default implemention in the provider side. It needs to be handled by 67 * the user. Otherwise, the provider side will do nothing but simply return error. 68 */ 69 virtual int UnregisterObserverExtProvider(const Uri &uri, 70 const sptr<AAFwk::IDataAbilityObserver> &dataObserver) = 0; 71 72 /** 73 * Notifies the registered observers of a change to the data resource specified by Uris. This function is supported 74 * only when using non-silent DataShareHelper, and there is no default implemention in the provider side. It needs 75 * to be handled by the user. Otherwise, the provider side will do nothing but simply return true. 76 */ 77 virtual int NotifyChangeExtProvider(const ChangeInfo &changeInfo) = 0; 78 79 virtual std::pair<int32_t, int32_t> InsertEx(const Uri &uri, const DataShareValuesBucket &value) = 0; 80 81 virtual std::pair<int32_t, int32_t> UpdateEx( 82 const Uri &uri, const DataSharePredicates &predicates, const DataShareValuesBucket &value) = 0; 83 84 virtual std::pair<int32_t, int32_t> DeleteEx(const Uri &uri, const DataSharePredicates &predicates) = 0; 85 }; 86 } // namespace DataShare 87 } // namespace OHOS 88 #endif // GENERAL_CONTROLLER_H 89