Golem  v0.1.1
Generic Operating system Libraries for Embedded Multitasking
 All Data Structures Files Functions Variables Pages
example_glm_list.c
1 /*
2  * Example using glm_list.h in combination with glm_object.h
3  *
4  * This example assumes the caller has already created an object using
5  * malloc() or equivalent for adding to the list named 'my_obj' in this
6  * example. It is also assumed that the caller has already obtained a
7  * heap-ID (using glm_heap.h) named 'my_heap_id' in this example.
8  * which is named
9  */
10 
11 #include "glm_list.h"
12 
13 // Declare and initialize the required pointer-variables
14 list_t * my_list = NULL;
15 list_item_t * my_item = NULL;
16 
17 typedef struct
18 {
19  char *firstname;
20  char *lastname;
21 } my_object_t;
22 
23 // Create an instance of the list to which we want add my_obj and maybe other
24 // objects.
25 my_list = list_create(heap_id);
26 
27 // Proceed if successful
28 if (NULL != my_list)
29 {
30  // Create an object using Golem's heap functionality
31  my_object = heap_malloc(heap_id, sizeof(my_object_t));
32 
33  // Now create a new list item holding the alarm
34  my_item = list_item_create(my_list, (void* my_object));
35 
36  // Proceed if successful
37  if (NULL != my_item)
38  {
39  // Append object to the list
40  my_item = list_append(my_list, my_item);
41  }
42 }
43