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 #ifndef OHOS_WIFI_CONFIG_FILE_SPEC_H
17 #define OHOS_WIFI_CONFIG_FILE_SPEC_H
18 #include <fstream>
19 #include <sstream>
20 #include <string>
21 #include <vector>
22 #include "wifi_internal_msg.h"
23 #include "wifi_p2p_msg.h"
24 #include "wifi_hisysevent.h"
25 #include "wifi_common_util.h"
26 #ifndef OHOS_ARCH_LITE
27 #include "wifi_backup_config.h"
28 #endif
29
30 namespace OHOS {
31 namespace Wifi {
32 /* ----------------- template function begin ----------------------- */
33 /**
34 * @Description Clear and init item
35 *
36 * @tparam T - typename
37 * @param item - item
38 */
39 template <typename T>
ClearTClass(T & item)40 void ClearTClass(T &item)
41 {
42 /* fixed compile warning, -Werror,-Wunused-parameter */
43 item;
44 return;
45 }
46
47
48 /**
49 * @Description Set item's data, input key is the item's member and input value is the
50 * member's value
51 *
52 * @tparam T - typename
53 * @param item - T &item
54 * @param key - Item key
55 * @param value - Item value
56 * @return int - parse error: 0 Success, >0 parse failed
57 */
58 template <typename T>
SetTClassKeyValue(T & item,const std::string & key,const std::string & value)59 int SetTClassKeyValue(T &item, const std::string &key, const std::string &value)
60 {
61 /* fixed compile warning, -Werror,-Wunused-parameter */
62 item;
63 std::ostringstream ss;
64 ss << key << value << std::endl;
65 return 0;
66 }
67
68 /**
69 * @Description Output the item's head
70 *
71 * @tparam T - typename
72 * @param item - item
73 * @return std::string - the item's type name
74 */
75 template <typename T>
GetTClassName()76 std::string GetTClassName()
77 {
78 return "";
79 }
80
81 /**
82 * @Description Output the item, format: item's member = the member value
83 *
84 * @tparam T - typename
85 * @param item - item
86 * @return std::string - output item's total member=value string
87 */
88 template <typename T>
OutTClassString(T & item)89 std::string OutTClassString(T &item)
90 {
91 /* fixed compile warning, -Werror,-Wunused-parameter */
92 item;
93 std::string s;
94 return s;
95 }
96
97 /* ----------------- template function end --------------------------------- */
98
99 /* ------------template function specialization declare begin-------------- */
100 /**
101 * @Description Clear and init WifiDeviceConfig
102 *
103 * @tparam
104 * @param item - WifiDeviceConfig item
105 */
106 template <>
107 void ClearTClass<WifiDeviceConfig>(WifiDeviceConfig &item);
108
109 /**
110 * @Description Set WifiDeviceConfig item data
111 *
112 * @tparam
113 * @param item - WifiDeviceConfig &item
114 * @param key - WifiDeviceConfig struct member name
115 * @param value - the WifiDeviceConfig item member value
116 * @return int - parse error: 0 Success, >0 parse failed
117 */
118 template <>
119 int SetTClassKeyValue<WifiDeviceConfig>(WifiDeviceConfig &item, const std::string &key, const std::string &value);
120
121 /**
122 * @Description Output WifiDeviceConfig class name
123 *
124 * @tparam
125 * @param item - WifiDeviceConfig &item
126 * @return std::string - Class name
127 */
128 template <>
129 std::string GetTClassName<WifiDeviceConfig>();
130
131 /**
132 * @Description Output the WifiDeviceConfig item, format: item's member = the member value
133 *
134 * @tparam
135 * @param item - WifiDeviceConfig &item
136 * @return std::string - output total member=value string about the WifiDeviceConfig item
137 */
138 template <>
139 std::string OutTClassString<WifiDeviceConfig>(WifiDeviceConfig &item);
140
141 template <>
142 std::string OutTClassString<WifiRestrictedInfo>(WifiRestrictedInfo &item);
143
144 template <>
145 std::string GetTClassName<WifiRestrictedInfo>();
146
147 template <>
148 void ClearTClass<WifiRestrictedInfo>(WifiRestrictedInfo &item);
149
150 template <>
151 int SetTClassKeyValue<WifiRestrictedInfo>(WifiRestrictedInfo &item, const std::string &key, const std::string &value);
152
153 #ifndef OHOS_ARCH_LITE
154 /**
155 * @Description Clear and init WifiBackupConfig
156 *
157 * @tparam
158 * @param item - WifiBackupConfig item
159 */
160 template <>
161 void ClearTClass<WifiBackupConfig>(WifiBackupConfig &item);
162
163 /**
164 * @Description Set WifiBackupConfig item data
165 *
166 * @tparam
167 * @param item - WifiBackupConfig &item
168 * @param key - WifiBackupConfig struct member name
169 * @param value - the WifiBackupConfig item member value
170 * @return int - parse error: 0 Success, >0 parse failed
171 */
172 template <>
173 int SetTClassKeyValue<WifiBackupConfig>(WifiBackupConfig &item, const std::string &key, const std::string &value);
174
175 /**
176 * @Description Output WifiBackupConfig class name
177 *
178 * @tparam
179 * @param item - WifiBackupConfig &item
180 * @return std::string - Class name
181 */
182 template <>
183 std::string GetTClassName<WifiBackupConfig>();
184
185 /**
186 * @Description Output the WifiBackupConfig item, format: item's member = the member value
187 *
188 * @tparam
189 * @param item - WifiBackupConfig &item
190 * @return std::string - output total member=value string about the WifiBackupConfig item
191 */
192 template <>
193 std::string OutTClassString<WifiBackupConfig>(WifiBackupConfig &item);
194 #endif
195
196 /**
197 * @Description Clear and init HotspotConfig
198 *
199 * @tparam
200 * @param item - HotspotConfig item
201 */
202 template <>
203 void ClearTClass<HotspotConfig>(HotspotConfig &item);
204
205 /**
206 * @Description Set HotspotConfig item data
207 *
208 * @tparam
209 * @param item - HotspotConfig &item
210 * @param key - HotspotConfig struct member name
211 * @param value - the HotspotConfig item member value
212 * @return int - parse error: 0 Success, >0 parse failed
213 */
214 template <>
215 int SetTClassKeyValue<HotspotConfig>(HotspotConfig &item, const std::string &key, const std::string &value);
216
217 /**
218 * @Description Output HotspotConfig class name
219 *
220 * @tparam
221 * @param item - HotspotConfig &item
222 * @return std::string - Class name
223 */
224 template <>
225 std::string GetTClassName<HotspotConfig>();
226
227 /**
228 * @Description Output the HotspotConfig item, format: item's member = the member value
229 *
230 * @tparam
231 * @param item - HotspotConfig &item
232 * @return std::string - output total member=value string about the HotspotConfig item
233 */
234 template <>
235 std::string OutTClassString<HotspotConfig>(HotspotConfig &item);
236
237 /**
238 * @Description Clear and init P2pVendorConfig
239 *
240 * @tparam
241 * @param item - P2pVendorConfig &item
242 */
243 template<>
244 void ClearTClass<P2pVendorConfig>(P2pVendorConfig &item);
245
246 /**
247 * @Description Set P2pVendorConfig item data
248 *
249 * @tparam
250 * @param item - P2pVendorConfig &item
251 * @param key - P2pVendorConfig struct member name
252 * @param value - the P2pVendorConfig item member value
253 * @return int - parse error: 0 Success, >0 parse failed
254 */
255 template<>
256 int SetTClassKeyValue<P2pVendorConfig>(P2pVendorConfig &item, const std::string &key, const std::string &value);
257
258 /**
259 * @Description Output P2pVendorConfig class name
260 *
261 * @tparam
262 * @param item - P2pVendorConfig &item
263 * @return std::string - Class name
264 */
265 template<>
266 std::string GetTClassName<P2pVendorConfig>();
267
268 /**
269 * @Description Output the P2pVendorConfig item, format: item's member = the member value
270 *
271 * @tparam
272 * @param item - P2pVendorConfig &item
273 * @return std::string - output total member=value string about the P2pVendorConfig item
274 */
275 template<>
276 std::string OutTClassString<P2pVendorConfig>(P2pVendorConfig &item);
277
278 /**
279 * @Description Clear and init StationInfo
280 *
281 * @tparam
282 * @param item - StationInfo &item
283 */
284 template <>
285 void ClearTClass<StationInfo>(StationInfo &item);
286
287 /**
288 * @Description Set StationInfo item data
289 *
290 * @tparam
291 * @param item - StationInfo &item
292 * @param key - StationInfo struct member name
293 * @param value - the StationInfo item member value
294 * @return int - parse error: 0 Success, >0 parse failed
295 */
296 template <>
297 int SetTClassKeyValue<StationInfo>(StationInfo &item, const std::string &key, const std::string &value);
298
299 /**
300 * @Description Output StationInfo class name
301 *
302 * @tparam
303 * @param item - StationInfo &item
304 * @return std::string - Class name
305 */
306 template <>
307 std::string GetTClassName<StationInfo>();
308
309 /**
310 * @Description Output the StationInfo item, format: item's member = the member value
311 *
312 * @tparam
313 * @param item - StationInfo &item
314 * @return std::string - output total member=value string about the StationInfo item
315 */
316 template <>
317 std::string OutTClassString<StationInfo>(StationInfo &item);
318
319 /**
320 * @Description Clear and init WifiConfig
321 *
322 * @tparam
323 * @param item - WifiConfig &item
324 */
325 template <>
326 void ClearTClass<WifiConfig>(WifiConfig &item);
327
328 /**
329 * @Description Set WifiConfig item data
330 *
331 * @tparam
332 * @param item - WifiConfig &item
333 * @param key - WifiConfig struct member name
334 * @param value - the WifiConfig item member value
335 * @return int - parse error: 0 Success, >0 parse failed
336 */
337 template <>
338 int SetTClassKeyValue<WifiConfig>(WifiConfig &item, const std::string &key, const std::string &value);
339
340 /**
341 * @Description Output WifiConfig class name
342 *
343 * @tparam
344 * @param item - WifiConfig &item
345 * @return std::string - Class name
346 */
347 template <>
348 std::string GetTClassName<WifiConfig>();
349
350 /**
351 * @Description Output the WifiConfig item, format: item's member = the member value
352 *
353 * @tparam
354 * @param item - WifiConfig &item
355 * @return std::string - output total member=value string about the WifiConfig item
356 */
357 template <>
358 std::string OutTClassString<WifiConfig>(WifiConfig &item);
359
360 /**
361 * @Description Clear and init WifiP2pGroupInfo
362 *
363 * @tparam
364 * @param item - WifiP2pGroupInfo item
365 */
366 template<>
367 void ClearTClass<WifiP2pGroupInfo>(WifiP2pGroupInfo &item);
368
369 /**
370 * @Description Set WifiP2pGroupInfo item data
371 *
372 * @tparam
373 * @param item - WifiP2pGroupInfo &item
374 * @param key - WifiP2pGroupInfo struct member name
375 * @param value - the WifiP2pGroupInfo item member value
376 * @return int - parse error: 0 Success, >0 parse failed
377 */
378 template<>
379 int SetTClassKeyValue<WifiP2pGroupInfo>(WifiP2pGroupInfo &item, const std::string &key, const std::string &value);
380
381 /**
382 * @Description Output WifiP2pGroupInfo class name
383 *
384 * @tparam
385 * @param item - WifiP2pGroupInfo &item
386 * @return std::string - Class name
387 */
388 template<>
389 std::string GetTClassName<WifiP2pGroupInfo>();
390
391 /**
392 * @Description Output the WifiP2pGroupInfo item, format: item's member = the member value
393 *
394 * @tparam
395 * @param item - WifiP2pGroupInfo &item
396 * @return std::string - output total member=value string about the WifiP2pGroupInfo item
397 */
398 template<>
399 std::string OutTClassString<WifiP2pGroupInfo>(WifiP2pGroupInfo &item);
400
401 /**
402 * @Description Clear and init TrustListPolicy
403 *
404 * @tparam
405 * @param item - TrustListPolicy &item
406 */
407 template <>
408 void ClearTClass<TrustListPolicy>(TrustListPolicy &item);
409
410 /**
411 * @Description Set TrustListPolicy item data
412 *
413 * @tparam
414 * @param item - TrustListPolicy &item
415 * @param key - TrustListPolicy struct member name
416 * @param value - the TrustListPolicy item member value
417 * @return int - parse error: 0 Success, >0 parse failed
418 */
419 template <>
420 int SetTClassKeyValue<TrustListPolicy>(TrustListPolicy &item, const std::string &key, const std::string &value);
421
422 /**
423 * @Description Output TrustListPolicy class name
424 *
425 * @tparam
426 * @param item - TrustListPolicy &item
427 * @return std::string - Class name
428 */
429 template <>
430 std::string GetTClassName<TrustListPolicy>();
431
432 /**
433 * @Description Output the TrustListPolicy item, format: item's member = the member value
434 *
435 * @tparam
436 * @param item - TrustListPolicy &item
437 * @return std::string - output total member=value string about the TrustListPolicy item
438 */
439 template <>
440 std::string OutTClassString<TrustListPolicy>(TrustListPolicy &item);
441
442 /**
443 * @Description Clear and init MovingFreezePolicy
444 *
445 * @tparam
446 * @param item - MovingFreezePolicy &item
447 */
448 template <>
449 void ClearTClass<MovingFreezePolicy>(MovingFreezePolicy &item);
450
451 /**
452 * @Description Set MovingFreezePolicy item data
453 *
454 * @tparam
455 * @param item - MovingFreezePolicy &item
456 * @param key - MovingFreezePolicy struct member name
457 * @param value - the MovingFreezePolicy item member value
458 * @return int - parse error: 0 Success, >0 parse failed
459 */
460 template <>
461 int SetTClassKeyValue<MovingFreezePolicy>(MovingFreezePolicy &item, const std::string &key, const std::string &value);
462
463 /**
464 * @Description Output MovingFreezePolicy class name
465 *
466 * @tparam
467 * @param item - MovingFreezePolicy &item
468 * @return std::string - Class name
469 */
470 template <>
471 std::string GetTClassName<MovingFreezePolicy>();
472
473 /**
474 * @Description Output the MovingFreezePolicy item, format: item's member = the member value
475 *
476 * @tparam
477 * @param item - MovingFreezePolicy &item
478 * @return std::string - output total member=value string about the MovingFreezePolicy item
479 */
480 template <>
481 std::string OutTClassString<MovingFreezePolicy>(MovingFreezePolicy &item);
482
483 /**
484 * @Description Clear and init WifiStoreRandomMac
485 *
486 * @tparam
487 * @param item - WifiStoreRandomMac &item
488 */
489 template <>
490 void ClearTClass<WifiStoreRandomMac>(WifiStoreRandomMac &item);
491
492 /**
493 * @Description Set WifiStoreRandomMac item data
494 *
495 * @tparam
496 * @param item - WifiStoreRandomMac &item
497 * @param key - WifiStoreRandomMac struct member name
498 * @param value - the WifiStoreRandomMac item member value
499 * @return int - parse error: 0 Success, >0 parse failed
500 */
501 template <>
502 int SetTClassKeyValue<WifiStoreRandomMac>(WifiStoreRandomMac &item, const std::string &key, const std::string &value);
503
504 /**
505 * @Description Output WifiStoreRandomMac class name
506 *
507 * @tparam
508 * @param item - WifiStoreRandomMac &item
509 * @return std::string - Class name
510 */
511 template <>
512 std::string GetTClassName<WifiStoreRandomMac>();
513
514 /**
515 * @Description Output the WifiStoreRandomMac item, format: item's member = the member value
516 *
517 * @tparam
518 * @param item - WifiStoreRandomMac &item
519 * @return std::string - output total member=value string about the WifiStoreRandomMac item
520 */
521 template <>
522 std::string OutTClassString<WifiStoreRandomMac>(WifiStoreRandomMac &item);
523 /* ----------template function specialization declare end----------- */
524 } // namespace Wifi
525 } // namespace OHOS
526 #endif
527