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_proxy.h"
17 
18 #include "camera_log.h"
19 #include "camera_service_ipc_interface_code.h"
20 
21 namespace OHOS {
22 namespace CameraStandard {
23 
HStreamDepthDataProxy(const sptr<IRemoteObject> & impl)24 HStreamDepthDataProxy::HStreamDepthDataProxy(const sptr<IRemoteObject>& impl) : IRemoteProxy<IStreamDepthData>(impl) {}
25 
~HStreamDepthDataProxy()26 HStreamDepthDataProxy::~HStreamDepthDataProxy()
27 {
28     MEDIA_INFO_LOG("~HStreamDepthDataProxy is called");
29 }
30 
Start()31 int32_t HStreamDepthDataProxy::Start()
32 {
33     MessageParcel data;
34     MessageParcel reply;
35     MessageOption option;
36 
37     data.WriteInterfaceToken(GetDescriptor());
38     int error = Remote()->SendRequest(
39         static_cast<uint32_t>(StreamDepthDataInterfaceCode::CAMERA_STREAM_DEPTH_DATA_START), data, reply, option);
40     if (error != ERR_NONE) {
41         MEDIA_ERR_LOG("HStreamDepthDataProxy Start failed, error: %{public}d", error);
42     }
43 
44     return error;
45 }
46 
Stop()47 int32_t HStreamDepthDataProxy::Stop()
48 {
49     MessageParcel data;
50     MessageParcel reply;
51     MessageOption option;
52 
53     data.WriteInterfaceToken(GetDescriptor());
54     int error = Remote()->SendRequest(
55         static_cast<uint32_t>(StreamDepthDataInterfaceCode::CAMERA_STREAM_DEPTH_DATA_STOP), data, reply, option);
56     if (error != ERR_NONE) {
57         MEDIA_ERR_LOG("HStreamDepthDataProxy Stop failed, error: %{public}d", error);
58     }
59 
60     return error;
61 }
62 
Release()63 int32_t HStreamDepthDataProxy::Release()
64 {
65     MessageParcel data;
66     MessageParcel reply;
67     MessageOption option;
68 
69     data.WriteInterfaceToken(GetDescriptor());
70     int error = Remote()->SendRequest(
71         static_cast<uint32_t>(StreamDepthDataInterfaceCode::CAMERA_STREAM_DEPTH_DATA_RELEASE), data, reply, option);
72     if (error != ERR_NONE) {
73         MEDIA_ERR_LOG("HStreamDepthDataProxy Stop failed, error: %{public}d", error);
74     }
75     return error;
76 }
77 
SetCallback(sptr<IStreamDepthDataCallback> & callback)78 int32_t HStreamDepthDataProxy::SetCallback(sptr<IStreamDepthDataCallback>& callback)
79 {
80     MessageParcel data;
81     MessageParcel reply;
82     MessageOption option;
83 
84     if (callback == nullptr) {
85         MEDIA_ERR_LOG("HStreamDepthDataProxy SetCallback callback is null");
86         return IPC_PROXY_ERR;
87     }
88 
89     data.WriteInterfaceToken(GetDescriptor());
90     data.WriteRemoteObject(callback->AsObject());
91 
92     int error = Remote()->SendRequest(static_cast<uint32_t>(
93         StreamDepthDataInterfaceCode::CAMERA_STREAM_DEPTH_DATA_SET_CALLBACK), data, reply, option);
94     if (error != ERR_NONE) {
95         MEDIA_ERR_LOG("HStreamDepthDataProxy SetCallback failed, error: %{public}d", error);
96     }
97 
98     return error;
99 }
100 
SetDataAccuracy(int32_t dataAccuracy)101 int32_t HStreamDepthDataProxy::SetDataAccuracy(int32_t dataAccuracy)
102 {
103     MessageParcel data;
104     MessageParcel reply;
105     MessageOption option;
106 
107     data.WriteInterfaceToken(GetDescriptor());
108     data.WriteInt32(dataAccuracy);
109 
110     int error = Remote()->SendRequest(static_cast<uint32_t>(
111         StreamDepthDataInterfaceCode::CAMERA_STREAM_DEPTH_DATA_ACCURACY_SET), data, reply, option);
112     if (error != ERR_NONE) {
113         MEDIA_ERR_LOG("HStreamDepthDataProxy SetDataAccuracy failed, error: %{public}d", error);
114     }
115     return error;
116 }
117 } // namespace CameraStandard
118 } // namespace OHOS