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 #include "deferred_photo_processing_session_callback_stub.h"
16 #include "deferred_processing_service_ipc_interface_code.h"
17 #include "dp_log.h"
18 #include "picture.h"
19
20 namespace OHOS {
21 namespace CameraStandard {
22 namespace DeferredProcessing {
23
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)24 int DeferredPhotoProcessingSessionCallbackStub::OnRemoteRequest(
25 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
26 {
27 int errCode = -1;
28
29 DP_CHECK_RETURN_RET(data.ReadInterfaceToken() != GetDescriptor(), errCode);
30 switch (code) {
31 case static_cast<uint32_t>(
32 DeferredProcessingServiceCallbackInterfaceCode::DPS_PHOTO_CALLBACK_PROCESS_IMAGE_DONE): {
33 errCode = DeferredPhotoProcessingSessionCallbackStub::HandleOnProcessImageDone(data);
34 break;
35 }
36 case static_cast<uint32_t>(DeferredProcessingServiceCallbackInterfaceCode::DPS_PHOTO_CALLBACK_ERROR): {
37 errCode = DeferredPhotoProcessingSessionCallbackStub::HandleOnError(data);
38 break;
39 }
40 case static_cast<uint32_t>(DeferredProcessingServiceCallbackInterfaceCode::DPS_PHOTO_CALLBACK_STATE_CHANGED): {
41 errCode = DeferredPhotoProcessingSessionCallbackStub::HandleOnStateChanged(data);
42 break;
43 }
44 case static_cast<uint32_t>(
45 DeferredProcessingServiceCallbackInterfaceCode::DPS_PHOTO_CALLBACK_LOW_QUALITY_IMAGE): {
46 errCode = DeferredPhotoProcessingSessionCallbackStub::HandleProcessLowQualityImage(data);
47 break;
48 }
49 case static_cast<uint32_t>(
50 DeferredProcessingServiceCallbackInterfaceCode::DPS_PHOTO_CALLBACK_PROCESS_PICTURE_DONE): {
51 errCode = DeferredPhotoProcessingSessionCallbackStub::HandleOnProcessPictureDone(data);
52 break;
53 }
54 default:
55 DP_ERR_LOG("DeferredPhotoProcessingSessionCallbackStub request code %{public}d not handled", code);
56 errCode = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
57 break;
58 }
59 return errCode;
60 }
61
HandleOnProcessImageDone(MessageParcel & data)62 int DeferredPhotoProcessingSessionCallbackStub::HandleOnProcessImageDone(MessageParcel& data)
63 {
64 DP_INFO_LOG("DeferredPhotoProcessingSessionCallbackStub HandleOnProcessImageDone enter");
65 std::string imageId = data.ReadString();
66 sptr<IPCFileDescriptor> ipcFd = data.ReadObject<IPCFileDescriptor>();
67 long bytes = data.ReadInt64();
68 bool isCloudImageEnhanceSupported = data.ReadBool();
69 int32_t ret = OnProcessImageDone(imageId, ipcFd, bytes, isCloudImageEnhanceSupported);
70 DP_INFO_LOG("DeferredPhotoProcessingSessionCallbackStub HandleOnProcessImageDone result: %{public}d", ret);
71 return ret;
72 }
73
HandleOnError(MessageParcel & data)74 int DeferredPhotoProcessingSessionCallbackStub::HandleOnError(MessageParcel& data)
75 {
76 DP_INFO_LOG("DeferredPhotoProcessingSessionCallbackStub HandleOnError enter");
77 std::string imageId = data.ReadString();
78 int32_t errorCode = data.ReadInt32();
79
80 int32_t ret = OnError(imageId, (ErrorCode)errorCode);
81 DP_INFO_LOG("DeferredPhotoProcessingSessionCallbackStub HandleOnError result: %{public}d", ret);
82 return ret;
83 }
84
HandleOnStateChanged(MessageParcel & data)85 int DeferredPhotoProcessingSessionCallbackStub::HandleOnStateChanged(MessageParcel& data)
86 {
87 DP_INFO_LOG("DeferredPhotoProcessingSessionCallbackStub HandleOnStateChanged enter");
88 int32_t status = data.ReadInt32();
89
90 int32_t ret = OnStateChanged((StatusCode)status);
91 DP_INFO_LOG("DeferredPhotoProcessingSessionCallbackStub HandleOnStateChanged result: %{public}d", ret);
92 return ret;
93 }
94
HandleProcessLowQualityImage(MessageParcel & data)95 int DeferredPhotoProcessingSessionCallbackStub::HandleProcessLowQualityImage(MessageParcel& data)
96 {
97 DP_INFO_LOG("DeferredPhotoProcessingSessionCallbackStub HandleProcessLowQualityImage enter");
98 std::string imageId = data.ReadString();
99 std::shared_ptr<Media::Picture> picturePtr(Media::Picture::Unmarshalling(data));
100 int32_t ret = OnDeliveryLowQualityImage(imageId, picturePtr);
101 DP_INFO_LOG("DeferredPhotoProcessingSessionCallbackStub HandleProcessLowQualityImage result: %{public}d", ret);
102 return ret;
103 }
104
HandleOnProcessPictureDone(MessageParcel & data)105 int DeferredPhotoProcessingSessionCallbackStub::HandleOnProcessPictureDone(MessageParcel& data)
106 {
107 DP_INFO_LOG("DeferredPhotoProcessingSessionCallbackStub HandleProcessLowQualityImage enter");
108 std::string imageId = data.ReadString();
109 bool isCloudImageEnhanceSupported = data.ReadBool();
110 std::shared_ptr<Media::Picture> picturePtr(Media::Picture::Unmarshalling(data));
111 int32_t ret = OnProcessImageDone(imageId, picturePtr, isCloudImageEnhanceSupported);
112 DP_INFO_LOG("DeferredPhotoProcessingSessionCallbackStub HandleProcessLowQualityImage result: %{public}d", ret);
113 return ret;
114 }
115 } // namespace DeferredProcessing
116 } // namespace CameraStandard
117 } // namespace OHOS