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