1 /*
2 * Copyright (c) 2021-2022 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 "hcamera_device_callback_proxy.h"
17 #include "camera_log.h"
18 #include "metadata_utils.h"
19 #include "camera_service_ipc_interface_code.h"
20
21 namespace OHOS {
22 namespace CameraStandard {
HCameraDeviceCallbackProxy(const sptr<IRemoteObject> & impl)23 HCameraDeviceCallbackProxy::HCameraDeviceCallbackProxy(const sptr<IRemoteObject> &impl)
24 : IRemoteProxy<ICameraDeviceServiceCallback>(impl) { }
25
OnError(const int32_t errorType,const int32_t errorMsg)26 int32_t HCameraDeviceCallbackProxy::OnError(const int32_t errorType, const int32_t errorMsg)
27 {
28 MessageParcel data;
29 MessageParcel reply;
30 MessageOption option;
31
32 if (!data.WriteInterfaceToken(GetDescriptor())) {
33 MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnError Write interface token failed");
34 return IPC_PROXY_ERR;
35 }
36 if (!data.WriteInt32(errorType)) {
37 MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnError Write errorType failed");
38 return IPC_PROXY_ERR;
39 }
40 if (!data.WriteInt32(errorMsg)) {
41 MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnError Write errorMsg failed");
42 return IPC_PROXY_ERR;
43 }
44 int error = Remote()->SendRequest(
45 static_cast<uint32_t>(CameraDeviceCallbackInterfaceCode::CAMERA_DEVICE_ON_ERROR), data, reply, option);
46 if (error != ERR_NONE) {
47 MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnError failed, error: %{public}d", error);
48 }
49 return error;
50 }
51
OnResult(const uint64_t timestamp,const std::shared_ptr<Camera::CameraMetadata> & result)52 int32_t HCameraDeviceCallbackProxy::OnResult(const uint64_t timestamp,
53 const std::shared_ptr<Camera::CameraMetadata> &result)
54 {
55 MessageParcel data;
56 MessageParcel reply;
57 MessageOption option;
58
59 if (!data.WriteInterfaceToken(GetDescriptor())) {
60 MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnResult Write interface token failed");
61 return IPC_PROXY_ERR;
62 }
63 if (!data.WriteUint64(timestamp)) {
64 MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnResult Write timestamp failed");
65 return IPC_PROXY_ERR;
66 }
67 if (!(Camera::MetadataUtils::EncodeCameraMetadata(result, data))) {
68 MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnResult EncodeCameraMetadata failed");
69 return IPC_PROXY_ERR;
70 }
71 int error = Remote()->SendRequest(
72 static_cast<uint32_t>(CameraDeviceCallbackInterfaceCode::CAMERA_DEVICE_ON_RESULT), data, reply, option);
73 if (error != ERR_NONE) {
74 MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnResult failed, error: %{public}d", error);
75 }
76 return error;
77 }
78 } // namespace CameraStandard
79 } // namespace OHOS
80