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_AND_RETURN_RET(data.ReadInterfaceToken() == GetDescriptor(), errCode);
32 errCode = OperatePermissionCheck(code);
33 CHECK_AND_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_ACCURACY_SET):
45 errCode = HStreamDepthDataStub::HandleSetDataAccuracy(data);
46 break;
47 case static_cast<uint32_t>(StreamDepthDataInterfaceCode::CAMERA_STREAM_DEPTH_DATA_RELEASE):
48 errCode = Release();
49 break;
50 default:
51 MEDIA_ERR_LOG("HStreamDepthDataStub request code %{public}u not handled", code);
52 errCode = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
53 break;
54 }
55
56 return errCode;
57 }
58
HandleSetCallback(MessageParcel & data)59 int32_t HStreamDepthDataStub::HandleSetCallback(MessageParcel& data)
60 {
61 auto remoteObject = data.ReadRemoteObject();
62 CHECK_AND_RETURN_RET_LOG(remoteObject != nullptr, IPC_STUB_INVALID_DATA_ERR,
63 "HStreamDepthDataStub HandleSetCallback StreamDepthDataCallback is null");
64
65 auto callback = iface_cast<IStreamDepthDataCallback>(remoteObject);
66 CHECK_AND_RETURN_RET_LOG(callback != nullptr, IPC_STUB_INVALID_DATA_ERR,
67 "HStreamDepthDataStub HandleSetCallback callback is null");
68 return SetCallback(callback);
69 }
70
HandleSetDataAccuracy(MessageParcel & data)71 int32_t HStreamDepthDataStub::HandleSetDataAccuracy(MessageParcel& data)
72 {
73 int32_t dataAccuracy = data.ReadInt32();
74
75 int error = SetDataAccuracy(dataAccuracy);
76 if (error != ERR_NONE) {
77 MEDIA_ERR_LOG("HStreamDepthDataStub::HandleSetDataAccuracy failed : %{public}d", error);
78 }
79 return error;
80 }
81 } // namespace CameraStandard
82 } // namespace OHOS