On Wed, 29 Sep 2010 05:53:04 -0300 Gustavo Sverzut Barbieri
<[email protected]> said:
the attached is what i was thinking of
> Hi all,
>
> Often programs need to use secondary resources such as images, theme,
> configuration files and so on. Finding them proves to be a major pain,
> particularly when you want it to be relocatable or you want your
> development version to take precedence over installed.
>
> Find attached an initial implementation of ecore_resource_pool (could
> be eina as well) and ecore_app_resource/ecore_sys_resource that
> pre-defines some paths based on ecore_app_args_set().
>
> tst-ecore-resource.c is a test program that plays the role of an
> application using command line parameters, then queries system's
> "passwd" from category "etc" and then simulates being ecore creating
> its own private resource pool (ie: elementary could use to find its
> themes).
>
> There are extension ideas such as environment variables, we just need
> to figure out what is required and then add them to ecore_app.c
>
> Comments, suggestions?
>
> --
> Gustavo Sverzut Barbieri
> http://profusion.mobi embedded systems
> --------------------------------------
> MSN: [email protected]
> Skype: gsbarbieri
> Mobile: +55 (19) 9225-2202
--
------------- Codito, ergo sum - "I code, therefore I am" --------------
The Rasterman (Carsten Haitzler) [email protected]
typedef struct _Ecore_Resource Ecore_Resource;
typedef enum
{
ECORE_RESOURCE_APP_PREFIX,
ECORE_RESOURCE_APP_BIN,
ECORE_RESOURCE_APP_SBIN,
ECORE_RESOURCE_APP_LIB,
ECORE_RESOURCE_APP_SBIN,
ECORE_RESOURCE_APP_SHARE,
ECORE_RESOURCE_APP_LIBEXEC,
ECORE_RESOURCE_APP_ETC,
ECORE_RESOURCE_SYS_PREFIX,
ECORE_RESOURCE_SYS_BIN,
ECORE_RESOURCE_SYS_SBIN,
ECORE_RESOURCE_SYS_LIB,
ECORE_RESOURCE_SYS_SBIN,
ECORE_RESOURCE_SYS_SHARE,
ECORE_RESOURCE_SYS_LIBEXEC,
ECORE_RESOURCE_SYS_ETC,
ECORE_RESOURCE_SYS_TMP,
ECORE_RESOURCE_SYS_VAR_TMP,
ECORE_RESOURCE_SYS_VAR_RUN,
ECORE_RESOURCE_SYS_VAR_LOG,
ECORE_RESOURCE_SYS_VAR_SPOOL,
ECORE_RESOURCE_SYS_VAR_CACHE,
ECORE_RESOURCE_SYS_VAR_LIB,
ECORE_RESOURCE_HOME,
ECORE_RESOURCE_HOME_CONFIG,
ECORE_RESOURCE_HOME_SHARE
} Ecore_Resource_Type;
EAPI Ecore_Resource *ecore_resource_new(void);
EAPI void ecore_resource_free(Ecore_Resource *r);
EAPI void ecore_resource_test(Ecore_Resource *r, Ecore_Resource_Type type, const char *testpath);
EAPI void ecore_resource_seed_symbol(Ecore_Resource *r, void (*sym) ());
EAPI void ecore_resource_seed_argv0(Ecore_Resource *r, const char *argv0);
EAPI void ecore_resource_seed_envs(Ecore_Resource *r, const char *envbase);
EAPI void ecore_resource_seed_fixed(Ecore_Resource *r, Ecore_Resource_Type type, const char *path);
EAPI const char *ecore_resource_get(Ecore_Resource *r, Ecore_Resource_Type type);
// usage:
//
// packagie is configured with prefix as "/usr"
// package has in its build pass in PACKAGE_PREFIX, PACKAGE_DATA, PACKAGE_BIN
// as "/usr", "/usr/share", "/usr/bin" for example. i.e.:
//
// -DPACKAGE_PREFIX=\"$(prefix)\"
// -DPACKAGE_DATA=\"$(datadir)\"
// -DPACKAGE_LIB=\"$(libdir)\"
// -DPACKAGE_BIN=\"$(bindir)\"
//
// the app installes a data file as:
// /usr/share/appname/somefile.txt
//
// this assumes a heirachy from PREFIX for auto-detection. i.e. PREFIX/share for data,
// PREFIX/bin for binaries, PREFIX/lib for libraries etc. and in the end auto-detection (not
// compiled in prefixes or env vars unless only prefix is given) relies on this fhs-style heirachy
int
main(int argc, char **argv)
{
ecore_init();
// NULL is the default resource - for the app, libs can create new resources for themselves with
// ecore_resource_new()
// and free them with
// ecore_resource_free()
// here we use NULL for the app. libs would use their own resource. you can't free the NULL resource.
//
// this passes in a symbol - ANY symbol in the binary OR the shared library (depending which you
// want to locate). this allows ecore_resource to use dlinfo() to try find where the binary or
// library comes from
ecore_resource_seed_symbol(NULL, main);
// this allows ecore_resource to use the apps executable if it is an absolute path OR if its a
// relative path, and if not... it can hunt $PATH for the given argv0 to know where it is.
ecore_resource_seed_argv0(NULL, argv[0]);
// this sets a base for env vars that are able to oevrride fixed, argv0, symbol or other auto
// dected locations. use env vars like APPNAME_DATA, APPNAME_BIN, APPNAME_PREFIX, APPNAME_BIN etc.
// and they must point to things like "/usr/share", "/usr/bin", "/usr", "/usr/bin"
ecore_resource_seed_envs(NULL, "APPNAME");
// supply the compiled in dirs/prefixes etc. for any resource, though this is intended only to
// provide what you use and care about
ecore_resource_seed_fixed(NULL, ECORE_RESOURCE_APP_PREFIX, PACKAGE_PREFIX);
ecore_resource_seed_fixed(NULL, ECORE_RESOURCE_APP_DATA, PACKAGE_DATA);
ecore_resource_seed_fixed(NULL, ECORE_RESOURCE_APP_LIB, PACKAGE_LIB);
ecore_resource_seed_fixed(NULL, ECORE_RESOURCE_APP_BIN, PACKAGE_BIN);
// and now let all the auto-detection and more try and find just where the app resources are. need
// to make sure the given file exists - if it does then the test is considered successful. in
// the below case it will look for: "/usr/share/appname/somefile.txt". wherever it is found - that
// will be the ultimate "prefix" used
ecore_resource_test(NULL, ECORE_RESOURCE_APP_SHARE, "appname/somefile.txt");
// should print the dir: /usr/share/appname
printf("app data dir: %s/appname", ecore_resource_get(NULL, ECORE_RESOURCE_APP_SHARE));
// should print the dir: /usr/bin
printf("app bin dir: %s", ecore_resource_get(NULL, ECORE_RESOURCE_APP_BIN));
// ... etc.
ecore_main_loop_begin();
}
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel