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 "hstream_depth_data_stub.h"
17
18 #include "camera_log.h"
19 #include "camera_service_ipc_interface_code.h"
20 #include "camera_util.h"
21
22 namespace OHOS {
23 namespace CameraStandard {
24
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)25 int HStreamDepthDataStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
26 MessageOption& option)
27 {
28 DisableJeMalloc();
29 int errCode = -1;
30
31 CHECK_ERROR_RETURN_RET(data.ReadInterfaceToken() != GetDescriptor(), errCode);
32 errCode = OperatePermissionCheck(code);
33 CHECK_ERROR_RETURN_RET(errCode != CAMERA_OK, errCode);
34 switch (code) {
35 case static_cast<uint32_t>(StreamDepthDataInterfaceCode::CAMERA_STREAM_DEPTH_DATA_START):
36 errCode = Start();
37 break;
38 case static_cast<uint32_t>(StreamDepthDataInterfaceCode::CAMERA_STREAM_DEPTH_DATA_STOP):
39 errCode = Stop();
40 break;
41 case static_cast<uint32_t>(StreamDepthDataInterfaceCode::CAMERA_STREAM_DEPTH_DATA_SET_CALLBACK):
42 errCode = HStreamDepthDataStub::HandleSetCallback(data);
43 break;
44 case static_cast<uint32_t>(StreamDepthDataInterfaceCode::CAMERA_STREAM_DEPTH_DATA_UNSET_CALLBACK):
45 errCode = UnSetCallback();
46 break;
47 case static_cast<uint32_t>(StreamDepthDataInterfaceCode::CAMERA_STREAM_DEPTH_DATA_ACCURACY_SET):
48 errCode = HStreamDepthDataStub::HandleSetDataAccuracy(data);
49 break;
50 case static_cast<uint32_t>(StreamDepthDataInterfaceCode::CAMERA_STREAM_DEPTH_DATA_RELEASE):
51 errCode = Release();
52 break;
53 default:
54 MEDIA_ERR_LOG("HStreamDepthDataStub request code %{public}u not handled", code);
55 errCode = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
56 break;
57 }
58
59 return errCode;
60 }
61
HandleSetCallback(MessageParcel & data)62 int32_t HStreamDepthDataStub::HandleSetCallback(MessageParcel& data)
63 {
64 auto remoteObject = data.ReadRemoteObject();
65 CHECK_ERROR_RETURN_RET_LOG(remoteObject == nullptr, IPC_STUB_INVALID_DATA_ERR,
66 "HStreamDepthDataStub HandleSetCallback StreamDepthDataCallback is null");
67
68 auto callback = iface_cast<IStreamDepthDataCallback>(remoteObject);
69 CHECK_ERROR_RETURN_RET_LOG(callback == nullptr, IPC_STUB_INVALID_DATA_ERR,
70 "HStreamDepthDataStub HandleSetCallback callback is null");
71 return SetCallback(callback);
72 }
73
HandleSetDataAccuracy(MessageParcel & data)74 int32_t HStreamDepthDataStub::HandleSetDataAccuracy(MessageParcel& data)
75 {
76 int32_t dataAccuracy = data.ReadInt32();
77
78 int error = SetDataAccuracy(dataAccuracy);
79 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HStreamDepthDataStub::HandleSetDataAccuracy failed : %{public}d", error);
80 return error;
81 }
82 } // namespace CameraStandard
83 } // namespace OHOS
84