1 /*
2  * Copyright (C) 2024 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 MULTISTAGES_CAPTURE_REQUEST_TASK_MANAGER_H
17 #define MULTISTAGES_CAPTURE_REQUEST_TASK_MANAGER_H
18 
19 #include <mutex>
20 #include <string>
21 #include <unordered_set>
22 #include <unordered_map>
23 
24 namespace OHOS {
25 namespace Media {
26 #define EXPORT __attribute__ ((visibility ("default")))
27 enum class PhotoState : int32_t {
28     NORMAL = 0, // state of photo in normal album
29     TRASHED,    // state of photo in trashed album
30     DELETED,    // state of photo delete from trashed album
31 };
32 
33 enum class RequestType : int32_t {
34     CANCEL_REQUEST = -1,
35     REQUEST = 1,
36 };
37 
38 struct LowQualityPhotoInfo {
39     int32_t fileId;
40     PhotoState state;
41     int32_t requestCount;
LowQualityPhotoInfoLowQualityPhotoInfo42     LowQualityPhotoInfo() : fileId(0), state(PhotoState::NORMAL), requestCount(0) {}
LowQualityPhotoInfoLowQualityPhotoInfo43     LowQualityPhotoInfo(int32_t fileId, PhotoState state, int32_t count)
44         : fileId(fileId), state(state), requestCount(count) {}
45 };
46 
47 class MultiStagesCaptureRequestTaskManager {
48 public:
49     EXPORT static void AddPhotoInProgress(int32_t fileId, const std::string &photoId, bool isTrashed);
50     EXPORT static void RemovePhotoInProgress(const std::string &photoId, bool isRestorable);
51     static void UpdatePhotoInProgress(const std::string &photoId);
52     static bool IsPhotoInProcess(const std::string &photoId);
53     static int32_t UpdatePhotoInProcessRequestCount(const std::string &photoId, RequestType requestType);
54     static std::string GetProcessingPhotoId(int32_t fileId);
55 
56 private:
57     // key: file_id, value: photo_id
58     EXPORT static std::unordered_map<int32_t, std::string> fileId2PhotoId_;
59 
60     // key: photo_id
61     EXPORT static std::unordered_map<std::string, std::shared_ptr<LowQualityPhotoInfo>> photoIdInProcess_;
62 
63     static std::mutex mutex_;
64 };
65 } // Media
66 } // OHOS
67 #endif // MULTISTAGES_CAPTURE_REQUEST_TASK_MANAGER_H