• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "camera_device_callback_proxy.h"
17 #include <hdf_base.h>
18 #include <hdf_log.h>
19 #include <message_parcel.h>
20 #include "metadata_utils.h"
21 
22 namespace OHOS::Camera {
OnError(ErrorType type,int32_t errorMsg)23 void CameraDeviceCallbackProxy::OnError(ErrorType type, int32_t errorMsg)
24 {
25     MessageParcel data;
26     MessageParcel reply;
27     MessageOption option;
28 
29     if (!data.WriteInterfaceToken(CameraDeviceCallbackProxy::GetDescriptor())) {
30         HDF_LOGE("%{public}s: write interface descriptor failed.", __func__);
31         return;
32     }
33 
34     if (!data.WriteUint32(type)) {
35         HDF_LOGE("%{public}s: write error type failed.", __func__);
36         return;
37     }
38 
39     if (!data.WriteInt32(errorMsg)) {
40         HDF_LOGE("%{public}s: write error message failed.", __func__);
41         return;
42     }
43 
44     int32_t ret = Remote()->SendRequest(CMD_CAMERA_DEVICE_CALLBACK_ON_ERROR, data, reply, option);
45     if (ret != HDF_SUCCESS) {
46         HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
47         return;
48     }
49 }
50 
OnResult(uint64_t timestamp,const std::shared_ptr<CameraMetadata> & result)51 void CameraDeviceCallbackProxy::OnResult(uint64_t timestamp,
52     const std::shared_ptr<CameraMetadata> &result)
53 {
54     MessageParcel data;
55     MessageParcel reply;
56     MessageOption option;
57 
58     if (result == nullptr) {
59         return;
60     }
61 
62     if (!data.WriteInterfaceToken(CameraDeviceCallbackProxy::GetDescriptor())) {
63         HDF_LOGE("%{public}s: write interface descriptor failed.", __func__);
64         return;
65     }
66 
67     if (!data.WriteUint64(timestamp)) {
68         HDF_LOGE("%{public}s: write timestamp failed.", __func__);
69         return;
70     }
71 
72     if (!MetadataUtils::EncodeCameraMetadata(result, data)) {
73         HDF_LOGE("%s: write metadata failed", __func__);
74         return;
75     }
76 
77     int32_t ret = Remote()->SendRequest(
78         CMD_CAMERA_DEVICE_CALLBACK_ON_RESULT, data, reply, option);
79     if (ret != HDF_SUCCESS) {
80         HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
81         return;
82     }
83 }
84 }