• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)25 int32_t HCameraServiceCallbackProxy::OnCameraStatusChanged(const std::string& cameraId, const CameraStatus status)
26 {
27     MessageParcel data;
28     MessageParcel reply;
29     MessageOption option;
30     MEDIA_INFO_LOG("HCameraServiceCallbackProxy OnCameraStatusChanged called");
31     if (!data.WriteInterfaceToken(GetDescriptor())) {
32         MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnCameraStatusChanged Write interface token failed");
33         return IPC_PROXY_ERR;
34     }
35     if (!data.WriteString(cameraId)) {
36         MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnCameraStatusChanged Write CameraId failed");
37         return IPC_PROXY_ERR;
38     }
39     if (!data.WriteInt32(status)) {
40         MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnCameraStatusChanged Write status failed");
41         return IPC_PROXY_ERR;
42     }
43     int error = Remote()->SendRequest(
44         static_cast<uint32_t>(CameraServiceCallbackInterfaceCode::CAMERA_CALLBACK_STATUS_CHANGED),
45         data, reply, option);
46     if (error != ERR_NONE) {
47         MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnCameraStatusChanged failed, error: %{public}d", error);
48     }
49     return error;
50 }
51 
OnFlashlightStatusChanged(const std::string & cameraId,const FlashStatus status)52 int32_t HCameraServiceCallbackProxy::OnFlashlightStatusChanged(const std::string& cameraId, const FlashStatus status)
53 {
54     MessageParcel data;
55     MessageParcel reply;
56     MessageOption option;
57     int error = ERR_NONE;
58 
59     if (!data.WriteInterfaceToken(GetDescriptor())) {
60         MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnFlashlightStatus Write interface token failed");
61         return IPC_PROXY_ERR;
62     }
63     if (!data.WriteString(cameraId)) {
64         MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnFlashlightStatus Write CameraId failed");
65         return IPC_PROXY_ERR;
66     }
67     if (!data.WriteInt32(status)) {
68         MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnFlashlightStatus Write status failed");
69         return IPC_PROXY_ERR;
70     }
71     error = Remote()->SendRequest(
72         static_cast<uint32_t>(CameraServiceCallbackInterfaceCode::CAMERA_CALLBACK_FLASHLIGHT_STATUS_CHANGED),
73         data, reply, option);
74     if (error != ERR_NONE) {
75         MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnFlashlightStatus failed, error: %{public}d", error);
76     }
77     return error;
78 }
79 
HCameraMuteServiceCallbackProxy(const sptr<IRemoteObject> & impl)80 HCameraMuteServiceCallbackProxy::HCameraMuteServiceCallbackProxy(const sptr<IRemoteObject> &impl)
81     : IRemoteProxy<ICameraMuteServiceCallback>(impl) { }
82 
OnCameraMute(bool muteMode)83 int32_t HCameraMuteServiceCallbackProxy::OnCameraMute(bool muteMode)
84 {
85     MessageParcel data;
86     MessageParcel reply;
87     MessageOption option;
88 
89     if (!data.WriteInterfaceToken(GetDescriptor())) {
90         MEDIA_ERR_LOG("HCameraMuteServiceCallbackProxy OnCameraMute Write interface token failed");
91         return IPC_PROXY_ERR;
92     }
93     if (!data.WriteBool(muteMode)) {
94         MEDIA_ERR_LOG("HCameraMuteServiceCallbackProxy OnCameraMute Write muteMode failed");
95         return IPC_PROXY_ERR;
96     }
97 
98     int error = Remote()->SendRequest(
99         static_cast<uint32_t>(CameraMuteServiceCallbackInterfaceCode::CAMERA_CALLBACK_MUTE_MODE),
100         data, reply, option);
101     if (error != ERR_NONE) {
102         MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnCameraMute failed, error: %{public}d", error);
103     }
104     return error;
105 }
106 } // namespace CameraStandard
107 } // namespace OHOS
108