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