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_service_callback_proxy.h"
17 #include "camera_log.h"
18 #include "camera_service_ipc_interface_code.h"
19
20 namespace OHOS {
21 namespace CameraStandard {
HCameraServiceCallbackProxy(const sptr<IRemoteObject> & impl)22 HCameraServiceCallbackProxy::HCameraServiceCallbackProxy(const sptr<IRemoteObject> &impl)
23 : IRemoteProxy<ICameraServiceCallback>(impl) { }
24
OnCameraStatusChanged(const std::string & cameraId,const CameraStatus status,const std::string & bundleName)25 int32_t HCameraServiceCallbackProxy::OnCameraStatusChanged(const std::string& cameraId, const CameraStatus status,
26 const std::string& bundleName)
27 {
28 MessageParcel data;
29 MessageParcel reply;
30 MessageOption option;
31 option.SetFlags(option.TF_ASYNC);
32 MEDIA_INFO_LOG("HCameraServiceCallbackProxy OnCameraStatusChanged called");
33
34 data.WriteInterfaceToken(GetDescriptor());
35 data.WriteString(cameraId);
36 data.WriteInt32(status);
37 data.WriteString(bundleName);
38
39 int error = Remote()->SendRequest(
40 static_cast<uint32_t>(CameraServiceCallbackInterfaceCode::CAMERA_CALLBACK_STATUS_CHANGED),
41 data, reply, option);
42 if (error != ERR_NONE) {
43 MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnCameraStatusChanged failed, error: %{public}d", error);
44 }
45 return error;
46 }
47
OnFlashlightStatusChanged(const std::string & cameraId,const FlashStatus status)48 int32_t HCameraServiceCallbackProxy::OnFlashlightStatusChanged(const std::string& cameraId, const FlashStatus status)
49 {
50 MessageParcel data;
51 MessageParcel reply;
52 MessageOption option;
53 option.SetFlags(option.TF_ASYNC);
54 int error = ERR_NONE;
55
56 data.WriteInterfaceToken(GetDescriptor());
57 data.WriteString(cameraId);
58 data.WriteInt32(status);
59 error = Remote()->SendRequest(
60 static_cast<uint32_t>(CameraServiceCallbackInterfaceCode::CAMERA_CALLBACK_FLASHLIGHT_STATUS_CHANGED),
61 data, reply, option);
62 if (error != ERR_NONE) {
63 MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnFlashlightStatus failed, error: %{public}d", error);
64 }
65 return error;
66 }
67
HCameraMuteServiceCallbackProxy(const sptr<IRemoteObject> & impl)68 HCameraMuteServiceCallbackProxy::HCameraMuteServiceCallbackProxy(const sptr<IRemoteObject> &impl)
69 : IRemoteProxy<ICameraMuteServiceCallback>(impl) { }
70
OnCameraMute(bool muteMode)71 int32_t HCameraMuteServiceCallbackProxy::OnCameraMute(bool muteMode)
72 {
73 MessageParcel data;
74 MessageParcel reply;
75 MessageOption option;
76 option.SetFlags(option.TF_ASYNC);
77
78 data.WriteInterfaceToken(GetDescriptor());
79 data.WriteBool(muteMode);
80
81 int error = Remote()->SendRequest(
82 static_cast<uint32_t>(CameraMuteServiceCallbackInterfaceCode::CAMERA_CALLBACK_MUTE_MODE),
83 data, reply, option);
84 if (error != ERR_NONE) {
85 MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnCameraMute failed, error: %{public}d", error);
86 }
87 return error;
88 }
89
HTorchServiceCallbackProxy(const sptr<IRemoteObject> & impl)90 HTorchServiceCallbackProxy::HTorchServiceCallbackProxy(const sptr<IRemoteObject> &impl)
91 : IRemoteProxy<ITorchServiceCallback>(impl) { }
92
OnTorchStatusChange(const TorchStatus status)93 int32_t HTorchServiceCallbackProxy::OnTorchStatusChange(const TorchStatus status)
94 {
95 MessageParcel data;
96 MessageParcel reply;
97 MessageOption option;
98 option.SetFlags(option.TF_ASYNC);
99 int error = ERR_NONE;
100
101 data.WriteInterfaceToken(GetDescriptor());
102 data.WriteInt32(status);
103 error = Remote()->SendRequest(
104 static_cast<uint32_t>(TorchServiceCallbackInterfaceCode::TORCH_CALLBACK_TORCH_STATUS_CHANGE),
105 data, reply, option);
106 if (error != ERR_NONE) {
107 MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnTorchStatusChange failed, error: %{public}d", error);
108 }
109 return error;
110 }
111
HFoldServiceCallbackProxy(const sptr<IRemoteObject> & impl)112 HFoldServiceCallbackProxy::HFoldServiceCallbackProxy(const sptr<IRemoteObject> &impl)
113 : IRemoteProxy<IFoldServiceCallback>(impl) { }
114
OnFoldStatusChanged(const FoldStatus status)115 int32_t HFoldServiceCallbackProxy::OnFoldStatusChanged(const FoldStatus status)
116 {
117 MessageParcel data;
118 MessageParcel reply;
119 MessageOption option;
120 option.SetFlags(option.TF_ASYNC);
121 int error = ERR_NONE;
122
123 data.WriteInterfaceToken(GetDescriptor());
124 data.WriteInt32(status);
125 error = Remote()->SendRequest(
126 static_cast<uint32_t>(FoldServiceCallbackInterfaceCode::FOLD_CALLBACK_FOLD_STATUS_CHANGE),
127 data, reply, option);
128 if (error != ERR_NONE) {
129 MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnFoldStatusChanged failed, error: %{public}d", error);
130 }
131 return error;
132 }
133 } // namespace CameraStandard
134 } // namespace OHOS
135