summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Michael <cp.michael@samsung.com>2018-01-11 12:18:35 -0500
committerChris Michael <cp.michael@samsung.com>2018-01-11 12:18:35 -0500
commita335b89f206f6ec1fb9043465920ec87a264f69c (patch)
tree014dacf7516c4701059c67f397d904772786656c
parent7af99adfcaeb0127876c601a4792eefb22e39df6 (diff)
express: Start on config infrastructuredevs/devilhorns/refactor
Signed-off-by: Chris Michael <cp.michael@samsung.com>
-rw-r--r--src/bin/Makefile.am1
-rw-r--r--src/bin/config.c127
-rw-r--r--src/bin/private.h42
3 files changed, 170 insertions, 0 deletions
diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am
index 8dde623..903ab8c 100644
--- a/src/bin/Makefile.am
+++ b/src/bin/Makefile.am
@@ -18,6 +18,7 @@ EXPRESSHEADERS = \
18 18
19express_SOURCES = \ 19express_SOURCES = \
20 $(EXPRESSHEADERS) \ 20 $(EXPRESSHEADERS) \
21 config.c \
21 win.c \ 22 win.c \
22 main.c 23 main.c
23 24
diff --git a/src/bin/config.c b/src/bin/config.c
new file mode 100644
index 0000000..8fc64f0
--- /dev/null
+++ b/src/bin/config.c
@@ -0,0 +1,127 @@
1#include "private.h"
2
3#define EX_CONFIG_LIMIT(v, min, max) \
4 if (v > max) v = max; else if (v < min) v = min;
5
6#define EX_CONFIG_DD_NEW(str, typ) \
7 _cfg_descriptor_new(str, sizeof(typ))
8
9#define EX_CONFIG_DD_FREE(eed) \
10 if (eed) { eet_data_descriptor_free(eed); (eed) = NULL; }
11
12#define EX_CONFIG_VAL(edd, type, member, dtype) \
13 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, type, #member, member, dtype)
14
15#define EX_CONFIG_SUB(edd, type, member, eddtype) \
16 EET_DATA_DESCRIPTOR_ADD_SUB(edd, type, #member, member, eddtype)
17
18#define EX_CONFIG_LIST(edd, type, member, eddtype) \
19 EET_DATA_DESCRIPTOR_ADD_LIST(edd, type, #member, member, eddtype)
20
21#define EX_CONFIG_HASH(edd, type, member, eddtype) \
22 EET_DATA_DESCRIPTOR_ADD_HASH(edd, type, #member, member, eddtype)
23
24#define EX_CONFIG_FILE_EPOCH 0x0004
25#define EX_CONFIG_FILE_GENERATION 0x012d
26#define EX_CONFIG_FILE_VERSION \
27 ((EX_CONFIG_FILE_EPOCH << 16) | EX_CONFIG_FILE_GENERATION)
28
29typedef Eet_Data_Descriptor Ex_Config_DD;
30
31static Ex_Config_DD *_ex_cfg_edd = NULL;
32
33Config *_ex_cfg = NULL;
34
35static Ex_Config_DD *
36_cfg_descriptor_new(const char *name, int size)
37{
38 Eet_Data_Descriptor_Class eddc;
39
40 if (!eet_eina_stream_data_descriptor_class_set(&eddc, sizeof(eddc),
41 name, size))
42 return NULL;
43
44 return (Ex_Config_DD *)eet_data_descriptor_stream_new(&eddc);
45}
46
47static void
48_cfg_cb_free(void)
49{
50 free(_ex_cfg);
51 _ex_cfg = NULL;
52}
53
54static void *
55_cfg_domain_load(const char *domain, Ex_Config_DD *edd)
56{
57 if (!domain) return NULL;
58
59 return NULL;
60}
61
62static Eina_Bool
63_cfg_domain_save(const char *domain, Ex_Config_DD *edd, const void *data)
64{
65 Eet_File *ef;
66 char buff[PATH_MAX];
67 const char *userdir;
68
69 if (!domain) return 0;
70 /* TODO */
71 /* userdir = _util_user_dir_get(); */
72 snprintf(buff, sizeof(buff), "%s/", userdir);
73 if (!ecore_file_exists(buff)) ecore_file_mkpath(buff);
74 snprintf(buff, sizeof(buff), "%s/%s.tmp", userdir, domain);
75 ef = eet_open(buff, EET_FILE_MODE_WRITE);
76 if (ef)
77 {
78 char buff2[PATH_MAX];
79
80 snprintf(buff2, sizeof(buff2), "%s/%s.cfg", userdir, domain);
81 if (!eet_data_write(ef, edd, "config", data, 1))
82 {
83 eet_close(ef);
84 return EINA_FALSE;
85 }
86
87 if (eet_close(ef) > 0) return EINA_FALSE;
88 if (!ecore_file_mv(buff, buff2)) return EINA_FALSE;
89 return EINA_TRUE;
90 }
91
92 return EINA_FALSE;
93}
94
95Eina_Bool
96_cfg_init(void)
97{
98 return EINA_TRUE;
99}
100
101Eina_Bool
102_cfg_shutdown(void)
103{
104 _cfg_cb_free();
105
106 EX_CONFIG_DD_FREE(_ex_cfg_edd);
107
108 return EINA_TRUE;
109}
110
111Eina_Bool
112_cfg_load(void)
113{
114 _ex_cfg = _cfg_domain_load(PACKAGE_NAME, _ex_cfg_edd);
115 if (_ex_cfg)
116 {
117
118 }
119
120 return EINA_TRUE;
121}
122
123Eina_Bool
124_cfg_save(void)
125{
126 return _cfg_domain_save(PACKAGE_NAME, _ex_cfg_edd, _ex_cfg);
127}
diff --git a/src/bin/private.h b/src/bin/private.h
index 9147394..1cbe715 100644
--- a/src/bin/private.h
+++ b/src/bin/private.h
@@ -50,7 +50,49 @@ extern int _log_dom;
50 50
51typedef struct _Window Window; 51typedef struct _Window Window;
52 52
53typedef struct _Config_Channel
54{
55 const char *name, *pass;
56} Config_Channel;
57
58typedef struct _Config_Server
59{
60 int port;
61 const char *name;
62} Config_Server;
63
64typedef struct _Config_Network
65{
66 const char *name;
67
68 const char *nickname;
69 const char *username;
70
71 const char *nickpwd;
72 const char *serverpwd;
73
74 Eina_List *servers, *channels;
75
76 Eina_Bool autoconnect : 1;
77 Eina_Bool bypass_proxy : 1;
78 Eina_Bool use_ssl : 1;
79} Config_Network;
80
81typedef struct _Config
82{
83 int version;
84
85 Eina_List *networks;
86} Config;
87
88extern Config *_ex_cfg;
89
53Eina_Bool _win_create(void); 90Eina_Bool _win_create(void);
54Eina_Bool _win_destroy(void); 91Eina_Bool _win_destroy(void);
55 92
93Eina_Bool _cfg_init(void);
94Eina_Bool _cfg_shutdown(void);
95Eina_Bool _cfg_load(void);
96Eina_Bool _cfg_save(void);
97
56#endif 98#endif