now *THIS* shoudl make tome happy. bilget - take a look - this does what you
authorCarsten Haitzler <raster@rasterman.com>
Wed, 14 Feb 2001 04:30:15 +0000 (04:30 +0000)
committerCarsten Haitzler <raster@rasterman.com>
Wed, 14 Feb 2001 04:30:15 +0000 (04:30 +0000)
want (ok - it gets it only if the value is stale for more than 5 seconds)
the comments say its waiting on efsd to be more solid and then i'll have a
set of config file monitoring flags that will state if the source db is
invalid and only then to getit - it still pretty much comes down to a compre
- branch and retrieve from ram operation per config value at the beginning
of a function. it's be good if you - instead of sahyin the design is HIT and
saying i cant desing - just point out somehting coudl be more optimized and
suggest things :) i dont deal well with peolep telling me shit is shite when
i'm not even done with it :)

SVN revision: 4204

src/e.h
src/menu.c
src/util.c

diff --git a/src/e.h b/src/e.h
index 7d20873..7ab690a 100644 (file)
--- a/src/e.h
+++ b/src/e.h
@@ -577,6 +577,7 @@ int e_file_cp(char *src, char *dst);
 char *e_file_real(char *file);
 char *e_file_get_file(char *file);
 char *e_file_get_dir(char *file);
+void *e_memdup(void *data, int size);
     
 void e_exec_set_args(int argc, char **argv);
 void e_exec_restart(void);
@@ -584,9 +585,114 @@ pid_t e_exec_run(char *exe);
 pid_t e_exec_run_in_dir(char *exe, char *dir);
 pid_t e_run_in_dir_with_env(char *exe, char *dir, int *launch_id_ret, char **env, char *launch_path);
     
+typedef struct _e_config_element E_Config_Element;
+struct _e_config_element 
+{
+   char *src;
+   char *key;
+   double last_fetch;
+   int   type;
+   int    def_int_val;
+   float  def_float_val;
+   char  *def_str_val;
+   void  *def_data_val;
+   int    def_data_val_size;
+   int    cur_int_val;
+   float  cur_float_val;
+   char  *cur_str_val;
+   void  *cur_data_val;
+   int    cur_data_val_size;
+};
+#define E_CFG_INT_T   123
+#define E_CFG_FLOAT_T 1234
+#define E_CFG_STR_T   12345
+#define E_CFG_DATA_T  123456
+#define E_CFG_INT(_var, _src, _key, _default) \
+static E_Config_Element _var = { _src, _key, 0.0, E_CFG_INT_T, \
+_default, 0.0, NULL, NULL, 0, \
+0, 0.0, NULL, NULL, 0, \
+}
+#define E_CFG_FLOAT(_var, _src, _key, _default) \
+static E_Config_Element _var = { _src, _key, 0.0, E_CFG_FLOAT_T, \
+0, _default, NULL, NULL, 0, \
+0, 0.0, NULL, NULL, 0, \
+}
+#define E_CFG_STR(_var, _src, _key, _default) \
+static E_Config_Element _var = { _src, _key, 0.0, E_CFG_STR_T, \
+0, 0.0, _default, NULL, 0, \
+0, 0.0, NULL, NULL, 0, \
+}
+#define E_CFG_DATA(_var, _src, _key, _default, _default_size) \
+static E_Config_Element _var = { _src, _key, 0.0, E_CFG_DATAT_T, \
+0, 0.0, NULL, _default, _default_size, \
+0, 0.0, NULL, NULL, 0, \
+}
+/* yes for now it only fetches them every 5 seconds - in the end i need a */
+/* validity flag for the database file to know if it changed and only then */
+/* get the value again. this is waiting for efsd to become more solid */
+#define E_CFG_VALIDITY_CHECK(_var) \
+{ \
+double __time; \
+__time = e_get_time(); \
+if (_var.last_fetch < (__time - 5.0)) { \
+int __cfg_ok = 0; \
+_var.last_fetch = __time;
+#define E_CFG_END_VALIDITY_CHECK \
+} \
+}
+
+#define E_CONFIG_INT_GET(_var, _val) \
+{{ \
+E_CFG_VALIDITY_CHECK(_var) \
+E_DB_INT_GET(e_config_get(_var.src), _var.key, _var.cur_int_val, __cfg_ok); \
+if (!__cfg_ok) _var.cur_int_val = _var.def_int_val; \
+E_CFG_END_VALIDITY_CHECK \
+} \
+_val = _var.cur_int_val;}
+#define E_CONFIG_FLOAT_GET(_var, _val) \
+{{ \
+E_CFG_VALIDITY_CHECK(_var) \
+E_DB_FLOAT_GET(e_config_get(_var.src), _var.key, _var.cur_float_val, __cfg_ok); \
+if (!__cfg_ok) _var.cur_float_val = _var.def_float_val; \
+E_CFG_END_VALIDITY_CHECK \
+} \
+_val = _var.cur_float_val;}
+#define E_CONFIG_STR_GET(_var, _val) \
+{{ \
+E_CFG_VALIDITY_CHECK(_var) \
+if (_var.cur_str_val) free(_var.cur_str_val); \
+_var.cur_str_val = NULL; \
+E_DB_STR_GET(e_config_get(_var.src), _var.key, _var.cur_str_val, __cfg_ok); \
+if (!__cfg_ok) _var.cur_str_val = _var.def_str_val \
+E_CFG_END_VALIDITY_CHECK \
+} \
+_val = _var.cur_str_val;}
+#define E_CONFIG_DATA_GET(_var, _val, _size) \
+{{ \
+E_CFG_VALIDITY_CHECK(_var) \
+if (_var.cur_data_val) free(_var.cur_data_val); \
+_var.cur_data_val = NULL; \
+_var.cur_data_size = 0; \
+{ E_DB_File *__db; \
+__db = e_db_open_read(e_config_get(_var.src)); \
+if (__db) { \
+_var.cur_data_val = e_db_data_get(__db, _var.key, &(_var.cur_data_size)); \
+if (_var.cur_data_val) __cfg_ok = 1; \
+e_db_close(__db); \
+} \
+} \
+if (!__cfg_ok) { \
+_var.cur_data_val = e_memdup(_var.def_data_val, _var.def_data_size); \
+_var.cur_data_size = _var.def_data_size; \
+} \
+E_CFG_END_VALIDITY_CHECK \
+} \
+_val = _var.cur_data_val; \
+_size = _var.cur_data_size;}
+
 char *e_config_get(char *type);
-void e_config_init(void);
-void e_config_set_user_dir(char *dir);
+void  e_config_init(void);
+void  e_config_set_user_dir(char *dir);
 char *e_config_user_dir(void);
 
 void e_view_free(E_View *v);
index f7aaaae..a35312a 100644 (file)
@@ -25,15 +25,16 @@ e_scroller_timer(int val, void *data)
    int ok = 0;
    int resist = 5;
    int scroll_speed = 12;
-   char *settings_db;
    static double last_time = 0.0;
    double t;
+   /* these two lines... */
+   E_CFG_INT(cfg_resist, "settings", "/menu/scroll/resist", 5);
+   E_CFG_INT(cfg_scroll_speed, "settings", "/menu/scroll/speed", 12);
+   
+   /* and these 2 should do exactly what tom wants - see e.h */
+   E_CONFIG_INT_GET(cfg_resist, resist);
+   E_CONFIG_INT_GET(cfg_scroll_speed, scroll_speed);
    
-   settings_db = e_config_get("settings");
-   ok = 0; E_DB_INT_GET(settings_db, "/menu/scroll/resist", resist, ok);
-   if (!ok) resist = 5;
-   ok = 0; E_DB_INT_GET(settings_db, "/menu/scroll/speed", scroll_speed, ok);
-   if (!ok) scroll_speed = 12;
    t = e_get_time();
    if (val != 0)
      scroll_speed = (int)(((t - last_time) / 0.02) * (double)scroll_speed);
index 952da38..070675e 100644 (file)
@@ -111,3 +111,14 @@ e_file_get_dir(char *file)
    *p = 0;
    return strdup(buf);
 }
+
+void *
+e_memdup(void *data, int size)
+{
+   void *data_dup;
+   
+   data_dup = malloc(size);
+   if (!data_dup) return NULL;
+   memcpy(data_dup, data, size);
+   return data_dup;
+}