• 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 <message_parcel.h>
19 #include "utils_data_stub.h"
20 
21 namespace OHOS::Camera {
OnError(ErrorType type,int32_t errorMsg)22 void CameraDeviceCallbackProxy::OnError(ErrorType type, int32_t errorMsg)
23 {
24     MessageParcel data;
25     MessageParcel reply;
26     MessageOption option;
27 
28     if (!data.WriteUint32(type)) {
29         HDF_LOGE("%{public}s: write error type failed.", __func__);
30         return;
31     }
32 
33     if (!data.WriteInt32(errorMsg)) {
34         HDF_LOGE("%{public}s: write error message failed.", __func__);
35         return;
36     }
37 
38     int32_t ret = Remote()->SendRequest(CMD_CAMERA_DEVICE_CALLBACK_REMOTE_ON_ERROR, data, reply, option);
39     if (ret != HDF_SUCCESS) {
40         HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
41         return;
42     }
43 }
44 
OnResult(uint64_t timestamp,const std::shared_ptr<CameraStandard::CameraMetadata> & result)45 void CameraDeviceCallbackProxy::OnResult(uint64_t timestamp,
46     const std::shared_ptr<CameraStandard::CameraMetadata> &result)
47 {
48     MessageParcel data;
49     MessageParcel reply;
50     MessageOption option;
51 
52     if (result == nullptr) {
53         return;
54     }
55 
56     if (!data.WriteUint64(timestamp)) {
57         HDF_LOGE("%{public}s: write timestamp failed.", __func__);
58         return;
59     }
60 
61     if (!UtilsDataStub::EncodeCameraMetadata(result, data)) {
62         HDF_LOGE("%s: write metadata failed", __func__);
63         return;
64     }
65 
66     int32_t ret = Remote()->SendRequest(
67         CMD_CAMERA_DEVICE_CALLBACK_REMOTE_ON_RESULT, data, reply, option);
68     if (ret != HDF_SUCCESS) {
69         HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
70         return;
71     }
72 }
73 }