1 /*
2  * Copyright (c) 2006-2021, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2021-09-02     WillianChan  add var_export example code
9  */
10 
11 #include <var_export.h>
12 
13 /* use VAR_EXPOR() to export 10 pieces of data into sections */
14 VAR_EXPORT(module0, identi0, 0);
15 VAR_EXPORT(module1, identi1, 1);
16 VAR_EXPORT(module2, identi2, 2);
17 VAR_EXPORT(module3, identi3, 3);
18 VAR_EXPORT(module4, identi4, 4);
19 VAR_EXPORT(module5, identi5, 5);
20 VAR_EXPORT(module6, identi6, 6);
21 VAR_EXPORT(module7, identi7, 7);
22 VAR_EXPORT(module8, identi8, 8);
23 VAR_EXPORT(module9, identi9, 9);
24 
found_by_module(void)25 void found_by_module(void)
26 {
27     ve_iterator_t iter;
28     const ve_exporter_t* exporter;
29     ve_module_t module;
30     rt_base_t value;
31 
32     /* query all exporters with the same name as module1 */
33     if (!ve_module_init(&module, "module1"))
34         /* initialize the iterator */
35         ve_iter_init(&module, &iter);
36     else
37         return;
38 
39     while (1)
40     {
41         /* start iterating */
42         exporter = ve_iter_next(&iter);
43         if (exporter == RT_NULL)
44             break;
45         else
46         {
47             /* checks whether the value exists */
48             if (ve_value_exist(&module, "identi1") == RT_TRUE)
49             {
50                 value = ve_value_get(&module, "identi1");
51                 rt_kprintf("[ve_example] value = %dn", value);
52                 return;
53             }
54             else
55             {
56                 rt_kprintf("[ve_example] value not exist.\n");
57                 return;
58             }
59         }
60     }
61 }
62 #ifdef RT_USING_FINSH
63 #include <finsh.h>
64 MSH_CMD_EXPORT(found_by_module, found by module);
65 #endif /* RT_USING_FINSH */