ecore_config now formats like most of the rest of ecore!!!

and - errr - handy - need to talk to you about function call names, and the
use of "long's"

:)


SVN revision: 10112
This commit is contained in:
Carsten Haitzler 2004-05-08 03:10:45 +00:00
parent a3f6222d01
commit 20df203105
9 changed files with 3104 additions and 2098 deletions

View File

@ -5,10 +5,6 @@
* @file * @file
* @brief Provides the Enlightened Property Library. * @brief Provides the Enlightened Property Library.
* *
* The Enlightened Property Library (Ecore_Config) is an adbstraction from the
* complexities of writing your own configuration. It provides many features
* using the Enlightenment 17 development libraries.
*
* This file provies all headers and structs for use with Ecore_Config. * This file provies all headers and structs for use with Ecore_Config.
* Using individual header files should not be necessary. * Using individual header files should not be necessary.
*/ */
@ -41,137 +37,168 @@
/* structures */ /* structures */
typedef enum Ecore_Config_Type { /**
PT_NIL=0, * Valid configuration property types.
PT_INT=1, */
PT_FLT=2, typedef enum Ecore_Config_Type
PT_STR=3, {
PT_RGB=4, PT_NIL = 0, ///< Property with no value.
PT_THM=5 PT_INT = 1, ///< Integer property type.
PT_FLT = 2, ///< Float property type.
PT_STR = 3, ///< String property type.
PT_RGB = 4, ///< Colour property type.
PT_THM = 5 ///< Theme property type.
} Ecore_Config_Type; } Ecore_Config_Type;
typedef enum Ecore_Config_Flag
{
typedef enum Ecore_Config_Flag { PF_NONE = 0,
PF_NONE=0, PF_BOUNDS = 1,
PF_BOUNDS=1, PF_MODIFIED = 2,
PF_MODIFIED=2, PF_SYSTEM = 4
PF_SYSTEM=4
} Ecore_Config_Flag; } Ecore_Config_Flag;
/**
* Property change callback function prototype.
*/
typedef int (*Ecore_Config_Listener) (const char *key,
const Ecore_Config_Type type,
const int tag, void *data);
typedef struct Ecore_Config_Listener_List
typedef int (*Ecore_Config_Listener)(const char *key,const Ecore_Config_Type type,const int tag,void *data); {
typedef struct Ecore_Config_Listener_List {
Ecore_Config_Listener listener; Ecore_Config_Listener listener;
const char *name; const char *name;
void *data; void *data;
int tag; int tag;
struct Ecore_Config_Listener_List *next; } Ecore_Config_Listener_List; struct Ecore_Config_Listener_List *next;
} Ecore_Config_Listener_List;
/** /**
* The actual property for storing a key-value pair. * The actual property for storing a key-value pair.
*/ */
typedef struct Ecore_Config_Prop { typedef struct Ecore_Config_Prop
char *key; {
char *description; char *key; ///< Property key.
char *description; ///< Description set by ecore_config_descibe.
char short_opt; char short_opt;
char *long_opt; char *long_opt;
char *ptr; char *ptr; ///< Used as the value when the property is a string or theme.
Ecore_Config_Type type; Ecore_Config_Type type; ///< Property type.
long val,lo,hi,step; long val; ///< Used as the value when the property is an integer, float or colour.
Ecore_Config_Flag flags; long lo; ///< Lower bound for the value when the property is an integer or float.
Ecore_Config_Listener_List *listeners; long hi; ///< Higher bound for the value when the property is an integer or float.
void *data; long step; ///< Increment for the value when the property is an integer or float.
struct Ecore_Config_Prop *next; /**< pointer to the next property in the list */ Ecore_Config_Flag flags; /// < Configuration flags.
} Ecore_Config_Prop; Ecore_Config_Listener_List *listeners; ///< List of change listeners.
void *data; /// < Stores extra data for the property.
struct Ecore_Config_Prop *next; ///< Pointer to the next property in the list.
} Ecore_Config_Prop;
/** /*
* A container for a list of properties. Provided so that an application can * A container for a list of properties. Provided so that an
* use different set of properties at any time. This is useful for multiple * application can use different set of properties at any time. This
* window support. * is useful for multiple window support.
*/ */
typedef struct Ecore_Config_Bundle { typedef struct Ecore_Config_Bundle
char *identifier; /**< identifier for this set of properties (window ID for example) */ {
char *owner; /**< this is used to store the application name related to the bundle */ char *identifier; ///< Identifier for this set of properties (window ID for example)
long serial; /**< unique identifier to identify bundle */ char *owner; ///< This is used to store the application name related to the bundle
Ecore_Config_Prop *data; /**< pointer to root of property list */ long serial; ///< Unique identifier to identify bundle
void *user_data; /**< app specific pointer to "other data" */ Ecore_Config_Prop *data; ///< Pointer to root of property list
struct Ecore_Config_Bundle *next; /**< pointer to next bundle in this application */ void *user_data; ///< App specific pointer to "other data"
} Ecore_Config_Bundle; struct Ecore_Config_Bundle *next; ///< Pointer to next bundle in this application
} Ecore_Config_Bundle;
typedef struct Ecore_Config_Server { typedef struct Ecore_Config_Server
{
void *server; void *server;
char *name; char *name;
Ecore_Config_Bundle *bundles; /* data anchor */ Ecore_Config_Bundle *bundles; /* data anchor */
struct Ecore_Config_Server *next; } Ecore_Config_Server; struct Ecore_Config_Server *next;
} Ecore_Config_Server;
# ifdef __cplusplus # ifdef __cplusplus
extern "C" { extern "C"
{
# endif # endif
/* global ptrs to save passing them through the API */ /* global ptrs to save passing them through the API */
extern Ecore_Config_Server *__ecore_config_server_global; extern Ecore_Config_Server *__ecore_config_server_global;
extern Ecore_Config_Server *__ecore_config_server_local; extern Ecore_Config_Server *__ecore_config_server_local;
extern Ecore_Config_Bundle *__ecore_config_bundle_local; extern Ecore_Config_Bundle *__ecore_config_bundle_local;
extern char *__ecore_config_app_name; extern char *__ecore_config_app_name;
Ecore_Config_Prop *ecore_config_get(const char *key); Ecore_Config_Prop *ecore_config_get(const char *key);
const char *ecore_config_get_type(const Ecore_Config_Prop *e); const char *ecore_config_get_type(const Ecore_Config_Prop * e);
void *ecore_config_get_data(const char *key); void *ecore_config_get_data(const char *key);
char *ecore_config_get_string(const char *key); char *ecore_config_get_string(const char *key);
long ecore_config_get_int(const char *key); long ecore_config_get_int(const char *key);
int ecore_config_get_rgb(const char *key,int *r, int *g, int *b); int ecore_config_get_rgb(const char *key, int *r, int *g,
float ecore_config_get_float(const char *key); int *b);
char *ecore_config_get_theme(const char *key); float ecore_config_get_float(const char *key);
char *ecore_config_get_as_string(const char *key); char *ecore_config_get_theme(const char *key);
int ecore_config_describe(const char *key, char *desc); char *ecore_config_get_as_string(const char *key);
int ecore_config_set_short_opt(const char *key, char short_opt); int ecore_config_describe(const char *key, char *desc);
int ecore_config_set_long_opt(const char *key, char *long_opt); int ecore_config_set_short_opt(const char *key,
int ecore_config_set(const char *key,char *val); char short_opt);
int ecore_config_set_typed(const char *key,void *val,int type); int ecore_config_set_long_opt(const char *key,
int ecore_config_set_string(const char *key,char *val); char *long_opt);
int ecore_config_set_int(const char *key,int val); int ecore_config_set(const char *key, char *val);
int ecore_config_set_rgb(const char *key,char *val); int ecore_config_set_typed(const char *key, void *val,
char *ecore_config_get_rgbstr(const char *key); int type);
int ecore_config_set_float(const char *key,float val); int ecore_config_set_string(const char *key, char *val);
int ecore_config_set_theme(const char *key,char *val); int ecore_config_set_int(const char *key, int val);
int ecore_config_set_theme_preview_group(const char *key, char *group); int ecore_config_set_rgb(const char *key, char *val);
int ecore_config_set_as_string(const char *key,char *val); char *ecore_config_get_rgbstr(const char *key);
int ecore_config_set_float(const char *key, float val);
int ecore_config_set_theme(const char *key, char *val);
int ecore_config_set_theme_preview_group(const char *key,
char *group);
int ecore_config_set_as_string(const char *key, char *val);
int ecore_config_default(const char *key,char *val,float lo,float hi,float step); int ecore_config_default(const char *key, char *val,
int ecore_config_default_typed(const char *key,void *val,int type); float lo, float hi, float step);
int ecore_config_default_int(const char *key,int val); int ecore_config_default_typed(const char *key, void *val,
int ecore_config_default_int_bound(const char *key,int val,int lo,int hi,int step); int type);
int ecore_config_default_string(const char *key,char *val); int ecore_config_default_int(const char *key, int val);
int ecore_config_default_float(const char *key,float val); int ecore_config_default_int_bound(const char *key, int val,
int ecore_config_default_float_bound(const char *key,float val,float lo,float hi,float step); int lo, int hi, int step);
int ecore_config_default_rgb(const char *key,char *val); int ecore_config_default_string(const char *key, char *val);
int ecore_config_default_theme(const char *key,char *val); int ecore_config_default_float(const char *key, float val);
int ecore_config_default_float_bound(const char *key,
float val, float lo,
float hi, float step);
int ecore_config_default_rgb(const char *key, char *val);
int ecore_config_default_theme(const char *key, char *val);
int ecore_config_listen(const char *name,const char *key,Ecore_Config_Listener listener,int tag,void *data); int ecore_config_listen(const char *name, const char *key,
int ecore_config_deaf(const char *name,const char *key,Ecore_Config_Listener listener); Ecore_Config_Listener listener,
Ecore_Config_Prop *ecore_config_dst(Ecore_Config_Prop *e); int tag, void *data);
int ecore_config_guess_type(const char *key, char *val); int ecore_config_deaf(const char *name, const char *key,
Ecore_Config_Listener listener);
Ecore_Config_Prop *ecore_config_dst(Ecore_Config_Prop * e);
int ecore_config_guess_type(const char *key, char *val);
Ecore_Config_Bundle *ecore_config_bundle_new(Ecore_Config_Server *srv, const char *id); Ecore_Config_Bundle *ecore_config_bundle_new(Ecore_Config_Server * srv,
Ecore_Config_Bundle *ecore_config_bundle_get_1st(Ecore_Config_Server *srv); const char *id);
Ecore_Config_Bundle *ecore_config_bundle_get_next(Ecore_Config_Bundle *ns); Ecore_Config_Bundle *ecore_config_bundle_get_1st(Ecore_Config_Server * srv);
Ecore_Config_Bundle *ecore_config_bundle_get_by_serial(Ecore_Config_Server *srv, long serial); Ecore_Config_Bundle *ecore_config_bundle_get_next(Ecore_Config_Bundle * ns);
Ecore_Config_Bundle *ecore_config_bundle_get_by_label(Ecore_Config_Server *srv, const char *label); Ecore_Config_Bundle *ecore_config_bundle_get_by_serial(Ecore_Config_Server *
long ecore_config_bundle_get_serial(Ecore_Config_Bundle *ns); srv, long serial);
char *ecore_config_bundle_get_label(Ecore_Config_Bundle *ns); Ecore_Config_Bundle *ecore_config_bundle_get_by_label(Ecore_Config_Server *
srv,
const char *label);
long ecore_config_bundle_get_serial(Ecore_Config_Bundle * ns);
char *ecore_config_bundle_get_label(Ecore_Config_Bundle * ns);
int ecore_config_init(char *name);
int ecore_config_shutdown(void);
int ecore_config_init(char *name); int ecore_config_load(void);
int ecore_config_shutdown(void); int ecore_config_load_file(char *file);
int ecore_config_save(void);
int ecore_config_load(void); int ecore_config_save_file(char *file);
int ecore_config_load_file(char *file);
int ecore_config_save(void);
int ecore_config_save_file(char *file);
/* error codes */ /* error codes */
# define ECORE_CONFIG_ERR_NOTSUPP (-16) # define ECORE_CONFIG_ERR_NOTSUPP (-16)
@ -185,33 +212,55 @@ int ecore_config_save_file(char *file);
# define ECORE_CONFIG_ERR_PATHEX (-8) # define ECORE_CONFIG_ERR_PATHEX (-8)
# define ECORE_CONFIG_ERR_TYPEMISMATCH (-7) # define ECORE_CONFIG_ERR_TYPEMISMATCH (-7)
# define ECORE_CONFIG_ERR_MUTEX (-6) # define ECORE_CONFIG_ERR_MUTEX (-6)
# define ECORE_CONFIG_ERR_NOTFOUND (-5) # define ECORE_CONFIG_ERR_NOTFOUND (-5) ///< Error indicating that the item searched for could not be found.
# define ECORE_CONFIG_ERR_OOM (-4) # define ECORE_CONFIG_ERR_OOM (-4) ///< Error given when the program runs out of memory.
# define ECORE_CONFIG_ERR_IGNORED (-3) # define ECORE_CONFIG_ERR_IGNORED (-3) ///< Error occurred, but was ignored.
# define ECORE_CONFIG_ERR_NODATA (-2) # define ECORE_CONFIG_ERR_NODATA (-2) ///< Error given when necessary data is not provided.
# define ECORE_CONFIG_ERR_FAIL (-1) # define ECORE_CONFIG_ERR_FAIL (-1) ///< Failure result.
# define ECORE_CONFIG_ERR_SUCC (0) # define ECORE_CONFIG_ERR_SUCC (0) ///< Success result.
# define ECORE_CONFIG_PARSE_HELP (-2) # define ECORE_CONFIG_PARSE_HELP (-2)
# define ECORE_CONFIG_PARSE_EXIT (-1) # define ECORE_CONFIG_PARSE_EXIT (-1)
# define ECORE_CONFIG_PARSE_CONTINUE (0) # define ECORE_CONFIG_PARSE_CONTINUE (0)
/* convenience mathods in convenience.c */ /* convenience mathods in convenience.c */
int ecore_config_evas_font_path_apply(Evas *evas); int ecore_config_evas_font_path_apply(Evas * evas);
void ecore_config_args_display(void); void ecore_config_args_display(void);
int ecore_config_args_parse(int argc, char **argv); int ecore_config_args_parse(int argc, char **argv);
void ecore_config_app_describe(char *description); void ecore_config_app_describe(char *description);
int ecore_config_create(const char *key, void *val, char short_opt, char *long_opt, char *desc);
int ecore_config_create_typed(const char *key, void *val, int type, char short_opt, char *long_opt, char *desc);
int ecore_config_create_int(const char *key, int val, char short_opt, char *long_opt, char *desc);
int ecore_config_create_int_bound(const char *key, int val, int low, int high, int step, char short_opt, char *long_opt, char *desc);
int ecore_config_create_string(const char *key, char *val, char short_opt, char *long_opt, char *desc);
int ecore_config_create_float(const char *key, float val, char short_opt, char *long_opt, char *desc);
int ecore_config_create_float_bound(const char *key, float val, float low, float high, float step, char short_opt, char *long_opt, char *desc);
int ecore_config_create_rgb(const char *key, char *val, char short_opt, char *long_opt, char *desc);
int ecore_config_create_theme(const char *key, char *val, char short_opt, char *long_opt, char *desc);
int ecore_config_create(const char *key, void *val,
char short_opt, char *long_opt,
char *desc);
int ecore_config_create_typed(const char *key, void *val,
int type, char short_opt,
char *long_opt, char *desc);
int ecore_config_create_int(const char *key, int val,
char short_opt, char *long_opt,
char *desc);
int ecore_config_create_int_bound(const char *key, int val,
int low, int high,
int step, char short_opt,
char *long_opt,
char *desc);
int ecore_config_create_string(const char *key, char *val,
char short_opt,
char *long_opt, char *desc);
int ecore_config_create_float(const char *key, float val,
char short_opt, char *long_opt,
char *desc);
int ecore_config_create_float_bound(const char *key,
float val, float low,
float high, float step,
char short_opt,
char *long_opt,
char *desc);
int ecore_config_create_rgb(const char *key, char *val,
char short_opt, char *long_opt,
char *desc);
int ecore_config_create_theme(const char *key, char *val,
char short_opt, char *long_opt,
char *desc);
# ifdef __cplusplus # ifdef __cplusplus
} }

View File

@ -6,90 +6,151 @@
char *__ecore_config_app_description; char *__ecore_config_app_description;
extern int ecore_config_bound(Ecore_Config_Prop *e); extern int ecore_config_bound(Ecore_Config_Prop * e);
/* shorthand prop setup code to make client apps a little smaller ;) */ /* shorthand prop setup code to make client apps a little smaller ;) */
int ecore_config_create(const char *key, void *val, char short_opt, char *long_opt, char *desc) { int
int type=ecore_config_guess_type(key, val); ecore_config_create(const char *key, void *val, char short_opt, char *long_opt,
return ecore_config_create_typed(key, val, type, short_opt, long_opt, desc);} char *desc)
{
int type = ecore_config_guess_type(key, val);
int ecore_config_create_typed(const char *key, void *val, int type, char short_opt, char *long_opt, char *desc) { return ecore_config_create_typed(key, val, type, short_opt, long_opt, desc);
}
int
ecore_config_create_typed(const char *key, void *val, int type, char short_opt,
char *long_opt, char *desc)
{
int ret; int ret;
if ((ret=ecore_config_default_typed(key, val, type)) != ECORE_CONFIG_ERR_SUCC) if ((ret =
ecore_config_default_typed(key, val, type)) != ECORE_CONFIG_ERR_SUCC)
return ret; return ret;
if ((ret=ecore_config_set_short_opt(key, short_opt)) != ECORE_CONFIG_ERR_SUCC) if ((ret =
ecore_config_set_short_opt(key, short_opt)) != ECORE_CONFIG_ERR_SUCC)
return ret; return ret;
if ((ret=ecore_config_set_long_opt(key, long_opt)) != ECORE_CONFIG_ERR_SUCC) if ((ret =
ecore_config_set_long_opt(key, long_opt)) != ECORE_CONFIG_ERR_SUCC)
return ret; return ret;
ret=ecore_config_describe(key, desc); ret = ecore_config_describe(key, desc);
return ret;} return ret;
}
int ecore_config_create_int(const char *key, int val, char short_opt, char *long_opt, char *desc) { int
ecore_config_create_int(const char *key, int val, char short_opt,
char *long_opt, char *desc)
{
return return
ecore_config_create_typed(key, (void *)&val, PT_INT, short_opt, long_opt, desc);} ecore_config_create_typed(key, (void *)&val, PT_INT, short_opt, long_opt,
desc);
}
int ecore_config_create_int_bound(const char *key, int val, int low, int high, int step, char short_opt, char *long_opt, char *desc) { int
ecore_config_create_int_bound(const char *key, int val, int low, int high,
int step, char short_opt, char *long_opt,
char *desc)
{
Ecore_Config_Prop *e; Ecore_Config_Prop *e;
int ret; int ret;
ret=
ecore_config_create_typed(key, (void *)&val, PT_INT, short_opt, long_opt, desc); ret =
ecore_config_create_typed(key, (void *)&val, PT_INT, short_opt, long_opt,
desc);
if (ret != ECORE_CONFIG_ERR_SUCC) if (ret != ECORE_CONFIG_ERR_SUCC)
return ret; return ret;
e=ecore_config_get(key); e = ecore_config_get(key);
if (e) { if (e)
e->step=step; {
e->flags|=PF_BOUNDS; e->step = step;
e->lo=low; e->flags |= PF_BOUNDS;
e->hi=high; e->lo = low;
e->hi = high;
ecore_config_bound(e); ecore_config_bound(e);
} }
return ret;} return ret;
}
int ecore_config_create_string(const char *key, char *val, char short_opt, char *long_opt, char *desc) { int
ecore_config_create_string(const char *key, char *val, char short_opt,
char *long_opt, char *desc)
{
return return
ecore_config_create_typed(key, (void *)val, PT_STR, short_opt, long_opt, desc);} ecore_config_create_typed(key, (void *)val, PT_STR, short_opt, long_opt,
desc);
}
int ecore_config_create_float(const char *key, float val, char short_opt, char *long_opt, char *desc) { int
ecore_config_create_float(const char *key, float val, char short_opt,
char *long_opt, char *desc)
{
return return
ecore_config_create_typed(key, (void *)&val, PT_FLT, short_opt, long_opt, desc);} ecore_config_create_typed(key, (void *)&val, PT_FLT, short_opt, long_opt,
desc);
}
int ecore_config_create_float_bound(const char *key, float val, float low, float high, float step, char short_opt, char *long_opt, char *desc) { int
ecore_config_create_float_bound(const char *key, float val, float low,
float high, float step, char short_opt,
char *long_opt, char *desc)
{
Ecore_Config_Prop *e; Ecore_Config_Prop *e;
int ret; int ret;
ret=
ecore_config_create_typed(key, (void *)&val, PT_FLT, short_opt, long_opt, desc); ret =
e=ecore_config_get(key); ecore_config_create_typed(key, (void *)&val, PT_FLT, short_opt, long_opt,
if (e) { desc);
e->step=(int)(step*ECORE_CONFIG_FLOAT_PRECISION); e = ecore_config_get(key);
e->flags|=PF_BOUNDS; if (e)
e->lo=(int)(low*ECORE_CONFIG_FLOAT_PRECISION); {
e->hi=(int)(high*ECORE_CONFIG_FLOAT_PRECISION); e->step = (int)(step * ECORE_CONFIG_FLOAT_PRECISION);
e->flags |= PF_BOUNDS;
e->lo = (int)(low * ECORE_CONFIG_FLOAT_PRECISION);
e->hi = (int)(high * ECORE_CONFIG_FLOAT_PRECISION);
ecore_config_bound(e); ecore_config_bound(e);
} }
return ret;} return ret;
}
int ecore_config_create_rgb(const char *key, char *val, char short_opt, char *long_opt, char *desc) { int
ecore_config_create_rgb(const char *key, char *val, char short_opt,
char *long_opt, char *desc)
{
return return
ecore_config_create_typed(key, (void *)val, PT_RGB, short_opt, long_opt, desc);} ecore_config_create_typed(key, (void *)val, PT_RGB, short_opt, long_opt,
desc);
}
int ecore_config_create_theme(const char *key, char *val, char short_opt, char *long_opt, char *desc) { int
ecore_config_create_theme(const char *key, char *val, char short_opt,
char *long_opt, char *desc)
{
return return
ecore_config_create_typed(key, (void *)val, PT_THM, short_opt, long_opt, desc);} ecore_config_create_typed(key, (void *)val, PT_THM, short_opt, long_opt,
desc);
}
/* this should only be built if evas is present */ /* this should only be built if evas is present */
/**
* Calls evas_font_path_append on @evas for each of the font names stored
* in the property "/e/font/path".
* @param evas Evas object to append the font names to.
* @return ECORE_CONFIG_ERR_SUCC on success. ECORE_CONFIG_ERR_NODATA
* is returned if the property has not been set.
*/
int int
ecore_config_evas_font_path_apply (Evas * evas) ecore_config_evas_font_path_apply(Evas * evas)
{ {
char *font_path, *font_path_tmp, *ptr, *end; char *font_path, *font_path_tmp, *ptr, *end;
font_path = ecore_config_get_string ("/e/font/path"); font_path = ecore_config_get_string("/e/font/path");
if (!font_path) if (!font_path)
return ECORE_CONFIG_ERR_NODATA; return ECORE_CONFIG_ERR_NODATA;
ptr = font_path; ptr = font_path;
end = font_path + strlen (font_path); end = font_path + strlen(font_path);
font_path_tmp = font_path; font_path_tmp = font_path;
while (ptr && ptr < end) while (ptr && ptr < end)
{ {
@ -98,18 +159,22 @@ ecore_config_evas_font_path_apply (Evas * evas)
if (ptr < end) if (ptr < end)
*ptr = '\0'; *ptr = '\0';
evas_font_path_append (evas, font_path_tmp); evas_font_path_append(evas, font_path_tmp);
ptr++; ptr++;
font_path_tmp = ptr; font_path_tmp = ptr;
} }
free (font_path); free(font_path);
return ECORE_CONFIG_ERR_SUCC; return ECORE_CONFIG_ERR_SUCC;
} }
static char *_ecore_config_short_types[]={ "nil", "int", "flt", "str", "rgb", "str"}; static char *_ecore_config_short_types[] =
{ "nil", "int", "flt", "str", "rgb", "str" };
/**
* Prints the property list of the local configuration bundle to output.
*/
void void
ecore_config_args_display(void) ecore_config_args_display(void)
{ {
@ -119,33 +184,41 @@ ecore_config_args_display(void)
printf("%s\n\n", __ecore_config_app_description); printf("%s\n\n", __ecore_config_app_description);
printf("Supported Options:\n"); printf("Supported Options:\n");
printf(" -h, --help\t Print this text\n"); printf(" -h, --help\t Print this text\n");
if (!__ecore_config_bundle_local) return; if (!__ecore_config_bundle_local)
return;
props = __ecore_config_bundle_local->data; props = __ecore_config_bundle_local->data;
while (props) while (props)
{ {
if (props->flags&PF_SYSTEM) { if (props->flags & PF_SYSTEM)
{
props = props->next; props = props->next;
continue; continue;
} }
printf(" %c%c%c --%s\t<%s> %s\n", props->short_opt?'-':' ', printf(" %c%c%c --%s\t<%s> %s\n", props->short_opt ? '-' : ' ',
props->short_opt?props->short_opt:' ', props->short_opt?',':' ', props->short_opt ? props->short_opt : ' ',
props->long_opt?props->long_opt:props->key, props->short_opt ? ',' : ' ',
props->long_opt ? props->long_opt : props->key,
_ecore_config_short_types[props->type], _ecore_config_short_types[props->type],
props->description?props->description:"(no description available)"); props->description ? props->
description : "(no description available)");
props = props->next; props = props->next;
} }
} }
int int
ecore_config_parse_set(Ecore_Config_Prop *prop,char *arg,char *opt,char opt2) { ecore_config_parse_set(Ecore_Config_Prop * prop, char *arg, char *opt,
if (!arg) { char opt2)
{
if (!arg)
{
if (opt) if (opt)
printf("Missing expected argument for option --%s\n", opt); printf("Missing expected argument for option --%s\n", opt);
else else
printf("Missing expected argument for option -%c\n", opt2); printf("Missing expected argument for option -%c\n", opt2);
return ECORE_CONFIG_PARSE_EXIT; return ECORE_CONFIG_PARSE_EXIT;
} else }
else
ecore_config_set(prop->key, arg); ecore_config_set(prop->key, arg);
return ECORE_CONFIG_PARSE_CONTINUE; return ECORE_CONFIG_PARSE_CONTINUE;
} }
@ -159,10 +232,12 @@ ecore_config_args_parse(int argc, char **argv)
Ecore_Config_Prop *prop; Ecore_Config_Prop *prop;
nextarg = 1; nextarg = 1;
while (nextarg < argc) { while (nextarg < argc)
{
arg = argv[nextarg]; arg = argv[nextarg];
if (*arg != '-') { if (*arg != '-')
{
printf("Unexpected attribute \"%s\"\n", arg); printf("Unexpected attribute \"%s\"\n", arg);
nextarg++; nextarg++;
continue; continue;
@ -171,54 +246,76 @@ ecore_config_args_parse(int argc, char **argv)
next_short_opt = 1; next_short_opt = 1;
short_opt = *(arg + next_short_opt); short_opt = *(arg + next_short_opt);
if (short_opt == '-') { if (short_opt == '-')
{
long_opt = arg + 2; long_opt = arg + 2;
if (!strcmp(long_opt, "help")) { if (!strcmp(long_opt, "help"))
{
ecore_config_args_display(); ecore_config_args_display();
return ECORE_CONFIG_PARSE_HELP; return ECORE_CONFIG_PARSE_HELP;
} }
found = 0; found = 0;
prop = __ecore_config_bundle_local->data; prop = __ecore_config_bundle_local->data;
while (prop) { while (prop)
{
if ((prop->long_opt && !strcmp(long_opt, prop->long_opt)) if ((prop->long_opt && !strcmp(long_opt, prop->long_opt))
|| !strcmp(long_opt, prop->key)) { || !strcmp(long_opt, prop->key))
{
found = 1; found = 1;
if ((ret=ecore_config_parse_set(prop, argv[++nextarg], long_opt,'\0')) if ((ret =
!= ECORE_CONFIG_PARSE_CONTINUE); ecore_config_parse_set(prop, argv[++nextarg],
long_opt,
'\0')) !=
ECORE_CONFIG_PARSE_CONTINUE);
return ret; return ret;
break; break;
} }
prop = prop->next; prop = prop->next;
} }
if (!found) { if (!found)
{
printf("Unrecognised option \"%s\"\n", long_opt); printf("Unrecognised option \"%s\"\n", long_opt);
printf("Try using -h or --help for more information.\n\n"); printf("Try using -h or --help for more information.\n\n");
return ECORE_CONFIG_PARSE_EXIT; return ECORE_CONFIG_PARSE_EXIT;
} }
} else { }
while (short_opt) { else
if (short_opt == 'h') { {
while (short_opt)
{
if (short_opt == 'h')
{
ecore_config_args_display(); ecore_config_args_display();
return ECORE_CONFIG_PARSE_HELP; return ECORE_CONFIG_PARSE_HELP;
} else { }
else
{
found = 0; found = 0;
prop = __ecore_config_bundle_local->data; prop = __ecore_config_bundle_local->data;
while (prop) { while (prop)
if (short_opt == prop->short_opt) { {
if (short_opt == prop->short_opt)
{
found = 1; found = 1;
if ((ret=ecore_config_parse_set(prop, argv[++nextarg], NULL, short_opt)) if ((ret =
!= ECORE_CONFIG_PARSE_CONTINUE) ecore_config_parse_set(prop,
argv[++nextarg],
NULL,
short_opt)) !=
ECORE_CONFIG_PARSE_CONTINUE)
return ret; return ret;
break; break;
} }
prop = prop->next; prop = prop->next;
} }
if (!found) { if (!found)
{
printf("Unrecognised option '%c'\n", short_opt); printf("Unrecognised option '%c'\n", short_opt);
printf("Try using -h or --help for more information.\n\n"); printf
("Try using -h or --help for more information.\n\n");
return ECORE_CONFIG_PARSE_EXIT; return ECORE_CONFIG_PARSE_EXIT;
} }
} }
@ -232,7 +329,8 @@ ecore_config_args_parse(int argc, char **argv)
} }
void void
ecore_config_app_describe(char *description) { ecore_config_app_describe(char *description)
{
if (__ecore_config_app_description) if (__ecore_config_app_description)
free(__ecore_config_app_description); free(__ecore_config_app_description);
__ecore_config_app_description = strdup(description); __ecore_config_app_description = strdup(description);

File diff suppressed because it is too large Load Diff

View File

@ -10,19 +10,45 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
int ecore_config_load(void) { /**
* Loads the default configuration.
* @return ECORE_CONFIG_ERR_SUCC on success. ECORE_CONFIG_ERR_NODATA is
* returned if the file cannot be loaded.
*/
int
ecore_config_load(void)
{
char file[PATH_MAX]; char file[PATH_MAX];
snprintf(file, PATH_MAX, "%s/.e/apps/%s/config.db",getenv("HOME"),__ecore_config_app_name);
snprintf(file, PATH_MAX, "%s/.e/apps/%s/config.db", getenv("HOME"),
__ecore_config_app_name);
return ecore_config_load_file(file); return ecore_config_load_file(file);
} }
int ecore_config_save(void) { /**
* Saves the current configuration to the default file.
* @return ECORE_CONFIG_ERR_SUCC is returned on success.
* ECORE_CONFIG_ERR_FAIL is returned if the data cannot be saved.
*/
int
ecore_config_save(void)
{
char file[PATH_MAX]; char file[PATH_MAX];
snprintf(file, PATH_MAX, "%s/.e/apps/%s/config.db",getenv("HOME"),__ecore_config_app_name);
snprintf(file, PATH_MAX, "%s/.e/apps/%s/config.db", getenv("HOME"),
__ecore_config_app_name);
return ecore_config_save_file(file); return ecore_config_save_file(file);
} }
int ecore_config_load_file(char *file) { /**
* Load the given configuration file to the local configuration.
* @param file Name of the file to load.
* @return ECORE_CONFIG_ERR_SUCC on success. ECORE_CONFIG_ERR_NODATA is
* returned if the file cannot be loaded.
*/
int
ecore_config_load_file(char *file)
{
E_DB_File *db; E_DB_File *db;
char **keys; char **keys;
int key_count; int key_count;
@ -31,65 +57,89 @@ int ecore_config_load_file(char *file) {
float ftmp; float ftmp;
char *type; char *type;
char *data; char *data;
db=NULL;
db = NULL;
type = NULL; type = NULL;
data = NULL; data = NULL;
db = e_db_open_read(file); db = e_db_open_read(file);
if (!db) { if (!db)
{
E(0, "Cannot open database from file %s!\n", file); E(0, "Cannot open database from file %s!\n", file);
return ECORE_CONFIG_ERR_NODATA; return ECORE_CONFIG_ERR_NODATA;
} }
keys = e_db_dump_key_list(file, &key_count); keys = e_db_dump_key_list(file, &key_count);
for (x = 0; x < key_count; x++) { for (x = 0; x < key_count; x++)
{
type = e_db_type_get(db, keys[x]); type = e_db_type_get(db, keys[x]);
if (!type) type = "?"; if (!type)
type = "?";
if (!strcmp(type, "int")) { if (!strcmp(type, "int"))
if (e_db_int_get(db, keys[x], &itmp)) { {
if (e_db_int_get(db, keys[x], &itmp))
{
ecore_config_set_int(keys[x], itmp); ecore_config_set_int(keys[x], itmp);
} else { }
else
{
E(0, "Could not read key %s!\n", keys[x]); E(0, "Could not read key %s!\n", keys[x]);
} }
} else if (!strcmp(type, "float")) { }
if (e_db_float_get(db, keys[x], &ftmp)) { else if (!strcmp(type, "float"))
{
if (e_db_float_get(db, keys[x], &ftmp))
{
ecore_config_set_float(keys[x], ftmp); ecore_config_set_float(keys[x], ftmp);
} else { }
else
{
E(0, "Could not read key %s!\n", keys[x]); E(0, "Could not read key %s!\n", keys[x]);
} }
} else if (!strcmp(type, "str")) { }
else if (!strcmp(type, "str"))
{
data = e_db_str_get(db, keys[x]); data = e_db_str_get(db, keys[x]);
if (data) { if (data)
itmp = ecore_config_guess_type(keys[x],data); {
switch (itmp) { itmp = ecore_config_guess_type(keys[x], data);
switch (itmp)
{
case PT_RGB: case PT_RGB:
ecore_config_set_rgb(keys[x],data); ecore_config_set_rgb(keys[x], data);
break; break;
case PT_THM: case PT_THM:
ecore_config_set_theme(keys[x],data); ecore_config_set_theme(keys[x], data);
break; break;
default: default:
ecore_config_set_string(keys[x],data); ecore_config_set_string(keys[x], data);
} }
free(data); free(data);
} else { }
else
{
E(0, "Could not read key %s!\n", keys[x]); E(0, "Could not read key %s!\n", keys[x]);
} }
} else { }
else
{
E(1, "Unexpected type: %s\n", type); E(1, "Unexpected type: %s\n", type);
continue; continue;
} }
if (type) free(type); if (type)
free(type);
} }
e_db_close(db); e_db_close(db);
free(keys); free(keys);
return ECORE_CONFIG_ERR_SUCC; return ECORE_CONFIG_ERR_SUCC;
} }
static void static void
_ecore_config_recurse_mkdir(char *file) { _ecore_config_recurse_mkdir(char *file)
{
char *file_ptr; char *file_ptr;
char *file_tmp; char *file_tmp;
struct stat status; struct stat status;
@ -100,36 +150,50 @@ _ecore_config_recurse_mkdir(char *file) {
file_ptr--; file_ptr--;
*file_ptr = '\0'; *file_ptr = '\0';
if(stat(file_tmp, &status)) { if (stat(file_tmp, &status))
{
_ecore_config_recurse_mkdir(file_tmp); _ecore_config_recurse_mkdir(file_tmp);
mkdir(file_tmp, S_IRUSR | S_IWUSR | S_IXUSR); mkdir(file_tmp, S_IRUSR | S_IWUSR | S_IXUSR);
} }
free(file_tmp); free(file_tmp);
} }
int ecore_config_save_file(char *file) { /**
* Saves the local configuration to the given file.
* @param file Name of the file to save to.
* @return ECORE_CONFIG_ERR_SUCC is returned on success.
* ECORE_CONFIG_ERR_FAIL is returned if the data cannot be saved.
*/
int
ecore_config_save_file(char *file)
{
Ecore_Config_Prop *next; Ecore_Config_Prop *next;
E_DB_File *db; E_DB_File *db;
struct stat status; struct stat status;
next=__ecore_config_bundle_local->data;
next = __ecore_config_bundle_local->data;
db = NULL; db = NULL;
/* if file does not exist check to see if the dirs exist, creating if not */ /* if file does not exist check to see if the dirs exist, creating if not */
if(stat(file, &status)) if (stat(file, &status))
_ecore_config_recurse_mkdir(file); _ecore_config_recurse_mkdir(file);
db = e_db_open(file); db = e_db_open(file);
if (!db) { if (!db)
{
E(0, "Cannot open database from file %s!\n", file); E(0, "Cannot open database from file %s!\n", file);
return ECORE_CONFIG_ERR_FAIL; return ECORE_CONFIG_ERR_FAIL;
} }
while (next) { while (next)
if (!(next->flags&PF_MODIFIED)) { {
next=next->next; if (!(next->flags & PF_MODIFIED))
{
next = next->next;
continue; continue;
} }
switch (next->type) { switch (next->type)
{
case PT_INT: case PT_INT:
e_db_int_set(db, next->key, ecore_config_get_int(next->key)); e_db_int_set(db, next->key, ecore_config_get_int(next->key));
break; break;
@ -150,11 +214,10 @@ int ecore_config_save_file(char *file) {
break; break;
} }
next=next->next; next = next->next;
} }
e_db_close(db); e_db_close(db);
e_db_flush(); e_db_flush();
return ECORE_CONFIG_ERR_SUCC; return ECORE_CONFIG_ERR_SUCC;
} }

View File

@ -1,7 +1,8 @@
#include <Ecore_Ipc.h> #include <Ecore_Ipc.h>
#include "Ecore_Config.h" #include "Ecore_Config.h"
typedef enum { typedef enum
{
IPC_NONE, IPC_NONE,
IPC_PROP_LIST, IPC_PROP_LIST,
IPC_GLOBAL_PROP_LIST, IPC_GLOBAL_PROP_LIST,
@ -20,14 +21,26 @@ typedef enum {
Ecore_Config_Server *_ecore_config_server_convert(void *srv); Ecore_Config_Server *_ecore_config_server_convert(void *srv);
char *_ecore_config_ipc_prop_list(Ecore_Config_Server *srv, const long serial); char *_ecore_config_ipc_prop_list(Ecore_Config_Server * srv,
char *_ecore_config_ipc_prop_desc(Ecore_Config_Server *srv, const long serial,const char *key); const long serial);
char *_ecore_config_ipc_prop_get(Ecore_Config_Server *srv, const long serial,const char *key); char *_ecore_config_ipc_prop_desc(Ecore_Config_Server * srv,
int _ecore_config_ipc_prop_set(Ecore_Config_Server *srv, const long serial,const char *key,const char *val); const long serial,
const char *key);
char *_ecore_config_ipc_bundle_list(Ecore_Config_Server *srv); char *_ecore_config_ipc_prop_get(Ecore_Config_Server * srv,
int _ecore_config_ipc_bundle_new(Ecore_Config_Server *srv, const char *); const long serial,
char *_ecore_config_ipc_bundle_label_get(Ecore_Config_Server *srv, const long); const char *key);
int _ecore_config_ipc_bundle_label_set(Ecore_Config_Server *srv, const long,const char *); int _ecore_config_ipc_prop_set(Ecore_Config_Server * srv,
long _ecore_config_ipc_bundle_label_find(Ecore_Config_Server *srv, const char *); const long serial,
const char *key,
const char *val);
char *_ecore_config_ipc_bundle_list(Ecore_Config_Server * srv);
int _ecore_config_ipc_bundle_new(Ecore_Config_Server * srv,
const char *);
char *_ecore_config_ipc_bundle_label_get(Ecore_Config_Server *
srv, const long);
int _ecore_config_ipc_bundle_label_set(Ecore_Config_Server *
srv, const long,
const char *);
long _ecore_config_ipc_bundle_label_find(Ecore_Config_Server *
srv, const char *);

View File

@ -21,33 +21,34 @@
#include "Ecore_Config.h" #include "Ecore_Config.h"
#include "config.h" #include "config.h"
/*****************************************************************************/ /*****************************************************************************/
static int
_ecore_config_ipc_ecore_get_string(char **m, char **r)
static int _ecore_config_ipc_ecore_get_string(char **m,char **r) { {
char *q; char *q;
int l=0; int l = 0;
if(!m||!*m) if (!m || !*m)
return ECORE_CONFIG_ERR_NODATA; return ECORE_CONFIG_ERR_NODATA;
if(!r) if (!r)
return ECORE_CONFIG_ERR_FAIL; return ECORE_CONFIG_ERR_FAIL;
q=*m; q = *m;
if(*q!='s') if (*q != 's')
return ECORE_CONFIG_ERR_TYPEMISMATCH; return ECORE_CONFIG_ERR_TYPEMISMATCH;
q++; q++;
l=(*(q++))<<8; l = (*(q++)) << 8;
l+=*(q++); l += *(q++);
*r=q; *r = q;
q+=l; q += l;
*m=q; *m = q;
E(1,"IPC/eCore: got string-%d \"%s\"\n",l,*r); E(1, "IPC/eCore: got string-%d \"%s\"\n", l, *r);
return ECORE_CONFIG_ERR_SUCC; } return ECORE_CONFIG_ERR_SUCC;
}
char *
char *_ecore_config_ipc_global_prop_list(Ecore_Config_Server *srv, const long serial) { _ecore_config_ipc_global_prop_list(Ecore_Config_Server * srv, const long serial)
{
E_DB_File *db; E_DB_File *db;
char **keys; char **keys;
int key_count, x; int key_count, x;
@ -55,14 +56,16 @@ char *_ecore_config_ipc_global_prop_list(Ecore_Config_Server *srv, const long se
int f; int f;
char *buf, *p, *type, *data; char *buf, *p, *type, *data;
s=estring_new(8192); s = estring_new(8192);
f=0; f = 0;
if((p=getenv("HOME"))) { /* debug-only ### FIXME */ if ((p = getenv("HOME")))
if ((buf=malloc(PATH_MAX*sizeof(char)))) { { /* debug-only ### FIXME */
snprintf(buf,PATH_MAX,"%s/.e/config.db",p); if ((buf = malloc(PATH_MAX * sizeof(char))))
db=e_db_open_read(buf); {
if (!(db=e_db_open_read(buf))) snprintf(buf, PATH_MAX, "%s/.e/config.db", p);
if (!(db=e_db_open_read(buf=PACKAGE_DATA_DIR "/system.db"))) db = e_db_open_read(buf);
if (!(db = e_db_open_read(buf)))
if (!(db = e_db_open_read(buf = PACKAGE_DATA_DIR "/system.db")))
return NULL; return NULL;
} }
} }
@ -70,258 +73,299 @@ char *_ecore_config_ipc_global_prop_list(Ecore_Config_Server *srv, const long se
keys = e_db_dump_key_list(buf, &key_count); keys = e_db_dump_key_list(buf, &key_count);
free(buf); free(buf);
for (x = 0; x < key_count; x++) { for (x = 0; x < key_count; x++)
{
type = e_db_type_get(db, keys[x]); type = e_db_type_get(db, keys[x]);
if (!type) type = "?"; if (!type)
type = "?";
if (!strcmp(type, "int")) if (!strcmp(type, "int"))
estring_appendf(s,"%s%s: integer",f?"\n":"",keys[x]); estring_appendf(s, "%s%s: integer", f ? "\n" : "", keys[x]);
else if (!strcmp(type, "float")) else if (!strcmp(type, "float"))
estring_appendf(s,"%s%s: float",f?"\n":"",keys[x]); estring_appendf(s, "%s%s: float", f ? "\n" : "", keys[x]);
else if (!strcmp(type, "str")) { else if (!strcmp(type, "str"))
{
data = e_db_str_get(db, keys[x]); data = e_db_str_get(db, keys[x]);
if (data) { if (data)
if (ecore_config_guess_type(keys[x], data)==PT_RGB) {
estring_appendf(s,"%s%s: colour",f?"\n":"",keys[x]); if (ecore_config_guess_type(keys[x], data) == PT_RGB)
estring_appendf(s, "%s%s: colour", f ? "\n" : "", keys[x]);
else else
estring_appendf(s,"%s%s: string",f?"\n":"",keys[x]); estring_appendf(s, "%s%s: string", f ? "\n" : "", keys[x]);
free(data); free(data);
} else {
estring_appendf(s,"%s%s: string",f?"\n":"",keys[x]);
} }
} else else
estring_appendf(s,"%s%s: unknown",f?"\n":"",keys[x]); {
estring_appendf(s, "%s%s: string", f ? "\n" : "", keys[x]);
}
}
else
estring_appendf(s, "%s%s: unknown", f ? "\n" : "", keys[x]);
if (type) free(type); if (type)
f=1; free(type);
f = 1;
} }
e_db_close(db); e_db_close(db);
free(keys); free(keys);
return estring_disown(s);} return estring_disown(s);
}
/*****************************************************************************/ /*****************************************************************************/
static int
_ecore_config_ipc_ecore_send(Ecore_Ipc_Event_Client_Data * e, int code,
char *reply)
{
static int our_ref = 0;
int len = reply ? strlen(reply) + 1 : 0;
static int _ecore_config_ipc_ecore_send(Ecore_Ipc_Event_Client_Data *e,int code,char *reply) {
static int our_ref=0;
int len=reply?strlen(reply)+1:0;
our_ref++; our_ref++;
E(1,"IPC/eCore: replying [0,0] %d IRT %d => %d {\"%s\":%d}\n",our_ref,e->ref,code,reply?reply:"",len); E(1, "IPC/eCore: replying [0,0] %d IRT %d => %d {\"%s\":%d}\n", our_ref,
return ecore_ipc_client_send(e->client,0,0,our_ref,e->ref,code,reply,len); } e->ref, code, reply ? reply : "", len);
return ecore_ipc_client_send(e->client, 0, 0, our_ref, e->ref, code, reply,
len);
}
/*****************************************************************************/ /*****************************************************************************/
static int _ecore_config_ipc_ecore_handle_request(Ecore_Ipc_Server *server,Ecore_Ipc_Event_Client_Data *e) { static int
_ecore_config_ipc_ecore_handle_request(Ecore_Ipc_Server * server,
Ecore_Ipc_Event_Client_Data * e)
{
Ecore_Config_Server *srv; Ecore_Config_Server *srv;
long serial; long serial;
int ret; int ret;
char *r,*k,*v,*m; char *r, *k, *v, *m;
srv=_ecore_config_server_convert(server); srv = _ecore_config_server_convert(server);
serial=e->minor; serial = e->minor;
ret=ECORE_CONFIG_ERR_FAIL; ret = ECORE_CONFIG_ERR_FAIL;
r=NULL; r = NULL;
m=(char *)e->data; m = (char *)e->data;
E(1,"IPC/eCore: client sent: [%d,%d] #%d (%d) @ %p\n",e->major,e->minor,e->ref,e->size,server); E(1, "IPC/eCore: client sent: [%d,%d] #%d (%d) @ %p\n", e->major, e->minor,
e->ref, e->size, server);
switch(e->major) { switch (e->major)
{
case IPC_PROP_LIST: case IPC_PROP_LIST:
if (srv == __ecore_config_server_global) if (srv == __ecore_config_server_global)
r=_ecore_config_ipc_global_prop_list(srv, serial); r = _ecore_config_ipc_global_prop_list(srv, serial);
else else
r=_ecore_config_ipc_prop_list(srv, serial); r = _ecore_config_ipc_prop_list(srv, serial);
break; break;
case IPC_PROP_DESC: case IPC_PROP_DESC:
if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC) if (_ecore_config_ipc_ecore_get_string(&m, &k) == ECORE_CONFIG_ERR_SUCC)
r=_ecore_config_ipc_prop_desc(srv, serial,k); r = _ecore_config_ipc_prop_desc(srv, serial, k);
break; break;
case IPC_PROP_GET: case IPC_PROP_GET:
if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC) if (_ecore_config_ipc_ecore_get_string(&m, &k) == ECORE_CONFIG_ERR_SUCC)
r=_ecore_config_ipc_prop_get(srv, serial,k); r = _ecore_config_ipc_prop_get(srv, serial, k);
break; break;
case IPC_PROP_SET: case IPC_PROP_SET:
if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC) { if (_ecore_config_ipc_ecore_get_string(&m, &k) == ECORE_CONFIG_ERR_SUCC)
if(_ecore_config_ipc_ecore_get_string(&m,&v)==ECORE_CONFIG_ERR_SUCC) {
return _ecore_config_ipc_ecore_send(e,_ecore_config_ipc_prop_set(srv, serial,k,v),NULL); } if (_ecore_config_ipc_ecore_get_string(&m, &v) ==
ECORE_CONFIG_ERR_SUCC)
return _ecore_config_ipc_ecore_send(e,
_ecore_config_ipc_prop_set
(srv, serial, k, v), NULL);
}
break; break;
case IPC_BUNDLE_LIST: case IPC_BUNDLE_LIST:
r=_ecore_config_ipc_bundle_list(srv); r = _ecore_config_ipc_bundle_list(srv);
break; break;
case IPC_BUNDLE_NEW: case IPC_BUNDLE_NEW:
if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC) if (_ecore_config_ipc_ecore_get_string(&m, &k) == ECORE_CONFIG_ERR_SUCC)
return _ecore_config_ipc_ecore_send(e,k?_ecore_config_ipc_bundle_new(srv, k):ECORE_CONFIG_ERR_FAIL,NULL); return _ecore_config_ipc_ecore_send(e,
k ?
_ecore_config_ipc_bundle_new(srv,
k) :
ECORE_CONFIG_ERR_FAIL, NULL);
break; break;
case IPC_BUNDLE_LABEL_SET: case IPC_BUNDLE_LABEL_SET:
if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC) if (_ecore_config_ipc_ecore_get_string(&m, &k) == ECORE_CONFIG_ERR_SUCC)
return _ecore_config_ipc_ecore_send(e,k?_ecore_config_ipc_bundle_label_set(srv, serial,k):ECORE_CONFIG_ERR_FAIL,NULL); return _ecore_config_ipc_ecore_send(e,
k ?
_ecore_config_ipc_bundle_label_set
(srv, serial,
k) : ECORE_CONFIG_ERR_FAIL,
NULL);
break; break;
case IPC_BUNDLE_LABEL_FIND: case IPC_BUNDLE_LABEL_FIND:
if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC) if (_ecore_config_ipc_ecore_get_string(&m, &k) == ECORE_CONFIG_ERR_SUCC)
return _ecore_config_ipc_ecore_send(e,_ecore_config_ipc_bundle_label_find(srv, k),NULL); return _ecore_config_ipc_ecore_send(e,
_ecore_config_ipc_bundle_label_find
(srv, k), NULL);
break; break;
case IPC_BUNDLE_LABEL_GET: case IPC_BUNDLE_LABEL_GET:
r=_ecore_config_ipc_bundle_label_get(srv, serial); r = _ecore_config_ipc_bundle_label_get(srv, serial);
break; } break;
}
ret=_ecore_config_ipc_ecore_send(e,r?ECORE_CONFIG_ERR_SUCC:ECORE_CONFIG_ERR_FAIL,r); ret =
if(r) { _ecore_config_ipc_ecore_send(e,
r ? ECORE_CONFIG_ERR_SUCC :
ECORE_CONFIG_ERR_FAIL, r);
if (r)
{
free(r); free(r);
return ret; } return ret;
return ECORE_CONFIG_ERR_NOTFOUND; } }
return ECORE_CONFIG_ERR_NOTFOUND;
}
/*****************************************************************************/ /*****************************************************************************/
static int
_ecore_config_ipc_client_add(void *data, int type, void *event)
static int _ecore_config_ipc_client_add(void *data,int type,void *event) { {
Ecore_Ipc_Server **server; Ecore_Ipc_Server **server;
Ecore_Ipc_Event_Client_Data *e; Ecore_Ipc_Event_Client_Data *e;
server=(Ecore_Ipc_Server **)data;
e=(Ecore_Ipc_Event_Client_Data *)event; server = (Ecore_Ipc_Server **) data;
e = (Ecore_Ipc_Event_Client_Data *) event;
if (*server != ecore_ipc_client_server_get(e->client)) if (*server != ecore_ipc_client_server_get(e->client))
return 1; return 1;
E(1,"IPC/eCore: Client connected. @ %p\n",server); E(1, "IPC/eCore: Client connected. @ %p\n", server);
return 1; } return 1;
}
static int
_ecore_config_ipc_client_del(void *data, int type, void *event)
static int _ecore_config_ipc_client_del(void *data, int type, void *event) { {
Ecore_Ipc_Server **server; Ecore_Ipc_Server **server;
Ecore_Ipc_Event_Client_Data *e; Ecore_Ipc_Event_Client_Data *e;
server=(Ecore_Ipc_Server **)data;
e=(Ecore_Ipc_Event_Client_Data *)event; server = (Ecore_Ipc_Server **) data;
e = (Ecore_Ipc_Event_Client_Data *) event;
if (*server != ecore_ipc_client_server_get(e->client)) if (*server != ecore_ipc_client_server_get(e->client))
return 1; return 1;
E(1,"IPC/eCore: Client disconnected. @ %p\n",server); E(1, "IPC/eCore: Client disconnected. @ %p\n", server);
return 1; } return 1;
}
static int
_ecore_config_ipc_client_sent(void *data, int type, void *event)
static int _ecore_config_ipc_client_sent(void *data,int type,void *event) { {
Ecore_Ipc_Server **server; Ecore_Ipc_Server **server;
Ecore_Ipc_Event_Client_Data *e; Ecore_Ipc_Event_Client_Data *e;
server=(Ecore_Ipc_Server **)data;
e=(Ecore_Ipc_Event_Client_Data *)event; server = (Ecore_Ipc_Server **) data;
e = (Ecore_Ipc_Event_Client_Data *) event;
if (*server != ecore_ipc_client_server_get(e->client)) if (*server != ecore_ipc_client_server_get(e->client))
return 1; return 1;
_ecore_config_ipc_ecore_handle_request(*server,e); _ecore_config_ipc_ecore_handle_request(*server, e);
return 1; } return 1;
}
/*****************************************************************************/ /*****************************************************************************/
int
_ecore_config_mod_init(char *pipe_name, void **data)
int _ecore_config_mod_init(char *pipe_name, void **data) { {
Ecore_Ipc_Server **server; Ecore_Ipc_Server **server;
struct stat st; struct stat st;
char *p; char *p;
int port; int port;
char socket[PATH_MAX]; char socket[PATH_MAX];
server=(Ecore_Ipc_Server **)data; server = (Ecore_Ipc_Server **) data;
port=0; port = 0;
if(!server) if (!server)
return ECORE_CONFIG_ERR_FAIL; return ECORE_CONFIG_ERR_FAIL;
/* if(*server) /* if(*server)
return ECORE_CONFIG_ERR_IGNORED; */ return ECORE_CONFIG_ERR_IGNORED; */
ecore_init(); ecore_init();
if(ecore_ipc_init()<1) if (ecore_ipc_init() < 1)
return ECORE_CONFIG_ERR_FAIL; return ECORE_CONFIG_ERR_FAIL;
if((p=getenv("HOME"))) { /* debug-only ### FIXME */ if ((p = getenv("HOME")))
{ /* debug-only ### FIXME */
int stale; int stale;
stale=1;
while (stale) {
snprintf(socket,PATH_MAX,"%s/.ecore/%s/%d",p,pipe_name,port);
if(!stat(socket,&st)) { stale = 1;
E(0,"IPC/eCore: pipe \"%s\" already exists!?\n",socket); while (stale)
{
snprintf(socket, PATH_MAX, "%s/.ecore/%s/%d", p, pipe_name, port);
if (!stat(socket, &st))
{
E(0, "IPC/eCore: pipe \"%s\" already exists!?\n", socket);
/* if(unlink(buf)) /* if(unlink(buf))
E(0,"IPC/eCore: could not remove pipe \"%s\": %d\n",buf,errno); }}*/ E(0,"IPC/eCore: could not remove pipe \"%s\": %d\n",buf,errno); }}*/
port++; port++;
} else { }
else
{
stale = 0; stale = 0;
} }
} }
} }
*server=ecore_ipc_server_add(ECORE_IPC_LOCAL_USER,pipe_name,port,NULL); *server = ecore_ipc_server_add(ECORE_IPC_LOCAL_USER, pipe_name, port, NULL);
ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD, _ecore_config_ipc_client_add, server); ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD,
ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL, _ecore_config_ipc_client_del, server); _ecore_config_ipc_client_add, server);
ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DATA,_ecore_config_ipc_client_sent,server); ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL,
_ecore_config_ipc_client_del, server);
ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DATA,
_ecore_config_ipc_client_sent, server);
if(server) { if (server)
E(1,"IPC/eCore: Server is listening on %s.\n", pipe_name); {
E(1, "IPC/eCore: Server is listening on %s.\n", pipe_name);
} }
return ECORE_CONFIG_ERR_SUCC; } return ECORE_CONFIG_ERR_SUCC;
}
int
_ecore_config_mod_exit(void **data)
int _ecore_config_mod_exit(void **data) { {
int ret; int ret;
Ecore_Ipc_Server **server; Ecore_Ipc_Server **server;
ret=ECORE_CONFIG_ERR_SUCC;
server=(Ecore_Ipc_Server **)data;
if(!server) ret = ECORE_CONFIG_ERR_SUCC;
server = (Ecore_Ipc_Server **) data;
if (!server)
return ECORE_CONFIG_ERR_FAIL; return ECORE_CONFIG_ERR_FAIL;
if(*server) { if (*server)
{
ecore_ipc_server_del(*server); ecore_ipc_server_del(*server);
*server=NULL; } *server = NULL;
}
ecore_ipc_shutdown(); ecore_ipc_shutdown();
return ret; } return ret;
}
/*****************************************************************************/ /*****************************************************************************/
int
_ecore_config_mod_poll(void **data)
int _ecore_config_mod_poll(void **data) { {
Ecore_Ipc_Server **server; Ecore_Ipc_Server **server;
server=(Ecore_Ipc_Server **)data;
if(!server) server = (Ecore_Ipc_Server **) data;
if (!server)
return ECORE_CONFIG_ERR_FAIL; return ECORE_CONFIG_ERR_FAIL;
ecore_main_loop_iterate(); ecore_main_loop_iterate();
return ECORE_CONFIG_ERR_SUCC; } return ECORE_CONFIG_ERR_SUCC;
}
/*****************************************************************************/ /*****************************************************************************/

View File

@ -1,7 +1,6 @@
/* ############## bad */ /* ############## bad */
#define HAVE_EVAS2 #define HAVE_EVAS2
#include "Ecore_Config.h" #include "Ecore_Config.h"
#include "util.h" #include "util.h"
#include "ipc.h" #include "ipc.h"
@ -21,32 +20,34 @@
# define TRUE (!FALSE) # define TRUE (!FALSE)
#endif #endif
typedef struct _ecore_config_ipc { typedef struct _ecore_config_ipc
{
void *lib; void *lib;
void *data; void *data;
int (*ipc_init)(char *pipe_name,void **data); int (*ipc_init) (char *pipe_name, void **data);
int (*ipc_exit)(void **data); int (*ipc_exit) (void **data);
int (*ipc_poll)(void **data); int (*ipc_poll) (void **data);
struct _ecore_config_ipc *next; struct _ecore_config_ipc *next;
} Ecore_Config_Ipc; } Ecore_Config_Ipc;
static Ecore_Config_Ipc *ipc_modules = NULL;
static unsigned long ipc_timer = 0L;
Ecore_Config_Server *
static Ecore_Config_Ipc *ipc_modules=NULL; _ecore_config_server_convert(void *srv)
static unsigned long ipc_timer=0L; {
Ecore_Config_Server *_ecore_config_server_convert(void *srv) {
Ecore_Config_Ipc *ipc_tmp; Ecore_Config_Ipc *ipc_tmp;
Ecore_Config_Server *srv_tmp; Ecore_Config_Server *srv_tmp;
ipc_tmp = ipc_modules; ipc_tmp = ipc_modules;
while (ipc_tmp) { while (ipc_tmp)
{
srv_tmp = ipc_tmp->data; srv_tmp = ipc_tmp->data;
while (srv_tmp) { while (srv_tmp)
{
if (srv_tmp->server == srv) if (srv_tmp->server == srv)
return srv_tmp; return srv_tmp;
srv_tmp=srv_tmp->next; srv_tmp = srv_tmp->next;
} }
ipc_tmp = ipc_tmp->next; ipc_tmp = ipc_tmp->next;
} }
@ -58,179 +59,220 @@ Ecore_Config_Server *_ecore_config_server_convert(void *srv) {
/* INTERFACE FOR IPC MODULES */ /* INTERFACE FOR IPC MODULES */
/*****************************/ /*****************************/
char *
_ecore_config_ipc_prop_list(Ecore_Config_Server * srv, const long serial)
char *_ecore_config_ipc_prop_list(Ecore_Config_Server *srv, const long serial) { {
Ecore_Config_Bundle *theme; Ecore_Config_Bundle *theme;
Ecore_Config_Prop *e; Ecore_Config_Prop *e;
estring *s; estring *s;
int f; int f;
theme=ecore_config_bundle_get_by_serial(srv, serial); theme = ecore_config_bundle_get_by_serial(srv, serial);
e=theme?theme->data:NULL; e = theme ? theme->data : NULL;
s=estring_new(8192); s = estring_new(8192);
f=0; f = 0;
while(e) { while (e)
{
/* ignore system properties in listings, unless they have been overridden */ /* ignore system properties in listings, unless they have been overridden */
if (e->flags&PF_SYSTEM && !(e->flags&PF_MODIFIED)) { if (e->flags & PF_SYSTEM && !(e->flags & PF_MODIFIED))
e=e->next; {
e = e->next;
continue; continue;
} }
estring_appendf(s,"%s%s: %s",f?"\n":"",e->key,ecore_config_get_type(e)); estring_appendf(s, "%s%s: %s", f ? "\n" : "", e->key,
if(e->flags&PF_BOUNDS) { ecore_config_get_type(e));
if (e->type==PT_FLT) if (e->flags & PF_BOUNDS)
estring_appendf(s,", range %le..%le",(float)e->lo/ECORE_CONFIG_FLOAT_PRECISION,(float)e->hi/ECORE_CONFIG_FLOAT_PRECISION); {
if (e->type == PT_FLT)
estring_appendf(s, ", range %le..%le",
(float)e->lo / ECORE_CONFIG_FLOAT_PRECISION,
(float)e->hi / ECORE_CONFIG_FLOAT_PRECISION);
else else
estring_appendf(s,", range %d..%d",e->lo,e->hi); estring_appendf(s, ", range %d..%d", e->lo, e->hi);
}
if (e->type == PT_THM)
estring_appendf(s, ", group %s", e->data ? e->data : "Main");
f = 1;
e = e->next;
} }
if(e->type==PT_THM)
estring_appendf(s,", group %s",e->data?e->data:"Main");
f=1;
e=e->next; }
return estring_disown(s); } return estring_disown(s);
}
char *
_ecore_config_ipc_prop_desc(Ecore_Config_Server * srv, const long serial,
char *_ecore_config_ipc_prop_desc(Ecore_Config_Server *srv, const long serial,const char *key) { const char *key)
{
#ifdef HAVE_EVAS2 #ifdef HAVE_EVAS2
Ecore_Config_Bundle *theme; Ecore_Config_Bundle *theme;
Ecore_Config_Prop *e; Ecore_Config_Prop *e;
theme=ecore_config_bundle_get_by_serial(srv, serial);
e=ecore_config_get(key);
if(e) { theme = ecore_config_bundle_get_by_serial(srv, serial);
estring *s=estring_new(512); e = ecore_config_get(key);
estring_appendf(s,"%s: %s",e->key,ecore_config_get_type(e));
if(e->flags&PF_BOUNDS) if (e)
estring_appendf(s,", range %d..%d",e->lo,e->hi); {
return estring_disown(s); } estring *s = estring_new(512);
estring_appendf(s, "%s: %s", e->key, ecore_config_get_type(e));
if (e->flags & PF_BOUNDS)
estring_appendf(s, ", range %d..%d", e->lo, e->hi);
return estring_disown(s);
}
#endif #endif
return strdup("<undefined>"); } return strdup("<undefined>");
}
char *
_ecore_config_ipc_prop_get(Ecore_Config_Server * srv, const long serial,
char *_ecore_config_ipc_prop_get(Ecore_Config_Server *srv, const long serial,const char *key) { const char *key)
{
#ifdef HAVE_EVAS2 #ifdef HAVE_EVAS2
char *ret; char *ret;
Ecore_Config_Bundle *theme; Ecore_Config_Bundle *theme;
ret=NULL;
theme=ecore_config_bundle_get_by_serial(srv, serial); ret = NULL;
if((ret=ecore_config_get_as_string(/*theme,*/key))) theme = ecore_config_bundle_get_by_serial(srv, serial);
if ((ret = ecore_config_get_as_string( /*theme, */ key)))
return ret; return ret;
#endif #endif
return strdup("<undefined>"); } return strdup("<undefined>");
}
int
_ecore_config_ipc_prop_set(Ecore_Config_Server * srv, const long serial,
int _ecore_config_ipc_prop_set(Ecore_Config_Server *srv, const long serial,const char *key,const char *val) { const char *key, const char *val)
{
#ifdef HAVE_EVAS2 #ifdef HAVE_EVAS2
int ret; int ret;
Ecore_Config_Bundle *theme; Ecore_Config_Bundle *theme;
theme=ecore_config_bundle_get_by_serial(srv, serial);
ret=ecore_config_set(key,(char *)val); theme = ecore_config_bundle_get_by_serial(srv, serial);
E(1,"ipc.prop.set(%s->%s,\"%s\") => %d\n",theme?theme->identifier:"",key,val,ret); ret = ecore_config_set(key, (char *)val);
E(1, "ipc.prop.set(%s->%s,\"%s\") => %d\n", theme ? theme->identifier : "",
key, val, ret);
return ret; return ret;
#else #else
return ECORE_CONFIG_ERR_NOTSUPP; return ECORE_CONFIG_ERR_NOTSUPP;
#endif #endif
} }
/*****************************************************************************/ /*****************************************************************************/
char *
char *_ecore_config_ipc_bundle_list(Ecore_Config_Server *srv) { _ecore_config_ipc_bundle_list(Ecore_Config_Server * srv)
{
Ecore_Config_Bundle *ns; Ecore_Config_Bundle *ns;
estring *s; estring *s;
int f; int f;
ns=ecore_config_bundle_get_1st(srv); ns = ecore_config_bundle_get_1st(srv);
s=estring_new(8192); s = estring_new(8192);
f=0; f = 0;
if(!ns) if (!ns)
return strdup("<no_bundles_created>"); return strdup("<no_bundles_created>");
while(ns) { while (ns)
estring_appendf(s,"%s%d: %s",f?"\n":"",ecore_config_bundle_get_serial(ns),ecore_config_bundle_get_label(ns)); {
f=1; estring_appendf(s, "%s%d: %s", f ? "\n" : "",
ns=ecore_config_bundle_get_next(ns); } ecore_config_bundle_get_serial(ns),
ecore_config_bundle_get_label(ns));
f = 1;
ns = ecore_config_bundle_get_next(ns);
}
return estring_disown(s); } return estring_disown(s);
}
int
_ecore_config_ipc_bundle_new(Ecore_Config_Server * srv, const char *label)
int _ecore_config_ipc_bundle_new(Ecore_Config_Server *srv, const char *label) { {
if (ecore_config_bundle_new(srv, label)) if (ecore_config_bundle_new(srv, label))
return ECORE_CONFIG_ERR_SUCC; return ECORE_CONFIG_ERR_SUCC;
return ECORE_CONFIG_ERR_FAIL; } return ECORE_CONFIG_ERR_FAIL;
}
char *
_ecore_config_ipc_bundle_label_get(Ecore_Config_Server * srv, const long serial)
char *_ecore_config_ipc_bundle_label_get(Ecore_Config_Server *srv, const long serial) { {
Ecore_Config_Bundle *ns; Ecore_Config_Bundle *ns;
char *label; char *label;
ns=ecore_config_bundle_get_by_serial(srv, serial);
label=ecore_config_bundle_get_label(ns);
return strdup(label?label:"<no such bundle>"); }
ns = ecore_config_bundle_get_by_serial(srv, serial);
label = ecore_config_bundle_get_label(ns);
return strdup(label ? label : "<no such bundle>");
}
int
int _ecore_config_ipc_bundle_label_set(Ecore_Config_Server *srv, const long serial,const char *label) { _ecore_config_ipc_bundle_label_set(Ecore_Config_Server * srv, const long serial,
const char *label)
{
Ecore_Config_Bundle *ns; Ecore_Config_Bundle *ns;
ns=ecore_config_bundle_get_by_serial(srv, serial);
if (!(ns->identifier=malloc(sizeof(label)))) ns = ecore_config_bundle_get_by_serial(srv, serial);
if (!(ns->identifier = malloc(sizeof(label))))
return ECORE_CONFIG_ERR_OOM; return ECORE_CONFIG_ERR_OOM;
memcpy(ns->identifier,label,sizeof(label)); memcpy(ns->identifier, label, sizeof(label));
return ECORE_CONFIG_ERR_SUCC; } return ECORE_CONFIG_ERR_SUCC;
}
long
_ecore_config_ipc_bundle_label_find(Ecore_Config_Server * srv,
long _ecore_config_ipc_bundle_label_find(Ecore_Config_Server *srv, const char *label) { const char *label)
{
Ecore_Config_Bundle *ns; Ecore_Config_Bundle *ns;
ns=ecore_config_bundle_get_by_label(srv, label);
return ns?ecore_config_bundle_get_serial(ns):-1; }
ns = ecore_config_bundle_get_by_label(srv, label);
return ns ? ecore_config_bundle_get_serial(ns) : -1;
}
static int
_ecore_config_ipc_poll(void *data)
static int _ecore_config_ipc_poll(void *data) { {
Ecore_Config_Ipc *m; Ecore_Config_Ipc *m;
Ecore_Config_Server *s; Ecore_Config_Server *s;
m=(Ecore_Config_Ipc *)data; m = (Ecore_Config_Ipc *) data;
while(m) { while (m)
{
s = m->data; s = m->data;
while (s) { while (s)
{
m->ipc_poll(&s->server); m->ipc_poll(&s->server);
s = s->next; s = s->next;
} }
m=m->next; } m = m->next;
}
return TRUE; } return TRUE;
}
int
_ecore_config_ipc_exit(void)
int _ecore_config_ipc_exit(void) { {
Ecore_Config_Ipc *m; Ecore_Config_Ipc *m;
Ecore_Config_Server *l; Ecore_Config_Server *l;
if(ipc_timer) if (ipc_timer)
timeout_remove(ipc_timer); timeout_remove(ipc_timer);
while(ipc_modules) { while (ipc_modules)
m=ipc_modules; {
ipc_modules=ipc_modules->next; m = ipc_modules;
l=m->data; ipc_modules = ipc_modules->next;
while(l) { l = m->data;
while (l)
{
m->ipc_exit(&l->server); m->ipc_exit(&l->server);
l=l->next; l = l->next;
} }
free(m); } free(m);
return ECORE_CONFIG_ERR_IGNORED; } }
return ECORE_CONFIG_ERR_IGNORED;
}
Ecore_Config_Server *
_ecore_config_ipc_init(char *pipe_name)
Ecore_Config_Server *_ecore_config_ipc_init(char *pipe_name) { {
char buf[PATH_MAX]; char buf[PATH_MAX];
glob_t globbuf; glob_t globbuf;
int ret; int ret;
@ -238,13 +280,16 @@ Ecore_Config_Server *_ecore_config_ipc_init(char *pipe_name) {
Ecore_Config_Ipc *nm; Ecore_Config_Ipc *nm;
Ecore_Config_Server *list; Ecore_Config_Server *list;
Ecore_Config_Server *ret_srv; Ecore_Config_Server *ret_srv;
nm=NULL;
list=NULL;
ret_srv=NULL;
if (nm) { nm = NULL;
list=(Ecore_Config_Server *)nm->data; list = NULL;
while (list) { ret_srv = NULL;
if (nm)
{
list = (Ecore_Config_Server *) nm->data;
while (list)
{
if (!strcmp(list->name, pipe_name)) if (!strcmp(list->name, pipe_name))
return NULL; return NULL;
@ -252,82 +297,113 @@ Ecore_Config_Server *_ecore_config_ipc_init(char *pipe_name) {
} }
} }
list=NULL; list = NULL;
if (ipc_modules) { if (ipc_modules)
{
nm = ipc_modules; nm = ipc_modules;
while (nm) { while (nm)
list=malloc(sizeof(Ecore_Config_Server)); {
list = malloc(sizeof(Ecore_Config_Server));
memset(list, 0, sizeof(Ecore_Config_Server)); memset(list, 0, sizeof(Ecore_Config_Server));
if((ret=nm->ipc_init(pipe_name,&list->server))!=ECORE_CONFIG_ERR_SUCC) { if ((ret =
E(2,"_ecore_config_ipc_init: failed to register %s, code %d\n", pipe_name, ret); nm->ipc_init(pipe_name,
&list->server)) != ECORE_CONFIG_ERR_SUCC)
{
E(2,
"_ecore_config_ipc_init: failed to register %s, code %d\n",
pipe_name, ret);
break; break;
} }
E(2,"_ecore_config_ipc_init: registered \"%s\"...\n",pipe_name); E(2, "_ecore_config_ipc_init: registered \"%s\"...\n", pipe_name);
list->name=strdup(pipe_name); list->name = strdup(pipe_name);
list->next=nm->data; list->next = nm->data;
nm->data=list; nm->data = list;
if (!ret_srv) ret_srv=list; if (!ret_srv)
ret_srv = list;
nm = nm->next; nm = nm->next;
} }
return ret_srv; return ret_srv;
} }
if(((ret=snprintf(buf,PATH_MAX,PACKAGE_LIB_DIR "/ecore_config_ipc_*.so"))<0)|| if (((ret =
(ret>=PATH_MAX)) snprintf(buf, PATH_MAX, PACKAGE_LIB_DIR "/ecore_config_ipc_*.so")) < 0)
|| (ret >= PATH_MAX))
return NULL; return NULL;
glob(buf,0,NULL,&globbuf); glob(buf, 0, NULL, &globbuf);
if(!globbuf.gl_pathc) if (!globbuf.gl_pathc)
return NULL; return NULL;
for(c=0;c<globbuf.gl_pathc;c++) { for (c = 0; c < globbuf.gl_pathc; c++)
if(!(nm=malloc(sizeof(Ecore_Config_Ipc)))) { {
ret=ECORE_CONFIG_ERR_OOM; if (!(nm = malloc(sizeof(Ecore_Config_Ipc))))
goto done; } {
memset(nm,0,sizeof(Ecore_Config_Ipc)); ret = ECORE_CONFIG_ERR_OOM;
goto done;
}
memset(nm, 0, sizeof(Ecore_Config_Ipc));
E(1,"_ecore_config_ipc_init: checking \"%s\"...\n",globbuf.gl_pathv[c]); E(1, "_ecore_config_ipc_init: checking \"%s\"...\n",
ret=dlmulti("IPC-plugin",globbuf.gl_pathv[c],RTLD_NOW,&nm->lib, globbuf.gl_pathv[c]);
ret =
dlmulti("IPC-plugin", globbuf.gl_pathv[c], RTLD_NOW, &nm->lib,
"!_ecore_config_mod_init !_ecore_config_mod_exit !_ecore_config_mod_poll", "!_ecore_config_mod_init !_ecore_config_mod_exit !_ecore_config_mod_poll",
&nm->ipc_init,&nm->ipc_exit,&nm->ipc_poll); &nm->ipc_init, &nm->ipc_exit, &nm->ipc_poll);
if(ret==ECORE_CONFIG_ERR_NODATA) if (ret == ECORE_CONFIG_ERR_NODATA)
E(0,"_ecore_config_ipc_init: could not load \"%s\": %s...\n",globbuf.gl_pathv[c],dlerror()); E(0, "_ecore_config_ipc_init: could not load \"%s\": %s...\n",
else if(ret==ECORE_CONFIG_ERR_SUCC) { globbuf.gl_pathv[c], dlerror());
list=malloc(sizeof(Ecore_Config_Server)); else if (ret == ECORE_CONFIG_ERR_SUCC)
{
list = malloc(sizeof(Ecore_Config_Server));
/* memcpy(list, 0, sizeof(Ecore_Config_Server));*/ /* memcpy(list, 0, sizeof(Ecore_Config_Server));*/
if((ret=nm->ipc_init(pipe_name,&list->server))!=ECORE_CONFIG_ERR_SUCC) if ((ret =
E(0,"_ecore_config_ipc_init: could not initialize \"%s\": %d\n",globbuf.gl_pathv[c],ret); nm->ipc_init(pipe_name,
else { &list->server)) != ECORE_CONFIG_ERR_SUCC)
char *p=globbuf.gl_pathv[c]; E(0,
if(DEBUG!=0) { "_ecore_config_ipc_init: could not initialize \"%s\": %d\n",
char *q=strrchr(p,DIR_DELIMITER); globbuf.gl_pathv[c], ret);
if(q) else
p=++q; } {
E(0,"_ecore_config_ipc_init: adding \"%s\"...\n",p); char *p = globbuf.gl_pathv[c];
E(2,"_ecore_config_ipc_init: registered \"%s\"...\n",pipe_name);
list->name=strdup(pipe_name); if (DEBUG != 0)
list->next=nm->data; {
nm->data=list; char *q = strrchr(p, DIR_DELIMITER);
if (!ret_srv) ret_srv=list;
nm->next=ipc_modules; if (q)
ipc_modules=nm; }} p = ++q;
if(ret!=ECORE_CONFIG_ERR_SUCC) }
free(nm); } E(0, "_ecore_config_ipc_init: adding \"%s\"...\n", p);
E(2, "_ecore_config_ipc_init: registered \"%s\"...\n",
pipe_name);
list->name = strdup(pipe_name);
list->next = nm->data;
nm->data = list;
if (!ret_srv)
ret_srv = list;
nm->next = ipc_modules;
ipc_modules = nm;
}
}
if (ret != ECORE_CONFIG_ERR_SUCC)
free(nm);
}
done: done:
globfree(&globbuf); globfree(&globbuf);
if(ipc_modules) { if (ipc_modules)
ipc_timer=timeout_add(100,_ecore_config_ipc_poll,ipc_modules); } {
return ret_srv; } ipc_timer = timeout_add(100, _ecore_config_ipc_poll, ipc_modules);
}
return ret_srv;
}
/*****************************************************************************/ /*****************************************************************************/

File diff suppressed because it is too large Load Diff

View File

@ -1,58 +1,63 @@
#define TIMER_STOP 0 #define TIMER_STOP 0
#define TIMER_CONT 1 #define TIMER_CONT 1
typedef struct _estring { typedef struct _estring
{
char *str; char *str;
int alloc,used; int alloc, used;
} estring; } estring;
typedef struct _eslist { typedef struct _eslist
{
void *payload; void *payload;
struct _eslist *next; struct _eslist *next;
} eslist; } eslist;
int parse_line(char *, char **, char **, char **, char **);
int parse_line(char *,char **,char **,char **,char **);
char *unit_size(char *size); char *unit_size(char *size);
/*unsigned long now(long delay);*/ /*unsigned long now(long delay);*/
void qsrt(void *a[],void *data,int lo,int hi,int (*compare)(const void *,const void *,const void *)); void qsrt(void *a[], void *data, int lo, int hi,
int dlmulti(char *name,char *file,int flag,void **libr,const char *fmt, ...); int (*compare) (const void *, const void *,
const void *));
int dlmulti(char *name, char *file, int flag, void **libr,
const char *fmt, ...);
typedef void (*hash_walker) (char *key, void *value, void *data);
void *hash_table_new(void (*freekey), void (*freeval));
typedef void (*hash_walker)(char *key,void *value,void *data); void *hash_table_fetch(void *hashtable, char *key);
int hash_table_insert(void *hashtable, char *key, void *value);
void *hash_table_new( void (*freekey),void (*freeval)); int hash_table_replace(void *hashtable, char *key, void *value);
void *hash_table_fetch( void *hashtable,char *key); int hash_table_remove(void *hashtable, char *key);
int hash_table_insert( void *hashtable,char *key,void *value); int hash_table_dst(void *hashtable);
int hash_table_replace(void *hashtable,char *key,void *value); int hash_table_walk(void *hashtable, hash_walker fun,
int hash_table_remove( void *hashtable,char *key); void *data);
int hash_table_dst( void *hashtable);
int hash_table_walk( void *hashtable,hash_walker fun,void *data);
int eslist_free(eslist **); int eslist_free(eslist **);
int eslist_next(eslist **); int eslist_next(eslist **);
#define ESLIST_NEXT(e) (e=e->next) #define ESLIST_NEXT(e) (e=e->next)
void *eslist_payload(eslist **); void *eslist_payload(eslist **);
#define ESLIST_PAYLOAD(e) ((e)->payload) #define ESLIST_PAYLOAD(e) ((e)->payload)
int eslist_prepend(eslist **,void *); int eslist_prepend(eslist **, void *);
int eslist_append(eslist **,void *); int eslist_append(eslist **, void *);
estring *estring_new(int size); estring *estring_new(int size);
estring *estring_dst(estring *e); estring *estring_dst(estring * e);
char *estring_disown(estring *e); char *estring_disown(estring * e);
char *estring_free(estring *e,int release_payload); /* glib compat */ char *estring_free(estring * e, int release_payload); /* glib compat */
int estring_printf(estring *e,char *fmt, ...); int estring_printf(estring * e, char *fmt, ...);
int estring_appendf(estring *e,char *fmt, ...); int estring_appendf(estring * e, char *fmt, ...);
int estring_truncate(estring *e,int size); int estring_truncate(estring * e, int size);
#define ESTRING_GET_CSTRING(a) ((a)->str) #define ESTRING_GET_CSTRING(a) ((a)->str)
int esprintf(char **result,char *fmt, ...); int esprintf(char **result, char *fmt, ...);
int ejoin(char **result,char *delim, ...); int ejoin(char **result, char *delim, ...);
int ecat(char **result, ...); int ecat(char **result, ...);
unsigned long timeout_add(unsigned int f, int (*fun) (void *),
void *data);
unsigned long timeout_add(unsigned int f,int(*fun)(void *),void *data);
int timeout_remove(unsigned long handle); int timeout_remove(unsigned long handle);