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 FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_DATASHARE_BRIDGE_H 17 #define FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_DATASHARE_BRIDGE_H 18 19 #include <condition_variable> 20 #include <mutex> 21 22 #include "kvstore_result_set.h" 23 #include "result_set_bridge.h" 24 #include "single_kvstore.h" 25 26 namespace OHOS { 27 namespace Media { 28 class ThumbnailSemaphore { 29 public: 30 explicit ThumbnailSemaphore(int32_t count); 31 virtual ~ThumbnailSemaphore() = default; 32 33 void Signal(); 34 void Wait(); 35 36 private: 37 std::mutex mutex_; 38 std::condition_variable cv_; 39 int32_t count_; 40 }; 41 42 class ThumbnailDataShareBridge : public DataShare::ResultSetBridge { 43 public: 44 virtual ~ThumbnailDataShareBridge() = default; 45 int GetRowCount(int32_t &count) override; 46 int GetAllColumnNames(std::vector<std::string> &columnNames) override; 47 int OnGo(int32_t startRowIndex, int32_t targetRowIndex, DataShare::ResultSetBridge::Writer &writer) override; 48 static std::shared_ptr<DataShare::ResultSetBridge> Create( 49 const std::shared_ptr<DistributedKv::SingleKvStore> &singleKvStorePtr, 50 const std::string &thumbnailkey); 51 52 private: 53 ThumbnailDataShareBridge() = default; 54 ThumbnailDataShareBridge(const std::shared_ptr<DistributedKv::SingleKvStore> &kvStore, const std::string &key); 55 bool FillBlock(int startRowIndex, DataShare::ResultSetBridge::Writer &Writer); 56 57 std::shared_ptr<DistributedKv::SingleKvStore> singleKvStorePtr_; 58 std::string thumbnailKey_; 59 static ThumbnailSemaphore sem_; 60 }; 61 } // namespace Media 62 } // namespace OHOS 63 #endif // FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_DATASHARE_BRIDGE_H 64