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_SERVICE_IMPL_H 17 #define GENERAL_CONTROLLER_SERVICE_IMPL_H 18 19 #include <memory> 20 21 #include "concurrent_map.h" 22 #include "data_share_manager_impl.h" 23 #include "general_controller.h" 24 #include "uri.h" 25 26 namespace OHOS { 27 namespace AAFwk { 28 class IDataAbilityObserver; 29 } 30 31 namespace DataShare { 32 class GeneralControllerServiceImpl : public GeneralController { 33 public: 34 GeneralControllerServiceImpl(const std::string &ext); 35 36 virtual ~GeneralControllerServiceImpl(); 37 38 int Insert(const Uri &uri, const DataShareValuesBucket &value) override; 39 40 int Update(const Uri &uri, const DataSharePredicates &predicates, const DataShareValuesBucket &value) override; 41 42 int Delete(const Uri &uri, const DataSharePredicates &predicates) override; 43 44 std::shared_ptr<DataShareResultSet> Query(const Uri &uri, const DataSharePredicates &predicates, 45 std::vector<std::string> &columns, DatashareBusinessError &businessError) override; 46 47 int RegisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver) override; 48 49 int UnregisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver) override; 50 51 void NotifyChange(const Uri &uri) override; 52 53 std::pair<int32_t, int32_t> InsertEx(const Uri &uri, const DataShareValuesBucket &value) override; 54 55 std::pair<int32_t, int32_t> UpdateEx( 56 const Uri &uri, const DataSharePredicates &predicates, const DataShareValuesBucket &value) override; 57 58 std::pair<int32_t, int32_t> DeleteEx(const Uri &uri, const DataSharePredicates &predicates) override; 59 60 private: 61 void ReRegisterObserver(); 62 63 void SetRegisterCallback(); 64 65 ConcurrentMap<sptr<AAFwk::IDataAbilityObserver>, std::list<Uri>> observers_; 66 67 std::string extUri_; 68 69 static constexpr int MAX_RETRY_COUNT = 3; 70 71 static constexpr int RANDOM_MIN = 50; 72 73 static constexpr int RANDOM_MAX = 150; 74 }; 75 } // namespace DataShare 76 } // namespace OHOS 77 #endif // GENERAL_CONTROLLER_SERVICE_IMPL_H 78