summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2009-09-12 18:23:28 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2009-09-12 18:23:28 +0000
commitab2db3f4aa84f12da40a73923404e9ca957a87fd (patch)
treebdd317a132d432b0dcbe5bb78450da2cdfea6e47
parent8db7791cde8adf8d2d96251323dfaf8f0bd97fdd (diff)
API BREAK: update to match C API
SVN revision: 42446
-rw-r--r--ethumb/ethumb.client.pyx30
-rwxr-xr-xexamples/01-simple.py4
-rw-r--r--include/ethumb/client.pxd17
3 files changed, 25 insertions, 26 deletions
diff --git a/ethumb/ethumb.client.pyx b/ethumb/ethumb.client.pyx
index 3c0a6c0..c94c6fd 100644
--- a/ethumb/ethumb.client.pyx
+++ b/ethumb/ethumb.client.pyx
@@ -28,7 +28,7 @@ def shutdown():
28def init(): 28def init():
29 return ethumb_client_init() 29 return ethumb_client_init()
30 30
31cdef void _connect_cb(Ethumb_Client *client, Eina_Bool success, void *data) with gil: 31cdef void _connect_cb(void *data, Ethumb_Client *client, Eina_Bool success) with gil:
32 cdef Client self = <Client>data 32 cdef Client self = <Client>data
33 s = bool(<unsigned int>success) 33 s = bool(<unsigned int>success)
34 try: 34 try:
@@ -43,7 +43,7 @@ cdef void _connect_cb(Ethumb_Client *client, Eina_Bool success, void *data) with
43 self._on_connect_callback = None 43 self._on_connect_callback = None
44 44
45 45
46cdef void _on_server_die_cb(Ethumb_Client *client, void *data) with gil: 46cdef void _on_server_die_cb(void *data, Ethumb_Client *client) with gil:
47 cdef Client self = <Client>data 47 cdef Client self = <Client>data
48 if self._on_server_die_callback is not None: 48 if self._on_server_die_callback is not None:
49 try: 49 try:
@@ -58,20 +58,16 @@ cdef void _on_server_die_cb(Ethumb_Client *client, void *data) with gil:
58 self._on_server_die_callback = None 58 self._on_server_die_callback = None
59 59
60 60
61cdef void _generated_cb(int id, char *file, char *key, char *thumb_path, char *thumb_key, Eina_Bool success, void *data) with gil: 61cdef void _generated_cb(void *data, Ethumb_Client *client, int id, char *file, char *key, char *thumb_path, char *thumb_key, Eina_Bool success) with gil:
62 obj = <object>data 62 obj = <object>data
63 (self, func, args, kargs) = obj 63 (self, func, args, kargs) = obj
64 f = str_from_c(file) 64 f = str_from_c(file)
65 k = str_from_c(key) 65 k = str_from_c(key)
66 tp = str_from_c(thumb_path) 66 tp = str_from_c(thumb_path)
67 tk = str_from_c(thumb_key) 67 tk = str_from_c(thumb_key)
68 s = success != 0 68 s = bool(success != 0)
69 if success:
70 s = True
71 else:
72 s = False
73 try: 69 try:
74 func(id, f, k, tp, tk, s, *args, **kargs) 70 func(self, id, f, k, tp, tk, s, *args, **kargs)
75 except Exception, e: 71 except Exception, e:
76 traceback.print_exc() 72 traceback.print_exc()
77 73
@@ -137,7 +133,7 @@ cdef class Client:
137 raise SystemError("Error connecting to server.") 133 raise SystemError("Error connecting to server.")
138 else: 134 else:
139 ethumb_client_on_server_die_callback_set( 135 ethumb_client_on_server_die_callback_set(
140 self.obj, _on_server_die_cb, <void*>self) 136 self.obj, _on_server_die_cb, <void*>self, NULL)
141 137
142 def __dealloc__(self): 138 def __dealloc__(self):
143 if self.obj != NULL: 139 if self.obj != NULL:
@@ -569,7 +565,7 @@ cdef class Client:
569 565
570 @parm: B{func} function to call on generation completion, even 566 @parm: B{func} function to call on generation completion, even
571 if failed or succeeded. Signature is: 567 if failed or succeeded. Signature is:
572 C{func(id, file, key, thumb_path, thumb_key, status, *args, **kargs)} 568 C{func(self, id, file, key, thumb_path, thumb_key, status, *args, **kargs)}
573 with status being True for successful generation or 569 with status being True for successful generation or
574 False on failure. 570 False on failure.
575 571
@@ -597,24 +593,24 @@ cdef class Client:
597 raise SystemError("could not generate thumbnail. " 593 raise SystemError("could not generate thumbnail. "
598 "Did you set the file?") 594 "Did you set the file?")
599 595
600 def cancel(self, int id): 596 def generate_cancel(self, int id):
601 """Cancel thumbnail request. 597 """Cancel thumbnail request given its id.
602 598
603 Calling this function aborts thumbnail generation and B{func} 599 Calling this function aborts thumbnail generation and B{func}
604 given to L{generate()} will not be called! 600 given to L{generate()} will not be called!
605 601
606 @parm: B{id} identifier returned by L{generate()} 602 @parm: B{id} identifier returned by L{generate()}
607 """ 603 """
608 ethumb_client_queue_remove(self.obj, id, NULL, NULL) 604 ethumb_client_generate_cancel(self.obj, id, NULL, NULL, NULL)
609 605
610 def clear(self): 606 def generate_cancel_all(self):
611 """Clear request queue. 607 """Clear request queue, canceling all generation requests.
612 608
613 This will abort all existing requests, no B{func} given to 609 This will abort all existing requests, no B{func} given to
614 L{generate()} will be called. 610 L{generate()} will be called.
615 611
616 Same as calling L{cancel()} in all exising requests. 612 Same as calling L{cancel()} in all exising requests.
617 """ 613 """
618 ethumb_client_queue_clear(self.obj) 614 ethumb_client_generate_cancel_all(self.obj)
619 615
620init() 616init()
diff --git a/examples/01-simple.py b/examples/01-simple.py
index f039789..4ecc7e9 100755
--- a/examples/01-simple.py
+++ b/examples/01-simple.py
@@ -21,13 +21,13 @@ def pop_existent(client, files):
21 21
22def request_next(client, files): 22def request_next(client, files):
23 if pop_existent(client, files): 23 if pop_existent(client, files):
24 id = client.generate(generated_cb, files, client) 24 id = client.generate(generated_cb, files)
25 print "generating id=%d" % id 25 print "generating id=%d" % id
26 else: 26 else:
27 print "nothing left to generate." 27 print "nothing left to generate."
28 ecore.main_loop_quit() 28 ecore.main_loop_quit()
29 29
30def generated_cb(id, file, key, tpath, tkey, success, files, client): 30def generated_cb(client, id, file, key, tpath, tkey, success, files):
31 if success: 31 if success:
32 print "id=%d (%s, %s) successfully generated %s, %s" % \ 32 print "id=%d (%s, %s) successfully generated %s, %s" % \
33 (id, file, key, tpath, tkey) 33 (id, file, key, tpath, tkey)
diff --git a/include/ethumb/client.pxd b/include/ethumb/client.pxd
index a358087..d145875 100644
--- a/include/ethumb/client.pxd
+++ b/include/ethumb/client.pxd
@@ -20,15 +20,18 @@ cdef extern from "Eina.h":
20 20
21cdef extern from "Ethumb_Client.h": 21cdef extern from "Ethumb_Client.h":
22 ctypedef struct Ethumb_Client 22 ctypedef struct Ethumb_Client
23 ctypedef void (*connect_callback_t)(Ethumb_Client *client, Eina_Bool success, void *data) 23 ctypedef void (*Ethumb_Client_Connect_Cb)(void *data, Ethumb_Client *client, Eina_Bool success)
24 ctypedef void (*generated_callback_t)(int id, char *file, char *key, char *thumb_path, char *thumb_key, Eina_Bool success, void *data) 24 ctypedef void (*Ethumb_Client_Die_Cb)(void *data, Ethumb_Client *client)
25 ctypedef void (*Ethumb_Client_Generate_Cb)(void *data, Ethumb_Client *client, int id, char *file, char *key, char *thumb_path, char *thumb_key, Eina_Bool success)
26 ctypedef void (*Ethumb_Client_Generate_Cancel_Cb)(void *data, Eina_Bool success)
27 ctypedef void (*Eina_Free_Cb)(void *data)
25 28
26 int ethumb_client_init() 29 int ethumb_client_init()
27 ethumb_client_shutdown() 30 ethumb_client_shutdown()
28 31
29 Ethumb_Client *ethumb_client_connect(connect_callback_t cb, void *data, void (*free_data)(void *)) 32 Ethumb_Client *ethumb_client_connect(Ethumb_Client_Connect_Cb cb, void *data, Eina_Free_Cb free_data)
30 void ethumb_client_disconnect(Ethumb_Client *client) 33 void ethumb_client_disconnect(Ethumb_Client *client)
31 void ethumb_client_on_server_die_callback_set(Ethumb_Client *client, void (*on_server_die_cb)(Ethumb_Client *client, void *data), void *data) 34 void ethumb_client_on_server_die_callback_set(Ethumb_Client *client, Ethumb_Client_Die_Cb server_die_cb, void *data, Eina_Free_Cb free_data)
32 35
33 void ethumb_client_fdo_set(Ethumb_Client *client, int s) 36 void ethumb_client_fdo_set(Ethumb_Client *client, int s)
34 37
@@ -63,9 +66,9 @@ cdef extern from "Ethumb_Client.h":
63 void ethumb_client_thumb_path_set(Ethumb_Client *client, char *path, char *key) 66 void ethumb_client_thumb_path_set(Ethumb_Client *client, char *path, char *key)
64 void ethumb_client_thumb_path_get(Ethumb_Client *client, char **path, char **key) 67 void ethumb_client_thumb_path_get(Ethumb_Client *client, char **path, char **key)
65 Eina_Bool ethumb_client_thumb_exists(Ethumb_Client *client) 68 Eina_Bool ethumb_client_thumb_exists(Ethumb_Client *client)
66 int ethumb_client_generate(Ethumb_Client *client, generated_callback_t generated_cb, void *data, void (*free_data)(void *)) 69 int ethumb_client_generate(Ethumb_Client *client, Ethumb_Client_Generate_Cb generated_cb, void *data, Eina_Free_Cb free_data)
67 void ethumb_client_queue_remove(Ethumb_Client *client, int id, void (*queue_remove_cb)(Eina_Bool success, void *data), void *data) 70 void ethumb_client_generate_cancel(Ethumb_Client *client, int id, Ethumb_Client_Generate_Cancel_Cb cancel_cb, void *data, Eina_Free_Cb free_data)
68 void ethumb_client_queue_clear(Ethumb_Client *client) 71 void ethumb_client_generate_cancel_all(Ethumb_Client *client)
69 72
70cdef class Client: 73cdef class Client:
71 cdef Ethumb_Client *obj 74 cdef Ethumb_Client *obj