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
* @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.
* Using individual header files should not be necessary.
*/
@ -41,137 +37,168 @@
/* structures */
typedef enum Ecore_Config_Type {
PT_NIL=0,
PT_INT=1,
PT_FLT=2,
PT_STR=3,
PT_RGB=4,
PT_THM=5
/**
* Valid configuration property types.
*/
typedef enum Ecore_Config_Type
{
PT_NIL = 0, ///< Property with no value.
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;
typedef enum Ecore_Config_Flag {
PF_NONE=0,
PF_BOUNDS=1,
PF_MODIFIED=2,
PF_SYSTEM=4
typedef enum Ecore_Config_Flag
{
PF_NONE = 0,
PF_BOUNDS = 1,
PF_MODIFIED = 2,
PF_SYSTEM = 4
} 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 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;
const char *name;
void *data;
int tag;
struct Ecore_Config_Listener_List *next; } Ecore_Config_Listener_List;
typedef struct Ecore_Config_Listener_List
{
Ecore_Config_Listener listener;
const char *name;
void *data;
int tag;
struct Ecore_Config_Listener_List *next;
} Ecore_Config_Listener_List;
/**
* The actual property for storing a key-value pair.
*/
typedef struct Ecore_Config_Prop {
char *key;
char *description;
char short_opt;
char *long_opt;
char *ptr;
Ecore_Config_Type type;
long val,lo,hi,step;
Ecore_Config_Flag flags;
Ecore_Config_Listener_List *listeners;
void *data;
struct Ecore_Config_Prop *next; /**< pointer to the next property in the list */
} Ecore_Config_Prop;
typedef struct Ecore_Config_Prop
{
char *key; ///< Property key.
char *description; ///< Description set by ecore_config_descibe.
char short_opt;
char *long_opt;
char *ptr; ///< Used as the value when the property is a string or theme.
Ecore_Config_Type type; ///< Property type.
long val; ///< Used as the value when the property is an integer, float or colour.
long lo; ///< Lower bound for the value when the property is an integer or float.
long hi; ///< Higher bound for the value when the property is an integer or float.
long step; ///< Increment for the value when the property is an integer or float.
Ecore_Config_Flag flags; /// < Configuration flags.
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
* use different set of properties at any time. This is useful for multiple
* window support.
/*
* A container for a list of properties. Provided so that an
* application can use different set of properties at any time. This
* is useful for multiple window support.
*/
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 */
long serial; /**< unique identifier to identify bundle */
Ecore_Config_Prop *data; /**< pointer to root of property list */
void *user_data; /**< app specific pointer to "other data" */
struct Ecore_Config_Bundle *next; /**< pointer to next bundle in this application */
} 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
long serial; ///< Unique identifier to identify bundle
Ecore_Config_Prop *data; ///< Pointer to root of property list
void *user_data; ///< App specific pointer to "other data"
struct Ecore_Config_Bundle *next; ///< Pointer to next bundle in this application
} Ecore_Config_Bundle;
typedef struct Ecore_Config_Server {
void *server;
char *name;
Ecore_Config_Bundle *bundles; /* data anchor */
struct Ecore_Config_Server *next; } Ecore_Config_Server;
typedef struct Ecore_Config_Server
{
void *server;
char *name;
Ecore_Config_Bundle *bundles; /* data anchor */
struct Ecore_Config_Server *next;
} Ecore_Config_Server;
# ifdef __cplusplus
extern "C" {
extern "C"
{
# endif
/* global ptrs to save passing them through the API */
extern Ecore_Config_Server *__ecore_config_server_global;
extern Ecore_Config_Server *__ecore_config_server_local;
extern Ecore_Config_Bundle *__ecore_config_bundle_local;
extern char *__ecore_config_app_name;
extern Ecore_Config_Server *__ecore_config_server_global;
extern Ecore_Config_Server *__ecore_config_server_local;
extern Ecore_Config_Bundle *__ecore_config_bundle_local;
extern char *__ecore_config_app_name;
Ecore_Config_Prop *ecore_config_get(const char *key);
const char *ecore_config_get_type(const Ecore_Config_Prop *e);
void *ecore_config_get_data(const char *key);
char *ecore_config_get_string(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);
float ecore_config_get_float(const char *key);
char *ecore_config_get_theme(const char *key);
char *ecore_config_get_as_string(const char *key);
int ecore_config_describe(const char *key, char *desc);
int ecore_config_set_short_opt(const char *key, char short_opt);
int ecore_config_set_long_opt(const char *key, char *long_opt);
int ecore_config_set(const char *key,char *val);
int ecore_config_set_typed(const char *key,void *val,int type);
int ecore_config_set_string(const char *key,char *val);
int ecore_config_set_int(const char *key,int val);
int ecore_config_set_rgb(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);
Ecore_Config_Prop *ecore_config_get(const char *key);
const char *ecore_config_get_type(const Ecore_Config_Prop * e);
void *ecore_config_get_data(const char *key);
char *ecore_config_get_string(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);
float ecore_config_get_float(const char *key);
char *ecore_config_get_theme(const char *key);
char *ecore_config_get_as_string(const char *key);
int ecore_config_describe(const char *key, char *desc);
int ecore_config_set_short_opt(const char *key,
char short_opt);
int ecore_config_set_long_opt(const char *key,
char *long_opt);
int ecore_config_set(const char *key, char *val);
int ecore_config_set_typed(const char *key, void *val,
int type);
int ecore_config_set_string(const char *key, char *val);
int ecore_config_set_int(const char *key, int val);
int ecore_config_set_rgb(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_typed(const char *key,void *val,int type);
int ecore_config_default_int(const char *key,int val);
int ecore_config_default_int_bound(const char *key,int val,int lo,int hi,int step);
int ecore_config_default_string(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_default(const char *key, char *val,
float lo, float hi, float step);
int ecore_config_default_typed(const char *key, void *val,
int type);
int ecore_config_default_int(const char *key, int val);
int ecore_config_default_int_bound(const char *key, int val,
int lo, int hi, int step);
int ecore_config_default_string(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_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);
int ecore_config_listen(const char *name, const char *key,
Ecore_Config_Listener listener,
int tag, void *data);
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_get_1st(Ecore_Config_Server *srv);
Ecore_Config_Bundle *ecore_config_bundle_get_next(Ecore_Config_Bundle *ns);
Ecore_Config_Bundle *ecore_config_bundle_get_by_serial(Ecore_Config_Server *srv, long serial);
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);
Ecore_Config_Bundle *ecore_config_bundle_new(Ecore_Config_Server * srv,
const char *id);
Ecore_Config_Bundle *ecore_config_bundle_get_1st(Ecore_Config_Server * srv);
Ecore_Config_Bundle *ecore_config_bundle_get_next(Ecore_Config_Bundle * ns);
Ecore_Config_Bundle *ecore_config_bundle_get_by_serial(Ecore_Config_Server *
srv, long serial);
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_shutdown(void);
int ecore_config_load(void);
int ecore_config_load_file(char *file);
int ecore_config_save(void);
int ecore_config_save_file(char *file);
int ecore_config_load(void);
int ecore_config_load_file(char *file);
int ecore_config_save(void);
int ecore_config_save_file(char *file);
/* error codes */
# 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_TYPEMISMATCH (-7)
# define ECORE_CONFIG_ERR_MUTEX (-6)
# define ECORE_CONFIG_ERR_NOTFOUND (-5)
# define ECORE_CONFIG_ERR_OOM (-4)
# define ECORE_CONFIG_ERR_IGNORED (-3)
# define ECORE_CONFIG_ERR_NODATA (-2)
# define ECORE_CONFIG_ERR_FAIL (-1)
# define ECORE_CONFIG_ERR_SUCC (0)
# define ECORE_CONFIG_ERR_NOTFOUND (-5) ///< Error indicating that the item searched for could not be found.
# define ECORE_CONFIG_ERR_OOM (-4) ///< Error given when the program runs out of memory.
# define ECORE_CONFIG_ERR_IGNORED (-3) ///< Error occurred, but was ignored.
# define ECORE_CONFIG_ERR_NODATA (-2) ///< Error given when necessary data is not provided.
# define ECORE_CONFIG_ERR_FAIL (-1) ///< Failure result.
# define ECORE_CONFIG_ERR_SUCC (0) ///< Success result.
# define ECORE_CONFIG_PARSE_HELP (-2)
# define ECORE_CONFIG_PARSE_EXIT (-1)
# define ECORE_CONFIG_PARSE_CONTINUE (0)
/* convenience mathods in convenience.c */
int ecore_config_evas_font_path_apply(Evas *evas);
void ecore_config_args_display(void);
int ecore_config_args_parse(int argc, char **argv);
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_evas_font_path_apply(Evas * evas);
void ecore_config_args_display(void);
int ecore_config_args_parse(int argc, char **argv);
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);
# ifdef __cplusplus
}

View File

@ -4,236 +4,334 @@
#include <stdio.h>
#include <stdlib.h>
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 ;) */
int ecore_config_create(const char *key, void *val, char short_opt, char *long_opt, char *desc) {
int type=ecore_config_guess_type(key, val);
return ecore_config_create_typed(key, val, type, short_opt, long_opt, desc);}
int
ecore_config_create(const char *key, void *val, char short_opt, char *long_opt,
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) {
int ret;
return ecore_config_create_typed(key, val, type, short_opt, long_opt, desc);
}
if ((ret=ecore_config_default_typed(key, val, type)) != ECORE_CONFIG_ERR_SUCC)
return ret;
if ((ret=ecore_config_set_short_opt(key, short_opt)) != ECORE_CONFIG_ERR_SUCC)
return ret;
if ((ret=ecore_config_set_long_opt(key, long_opt)) != ECORE_CONFIG_ERR_SUCC)
return ret;
ret=ecore_config_describe(key, desc);
return ret;}
int ecore_config_create_int(const char *key, int val, char short_opt, char *long_opt, char *desc) {
return
ecore_config_create_typed(key, (void *)&val, PT_INT, 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 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;
int ret;
ret=
ecore_config_create_typed(key, (void *)&val, PT_INT, short_opt, long_opt, desc);
if (ret != ECORE_CONFIG_ERR_SUCC)
return ret;
e=ecore_config_get(key);
if (e) {
e->step=step;
e->flags|=PF_BOUNDS;
e->lo=low;
e->hi=high;
ecore_config_bound(e);
}
return ret;}
if ((ret =
ecore_config_default_typed(key, val, type)) != ECORE_CONFIG_ERR_SUCC)
return ret;
if ((ret =
ecore_config_set_short_opt(key, short_opt)) != ECORE_CONFIG_ERR_SUCC)
return ret;
if ((ret =
ecore_config_set_long_opt(key, long_opt)) != ECORE_CONFIG_ERR_SUCC)
return ret;
ret = ecore_config_describe(key, desc);
return ret;
}
int ecore_config_create_string(const char *key, char *val, char short_opt, char *long_opt, char *desc) {
return
ecore_config_create_typed(key, (void *)val, PT_STR, short_opt, long_opt, desc);}
int
ecore_config_create_int(const char *key, int val, char short_opt,
char *long_opt, char *desc)
{
return
ecore_config_create_typed(key, (void *)&val, PT_INT, short_opt, long_opt,
desc);
}
int ecore_config_create_float(const char *key, float val, char short_opt, char *long_opt, char *desc) {
return
ecore_config_create_typed(key, (void *)&val, PT_FLT, 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)
{
Ecore_Config_Prop *e;
int ret;
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;
int ret;
ret=
ecore_config_create_typed(key, (void *)&val, PT_FLT, short_opt, long_opt, desc);
e=ecore_config_get(key);
if (e) {
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);
}
return ret;}
ret =
ecore_config_create_typed(key, (void *)&val, PT_INT, short_opt, long_opt,
desc);
if (ret != ECORE_CONFIG_ERR_SUCC)
return ret;
e = ecore_config_get(key);
if (e)
{
e->step = step;
e->flags |= PF_BOUNDS;
e->lo = low;
e->hi = high;
ecore_config_bound(e);
}
return ret;
}
int ecore_config_create_rgb(const char *key, char *val, char short_opt, char *long_opt, char *desc) {
return
ecore_config_create_typed(key, (void *)val, PT_RGB, short_opt, long_opt, desc);}
int
ecore_config_create_string(const char *key, char *val, char short_opt,
char *long_opt, char *desc)
{
return
ecore_config_create_typed(key, (void *)val, PT_STR, short_opt, long_opt,
desc);
}
int ecore_config_create_theme(const char *key, char *val, char short_opt, char *long_opt, char *desc) {
return
ecore_config_create_typed(key, (void *)val, PT_THM, short_opt, long_opt, desc);}
int
ecore_config_create_float(const char *key, float val, char short_opt,
char *long_opt, char *desc)
{
return
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)
{
Ecore_Config_Prop *e;
int ret;
ret =
ecore_config_create_typed(key, (void *)&val, PT_FLT, short_opt, long_opt,
desc);
e = ecore_config_get(key);
if (e)
{
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);
}
return ret;
}
int
ecore_config_create_rgb(const char *key, char *val, char short_opt,
char *long_opt, char *desc)
{
return
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)
{
return
ecore_config_create_typed(key, (void *)val, PT_THM, short_opt, long_opt,
desc);
}
/* 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
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)
return ECORE_CONFIG_ERR_NODATA;
ptr = font_path;
end = font_path + strlen (font_path);
font_path_tmp = font_path;
while (ptr && ptr < end)
{
while (*ptr != '|' && ptr < end)
ptr++;
if (ptr < end)
*ptr = '\0';
if (!font_path)
return ECORE_CONFIG_ERR_NODATA;
ptr = font_path;
end = font_path + strlen(font_path);
font_path_tmp = font_path;
while (ptr && ptr < end)
{
while (*ptr != '|' && ptr < end)
ptr++;
if (ptr < end)
*ptr = '\0';
evas_font_path_append (evas, font_path_tmp);
ptr++;
font_path_tmp = ptr;
}
evas_font_path_append(evas, 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
ecore_config_args_display(void)
{
Ecore_Config_Prop *props;
if (__ecore_config_app_description)
printf("%s\n\n", __ecore_config_app_description);
printf("Supported Options:\n");
printf(" -h, --help\t Print this text\n");
if (!__ecore_config_bundle_local) return;
props = __ecore_config_bundle_local->data;
while (props)
{
if (props->flags&PF_SYSTEM) {
props = props->next;
continue;
}
printf(" %c%c%c --%s\t<%s> %s\n", props->short_opt?'-':' ',
props->short_opt?props->short_opt:' ', props->short_opt?',':' ',
props->long_opt?props->long_opt:props->key,
_ecore_config_short_types[props->type],
props->description?props->description:"(no description available)");
props = props->next;
}
Ecore_Config_Prop *props;
if (__ecore_config_app_description)
printf("%s\n\n", __ecore_config_app_description);
printf("Supported Options:\n");
printf(" -h, --help\t Print this text\n");
if (!__ecore_config_bundle_local)
return;
props = __ecore_config_bundle_local->data;
while (props)
{
if (props->flags & PF_SYSTEM)
{
props = props->next;
continue;
}
printf(" %c%c%c --%s\t<%s> %s\n", props->short_opt ? '-' : ' ',
props->short_opt ? props->short_opt : ' ',
props->short_opt ? ',' : ' ',
props->long_opt ? props->long_opt : props->key,
_ecore_config_short_types[props->type],
props->description ? props->
description : "(no description available)");
props = props->next;
}
}
int
ecore_config_parse_set(Ecore_Config_Prop *prop,char *arg,char *opt,char opt2) {
if (!arg) {
if (opt)
printf("Missing expected argument for option --%s\n", opt);
else
printf("Missing expected argument for option -%c\n", opt2);
return ECORE_CONFIG_PARSE_EXIT;
} else
ecore_config_set(prop->key, arg);
return ECORE_CONFIG_PARSE_CONTINUE;
ecore_config_parse_set(Ecore_Config_Prop * prop, char *arg, char *opt,
char opt2)
{
if (!arg)
{
if (opt)
printf("Missing expected argument for option --%s\n", opt);
else
printf("Missing expected argument for option -%c\n", opt2);
return ECORE_CONFIG_PARSE_EXIT;
}
else
ecore_config_set(prop->key, arg);
return ECORE_CONFIG_PARSE_CONTINUE;
}
int
ecore_config_args_parse(int argc, char **argv)
{
int nextarg, next_short_opt, found, ret;
char *arg;
char *long_opt, short_opt;
Ecore_Config_Prop *prop;
nextarg = 1;
while (nextarg < argc) {
arg = argv[nextarg];
int nextarg, next_short_opt, found, ret;
char *arg;
char *long_opt, short_opt;
Ecore_Config_Prop *prop;
if (*arg != '-') {
printf("Unexpected attribute \"%s\"\n", arg);
nextarg++;
continue;
}
next_short_opt = 1;
short_opt = *(arg + next_short_opt);
nextarg = 1;
while (nextarg < argc)
{
arg = argv[nextarg];
if (short_opt == '-') {
long_opt = arg + 2;
if (!strcmp(long_opt, "help")) {
ecore_config_args_display();
return ECORE_CONFIG_PARSE_HELP;
}
if (*arg != '-')
{
printf("Unexpected attribute \"%s\"\n", arg);
nextarg++;
continue;
}
found = 0;
prop = __ecore_config_bundle_local->data;
while (prop) {
if ((prop->long_opt && !strcmp(long_opt, prop->long_opt))
|| !strcmp(long_opt, prop->key)) {
found = 1;
if ((ret=ecore_config_parse_set(prop, argv[++nextarg], long_opt,'\0'))
!= ECORE_CONFIG_PARSE_CONTINUE);
return ret;
break;
}
prop = prop->next;
}
if (!found) {
printf("Unrecognised option \"%s\"\n", long_opt);
printf("Try using -h or --help for more information.\n\n");
return ECORE_CONFIG_PARSE_EXIT;
}
} else {
while (short_opt) {
if (short_opt == 'h') {
ecore_config_args_display();
return ECORE_CONFIG_PARSE_HELP;
} else {
found = 0;
prop = __ecore_config_bundle_local->data;
while (prop) {
if (short_opt == prop->short_opt) {
found = 1;
if ((ret=ecore_config_parse_set(prop, argv[++nextarg], NULL, short_opt))
!= ECORE_CONFIG_PARSE_CONTINUE)
return ret;
break;
}
prop = prop->next;
}
if (!found) {
printf("Unrecognised option '%c'\n", short_opt);
printf("Try using -h or --help for more information.\n\n");
return ECORE_CONFIG_PARSE_EXIT;
}
}
short_opt = *(arg + ++next_short_opt);
}
}
nextarg++;
}
next_short_opt = 1;
short_opt = *(arg + next_short_opt);
return ECORE_CONFIG_PARSE_CONTINUE;
if (short_opt == '-')
{
long_opt = arg + 2;
if (!strcmp(long_opt, "help"))
{
ecore_config_args_display();
return ECORE_CONFIG_PARSE_HELP;
}
found = 0;
prop = __ecore_config_bundle_local->data;
while (prop)
{
if ((prop->long_opt && !strcmp(long_opt, prop->long_opt))
|| !strcmp(long_opt, prop->key))
{
found = 1;
if ((ret =
ecore_config_parse_set(prop, argv[++nextarg],
long_opt,
'\0')) !=
ECORE_CONFIG_PARSE_CONTINUE);
return ret;
break;
}
prop = prop->next;
}
if (!found)
{
printf("Unrecognised option \"%s\"\n", long_opt);
printf("Try using -h or --help for more information.\n\n");
return ECORE_CONFIG_PARSE_EXIT;
}
}
else
{
while (short_opt)
{
if (short_opt == 'h')
{
ecore_config_args_display();
return ECORE_CONFIG_PARSE_HELP;
}
else
{
found = 0;
prop = __ecore_config_bundle_local->data;
while (prop)
{
if (short_opt == prop->short_opt)
{
found = 1;
if ((ret =
ecore_config_parse_set(prop,
argv[++nextarg],
NULL,
short_opt)) !=
ECORE_CONFIG_PARSE_CONTINUE)
return ret;
break;
}
prop = prop->next;
}
if (!found)
{
printf("Unrecognised option '%c'\n", short_opt);
printf
("Try using -h or --help for more information.\n\n");
return ECORE_CONFIG_PARSE_EXIT;
}
}
short_opt = *(arg + ++next_short_opt);
}
}
nextarg++;
}
return ECORE_CONFIG_PARSE_CONTINUE;
}
void
ecore_config_app_describe(char *description) {
if (__ecore_config_app_description)
free(__ecore_config_app_description);
__ecore_config_app_description = strdup(description);
ecore_config_app_describe(char *description)
{
if (__ecore_config_app_description)
free(__ecore_config_app_description);
__ecore_config_app_description = strdup(description);
}

File diff suppressed because it is too large Load Diff

View File

@ -10,151 +10,214 @@
#include <sys/stat.h>
#include <unistd.h>
int ecore_config_load(void) {
char file[PATH_MAX];
snprintf(file, PATH_MAX, "%s/.e/apps/%s/config.db",getenv("HOME"),__ecore_config_app_name);
return ecore_config_load_file(file);
/**
* 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];
snprintf(file, PATH_MAX, "%s/.e/apps/%s/config.db", getenv("HOME"),
__ecore_config_app_name);
return ecore_config_load_file(file);
}
int ecore_config_save(void) {
char file[PATH_MAX];
snprintf(file, PATH_MAX, "%s/.e/apps/%s/config.db",getenv("HOME"),__ecore_config_app_name);
return ecore_config_save_file(file);
/**
* 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];
snprintf(file, PATH_MAX, "%s/.e/apps/%s/config.db", getenv("HOME"),
__ecore_config_app_name);
return ecore_config_save_file(file);
}
int ecore_config_load_file(char *file) {
E_DB_File *db;
char **keys;
int key_count;
int x;
int itmp;
float ftmp;
char *type;
char *data;
db=NULL;
type = NULL;
data = NULL;
db = e_db_open_read(file);
if (!db) {
E(0, "Cannot open database from file %s!\n", file);
return ECORE_CONFIG_ERR_NODATA;
}
/**
* 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;
char **keys;
int key_count;
int x;
int itmp;
float ftmp;
char *type;
char *data;
keys = e_db_dump_key_list(file, &key_count);
for (x = 0; x < key_count; x++) {
db = NULL;
type = NULL;
data = NULL;
type = e_db_type_get(db, keys[x]);
if (!type) type = "?";
db = e_db_open_read(file);
if (!db)
{
E(0, "Cannot open database from file %s!\n", file);
return ECORE_CONFIG_ERR_NODATA;
}
if (!strcmp(type, "int")) {
if (e_db_int_get(db, keys[x], &itmp)) {
ecore_config_set_int(keys[x], itmp);
} else {
E(0, "Could not read key %s!\n", keys[x]);
}
} else if (!strcmp(type, "float")) {
if (e_db_float_get(db, keys[x], &ftmp)) {
ecore_config_set_float(keys[x], ftmp);
} else {
E(0, "Could not read key %s!\n", keys[x]);
}
} else if (!strcmp(type, "str")) {
data = e_db_str_get(db, keys[x]);
if (data) {
itmp = ecore_config_guess_type(keys[x],data);
switch (itmp) {
case PT_RGB:
ecore_config_set_rgb(keys[x],data);
break;
case PT_THM:
ecore_config_set_theme(keys[x],data);
break;
default:
ecore_config_set_string(keys[x],data);
}
free(data);
} else {
E(0, "Could not read key %s!\n", keys[x]);
}
} else {
E(1, "Unexpected type: %s\n", type);
continue;
}
if (type) free(type);
}
e_db_close(db);
free(keys);
return ECORE_CONFIG_ERR_SUCC;
}
static void
_ecore_config_recurse_mkdir(char *file) {
char *file_ptr;
char *file_tmp;
struct stat status;
keys = e_db_dump_key_list(file, &key_count);
for (x = 0; x < key_count; x++)
{
file_tmp = strdup(file);
file_ptr = file_tmp + strlen(file_tmp);
while (*file_ptr != '/' && file_ptr > file_tmp)
file_ptr--;
*file_ptr = '\0';
type = e_db_type_get(db, keys[x]);
if (!type)
type = "?";
if(stat(file_tmp, &status)) {
_ecore_config_recurse_mkdir(file_tmp);
mkdir(file_tmp, S_IRUSR | S_IWUSR | S_IXUSR);
}
free(file_tmp);
if (!strcmp(type, "int"))
{
if (e_db_int_get(db, keys[x], &itmp))
{
ecore_config_set_int(keys[x], itmp);
}
else
{
E(0, "Could not read key %s!\n", keys[x]);
}
}
else if (!strcmp(type, "float"))
{
if (e_db_float_get(db, keys[x], &ftmp))
{
ecore_config_set_float(keys[x], ftmp);
}
else
{
E(0, "Could not read key %s!\n", keys[x]);
}
}
else if (!strcmp(type, "str"))
{
data = e_db_str_get(db, keys[x]);
if (data)
{
itmp = ecore_config_guess_type(keys[x], data);
switch (itmp)
{
case PT_RGB:
ecore_config_set_rgb(keys[x], data);
break;
case PT_THM:
ecore_config_set_theme(keys[x], data);
break;
default:
ecore_config_set_string(keys[x], data);
}
free(data);
}
else
{
E(0, "Could not read key %s!\n", keys[x]);
}
}
else
{
E(1, "Unexpected type: %s\n", type);
continue;
}
if (type)
free(type);
}
e_db_close(db);
free(keys);
return ECORE_CONFIG_ERR_SUCC;
}
int ecore_config_save_file(char *file) {
Ecore_Config_Prop *next;
E_DB_File *db;
struct stat status;
next=__ecore_config_bundle_local->data;
db = NULL;
static void
_ecore_config_recurse_mkdir(char *file)
{
char *file_ptr;
char *file_tmp;
struct stat status;
/* if file does not exist check to see if the dirs exist, creating if not */
if(stat(file, &status))
_ecore_config_recurse_mkdir(file);
file_tmp = strdup(file);
file_ptr = file_tmp + strlen(file_tmp);
while (*file_ptr != '/' && file_ptr > file_tmp)
file_ptr--;
*file_ptr = '\0';
db = e_db_open(file);
if (!db) {
E(0, "Cannot open database from file %s!\n", file);
return ECORE_CONFIG_ERR_FAIL;
}
while (next) {
if (!(next->flags&PF_MODIFIED)) {
next=next->next;
continue;
}
switch (next->type) {
case PT_INT:
e_db_int_set(db, next->key, ecore_config_get_int(next->key));
break;
case PT_FLT:
e_db_float_set(db, next->key, ecore_config_get_float(next->key));
break;
case PT_RGB:
e_db_str_set(db, next->key, ecore_config_get_rgbstr(next->key));
break;
case PT_STR:
e_db_str_set(db, next->key, ecore_config_get_string(next->key));
break;
case PT_THM:
e_db_str_set(db, next->key, ecore_config_get_theme(next->key));
break;
case PT_NIL:
/* currently we do nothing for undefined ojects */
break;
}
next=next->next;
}
e_db_close(db);
e_db_flush();
return ECORE_CONFIG_ERR_SUCC;
if (stat(file_tmp, &status))
{
_ecore_config_recurse_mkdir(file_tmp);
mkdir(file_tmp, S_IRUSR | S_IWUSR | S_IXUSR);
}
free(file_tmp);
}
/**
* 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;
E_DB_File *db;
struct stat status;
next = __ecore_config_bundle_local->data;
db = NULL;
/* if file does not exist check to see if the dirs exist, creating if not */
if (stat(file, &status))
_ecore_config_recurse_mkdir(file);
db = e_db_open(file);
if (!db)
{
E(0, "Cannot open database from file %s!\n", file);
return ECORE_CONFIG_ERR_FAIL;
}
while (next)
{
if (!(next->flags & PF_MODIFIED))
{
next = next->next;
continue;
}
switch (next->type)
{
case PT_INT:
e_db_int_set(db, next->key, ecore_config_get_int(next->key));
break;
case PT_FLT:
e_db_float_set(db, next->key, ecore_config_get_float(next->key));
break;
case PT_RGB:
e_db_str_set(db, next->key, ecore_config_get_rgbstr(next->key));
break;
case PT_STR:
e_db_str_set(db, next->key, ecore_config_get_string(next->key));
break;
case PT_THM:
e_db_str_set(db, next->key, ecore_config_get_theme(next->key));
break;
case PT_NIL:
/* currently we do nothing for undefined ojects */
break;
}
next = next->next;
}
e_db_close(db);
e_db_flush();
return ECORE_CONFIG_ERR_SUCC;
}

View File

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

View File

@ -1,7 +1,6 @@
/* ############## bad */
#define HAVE_EVAS2
#include "Ecore_Config.h"
#include "util.h"
#include "ipc.h"
@ -14,320 +13,397 @@
#include <glob.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h> /* malloc(), free() */
#include <stdlib.h> /* malloc(), free() */
#ifndef TRUE
# define FALSE 0
# define TRUE (!FALSE)
#endif
typedef struct _ecore_config_ipc {
void *lib;
void *data;
int (*ipc_init)(char *pipe_name,void **data);
int (*ipc_exit)(void **data);
int (*ipc_poll)(void **data);
struct _ecore_config_ipc *next;
typedef struct _ecore_config_ipc
{
void *lib;
void *data;
int (*ipc_init) (char *pipe_name, void **data);
int (*ipc_exit) (void **data);
int (*ipc_poll) (void **data);
struct _ecore_config_ipc *next;
} Ecore_Config_Ipc;
static Ecore_Config_Ipc *ipc_modules = NULL;
static unsigned long ipc_timer = 0L;
Ecore_Config_Server *
_ecore_config_server_convert(void *srv)
{
Ecore_Config_Ipc *ipc_tmp;
Ecore_Config_Server *srv_tmp;
static Ecore_Config_Ipc *ipc_modules=NULL;
static unsigned long ipc_timer=0L;
ipc_tmp = ipc_modules;
while (ipc_tmp)
{
srv_tmp = ipc_tmp->data;
while (srv_tmp)
{
if (srv_tmp->server == srv)
return srv_tmp;
srv_tmp = srv_tmp->next;
}
ipc_tmp = ipc_tmp->next;
}
Ecore_Config_Server *_ecore_config_server_convert(void *srv) {
Ecore_Config_Ipc *ipc_tmp;
Ecore_Config_Server *srv_tmp;
ipc_tmp = ipc_modules;
while (ipc_tmp) {
srv_tmp = ipc_tmp->data;
while (srv_tmp) {
if (srv_tmp->server == srv)
return srv_tmp;
srv_tmp=srv_tmp->next;
}
ipc_tmp = ipc_tmp->next;
}
return __ecore_config_server_global;
return __ecore_config_server_global;
}
/*****************************************************************************/
/* INTERFACE FOR IPC MODULES */
/*****************************/
char *
_ecore_config_ipc_prop_list(Ecore_Config_Server * srv, const long serial)
{
Ecore_Config_Bundle *theme;
Ecore_Config_Prop *e;
estring *s;
int f;
theme = ecore_config_bundle_get_by_serial(srv, serial);
e = theme ? theme->data : NULL;
s = estring_new(8192);
f = 0;
while (e)
{
/* ignore system properties in listings, unless they have been overridden */
if (e->flags & PF_SYSTEM && !(e->flags & PF_MODIFIED))
{
e = e->next;
continue;
}
estring_appendf(s, "%s%s: %s", f ? "\n" : "", e->key,
ecore_config_get_type(e));
if (e->flags & PF_BOUNDS)
{
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
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;
}
char *_ecore_config_ipc_prop_list(Ecore_Config_Server *srv, const long serial) {
Ecore_Config_Bundle *theme;
Ecore_Config_Prop *e;
estring *s;
int f;
return estring_disown(s);
}
theme=ecore_config_bundle_get_by_serial(srv, serial);
e=theme?theme->data:NULL;
s=estring_new(8192);
f=0;
while(e) {
/* ignore system properties in listings, unless they have been overridden */
if (e->flags&PF_SYSTEM && !(e->flags&PF_MODIFIED)) {
e=e->next;
continue;
}
estring_appendf(s,"%s%s: %s",f?"\n":"",e->key,ecore_config_get_type(e));
if(e->flags&PF_BOUNDS) {
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
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; }
return estring_disown(s); }
char *_ecore_config_ipc_prop_desc(Ecore_Config_Server *srv, const long serial,const char *key) {
char *
_ecore_config_ipc_prop_desc(Ecore_Config_Server * srv, const long serial,
const char *key)
{
#ifdef HAVE_EVAS2
Ecore_Config_Bundle *theme;
Ecore_Config_Prop *e;
theme=ecore_config_bundle_get_by_serial(srv, serial);
e=ecore_config_get(key);
Ecore_Config_Bundle *theme;
Ecore_Config_Prop *e;
if(e) {
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); }
theme = ecore_config_bundle_get_by_serial(srv, serial);
e = ecore_config_get(key);
if (e)
{
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
return strdup("<undefined>"); }
return strdup("<undefined>");
}
char *_ecore_config_ipc_prop_get(Ecore_Config_Server *srv, const long serial,const char *key) {
char *
_ecore_config_ipc_prop_get(Ecore_Config_Server * srv, const long serial,
const char *key)
{
#ifdef HAVE_EVAS2
char *ret;
Ecore_Config_Bundle *theme;
ret=NULL;
theme=ecore_config_bundle_get_by_serial(srv, serial);
if((ret=ecore_config_get_as_string(/*theme,*/key)))
return ret;
char *ret;
Ecore_Config_Bundle *theme;
ret = NULL;
theme = ecore_config_bundle_get_by_serial(srv, serial);
if ((ret = ecore_config_get_as_string( /*theme, */ key)))
return ret;
#endif
return strdup("<undefined>"); }
return strdup("<undefined>");
}
int _ecore_config_ipc_prop_set(Ecore_Config_Server *srv, const long serial,const char *key,const char *val) {
int
_ecore_config_ipc_prop_set(Ecore_Config_Server * srv, const long serial,
const char *key, const char *val)
{
#ifdef HAVE_EVAS2
int ret;
Ecore_Config_Bundle *theme;
theme=ecore_config_bundle_get_by_serial(srv, serial);
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;
int ret;
Ecore_Config_Bundle *theme;
theme = ecore_config_bundle_get_by_serial(srv, serial);
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;
#else
return ECORE_CONFIG_ERR_NOTSUPP;
return ECORE_CONFIG_ERR_NOTSUPP;
#endif
}
/*****************************************************************************/
char *
_ecore_config_ipc_bundle_list(Ecore_Config_Server * srv)
{
Ecore_Config_Bundle *ns;
estring *s;
int f;
char *_ecore_config_ipc_bundle_list(Ecore_Config_Server *srv) {
Ecore_Config_Bundle *ns;
estring *s;
int f;
ns = ecore_config_bundle_get_1st(srv);
s = estring_new(8192);
f = 0;
if (!ns)
return strdup("<no_bundles_created>");
ns=ecore_config_bundle_get_1st(srv);
s=estring_new(8192);
f=0;
if(!ns)
return strdup("<no_bundles_created>");
while (ns)
{
estring_appendf(s, "%s%d: %s", f ? "\n" : "",
ecore_config_bundle_get_serial(ns),
ecore_config_bundle_get_label(ns));
f = 1;
ns = ecore_config_bundle_get_next(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;
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)
{
if (ecore_config_bundle_new(srv, label))
return ECORE_CONFIG_ERR_SUCC;
return ECORE_CONFIG_ERR_FAIL;
}
char *
_ecore_config_ipc_bundle_label_get(Ecore_Config_Server * srv, const long serial)
{
Ecore_Config_Bundle *ns;
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>");
}
int _ecore_config_ipc_bundle_new(Ecore_Config_Server *srv, const char *label) {
if (ecore_config_bundle_new(srv, label))
return ECORE_CONFIG_ERR_SUCC;
return ECORE_CONFIG_ERR_FAIL; }
int
_ecore_config_ipc_bundle_label_set(Ecore_Config_Server * srv, const long serial,
const char *label)
{
Ecore_Config_Bundle *ns;
ns = ecore_config_bundle_get_by_serial(srv, serial);
if (!(ns->identifier = malloc(sizeof(label))))
return ECORE_CONFIG_ERR_OOM;
memcpy(ns->identifier, label, sizeof(label));
return ECORE_CONFIG_ERR_SUCC;
}
long
_ecore_config_ipc_bundle_label_find(Ecore_Config_Server * srv,
const char *label)
{
Ecore_Config_Bundle *ns;
char *_ecore_config_ipc_bundle_label_get(Ecore_Config_Server *srv, const long serial) {
Ecore_Config_Bundle *ns;
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_label(srv, label);
return ns ? ecore_config_bundle_get_serial(ns) : -1;
}
static int
_ecore_config_ipc_poll(void *data)
{
Ecore_Config_Ipc *m;
Ecore_Config_Server *s;
m = (Ecore_Config_Ipc *) data;
while (m)
{
s = m->data;
while (s)
{
m->ipc_poll(&s->server);
s = s->next;
}
m = m->next;
}
int _ecore_config_ipc_bundle_label_set(Ecore_Config_Server *srv, const long serial,const char *label) {
Ecore_Config_Bundle *ns;
ns=ecore_config_bundle_get_by_serial(srv, serial);
if (!(ns->identifier=malloc(sizeof(label))))
return ECORE_CONFIG_ERR_OOM;
memcpy(ns->identifier,label,sizeof(label));
return ECORE_CONFIG_ERR_SUCC; }
return TRUE;
}
int
_ecore_config_ipc_exit(void)
{
Ecore_Config_Ipc *m;
Ecore_Config_Server *l;
if (ipc_timer)
timeout_remove(ipc_timer);
while (ipc_modules)
{
m = ipc_modules;
ipc_modules = ipc_modules->next;
l = m->data;
while (l)
{
m->ipc_exit(&l->server);
l = l->next;
}
free(m);
}
return ECORE_CONFIG_ERR_IGNORED;
}
long _ecore_config_ipc_bundle_label_find(Ecore_Config_Server *srv, const char *label) {
Ecore_Config_Bundle *ns;
ns=ecore_config_bundle_get_by_label(srv, label);
return ns?ecore_config_bundle_get_serial(ns):-1; }
Ecore_Config_Server *
_ecore_config_ipc_init(char *pipe_name)
{
char buf[PATH_MAX];
glob_t globbuf;
int ret;
unsigned int c;
Ecore_Config_Ipc *nm;
Ecore_Config_Server *list;
Ecore_Config_Server *ret_srv;
nm = NULL;
list = NULL;
ret_srv = NULL;
if (nm)
{
list = (Ecore_Config_Server *) nm->data;
while (list)
{
if (!strcmp(list->name, pipe_name))
return NULL;
list = list->next;
}
}
static int _ecore_config_ipc_poll(void *data) {
Ecore_Config_Ipc *m;
Ecore_Config_Server *s;
list = NULL;
m=(Ecore_Config_Ipc *)data;
while(m) {
s = m->data;
while (s) {
m->ipc_poll(&s->server);
s = s->next;
}
m=m->next; }
if (ipc_modules)
{
nm = ipc_modules;
while (nm)
{
list = malloc(sizeof(Ecore_Config_Server));
memset(list, 0, sizeof(Ecore_Config_Server));
if ((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;
}
return TRUE; }
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 = nm->next;
}
int _ecore_config_ipc_exit(void) {
Ecore_Config_Ipc *m;
Ecore_Config_Server *l;
if(ipc_timer)
timeout_remove(ipc_timer);
while(ipc_modules) {
m=ipc_modules;
ipc_modules=ipc_modules->next;
l=m->data;
while(l) {
m->ipc_exit(&l->server);
l=l->next;
}
free(m); }
return ECORE_CONFIG_ERR_IGNORED; }
return ret_srv;
}
if (((ret =
snprintf(buf, PATH_MAX, PACKAGE_LIB_DIR "/ecore_config_ipc_*.so")) < 0)
|| (ret >= PATH_MAX))
return NULL;
glob(buf, 0, NULL, &globbuf);
if (!globbuf.gl_pathc)
return NULL;
Ecore_Config_Server *_ecore_config_ipc_init(char *pipe_name) {
char buf[PATH_MAX];
glob_t globbuf;
int ret;
unsigned int c;
Ecore_Config_Ipc *nm;
Ecore_Config_Server *list;
Ecore_Config_Server *ret_srv;
nm=NULL;
list=NULL;
ret_srv=NULL;
for (c = 0; c < globbuf.gl_pathc; c++)
{
if (!(nm = malloc(sizeof(Ecore_Config_Ipc))))
{
ret = ECORE_CONFIG_ERR_OOM;
goto done;
}
memset(nm, 0, sizeof(Ecore_Config_Ipc));
if (nm) {
list=(Ecore_Config_Server *)nm->data;
while (list) {
if (!strcmp(list->name, pipe_name))
return NULL;
list = list->next;
}
}
list=NULL;
if (ipc_modules) {
nm = ipc_modules;
while (nm) {
list=malloc(sizeof(Ecore_Config_Server));
memset(list, 0, sizeof(Ecore_Config_Server));
if((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;
}
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 = nm->next;
}
return ret_srv;
}
if(((ret=snprintf(buf,PATH_MAX,PACKAGE_LIB_DIR "/ecore_config_ipc_*.so"))<0)||
(ret>=PATH_MAX))
return NULL;
glob(buf,0,NULL,&globbuf);
if(!globbuf.gl_pathc)
return NULL;
for(c=0;c<globbuf.gl_pathc;c++) {
if(!(nm=malloc(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]);
ret=dlmulti("IPC-plugin",globbuf.gl_pathv[c],RTLD_NOW,&nm->lib,
"!_ecore_config_mod_init !_ecore_config_mod_exit !_ecore_config_mod_poll",
&nm->ipc_init,&nm->ipc_exit,&nm->ipc_poll);
if(ret==ECORE_CONFIG_ERR_NODATA)
E(0,"_ecore_config_ipc_init: could not load \"%s\": %s...\n",globbuf.gl_pathv[c],dlerror());
else if(ret==ECORE_CONFIG_ERR_SUCC) {
list=malloc(sizeof(Ecore_Config_Server));
E(1, "_ecore_config_ipc_init: checking \"%s\"...\n",
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",
&nm->ipc_init, &nm->ipc_exit, &nm->ipc_poll);
if (ret == ECORE_CONFIG_ERR_NODATA)
E(0, "_ecore_config_ipc_init: could not load \"%s\": %s...\n",
globbuf.gl_pathv[c], dlerror());
else if (ret == ECORE_CONFIG_ERR_SUCC)
{
list = malloc(sizeof(Ecore_Config_Server));
/* memcpy(list, 0, sizeof(Ecore_Config_Server));*/
if((ret=nm->ipc_init(pipe_name,&list->server))!=ECORE_CONFIG_ERR_SUCC)
E(0,"_ecore_config_ipc_init: could not initialize \"%s\": %d\n",globbuf.gl_pathv[c],ret);
else {
char *p=globbuf.gl_pathv[c];
if(DEBUG!=0) {
char *q=strrchr(p,DIR_DELIMITER);
if(q)
p=++q; }
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;
if ((ret =
nm->ipc_init(pipe_name,
&list->server)) != ECORE_CONFIG_ERR_SUCC)
E(0,
"_ecore_config_ipc_init: could not initialize \"%s\": %d\n",
globbuf.gl_pathv[c], ret);
else
{
char *p = globbuf.gl_pathv[c];
nm->next=ipc_modules;
ipc_modules=nm; }}
if(ret!=ECORE_CONFIG_ERR_SUCC)
free(nm); }
if (DEBUG != 0)
{
char *q = strrchr(p, DIR_DELIMITER);
if (q)
p = ++q;
}
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:
globfree(&globbuf);
if(ipc_modules) {
ipc_timer=timeout_add(100,_ecore_config_ipc_poll,ipc_modules); }
return ret_srv; }
globfree(&globbuf);
if (ipc_modules)
{
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_CONT 1
typedef struct _estring {
char *str;
int alloc,used;
typedef struct _estring
{
char *str;
int alloc, used;
} estring;
typedef struct _eslist {
void *payload;
struct _eslist *next;
typedef struct _eslist
{
void *payload;
struct _eslist *next;
} eslist;
int parse_line(char *, char **, char **, char **, char **);
char *unit_size(char *size);
int parse_line(char *,char **,char **,char **,char **);
char *unit_size(char *size);
/*unsigned long now(long delay);*/
void qsrt(void *a[],void *data,int lo,int hi,int (*compare)(const void *,const void *,const void *));
int dlmulti(char *name,char *file,int flag,void **libr,const char *fmt, ...);
void qsrt(void *a[], void *data, int lo, int hi,
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));
void *hash_table_fetch(void *hashtable, char *key);
int hash_table_insert(void *hashtable, char *key, void *value);
int hash_table_replace(void *hashtable, char *key, void *value);
int hash_table_remove(void *hashtable, char *key);
int hash_table_dst(void *hashtable);
int hash_table_walk(void *hashtable, hash_walker fun,
void *data);
typedef void (*hash_walker)(char *key,void *value,void *data);
int eslist_free(eslist **);
int eslist_next(eslist **);
void *hash_table_new( void (*freekey),void (*freeval));
void *hash_table_fetch( void *hashtable,char *key);
int hash_table_insert( void *hashtable,char *key,void *value);
int hash_table_replace(void *hashtable,char *key,void *value);
int hash_table_remove( void *hashtable,char *key);
int hash_table_dst( void *hashtable);
int hash_table_walk( void *hashtable,hash_walker fun,void *data);
int eslist_free(eslist **);
int eslist_next(eslist **);
#define ESLIST_NEXT(e) (e=e->next)
void *eslist_payload(eslist **);
#define ESLIST_PAYLOAD(e) ((e)->payload)
int eslist_prepend(eslist **,void *);
int eslist_append(eslist **,void *);
void *eslist_payload(eslist **);
#define ESLIST_PAYLOAD(e) ((e)->payload)
int eslist_prepend(eslist **, void *);
int eslist_append(eslist **, void *);
estring *estring_new(int size);
estring *estring_dst(estring * e);
char *estring_disown(estring * e);
char *estring_free(estring * e, int release_payload); /* glib compat */
int estring_printf(estring * e, char *fmt, ...);
int estring_appendf(estring * e, char *fmt, ...);
int estring_truncate(estring * e, int size);
estring *estring_new(int size);
estring *estring_dst(estring *e);
char *estring_disown(estring *e);
char *estring_free(estring *e,int release_payload); /* glib compat */
int estring_printf(estring *e,char *fmt, ...);
int estring_appendf(estring *e,char *fmt, ...);
int estring_truncate(estring *e,int size);
#define ESTRING_GET_CSTRING(a) ((a)->str)
int esprintf(char **result,char *fmt, ...);
int ejoin(char **result,char *delim, ...);
int ecat(char **result, ...);
unsigned long timeout_add(unsigned int f,int(*fun)(void *),void *data);
int timeout_remove(unsigned long handle);
int esprintf(char **result, char *fmt, ...);
int ejoin(char **result, char *delim, ...);
int ecat(char **result, ...);
unsigned long timeout_add(unsigned int f, int (*fun) (void *),
void *data);
int timeout_remove(unsigned long handle);