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