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 #include "scheduler_manager.h"
17
18 #include "dp_utils.h"
19
20 namespace OHOS {
21 namespace CameraStandard {
22 namespace DeferredProcessing {
SchedulerManager()23 SchedulerManager::SchedulerManager()
24 {
25 DP_DEBUG_LOG("entered.");
26 }
27
~SchedulerManager()28 SchedulerManager::~SchedulerManager()
29 {
30 DP_DEBUG_LOG("entered.");
31 photoController_.clear();
32 photoProcessors_.clear();
33 videoController_.clear();
34 videoProcessors_.clear();
35 schedulerCoordinator_ = nullptr;
36 }
37
Initialize()38 int32_t SchedulerManager::Initialize()
39 {
40 DP_DEBUG_LOG("entered.");
41 schedulerCoordinator_ = std::make_unique<SchedulerCoordinator>();
42 schedulerCoordinator_->Initialize();
43 return DP_OK;
44 }
45
GetPhotoProcessor(const int32_t userId,TaskManager * taskManager,std::shared_ptr<IImageProcessCallbacks> callbacks)46 std::shared_ptr<DeferredPhotoProcessor> SchedulerManager::GetPhotoProcessor(const int32_t userId,
47 TaskManager* taskManager, std::shared_ptr<IImageProcessCallbacks> callbacks)
48 {
49 DP_DEBUG_LOG("entered.");
50 DP_CHECK_EXECUTE(photoProcessors_.find(userId) == photoProcessors_.end(),
51 CreatePhotoProcessor(userId, taskManager, callbacks));
52 return photoProcessors_[userId];
53 }
54
55
CreatePhotoProcessor(const int32_t userId,TaskManager * taskManager,std::shared_ptr<IImageProcessCallbacks> callbacks)56 void SchedulerManager::CreatePhotoProcessor(const int32_t userId, TaskManager* taskManager,
57 std::shared_ptr<IImageProcessCallbacks> callbacks)
58 {
59 DP_INFO_LOG("entered");
60 auto photoRepository = std::make_shared<PhotoJobRepository>(userId);
61 auto photoProcessor = std::make_shared<DeferredPhotoProcessor>(userId, taskManager, photoRepository, callbacks);
62 auto photoController = std::make_shared<DeferredPhotoController>(userId, photoRepository, photoProcessor);
63 photoController->Initialize();
64 photoProcessor->Initialize();
65 photoProcessors_[userId] = photoProcessor;
66 photoController_[userId] = photoController;
67 return;
68 }
69
GetVideoProcessor(const int32_t userId)70 std::shared_ptr<DeferredVideoProcessor> SchedulerManager::GetVideoProcessor(const int32_t userId)
71 {
72 DP_DEBUG_LOG("entered.");
73 DP_CHECK_ERROR_RETURN_RET_LOG(videoProcessors_.find(userId) == videoProcessors_.end(), nullptr,
74 "VideoProcessors is nullptr.");
75 return videoProcessors_[userId];
76 }
77
GetVideoController(const int32_t userId)78 std::shared_ptr<DeferredVideoController> SchedulerManager::GetVideoController(const int32_t userId)
79 {
80 DP_DEBUG_LOG("entered.");
81 DP_CHECK_ERROR_RETURN_RET_LOG(videoController_.find(userId) == videoController_.end(), nullptr,
82 "VideoController is nullptr.");
83 return videoController_[userId];
84 }
85
CreateVideoProcessor(const int32_t userId,const std::shared_ptr<IVideoProcessCallbacks> & callbacks)86 void SchedulerManager::CreateVideoProcessor(const int32_t userId,
87 const std::shared_ptr<IVideoProcessCallbacks>& callbacks)
88 {
89 DP_DEBUG_LOG("entered.");
90 auto videoRepository = std::make_shared<VideoJobRepository>(userId);
91 auto videoProcessor = std::make_shared<DeferredVideoProcessor>(userId, videoRepository, callbacks);
92 auto videoController = CreateShared<DeferredVideoController>(userId, videoRepository, videoProcessor);
93 videoController->Initialize();
94 videoProcessor->Initialize();
95 videoProcessors_[userId] = videoProcessor;
96 videoController_[userId] = videoController;
97 }
98 } // namespace DeferredProcessing
99 } // namespace CameraStandard
100 } // namespace OHOS