• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_interface.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,uint32_t cloudImageEnhanceFlag)27 int32_t DeferredPhotoProcessingSessionCallbackProxy::OnProcessImageDone(const std::string &imageId,
28     sptr<IPCFileDescriptor> ipcFd, long bytes, uint32_t cloudImageEnhanceFlag)
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.WriteUint32(cloudImageEnhanceFlag);
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<PictureIntf> picture,uint32_t cloudImageEnhanceFlag)48 int32_t DeferredPhotoProcessingSessionCallbackProxy::OnProcessImageDone(const std::string &imageId,
49     std::shared_ptr<PictureIntf> picture, uint32_t cloudImageEnhanceFlag)
50 {
51     MessageParcel data;
52     MessageParcel reply;
53     MessageOption option;
54 
55     data.WriteInterfaceToken(GetDescriptor());
56     data.WriteString(imageId);
57     data.WriteUint32(cloudImageEnhanceFlag);
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<PictureIntf> picture)73 int32_t DeferredPhotoProcessingSessionCallbackProxy::OnDeliveryLowQualityImage(const std::string &imageId,
74     std::shared_ptr<PictureIntf> picture)
75 {
76     MessageParcel data;
77     MessageParcel reply;
78     MessageOption option;
79 
80     data.WriteInterfaceToken(GetDescriptor());
81     data.WriteString(imageId);
82     DP_CHECK_ERROR_RETURN_RET_LOG(picture == nullptr, -1,
83         "DeferredPhotoProcessingSessionCallbackProxy OnDeliveryLowQualityImage picture is nullptr");
84     if (!picture->Marshalling(data)) {
85         DP_ERR_LOG("OnDeliveryLowQualityImage Marshalling failed");
86         return -1;
87     }
88 
89     int error = Remote()->SendRequest(
90         static_cast<uint32_t>(DeferredProcessingServiceCallbackInterfaceCode::DPS_PHOTO_CALLBACK_LOW_QUALITY_IMAGE),
91         data, reply, option);
92     if (error != ERR_NONE) {
93         DP_ERR_LOG("OnDeliveryLowQualityImage failed, error: %{public}d", error);
94     }
95     return error;
96 }
97 
OnError(const std::string & imageId,ErrorCode errorCode)98 int32_t DeferredPhotoProcessingSessionCallbackProxy::OnError(const std::string &imageId, ErrorCode errorCode)
99 {
100     MessageParcel data;
101     MessageParcel reply;
102     MessageOption option;
103 
104     data.WriteInterfaceToken(GetDescriptor());
105     data.WriteString(imageId);
106     data.WriteInt32(errorCode);
107 
108     int error = Remote()->SendRequest(
109         static_cast<uint32_t>(DeferredProcessingServiceCallbackInterfaceCode::DPS_PHOTO_CALLBACK_ERROR),
110         data, reply, option);
111     DP_CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
112         "DeferredPhotoProcessingSessionCallbackProxy OnError failed, error: %{public}d", error);
113     return error;
114 }
115 
OnStateChanged(StatusCode status)116 int32_t DeferredPhotoProcessingSessionCallbackProxy::OnStateChanged(StatusCode status)
117 {
118     MessageParcel data;
119     MessageParcel reply;
120     MessageOption option;
121 
122     data.WriteInterfaceToken(GetDescriptor());
123     data.WriteInt32(status);
124 
125     int error = Remote()->SendRequest(
126         static_cast<uint32_t>(DeferredProcessingServiceCallbackInterfaceCode::DPS_PHOTO_CALLBACK_STATE_CHANGED),
127         data, reply, option);
128     DP_CHECK_ERROR_PRINT_LOG(error != ERR_NONE,
129         "DeferredPhotoProcessingSessionCallbackProxy OnStateChanged failed, error: %{public}d", error);
130     return error;
131 }
132 } //namespace DeferredProcessing
133 } // namespace CameraStandard
134 } // namespace OHOS