aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Antognolli <antognolli@gmail.com>2009-07-09 19:14:29 +0000
committerRafael Antognolli <antognolli@gmail.com>2009-07-09 19:14:29 +0000
commit5dc0fa41efaca8d309372df2cb85ac21235f207e (patch)
tree8dd52df73aacd18a94edd3ac7c4884a196b81421
parentFixed wrong usage of eina_list_remove_list on Ethumb_Client. (diff)
downloadefl-5dc0fa41efaca8d309372df2cb85ac21235f207e.tar.gz
Added support to free_data callbacks.
Some functions that require callbacks and data passed to them now can receive a free_data callback as argument too. SVN revision: 41285
-rw-r--r--legacy/ethumb/src/bin/ethumb.c2
-rw-r--r--legacy/ethumb/src/bin/ethumbd_child.c2
-rw-r--r--legacy/ethumb/src/lib/Ethumb.c6
-rw-r--r--legacy/ethumb/src/lib/Ethumb.h2
-rw-r--r--legacy/ethumb/src/lib/client/Ethumb_Client.c27
-rw-r--r--legacy/ethumb/src/lib/client/Ethumb_Client.h4
-rw-r--r--legacy/ethumb/src/lib/ethumb_private.h1
-rw-r--r--legacy/ethumb/src/tests/ethumb_dbus.c10
8 files changed, 35 insertions, 19 deletions
diff --git a/legacy/ethumb/src/bin/ethumb.c b/legacy/ethumb/src/bin/ethumb.c
index 4c344c3fbb..faf6e801f4 100644
--- a/legacy/ethumb/src/bin/ethumb.c
+++ b/legacy/ethumb/src/bin/ethumb.c
@@ -234,7 +234,7 @@ main(int argc, char *argv[])
r = 1;
}
else
- r = ethumb_generate(e, _finished_thumb, NULL);
+ r = ethumb_generate(e, _finished_thumb, NULL, NULL);
}
if (r && !quit_option)
diff --git a/legacy/ethumb/src/bin/ethumbd_child.c b/legacy/ethumb/src/bin/ethumbd_child.c
index 06eced531c..4b790c5911 100644
--- a/legacy/ethumb/src/bin/ethumbd_child.c
+++ b/legacy/ethumb/src/bin/ethumbd_child.c
@@ -268,7 +268,7 @@ _ec_op_generate(struct _Ethumbd_Child *ec)
ethumb_file_set(ec->ethumbt[index], path, key);
ethumb_thumb_path_set(ec->ethumbt[index], thumb_path, thumb_key);
ethumb_generate(ec->ethumbt[index], _ec_op_generated_cb,
- ec);
+ ec, NULL);
free(path);
free(key);
diff --git a/legacy/ethumb/src/lib/Ethumb.c b/legacy/ethumb/src/lib/Ethumb.c
index d20b5f5fe0..da909f7525 100644
--- a/legacy/ethumb/src/lib/Ethumb.c
+++ b/legacy/ethumb/src/lib/Ethumb.c
@@ -966,9 +966,12 @@ _ethumb_finished_idler_cb(void *data)
Ethumb *e = data;
e->finished_cb(e, e->cb_result, e->cb_data);
+ if (e->cb_data_free)
+ e->cb_data_free(e->cb_data);
e->finished_idler = NULL;
e->finished_cb = NULL;
e->cb_data = NULL;
+ e->cb_data_free = NULL;
return 0;
}
@@ -985,7 +988,7 @@ ethumb_finished_callback_call(Ethumb *e, int result)
}
EAPI Eina_Bool
-ethumb_generate(Ethumb *e, ethumb_generate_callback_t finished_cb, void *data)
+ethumb_generate(Ethumb *e, ethumb_generate_callback_t finished_cb, void *data, void (*free_data)(void *))
{
int r;
@@ -1000,6 +1003,7 @@ ethumb_generate(Ethumb *e, ethumb_generate_callback_t finished_cb, void *data)
}
e->finished_cb = finished_cb;
e->cb_data = data;
+ e->cb_data_free = free_data;
if (!e->src_path)
{
diff --git a/legacy/ethumb/src/lib/Ethumb.h b/legacy/ethumb/src/lib/Ethumb.h
index f7bf87256b..70db3e5117 100644
--- a/legacy/ethumb/src/lib/Ethumb.h
+++ b/legacy/ethumb/src/lib/Ethumb.h
@@ -109,7 +109,7 @@ EAPI void ethumb_file_get(const Ethumb *e, const char **path, const char **key)
EAPI void ethumb_file_free(Ethumb *e) EINA_ARG_NONNULL(1);
EAPI void ethumb_thumb_path_set(Ethumb *e, const char *path, const char *key) EINA_ARG_NONNULL(1);
EAPI void ethumb_thumb_path_get(Ethumb *e, const char **path, const char **key) EINA_ARG_NONNULL(1);
-EAPI Eina_Bool ethumb_generate(Ethumb *e, ethumb_generate_callback_t finished_cb, void *data) EINA_ARG_NONNULL(1, 2);
+EAPI Eina_Bool ethumb_generate(Ethumb *e, ethumb_generate_callback_t finished_cb, void *data, void (*free_data)(void *)) EINA_ARG_NONNULL(1, 2);
EAPI Eina_Bool ethumb_exists(Ethumb *e) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_PURE;
#ifdef __cplusplus
diff --git a/legacy/ethumb/src/lib/client/Ethumb_Client.c b/legacy/ethumb/src/lib/client/Ethumb_Client.c
index 3fa725e4b5..c1338ad8c6 100644
--- a/legacy/ethumb/src/lib/client/Ethumb_Client.c
+++ b/legacy/ethumb/src/lib/client/Ethumb_Client.c
@@ -63,6 +63,7 @@ struct _Ethumb_Client
DBusPendingCall *pending_new;
ec_connect_callback_t connect_cb;
void *connect_cb_data;
+ void (*connect_cb_free_data)(void *);
Eina_List *pending_add;
Eina_List *pending_remove;
Eina_List *pending_gen;
@@ -86,6 +87,7 @@ struct _ethumb_pending_add
const char *thumb_key;
generated_callback_t generated_cb;
void *data;
+ void (*free_data)(void *);
DBusPendingCall *pending_call;
Ethumb_Client *client;
};
@@ -108,6 +110,7 @@ struct _ethumb_pending_gen
const char *thumb_key;
generated_callback_t generated_cb;
void *data;
+ void (*free_data)(void *);
};
static const char _ethumb_dbus_bus_name[] = "org.enlightenment.Ethumb";
@@ -248,11 +251,14 @@ _ethumb_client_new_cb(void *data, DBusMessage *msg, DBusError *error)
_ethumb_client_generated_cb, client);
client->connect_cb(client, 1, client->connect_cb_data);
+ if (client->connect_cb_free_data)
+ client->connect_cb_free_data(client->connect_cb_data);
return;
end_error:
client->connect_cb(client, 0, client->connect_cb_data);
- return;
+ if (client->connect_cb_free_data)
+ client->connect_cb_free_data(client->connect_cb_data);
}
static void
@@ -317,6 +323,8 @@ _ethumb_client_start_server_cb(void *data, DBusMessage *msg, DBusError *err)
error:
ERR("failed to start Ethumbd DBus service by its name.\n");
client->connect_cb(client, 0, client->connect_cb_data);
+ if (client->connect_cb_free_data)
+ client->connect_cb_free_data(client->connect_cb_data);
}
static void
@@ -336,6 +344,8 @@ _ethumb_client_start_server(Ethumb_Client *client)
{
ERR("could not start service by name!\n");
client->connect_cb(client, 0, client->connect_cb_data);
+ if (client->connect_cb_free_data)
+ client->connect_cb_free_data(client->connect_cb_data);
}
}
@@ -379,6 +389,8 @@ _ethumb_client_get_name_owner(void *data, DBusMessage *msg, DBusError *err)
error:
client->connect_cb(client, 0, client->connect_cb_data);
+ if (client->connect_cb_free_data)
+ client->connect_cb_free_data(client->connect_cb_data);
}
EAPI int
@@ -406,7 +418,7 @@ ethumb_client_shutdown(void)
}
EAPI Ethumb_Client *
-ethumb_client_connect(ec_connect_callback_t connect_cb, void *data)
+ethumb_client_connect(ec_connect_callback_t connect_cb, void *data, void (*free_data)(void *))
{
Ethumb_Client *eclient;
@@ -421,6 +433,7 @@ ethumb_client_connect(ec_connect_callback_t connect_cb, void *data)
eclient->connect_cb = connect_cb;
eclient->connect_cb_data = data;
+ eclient->connect_cb_free_data = free_data;
eclient->ethumb = ethumb_new();
if (!eclient->ethumb)
@@ -739,6 +752,8 @@ _ethumb_client_generated_cb(void *data, DBusMessage *msg)
pending->generated_cb(id, pending->file, pending->key,
pending->thumb, pending->thumb_key,
success, pending->data);
+ if (pending->free_data)
+ pending->free_data(pending->data);
eina_stringshare_del(pending->file);
eina_stringshare_del(pending->key);
eina_stringshare_del(pending->thumb);
@@ -780,6 +795,7 @@ _ethumb_client_queue_add_cb(void *data, DBusMessage *msg, DBusError *error)
generating->thumb_key = pending->thumb_key;
generating->generated_cb = pending->generated_cb;
generating->data = pending->data;
+ generating->free_data = pending->free_data;
client->pending_gen = eina_list_append(client->pending_gen, generating);
end:
@@ -787,7 +803,7 @@ end:
}
static long
-_ethumb_client_queue_add(Ethumb_Client *client, const char *file, const char *key, const char *thumb, const char *thumb_key, generated_callback_t generated_cb, void *data)
+_ethumb_client_queue_add(Ethumb_Client *client, const char *file, const char *key, const char *thumb, const char *thumb_key, generated_callback_t generated_cb, void *data, void (*free_data)(void *))
{
DBusMessage *msg;
DBusMessageIter iter;
@@ -801,6 +817,7 @@ _ethumb_client_queue_add(Ethumb_Client *client, const char *file, const char *ke
pending->thumb_key = eina_stringshare_add(thumb_key);
pending->generated_cb = generated_cb;
pending->data = data;
+ pending->free_data = free_data;
pending->client = client;
client->id_count = (client->id_count + 1) % MAX_ID;
@@ -1141,7 +1158,7 @@ ethumb_client_thumb_exists(Ethumb_Client *client)
}
EAPI long
-ethumb_client_generate(Ethumb_Client *client, generated_callback_t generated_cb, void *data)
+ethumb_client_generate(Ethumb_Client *client, generated_callback_t generated_cb, void *data, void (*free_data)(void *))
{
const char *file, *key, *thumb, *thumb_key;
long id;
@@ -1159,7 +1176,7 @@ ethumb_client_generate(Ethumb_Client *client, generated_callback_t generated_cb,
if (client->ethumb_dirty)
ethumb_client_ethumb_setup(client);
id = _ethumb_client_queue_add(client, file, key, thumb, thumb_key,
- generated_cb, data);
+ generated_cb, data, free_data);
return id;
}
diff --git a/legacy/ethumb/src/lib/client/Ethumb_Client.h b/legacy/ethumb/src/lib/client/Ethumb_Client.h
index 07d40afe9f..e60b46d97e 100644
--- a/legacy/ethumb/src/lib/client/Ethumb_Client.h
+++ b/legacy/ethumb/src/lib/client/Ethumb_Client.h
@@ -46,7 +46,7 @@ typedef void (*generated_callback_t)(long id, const char *file, const char *key,
EAPI int ethumb_client_init(void);
EAPI int ethumb_client_shutdown(void);
-EAPI Ethumb_Client * ethumb_client_connect(ec_connect_callback_t connect_cb, void *data);
+EAPI Ethumb_Client * ethumb_client_connect(ec_connect_callback_t connect_cb, void *data, void (*free_data)(void *));
EAPI void ethumb_client_disconnect(Ethumb_Client *client);
EAPI void ethumb_client_on_server_die_callback_set(Ethumb_Client *client, void (*on_server_die_cb)(Ethumb_Client *client, void *data), void *data);
@@ -79,7 +79,7 @@ EAPI void ethumb_client_file_free(Ethumb_Client *client);
EAPI void ethumb_client_thumb_path_set(Ethumb_Client *client, const char *path, const char *key);
EAPI void ethumb_client_thumb_path_get(Ethumb_Client *client, const char **path, const char **key);
EAPI Eina_Bool ethumb_client_thumb_exists(Ethumb_Client *client);
-EAPI long ethumb_client_generate(Ethumb_Client *client, generated_callback_t generated_cb, void *data);
+EAPI long ethumb_client_generate(Ethumb_Client *client, generated_callback_t generated_cb, void *data, void (*free_data)(void *));
#ifdef __cplusplus
}
diff --git a/legacy/ethumb/src/lib/ethumb_private.h b/legacy/ethumb/src/lib/ethumb_private.h
index b43131f2bf..c6975cc47f 100644
--- a/legacy/ethumb/src/lib/ethumb_private.h
+++ b/legacy/ethumb/src/lib/ethumb_private.h
@@ -39,6 +39,7 @@ struct _Ethumb
Ecore_Idler *finished_idler;
ethumb_generate_callback_t finished_cb;
void *cb_data;
+ void (*cb_data_free)(void *);
int cb_result;
};
diff --git a/legacy/ethumb/src/tests/ethumb_dbus.c b/legacy/ethumb/src/tests/ethumb_dbus.c
index 1c4026bc77..59a95bfdc9 100644
--- a/legacy/ethumb/src/tests/ethumb_dbus.c
+++ b/legacy/ethumb/src/tests/ethumb_dbus.c
@@ -57,7 +57,6 @@ _request_thumbnails(Ethumb_Client *client, void *data)
DIR *dir;
struct dirent *de;
char buf[PATH_MAX];
- int i;
dir = opendir(path);
if (!dir)
@@ -78,12 +77,7 @@ _request_thumbnails(Ethumb_Client *client, void *data)
continue;
snprintf(buf, sizeof(buf), "%s/%s", path, de->d_name);
ethumb_client_file_set(client, buf, NULL);
- ethumb_client_generate(client, _queue_add_cb, NULL);
- }
-
- for (i = 100; i < 200; i++)
- {
- ethumb_client_queue_remove(client, i, NULL, NULL);
+ ethumb_client_generate(client, _queue_add_cb, NULL, NULL);
}
closedir(dir);
@@ -115,7 +109,7 @@ main(int argc, char *argv[])
}
ethumb_client_init();
- client = ethumb_client_connect(_connect_cb, argv[1]);
+ client = ethumb_client_connect(_connect_cb, argv[1], NULL);
if (!client)
{
fprintf(stderr, "ERROR: couldn't connect to server.\n");