e17/evry: use 'extern' for evry_api to share with other modules. fix leak in calc

SVN revision: 62376
This commit is contained in:
Hannes Janetzek 2011-08-12 10:58:44 +00:00
parent 4f5dcfc1e4
commit 6a3e45a9d6
9 changed files with 62 additions and 107 deletions

View File

@ -9,8 +9,6 @@ static void _config_init(void);
static void _config_free(void);
static Eina_Bool _cleanup_history(void *data);
static void _evry_type_init(const char *type);
static Evry_API *_api = NULL;
static Eina_List *_evry_types = NULL;
static E_Int_Menu_Augmentation *maug = NULL;
static E_Action *act = NULL;
@ -23,6 +21,7 @@ Evry_Config *evry_conf = NULL;
int _evry_events[NUM_EVRY_EVENTS];
int _e_module_evry_log_dom = -1;
Evry_API *evry = NULL;
/* module setup */
EAPI E_Module_Api e_modapi =
@ -92,9 +91,9 @@ e_modapi_init(E_Module *m)
_evry_events[EVRY_EVENT_ACTION_PERFORMED] = ecore_event_type_new();
_evry_events[EVRY_EVENT_PLUGIN_SELECTED] = ecore_event_type_new();
_api = E_NEW(Evry_API, 1);
_api->log_dom = _e_module_evry_log_dom;
#define SET(func) (_api->func = &evry_##func);
evry = E_NEW(Evry_API, 1);
evry->log_dom = _e_module_evry_log_dom;
#define SET(func) (evry->func = &evry_##func);
SET(api_version_check);
SET(item_new);
SET(item_free);
@ -139,10 +138,10 @@ e_modapi_init(E_Module *m)
evry_plug_windows_init(m);
evry_plug_settings_init(m);
evry_plug_calc_init(m);
e_datastore_set("evry_api", _api);
e_datastore_set("evry_active", evry);
EINA_LIST_FOREACH(e_datastore_get("evry_modules"), l, em)
em->active = em->init(_api);
em->active = em->init();
evry_plug_collection_init();
evry_plug_clipboard_init();
@ -171,9 +170,10 @@ e_modapi_shutdown(E_Module *m __UNUSED__)
EINA_LIST_FOREACH(e_datastore_get("evry_modules"), l, em)
em->shutdown();
e_datastore_del("evry_api");
E_FREE(_api);
e_datastore_del("evry_active");
E_FREE(evry);
evry = NULL;
#ifndef USE_MODULE_EVERYTHING_AS_MODULES
evry_plug_apps_shutdown();
evry_plug_files_shutdown();

View File

@ -330,34 +330,6 @@ extern Evry_History *evry_hist;
extern Evry_Config *evry_conf;
extern int _evry_events[NUM_EVRY_EVENTS];
#define EVRY_ITEM_NEW(_base, _plugin, _label, _icon_get, _free) \
(_base *) evry_item_new(EVRY_ITEM(E_NEW(_base, 1)), EVRY_PLUGIN(_plugin), \
_label, _icon_get, _free)
#define EVRY_ITEM_FREE(_item) evry_item_free((Evry_Item *)_item)
#define EVRY_ITEM_REF(_item) evry_item_ref((Evry_Item *)_item)
#define EVRY_PLUGIN_NEW(_base, _name, _icon, _item_type, _begin, _cleanup, _fetch, _free) \
evry_plugin_new(EVRY_PLUGIN(E_NEW(_base, 1)), _name, _(_name), _icon, _item_type, \
_begin, _cleanup, _fetch, _free)
#define EVRY_ACTION_NEW(_name, _in1, _in2, _icon, _action, _check) \
evry_action_new(_name, _(_name), _in1, _in2, _icon, _action, _check)
#define EVRY_PLUGIN_FREE(_p) \
if (_p) evry_plugin_free(EVRY_PLUGIN(_p))
#define EVRY_PLUGIN_UPDATE(_p, _action) \
if (_p) evry_plugin_update(EVRY_PLUGIN(_p), _action)
#define EVRY_PLUGIN_ITEMS_FREE(_p) { \
Evry_Item *it; \
EINA_LIST_FREE(EVRY_PLUGIN(_p)->items, it) \
evry_item_free(it); }
#define EVRY_PLUGIN_ITEMS_ADD(_plugin, _items, _input, _match_detail, _set_usage) \
evry_util_plugin_items_add(EVRY_PLUGIN(_plugin), _items, _input, _match_detail, _set_usage)
/*** E Module ***/
EAPI void *e_modapi_init (E_Module *m);
EAPI int e_modapi_shutdown (E_Module *m);
@ -383,8 +355,9 @@ extern int _e_module_evry_log_dom;
#define WRN(...) EINA_LOG_DOM_WARN(_e_module_evry_log_dom, __VA_ARGS__)
#define ERR(...) EINA_LOG_DOM_ERR(_e_module_evry_log_dom, __VA_ARGS__)
//#define CHECK_REFS 1
//#define CHECK_TIME 1
/* #define CHECK_REFS 1
* #define PRINT_REFS 1
* #define CHECK_TIME 1 */
//#undef DBG
//#define DBG(...) ERR(__VA_ARGS__)

View File

@ -419,16 +419,11 @@ _evry_selectors_shift(Evry_Window *win, int dir)
}
Evry_Item *
evry_item_new(Evry_Item *base, Evry_Plugin *p, const char *label,
evry_item_new(Evry_Item *it, Evry_Plugin *p, const char *label,
Evas_Object *(*icon_get) (Evry_Item *it, Evas *e),
void (*cb_free) (Evry_Item *item))
{
Evry_Item *it;
if (base)
{
it = base;
}
else
if (!it)
{
it = E_NEW(Evry_Item, 1);
if (!it) return NULL;
@ -463,7 +458,7 @@ evry_item_free(Evry_Item *it)
it->ref--;
#ifdef PRINT_REFS
printf("%d, %d\t unref: %s\n", it->ref, _item_cnt - 1, it->label);
printf("%d, %d\t unref: %s\n", it->ref, _item_cnt, it->label);
#endif
if (it->ref > 0) return;
@ -539,7 +534,8 @@ _evry_selector_update_actions(Evry_Selector *sel)
if (sel->action_timer)
ecore_timer_del(sel->action_timer);
sel->action_timer = ecore_timer_add(0.1, _evry_timer_cb_actions_get, sel);
_evry_selector_item_clear(sel);
sel->action_timer = ecore_timer_add(0.2, _evry_timer_cb_actions_get, sel);
}
void
@ -1325,7 +1321,7 @@ _evry_selector_item_update(Evry_Selector *sel)
if (!_evry_selector_thumb(sel, it))
{
o = evry_util_icon_get(it, win->evas);
if ((!o) && it->plugin)
o = evry_util_icon_get(EVRY_ITEM(it->plugin), win->evas);
}

View File

@ -51,12 +51,13 @@ typedef struct _Evry_Event_Item_Changed Evry_Event_Item_Changed;
typedef struct _Evry_Event_Item_Selected Evry_Event_Item_Selected;
typedef struct _Evry_Event_Action_Performed Evry_Event_Action_Performed;
extern Evry_API *evry;
struct _Evry_Module
{
Eina_Bool active;
int (*init)(const Evry_API *api);
int (*init)(void);
void (*shutdown)(void);
};
@ -163,7 +164,6 @@ struct _Evry_Event_Action_Performed
#define GET_ITEM(_it, _any) Evry_Item *_it = (Evry_Item *) _any
/*** Evry_Item macros ***/
#ifndef EVRY_H
#define EVRY_ITEM_NEW(_base, _plugin, _label, _icon_get, _free) \
(_base *) evry->item_new(EVRY_ITEM(E_NEW(_base, 1)), \
EVRY_PLUGIN(_plugin), \
@ -171,7 +171,6 @@ struct _Evry_Event_Action_Performed
#define EVRY_ITEM_FREE(_item) evry->item_free((Evry_Item *)_item)
#define EVRY_ITEM_REF(_item) evry->item_ref((Evry_Item *)_item)
#endif
#define EVRY_ITEM_DATA_INT_SET(_item, _data) \
((Evry_Item *)_item)->data = (void*)(long) _data
@ -208,7 +207,6 @@ struct _Evry_Event_Action_Performed
#define IS_BROWSEABLE(_item) ((Evry_Item *)_item)->browseable
/*** Evry_Plugin macros ***/
#ifndef EVRY_H
#define EVRY_PLUGIN_NEW(_base, _name, _icon, _item_type, _begin, _finish, _fetch, _free) \
evry->plugin_new(EVRY_PLUGIN(E_NEW(_base, 1)), _name, _(_name), _icon, _item_type, \
_begin, _finish, _fetch, _free)
@ -225,7 +223,7 @@ struct _Evry_Event_Action_Performed
#define EVRY_PLUGIN_UPDATE(_p, _action) \
if (_p) evry->plugin_update(EVRY_PLUGIN(_p), _action)
#endif
#define EVRY_PLUGIN_ITEMS_SORT(_p, _sortcb) \
EVRY_PLUGIN(_p)->items = eina_list_sort \
(EVRY_PLUGIN(_p)->items, eina_list_count(EVRY_PLUGIN(_p)->items), _sortcb)
@ -235,18 +233,18 @@ struct _Evry_Event_Action_Performed
typedef void (*Evry_Item_Free_Cb) (Evry_Item *it);
#define EVRY_PLUGIN_INSTANCE(_p, _plugin) { \
_p = E_NEW(Plugin, 1); \
_p->base = *_plugin; \
_p->base.items = NULL; \
_p->base.base.ref = 1; \
_p->base.base.free = (Evry_Item_Free_Cb)_p->base.finish; \
_p->base.base.label = eina_stringshare_add(_plugin->base.label); \
#define EVRY_PLUGIN_INSTANCE(_p, _plugin) { \
_p = E_NEW(Plugin, 1); \
_p->base = *_plugin; \
_p->base.items = NULL; \
evry->item_new(&_p->base.base, (Evry_Plugin*)_p, \
_plugin->base.label, NULL, \
(Evry_Item_Free_Cb)_p->base.finish); \
_p->base.base.detail = eina_stringshare_add(_plugin->base.detail); \
_p->base.base.icon = eina_stringshare_add(_plugin->base.icon); \
_p->base.base.icon = eina_stringshare_add(_plugin->base.icon); \
_p->base.base.context = eina_stringshare_add(_plugin->base.context); \
_p->base.base.id = eina_stringshare_add(_plugin->base.id); \
_p->base.base.plugin = (Evry_Plugin*)_p; } \
_p->base.base.id = eina_stringshare_add(_plugin->base.id); \
}
#define EVRY_PLUGIN_ITEMS_CLEAR(_p) { \
Evry_Item *it; \
@ -254,23 +252,21 @@ typedef void (*Evry_Item_Free_Cb) (Evry_Item *it);
if (it) it->fuzzy_match = 0; }
/*** Evry_Action macros ***/
#ifndef EVRY_H
#define EVRY_ACTION_NEW(_name, _in1, _in2, _icon, _action, _check) \
evry->action_new(_name, _(_name), _in1, _in2, _icon, _action, _check)
#define EVRY_ACTION_FREE(_act) if (_act) evry->action_free(EVRY_ACTN(_act))
#endif
#define EVRY_MODULE_NEW(_module, _evry_api, _init, _shutdown) \
{ \
_module = E_NEW(Evry_Module, 1); \
_module->init = &_init; \
_module->shutdown = &_shutdown; \
Eina_List *l = e_datastore_get("evry_modules"); \
l = eina_list_append(l, _module); \
e_datastore_set("evry_modules", l); \
if ((_evry_api = e_datastore_get("evry_api"))) \
evry_module->active = _init(_evry_api); \
#define EVRY_MODULE_NEW(_module, _init, _shutdown) \
{ \
_module = E_NEW(Evry_Module, 1); \
_module->init = &_init; \
_module->shutdown = &_shutdown; \
Eina_List *l = e_datastore_get("evry_modules"); \
l = eina_list_append(l, _module); \
e_datastore_set("evry_modules", l); \
if ((e_datastore_get("evry_active"))) \
evry_module->active = _init(); \
}
#define EVRY_MODULE_FREE(_module) \

View File

@ -51,7 +51,6 @@ struct _Module_Config
E_Module *module;
};
static const Evry_API *evry = NULL;
static Evry_Module *evry_module = NULL;
static Eina_List *handlers = NULL;
@ -1011,7 +1010,7 @@ _desktop_cache_update(void *data __UNUSED__, int type __UNUSED__, void *event __
}
static int
_plugins_init(const Evry_API *api)
_plugins_init(void)
{
Evry_Plugin *p;
int prio = 0;
@ -1021,8 +1020,6 @@ _plugins_init(const Evry_API *api)
if (evry_module->active)
return EINA_TRUE;
evry = api;
if (!evry->api_version_check(EVRY_API_VERSION))
return EINA_FALSE;
@ -1352,7 +1349,7 @@ evry_plug_apps_init(E_Module *m)
{
_conf_init(m);
EVRY_MODULE_NEW(evry_module, evry, _plugins_init, _plugins_shutdown);
EVRY_MODULE_NEW(evry_module, _plugins_init, _plugins_shutdown);
/* taken from e_exebuf.c */
exelist_exe_edd = E_CONFIG_DD_NEW("E_Exe", E_Exe);

View File

@ -13,7 +13,6 @@ static Eina_Bool _cb_data(void *data, int type, void *event);
static Eina_Bool _cb_error(void *data, int type, void *event);
static Eina_Bool _cb_del(void *data, int type, void *event);
static const Evry_API *evry = NULL;
static Evry_Module *evry_module = NULL;
static Evry_Plugin *_plug;
static Ecore_Event_Handler *action_handler = NULL;
@ -31,7 +30,7 @@ _begin(Evry_Plugin *plugin, const Evry_Item *item __UNUSED__)
{
Evry_Item *it;
Plugin *p;
if (active)
return NULL;
@ -54,7 +53,7 @@ _begin(Evry_Plugin *plugin, const Evry_Item *item __UNUSED__)
it->context = eina_stringshare_ref(p->base.name);
cur_item = it;
active = EINA_TRUE;
return EVRY_PLUGIN(p);
}
@ -84,11 +83,14 @@ _run_bc(Plugin *p)
static void
_finish(Evry_Plugin *plugin)
{
GET_PLUGIN(p, plugin);
GET_PLUGIN(p, plugin);
Ecore_Event_Handler *h;
Evry_Item *it;
int items = 0;
if (!eina_list_data_find(p->base.items, cur_item))
EVRY_ITEM_FREE(cur_item);
EINA_LIST_FREE(p->base.items, it)
{
if ((items++ > 1) && (items < 10))
@ -106,7 +108,9 @@ _finish(Evry_Plugin *plugin)
ecore_exe_free(exe);
exe = NULL;
}
active = EINA_FALSE;
cur_item = NULL;
E_FREE(p);
}
@ -158,7 +162,7 @@ static int
_fetch(Evry_Plugin *plugin, const char *input)
{
GET_PLUGIN(p, plugin);
char buf[1024];
if (!input) return 0;
@ -214,7 +218,7 @@ _cb_error(void *data, int type __UNUSED__, void *event)
{
Ecore_Exe_Event_Data *ev = event;
Evry_Plugin *p = data;
if (ev->exe != exe)
return ECORE_CALLBACK_PASS_ON;
@ -238,13 +242,11 @@ _cb_del(void *data __UNUSED__, int type __UNUSED__, void *event)
}
static int
_plugins_init(const Evry_API *_api)
_plugins_init(void)
{
if (evry_module->active)
return EINA_TRUE;
evry = _api;
if (!evry->api_version_check(EVRY_API_VERSION))
return EINA_FALSE;
@ -291,7 +293,7 @@ _plugins_shutdown(void)
Eina_Bool
evry_plug_calc_init(E_Module *m)
{
EVRY_MODULE_NEW(evry_module, evry, _plugins_init, _plugins_shutdown);
EVRY_MODULE_NEW(evry_module, _plugins_init, _plugins_shutdown);
return EINA_TRUE;
}

View File

@ -90,7 +90,6 @@ struct _Module_Config
E_Module *module;
};
static const Evry_API *evry = NULL;
static Evry_Module *evry_module = NULL;
static Module_Config *_conf;
@ -1305,7 +1304,7 @@ _cb_key_down(Evry_Plugin *plugin, const Ecore_Event_Key *ev)
static int
_plugins_init(const Evry_API *api)
_plugins_init(void)
{
Evry_Action *act, *act_sort_date, *act_sort_name;
Evry_Plugin *p;
@ -1314,8 +1313,6 @@ _plugins_init(const Evry_API *api)
if (evry_module->active)
return EINA_TRUE;
evry = api;
if (!evry->api_version_check(EVRY_API_VERSION))
return EINA_FALSE;
@ -1647,7 +1644,7 @@ evry_plug_files_init(E_Module *m)
{
_conf_init(m);
EVRY_MODULE_NEW(evry_module, evry, _plugins_init, _plugins_shutdown);
EVRY_MODULE_NEW(evry_module, _plugins_init, _plugins_shutdown);
return EINA_TRUE;
}

View File

@ -20,7 +20,6 @@ struct _Settings_Item
E_Configure_It *eci;
};
static const Evry_API *evry = NULL;
static Evry_Module *evry_module = NULL;
static Evry_Plugin *p;
static Evry_Action *act;
@ -174,13 +173,11 @@ _action(Evry_Action *act)
}
static int
_plugins_init(const Evry_API *_api)
_plugins_init(void)
{
if (evry_module->active)
return EINA_TRUE;
evry = _api;
if (!evry->api_version_check(EVRY_API_VERSION))
return EINA_FALSE;
@ -220,7 +217,7 @@ _plugins_shutdown(void)
Eina_Bool
evry_plug_settings_init(E_Module *m)
{
EVRY_MODULE_NEW(evry_module, evry, _plugins_init, _plugins_shutdown);
EVRY_MODULE_NEW(evry_module, _plugins_init, _plugins_shutdown);
e_module_delayed_set(m, 1);

View File

@ -26,7 +26,6 @@ struct _Border_Item
#define GET_BORDER(_bd, _it) Border_Item *_bd = (Border_Item *)_it;
static const Evry_API *evry = NULL;
static Evry_Module *evry_module = NULL;
static Evry_Plugin *_plug;
static Eina_List *_actions = NULL;
@ -402,15 +401,13 @@ _act_border(Evry_Action *act)
}
static int
_plugins_init(const Evry_API *_api)
_plugins_init(void)
{
Evry_Action *act;
if (evry_module->active)
return EINA_TRUE;
evry = _api;
if (!evry->api_version_check(EVRY_API_VERSION))
return EINA_FALSE;
@ -480,7 +477,7 @@ _plugins_shutdown(void)
Eina_Bool
evry_plug_windows_init(E_Module *m)
{
EVRY_MODULE_NEW(evry_module, evry, _plugins_init, _plugins_shutdown);
EVRY_MODULE_NEW(evry_module, _plugins_init, _plugins_shutdown);
return EINA_TRUE;
}