summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzmike <michael.blumenkrantz@gmail.com>2014-02-14 23:00:26 -0500
committerzmike <michael.blumenkrantz@gmail.com>2014-02-14 23:00:26 -0500
commit6b5e43d0de009d5d183844cb9ddf2acb36f7f342 (patch)
treeda388a4539598c60827ba462335ba6fbba5fc4ea
parent0da5e9b55f290d1445db7e52e78c49ae90d28a61 (diff)
allow grouping/combining of fetch requests
-rw-r--r--src/bin/empc.c1
-rw-r--r--src/bin/empc_metadata.c46
-rw-r--r--src/bin/empc_private.h10
3 files changed, 50 insertions, 7 deletions
diff --git a/src/bin/empc.c b/src/bin/empc.c
index 62a4221..0109735 100644
--- a/src/bin/empc.c
+++ b/src/bin/empc.c
@@ -101,6 +101,7 @@ fetch_req_free(Empc_Fetch_Request_Internal *ireq)
101 eina_stringshare_del(ireq->req.artist); 101 eina_stringshare_del(ireq->req.artist);
102 eina_stringshare_del(ireq->req.album); 102 eina_stringshare_del(ireq->req.album);
103 eina_stringshare_del(ireq->req.song); 103 eina_stringshare_del(ireq->req.song);
104 E_FREE_LIST(ireq->results, free);
104 free(ireq); 105 free(ireq);
105} 106}
106 107
diff --git a/src/bin/empc_metadata.c b/src/bin/empc_metadata.c
index 0c7757d..8003289 100644
--- a/src/bin/empc_metadata.c
+++ b/src/bin/empc_metadata.c
@@ -43,11 +43,30 @@ metadata_fetch_begin(Empc_Metadata_Type type, Evas_Object *obj, const char *attr
43{ 43{
44 Empc_Fetch_Request_Internal *ireq; 44 Empc_Fetch_Request_Internal *ireq;
45 Empc_Fetch_Request *req; 45 Empc_Fetch_Request *req;
46 Empc_Metadata_Result_Cb *res;
46 char buf[2048]; 47 char buf[2048];
47 48
48 if (attr1 && (!attr1[0]) && attr2 && (!attr2[0])) return NULL; //fuck you 49 if (attr1 && (!attr1[0]) && attr2 && (!attr2[0])) return NULL; //fuck you
50 force = !!force;
49 snprintf(buf, sizeof(buf), "%s::%s", attr1 ?: "", attr2 ?: ""); 51 snprintf(buf, sizeof(buf), "%s::%s", attr1 ?: "", attr2 ?: "");
50 if (eina_hash_find(empc_metadata_fetch_reqs[type], buf)) return NULL; 52 ireq = eina_hash_find(empc_metadata_fetch_reqs[type], buf);
53 if (ireq)
54 {
55 Eina_List *l;
56
57 if (ireq->req.type != type) return NULL; //wtf
58 EINA_LIST_FOREACH(ireq->results, l, res)
59 {
60 if ((res->cb == cb) && (res->data == data)) return NULL;
61 }
62 res = malloc(sizeof(Empc_Metadata_Result_Cb));
63 res->cb = cb;
64 res->data = (void*)data;
65 res->force = force;
66 ireq->results = eina_list_append(ireq->results, res);
67 ireq->req.force |= force;
68 return (Empc_Fetch_Request*)ireq;
69 }
51 switch (type) 70 switch (type)
52 { 71 {
53 case EMPC_METADATA_TYPE_IMAGE: 72 case EMPC_METADATA_TYPE_IMAGE:
@@ -60,8 +79,11 @@ metadata_fetch_begin(Empc_Metadata_Type type, Evas_Object *obj, const char *attr
60 } 79 }
61 ireq->req.type = type; 80 ireq->req.type = type;
62 ireq->req.obj = obj; 81 ireq->req.obj = obj;
63 ireq->result = cb; 82 res = malloc(sizeof(Empc_Metadata_Result_Cb));
64 ireq->data = (void*)data; 83 res->cb = cb;
84 res->data = (void*)data;
85 res->force = force;
86 ireq->results = eina_list_append(ireq->results, res);
65 ireq->req.force = !!force; 87 ireq->req.force = !!force;
66 eina_hash_add(empc_metadata_fetch_reqs[type], buf, ireq); 88 eina_hash_add(empc_metadata_fetch_reqs[type], buf, ireq);
67 req = metadata_fetch_continue(ireq); 89 req = metadata_fetch_continue(ireq);
@@ -92,6 +114,8 @@ void
92empc_metadata_fetch_done(Empc_Fetch_Request *req, Evas_Object *obj) 114empc_metadata_fetch_done(Empc_Fetch_Request *req, Evas_Object *obj)
93{ 115{
94 Empc_Fetch_Request_Internal *ireq = (Empc_Fetch_Request_Internal*)req; 116 Empc_Fetch_Request_Internal *ireq = (Empc_Fetch_Request_Internal*)req;
117 Empc_Metadata_Result_Cb *res;
118 Eina_List *l, *ll;
95 119
96 ireq->in_progress = 0; 120 ireq->in_progress = 0;
97 switch (ireq->req.type) 121 switch (ireq->req.type)
@@ -118,14 +142,26 @@ empc_metadata_fetch_done(Empc_Fetch_Request *req, Evas_Object *obj)
118 if (del) 142 if (del)
119 { 143 {
120 if ((!ireq->count) && (!ireq->deleted)) 144 if ((!ireq->count) && (!ireq->deleted))
121 ireq->result(ireq->data, req, NULL); 145 {
146 EINA_LIST_FREE(ireq->results, res)
147 {
148 res->cb(res->data, req, NULL);
149 free(res);
150 }
151 }
122 eina_hash_del_by_data(empc_metadata_fetch_reqs[ireq->req.type], req); 152 eina_hash_del_by_data(empc_metadata_fetch_reqs[ireq->req.type], req);
123 } 153 }
124 return; 154 return;
125 } 155 }
126 //evas_object_smart_callback_add(img, "download,done", metadata_image_done, NULL); 156 //evas_object_smart_callback_add(img, "download,done", metadata_image_done, NULL);
127 ireq->count++; 157 ireq->count++;
128 ireq->result(ireq->data, req, obj); 158 EINA_LIST_FOREACH_SAFE(ireq->results, l, ll, res)
159 {
160 res->cb(res->data, req, obj);
161 if (res->force) continue;
162 ireq->results = eina_list_remove_list(ireq->results, l);
163 free(res);
164 }
129} 165}
130 166
131Evas_Object * 167Evas_Object *
diff --git a/src/bin/empc_private.h b/src/bin/empc_private.h
index 6345e03..4760f61 100644
--- a/src/bin/empc_private.h
+++ b/src/bin/empc_private.h
@@ -39,12 +39,18 @@ typedef struct Empc_Module_Metadata_Save
39 Empc_Module_Metadata_Save_Text_Cb save_text; 39 Empc_Module_Metadata_Save_Text_Cb save_text;
40} Empc_Module_Metadata_Save; 40} Empc_Module_Metadata_Save;
41 41
42typedef struct Empc_Metadata_Result_Cb
43{
44 Empc_Module_Metadata_Fetch_Result_Cb cb;
45 void *data;
46 Eina_Bool force : 1;
47} Empc_Metadata_Result_Cb;
48
42typedef struct Empc_Fetch_Request_Internal 49typedef struct Empc_Fetch_Request_Internal
43{ 50{
44 Empc_Fetch_Request req; 51 Empc_Fetch_Request req;
45 Empc_Module *module; 52 Empc_Module *module;
46 Empc_Module_Metadata_Fetch_Result_Cb result; 53 Eina_List *results; //Empc_Metadata_Result_Cb
47 void *data;
48 unsigned int count; 54 unsigned int count;
49 Eina_Bool in_progress : 1; 55 Eina_Bool in_progress : 1;
50 Eina_Bool deleted : 1; 56 Eina_Bool deleted : 1;