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 int32_t ret = Initialize();
58 if (ret != DP_OK) {
59 return ret;
60 }
61
62 processor_->AddImage(photoId_, discardable_, metadata_);
63 return DP_OK;
64 }
65
RemovePhotoCommand(const int32_t userId,const std::string & photoId,const bool restorable)66 RemovePhotoCommand::RemovePhotoCommand(const int32_t userId, const std::string& photoId, const bool restorable)
67 : PhotoCommand(userId, photoId), restorable_(restorable)
68 {
69 DP_DEBUG_LOG("RemovePhotoCommand, photoId: %{public}s, restorable: %{public}d", photoId_.c_str(), restorable_);
70 }
71
Executing()72 int32_t RemovePhotoCommand::Executing()
73 {
74 int32_t ret = Initialize();
75 if (ret != DP_OK) {
76 return ret;
77 }
78
79 processor_->RemoveImage(photoId_, restorable_);
80 return DP_OK;
81 }
82
Executing()83 int32_t RestorePhotoCommand::Executing()
84 {
85 int32_t ret = Initialize();
86 if (ret != DP_OK) {
87 return ret;
88 }
89
90 processor_->RestoreImage(photoId_);
91 return DP_OK;
92 }
93
ProcessPhotoCommand(const int32_t userId,const std::string & photoId,const std::string & appName)94 ProcessPhotoCommand::ProcessPhotoCommand(const int32_t userId, const std::string& photoId, const std::string& appName)
95 : PhotoCommand(userId, photoId), appName_(appName)
96 {
97 DP_DEBUG_LOG("ProcessPhotoCommand, photoId: %{public}s, appName: %{public}s", photoId_.c_str(), appName.c_str());
98 }
99
Executing()100 int32_t ProcessPhotoCommand::Executing()
101 {
102 int32_t ret = Initialize();
103 if (ret != DP_OK) {
104 return ret;
105 }
106
107 processor_->ProcessImage(appName_, photoId_);
108 return DP_OK;
109 }
110
Executing()111 int32_t CancelProcessPhotoCommand::Executing()
112 {
113 int32_t ret = Initialize();
114 if (ret != DP_OK) {
115 return ret;
116 }
117
118 processor_->CancelProcessImage(photoId_);
119 return DP_OK;
120 }
121 // LCOV_EXCL_STOP
122 } // namespace DeferredProcessing
123 } // namespace CameraStandard
124 } // namespace OHOS