1 /**
2  * @file lv_xml_widget.c
3  *
4  */
5 
6 /*********************
7  *      INCLUDES
8  *********************/
9 #include "lv_xml_widget.h"
10 #include "lv_xml_parser.h"
11 #include "../../stdlib/lv_string.h"
12 #include "../../stdlib/lv_mem.h"
13 
14 #if LV_USE_XML
15 
16 /*********************
17  *      DEFINES
18  *********************/
19 
20 /**********************
21  *      TYPEDEFS
22  **********************/
23 
24 /**********************
25  *  STATIC PROTOTYPES
26  **********************/
27 
28 /**********************
29  *  STATIC VARIABLES
30  **********************/
31 static lv_widget_processor_t * widget_processor_head;
32 
33 /**********************
34  *      MACROS
35  **********************/
36 
37 /**********************
38  *   GLOBAL FUNCTIONS
39  **********************/
40 
lv_xml_widget_register(const char * name,lv_xml_widget_create_cb_t create_cb,lv_xml_widget_apply_cb_t apply_cb)41 lv_result_t lv_xml_widget_register(const char * name, lv_xml_widget_create_cb_t create_cb,
42                                    lv_xml_widget_apply_cb_t apply_cb)
43 {
44     lv_widget_processor_t * p = lv_malloc(sizeof(lv_widget_processor_t));
45     lv_memzero(p, sizeof(lv_widget_processor_t));
46 
47     p->name = lv_strdup(name);
48     p->create_cb = create_cb;
49     p->apply_cb = apply_cb;
50 
51     if(widget_processor_head == NULL) widget_processor_head = p;
52     else {
53         p->next = widget_processor_head;
54         widget_processor_head = p;
55     }
56     return LV_RESULT_OK;
57 }
58 
lv_xml_widget_get_processor(const char * name)59 lv_widget_processor_t * lv_xml_widget_get_processor(const char * name)
60 {
61     /* Select the widget specific parser type based on the name */
62     lv_widget_processor_t * p = widget_processor_head;
63     while(p) {
64         if(lv_streq(p->name, name)) {
65             return p;
66         }
67 
68         p = p->next;
69     }
70     return NULL;
71 }
72 
73 
74 /**********************
75  *   STATIC FUNCTIONS
76  **********************/
77 
78 #endif /* LV_USE_XML */
79