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_callback_proxy.h"
17 #include "deferred_processing_service_ipc_interface_code.h"
18 #include "utils/dp_log.h"
19 #include "picture.h"
20 namespace OHOS {
21 namespace CameraStandard {
22 namespace DeferredProcessing {
DeferredPhotoProcessingSessionCallbackProxy(const sptr<IRemoteObject> & impl)23 DeferredPhotoProcessingSessionCallbackProxy::DeferredPhotoProcessingSessionCallbackProxy(
24 const sptr<IRemoteObject> &impl)
25 : IRemoteProxy<IDeferredPhotoProcessingSessionCallback>(impl) { }
26
OnProcessImageDone(const std::string & imageId,sptr<IPCFileDescriptor> ipcFd,long bytes,bool isCloudEnhancementAvailable)27 int32_t DeferredPhotoProcessingSessionCallbackProxy::OnProcessImageDone(const std::string &imageId,
28 sptr<IPCFileDescriptor> ipcFd, long bytes, bool isCloudEnhancementAvailable)
29 {
30 MessageParcel data;
31 MessageParcel reply;
32 MessageOption option;
33
34 data.WriteInterfaceToken(GetDescriptor());
35 data.WriteString(imageId);
36 data.WriteObject<IPCFileDescriptor>(ipcFd);
37 data.WriteInt64(bytes);
38 data.WriteBool(isCloudEnhancementAvailable);
39
40 int error = Remote()->SendRequest(
41 static_cast<uint32_t>(DeferredProcessingServiceCallbackInterfaceCode::DPS_PHOTO_CALLBACK_PROCESS_IMAGE_DONE),
42 data, reply, option);
43 DP_CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
44 "DeferredPhotoProcessingSessionCallbackProxy OnProcessImageDone failed, error: %{public}d", error);
45 return error;
46 }
47
OnProcessImageDone(const std::string & imageId,std::shared_ptr<Media::Picture> picture,bool isCloudEnhancementAvailable)48 int32_t DeferredPhotoProcessingSessionCallbackProxy::OnProcessImageDone(const std::string &imageId,
49 std::shared_ptr<Media::Picture> picture, bool isCloudEnhancementAvailable)
50 {
51 MessageParcel data;
52 MessageParcel reply;
53 MessageOption option;
54
55 data.WriteInterfaceToken(GetDescriptor());
56 data.WriteString(imageId);
57 data.WriteBool(isCloudEnhancementAvailable);
58
59 if (picture && !picture->Marshalling(data)) {
60 DP_ERR_LOG("OnProcessImageDone Marshalling failed");
61 return -1;
62 }
63
64 int error = Remote()->SendRequest(
65 static_cast<uint32_t>(DeferredProcessingServiceCallbackInterfaceCode::DPS_PHOTO_CALLBACK_PROCESS_PICTURE_DONE),
66 data, reply, option);
67 if (error != ERR_NONE) {
68 DP_ERR_LOG("DeferredPhotoProcessingSessionCallbackProxy OnProcessImageDone failed, error: %{public}d", error);
69 }
70 return error;
71 }
72
OnDeliveryLowQualityImage(const std::string & imageId,std::shared_ptr<Media::Picture> picture)73 int32_t DeferredPhotoProcessingSessionCallbackProxy::OnDeliveryLowQualityImage(const std::string &imageId,
74 std::shared_ptr<Media::Picture> picture)
75 {
76 MessageParcel data;
77 MessageParcel reply;
78 MessageOption option;
79
80 data.WriteInterfaceToken(GetDescriptor());
81 data.WriteString(imageId);
82 if (picture && !picture->Marshalling(data)) {
83 DP_ERR_LOG("OnDeliveryLowQualityImage Marshalling failed");
84 return -1;
85 }
86
87 int error = Remote()->SendRequest(
88 static_cast<uint32_t>(DeferredProcessingServiceCallbackInterfaceCode::DPS_PHOTO_CALLBACK_LOW_QUALITY_IMAGE),
89 data, reply, option);
90 if (error != ERR_NONE) {
91 DP_ERR_LOG("OnDeliveryLowQualityImage failed, error: %{public}d", error);
92 }
93 return error;
94 }
95
OnError(const std::string & imageId,ErrorCode errorCode)96 int32_t DeferredPhotoProcessingSessionCallbackProxy::OnError(const std::string &imageId, ErrorCode errorCode)
97 {
98 MessageParcel data;
99 MessageParcel reply;
100 MessageOption option;
101
102 data.WriteInterfaceToken(GetDescriptor());
103 data.WriteString(imageId);
104 data.WriteInt32(errorCode);
105
106 int error = Remote()->SendRequest(
107 static_cast<uint32_t>(DeferredProcessingServiceCallbackInterfaceCode::DPS_PHOTO_CALLBACK_ERROR),
108 data, reply, option);
109 DP_CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
110 "DeferredPhotoProcessingSessionCallbackProxy OnError failed, error: %{public}d", error);
111 return error;
112 }
113
OnStateChanged(StatusCode status)114 int32_t DeferredPhotoProcessingSessionCallbackProxy::OnStateChanged(StatusCode status)
115 {
116 MessageParcel data;
117 MessageParcel reply;
118 MessageOption option;
119
120 data.WriteInterfaceToken(GetDescriptor());
121 data.WriteInt32(status);
122
123 int error = Remote()->SendRequest(
124 static_cast<uint32_t>(DeferredProcessingServiceCallbackInterfaceCode::DPS_PHOTO_CALLBACK_STATE_CHANGED),
125 data, reply, option);
126 DP_CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
127 "DeferredPhotoProcessingSessionCallbackProxy OnStateChanged failed, error: %{public}d", error);
128 return error;
129 }
130 } //namespace DeferredProcessing
131 } // namespace CameraStandard
132 } // namespace OHOS