init_db: exclude hal-release information from database
[platform/core/api/system-info.git] / tool / system-info-tool.h
1 #ifndef __SYSTEM_INFO_TOOL_H__
2 #define __SYSTEM_INFO_TOOL_H__
3
4 #include <unistd.h>
5 #include <stdlib.h>
6 #include <glib.h>
7
8 #include <system_info.h>
9 #include <system_info_type.h>
10 #include <system_info_private.h>
11
12 #define BUFFER_MAX              128
13
14 enum db_e {
15         DB_START = 0,
16         DB_DEFAULT_RO = DB_START,
17         DB_HAL_RO,
18         DB_DEFAULT_RW,
19         DB_END,
20 };
21
22 struct db {
23         const char *path;
24         const char *name;
25         const char ticker;
26 };
27 extern const struct db db[DB_END];
28
29 struct value {
30         system_info_type_e type;
31         union {
32                 bool b;
33                 int i;
34                 double d;
35                 char *s;
36         };
37 };
38
39 struct dbentry {
40         const struct db *db;
41         char tag[BUFFER_MAX];
42         char key[BUFFER_MAX];
43         struct value value;
44 };
45
46 extern int runtime_env;
47
48 static inline void fclosep(FILE **fp)
49 {
50         if (*fp)
51                 fclose(*fp);
52 }
53 #define __auto_fclose__ __attribute__((cleanup(fclosep)))
54
55 static inline void closep(int *fd)
56 {
57         if (*fd >= 0)
58                 close(*fd);
59 }
60 #define __auto_close__ __attribute__((cleanup(closep)))
61
62 static inline void free_value(struct value *v)
63 {
64         if (v->type == SYSTEM_INFO_STRING)
65                 free(v->s);
66 }
67 #define __auto_free_value__ __attribute__((cleanup(free_value)))
68
69 static inline void free_dbentry(struct dbentry *entry)
70 {
71         if (entry->value.type == SYSTEM_INFO_STRING)
72                 free(entry->value.s);
73 }
74 #define __auto_free_dbentry__ __attribute__((cleanup(free_dbentry)))
75
76
77 const char *type_to_string(system_info_type_e type);
78 system_info_type_e string_to_type(const char *type);
79 void print_value(struct value value);
80 int convert_raw_key(const char *key, char *buffer, int len);
81
82 #define SYSINFO_G_LIST_APPEND(a, b)        \
83         a = g_list_append(a, (gpointer)b)
84
85 #define SYSINFO_G_LIST_FOREACH(head, elem, node)   \
86         for (elem = head, node = NULL; \
87                 elem && ((node = elem->data) != NULL); \
88                 elem = elem->next, node = NULL)
89
90 #endif