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_DEFERRED_PHOTO_CONTROLLER_H
17 #define OHOS_CAMERA_DPS_DEFERRED_PHOTO_CONTROLLER_H
18 
19 #include "basic_definitions.h"
20 #include "photo_job_repository.h"
21 #include "user_initiated_strategy.h"
22 #include "background_strategy.h"
23 #include "iimage_process_callbacks.h"
24 #include "deferred_photo_processor.h"
25 #include "ievents_listener.h"
26 
27 namespace OHOS {
28 namespace CameraStandard {
29 namespace DeferredProcessing {
30 class DeferredPhotoController {
31 public:
32     DeferredPhotoController(const int32_t userId, std::shared_ptr<PhotoJobRepository> repository,
33         std::shared_ptr<DeferredPhotoProcessor> processor);
34     ~DeferredPhotoController();
35     void Initialize();
36 
37 private:
38     class EventsListener;
39     class PhotoJobRepositoryListener;
40     void TryDoSchedule();
41     void PostProcess(DeferredPhotoWorkPtr work);
42     void SetDefaultExecutionMode();
43     void NotifyPressureLevelChanged(SystemPressureLevel level);
44     void NotifyHdiStatusChanged(HdiStatus status);
45     void NotifyMediaLibStatusChanged(MediaLibraryStatus status);
46     void NotifyCameraStatusChanged(CameraSessionStatus status);
47     void OnPhotoJobChanged(bool priorityChanged, bool statusChanged, DeferredPhotoJobPtr jobPtr);
48     void StartWaitForUser();
49     void StopWaitForUser();
50     void NotifyScheduleState(bool scheduling);
51 
52     std::recursive_mutex mutex_;
53     const int32_t userId_;
54     uint32_t callbackHandle_;
55     bool isWaitForUser_;
56     DpsStatus scheduleState_;
57     std::shared_ptr<PhotoJobRepository> photoJobRepository_;
58     std::shared_ptr<DeferredPhotoProcessor> photoProcessor_;
59     std::unique_ptr<UserInitiatedStrategy> userInitiatedStrategy_;
60     std::unique_ptr<BackgroundStrategy> backgroundStrategy_;
61     std::shared_ptr<EventsListener> eventsListener_;
62     std::shared_ptr<PhotoJobRepositoryListener> photoJobRepositoryListener_;
63 };
64 } // namespace DeferredProcessing
65 } // namespace CameraStandard
66 } // namespace OHOS
67 #endif // OHOS_CAMERA_DPS_DEFERRED_PHOTO_CONTROLLER_H