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_AGING_HELPER_H_
17 #define FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_AGING_HELPER_H_
18 
19 #include "medialibrary_async_worker.h"
20 #include "rdb_helper.h"
21 #include "single_kvstore.h"
22 #include "thumbnail_utils.h"
23 
24 namespace OHOS {
25 namespace Media {
26 class AgingAsyncTaskData : public AsyncTaskData {
27 public:
28     AgingAsyncTaskData() = default;
29     virtual ~AgingAsyncTaskData() override = default;
30     ThumbRdbOpt opts;
31     ThumbnailData thumbnailData;
32 };
33 
34 class ThumbnailAgingHelper {
35 public:
36     ThumbnailAgingHelper() = delete;
37     virtual ~ThumbnailAgingHelper() = delete;
38 
39     static int32_t AgingLcdBatch(ThumbRdbOpt &opts);
40 
41 #ifdef DISTRIBUTED
42     static int32_t AgingDistributeLcdBatch(ThumbRdbOpt &opts);
43     static int32_t InvalidateDistributeBatch(ThumbRdbOpt &opts);
44     static int32_t ClearKeyAndRecordFromMap(ThumbRdbOpt &opts);
45     static int32_t ClearRemoteLcdFromFileTable(ThumbRdbOpt &opts);
46 #endif
47     static int32_t ClearLcdFromFileTable(ThumbRdbOpt &opts);
48     static int32_t GetAgingDataCount(const int64_t &time, const bool &before, ThumbRdbOpt &opts, int &count);
49 private:
50     static int32_t GetLcdCount(ThumbRdbOpt &opts, int &outLcdCount);
51     static int32_t GetAgingLcdData(ThumbRdbOpt &opts, int LcdLimit, std::vector<ThumbnailData> &outDatas);
52     static int32_t GetDistributeLcdCount(ThumbRdbOpt &opts, int &outLcdCount);
53     static int32_t GetAgingDistributeLcdData(ThumbRdbOpt &opts,
54         int LcdLimit, std::vector<ThumbnailData> &outDatas);
55     static int32_t GetLcdCountByTime(const int64_t &time, const bool &before, ThumbRdbOpt &opts, int &outLcdCount);
56 };
57 } // namespace Media
58 } // namespace OHOS
59 
60 #endif  // FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_AGING_HELPER_H_
61