1 /* 2 * Copyright (c) 2022 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 KVSTORE_DATASHARE_BRIDGE_H 17 #define KVSTORE_DATASHARE_BRIDGE_H 18 19 #include "kvstore_result_set.h" 20 #include "single_kvstore.h" 21 #include "result_set_bridge.h" 22 #include "datashare_errno.h" 23 24 namespace OHOS { 25 namespace DistributedKv { 26 class KvStoreDataShareBridge : public DataShare::ResultSetBridge { 27 public: 28 KvStoreDataShareBridge(std::shared_ptr<KvStoreResultSet> kvResultSet); 29 30 ~KvStoreDataShareBridge() = default; 31 32 int GetRowCount(int32_t &count) override; 33 34 int GetAllColumnNames(std::vector<std::string> &columnNames) override; 35 36 int OnGo(int32_t startRowIndex, int32_t targetRowIndex, DataShare::ResultSetBridge::Writer &writer) override; 37 38 private: 39 int Count(); 40 41 bool FillBlock(int startRowIndex, DataShare::ResultSetBridge::Writer &writer) __attribute__((no_sanitize("cfi"))); 42 43 static constexpr int32_t INVALID_COUNT = -1; 44 45 int32_t resultRowCount {INVALID_COUNT}; 46 47 std::shared_ptr<KvStoreResultSet> kvResultSet_; 48 }; 49 } // namespace DistributedKv 50 } // namespace OHOS 51 #endif // KVSTORE_DATASHARE_BRIDGE_H 52