• 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 "remote_request_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(CAMERA_CALLBACK_STATUS_CHANGED, data, reply, option);
44     if (error != ERR_NONE) {
45         MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnCameraStatusChanged failed, error: %{public}d", error);
46     }
47     return error;
48 }
49 
OnFlashlightStatusChanged(const std::string & cameraId,const FlashStatus status)50 int32_t HCameraServiceCallbackProxy::OnFlashlightStatusChanged(const std::string& cameraId, const FlashStatus status)
51 {
52     MessageParcel data;
53     MessageParcel reply;
54     MessageOption option;
55     int error = ERR_NONE;
56 
57     if (!data.WriteInterfaceToken(GetDescriptor())) {
58         MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnFlashlightStatus Write interface token failed");
59         return IPC_PROXY_ERR;
60     }
61     if (!data.WriteString(cameraId)) {
62         MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnFlashlightStatus Write CameraId failed");
63         return IPC_PROXY_ERR;
64     }
65     if (!data.WriteInt32(status)) {
66         MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnFlashlightStatus Write status failed");
67         return IPC_PROXY_ERR;
68     }
69     error = Remote()->SendRequest(CAMERA_CALLBACK_FLASHLIGHT_STATUS_CHANGED, data, reply, option);
70     if (error != ERR_NONE) {
71         MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnFlashlightStatus failed, error: %{public}d", error);
72     }
73     return error;
74 }
75 
HCameraMuteServiceCallbackProxy(const sptr<IRemoteObject> & impl)76 HCameraMuteServiceCallbackProxy::HCameraMuteServiceCallbackProxy(const sptr<IRemoteObject> &impl)
77     : IRemoteProxy<ICameraMuteServiceCallback>(impl) { }
78 
OnCameraMute(bool muteMode)79 int32_t HCameraMuteServiceCallbackProxy::OnCameraMute(bool muteMode)
80 {
81     MessageParcel data;
82     MessageParcel reply;
83     MessageOption option;
84 
85     if (!data.WriteInterfaceToken(GetDescriptor())) {
86         MEDIA_ERR_LOG("HCameraMuteServiceCallbackProxy OnCameraMute Write interface token failed");
87         return IPC_PROXY_ERR;
88     }
89     if (!data.WriteBool(muteMode)) {
90         MEDIA_ERR_LOG("HCameraMuteServiceCallbackProxy OnCameraMute Write muteMode failed");
91         return IPC_PROXY_ERR;
92     }
93 
94     int error = Remote()->SendRequest(CAMERA_CALLBACK_MUTE_MODE, data, reply, option);
95     if (error != ERR_NONE) {
96         MEDIA_ERR_LOG("HCameraServiceCallbackProxy OnCameraMute failed, error: %{public}d", error);
97     }
98     return error;
99 }
100 } // namespace CameraStandard
101 } // namespace OHOS
102