1 /*
2 * Copyright (c) 2021 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 "offline_stream_operator_stub.h"
17 #include <hdf_log.h>
18 #include <hdf_base.h>
19 #include <hdf_sbuf_ipc.h>
20 #include "cmd_common.h"
21
22 namespace OHOS::Camera {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)23 int32_t OfflineStreamOperatorStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
24 MessageOption &option)
25 {
26 HDF_LOGE("%s: CameraDeviceStub::OnRemoteRequest entry!", __func__);
27 (void)option;
28 int32_t ret = HDF_SUCCESS;
29 switch (code) {
30 case CMD_OFFLINE_STREAM_OPERATOR_CANCEL_CAPTURE: {
31 if (data.ReadInterfaceToken() != OfflineStreamOperatorStub::GetDescriptor()) {
32 ret = HDF_ERR_INVALID_PARAM;
33 break;
34 }
35 ret = OfflineStreamOperatorStubCancelCapture(data, reply, option);
36 break;
37 }
38 case CMD_OFFLINE_STREAM_OPERATOR_RELEASE_STREAMS: {
39 if (data.ReadInterfaceToken() != OfflineStreamOperatorStub::GetDescriptor()) {
40 ret = HDF_ERR_INVALID_PARAM;
41 break;
42 }
43 ret = OfflineStreamOperatorStubReleaseStreams(data, reply, option);
44 break;
45 }
46 case CMD_OFFLINE_STREAM_OPERATOR_RELEASE: {
47 if (data.ReadInterfaceToken() != OfflineStreamOperatorStub::GetDescriptor()) {
48 ret = HDF_ERR_INVALID_PARAM;
49 break;
50 }
51 ret = OfflineStreamOperatorStubRelease(data, reply, option);
52 break;
53 }
54 default: {
55 ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
56 }
57 }
58 return ret;
59 }
60
OfflineStreamOperatorStubCancelCapture(MessageParcel & data,MessageParcel & reply,MessageOption & option)61 int32_t OfflineStreamOperatorStub::OfflineStreamOperatorStubCancelCapture(
62 MessageParcel &data, MessageParcel &reply, MessageOption &option)
63 {
64 int32_t captureId = data.ReadInt32();
65 CamRetCode ret = CancelCapture(captureId);
66 if (reply.WriteInt32(static_cast<int32_t>(ret))) {
67 HDF_LOGE("%s: write retcode failed", __func__);
68 return HDF_FAILURE;
69 }
70
71 return HDF_SUCCESS;
72 }
73
OfflineStreamOperatorStubReleaseStreams(MessageParcel & data,MessageParcel & reply,MessageOption & option)74 int32_t OfflineStreamOperatorStub::OfflineStreamOperatorStubReleaseStreams(
75 MessageParcel &data, MessageParcel &reply, MessageOption &option)
76 {
77 std::vector<int32_t> streamIds;
78 if (!data.ReadInt32Vector(&streamIds)) {
79 HDF_LOGE("%s: read streamIds failed", __func__);
80 return HDF_FAILURE;
81 }
82
83 CamRetCode ret = ReleaseStreams(streamIds);
84 if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
85 HDF_LOGE("%s: write retcode failed", __func__);
86 return HDF_FAILURE;
87 }
88
89 return HDF_SUCCESS;
90 }
91
OfflineStreamOperatorStubRelease(MessageParcel & data,MessageParcel & reply,MessageOption & option)92 int32_t OfflineStreamOperatorStub::OfflineStreamOperatorStubRelease(
93 MessageParcel &data, MessageParcel &reply, MessageOption &option)
94 {
95 CamRetCode ret = Release();
96 if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
97 HDF_LOGE("%s: write retcode failed", __func__);
98 return HDF_FAILURE;
99 }
100
101 return HDF_SUCCESS;
102 }
103 }
104