1 /*
2  * Copyright (c) 2023-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 OHOS_CAMERA_DPS_SCHEDULE_CONTROLLER_H
17 #define OHOS_CAMERA_DPS_SCHEDULE_CONTROLLER_H
18 
19 #include "set"
20 
21 #include "iimage_process_callbacks.h"
22 #include "photo_job_repository.h"
23 #include "photo_post_processor.h"
24 
25 namespace OHOS {
26 namespace CameraStandard {
27 namespace DeferredProcessing {
28 class DeferredPhotoProcessor : public IImageProcessCallbacks {
29 public:
30     DeferredPhotoProcessor(const int32_t userId, TaskManager* taskManager,
31         std::shared_ptr<PhotoJobRepository> repository, std::shared_ptr<IImageProcessCallbacks> callbacks);
32     ~DeferredPhotoProcessor();
33     void Initialize();
34 
35     void AddImage(const std::string& imageId, bool discardable, DpsMetadata& metadata);
36     void RemoveImage(const std::string& imageId, bool restorable);
37     void RestoreImage(const std::string& imageId);
38     void ProcessImage(const std::string& appName, const std::string& imageId);
39     void CancelProcessImage(const std::string& imageId);
40 
41     void SetCallback(IImageProcessCallbacks callbacks);
42 
43     void OnProcessDone(const int32_t userId,
44         const std::string& imageId, std::shared_ptr<BufferInfo> bufferInfo) override;
45     void OnProcessDoneExt(int userId, const std::string& imageId, std::shared_ptr<BufferInfoExt> bufferInfo) override;
46     void OnError(const int32_t userId, const std::string& imageId, DpsError errorCode) override;
47     void OnStateChanged(const int32_t userId, DpsStatus statusCode) override;
48     void NotifyScheduleState(DpsStatus status);
49 
50     void PostProcess(DeferredPhotoWorkPtr work);
51     void SetDefaultExecutionMode();
52     void Interrupt();
53     int GetConcurrency(ExecutionMode mode);
54     bool GetPendingImages(std::vector<std::string>& pendingImages);
55 
56 private:
57     bool IsFatalError(DpsError errorCode);
58 
59     const int32_t userId_;
60     TaskManager* taskManager_;
61     std::shared_ptr<PhotoJobRepository> repository_;
62     std::shared_ptr<PhotoPostProcessor> postProcessor_;
63     std::shared_ptr<IImageProcessCallbacks> callbacks_;
64     std::set<std::string> requestedImages_;
65     std::string postedImageId_;
66 };
67 } // namespace DeferredProcessing
68 } // namespace CameraStandard
69 } // namespace OHOS
70 #endif // OHOS_CAMERA_DPS_SCHEDULE_CONTROLLER_H