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 "distributed_camera_sink_stub.h"
17 #include "distributed_camera_errno.h"
18 #include "distributed_hardware_log.h"
19
20 namespace OHOS {
21 namespace DistributedHardware {
DistributedCameraSinkStub()22 DistributedCameraSinkStub::DistributedCameraSinkStub()
23 {
24 memberFuncMap_[INIT_SINK] = &DistributedCameraSinkStub::InitSinkInner;
25 memberFuncMap_[RELEASE_SINK] = &DistributedCameraSinkStub::ReleaseSinkInner;
26 memberFuncMap_[SUBSCRIBE_LOCAL_HARDWARE] = &DistributedCameraSinkStub::SubscribeLocalHardwareInner;
27 memberFuncMap_[UNSUBSCRIBE_LOCAL_HARDWARE] = &DistributedCameraSinkStub::UnsubscribeLocalHardwareInner;
28 memberFuncMap_[STOP_CAPTURE] = &DistributedCameraSinkStub::StopCaptureInner;
29 memberFuncMap_[CHANNEL_NEG] = &DistributedCameraSinkStub::ChannelNegInner;
30 memberFuncMap_[GET_CAMERA_INFO] = &DistributedCameraSinkStub::GetCameraInfoInner;
31 memberFuncMap_[OPEN_CHANNEL] = &DistributedCameraSinkStub::OpenChannelInner;
32 memberFuncMap_[CLOSE_CHANNEL] = &DistributedCameraSinkStub::CloseChannelInner;
33 }
34
~DistributedCameraSinkStub()35 DistributedCameraSinkStub::~DistributedCameraSinkStub()
36 {}
37
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)38 int32_t DistributedCameraSinkStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
39 MessageOption &option)
40 {
41 DHLOGD("DistributedCameraSinkStub::OnRemoteRequest code: %d", code);
42 std::u16string desc = DistributedCameraSinkStub::GetDescriptor();
43 std::u16string remoteDesc = data.ReadInterfaceToken();
44 if (desc != remoteDesc) {
45 DHLOGE("DistributedCameraSinkStub::OnRemoteRequest remoteDesc is invalid!");
46 return ERR_INVALID_DATA;
47 }
48 auto itFunc = memberFuncMap_.find(code);
49 if (itFunc == memberFuncMap_.end()) {
50 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
51 }
52
53 auto memberFunc = itFunc->second;
54 return (this->*memberFunc)(data, reply);
55 }
56
InitSinkInner(MessageParcel & data,MessageParcel & reply)57 int32_t DistributedCameraSinkStub::InitSinkInner(MessageParcel &data, MessageParcel &reply)
58 {
59 DHLOGD("DistributedCameraSinkStub::InitSinkInner");
60 int32_t ret = DCAMERA_OK;
61 do {
62 std::string params = data.ReadString();
63 if (params.empty() || params.size() > PARAM_MAX_SIZE) {
64 DHLOGE("DistributedCameraSinkStub::InitSinkInner params is invalid");
65 ret = DCAMERA_BAD_VALUE;
66 break;
67 }
68 ret = InitSink(params);
69 } while (0);
70 reply.WriteInt32(ret);
71 return DCAMERA_OK;
72 }
73
ReleaseSinkInner(MessageParcel & data,MessageParcel & reply)74 int32_t DistributedCameraSinkStub::ReleaseSinkInner(MessageParcel &data, MessageParcel &reply)
75 {
76 DHLOGD("DistributedCameraSinkStub::ReleaseSinkInner");
77 int32_t ret = ReleaseSink();
78 reply.WriteInt32(ret);
79 return DCAMERA_OK;
80 }
81
SubscribeLocalHardwareInner(MessageParcel & data,MessageParcel & reply)82 int32_t DistributedCameraSinkStub::SubscribeLocalHardwareInner(MessageParcel &data, MessageParcel &reply)
83 {
84 DHLOGD("DistributedCameraSinkStub::SubscribeLocalHardwareInner");
85 int32_t ret = DCAMERA_OK;
86 do {
87 std::string dhId = data.ReadString();
88 std::string parameters = data.ReadString();
89 if (parameters.empty() || parameters.size() > PARAM_MAX_SIZE || dhId.empty() ||
90 dhId.size() > DID_MAX_SIZE) {
91 DHLOGE("DistributedCameraSinkStub::SubscribeLocalHardwareInner params is invalid");
92 ret = DCAMERA_BAD_VALUE;
93 break;
94 }
95 ret = SubscribeLocalHardware(dhId, parameters);
96 } while (0);
97 reply.WriteInt32(ret);
98 return DCAMERA_OK;
99 }
100
UnsubscribeLocalHardwareInner(MessageParcel & data,MessageParcel & reply)101 int32_t DistributedCameraSinkStub::UnsubscribeLocalHardwareInner(MessageParcel &data, MessageParcel &reply)
102 {
103 DHLOGD("DistributedCameraSinkStub::UnsubscribeLocalHardwareInner");
104 int32_t ret = DCAMERA_OK;
105 do {
106 std::string dhId = data.ReadString();
107 if (dhId.empty() || dhId.size() > DID_MAX_SIZE) {
108 DHLOGE("DistributedCameraSinkStub::UnsubscribeLocalHardwareInner params is invalid");
109 ret = DCAMERA_BAD_VALUE;
110 break;
111 }
112 ret = UnsubscribeLocalHardware(dhId);
113 } while (0);
114 reply.WriteInt32(ret);
115 return DCAMERA_OK;
116 }
117
StopCaptureInner(MessageParcel & data,MessageParcel & reply)118 int32_t DistributedCameraSinkStub::StopCaptureInner(MessageParcel &data, MessageParcel &reply)
119 {
120 DHLOGD("DistributedCameraSinkStub::StopCaptureInner");
121 int32_t ret = DCAMERA_OK;
122 do {
123 std::string dhId = data.ReadString();
124 if (dhId.empty() || dhId.size() > DID_MAX_SIZE) {
125 DHLOGE("DistributedCameraSinkStub::StopCaptureInner params is invalid");
126 ret = DCAMERA_BAD_VALUE;
127 break;
128 }
129 ret = StopCapture(dhId);
130 } while (0);
131 reply.WriteInt32(ret);
132 return DCAMERA_OK;
133 }
134
ChannelNegInner(MessageParcel & data,MessageParcel & reply)135 int32_t DistributedCameraSinkStub::ChannelNegInner(MessageParcel &data, MessageParcel &reply)
136 {
137 DHLOGD("DistributedCameraSinkStub::ChannelNegInner");
138 int32_t ret = DCAMERA_OK;
139 do {
140 std::string dhId = data.ReadString();
141 std::string channelInfo = data.ReadString();
142 if (dhId.empty() || dhId.size() > DID_MAX_SIZE || channelInfo.empty() ||
143 channelInfo.size() > PARAM_MAX_SIZE) {
144 DHLOGE("DistributedCameraSinkStub::ChannelNegInner params is invalid");
145 ret = DCAMERA_BAD_VALUE;
146 break;
147 }
148 ret = ChannelNeg(dhId, channelInfo);
149 } while (0);
150 reply.WriteInt32(ret);
151 return DCAMERA_OK;
152 }
153
GetCameraInfoInner(MessageParcel & data,MessageParcel & reply)154 int32_t DistributedCameraSinkStub::GetCameraInfoInner(MessageParcel &data, MessageParcel &reply)
155 {
156 DHLOGD("DistributedCameraSinkStub::GetCameraInfoInner");
157 int32_t ret = DCAMERA_OK;
158 do {
159 std::string dhId = data.ReadString();
160 std::string cameraInfo = data.ReadString();
161 if (dhId.empty() || dhId.size() > DID_MAX_SIZE) {
162 DHLOGE("DistributedCameraSinkStub::GetCameraInfoInner params is invalid");
163 ret = DCAMERA_BAD_VALUE;
164 break;
165 }
166 ret = GetCameraInfo(dhId, cameraInfo);
167 } while (0);
168 reply.WriteInt32(ret);
169 return DCAMERA_OK;
170 }
171
OpenChannelInner(MessageParcel & data,MessageParcel & reply)172 int32_t DistributedCameraSinkStub::OpenChannelInner(MessageParcel &data, MessageParcel &reply)
173 {
174 DHLOGD("DistributedCameraSinkStub::OpenChannelInner");
175 int32_t ret = DCAMERA_OK;
176 do {
177 std::string dhId = data.ReadString();
178 std::string openInfo = data.ReadString();
179 if (dhId.empty() || dhId.size() > DID_MAX_SIZE || openInfo.empty()||
180 openInfo.size() > PARAM_MAX_SIZE) {
181 DHLOGE("DistributedCameraSinkStub::OpenChannelInner params is invalid");
182 ret = DCAMERA_BAD_VALUE;
183 break;
184 }
185 ret = OpenChannel(dhId, openInfo);
186 } while (0);
187 reply.WriteInt32(ret);
188 return DCAMERA_OK;
189 }
190
CloseChannelInner(MessageParcel & data,MessageParcel & reply)191 int32_t DistributedCameraSinkStub::CloseChannelInner(MessageParcel &data, MessageParcel &reply)
192 {
193 DHLOGD("DistributedCameraSinkStub::CloseChannelInner");
194 int32_t ret = DCAMERA_OK;
195 do {
196 std::string dhId = data.ReadString();
197 if (dhId.empty() || dhId.size() > DID_MAX_SIZE) {
198 DHLOGE("DistributedCameraSinkStub::CloseChannelInner params is invalid");
199 ret = DCAMERA_BAD_VALUE;
200 break;
201 }
202 ret = CloseChannel(dhId);
203 } while (0);
204 reply.WriteInt32(ret);
205 return DCAMERA_OK;
206 }
207 } // namespace DistributedHardware
208 } // namespace OHOS