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 data.WriteInterfaceToken(GetDescriptor());
33 data.WriteInt32(errorType);
34 data.WriteInt32(errorMsg);
35 option.SetFlags(option.TF_ASYNC);
36
37 int error = Remote()->SendRequest(
38 static_cast<uint32_t>(CameraDeviceCallbackInterfaceCode::CAMERA_DEVICE_ON_ERROR), data, reply, option);
39 if (error != ERR_NONE) {
40 MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnError failed, error: %{public}d", error);
41 }
42 return error;
43 }
44
OnResult(const uint64_t timestamp,const std::shared_ptr<Camera::CameraMetadata> & result)45 int32_t HCameraDeviceCallbackProxy::OnResult(const uint64_t timestamp,
46 const std::shared_ptr<Camera::CameraMetadata> &result)
47 {
48 MessageParcel data;
49 MessageParcel reply;
50 MessageOption option;
51 option.SetFlags(option.TF_ASYNC);
52
53 data.WriteInterfaceToken(GetDescriptor());
54 data.WriteUint64(timestamp);
55
56 if (!(Camera::MetadataUtils::EncodeCameraMetadata(result, data))) {
57 MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnResult EncodeCameraMetadata failed");
58 return IPC_PROXY_ERR;
59 }
60 int error = Remote()->SendRequest(
61 static_cast<uint32_t>(CameraDeviceCallbackInterfaceCode::CAMERA_DEVICE_ON_RESULT), data, reply, option);
62 if (error != ERR_NONE) {
63 MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnResult failed, error: %{public}d", error);
64 }
65 return error;
66 }
67 } // namespace CameraStandard
68 } // namespace OHOS
69