1 /*
2 * Copyright (c) 2024-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 #include "photo_process_command.h"
17
18 #include "dp_utils.h"
19 #include "dps.h"
20
21 namespace OHOS {
22 namespace CameraStandard {
23 namespace DeferredProcessing {
PhotoProcessCommand(const int32_t userId)24 PhotoProcessCommand::PhotoProcessCommand(const int32_t userId) : userId_(userId)
25 {
26 DP_DEBUG_LOG("entered. userId: %{public}d", userId_);
27 }
28
~PhotoProcessCommand()29 PhotoProcessCommand::~PhotoProcessCommand()
30 {
31 DP_DEBUG_LOG("entered.");
32 }
33
Initialize()34 int32_t PhotoProcessCommand::Initialize()
35 {
36 DP_CHECK_RETURN_RET(initialized_.load(), DP_OK);
37 auto schedulerManager = DPS_GetSchedulerManager();
38 DP_CHECK_ERROR_RETURN_RET_LOG(schedulerManager == nullptr, DP_NULL_POINTER, "SchedulerManager is nullptr.");
39 photoProcessor_ = schedulerManager->GetPhotoProcessor(userId_);
40 DP_CHECK_ERROR_RETURN_RET_LOG(photoProcessor_ == nullptr, DP_NULL_POINTER, "DeferredPhotoProcessor is nullptr.");
41 initialized_.store(true);
42 return DP_OK;
43 }
44
PhotoProcessSuccessCommand(const int32_t userId,const std::string & imageId,std::unique_ptr<ImageInfo> imageInfo)45 PhotoProcessSuccessCommand::PhotoProcessSuccessCommand(const int32_t userId, const std::string& imageId,
46 std::unique_ptr<ImageInfo> imageInfo)
47 : PhotoProcessCommand(userId), imageId_(imageId), imageInfo_(std::move(imageInfo))
48 {
49 DP_DEBUG_LOG("entered.");
50 }
51
Executing()52 int32_t PhotoProcessSuccessCommand::Executing()
53 {
54 int32_t ret = Initialize();
55 if (ret != DP_OK) {
56 return ret;
57 }
58
59 photoProcessor_->OnProcessSuccess(userId_, imageId_, std::move(imageInfo_));
60 return DP_OK;
61 }
62
PhotoProcessFailedCommand(const int32_t userId,const std::string & imageId,DpsError errorCode)63 PhotoProcessFailedCommand::PhotoProcessFailedCommand(const int32_t userId,
64 const std::string& imageId, DpsError errorCode)
65 : PhotoProcessCommand(userId), imageId_(imageId), error_(errorCode)
66 {
67 DP_DEBUG_LOG("entered.");
68 }
69
Executing()70 int32_t PhotoProcessFailedCommand::Executing()
71 {
72 int32_t ret = Initialize();
73 if (ret != DP_OK) {
74 return ret;
75 }
76
77 photoProcessor_->OnProcessError(userId_, imageId_, error_);
78 return DP_OK;
79 }
80
Executing()81 int32_t PhotoProcessTimeOutCommand::Executing()
82 {
83 if (int32_t ret = Initialize() != DP_OK) {
84 return ret;
85 }
86
87 photoProcessor_->OnProcessError(userId_, imageId_, error_);
88 return DP_OK;
89 }
90 } // namespace DeferredProcessing
91 } // namespace CameraStandard
92 } // namespace OHOS