1 /*
2 * Copyright (c) 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_metadata_stub.h"
17 #include "camera_log.h"
18 #include "camera_util.h"
19 #include "camera_service_ipc_interface_code.h"
20 #include <vector>
21
22 namespace OHOS {
23 namespace CameraStandard {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)24 int HStreamMetadataStub::OnRemoteRequest(
25 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
26 {
27 DisableJeMalloc();
28 int errCode = -1;
29
30 CHECK_ERROR_RETURN_RET(data.ReadInterfaceToken() != GetDescriptor(), errCode);
31 errCode = OperatePermissionCheck(code);
32 CHECK_ERROR_RETURN_RET(errCode != CAMERA_OK, errCode);
33 switch (code) {
34 case static_cast<uint32_t>(StreamMetadataInterfaceCode::CAMERA_STREAM_META_START):
35 errCode = Start();
36 break;
37 case static_cast<uint32_t>(StreamMetadataInterfaceCode::CAMERA_STREAM_META_STOP):
38 errCode = Stop();
39 break;
40 case static_cast<uint32_t>(StreamMetadataInterfaceCode::CAMERA_STREAM_META_RELEASE):
41 errCode = Release();
42 break;
43 case static_cast<uint32_t>(StreamMetadataInterfaceCode::CAMERA_STREAM_META_SET_CALLBACK):
44 errCode = HandleSetCallback(data);
45 break;
46 case static_cast<uint32_t>(StreamMetadataInterfaceCode::CAMERA_STREAM_META_UNSET_CALLBACK):
47 errCode = UnSetCallback();
48 break;
49 case static_cast<uint32_t>(StreamMetadataInterfaceCode::CAMERA_STREAM_META_ENABLE_RESULTS):
50 errCode = HandleEnableMetadataType(data);
51 break;
52 case static_cast<uint32_t>(StreamMetadataInterfaceCode::CAMERA_STREAM_META_DISABLE_RESULTS):
53 errCode = HandleDisableMetadataType(data);
54 break;
55 default:
56 MEDIA_ERR_LOG("HStreamMetadataStub request code %{public}u not handled", code);
57 errCode = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
58 break;
59 }
60
61 return errCode;
62 }
63
HandleSetCallback(MessageParcel & data)64 int32_t HStreamMetadataStub::HandleSetCallback(MessageParcel &data)
65 {
66 auto remoteObject = data.ReadRemoteObject();
67 CHECK_ERROR_RETURN_RET_LOG(remoteObject == nullptr, IPC_STUB_INVALID_DATA_ERR,
68 "HStreamMetadataStub HandleSetCallback remoteObject is null");
69
70 auto callback = iface_cast<IStreamMetadataCallback>(remoteObject);
71 CHECK_ERROR_RETURN_RET_LOG(callback == nullptr, IPC_STUB_INVALID_DATA_ERR,
72 "HStreamMetadataStub HandleSetCallback remoteCallback is null");
73 return SetCallback(callback);
74 }
75
HandleEnableMetadataType(MessageParcel & data)76 int32_t HStreamMetadataStub::HandleEnableMetadataType(MessageParcel& data)
77 {
78 std::vector<int32_t> metadataTypes;
79 CHECK_ERROR_PRINT_LOG(!data.ReadInt32Vector(&metadataTypes),
80 "HStreamMetadataStub Start metadataTypes is null");
81 int ret = EnableMetadataType(metadataTypes);
82 CHECK_ERROR_PRINT_LOG(ret != ERR_NONE, "HStreamMetadataStub HandleStart failed : %{public}d", ret);
83 return ret;
84 }
HandleDisableMetadataType(MessageParcel & data)85 int32_t HStreamMetadataStub::HandleDisableMetadataType(MessageParcel& data)
86 {
87 std::vector<int32_t> metadataTypes;
88 CHECK_ERROR_PRINT_LOG(!data.ReadInt32Vector(&metadataTypes),
89 "HStreamMetadataStub Start metadataTypes is null");
90 int ret = DisableMetadataType(metadataTypes);
91 CHECK_ERROR_PRINT_LOG(ret != ERR_NONE, "HStreamMetadataStub HandleStart failed : %{public}d", ret);
92 return ret;
93 }
94 } // namespace CameraStandard
95 } // namespace OHOS
96