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 "remote_request_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(CAMERA_DEVICE_ON_ERROR, data, reply, option);
45 if (error != ERR_NONE) {
46 MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnError failed, error: %{public}d", error);
47 }
48 return error;
49 }
50
OnResult(const uint64_t timestamp,const std::shared_ptr<Camera::CameraMetadata> & result)51 int32_t HCameraDeviceCallbackProxy::OnResult(const uint64_t timestamp,
52 const std::shared_ptr<Camera::CameraMetadata> &result)
53 {
54 MessageParcel data;
55 MessageParcel reply;
56 MessageOption option;
57
58 if (!data.WriteInterfaceToken(GetDescriptor())) {
59 MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnResult Write interface token failed");
60 return IPC_PROXY_ERR;
61 }
62 if (!data.WriteUint64(timestamp)) {
63 MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnResult Write timestamp failed");
64 return IPC_PROXY_ERR;
65 }
66 if (!(Camera::MetadataUtils::EncodeCameraMetadata(result, data))) {
67 MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnResult EncodeCameraMetadata failed");
68 return IPC_PROXY_ERR;
69 }
70 int error = Remote()->SendRequest(CAMERA_DEVICE_ON_RESULT, data, reply, option);
71 if (error != ERR_NONE) {
72 MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnResult failed, error: %{public}d", error);
73 }
74 return error;
75 }
76 } // namespace CameraStandard
77 } // namespace OHOS
78