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_host_callback_proxy.h"
17 #include <hdf_base.h>
18 #include <hdf_log.h>
19 #include <message_parcel.h>
20
21 namespace OHOS::Camera {
OnCameraStatus(const std::string & cameraId,CameraStatus status)22 void CameraHostCallbackProxy::OnCameraStatus(const std::string &cameraId, CameraStatus status)
23 {
24 MessageParcel data;
25 MessageParcel reply;
26 MessageOption option;
27
28 if (!data.WriteInterfaceToken(CameraHostCallbackProxy::GetDescriptor())) {
29 HDF_LOGE("%{public}s: write interface descriptor failed.", __func__);
30 return;
31 }
32
33 if (!data.WriteString(cameraId)) {
34 HDF_LOGE("%{public}s: write cameraId failed.", __func__);
35 return;
36 }
37
38 if (!data.WriteInt32(status)) {
39 HDF_LOGE("%{public}s: write status failed.", __func__);
40 return;
41 }
42
43 int32_t ret = Remote()->SendRequest(CMD_CAMERA_HOST_CALLBACK_ON_STATUS, data, reply, option);
44 if (ret != HDF_SUCCESS) {
45 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
46 return;
47 }
48 }
49
OnFlashlightStatus(const std::string & cameraId,FlashlightStatus status)50 void CameraHostCallbackProxy::OnFlashlightStatus(const std::string &cameraId, FlashlightStatus status)
51 {
52 MessageParcel data;
53 MessageParcel reply;
54 MessageOption option;
55
56 if (!data.WriteInterfaceToken(CameraHostCallbackProxy::GetDescriptor())) {
57 HDF_LOGE("%{public}s: write interface descriptor failed.", __func__);
58 return;
59 }
60
61 if (!data.WriteString(cameraId)) {
62 HDF_LOGE("%{public}s: write cameraId failed.", __func__);
63 return;
64 }
65
66 if (!data.WriteInt32(status)) {
67 HDF_LOGE("%{public}s: write status failed.", __func__);
68 return;
69 }
70
71 int32_t ret = Remote()->SendRequest(CMD_CAMERA_HOST_CALLBACK_ON_FLASHLIGHT_STATUS, data, reply, option);
72 if (ret != HDF_SUCCESS) {
73 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
74 return;
75 }
76 }
77
OnCameraEvent(const std::string & cameraId,CameraEvent event)78 void CameraHostCallbackProxy::OnCameraEvent(const std::string &cameraId, CameraEvent event)
79 {
80 MessageParcel data;
81 MessageParcel reply;
82 MessageOption option;
83
84 if (!data.WriteInterfaceToken(CameraHostCallbackProxy::GetDescriptor())) {
85 HDF_LOGE("%{public}s: write interface descriptor failed.", __func__);
86 return;
87 }
88
89 if (!data.WriteString(cameraId)) {
90 HDF_LOGE("%{public}s: write cameraId failed.", __func__);
91 return;
92 }
93
94 if (!data.WriteUint32(event)) {
95 HDF_LOGE("%{public}s: write event failed.", __func__);
96 return;
97 }
98
99 int32_t ret = Remote()->SendRequest(CMD_CAMERA_HOST_CALLBACK_ON_CAMERA_EVENT, data, reply, option);
100 if (ret != HDF_SUCCESS) {
101 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
102 return;
103 }
104 }
105 }