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 #ifndef OHOS_ARCH_LITE
142 /**
143  * @Description Clear and init WifiBackupConfig
144  *
145  * @tparam
146  * @param item - WifiBackupConfig item
147  */
148 template <>
149 void ClearTClass<WifiBackupConfig>(WifiBackupConfig &item);
150 
151 /**
152  * @Description Set WifiBackupConfig item data
153  *
154  * @tparam
155  * @param item - WifiBackupConfig &item
156  * @param key - WifiBackupConfig struct member name
157  * @param value - the WifiBackupConfig item member value
158  * @return int - parse error: 0 Success, >0 parse failed
159  */
160 template <>
161 int SetTClassKeyValue<WifiBackupConfig>(WifiBackupConfig &item, const std::string &key, const std::string &value);
162 
163 /**
164  * @Description Output WifiBackupConfig class name
165  *
166  * @tparam
167  * @param item - WifiBackupConfig &item
168  * @return std::string - Class name
169  */
170 template <>
171 std::string GetTClassName<WifiBackupConfig>();
172 
173 /**
174  * @Description Output the WifiBackupConfig item, format: item's member = the member value
175  *
176  * @tparam
177  * @param item - WifiBackupConfig &item
178  * @return std::string - output total member=value string about the WifiBackupConfig item
179  */
180 template <>
181 std::string OutTClassString<WifiBackupConfig>(WifiBackupConfig &item);
182 #endif
183 
184 /**
185  * @Description Clear and init HotspotConfig
186  *
187  * @tparam
188  * @param item - HotspotConfig item
189  */
190 template <>
191 void ClearTClass<HotspotConfig>(HotspotConfig &item);
192 
193 /**
194  * @Description Set HotspotConfig item data
195  *
196  * @tparam
197  * @param item - HotspotConfig &item
198  * @param key - HotspotConfig struct member name
199  * @param value - the HotspotConfig item member value
200  * @return int - parse error: 0 Success, >0 parse failed
201  */
202 template <>
203 int SetTClassKeyValue<HotspotConfig>(HotspotConfig &item, const std::string &key, const std::string &value);
204 
205 /**
206  * @Description Output HotspotConfig class name
207  *
208  * @tparam
209  * @param item - HotspotConfig &item
210  * @return std::string - Class name
211  */
212 template <>
213 std::string GetTClassName<HotspotConfig>();
214 
215 /**
216  * @Description Output the HotspotConfig item, format: item's member = the member value
217  *
218  * @tparam
219  * @param item - HotspotConfig &item
220  * @return std::string - output total member=value string about the HotspotConfig item
221  */
222 template <>
223 std::string OutTClassString<HotspotConfig>(HotspotConfig &item);
224 
225 /**
226  * @Description Clear and init P2pVendorConfig
227  *
228  * @tparam
229  * @param item - P2pVendorConfig &item
230  */
231 template<>
232 void ClearTClass<P2pVendorConfig>(P2pVendorConfig &item);
233 
234 /**
235  * @Description Set P2pVendorConfig item data
236  *
237  * @tparam
238  * @param item - P2pVendorConfig &item
239  * @param key - P2pVendorConfig struct member name
240  * @param value - the P2pVendorConfig item member value
241  * @return int - parse error: 0 Success, >0 parse failed
242  */
243 template<>
244 int SetTClassKeyValue<P2pVendorConfig>(P2pVendorConfig &item, const std::string &key, const std::string &value);
245 
246 /**
247  * @Description Output P2pVendorConfig class name
248  *
249  * @tparam
250  * @param item - P2pVendorConfig &item
251  * @return std::string - Class name
252  */
253 template<>
254 std::string GetTClassName<P2pVendorConfig>();
255 
256 /**
257  * @Description Output the P2pVendorConfig item, format: item's member = the member value
258  *
259  * @tparam
260  * @param item - P2pVendorConfig &item
261  * @return std::string - output total member=value string about the P2pVendorConfig item
262  */
263 template<>
264 std::string OutTClassString<P2pVendorConfig>(P2pVendorConfig &item);
265 
266 /**
267  * @Description Clear and init StationInfo
268  *
269  * @tparam
270  * @param item - StationInfo &item
271  */
272 template <>
273 void ClearTClass<StationInfo>(StationInfo &item);
274 
275 /**
276  * @Description Set StationInfo item data
277  *
278  * @tparam
279  * @param item - StationInfo &item
280  * @param key - StationInfo struct member name
281  * @param value - the StationInfo item member value
282  * @return int - parse error: 0 Success, >0 parse failed
283  */
284 template <>
285 int SetTClassKeyValue<StationInfo>(StationInfo &item, const std::string &key, const std::string &value);
286 
287 /**
288  * @Description Output StationInfo class name
289  *
290  * @tparam
291  * @param item - StationInfo &item
292  * @return std::string - Class name
293  */
294 template <>
295 std::string GetTClassName<StationInfo>();
296 
297 /**
298  * @Description Output the StationInfo item, format: item's member = the member value
299  *
300  * @tparam
301  * @param item - StationInfo &item
302  * @return std::string - output total member=value string about the StationInfo item
303  */
304 template <>
305 std::string OutTClassString<StationInfo>(StationInfo &item);
306 
307 /**
308  * @Description Clear and init WifiConfig
309  *
310  * @tparam
311  * @param item - WifiConfig &item
312  */
313 template <>
314 void ClearTClass<WifiConfig>(WifiConfig &item);
315 
316 /**
317  * @Description Set WifiConfig item data
318  *
319  * @tparam
320  * @param item - WifiConfig &item
321  * @param key - WifiConfig struct member name
322  * @param value - the WifiConfig item member value
323  * @return int - parse error: 0 Success, >0 parse failed
324  */
325 template <>
326 int SetTClassKeyValue<WifiConfig>(WifiConfig &item, const std::string &key, const std::string &value);
327 
328 /**
329  * @Description Output WifiConfig class name
330  *
331  * @tparam
332  * @param item - WifiConfig &item
333  * @return std::string - Class name
334  */
335 template <>
336 std::string GetTClassName<WifiConfig>();
337 
338 /**
339  * @Description Output the WifiConfig item, format: item's member = the member value
340  *
341  * @tparam
342  * @param item - WifiConfig &item
343  * @return std::string - output total member=value string about the WifiConfig item
344  */
345 template <>
346 std::string OutTClassString<WifiConfig>(WifiConfig &item);
347 
348 /**
349  * @Description Clear and init WifiP2pGroupInfo
350  *
351  * @tparam
352  * @param item - WifiP2pGroupInfo item
353  */
354 template<>
355 void ClearTClass<WifiP2pGroupInfo>(WifiP2pGroupInfo &item);
356 
357 /**
358  * @Description Set WifiP2pGroupInfo item data
359  *
360  * @tparam
361  * @param item - WifiP2pGroupInfo &item
362  * @param key - WifiP2pGroupInfo struct member name
363  * @param value - the WifiP2pGroupInfo item member value
364  * @return int - parse error: 0 Success, >0 parse failed
365  */
366 template<>
367 int SetTClassKeyValue<WifiP2pGroupInfo>(WifiP2pGroupInfo &item, const std::string &key, const std::string &value);
368 
369 /**
370  * @Description Output WifiP2pGroupInfo class name
371  *
372  * @tparam
373  * @param item - WifiP2pGroupInfo &item
374  * @return std::string - Class name
375  */
376 template<>
377 std::string GetTClassName<WifiP2pGroupInfo>();
378 
379 /**
380  * @Description Output the WifiP2pGroupInfo item, format: item's member = the member value
381  *
382  * @tparam
383  * @param item - WifiP2pGroupInfo &item
384  * @return std::string - output total member=value string about the WifiP2pGroupInfo item
385  */
386 template<>
387 std::string OutTClassString<WifiP2pGroupInfo>(WifiP2pGroupInfo &item);
388 
389 /**
390  * @Description Clear and init TrustListPolicy
391  *
392  * @tparam
393  * @param item - TrustListPolicy &item
394  */
395 template <>
396 void ClearTClass<TrustListPolicy>(TrustListPolicy &item);
397 
398 /**
399  * @Description Set TrustListPolicy item data
400  *
401  * @tparam
402  * @param item - TrustListPolicy &item
403  * @param key - TrustListPolicy struct member name
404  * @param value - the TrustListPolicy item member value
405  * @return int - parse error: 0 Success, >0 parse failed
406  */
407 template <>
408 int SetTClassKeyValue<TrustListPolicy>(TrustListPolicy &item, const std::string &key, const std::string &value);
409 
410 /**
411  * @Description Output TrustListPolicy class name
412  *
413  * @tparam
414  * @param item - TrustListPolicy &item
415  * @return std::string - Class name
416  */
417 template <>
418 std::string GetTClassName<TrustListPolicy>();
419 
420 /**
421  * @Description Output the TrustListPolicy item, format: item's member = the member value
422  *
423  * @tparam
424  * @param item - TrustListPolicy &item
425  * @return std::string - output total member=value string about the TrustListPolicy item
426  */
427 template <>
428 std::string OutTClassString<TrustListPolicy>(TrustListPolicy &item);
429 
430 /**
431  * @Description Clear and init MovingFreezePolicy
432  *
433  * @tparam
434  * @param item - MovingFreezePolicy &item
435  */
436 template <>
437 void ClearTClass<MovingFreezePolicy>(MovingFreezePolicy &item);
438 
439 /**
440  * @Description Set MovingFreezePolicy item data
441  *
442  * @tparam
443  * @param item - MovingFreezePolicy &item
444  * @param key - MovingFreezePolicy struct member name
445  * @param value - the MovingFreezePolicy item member value
446  * @return int - parse error: 0 Success, >0 parse failed
447  */
448 template <>
449 int SetTClassKeyValue<MovingFreezePolicy>(MovingFreezePolicy &item, const std::string &key, const std::string &value);
450 
451 /**
452  * @Description Output MovingFreezePolicy class name
453  *
454  * @tparam
455  * @param item - MovingFreezePolicy &item
456  * @return std::string - Class name
457  */
458 template <>
459 std::string GetTClassName<MovingFreezePolicy>();
460 
461 /**
462  * @Description Output the MovingFreezePolicy item, format: item's member = the member value
463  *
464  * @tparam
465  * @param item - MovingFreezePolicy &item
466  * @return std::string - output total member=value string about the MovingFreezePolicy item
467  */
468 template <>
469 std::string OutTClassString<MovingFreezePolicy>(MovingFreezePolicy &item);
470 
471 /**
472  * @Description Clear and init WifiStoreRandomMac
473  *
474  * @tparam
475  * @param item - WifiStoreRandomMac &item
476  */
477 template <>
478 void ClearTClass<WifiStoreRandomMac>(WifiStoreRandomMac &item);
479 
480 /**
481  * @Description Set WifiStoreRandomMac item data
482  *
483  * @tparam
484  * @param item - WifiStoreRandomMac &item
485  * @param key - WifiStoreRandomMac struct member name
486  * @param value - the WifiStoreRandomMac item member value
487  * @return int - parse error: 0 Success, >0 parse failed
488  */
489 template <>
490 int SetTClassKeyValue<WifiStoreRandomMac>(WifiStoreRandomMac &item, const std::string &key, const std::string &value);
491 
492 /**
493  * @Description Output WifiStoreRandomMac class name
494  *
495  * @tparam
496  * @param item - WifiStoreRandomMac &item
497  * @return std::string - Class name
498  */
499 template <>
500 std::string GetTClassName<WifiStoreRandomMac>();
501 
502 /**
503  * @Description Output the WifiStoreRandomMac item, format: item's member = the member value
504  *
505  * @tparam
506  * @param item - WifiStoreRandomMac &item
507  * @return std::string - output total member=value string about the WifiStoreRandomMac item
508  */
509 template <>
510 std::string OutTClassString<WifiStoreRandomMac>(WifiStoreRandomMac &item);
511 
512 /**
513  * @Description Clear and init PackageFilterConf
514  *
515  * @tparam
516  * @param item - PackageFilterConf &item
517  */
518 template <>
519 void ClearTClass<PackageFilterConf>(PackageFilterConf &item);
520 
521 /**
522  * @Description Clear and init VariableConf
523  *
524  * @tparam
525  * @param item - VariableConf &item
526  */
527 template <>
528 void ClearTClass<VariableConf>(VariableConf &item);
529 
530 /**
531  * @Description Set PackageFilterConf item data
532  *
533  * @tparam
534  * @param item - PackageFilterConf &item
535  * @param key - PackageFilterConf struct member name
536  * @param value - the PackageFilterConf item member value
537  * @return int - parse error: 0 Success, >0 parse failed
538  */
539 template <>
540 int SetTClassKeyValue<PackageFilterConf>(PackageFilterConf &item, const std::string &key, const std::string &value);
541 
542 /**
543  * @Description Set VariableConf item data
544  *
545  * @tparam
546  * @param item - VariableConf &item
547  * @param key - VariableConf struct member name
548  * @param value - the VariableConf item member value
549  * @return int - parse error: 0 Success, >0 parse failed
550  */
551 template <>
552 int SetTClassKeyValue<VariableConf>(VariableConf &item, const std::string &key, const std::string &value);
553 /* ----------template function specialization declare end----------- */
554 }  // namespace Wifi
555 }  // namespace OHOS
556 #endif
557