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_command.h"
17
18 #include "dps.h"
19
20 namespace OHOS {
21 namespace CameraStandard {
22 namespace DeferredProcessing {
23
24 // LCOV_EXCL_START
PhotoCommand(const int32_t userId,const std::string & photoId)25 PhotoCommand::PhotoCommand(const int32_t userId, const std::string& photoId)
26 : userId_(userId), photoId_(photoId)
27 {
28 DP_DEBUG_LOG("entered. userId: %{public}d, photoId: %{public}s", userId_, photoId_.c_str());
29 }
30
~PhotoCommand()31 PhotoCommand::~PhotoCommand()
32 {
33 DP_DEBUG_LOG("entered.");
34 }
35
Initialize()36 int32_t PhotoCommand::Initialize()
37 {
38 DP_CHECK_RETURN_RET(initialized_.load(), DP_OK);
39
40 schedulerManager_ = DPS_GetSchedulerManager();
41 DP_CHECK_ERROR_RETURN_RET_LOG(schedulerManager_ == nullptr, DP_NULL_POINTER, "SchedulerManager is nullptr.");
42 processor_ = schedulerManager_->GetPhotoProcessor(userId_);
43 DP_CHECK_ERROR_RETURN_RET_LOG(processor_ == nullptr, DP_NULL_POINTER, "VideoProcessor is nullptr.");
44 initialized_.store(true);
45 return DP_OK;
46 }
47
AddPhotoCommand(const int32_t userId,const std::string & photoId,const DpsMetadata & metadata,bool discardable)48 AddPhotoCommand::AddPhotoCommand(const int32_t userId, const std::string& photoId, const DpsMetadata& metadata,
49 bool discardable)
50 : PhotoCommand(userId, photoId), metadata_(metadata), discardable_(discardable)
51 {
52 DP_DEBUG_LOG("AddPhotoCommand, photoId: %{public}s, discardable: %{public}d", photoId_.c_str(), discardable_);
53 }
54
Executing()55 int32_t AddPhotoCommand::Executing()
56 {
57 if (int32_t ret = Initialize() != DP_OK) {
58 return ret;
59 }
60
61 processor_->AddImage(photoId_, discardable_, metadata_);
62 return DP_OK;
63 }
64
RemovePhotoCommand(const int32_t userId,const std::string & photoId,const bool restorable)65 RemovePhotoCommand::RemovePhotoCommand(const int32_t userId, const std::string& photoId, const bool restorable)
66 : PhotoCommand(userId, photoId), restorable_(restorable)
67 {
68 DP_DEBUG_LOG("RemovePhotoCommand, photoId: %{public}s, restorable: %{public}d", photoId_.c_str(), restorable_);
69 }
70
Executing()71 int32_t RemovePhotoCommand::Executing()
72 {
73 if (int32_t ret = Initialize() != DP_OK) {
74 return ret;
75 }
76
77 processor_->RemoveImage(photoId_, restorable_);
78 return DP_OK;
79 }
80
Executing()81 int32_t RestorePhotoCommand::Executing()
82 {
83 if (int32_t ret = Initialize() != DP_OK) {
84 return ret;
85 }
86
87 processor_->RestoreImage(photoId_);
88 return DP_OK;
89 }
90
ProcessPhotoCommand(const int32_t userId,const std::string & photoId,const std::string & appName)91 ProcessPhotoCommand::ProcessPhotoCommand(const int32_t userId, const std::string& photoId, const std::string& appName)
92 : PhotoCommand(userId, photoId), appName_(appName)
93 {
94 DP_DEBUG_LOG("RemovePhotoCommand, photoId: %{public}s, appName: %{public}s", photoId_.c_str(), appName.c_str());
95 }
96
Executing()97 int32_t ProcessPhotoCommand::Executing()
98 {
99 if (int32_t ret = Initialize() != DP_OK) {
100 return ret;
101 }
102
103 processor_->ProcessImage(appName_, photoId_);
104 return DP_OK;
105 }
106
Executing()107 int32_t CancelProcessPhotoCommand::Executing()
108 {
109 if (int32_t ret = Initialize() != DP_OK) {
110 return ret;
111 }
112
113 processor_->CancelProcessImage(photoId_);
114 return DP_OK;
115 }
116 // LCOV_EXCL_STOP
117 } // namespace DeferredProcessing
118 } // namespace CameraStandard
119 } // namespace OHOS