1 /*
2  * Copyright (c) 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 "scanner_info.h"
17 
18 namespace OHOS::Scan {
19 
20 
21 //tcp
ScanDeviceInfoTCP()22 ScanDeviceInfoTCP::ScanDeviceInfoTCP()
23 {
24     deviceName="";
25     uuid="";
26     model="";
27     manufacturer="";
28     deviceType="";
29     port="";
30     addr="";
31     button="";
32     feeder="";
33     deviceState = 0;
34 }
35 
ScanDeviceInfoTCP(const ScanDeviceInfoTCP & right)36 ScanDeviceInfoTCP::ScanDeviceInfoTCP(const ScanDeviceInfoTCP &right)
37 {
38     deviceName = right.deviceName;
39     uuid = right.uuid;
40     model = right.model;
41     manufacturer = right.manufacturer;
42     deviceType = right.deviceType;
43     port = right.port;
44     addr = right.addr;
45     button = right.button;
46     feeder = right.feeder;
47     deviceState = right.deviceState;
48 }
49 
operator =(const ScanDeviceInfoTCP & right)50 ScanDeviceInfoTCP &ScanDeviceInfoTCP::operator=(const ScanDeviceInfoTCP &right)
51 {
52     if (this != &right) {
53         deviceName = right.deviceName;
54         uuid = right.uuid;
55         model = right.model;
56         manufacturer = right.manufacturer;
57         deviceType = right.deviceType;
58         port = right.port;
59         addr = right.addr;
60         button = right.button;
61         feeder = right.feeder;
62         deviceState = right.deviceState;
63     }
64     return *this;
65 }
66 
SetDeviceName(const std::string & deviceName_)67 void ScanDeviceInfoTCP::SetDeviceName(const std::string& deviceName_)
68 {
69     deviceName = deviceName_;
70 }
71 
SetUuid(const std::string & uuid_)72 void ScanDeviceInfoTCP::SetUuid(const std::string& uuid_)
73 {
74     uuid = uuid_;
75 }
76 
SetModel(const std::string & model_)77 void ScanDeviceInfoTCP::SetModel(const std::string& model_)
78 {
79     model = model_;
80 }
81 
SetManufacturer(const std::string & manufacturer_)82 void ScanDeviceInfoTCP::SetManufacturer(const std::string& manufacturer_)
83 {
84     manufacturer = manufacturer_;
85 }
86 
SetDeviceType(const std::string & deviceType_)87 void ScanDeviceInfoTCP::SetDeviceType(const std::string& deviceType_)
88 {
89     deviceType = deviceType_;
90 }
91 
SetPort(const std::string & port_)92 void ScanDeviceInfoTCP::SetPort(const std::string& port_)
93 {
94     port = port_;
95 }
96 
SetAddr(const std::string & addr_)97 void ScanDeviceInfoTCP::SetAddr(const std::string& addr_)
98 {
99     addr = addr_;
100 }
101 
SetButton(const std::string & button_)102 void ScanDeviceInfoTCP::SetButton(const std::string& button_)
103 {
104     button = button_;
105 }
106 
SetFeeder(const std::string & feeder_)107 void ScanDeviceInfoTCP::SetFeeder(const std::string& feeder_)
108 {
109     feeder = feeder_;
110 }
111 
SetDeviceState(const uint32_t & deviceState_)112 void ScanDeviceInfoTCP::SetDeviceState(const uint32_t& deviceState_)
113 {
114     deviceState = deviceState_;
115 }
116 
GetDeviceName() const117 const std::string& ScanDeviceInfoTCP::GetDeviceName() const
118 {
119     return deviceName;
120 }
121 
GetUuid() const122 const std::string& ScanDeviceInfoTCP::GetUuid() const
123 {
124     return uuid;
125 }
126 
GetModel() const127 const std::string& ScanDeviceInfoTCP::GetModel() const
128 {
129     return model;
130 }
131 
GetManufacturer() const132 const std::string& ScanDeviceInfoTCP::GetManufacturer() const
133 {
134     return manufacturer;
135 }
136 
GetDeviceType() const137 const std::string& ScanDeviceInfoTCP::GetDeviceType() const
138 {
139     return deviceType;
140 }
141 
GetPort() const142 const std::string& ScanDeviceInfoTCP::GetPort() const
143 {
144     return port;
145 }
146 
GetAddr() const147 const std::string& ScanDeviceInfoTCP::GetAddr() const
148 {
149     return addr;
150 }
151 
GetButton() const152 const std::string& ScanDeviceInfoTCP::GetButton() const
153 {
154     return button;
155 }
156 
GetFeeder() const157 const std::string& ScanDeviceInfoTCP::GetFeeder() const
158 {
159     return feeder;
160 }
161 
GetDeviceState() const162 const uint32_t& ScanDeviceInfoTCP::GetDeviceState() const
163 {
164     return deviceState;
165 }
166 
ReadFromParcel(Parcel & parcel)167 bool ScanDeviceInfoTCP::ReadFromParcel(Parcel &parcel)
168 {
169     SetDeviceName(parcel.ReadString());
170     SetUuid(parcel.ReadString());
171     SetModel(parcel.ReadString());
172     SetManufacturer(parcel.ReadString());
173     SetDeviceType(parcel.ReadString());
174     SetPort(parcel.ReadString());
175     SetAddr(parcel.ReadString());
176     SetButton(parcel.ReadString());
177     SetFeeder(parcel.ReadString());
178     return true;
179 }
180 
Marshalling(Parcel & parcel) const181 bool ScanDeviceInfoTCP::Marshalling(Parcel &parcel) const
182 {
183     parcel.WriteString(GetDeviceName());
184     parcel.WriteString(GetUuid());
185     parcel.WriteString(GetModel());
186     parcel.WriteString(GetManufacturer());
187     parcel.WriteString(GetDeviceType());
188     parcel.WriteString(GetPort());
189     parcel.WriteString(GetAddr());
190     parcel.WriteString(GetButton());
191     parcel.WriteString(GetFeeder());
192     return true;
193 }
194 
Unmarshalling(Parcel & parcel)195 std::shared_ptr<ScanDeviceInfoTCP> ScanDeviceInfoTCP::Unmarshalling(Parcel &parcel)
196 {
197     auto nativeObj = std::make_shared<ScanDeviceInfoTCP>();
198     if (!nativeObj->ReadFromParcel(parcel)) {
199         SCAN_HILOGE("Failed to unmarshalling scaner info");
200         return nullptr;
201     }
202     return nativeObj;
203 }
204 
205 
ScanDeviceInfo()206 ScanDeviceInfo::ScanDeviceInfo()
207 {
208     deviceId = "";
209     manufacturer = "";
210     model = "";
211     deviceType = "";
212     deviceState = 0;
213     discoverMode = "";
214     serialNumber = "";
215     deviceName = "";
216     uniqueId = "";
217     uuid = "";
218 }
219 
ScanDeviceInfo(const ScanDeviceInfo & right)220 ScanDeviceInfo::ScanDeviceInfo(const ScanDeviceInfo &right)
221 {
222     deviceId = right.deviceId;
223     manufacturer = right.manufacturer;
224     model = right.model;
225     deviceType = right.deviceType;
226     deviceState = right.deviceState;
227     discoverMode = right.discoverMode;
228     serialNumber = right.serialNumber;
229     deviceName = right.deviceName;
230     uniqueId = right.uniqueId;
231     uuid = right.uuid;
232 }
233 
operator =(const ScanDeviceInfo & right)234 ScanDeviceInfo &ScanDeviceInfo::operator=(const ScanDeviceInfo &right)
235 {
236     if (this != &right) {
237         deviceId = right.deviceId;
238         manufacturer = right.manufacturer;
239         model = right.model;
240         deviceType = right.deviceType;
241         deviceState = right.deviceState;
242         discoverMode = right.discoverMode;
243         serialNumber = right.serialNumber;
244         deviceName = right.deviceName;
245         uniqueId = right.uniqueId;
246         uuid = right.uuid;
247     }
248     return *this;
249 }
250 
251 
SetDeviceId(const std::string & newScannerId)252 void ScanDeviceInfo::SetDeviceId(const std::string& newScannerId)
253 {
254     deviceId = newScannerId;
255 }
256 
GetDeviceId() const257 const std::string& ScanDeviceInfo::GetDeviceId() const
258 {
259     return deviceId;
260 }
261 
SetManufacturer(const std::string & newManufacturer)262 void ScanDeviceInfo::SetManufacturer(const std::string& newManufacturer)
263 {
264     manufacturer = newManufacturer;
265 }
266 
GetManufacturer() const267 const std::string& ScanDeviceInfo::GetManufacturer() const
268 {
269     return manufacturer;
270 }
271 
SetModel(const std::string & newModel)272 void ScanDeviceInfo::SetModel(const std::string& newModel)
273 {
274     model = newModel;
275 }
276 
GetModel() const277 const std::string& ScanDeviceInfo::GetModel() const
278 {
279     return model;
280 }
281 
SetDeviceType(const std::string & newDeviceType)282 void ScanDeviceInfo::SetDeviceType(const std::string& newDeviceType)
283 {
284     deviceType = newDeviceType;
285 }
286 
GetDeviceType() const287 const std::string& ScanDeviceInfo::GetDeviceType() const
288 {
289     return deviceType;
290 }
291 
SetDeviceState(const uint32_t & newDeviceState)292 void ScanDeviceInfo::SetDeviceState(const uint32_t& newDeviceState)
293 {
294     deviceState = newDeviceState;
295 }
296 
GetDeviceState() const297 const uint32_t& ScanDeviceInfo::GetDeviceState() const
298 {
299     return deviceState;
300 }
301 
SetDiscoverMode(const std::string & newDiscoverMode)302 void ScanDeviceInfo::SetDiscoverMode(const std::string& newDiscoverMode)
303 {
304     discoverMode = newDiscoverMode;
305 }
306 
GetDiscoverMode() const307 const std::string& ScanDeviceInfo::GetDiscoverMode() const
308 {
309     return discoverMode;
310 }
311 
SetSerialNumber(const std::string & newSerialNumber)312 void ScanDeviceInfo::SetSerialNumber(const std::string& newSerialNumber)
313 {
314     serialNumber = newSerialNumber;
315 }
316 
GetSerialNumber() const317 const std::string& ScanDeviceInfo::GetSerialNumber() const
318 {
319     return serialNumber;
320 }
321 
SetDeviceName(const std::string & newDeviceName)322 void ScanDeviceInfo::SetDeviceName(const std::string& newDeviceName)
323 {
324     deviceName = newDeviceName;
325 }
326 
GetDeviceName() const327 const std::string& ScanDeviceInfo::GetDeviceName() const
328 {
329     return deviceName;
330 }
331 
SetUniqueId(const std::string & uniqueId)332 void ScanDeviceInfo::SetUniqueId(const std::string& uniqueId)
333 {
334     this->uniqueId = uniqueId;
335 }
336 
GetUniqueId() const337 const std::string& ScanDeviceInfo::GetUniqueId() const
338 {
339     return uniqueId;
340 }
341 
SetUuid(const std::string & uuid)342 void ScanDeviceInfo::SetUuid(const std::string& uuid)
343 {
344     this->uuid = uuid;
345 }
346 
GetUuid() const347 const std::string& ScanDeviceInfo::GetUuid() const
348 {
349     return uuid;
350 }
351 
ReadFromParcel(Parcel & parcel)352 bool ScanDeviceInfo::ReadFromParcel(Parcel &parcel)
353 {
354     SetDeviceId(parcel.ReadString());
355     SetManufacturer(parcel.ReadString());
356     SetModel(parcel.ReadString());
357     SetDeviceType(parcel.ReadString());
358     SetDiscoverMode(parcel.ReadString());
359     SetSerialNumber(parcel.ReadString());
360     SetDeviceName(parcel.ReadString());
361     SetUniqueId(parcel.ReadString());
362     return true;
363 }
364 
Marshalling(Parcel & parcel) const365 bool ScanDeviceInfo::Marshalling(Parcel &parcel) const
366 {
367     parcel.WriteString(deviceId);
368     parcel.WriteString(manufacturer);
369     parcel.WriteString(model);
370     parcel.WriteString(deviceType);
371     parcel.WriteString(discoverMode);
372     parcel.WriteString(serialNumber);
373     parcel.WriteString(deviceName);
374     parcel.WriteString(uniqueId);
375     return true;
376 }
377 
Unmarshalling(Parcel & parcel)378 std::shared_ptr<ScanDeviceInfo> ScanDeviceInfo::Unmarshalling(Parcel &parcel)
379 {
380     auto nativeObj = std::make_shared<ScanDeviceInfo>();
381     if (!nativeObj->ReadFromParcel(parcel)) {
382         SCAN_HILOGE("Failed to unmarshalling scaner info");
383         return nullptr;
384     }
385     return nativeObj;
386 }
387 
388 // ScanDeviceInfoSync
389 
ScanDeviceInfoSync()390 ScanDeviceInfoSync::ScanDeviceInfoSync()
391 {
392     deviceId = "";
393     discoverMode = "";
394     serialNumber = "";
395     syncMode = "";
396     deviceState = 0;
397     oldDeviceId = "";
398 }
399 
ScanDeviceInfoSync(const ScanDeviceInfoSync & right)400 ScanDeviceInfoSync::ScanDeviceInfoSync(const ScanDeviceInfoSync &right)
401 {
402     deviceId = right.deviceId;
403     discoverMode = right.discoverMode;
404     serialNumber = right.serialNumber;
405     syncMode = right.syncMode;
406     deviceState = right.deviceState;
407     oldDeviceId = right.oldDeviceId;
408 }
409 
operator =(const ScanDeviceInfoSync & right)410 ScanDeviceInfoSync &ScanDeviceInfoSync::operator=(const ScanDeviceInfoSync &right)
411 {
412     if (this != &right) {
413         deviceId = right.deviceId;
414         discoverMode = right.discoverMode;
415         serialNumber = right.serialNumber;
416         syncMode = right.syncMode;
417         deviceState = right.deviceState;
418         oldDeviceId = right.oldDeviceId;
419     }
420     return *this;
421 }
422 
423 
SetDeviceId(const std::string & newScannerId)424 void ScanDeviceInfoSync::SetDeviceId(const std::string& newScannerId)
425 {
426     deviceId = newScannerId;
427 }
428 
GetDeviceId() const429 const std::string& ScanDeviceInfoSync::GetDeviceId() const
430 {
431     return deviceId;
432 }
433 
SetDiscoverMode(const std::string & newDiscoverMode)434 void ScanDeviceInfoSync::SetDiscoverMode(const std::string& newDiscoverMode)
435 {
436     discoverMode = newDiscoverMode;
437 }
438 
GetDiscoverMode() const439 const std::string& ScanDeviceInfoSync::GetDiscoverMode() const
440 {
441     return discoverMode;
442 }
443 
SetSerialNumber(const std::string & newSerialNumber)444 void ScanDeviceInfoSync::SetSerialNumber(const std::string& newSerialNumber)
445 {
446     serialNumber = newSerialNumber;
447 }
448 
GetSerialNumber() const449 const std::string& ScanDeviceInfoSync::GetSerialNumber() const
450 {
451     return serialNumber;
452 }
453 
SetSyncMode(const std::string & newSyncMode)454 void ScanDeviceInfoSync::SetSyncMode(const std::string& newSyncMode)
455 {
456     syncMode = newSyncMode;
457 }
458 
GetSyncMode() const459 const std::string& ScanDeviceInfoSync::GetSyncMode() const
460 {
461     return syncMode;
462 }
463 
SetDeviceState(const uint32_t & newDeviceState)464 void ScanDeviceInfoSync::SetDeviceState(const uint32_t& newDeviceState)
465 {
466     deviceState = newDeviceState;
467 }
468 
GetDeviceState() const469 const uint32_t& ScanDeviceInfoSync::GetDeviceState() const
470 {
471     return deviceState;
472 }
473 
SetOldDeviceId(const std::string & oldDeviceId)474 void ScanDeviceInfoSync::SetOldDeviceId(const std::string& oldDeviceId)
475 {
476     this->oldDeviceId = oldDeviceId;
477 }
478 
GetOldDeviceId() const479 const std::string& ScanDeviceInfoSync::GetOldDeviceId() const
480 {
481     return oldDeviceId;
482 }
483 
SetUniqueId(const std::string & uniqueId)484 void ScanDeviceInfoSync::SetUniqueId(const std::string& uniqueId)
485 {
486     this->uniqueId = uniqueId;
487 }
488 
GetUniqueId() const489 const std::string& ScanDeviceInfoSync::GetUniqueId() const
490 {
491     return uniqueId;
492 }
493 
ReadFromParcel(Parcel & parcel)494 void ScanDeviceInfoSync::ReadFromParcel(Parcel &parcel)
495 {
496     SetDeviceId(parcel.ReadString());
497     SetDiscoverMode(parcel.ReadString());
498     SetSerialNumber(parcel.ReadString());
499     SetSyncMode(parcel.ReadString());
500     SetOldDeviceId(parcel.ReadString());
501 }
502 
Marshalling(Parcel & parcel) const503 bool ScanDeviceInfoSync::Marshalling(Parcel &parcel) const
504 {
505     parcel.WriteString(deviceId);
506     parcel.WriteString(discoverMode);
507     parcel.WriteString(serialNumber);
508     parcel.WriteString(syncMode);
509     parcel.WriteString(oldDeviceId);
510     return true;
511 }
512 
Unmarshalling(Parcel & parcel)513 std::shared_ptr<ScanDeviceInfoSync> ScanDeviceInfoSync::Unmarshalling(Parcel &parcel)
514 {
515     auto nativeObj = std::make_shared<ScanDeviceInfoSync>();
516     nativeObj->ReadFromParcel(parcel);
517     return nativeObj;
518 }
519 
520 } // namespace OHOS::Scan
521