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_stub.h"
17 #include "camera_log.h"
18 #include "camera_service_ipc_interface_code.h"
19
20 namespace OHOS {
21 namespace CameraStandard {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)22 int HCameraServiceCallbackStub::OnRemoteRequest(
23 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
24 {
25 int errCode = -1;
26
27 CHECK_AND_RETURN_RET(data.ReadInterfaceToken() == GetDescriptor(), errCode);
28 switch (code) {
29 case CAMERA_CALLBACK_STATUS_CHANGED:
30 errCode = HCameraServiceCallbackStub::HandleOnCameraStatusChanged(data);
31 break;
32
33 case CAMERA_CALLBACK_FLASHLIGHT_STATUS_CHANGED:
34 errCode = HCameraServiceCallbackStub::HandleOnFlashlightStatusChanged(data);
35 break;
36
37 default:
38 MEDIA_ERR_LOG("HCameraServiceCallbackStub request code %{public}u not handled", code);
39 errCode = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
40 break;
41 }
42
43 return errCode;
44 }
45
HandleOnCameraStatusChanged(MessageParcel & data)46 int HCameraServiceCallbackStub::HandleOnCameraStatusChanged(MessageParcel& data)
47 {
48 std::string cameraId = data.ReadString();
49 int32_t status = data.ReadInt32();
50 std::string bundleName = data.ReadString();
51 MEDIA_INFO_LOG("HCameraServiceCallbackStub::HandleOnCameraStatusChanged called, cameraId = %{public}s, "
52 "status = %{public}d, bundleName = %{public}s", cameraId.c_str(), status, bundleName.c_str());
53 return OnCameraStatusChanged(cameraId, static_cast<CameraStatus>(status), bundleName);
54 }
55
HandleOnFlashlightStatusChanged(MessageParcel & data)56 int HCameraServiceCallbackStub::HandleOnFlashlightStatusChanged(MessageParcel& data)
57 {
58 std::string cameraId = data.ReadString();
59 int32_t status = data.ReadInt32();
60
61 return OnFlashlightStatusChanged(cameraId, static_cast<FlashStatus>(status));
62 }
63
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)64 int HTorchServiceCallbackStub::OnRemoteRequest(
65 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
66 {
67 int errCode = -1;
68
69 CHECK_AND_RETURN_RET(data.ReadInterfaceToken() == GetDescriptor(), errCode);
70 switch (code) {
71 case static_cast<uint32_t>(TorchServiceCallbackInterfaceCode::TORCH_CALLBACK_TORCH_STATUS_CHANGE):
72 errCode = HTorchServiceCallbackStub::HandleOnTorchStatusChange(data);
73 break;
74 default:
75 MEDIA_ERR_LOG("HTorchServiceCallbackStub request code %{public}u not handled", code);
76 errCode = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
77 break;
78 }
79
80 return errCode;
81 }
82
HandleOnTorchStatusChange(MessageParcel & data)83 int HTorchServiceCallbackStub::HandleOnTorchStatusChange(MessageParcel& data)
84 {
85 int32_t status = data.ReadInt32();
86
87 return OnTorchStatusChange((TorchStatus)status);
88 }
89
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)90 int HFoldServiceCallbackStub::OnRemoteRequest(
91 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
92 {
93 int errCode = -1;
94 CHECK_AND_RETURN_RET(data.ReadInterfaceToken() == GetDescriptor(), errCode);
95 switch (code) {
96 case static_cast<uint32_t>(FoldServiceCallbackInterfaceCode::FOLD_CALLBACK_FOLD_STATUS_CHANGE):
97 errCode = HFoldServiceCallbackStub::HandleOnFoldStatusChanged(data);
98 break;
99 default:
100 MEDIA_ERR_LOG("HFoldServiceCallbackStub request code %{public}u not handled", code);
101 errCode = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
102 break;
103 }
104 return errCode;
105 }
106
HandleOnFoldStatusChanged(MessageParcel & data)107 int HFoldServiceCallbackStub::HandleOnFoldStatusChanged(MessageParcel& data)
108 {
109 int32_t status = data.ReadInt32();
110
111 return OnFoldStatusChanged((FoldStatus)status);
112 }
113
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)114 int HCameraMuteServiceCallbackStub::OnRemoteRequest(
115 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
116 {
117 int errCode = -1;
118
119 CHECK_AND_RETURN_RET(data.ReadInterfaceToken() == GetDescriptor(), errCode);
120 switch (code) {
121 case static_cast<uint32_t>(CameraMuteServiceCallbackInterfaceCode::CAMERA_CALLBACK_MUTE_MODE):
122 errCode = HCameraMuteServiceCallbackStub::HandleOnCameraMute(data);
123 break;
124 default:
125 MEDIA_ERR_LOG("HCameraMuteServiceCallbackStub request code %{public}u not handled", code);
126 errCode = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
127 break;
128 }
129
130 return errCode;
131 }
132
HandleOnCameraMute(MessageParcel & data)133 int HCameraMuteServiceCallbackStub::HandleOnCameraMute(MessageParcel& data)
134 {
135 bool muteMode = data.ReadBool();
136
137 return OnCameraMute(muteMode);
138 }
139 } // namespace CameraStandard
140 } // namespace OHOS
141