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_AND_RETURN_RET(data.ReadInterfaceToken() == GetDescriptor(), errCode);
31     errCode = OperatePermissionCheck(code);
32     CHECK_AND_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_ENABLE_RESULTS):
47             errCode = HandleEnableMetadataType(data);
48             break;
49         case static_cast<uint32_t>(StreamMetadataInterfaceCode::CAMERA_STREAM_META_DISABLE_RESULTS):
50             errCode = HandleDisableMetadataType(data);
51             break;
52         default:
53             MEDIA_ERR_LOG("HStreamMetadataStub request code %{public}u not handled", code);
54             errCode = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
55             break;
56     }
57 
58     return errCode;
59 }
60 
HandleSetCallback(MessageParcel & data)61 int32_t HStreamMetadataStub::HandleSetCallback(MessageParcel &data)
62 {
63     auto remoteObject = data.ReadRemoteObject();
64     CHECK_AND_RETURN_RET_LOG(remoteObject != nullptr, IPC_STUB_INVALID_DATA_ERR,
65                              "HStreamMetadataStub HandleSetCallback remoteObject is null");
66 
67     auto callback = iface_cast<IStreamMetadataCallback>(remoteObject);
68     CHECK_AND_RETURN_RET_LOG(callback != nullptr, IPC_STUB_INVALID_DATA_ERR,
69                              "HStreamMetadataStub HandleSetCallback remoteCallback is null");
70     return SetCallback(callback);
71 }
72 
HandleEnableMetadataType(MessageParcel & data)73 int32_t HStreamMetadataStub::HandleEnableMetadataType(MessageParcel& data)
74 {
75     std::vector<int32_t> metadataTypes;
76     CHECK_AND_PRINT_LOG(data.ReadInt32Vector(&metadataTypes),
77         "HStreamMetadataStub Start metadataTypes is null");
78     int ret = EnableMetadataType(metadataTypes);
79     CHECK_ERROR_PRINT_LOG(ret != ERR_NONE, "HStreamMetadataStub HandleStart failed : %{public}d", ret);
80     return ret;
81 }
HandleDisableMetadataType(MessageParcel & data)82 int32_t HStreamMetadataStub::HandleDisableMetadataType(MessageParcel& data)
83 {
84     std::vector<int32_t> metadataTypes;
85     CHECK_AND_PRINT_LOG(data.ReadInt32Vector(&metadataTypes),
86         "HStreamMetadataStub Start metadataTypes is null");
87     int ret = DisableMetadataType(metadataTypes);
88     CHECK_ERROR_PRINT_LOG(ret != ERR_NONE, "HStreamMetadataStub HandleStart failed : %{public}d", ret);
89     return ret;
90 }
91 } // namespace CameraStandard
92 } // namespace OHOS
93