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 "deferred_photo_processing_session_proxy.h"
17 #include "deferred_processing_service_ipc_interface_code.h"
18 #include "metadata_utils.h"
19 #include "utils/dp_log.h"
20
21 namespace OHOS {
22 namespace CameraStandard {
23 namespace DeferredProcessing {
DeferredPhotoProcessingSessionProxy(const sptr<IRemoteObject> & impl)24 DeferredPhotoProcessingSessionProxy::DeferredPhotoProcessingSessionProxy(const sptr<IRemoteObject> &impl)
25 : IRemoteProxy<IDeferredPhotoProcessingSession>(impl) { }
26
BeginSynchronize()27 int32_t DeferredPhotoProcessingSessionProxy::BeginSynchronize()
28 {
29 MessageParcel data;
30 MessageParcel reply;
31 MessageOption option;
32
33 data.WriteInterfaceToken(GetDescriptor());
34 int error = Remote()->SendRequest(
35 static_cast<uint32_t>(DeferredProcessingServiceInterfaceCode::DPS_BEGIN_SYNCHRONIZE), data, reply, option);
36 if (error != ERR_NONE) {
37 DP_ERR_LOG("DeferredPhotoProcessingSessionProxy::BeginSynchronize failed, error: %{public}d", error);
38 }
39 return error;
40 }
41
EndSynchronize()42 int32_t DeferredPhotoProcessingSessionProxy::EndSynchronize()
43 {
44 MessageParcel data;
45 MessageParcel reply;
46 MessageOption option;
47
48 data.WriteInterfaceToken(GetDescriptor());
49 int error = Remote()->SendRequest(
50 static_cast<uint32_t>(DeferredProcessingServiceInterfaceCode::DPS_END_SYNCHRONIZE), data, reply, option);
51 if (error != ERR_NONE) {
52 DP_ERR_LOG("DeferredPhotoProcessingSessionProxy::EndSynchronize failed, error: %{public}d", error);
53 }
54 return error;
55 }
56
AddImage(const std::string & imageId,DpsMetadata & metadata,const bool discardable)57 int32_t DeferredPhotoProcessingSessionProxy::AddImage(const std::string& imageId,
58 DpsMetadata& metadata, const bool discardable)
59 {
60 MessageParcel data;
61 MessageParcel reply;
62 MessageOption option;
63
64 data.WriteInterfaceToken(GetDescriptor());
65 data.WriteString(imageId);
66 metadata.WriteToParcel(data);
67 data.WriteBool(discardable);
68
69 int error = Remote()->SendRequest(
70 static_cast<uint32_t>(DeferredProcessingServiceInterfaceCode::DPS_ADD_IMAGE), data, reply, option);
71 if (error != ERR_NONE) {
72 DP_ERR_LOG("DeferredPhotoProcessingSessionProxy::AddImage failed, error: %{public}d", error);
73 }
74 return error;
75 }
76
RemoveImage(const std::string & imageId,const bool restorable)77 int32_t DeferredPhotoProcessingSessionProxy::RemoveImage(const std::string& imageId, const bool restorable)
78 {
79 MessageParcel data;
80 MessageParcel reply;
81 MessageOption option;
82
83 data.WriteInterfaceToken(GetDescriptor());
84 data.WriteString(imageId);
85 data.WriteBool(restorable);
86
87 int error = Remote()->SendRequest(
88 static_cast<uint32_t>(DeferredProcessingServiceInterfaceCode::DPS_REMOVE_IMAGE), data, reply, option);
89 if (error != ERR_NONE) {
90 DP_ERR_LOG("DeferredPhotoProcessingSessionProxy::RemoveImage failed, error: %{public}d", error);
91 }
92 return error;
93 }
94
RestoreImage(const std::string & imageId)95 int32_t DeferredPhotoProcessingSessionProxy::RestoreImage(const std::string& imageId)
96 {
97 MessageParcel data;
98 MessageParcel reply;
99 MessageOption option;
100
101 data.WriteInterfaceToken(GetDescriptor());
102 data.WriteString(imageId);
103
104 int error = Remote()->SendRequest(
105 static_cast<uint32_t>(DeferredProcessingServiceInterfaceCode::DPS_RESTORE_IMAGE), data, reply, option);
106 if (error != ERR_NONE) {
107 DP_ERR_LOG("DeferredPhotoProcessingSessionProxy::RestoreImage failed, error: %{public}d", error);
108 }
109 return error;
110 }
111
ProcessImage(const std::string & appName,const std::string imageId)112 int32_t DeferredPhotoProcessingSessionProxy::ProcessImage(const std::string& appName, const std::string imageId)
113 {
114 MessageParcel data;
115 MessageParcel reply;
116 MessageOption option;
117
118 data.WriteInterfaceToken(GetDescriptor());
119 data.WriteString(appName);
120 data.WriteString(imageId);
121
122 int error = Remote()->SendRequest(
123 static_cast<uint32_t>(DeferredProcessingServiceInterfaceCode::DPS_PROCESS_IMAGE), data, reply, option);
124 if (error != ERR_NONE) {
125 DP_ERR_LOG("DeferredPhotoProcessingSessionProxy::ProcessImage failed, error: %{public}d", error);
126 }
127 return error;
128 }
129
CancelProcessImage(const std::string & imageId)130 int32_t DeferredPhotoProcessingSessionProxy::CancelProcessImage(const std::string& imageId)
131 {
132 MessageParcel data;
133 MessageParcel reply;
134 MessageOption option;
135
136 data.WriteInterfaceToken(GetDescriptor());
137 data.WriteString(imageId);
138
139 int error = Remote()->SendRequest(
140 static_cast<uint32_t>(DeferredProcessingServiceInterfaceCode::DPS_CANCEL_PROCESS_IMAGE), data, reply, option);
141 if (error != ERR_NONE) {
142 DP_ERR_LOG("DeferredPhotoProcessingSessionProxy::CancelProcessImage failed, error: %{public}d", error);
143 }
144 return error;
145 }
146
147 } // namespace DeferredProcessing
148 } // namespace CameraStandard
149 } // namespace OHOS
150