summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/eet/cipher.rst6
-rw-r--r--doc/eet/data.rst10
-rw-r--r--doc/eet/eet.rst17
-rw-r--r--doc/eet/file.rst21
-rw-r--r--doc/index.rst5
-rw-r--r--efl/eet/connection.pxi140
-rw-r--r--efl/eet/data_descriptor.pxi653
-rw-r--r--efl/eet/data_descriptor_class.pxi176
-rw-r--r--efl/eet/data_utils.pxi622
-rw-r--r--efl/eet/dictionary.pxi45
-rw-r--r--efl/eet/eet.pxd309
-rw-r--r--efl/eet/eet.pyx197
-rw-r--r--efl/eet/enums.pxd50
-rw-r--r--efl/eet/file.pxi1356
-rw-r--r--efl/eet/key.pxi80
-rw-r--r--efl/eet/node.pxi328
-rw-r--r--include/efl.eet.enums.pxd50
-rwxr-xr-xsetup.py10
18 files changed, 4075 insertions, 0 deletions
diff --git a/doc/eet/cipher.rst b/doc/eet/cipher.rst
new file mode 100644
index 0000000..44d83f3
--- /dev/null
+++ b/doc/eet/cipher.rst
@@ -0,0 +1,6 @@
1.. currentmodule:: efl.eet
2
3.. _Eet_Cipher_Group:
4
5Cipher, Identity and Protection Mechanisms
6==========================================
diff --git a/doc/eet/data.rst b/doc/eet/data.rst
new file mode 100644
index 0000000..b40f020
--- /dev/null
+++ b/doc/eet/data.rst
@@ -0,0 +1,10 @@
1.. currentmodule:: efl.eet
2
3.. _Eet_Data_Group:
4
5Eet Data Serialization
6=======================
7
8.. autoclass:: EetDataDescriptor
9
10.. autoclass:: EetDataDescriptorClass
diff --git a/doc/eet/eet.rst b/doc/eet/eet.rst
new file mode 100644
index 0000000..a300777
--- /dev/null
+++ b/doc/eet/eet.rst
@@ -0,0 +1,17 @@
1:mod:`efl.eet` Module
2=======================
3
4.. automodule:: efl.eet
5
6.. autofunction:: init
7
8.. autofunction:: shutdown
9
10.. autofunction:: clearcache
11
12.. autoexception:: EetError
13
14.. toctree::
15
16 file
17 cipher
diff --git a/doc/eet/file.rst b/doc/eet/file.rst
new file mode 100644
index 0000000..2572f2b
--- /dev/null
+++ b/doc/eet/file.rst
@@ -0,0 +1,21 @@
1.. currentmodule:: efl.eet
2
3.. _Eet_File_Group:
4
5Eet File Main Functions
6=======================
7
8:class:`efl.eet.EetDictionary` Class
9------------------------------------
10
11.. autoclass:: EetDictionary
12
13:class:`efl.eet.EetEntry` Class
14--------------------------------
15
16.. autoclass:: EetEntry
17
18:class:`efl.eet.EetFile` Class
19-------------------------------
20
21.. autoclass:: EetFile
diff --git a/doc/index.rst b/doc/index.rst
index ac42901..b4c68e4 100644
--- a/doc/index.rst
+++ b/doc/index.rst
@@ -42,6 +42,11 @@ EO
42.. toctree:: eo/eo.rst 42.. toctree:: eo/eo.rst
43 43
44 44
45Eet
46---
47
48.. toctree:: eet/eet
49
45Ecore 50Ecore
46----- 51-----
47 52
diff --git a/efl/eet/connection.pxi b/efl/eet/connection.pxi
new file mode 100644
index 0000000..eb5946f
--- /dev/null
+++ b/efl/eet/connection.pxi
@@ -0,0 +1,140 @@
1"""
2
3@typedef Eet_Connection
4Opaque handle to track paquet for a specific connection.
5
6
7"""
8typedef struct _Eet_Connection Eet_Connection;
9
10"""
11
12@typedef Eet_Read_Cb
13Called back when an :ref:`Eet_Data_Group` has been received completely and could be used.
14
15
16"""
17typedef Eina_Bool Eet_Read_Cb (const void *eet_data, size_t size, void *user_data);
18
19"""
20
21@typedef Eet_Write_Cb
22Called back when a packet containing :ref:`Eet_Data_Group` data is ready to be send.
23
24
25"""
26typedef Eina_Bool Eet_Write_Cb (const void *data, size_t size, void *user_data);
27
28"""
29
30Instanciate a new connection to track.
31:param eet_read_cb: Function to call when one Eet_Data packet has been fully assemble.
32:param eet_write_cb: Function to call when one Eet_Data packet is ready to be send over the wire.
33:param user_data: Pointer provided to both functions to be used as a context handler.
34:return: NULL on failure, or a valid Eet_Connection handler.
35
36For every connection to track you will need a separate Eet_Connection provider.
37
38:since: 1.2.4
39
40"""
41EAPI Eet_Connection *
42eet_connection_new(Eet_Read_Cb *eet_read_cb,
43 Eet_Write_Cb *eet_write_cb,
44 const void *user_data);
45
46"""
47
48Process a raw packet received over the link
49:param conn: Connection handler to track.
50:param data: Raw data packet.
51:param size: The size of that packet.
52:return: 0 on complete success, any other value indicate where in the stream it got wrong (It could be before that packet).
53
54Every time you receive a packet related to your connection, you should pass
55it to that function so that it could process and assemble packet has you
56receive it. It will automatically call Eet_Read_Cb when one is fully received.
57
58:since: 1.2.4
59
60"""
61EAPI int
62eet_connection_received(Eet_Connection *conn,
63 const void *data,
64 size_t size);
65
66"""
67
68Tell if the Eet_Connection as received some partial data.
69:param conn: Connection handler to request.
70:return: EINA_TRUE if there is some data pending inside, EINA_FALSE otherwise.
71
72Eet_Connection buffer data until the received data can be unserialized correctly. This
73function let you know if there is some data inside that buffer waiting for more data to
74be received before being processed.
75
76:since: 1.7
77
78"""
79EAPI Eina_Bool eet_connection_empty(Eet_Connection *conn);
80
81"""
82
83Convert a complex structure and prepare it to be send.
84:param conn: Connection handler to track.
85:param edd: The data descriptor to use when encoding.
86:param data_in: The pointer to the struct to encode into data.
87:param cipher_key: The key to use as cipher.
88:return: EINA_TRUE if the data where correctly send, EINA_FALSE if they don't.
89
90This function serialize data_in with edd, assemble the packet and call
91Eet_Write_Cb when ready. The data passed Eet_Write_Cb are temporary allocated
92and will vanish just after the return of the callback.
93
94:see: eet_data_descriptor_encode_cipher
95
96:since: 1.2.4
97
98"""
99EAPI Eina_Bool
100eet_connection_send(Eet_Connection *conn,
101 Eet_Data_Descriptor *edd,
102 const void *data_in,
103 const char *cipher_key);
104
105"""
106
107Convert a Eet_Node tree and prepare it to be send.
108:param conn: Connection handler to track.
109:param node: The data tree to use when encoding.
110:param cipher_key: The key to use as cipher.
111:return: EINA_TRUE if the data where correctly send, EINA_FALSE if they don't.
112
113This function serialize node, assemble the packet and call
114Eet_Write_Cb when ready. The data passed Eet_Write_Cb are temporary allocated
115and will vanish just after the return of the callback.
116
117:see: eet_data_node_encode_cipher
118
119:since: 1.2.4
120
121"""
122EAPI Eina_Bool
123eet_connection_node_send(Eet_Connection *conn,
124 Eet_Node *node,
125 const char *cipher_key);
126
127"""
128
129Close a connection and lost its track.
130:param conn: Connection handler to close.
131:param on_going: Signal if a partial packet wasn't completed.
132:return: the user_data passed to both callback.
133
134:since: 1.2.4
135
136"""
137EAPI void *
138eet_connection_close(Eet_Connection *conn,
139 Eina_Bool *on_going);
140
diff --git a/efl/eet/data_descriptor.pxi b/efl/eet/data_descriptor.pxi
new file mode 100644
index 0000000..97b76e2
--- /dev/null
+++ b/efl/eet/data_descriptor.pxi
@@ -0,0 +1,653 @@
1
2
3#define EET_T_UNKNOW 0 # Unknown data encoding type
4#define EET_T_CHAR 1 # Data type: char
5#define EET_T_SHORT 2 # Data type: short
6#define EET_T_INT 3 # Data type: int
7#define EET_T_LONG_LONG 4 # Data type: long long
8#define EET_T_FLOAT 5 # Data type: float
9#define EET_T_DOUBLE 6 # Data type: double
10#define EET_T_UCHAR 7 # Data type: unsigned char
11#define EET_T_USHORT 8 # Data type: unsigned short
12#define EET_T_UINT 9 # Data type: unsigned int
13#define EET_T_ULONG_LONG 10 # Data type: unsigned long long
14#define EET_T_STRING 11 # Data type: char *
15#define EET_T_INLINED_STRING 12 # Data type: char * (but compressed inside the resulting eet)
16#define EET_T_NULL 13 # Data type: (void *) (only use it if you know why)
17#define EET_T_F32P32 14 # Data type: fixed point 32.32
18#define EET_T_F16P16 15 # Data type: fixed point 16.16
19#define EET_T_F8P24 16 # Data type: fixed point 8.24
20#define EET_T_VALUE 17 # Data type: pointer to Eina_Value :since: 1.8
21#define EET_T_LAST 18 # Last data type
22
23#define EET_G_UNKNOWN 100 # Unknown group data encoding type
24#define EET_G_ARRAY 101 # Fixed size array group type
25#define EET_G_VAR_ARRAY 102 # Variable size array group type
26#define EET_G_LIST 103 # Linked list group type
27#define EET_G_HASH 104 # Hash table group type
28#define EET_G_UNION 105 # Union group type
29#define EET_G_VARIANT 106 # Selectable subtype group
30#define EET_G_UNKNOWN_NESTED 107 # Unknown nested group type. :since: 1.8
31#define EET_G_LAST 108 # Last group type
32
33#define EET_I_LIMIT 128 # Other type exist but are reserved for internal purpose.
34
35
36cdef class EetDataDescriptor(object):
37
38 """
39
40 Opaque handle that have information on a type members.
41
42 Descriptors are created using an #Eet_Data_Descriptor_Class, and they
43 describe the contents of the structure that will be serialized by Eet.
44 Not all members need be described by it, just those that should be handled
45 by Eet. This way it's possible to have one structure with both data to be
46 saved to a file, like application configuration, and runtime information
47 that would be meaningless to store, but is appropriate to keep together
48 during the program execution.
49 The members are added by means of
50 EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB(),
51 EET_DATA_DESCRIPTOR_ADD_LIST(), EET_DATA_DESCRIPTOR_ADD_HASH()
52 or eet_data_descriptor_element_add().
53
54 :see: eet_data_descriptor_stream_new()
55 :see: eet_data_descriptor_file_new()
56 :see: eet_data_descriptor_free()
57
58 """
59
60 cdef Eet_Data_Descriptor *edd
61
62 def __init__(self, cls):
63 """
64
65 This function creates a new data descriptor and returns a handle to the
66 new data descriptor. On creation it will be empty, containing no
67 contents describing anything other than the shell of the data structure.
68 :param eddc: The class from where to create the data descriptor.
69 :return: A handle to the new data descriptor.
70
71 You add structure members to the data descriptor using the macros
72 EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
73 EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
74 adding to the description.
75
76 Once you have described all the members of a struct you want loaded or
77 saved, eet can load and save those members for you, encode them into
78 endian-independent serialised data chunks for transmission across a
79 network or more.
80
81 This function specially ignores str_direct_alloc and str_direct_free. It
82 is useful when the eet_data you are reading doesn't have a dictionary,
83 like network stream or IPC. It also mean that all string will be
84 allocated and duplicated in memory.
85
86 :since: 1.2.3
87
88 """
89 self.edd = eet_data_descriptor_stream_new(cls.eddc)
90
91 def file_new(self, cls):
92 """
93
94 This function creates a new data descriptor and returns a handle to the
95 new data descriptor. On creation it will be empty, containing no
96 contents describing anything other than the shell of the data structure.
97 :param eddc: The class from where to create the data descriptor.
98 :return: A handle to the new data descriptor.
99
100 You add structure members to the data descriptor using the macros
101 EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
102 EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
103 adding to the description.
104
105 Once you have described all the members of a struct you want loaded or
106 saved, eet can load and save those members for you, encode them into
107 endian-independent serialised data chunks for transmission across a
108 a network or more.
109
110 This function uses str_direct_alloc and str_direct_free. It is useful
111 when the eet_data you are reading come from a file and have a
112 dictionary. This will reduce memory use and improve the possibility for
113 the OS to page this string out.
114
115 However, the load speed and memory saving comes with some drawbacks to
116 keep in mind. If you never modify the contents of the structures loaded
117 from the file, all you need to remember is that closing the eet file
118 will make the strings go away. On the other hand, should you need to
119 free a string, before doing so you have to verify that it's not part of
120 the eet dictionary. You can do this in the following way, assuming @p ef
121 is a valid Eet_File and @p str is a string loaded from said file.
122
123 @code
124 void eet_string_free(Eet_File *ef, const char *str)
125 {
126 Eet_Dictionary *dict = eet_dictionary_get(ef);
127 if (dict && eet_dictionary_string_check(dict, str))
128 {
129 // The file contains a dictionary and the given string is a part of
130 // of it, so we can't free it, just return.
131 return;
132 }
133 // We assume eina_stringshare was used on the descriptor
134 eina_stringshare_del(str);
135 }
136 @endcode
137
138 :since: 1.2.3
139
140 """
141 self.edd = eet_data_descriptor_file_new(cls.eddc)
142
143 def free(self):
144 """
145
146 This function frees a data descriptor when it is not needed anymore.
147 :param edd: The data descriptor to free.
148
149 This function takes a data descriptor handle as a parameter and frees all
150 data allocated for the data descriptor and the handle itself. After this
151 call the descriptor is no longer valid.
152
153 :since: 1.0.0
154
155 """
156 eet_data_descriptor_free(self.edd)
157
158 property name:
159 """
160
161 This function returns the name of a data descriptor.
162
163 :since: 1.8.0
164
165 """
166 return _ctouni(eet_data_descriptor_name_get(self.edd)
167
168
169 def decode(self, data_in, size_in):
170 """
171
172 Decode a data structure from an arbitrary location in memory.
173 :param edd: The data descriptor to use when decoding.
174 :param data_in: The pointer to the data to decode into a struct.
175 :param size_in: The size of the data pointed to in bytes.
176 :return: NULL on failure, or a valid decoded struct pointer on success.
177
178 This function will decode a data structure that has been encoded using
179 eet_data_descriptor_encode(), and return a data structure with all its
180 elements filled out, if successful, or NULL on failure.
181
182 The data to be decoded is stored at the memory pointed to by @p data_in,
183 and is described by the descriptor pointed to by @p edd. The data size is
184 passed in as the value to @p size_in, ande must be greater than 0 to
185 succeed.
186
187 This function is useful for decoding data structures delivered to the
188 application by means other than an eet file, such as an IPC or socket
189 connection, raw files, shared memory etc.
190
191 Please see eet_data_read() for more information.
192
193 @see eet_data_descriptor_decode_cipher()
194
195 :since: 1.0.0
196
197 """
198 EAPI void *
199 eet_data_descriptor_decode(Eet_Data_Descriptor *edd,
200 const void *data_in,
201 int size_in);
202
203 def encode(self, data_in):
204 """
205
206 Encode a dsata struct to memory and return that encoded data.
207 :param edd: The data descriptor to use when encoding.
208 :param data_in: The pointer to the struct to encode into data.
209 :param size_ret: pointer to the an int to be filled with the decoded size.
210 :return: NULL on failure, or a valid encoded data chunk on success.
211
212 This function takes a data structutre in memory and encodes it into a
213 serialised chunk of data that can be decoded again by
214 eet_data_descriptor_decode(). This is useful for being able to transmit
215 data structures across sockets, pipes, IPC or shared file mechanisms,
216 without having to worry about memory space, machine type, endianness etc.
217
218 The parameter @p edd must point to a valid data descriptor, and
219 @p data_in must point to the right data structure to encode. If not, the
220 encoding may fail.
221
222 On success a non NULL valid pointer is returned and what @p size_ret
223 points to is set to the size of this decoded data, in bytes. When the
224 encoded data is no longer needed, call free() on it. On failure NULL is
225 returned and what @p size_ret points to is set to 0.
226
227 Please see eet_data_write() for more information.
228
229 @see eet_data_descriptor_encode_cipher()
230
231 :since: 1.0.0
232
233 """
234 EAPI void *
235 eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
236 const void *data_in,
237 int *size_ret);
238
239 def decode_cipher(self, data_in, cipher_key, size_in):
240 """
241
242 Decode a data structure from an arbitrary location in memory
243 using a cipher.
244 :param edd: The data descriptor to use when decoding.
245 :param data_in: The pointer to the data to decode into a struct.
246 :param cipher_key: The key to use as cipher.
247 :param size_in: The size of the data pointed to in bytes.
248 :return: NULL on failure, or a valid decoded struct pointer on success.
249
250 This function will decode a data structure that has been encoded using
251 eet_data_descriptor_encode(), and return a data structure with all its
252 elements filled out, if successful, or NULL on failure.
253
254 The data to be decoded is stored at the memory pointed to by @p data_in,
255 and is described by the descriptor pointed to by @p edd. The data size is
256 passed in as the value to @p size_in, ande must be greater than 0 to
257 succeed.
258
259 This function is useful for decoding data structures delivered to the
260 application by means other than an eet file, such as an IPC or socket
261 connection, raw files, shared memory etc.
262
263 Please see eet_data_read() for more information.
264
265 @see eet_data_descriptor_decode()
266
267 :since: 1.0.0
268
269 """
270 EAPI void *
271 eet_data_descriptor_decode_cipher(Eet_Data_Descriptor *edd,
272 const void *data_in,
273 const char *cipher_key,
274 int size_in);
275
276 def encode_cipher(self, data_in, cipher_key):
277 """
278
279 Encode a data struct to memory and return that encoded data
280 using a cipher.
281 :param edd: The data descriptor to use when encoding.
282 :param data_in: The pointer to the struct to encode into data.
283 :param cipher_key: The key to use as cipher.
284 :param size_ret: pointer to the an int to be filled with the decoded size.
285 :return: NULL on failure, or a valid encoded data chunk on success.
286
287 This function takes a data structutre in memory and encodes it into a
288 serialised chunk of data that can be decoded again by
289 eet_data_descriptor_decode(). This is useful for being able to transmit
290 data structures across sockets, pipes, IPC or shared file mechanisms,
291 without having to worry about memory space, machine type, endianess etc.
292
293 The parameter @p edd must point to a valid data descriptor, and
294 @p data_in must point to the right data structure to encode. If not, the
295 encoding may fail.
296
297 On success a non NULL valid pointer is returned and what @p size_ret
298 points to is set to the size of this decoded data, in bytes. When the
299 encoded data is no longer needed, call free() on it. On failure NULL is
300 returned and what @p size_ret points to is set to 0.
301
302 Please see eet_data_write() for more information.
303
304 @see eet_data_descriptor_encode()
305
306 :since: 1.0.0
307
308 """
309 EAPI void *
310 eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd,
311 const void *data_in,
312 const char *cipher_key,
313 int *size_ret);
314
315
316 def add_basic(self, struct_type, name, member, type):
317 """
318
319 Add a basic data element to a data descriptor.
320 :param edd: The data descriptor to add the type to.
321 :param struct_type: The type of the struct.
322 :param name: The string name to use to encode/decode this member
323 (must be a constant global and never change).
324 :param member: The struct member itself to be encoded.
325 :param type: The type of the member to encode.
326
327 This macro is a convenience macro provided to add a member to
328 the data descriptor @p edd. The type of the structure is
329 provided as the @p struct_type parameter (for example: struct
330 my_struct). The @p name parameter defines a string that will be
331 used to uniquely name that member of the struct (it is suggested
332 to use the struct member itself). The @p member parameter is
333 the actual struct member itself (for example: values), and @p type is the
334 basic data type of the member which must be one of: EET_T_CHAR, EET_T_SHORT,
335 EET_T_INT, EET_T_LONG_LONG, EET_T_FLOAT, EET_T_DOUBLE, EET_T_UCHAR,
336 EET_T_USHORT, EET_T_UINT, EET_T_ULONG_LONG or EET_T_STRING.
337
338 :since: 1.0.0
339
340 """
341 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct_type, name, member, type)
342
343 def add_sub(self, struct_type, name, member, subtype):
344 """
345
346 Add a sub-element type to a data descriptor
347 :param edd: The data descriptor to add the type to.
348 :param struct_type: The type of the struct.
349 :param name: The string name to use to encode/decode this member
350 (must be a constant global and never change).
351 :param member: The struct member itself to be encoded.
352 :param subtype: The type of sub-type struct to add.
353
354 This macro lets you easily add a sub-type (a struct that's pointed to
355 by this one). All the parameters are the same as for
356 EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the exception.
357 This must be the data descriptor of the struct that is pointed to by
358 this element.
359
360 :since: 1.0.0
361
362 """
363 EET_DATA_DESCRIPTOR_ADD_SUB(edd, struct_type, name, member, subtype)
364
365 def add_sub_nested(self, struct_type, name, member, subtype):
366 """
367
368 Add a nested sub-element type to a data descriptor
369 :param edd: The data descriptor to add the type to.
370 :param struct_type: The type of the struct.
371 :param name: The string name to use to encode/decode this member
372 (must be a constant global and never change).
373 :param member: The struct member itself to be encoded.
374 :param subtype: The type of sub-type struct to add.
375
376 This macro lets you easily add a sub-type: a struct that is nested into
377 this one. If your data is pointed by this element instead of being nested,
378 you should use EET_DATA_DESCRIPTOR_ADD_SUB().
379 All the parameters are the same as for EET_DATA_DESCRIPTOR_ADD_SUB().
380
381 :since: 1.8.0
382
383 """
384 EET_DATA_DESCRIPTOR_ADD_SUB_NESTED(edd, struct_type, name, member, subtype)
385
386 def add_list(self, struct_type, name, member, subtype):
387 """
388
389 Add a linked list type to a data descriptor
390 :param edd: The data descriptor to add the type to.
391 :param struct_type: The type of the struct.
392 :param name: The string name to use to encode/decode this member
393 (must be a constant global and never change).
394 :param member: The struct member itself to be encoded.
395 :param subtype: The type of linked list member to add.
396
397 This macro lets you easily add a linked list of other data types. All the
398 parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC(), with the
399 @p subtype being the exception. This must be the data descriptor of the
400 element that is in each member of the linked list to be stored.
401
402 :since: 1.0.0
403
404 """
405 EET_DATA_DESCRIPTOR_ADD_LIST(edd, struct_type, name, member, subtype)
406
407 def add_list_string(self, struct_type, name, member):
408 """
409
410 Add a linked list of string to a data descriptor
411 :param edd: The data descriptor to add the type to.
412 :param struct_type: The type of the struct.
413 :param name: The string name to use to encode/decode this member
414 (must be a constant global and never change).
415 :param member: The struct member itself to be encoded.
416
417 This macro lets you easily add a linked list of char *. All the
418 parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC().
419
420 :since: 1.5.0
421
422 """
423 EET_DATA_DESCRIPTOR_ADD_LIST_STRING(edd, struct_type, name, member)
424
425 def add_hash(self, struct_type, name, member, subtype):
426 """
427
428 Add a hash type to a data descriptor
429 :param edd: The data descriptor to add the type to.
430 :param struct_type: The type of the struct.
431 :param name: The string name to use to encode/decode this member
432 (must be a constant global and never change).
433 :param member: The struct member itself to be encoded.
434 :param subtype: The type of hash member to add.
435
436 This macro lets you easily add a hash of other data types. All the
437 parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC(), with the
438 @p subtype being the exception. This must be the data descriptor of the
439 element that is in each member of the hash to be stored.
440 The hash keys must be strings.
441
442 :since: 1.0.0
443
444 """
445 EET_DATA_DESCRIPTOR_ADD_HASH(edd, struct_type, name, member, subtype)
446
447 def add_hash_string(self, struct_type, name, member):
448 """
449
450 Add a hash of string to a data descriptor
451 :param edd: The data descriptor to add the type to.
452 :param struct_type: The type of the struct.
453 :param name: The string name to use to encode/decode this member
454 (must be a constant global and never change).
455 :param member: The struct member itself to be encoded.
456
457 This macro lets you easily add a hash of string elements. All the
458 parameters are the same as for EET_DATA_DESCRIPTOR_ADD_HASH().
459
460 :since: 1.3.4
461
462 """
463 EET_DATA_DESCRIPTOR_ADD_HASH_STRING(edd, struct_type, name, member)
464
465 def add_basic_array(self, struct_type, name, member, type):
466 """
467
468 Add an array of basic data elements to a data descriptor.
469 :param edd: The data descriptor to add the type to.
470 :param struct_type: The type of the struct.
471 :param name: The string name to use to encode/decode this member
472 (must be a constant global and never change).
473 :param member: The struct member itself to be encoded.
474 :param type: The type of the member to encode.
475
476 This macro lets you easily add a fixed size array of basic data
477 types. All the parameters are the same as for
478 EET_DATA_DESCRIPTOR_ADD_BASIC().
479 The array must be defined with a fixed size in the declaration of the
480 struct containing it.
481
482 :since: 1.5.0
483
484 """
485 EET_DATA_DESCRIPTOR_ADD_BASIC_ARRAY(edd, struct_type, name, member, type)
486
487 def add_basic_var_array(self, struct_type, name, member, type):
488 """
489
490 Add a variable array of basic data elements to a data descriptor.
491 :param edd: The data descriptor to add the type to.
492 :param struct_type: The type of the struct.
493 :param name: The string name to use to encode/decode this member
494 (must be a constant global and never change).
495 :param member: The struct member itself to be encoded.
496 :param type: The type of the member to encode.
497
498 This macro lets you easily add a variable size array of basic data
499 types. All the parameters are the same as for
500 EET_DATA_DESCRIPTOR_ADD_BASIC(). This assumes you have
501 a struct member (of type EET_T_INT) called member_count (note the
502 _count appended to the member) that holds the number of items in
503 the array. This array will be allocated separately to the struct it
504 is in.
505
506 :since: 1.6.0
507
508 """
509 EET_DATA_DESCRIPTOR_ADD_BASIC_VAR_ARRAY(edd, struct_type, name, member, type)
510
511 def add_array(self, struct_type, name, member, subtype):
512 """
513
514 Add a fixed size array type to a data descriptor
515 :param edd: The data descriptor to add the type to.
516 :param struct_type: The type of the struct.
517 :param name: The string name to use to encode/decode this member
518 (must be a constant global and never change).
519 :param member: The struct member itself to be encoded.
520 :param subtype: The type of hash member to add.
521
522 This macro lets you easily add a fixed size array of other data
523 types. All the parameters are the same as for
524 EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the
525 exception. This must be the data descriptor of the element that
526 is in each member of the array to be stored.
527 The array must be defined with a fixed size in the declaration of the
528 struct containing it.
529
530 :since: 1.0.2
531
532 """
533 EET_DATA_DESCRIPTOR_ADD_ARRAY(edd, struct_type, name, member, subtype)
534
535 def add_var_array(self, struct_type, name, member, subtype):
536 """
537
538 Add a variable size array type to a data descriptor
539 :param edd: The data descriptor to add the type to.
540 :param struct_type: The type of the struct.
541 :param name: The string name to use to encode/decode this member
542 (must be a constant global and never change).
543 :param member: The struct member itself to be encoded.
544 :param subtype: The type of hash member to add.
545
546 This macro lets you easily add a variable size array of other data
547 types. All the parameters are the same as for
548 EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the
549 exception. This must be the data descriptor of the element that
550 is in each member of the array to be stored. This assumes you have
551 a struct member (of type EET_T_INT) called member_count (note the
552 _count appended to the member) that holds the number of items in
553 the array. This array will be allocated separately to the struct it
554 is in.
555
556 :since: 1.0.2
557
558 """
559 EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY(edd, struct_type, name, member, subtype)
560
561 def add_var_array_string(self, struct_type, name, member):
562 """
563
564 Add a variable size array type to a data descriptor
565 :param edd: The data descriptor to add the type to.
566 :param struct_type: The type of the struct.
567 :param name: The string name to use to encode/decode this member
568 (must be a constant global and never change).
569 :param member: The struct member itself to be encoded.
570
571 This macro lets you easily add a variable size array of strings. All
572 the parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC().
573
574 :since: 1.4.0
575
576 """
577 EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY_STRING(edd, struct_type, name, member)
578
579 def add_union(self, struct_type, name, member, type_member, unified_type):
580 """
581
582 Add an union type to a data descriptor
583 :param edd: The data descriptor to add the type to.
584 :param struct_type: The type of the struct.
585 :param name: The string name to use to encode/decode this member
586 (must be a constant global and never change).
587 :param member: The struct member itself to be encoded.
588 :param type_member: The member that give hints on what is in the union.
589 :param unified_type: Describe all possible type the union could handle.
590
591 This macro lets you easily add an union with a member that specify what is inside.
592 The @p unified_type is an Eet_Data_Descriptor, but only the entry that match the name
593 returned by type_get will be used for each serialized data. The type_get and type_set
594 callback of unified_type should be defined.
595
596 :since: 1.2.4
597 :see: Eet_Data_Descriptor_Class
598
599 """
600 EET_DATA_DESCRIPTOR_ADD_UNION(edd, struct_type, name, member, type_member, unified_type)
601
602 def add_variant(self, struct_type, name, member, type_member, unified_type):
603 """
604
605 Add a automatically selectable type to a data descriptor
606 :param edd: The data descriptor to add the type to.
607 :param struct_type: The type of the struct.
608 :param name: The string name to use to encode/decode this member
609 (must be a constant global and never change).
610 :param member: The struct member itself to be encoded.
611 :param type_member: The member that give hints on what is in the union.
612 :param unified_type: Describe all possible type the union could handle.
613
614 This macro lets you easily define what the content of @p member points to depending of
615 the content of @p type_member. The type_get and type_set callback of unified_type should
616 be defined. If the the type is not know at the time of restoring it, eet will still call
617 type_set of @p unified_type but the pointer will be set to a serialized binary representation
618 of what eet know. This make it possible, to save this pointer again by just returning the string
619 given previously and telling it by setting unknow to EINA_TRUE.
620
621 :since: 1.2.4
622 :see: Eet_Data_Descriptor_Class
623
624 """
625 EET_DATA_DESCRIPTOR_ADD_VARIANT(edd, struct_type, name, member, type_member, unified_type)
626
627 def add_mapping(self, name, subtype):
628 """
629
630 Add a mapping to a data descriptor that will be used by union, variant or inherited type
631 :param unified_type: The data descriptor to add the mapping to.
632 :param name: The string name to get/set type.
633 :param subtype: The matching data descriptor.
634
635 :since: 1.2.4
636 :see: Eet_Data_Descriptor_Class
637
638 """
639 EET_DATA_DESCRIPTOR_ADD_MAPPING(unified_type, name, subtype)
640
641 def add_mapping_basic(self, name, basic_type):
642 """
643
644 Add a mapping of a basic type to a data descriptor that will be used by a union type.
645 :param unified_type: The data descriptor to add the mapping to.
646 :param name: The string name to get/set type.
647 :param basic_type: The matching basic type.
648
649 :since: 1.8
650 :see: Eet_Data_Descriptor_Class
651
652 """
653 EET_DATA_DESCRIPTOR_ADD_MAPPING_BASIC(unified_type, name, basic_type)
diff --git a/efl/eet/data_descriptor_class.pxi b/efl/eet/data_descriptor_class.pxi
new file mode 100644
index 0000000..a32fbeb
--- /dev/null
+++ b/efl/eet/data_descriptor_class.pxi
@@ -0,0 +1,176 @@
1
2
3"""
4
5@def EET_DATA_DESCRIPTOR_CLASS_VERSION
6The version of #Eet_Data_Descriptor_Class at the time of the
7distribution of the sources. One should define this to its
8version member so it is compatible with abi changes, or at least
9will not crash with them.
10
11"""
12#define EET_DATA_DESCRIPTOR_CLASS_VERSION 4
13
14
15
16"""
17
18@typedef Eet_Data_Descriptor_Class
19
20Instructs Eet about memory management for different needs under
21serialization and parse process.
22
23"""
24typedef struct _Eet_Data_Descriptor_Class Eet_Data_Descriptor_Class;
25
26typedef int (*Eet_Descriptor_Hash_Foreach_Callback_Callback)(void *h, const char *k, void *dt, void *fdt);
27
28typedef void * (*Eet_Descriptor_Mem_Alloc_Callback)(size_t size);
29typedef void (*Eet_Descriptor_Mem_Free_Callback)(void *mem);
30typedef char * (*Eet_Descriptor_Str_Alloc_Callback)(const char *str);
31typedef void (*Eet_Descriptor_Str_Free_Callback)(const char *str);
32typedef void * (*Eet_Descriptor_List_Next_Callback)(void *l);
33typedef void * (*Eet_Descriptor_List_Append_Callback)(void *l, void *d);
34typedef void * (*Eet_Descriptor_List_Data_Callback)(void *l);
35typedef void * (*Eet_Descriptor_List_Free_Callback)(void *l);
36typedef void (*Eet_Descriptor_Hash_Foreach_Callback)(void *h, Eet_Descriptor_Hash_Foreach_Callback_Callback func, void *fdt);
37typedef void * (*Eet_Descriptor_Hash_Add_Callback)(void *h, const char *k, void *d);
38typedef void (*Eet_Descriptor_Hash_Free_Callback)(void *h);
39typedef char * (*Eet_Descriptor_Str_Direct_Alloc_Callback)(const char *str);
40typedef void (*Eet_Descriptor_Str_Direct_Free_Callback)(const char *str);
41typedef const char * (*Eet_Descriptor_Type_Get_Callback)(const void *data, Eina_Bool *unknow);
42typedef Eina_Bool (*Eet_Descriptor_Type_Set_Callback)(const char *type, void *data, Eina_Bool unknow);
43typedef void * (*Eet_Descriptor_Array_Alloc_Callback)(size_t size);
44typedef void (*Eet_Descriptor_Array_Free_Callback)(void *mem);
45"""
46
47@struct _Eet_Data_Descriptor_Class
48
49Instructs Eet about memory management for different needs under
50serialization and parse process.
51
52The list and hash methods match the Eina API, so for a more detailed
53reference on them, look at the Eina_List and Eina_Hash documentation,
54respectively.
55For the most part these will be used with the standard Eina functions,
56so using EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET() and
57EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET() will set up everything
58accordingly.
59
60"""
61struct _Eet_Data_Descriptor_Class
62{
63 int version; # ABI version. Should always be set to #EET_DATA_DESCRIPTOR_CLASS_VERSION
64 const char *name; # Name of the user data type to be serialized
65 int size; # Size in bytes of the user data type to be serialized
66 struct
67 {
68 Eet_Descriptor_Mem_Alloc_Callback mem_alloc; # how to allocate memory (usually malloc())
69 Eet_Descriptor_Mem_Free_Callback mem_free; # how to free memory (usually free())
70 Eet_Descriptor_Str_Alloc_Callback str_alloc; # how to allocate a string
71 Eet_Descriptor_Str_Free_Callback str_free; # how to free a string
72 Eet_Descriptor_List_Next_Callback list_next; # how to iterate to the next element of a list. Receives and should return the list node.
73 Eet_Descriptor_List_Append_Callback list_append; # how to append data @p d to list which head node is @p l
74 Eet_Descriptor_List_Data_Callback list_data; # retrieves the data from node @p l
75 Eet_Descriptor_List_Free_Callback list_free; # free all the nodes from the list which head node is @p l
76 Eet_Descriptor_Hash_Foreach_Callback hash_foreach; # iterates over all elements in the hash @p h in no specific order
77 Eet_Descriptor_Hash_Add_Callback hash_add; # add a new data @p d with key @p k in hash @p h
78 Eet_Descriptor_Hash_Free_Callback hash_free; # free all entries from the hash @p h
79 Eet_Descriptor_Str_Direct_Alloc_Callback str_direct_alloc; # how to allocate a string directly from file backed/mmaped region pointed by @p str
80 Eet_Descriptor_Str_Direct_Free_Callback str_direct_free; # how to free a string returned by str_direct_alloc
81 Eet_Descriptor_Type_Get_Callback type_get; # get the type, as used in the union or variant mapping, that should be used to store the given data into the eet file.
82 Eet_Descriptor_Type_Set_Callback type_set; # called when loading a mapped type with the given @p type used to describe the type in the descriptor
83 Eet_Descriptor_Array_Alloc_Callback array_alloc; # how to allocate memory for array (usually malloc())
84 Eet_Descriptor_Array_Free_Callback array_free; # how to free memory for array (usually free())
85 } func;
86};
87
88
89
90
91"""
92
93This function is an helper that set all the parameters of an
94Eet_Data_Descriptor_Class correctly when you use Eina data type
95with a stream.
96:param eddc: The Eet_Data_Descriptor_Class you want to set.
97:param eddc_size: The size of the Eet_Data_Descriptor_Class at the compilation time.
98:param name: The name of the structure described by this class.
99:param size: The size of the structure described by this class.
100:return: EINA_TRUE if the structure was correctly set (The only
101 reason that could make it fail is if you did give wrong
102 parameter).
103
104@note Unless there's a very specific reason to use this function directly,
105the EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET macro is recommended.
106
107:since: 1.2.3
108
109"""
110EAPI Eina_Bool
111eet_eina_stream_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc,
112 unsigned int eddc_size,
113 const char *name,
114 int size);
115
116"""
117
118This macro is an helper that set all the parameter of an
119Eet_Data_Descriptor_Class correctly when you use Eina data type
120with stream.
121:param clas: The Eet_Data_Descriptor_Class you want to set.
122:param type: The type of the structure described by this class.
123:return: EINA_TRUE if the structure was correctly set (The only
124 reason that could make it fail is if you did give wrong
125 parameter).
126
127:see: eet_data_descriptor_stream_new
128:since: 1.2.3
129
130"""
131#define EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(clas, type) \
132 (eet_eina_stream_data_descriptor_class_set(clas, sizeof (*(clas)), # type, sizeof(type)))
133
134"""
135
136This function is an helper that set all the parameter of an
137Eet_Data_Descriptor_Class correctly when you use Eina data type
138with a file.
139:param eddc: The Eet_Data_Descriptor_Class you want to set.
140:param eddc_size: The size of the Eet_Data_Descriptor_Class at the compilation time.
141:param name: The name of the structure described by this class.
142:param size: The size of the structure described by this class.
143:return: EINA_TRUE if the structure was correctly set (The only
144 reason that could make it fail is if you did give wrong
145 parameter).
146
147@note Unless there's a very specific reason to use this function directly,
148the EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET macro is recommended.
149
150:since: 1.2.3
151
152"""
153EAPI Eina_Bool
154eet_eina_file_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc,
155 unsigned int eddc_size,
156 const char *name,
157 int size);
158
159"""
160
161This macro is an helper that set all the parameter of an
162Eet_Data_Descriptor_Class correctly when you use Eina data type
163with file.
164:param clas: The Eet_Data_Descriptor_Class you want to set.
165:param type: The type of the structure described by this class.
166:return: EINA_TRUE if the structure was correctly set (The only
167 reason that could make it fail is if you did give wrong
168 parameter).
169
170:see: eet_data_descriptor_file_new
171:since: 1.2.3
172
173"""
174#define EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(clas, type) \
175 (eet_eina_file_data_descriptor_class_set(clas, sizeof (*(clas)), # type, sizeof(type)))
176
diff --git a/efl/eet/data_utils.pxi b/efl/eet/data_utils.pxi
new file mode 100644
index 0000000..06263b9
--- /dev/null
+++ b/efl/eet/data_utils.pxi
@@ -0,0 +1,622 @@
1"""
2
3Decode Image data header only to get information.
4:param data: The encoded pixel data.
5:param size: The size, in bytes, of the encoded pixel data.
6:param w: A pointer to the unsigned int to hold the width in pixels.
7:param h: A pointer to the unsigned int to hold the height in pixels.
8:param alpha: A pointer to the int to hold the alpha flag.
9:param compress: A pointer to the int to hold the compression amount.
10:param quality: A pointer to the int to hold the quality amount.
11:param lossy: A pointer to the int to hold the lossiness flag.
12:return: 1 on success, 0 on failure.
13
14This function works exactly like eet_data_image_header_read(), but instead
15of reading from an Eet file, it takes the buffer of size @p size pointed
16by @p data, which must be a valid Eet encoded image.
17
18On success the function returns 1 indicating the header was read and
19decoded properly, or 0 on failure.
20
21@see eet_data_image_header_read()
22@see eet_data_image_header_decode_cipher()
23
24:since: 1.0.0
25
26"""
27EAPI int
28eet_data_image_header_decode(const void *data,
29 int size,
30 unsigned int *w,
31 unsigned int *h,
32 int *alpha,
33 int *compress,
34 int *quality,
35 int *lossy);
36
37"""
38
39Decode Image data into pixel data.
40:param data: The encoded pixel data.
41:param size: The size, in bytes, of the encoded pixel data.
42:param w: A pointer to the unsigned int to hold the width in pixels.
43:param h: A pointer to the unsigned int to hold the height in pixels.
44:param alpha: A pointer to the int to hold the alpha flag.
45:param compress: A pointer to the int to hold the compression amount.
46:param quality: A pointer to the int to hold the quality amount.
47:param lossy: A pointer to the int to hold the lossiness flag.
48:return: The image pixel data decoded
49
50This function takes encoded pixel data and decodes it into raw RGBA
51pixels on success.
52
53It works exactly like eet_data_image_read(), but it takes the encoded
54data in the @p data buffer of size @p size, instead of reading from a file.
55All the others parameters are also the same.
56
57On success the function returns a pointer to the image data decoded. The
58calling application is responsible for calling free() on the image data
59when it is done with it. On failure NULL is returned and the parameter
60values may not contain any sensible data.
61
62@see eet_data_image_read()
63@see eet_data_image_decode_cipher()
64
65:since: 1.0.0
66
67"""
68EAPI void *
69eet_data_image_decode(const void *data,
70 int size,
71 unsigned int *w,
72 unsigned int *h,
73 int *alpha,
74 int *compress,
75 int *quality,
76 int *lossy);
77
78"""
79
80Decode Image data into pixel data and stores in the given buffer.
81:param data: The encoded pixel data.
82:param size: The size, in bytes, of the encoded pixel data.
83:param src_x: The starting x coordinate from where to dump the stream.
84:param src_y: The starting y coordinate from where to dump the stream.
85:param d: A pointer to the pixel surface.
86:param w: The expected width in pixels of the pixel surface to decode.
87:param h: The expected height in pixels of the pixel surface to decode.
88:param row_stride: The length of a pixels line in the destination surface.
89:param alpha: A pointer to the int to hold the alpha flag.
90:param compress: A pointer to the int to hold the compression amount.
91:param quality: A pointer to the int to hold the quality amount.
92:param lossy: A pointer to the int to hold the lossiness flag.
93:return: 1 on success, 0 otherwise.
94
95Like eet_data_image_read_to_surface(), but reading the given @p data buffer
96instead of a file.
97
98On success the function returns 1, and 0 on failure. On failure the
99parameter values may not contain any sensible data.
100
101@see eet_data_image_read_to_surface()
102@see eet_data_image_decode_to_surface_cipher()
103
104:since: 1.0.2
105
106"""
107EAPI int
108eet_data_image_decode_to_surface(const void *data,
109 int size,
110 unsigned int src_x,
111 unsigned int src_y,
112 unsigned int *d,
113 unsigned int w,
114 unsigned int h,
115 unsigned int row_stride,
116 int *alpha,
117 int *compress,
118 int *quality,
119 int *lossy);
120
121"""
122
123Encode image data for storage or transmission.
124:param data: A pointer to the image pixel data.
125:param size_ret: A pointer to an int to hold the size of the returned data.
126:param w: The width of the image in pixels.
127:param h: The height of the image in pixels.
128:param alpha: The alpha channel flag.
129:param compress: The compression amount.
130:param quality: The quality encoding amount.
131:param lossy: The lossiness flag.
132:return: The encoded image data.
133
134This function stakes image pixel data and encodes it with compression and
135possible loss of quality (as a trade off for size) for storage or
136transmission to another system.
137
138It works like eet_data_image_write(), but instead of writing the encoded
139image into an Eet file, it allocates a new buffer of the size required and
140returns the encoded data in it.
141
142On success this function returns a pointer to the encoded data that you
143can free with free() when no longer needed.
144
145@see eet_data_image_write()
146@see eet_data_image_read()
147@see eet_data_image_encode_cipher()
148
149:since: 1.0.0
150
151"""
152EAPI void *
153eet_data_image_encode(const void *data,
154 int *size_ret,
155 unsigned int w,
156 unsigned int h,
157 int alpha,
158 int compress,
159 int quality,
160 int lossy);
161
162
163"""
164
165Decode Image data header only to get information using a cipher.
166:param data: The encoded pixel data.
167:param cipher_key: The key to use as cipher.
168:param size: The size, in bytes, of the encoded pixel data.
169:param w: A pointer to the unsigned int to hold the width in pixels.
170:param h: A pointer to the unsigned int to hold the height in pixels.
171:param alpha: A pointer to the int to hold the alpha flag.
172:param compress: A pointer to the int to hold the compression amount.
173:param quality: A pointer to the int to hold the quality amount.
174:param lossy: A pointer to the int to hold the lossiness flag.
175:return: 1 on success, 0 on failure.
176
177This function takes encoded pixel data and decodes it into raw RGBA
178pixels on success.
179
180The other parameters of the image (width, height etc.) are placed into
181the values pointed to (they must be supplied). The pixel data is a linear
182array of pixels starting from the top-left of the image scanning row by
183row from left to right. Each pixel is a 32bit value, with the high byte
184being the alpha channel, the next being red, then green, and the low byte
185being blue. The width and height are measured in pixels and will be
186greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
187that the alpha channel is not used. 1 denotes that it is significant.
188Compress is filled with the compression value/amount the image was
189stored with. The quality value is filled with the quality encoding of
190the image file (0 - 100). The lossy flags is either 0 or 1 as to if
191the image was encoded lossily or not.
192
193On success the function returns 1 indicating the header was read and
194decoded properly, or 0 on failure.
195
196@see eet_data_image_header_decode()
197
198:since: 1.0.0
199
200"""
201EAPI int
202eet_data_image_header_decode_cipher(const void *data,
203 const char *cipher_key,
204 int size,
205 unsigned int *w,
206 unsigned int *h,
207 int *alpha,
208 int *compress,
209 int *quality,
210 int *lossy);
211
212"""
213
214Decode Image data into pixel data using a cipher.
215:param data: The encoded pixel data.
216:param cipher_key: The key to use as cipher.
217:param size: The size, in bytes, of the encoded pixel data.
218:param w: A pointer to the unsigned int to hold the width in pixels.
219:param h: A pointer to the unsigned int to hold the height in pixels.
220:param alpha: A pointer to the int to hold the alpha flag.
221:param compress: A pointer to the int to hold the compression amount.
222:param quality: A pointer to the int to hold the quality amount.
223:param lossy: A pointer to the int to hold the lossiness flag.
224:return: The image pixel data decoded
225
226This function takes encoded pixel data and decodes it into raw RGBA
227pixels on success.
228
229The other parameters of the image (width, height etc.) are placed into
230the values pointed to (they must be supplied). The pixel data is a linear
231array of pixels starting from the top-left of the image scanning row by
232row from left to right. Each pixel is a 32bit value, with the high byte
233being the alpha channel, the next being red, then green, and the low byte
234being blue. The width and height are measured in pixels and will be
235greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
236that the alpha channel is not used. 1 denotes that it is significant.
237Compress is filled with the compression value/amount the image was
238stored with. The quality value is filled with the quality encoding of
239the image file (0 - 100). The lossy flags is either 0 or 1 as to if
240the image was encoded lossily or not.
241
242On success the function returns a pointer to the image data decoded. The
243calling application is responsible for calling free() on the image data
244when it is done with it. On failure NULL is returned and the parameter
245values may not contain any sensible data.
246
247@see eet_data_image_decode()
248
249:since: 1.0.0
250
251"""
252EAPI void *
253eet_data_image_decode_cipher(const void *data,
254 const char *cipher_key,
255 int size,
256 unsigned int *w,
257 unsigned int *h,
258 int *alpha,
259 int *compress,
260 int *quality,
261 int *lossy);
262
263"""
264
265Decode Image data into pixel data using a cipher.
266:param data: The encoded pixel data.
267:param cipher_key: The key to use as cipher.
268:param size: The size, in bytes, of the encoded pixel data.
269:param src_x: The starting x coordinate from where to dump the stream.
270:param src_y: The starting y coordinate from where to dump the stream.
271:param d: A pointer to the pixel surface.
272:param w: The expected width in pixels of the pixel surface to decode.
273:param h: The expected height in pixels of the pixel surface to decode.
274:param row_stride: The length of a pixels line in the destination surface.
275:param alpha: A pointer to the int to hold the alpha flag.
276:param compress: A pointer to the int to hold the compression amount.
277:param quality: A pointer to the int to hold the quality amount.
278:param lossy: A pointer to the int to hold the lossiness flag.
279:return: 1 on success, 0 otherwise.
280
281This function takes encoded pixel data and decodes it into raw RGBA
282pixels on success.
283
284The other parameters of the image (alpha, compress etc.) are placed into
285the values pointed to (they must be supplied). The pixel data is a linear
286array of pixels starting from the top-left of the image scanning row by
287row from left to right. Each pixel is a 32bit value, with the high byte
288being the alpha channel, the next being red, then green, and the low byte
289being blue. The width and height are measured in pixels and will be
290greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
291that the alpha channel is not used. 1 denotes that it is significant.
292Compress is filled with the compression value/amount the image was
293stored with. The quality value is filled with the quality encoding of
294the image file (0 - 100). The lossy flags is either 0 or 1 as to if
295the image was encoded lossily or not.
296
297On success the function returns 1, and 0 on failure. On failure the
298parameter values may not contain any sensible data.
299
300@see eet_data_image_decode_to_surface()
301
302:since: 1.0.2
303
304"""
305EAPI int
306eet_data_image_decode_to_surface_cipher(const void *data,
307 const char *cipher_key,
308 int size,
309 unsigned int src_x,
310 unsigned int src_y,
311 unsigned int *d,
312 unsigned int w,
313 unsigned int h,
314 unsigned int row_stride,
315 int *alpha,
316 int *compress,
317 int *quality,
318 int *lossy);
319
320"""
321
322Encode image data for storage or transmission using a cipher.
323:param data: A pointer to the image pixel data.
324:param cipher_key: The key to use as cipher.
325:param size_ret: A pointer to an int to hold the size of the returned data.
326:param w: The width of the image in pixels.
327:param h: The height of the image in pixels.
328:param alpha: The alpha channel flag.
329:param compress: The compression amount.
330:param quality: The quality encoding amount.
331:param lossy: The lossiness flag.
332:return: The encoded image data.
333
334This function stakes image pixel data and encodes it with compression and
335possible loss of quality (as a trade off for size) for storage or
336transmission to another system.
337
338The data expected is the same format as returned by eet_data_image_read.
339If this is not the case weird things may happen. Width and height must
340be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning
341the alpha values are not useful and 1 meaning they are). Compress can
342be from 0 to 9 (0 meaning no compression, 9 meaning full compression).
343This is only used if the image is not lossily encoded. Quality is used on
344lossy compression and should be a value from 0 to 100. The lossy flag
345can be 0 or 1. 0 means encode losslessly and 1 means to encode with
346image quality loss (but then have a much smaller encoding).
347
348On success this function returns a pointer to the encoded data that you
349can free with free() when no longer needed.
350
351@see eet_data_image_encode()
352
353:since: 1.0.0
354
355"""
356EAPI void *
357eet_data_image_encode_cipher(const void *data,
358 const char *cipher_key,
359 unsigned int w,
360 unsigned int h,
361 int alpha,
362 int compress,
363 int quality,
364 int lossy,
365 int *size_ret);
366
367
368
369
370typedef void (*Eet_Dump_Callback)(void *data, const char *str);
371
372"""
373
374Dump an eet encoded data structure into ascii text
375:param data_in: The pointer to the data to decode into a struct.
376:param size_in: The size of the data pointed to in bytes.
377:param dumpfunc: The function to call passed a string when new
378 data is converted to text
379:param dumpdata: The data to pass to the @p dumpfunc callback.
380:return: 1 on success, 0 on failure
381
382This function will take a chunk of data encoded by
383eet_data_descriptor_encode() and convert it into human readable
384ascii text. It does this by calling the @p dumpfunc callback
385for all new text that is generated. This callback should append
386to any existing text buffer and will be passed the pointer @p
387dumpdata as a parameter as well as a string with new text to be
388appended.
389
390Example:
391
392@code
393void output(void *data, const char *string)
394{
395 printf("%s", string);
396}
397
398void dump(const char *file)
399{
400 FILE *f;
401 int len;
402 void *data;
403
404 f = fopen(file, "r");
405 fseek(f, 0, SEEK_END);
406 len = ftell(f);
407 rewind(f);
408 data = malloc(len);
409 fread(data, len, 1, f);
410 fclose(f);
411 eet_data_text_dump(data, len, output, NULL);
412}
413@endcode
414
415:see: eet_data_text_dump_cipher()
416
417:since: 1.0.0
418
419"""
420EAPI int
421eet_data_text_dump(const void *data_in,
422 int size_in,
423 Eet_Dump_Callback dumpfunc,
424 void *dumpdata);
425
426"""
427
428Take an ascii encoding from eet_data_text_dump() and re-encode in binary.
429:param text: The pointer to the string data to parse and encode.
430:param textlen: The size of the string in bytes (not including 0
431 byte terminator).
432:param size_ret: This gets filled in with the encoded data blob
433 size in bytes.
434:return: The encoded data on success, NULL on failure.
435
436This function will parse the string pointed to by @p text and return
437an encoded data lump the same way eet_data_descriptor_encode() takes an
438in-memory data struct and encodes into a binary blob. @p text is a normal
439C string.
440
441:see: eet_data_text_undump_cipher()
442
443:since: 1.0.0
444
445"""
446EAPI void *
447eet_data_text_undump(const char *text,
448 int textlen,
449 int *size_ret);
450
451
452
453
454"""
455
456Read a data structure from an eet extended attribute and decodes it using a cipher.
457:param filename: The file to extract the extended attribute from.
458:param attribute: The attribute to get the data from.
459:param edd: The data descriptor handle to use when decoding.
460:param cipher_key: The key to use as cipher.
461:return: A pointer to the decoded data structure.
462
463This function decodes a data structure stored in an eet extended attribute,
464returning a pointer to it if it decoded successfully, or NULL on failure.
465Eet can handle members being added or deleted from the data in
466storage and safely zero-fills unfilled members if they were not found
467in the data. It checks sizes and headers whenever it reads data, allowing
468the programmer to not worry about corrupt data.
469
470Once a data structure has been described by the programmer with the
471fields they wish to save or load, storing or retrieving a data structure
472from an eet file, from a chunk of memory or from an extended attribute
473is as simple as a single function call.
474
475:since: 1.5.0
476
477"""
478EAPI void *
479eet_data_xattr_cipher_get(const char *filename,
480 const char *attribute,
481 Eet_Data_Descriptor *edd,
482 const char *cipher_key);
483
484
485"""
486
487Write a data structure from memory and store in an eet extended attribute
488using a cipher.
489:param filename: The file to write the extended attribute to.
490:param attribute: The attribute to store the data to.
491:param edd: The data descriptor to use when encoding.
492:param cipher_key: The key to use as cipher.
493:param data: A pointer to the data structure to save and encode.
494:param flags: The policy to use when setting the data.
495:return: EINA_TRUE on success, EINA_FALSE on failure.
496
497This function is the reverse of eet_data_xattr_cipher_get(), saving a data structure
498to an eet extended attribute.
499
500:since: 1.5.0
501
502"""
503EAPI Eina_Bool
504eet_data_xattr_cipher_set(const char *filename,
505 const char *attribute,
506 Eet_Data_Descriptor *edd,
507 const char *cipher_key,
508 const void *data,
509 Eina_Xattr_Flags flags);
510
511"""
512
513Dump an eet encoded data structure into ascii text using a cipher.
514:param data_in: The pointer to the data to decode into a struct.
515:param cipher_key: The key to use as cipher.
516:param size_in: The size of the data pointed to in bytes.
517:param dumpfunc: The function to call passed a string when new
518 data is converted to text
519:param dumpdata: The data to pass to the @p dumpfunc callback.
520:return: 1 on success, 0 on failure
521
522This function will take a chunk of data encoded by
523eet_data_descriptor_encode() and convert it into human readable
524ascii text. It does this by calling the @p dumpfunc callback
525for all new text that is generated. This callback should append
526to any existing text buffer and will be passed the pointer @p
527dumpdata as a parameter as well as a string with new text to be
528appended.
529
530Example:
531
532@code
533void output(void *data, const char *string)
534{
535 printf("%s", string);
536}
537
538void dump(const char *file)
539{
540 FILE *f;
541 int len;
542 void *data;
543
544 f = fopen(file, "r");
545 fseek(f, 0, SEEK_END);
546 len = ftell(f);
547 rewind(f);
548 data = malloc(len);
549 fread(data, len, 1, f);
550 fclose(f);
551 eet_data_text_dump_cipher(data, cipher_key, len, output, NULL);
552}
553@endcode
554
555:see: eet_data_text_dump()
556
557:since: 1.0.0
558
559"""
560EAPI int
561eet_data_text_dump_cipher(const void *data_in,
562 const char *cipher_key,
563 int size_in,
564 Eet_Dump_Callback dumpfunc,
565 void *dumpdata);
566
567"""
568
569Take an ascii encoding from eet_data_text_dump() and re-encode
570in binary using a cipher.
571:param text: The pointer to the string data to parse and encode.
572:param cipher_key: The key to use as cipher.
573:param textlen: The size of the string in bytes (not including 0
574 byte terminator).
575:param size_ret: This gets filled in with the encoded data blob
576 size in bytes.
577:return: The encoded data on success, NULL on failure.
578
579This function will parse the string pointed to by @p text and return
580an encoded data lump the same way eet_data_descriptor_encode() takes an
581in-memory data struct and encodes into a binary blob. @p text is a normal
582C string.
583
584:see: eet_data_text_undump()
585
586:since: 1.0.0
587
588"""
589EAPI void *
590eet_data_text_undump_cipher(const char *text,
591 const char *cipher_key,
592 int textlen,
593 int *size_ret);
594
595
596"""
597
598TODO FIX ME
599
600"""
601EAPI Eet_Node *
602eet_data_node_decode_cipher(const void *data_in,
603 const char *cipher_key,
604 int size_in);
605
606
607"""
608
609Display the x509 der certificate to out.
610
611:param certificate: the x509 certificate to print
612:param der_length: The length the certificate.
613:param out: where to print.
614
615@warning You need to compile signature support in EET.
616:since: 1.2.0
617
618"""
619EAPI void
620eet_identity_certificate_print(const unsigned char *certificate,
621 int der_length,
622 FILE *out);
diff --git a/efl/eet/dictionary.pxi b/efl/eet/dictionary.pxi
new file mode 100644
index 0000000..d660c39
--- /dev/null
+++ b/efl/eet/dictionary.pxi
@@ -0,0 +1,45 @@
1
2from cpython cimport PyUnicode_AsUTF8String
3from efl.utils.conversions cimport _ctouni
4
5
6cdef class EetDictionary(object):
7
8 """
9
10 Opaque handle that defines a file-backed (mmaped) dictionary of strings.
11
12 """
13
14 cdef Eet_Dictionary *ed
15
16 def string_check(self, string):
17 """
18
19 Check if a given string comes from a given dictionary
20
21 :param string: A valid 0 byte terminated C string
22 :return: 1 if it is in the dictionary, 0 otherwise
23
24 This checks the given dictionary to see if the given string is actually
25 inside that dictionary (i.e. comes from it) and returns 1 if it does.
26 If the dictionary handle is invalid, the string is None or the string is
27 not in the dictionary, 0 is returned.
28
29 :since: 1.0.0
30
31 """
32 if isinstance(string, unicode): string = PyUnicode_AsUTF8String(string)
33 return bool(eet_dictionary_string_check(self.ed, string))
34
35 def count(self):
36 """
37
38 Return the number of strings inside a dictionary
39
40 :return int: the number of strings inside a dictionary
41
42 :since: 1.6.0
43
44 """
45 return eet_dictionary_count(self.ed)
diff --git a/efl/eet/eet.pxd b/efl/eet/eet.pxd
new file mode 100644
index 0000000..90a5ceb
--- /dev/null
+++ b/efl/eet/eet.pxd
@@ -0,0 +1,309 @@
1from libc.string cimport const_char
2from libc.stdlib cimport const_void
3
4from efl.eina cimport Eina_Bool, Eina_List
5
6from efl.eet.enums cimport Eet_Error, Eet_Compression, Eet_File_Mode
7
8cdef extern from *:
9 ctypedef unsigned char const_unsigned_char "const unsigned char"
10
11cdef extern from "Eet.h":
12
13 enum:
14 EET_VERSION_MAJOR
15 EET_VERSION_MINOR
16
17 ctypedef struct Eet_Version:
18 int major # major (binary or source incompatible changes)
19 int minor # minor (new features, bugfixes, major improvements version)
20 int micro # micro (bugfix, internal improvements, no new features version)
21 int revision # svn revision (0 if a proper release or the svn revision number Eet is built from)
22
23 extern Eet_Version *eet_version
24
25 int eet_init()
26 int eet_shutdown()
27 void eet_clearcache()
28
29 ctypedef struct Eet_File
30
31 ctypedef struct Eet_Dictionary
32 ctypedef Eet_Dictionary const_Eet_Dictionary "const Eet_Dictionary"
33
34 ctypedef _Eet_Entry Eet_Entry
35 struct _Eet_Entry:
36 const_char *name # The entry name
37
38 int offset # Where it start in the file
39 int size # The size on disk
40 int data_size # The decompressed size if relevant
41
42 Eina_Bool compression # Is this data compressed ?
43 Eina_Bool ciphered # Is it ciphered ?
44 Eina_Bool alias # Is it an alias ?
45
46 Eet_File * eet_open(const_char *file, Eet_File_Mode mode)
47 # Eet_File * eet_mmap(const_Eina_File *file)
48 # Eet_File * eet_memopen_read(const_void *data, size_t size)
49 Eet_File_Mode eet_mode_get(Eet_File *ef)
50 Eet_Error eet_close(Eet_File *ef)
51 Eet_Error eet_sync(Eet_File *ef)
52 Eet_Dictionary *eet_dictionary_get(Eet_File *ef)
53 int eet_dictionary_string_check(Eet_Dictionary *ed, const_char *string)
54 int eet_dictionary_count(const_Eet_Dictionary *ed)
55 void * eet_read(Eet_File *ef, const_char *name, int *size_ret)
56 const_void * eet_read_direct(Eet_File *ef, const_char *name, int *size_ret)
57 int eet_write(Eet_File *ef, const_char *name, const_void *data, int size, int compress)
58 int eet_delete(Eet_File *ef, const_char *name)
59 Eina_Bool eet_alias(Eet_File *ef, const_char *name, const_char *destination, int compress)
60 const_char * eet_file_get(Eet_File *ef)
61 const_char * eet_alias_get(Eet_File *ef, const_char *name)
62 char ** eet_list(Eet_File *ef, const_char *glob, int *count_ret)
63 # Eina_Iterator * eet_list_entries(Eet_File *ef)
64 int eet_num_entries(Eet_File *ef)
65 # void * eet_read_cipher(Eet_File *ef, const_char *name, int *size_ret, const_char *cipher_key)
66 # int eet_write_cipher(Eet_File *ef, const_char *name, const_void *data, int size, int compress, const_char *cipher_key)
67 # int eet_data_image_header_read(Eet_File *ef, const_char *name, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy)
68 # void * eet_data_image_read(Eet_File *ef, const_char *name, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy)
69 # int eet_data_image_read_to_surface(Eet_File *ef, const_char *name, unsigned int src_x, unsigned int src_y, unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride, int *alpha, int *compress, int *quality, int *lossy)
70 # int eet_data_image_write(Eet_File *ef, const_char *name, const_void *data, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy)
71 # int eet_data_image_header_decode(const_void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy)
72 # void * eet_data_image_decode(const_void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy)
73 # int eet_data_image_decode_to_surface(const_void *data, int size, unsigned int src_x, unsigned int src_y, unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride, int *alpha, int *compress, int *quality, int *lossy)
74 # void * eet_data_image_encode(const_void *data, int *size_ret, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy)
75 # int eet_data_image_header_read_cipher(Eet_File *ef, const_char *name, const_char *cipher_key, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy)
76 # void * eet_data_image_read_cipher(Eet_File *ef, const_char *name, const_char *cipher_key, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy)
77 # int eet_data_image_read_to_surface_cipher(Eet_File *ef, const_char *name, const_char *cipher_key, unsigned int src_x, unsigned int src_y, unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride, int *alpha, int *compress, int *quality, int *lossy)
78 # int eet_data_image_write_cipher(Eet_File *ef, const_char *name, const_char *cipher_key, const_void *data, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy)
79 # int eet_data_image_header_decode_cipher(const_void *data, const_char *cipher_key, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy)
80 # void * eet_data_image_decode_cipher(const_void *data, const_char *cipher_key, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy)
81 # int eet_data_image_decode_to_surface_cipher(const_void *data, const_char *cipher_key, int size, unsigned int src_x, unsigned int src_y, unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride, int *alpha, int *compress, int *quality, int *lossy)
82 # void * eet_data_image_encode_cipher(const_void *data, const_char *cipher_key, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy, int *size_ret)
83
84 # ctypedef struct Eet_Key
85
86 # ctypedef int (*Eet_Key_Password_Callback)(char *buffer, int size, int rwflag, void *data)
87
88 # Eet_Key * eet_identity_open(const_char *certificate_file, const_char *private_key_file, Eet_Key_Password_Callback cb)
89 # void eet_identity_close(Eet_Key *key)
90 # Eet_Error eet_identity_set(Eet_File *ef, Eet_Key *key)
91 # void eet_identity_print(Eet_Key *key, FILE *out)
92 # const_void * eet_identity_x509(Eet_File *ef, int *der_length)
93 # const_void * eet_identity_signature(Eet_File *ef, int *signature_length)
94 # const_void * eet_identity_sha1(Eet_File *ef, int *sha1_length)
95 # void eet_identity_certificate_print(const_unsigned_char *certificate, int der_length, FILE *out)
96
97 # enum:
98 # EET_T_UNKNOW # Unknown data encoding type
99 # EET_T_CHAR # Data type: char
100 # EET_T_SHORT # Data type: short
101 # EET_T_INT # Data type: int
102 # EET_T_LONG_LONG # Data type: long long
103 # EET_T_FLOAT # Data type: float
104 # EET_T_DOUBLE # Data type: double
105 # EET_T_UCHAR # Data type: unsigned char
106 # EET_T_USHORT # Data type: unsigned short
107 # EET_T_UINT # Data type: unsigned int
108 # EET_T_ULONG_LONG # Data type: unsigned long long
109 # EET_T_STRING # Data type: char *
110 # EET_T_INLINED_STRING # Data type: char * (but compressed inside the resulting eet)
111 # EET_T_NULL # Data type: (void *) (only use it if you know why)
112 # EET_T_F32P32 # Data type: fixed point 32.32
113 # EET_T_F16P16 # Data type: fixed point 16.16
114 # EET_T_F8P24 # Data type: fixed point 8.24
115 # EET_T_VALUE # Data type: pointer to Eina_Value @since 1.8
116 # EET_T_LAST # Last data type
117
118 # enum:
119 # EET_G_UNKNOWN # Unknown group data encoding type
120 # EET_G_ARRAY # Fixed size array group type
121 # EET_G_VAR_ARRAY # Variable size array group type
122 # EET_G_LIST # Linked list group type
123 # EET_G_HASH # Hash table group type
124 # EET_G_UNION # Union group type
125 # EET_G_VARIANT # Selectable subtype group
126 # EET_G_UNKNOWN_NESTED # Unknown nested group type. @since 1.8
127 # EET_G_LAST # Last group type
128
129 # enum:
130 # EET_I_LIMIT # Other type exist but are reserved for internal purpose.
131
132 # ctypedef struct Eet_Data_Descriptor
133
134 # enum:
135 # EET_DATA_DESCRIPTOR_CLASS_VERSION
136
137 # ctypedef _Eet_Data_Descriptor_Class Eet_Data_Descriptor_Class
138
139 # ctypedef int (*Eet_Descriptor_Hash_Foreach_Callback_Callback)(void *h, const_char *k, void *dt, void *fdt)
140
141 # ctypedef void * (*Eet_Descriptor_Mem_Alloc_Callback)(size_t size)
142 # ctypedef void (*Eet_Descriptor_Mem_Free_Callback)(void *mem)
143 # ctypedef char * (*Eet_Descriptor_Str_Alloc_Callback)(const_char *str)
144 # ctypedef void (*Eet_Descriptor_Str_Free_Callback)(const_char *str)
145 # ctypedef void * (*Eet_Descriptor_List_Next_Callback)(void *l)
146 # ctypedef void * (*Eet_Descriptor_List_Append_Callback)(void *l, void *d)
147 # ctypedef void * (*Eet_Descriptor_List_Data_Callback)(void *l)
148 # ctypedef void * (*Eet_Descriptor_List_Free_Callback)(void *l)
149 # ctypedef void (*Eet_Descriptor_Hash_Foreach_Callback)(void *h, Eet_Descriptor_Hash_Foreach_Callback_Callback func, void *fdt)
150 # ctypedef void * (*Eet_Descriptor_Hash_Add_Callback)(void *h, const_char *k, void *d)
151 # ctypedef void (*Eet_Descriptor_Hash_Free_Callback)(void *h)
152 # ctypedef char * (*Eet_Descriptor_Str_Direct_Alloc_Callback)(const_char *str)
153 # ctypedef void (*Eet_Descriptor_Str_Direct_Free_Callback)(const_char *str)
154 # ctypedef const_char * (*Eet_Descriptor_Type_Get_Callback)(const_void *data, Eina_Bool *unknow)
155 # ctypedef Eina_Bool (*Eet_Descriptor_Type_Set_Callback)(const_char *type, void *data, Eina_Bool unknow)
156 # ctypedef void * (*Eet_Descriptor_Array_Alloc_Callback)(size_t size)
157 # ctypedef void (*Eet_Descriptor_Array_Free_Callback)(void *mem)
158
159
160 # ctypedef struct _Eet_Data_Descriptor_Class_func:
161 # Eet_Descriptor_Mem_Alloc_Callback mem_alloc # how to allocate memory (usually malloc())
162 # Eet_Descriptor_Mem_Free_Callback mem_free # how to free memory (usually free())
163 # Eet_Descriptor_Str_Alloc_Callback str_alloc # how to allocate a string
164 # Eet_Descriptor_Str_Free_Callback str_free # how to free a string
165 # Eet_Descriptor_List_Next_Callback list_next # how to iterate to the next element of a list. Receives and should return the list node.
166 # Eet_Descriptor_List_Append_Callback list_append # how to append data @p d to list which head node is @p l
167 # Eet_Descriptor_List_Data_Callback list_data # retrieves the data from node @p l
168 # Eet_Descriptor_List_Free_Callback list_free # free all the nodes from the list which head node is @p l
169 # Eet_Descriptor_Hash_Foreach_Callback hash_foreach # iterates over all elements in the hash @p h in no specific order
170 # Eet_Descriptor_Hash_Add_Callback hash_add # add a new data @p d with key @p k in hash @p h
171 # Eet_Descriptor_Hash_Free_Callback hash_free # free all entries from the hash @p h
172 # Eet_Descriptor_Str_Direct_Alloc_Callback str_direct_alloc # how to allocate a string directly from file backed/mmaped region pointed by @p str
173 # Eet_Descriptor_Str_Direct_Free_Callback str_direct_free # how to free a string returned by str_direct_alloc
174 # Eet_Descriptor_Type_Get_Callback type_get # get the type, as used in the union or variant mapping, that should be used to store the given data into the eet file.
175 # Eet_Descriptor_Type_Set_Callback type_set # called when loading a mapped type with the given @p type used to describe the type in the descriptor
176 # Eet_Descriptor_Array_Alloc_Callback array_alloc # how to allocate memory for array (usually malloc())
177 # Eet_Descriptor_Array_Free_Callback array_free # how to free memory for array (usually free())
178
179 # struct _Eet_Data_Descriptor_Class:
180 # int version # ABI version. Should always be set to #EET_DATA_DESCRIPTOR_CLASS_VERSION
181 # const_char *name # Name of the user data type to be serialized
182 # int size # Size in bytes of the user data type to be serialized
183 # _Eet_Data_Descriptor_Class func
184
185
186 # Eet_Data_Descriptor * eet_data_descriptor_stream_new(const_Eet_Data_Descriptor_Class *eddc)
187 # Eet_Data_Descriptor * eet_data_descriptor_file_new(const_Eet_Data_Descriptor_Class *eddc)
188
189 # Eina_Bool eet_eina_stream_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc, unsigned int eddc_size, const_char *name, int size)
190 # Eina_Bool EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(Eet_Data_Descriptor_Class *clas, void *type)
191
192 # Eina_Bool eet_eina_file_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc, unsigned int eddc_size, const_char *name, int size)
193 # Eina_Bool EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(Eet_Data_Descriptor_Class *clas, void *type)
194
195
196 # void eet_data_descriptor_free(Eet_Data_Descriptor *edd)
197 # const_char * eet_data_descriptor_name_get(const_Eet_Data_Descriptor *edd)
198 # void eet_data_descriptor_element_add(Eet_Data_Descriptor *edd, const_char *name, int type, int group_type, int offset, int count, const_char *counter_name, Eet_Data_Descriptor *subtype)
199 # void * eet_data_read(Eet_File *ef, Eet_Data_Descriptor *edd, const_char *name)
200 # int eet_data_write(Eet_File *ef, Eet_Data_Descriptor *edd, const_char *name, const_void *data, int compress)
201
202
203 # ctypedef void (*Eet_Dump_Callback)(void *data, const_char *str)
204
205
206 # int eet_data_text_dump(const_void *data_in, int size_in, Eet_Dump_Callback dumpfunc, void *dumpdata)
207 # void * eet_data_text_undump(const_char *text, int textlen, int *size_ret)
208 # int eet_data_dump(Eet_File *ef, const_char *name, Eet_Dump_Callback dumpfunc, void *dumpdata)
209 # int eet_data_undump(Eet_File *ef, const_char *name, const_char *text, int textlen, int compress)
210 # void * eet_data_descriptor_decode(Eet_Data_Descriptor *edd, const_void *data_in, int size_in)
211 # void * eet_data_descriptor_encode(Eet_Data_Descriptor *edd, const_void *data_in, int *size_ret)
212
213 # void EET_DATA_DESCRIPTOR_ADD_BASIC(Eet_Data_Descriptor *edd, void *struct_type, const_char *name, void *member, int type)
214 # void EET_DATA_DESCRIPTOR_ADD_SUB(Eet_Data_Descriptor *edd, void *struct_type, const_char *name, void *member, Eet_Data_Descriptor *subtype)
215 # void EET_DATA_DESCRIPTOR_ADD_SUB_NESTED(Eet_Data_Descriptor *edd, void *struct_type, const_char *name, void *member, Eet_Data_Descriptor *subtype)
216 # void EET_DATA_DESCRIPTOR_ADD_SUB_LIST(Eet_Data_Descriptor *edd, void *struct_type, const_char *name, void *member, Eet_Data_Descriptor *subtype)
217 # void EET_DATA_DESCRIPTOR_ADD_LIST_STRING(Eet_Data_Descriptor *edd, void *struct_type, const_char *name, void *member)
218 # void EET_DATA_DESCRIPTOR_ADD_HASH(Eet_Data_Descriptor *edd, void *struct_type, const_char *name, void *member, Eet_Data_Descriptor *subtype)
219 # void EET_DATA_DESCRIPTOR_ADD_HASH_STRING(Eet_Data_Descriptor *edd, void *struct_type, const_char *name, void *member)
220 # void EET_DATA_DESCRIPTOR_ADD_BASIC_ARRAY(Eet_Data_Descriptor *edd, void *struct_type, const_char *name, void *member, int type)
221 # void EET_DATA_DESCRIPTOR_ADD_BASIC_VAR_ARRAY(Eet_Data_Descriptor *edd, void *struct_type, const_char *name, void *member, int type)
222 # void EET_DATA_DESCRIPTOR_ADD_ARRAY(Eet_Data_Descriptor *edd, void *struct_type, const_char *name, void *member, Eet_Data_Descriptor *subtype)
223 # void EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY(Eet_Data_Descriptor *edd, void *struct_type, const_char *name, void *member, Eet_Data_Descriptor *subtype)
224 # void EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY_STRING(Eet_Data_Descriptor *edd, void *struct_type, const_char *name, void *member)
225 # void EET_DATA_DESCRIPTOR_ADD_UNION(Eet_Data_Descriptor *edd, void *struct_type, const_char *name, void *member, void *type_member, Eet_Data_Descriptor *unified_type)
226 # void EET_DATA_DESCRIPTOR_ADD_VARIANT(Eet_Data_Descriptor *edd, void *struct_type, const_char *name, void *member, void *type_member, Eet_Data_Descriptor *unified_type)
227 # void EET_DATA_DESCRIPTOR_ADD_MAPPING(Eet_Data_Descriptor *unified_type, const_char *name, Eet_Data_Descriptor *subtype)
228 # void EET_DATA_DESCRIPTOR_ADD_MAPPING_BASIC(Eet_Data_Descriptor *unified_type, const_char *name, int basic_type)
229
230 # void * eet_data_read_cipher(Eet_File *ef, Eet_Data_Descriptor *edd, const_char *name, const_char *cipher_key)
231 # void * eet_data_xattr_cipher_get(const_char *filename, const_char *attribute, Eet_Data_Descriptor *edd, const_char *cipher_key)
232 # int eet_data_write_cipher(Eet_File *ef, Eet_Data_Descriptor *edd, const_char *name, const_char *cipher_key, const_void *data, int compress)
233 # Eina_Bool eet_data_xattr_cipher_set(const_char *filename, const_char *attribute, Eet_Data_Descriptor *edd, const_char *cipher_key, const_void *data, Eina_Xattr_Flags flags)
234 # int eet_data_text_dump_cipher(const_void *data_in, const_char *cipher_key, int size_in, Eet_Dump_Callback dumpfunc, void *dumpdata)
235 # void * eet_data_text_undump_cipher(const_char *text, const_char *cipher_key, int textlen, int *size_ret)
236 # int eet_data_dump_cipher(Eet_File *ef, const_char *name, const_char *cipher_key, Eet_Dump_Callback dumpfunc, void *dumpdata)
237 # int eet_data_undump_cipher(Eet_File *ef, const_char *name, const_char *cipher_key, const_char *text, int textlen, int compress)
238 # void * eet_data_descriptor_decode_cipher(Eet_Data_Descriptor *edd, const_void *data_in, const_char *cipher_key, int size_in)
239 # void * eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd, const_void *data_in, const_char *cipher_key, int *size_ret)
240
241 ctypedef struct Eet_Node
242
243 ctypedef _Eet_Node_Data Eet_Node_Data
244
245 ctypedef union _Eet_Node_Data_value:
246 char c
247 short s
248 int i
249 long long l
250 float f
251 double d
252 unsigned char uc
253 unsigned short us
254 unsigned int ui
255 unsigned long long ul
256 const_char *str
257
258 struct _Eet_Node_Data:
259 _Eet_Node_Data_value value
260
261 Eet_Node * eet_node_char_new(const_char *name, char c)
262 Eet_Node * eet_node_short_new(const_char *name, short s)
263 Eet_Node * eet_node_int_new(const_char *name, int i)
264 Eet_Node * eet_node_long_long_new(const_char *name, long long l)
265 Eet_Node * eet_node_float_new(const_char *name, float f)
266 Eet_Node * eet_node_double_new(const_char *name, double d)
267 Eet_Node * eet_node_unsigned_char_new(const_char *name, unsigned char uc)
268 Eet_Node * eet_node_unsigned_short_new(const_char *name, unsigned short us)
269 Eet_Node * eet_node_unsigned_int_new(const_char *name, unsigned int ui)
270 Eet_Node * eet_node_unsigned_long_long_new(const_char *name, unsigned long long l)
271 Eet_Node * eet_node_string_new(const_char *name, const_char *str)
272 Eet_Node * eet_node_inlined_string_new(const_char *name, const_char *str)
273 Eet_Node * eet_node_null_new(const_char *name)
274 Eet_Node * eet_node_list_new(const_char *name, Eina_List *nodes)
275 Eet_Node * eet_node_array_new(const_char *name, int count, Eina_List *nodes)
276 Eet_Node * eet_node_var_array_new(const_char *name, Eina_List *nodes)
277 Eet_Node * eet_node_hash_new(const_char *name, const_char *key, Eet_Node *node)
278 Eet_Node * eet_node_struct_new(const_char *name, Eina_List *nodes)
279 Eet_Node * eet_node_struct_child_new(const_char *parent, Eet_Node *child)
280
281 Eet_Node * eet_node_children_get(Eet_Node *node)
282 Eet_Node * eet_node_next_get(Eet_Node *node)
283 Eet_Node * eet_node_parent_get(Eet_Node *node)
284 void eet_node_list_append(Eet_Node *parent, const_char *name, Eet_Node *child)
285 void eet_node_struct_append(Eet_Node *parent, const_char *name, Eet_Node *child)
286 void eet_node_hash_add(Eet_Node *parent, const_char *name, const_char *key, Eet_Node *child)
287 # void eet_node_dump(Eet_Node *n, int dumplevel, Eet_Dump_Callback dumpfunc, void *dumpdata)
288 int eet_node_type_get(Eet_Node *node)
289 Eet_Node_Data * eet_node_value_get(Eet_Node *node)
290 void eet_node_del(Eet_Node *n)
291 # void * eet_data_node_encode_cipher(Eet_Node *node, const_char *cipher_key, int *size_ret)
292 # Eet_Node * eet_data_node_decode_cipher(const_void *data_in, const_char *cipher_key, int size_in)
293 # Eet_Node * eet_data_node_read_cipher(Eet_File *ef, const_char *name, const_char *cipher_key)
294 # int eet_data_node_write_cipher(Eet_File *ef, const_char *name, const_char *cipher_key, Eet_Node *node, int compress)
295
296
297 # ctypedef struct Eet_Connection
298
299 # ctypedef Eina_Bool Eet_Read_Cb (const_void *eet_data, size_t size, void *user_data)
300
301 # ctypedef Eina_Bool Eet_Write_Cb (const_void *data, size_t size, void *user_data)
302
303
304 # Eet_Connection * eet_connection_new(Eet_Read_Cb *eet_read_cb, Eet_Write_Cb *eet_write_cb, const_void *user_data)
305 # int eet_connection_received(Eet_Connection *conn, const_void *data, size_t size)
306 # Eina_Bool eet_connection_empty(Eet_Connection *conn)
307 # Eina_Bool eet_connection_send(Eet_Connection *conn, Eet_Data_Descriptor *edd, const_void *data_in, const_char *cipher_key)
308 # Eina_Bool eet_connection_node_send(Eet_Connection *conn, Eet_Node *node, const_char *cipher_key)
309 # void * eet_connection_close(Eet_Connection *conn, Eina_Bool *on_going)
diff --git a/efl/eet/eet.pyx b/efl/eet/eet.pyx
new file mode 100644
index 0000000..55146e1
--- /dev/null
+++ b/efl/eet/eet.pyx
@@ -0,0 +1,197 @@
1# Copyright (C) 2007-2014 various contributors (see AUTHORS)
2#
3# This file is part of Python-EFL.
4#
5# Python-EFL is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
9#
10# Python-EFL is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
17
18"""
19
20Eet Data Handling Library
21=========================
22
23These routines are used for Eet Library interaction
24
25.. _eet_main_intro:
26
27Introduction
28------------
29
30It is a tiny library designed to write an arbitrary set of chunks of data
31to a file and optionally compress each chunk (very much like a zip file)
32and allow fast random-access reading of the file later on. It does not
33do zip as a zip itself has more complexity than is needed, and it was much
34simpler to implement this once here.
35
36Eet is extremely fast, small and simple. Eet files can be very small and
37highly compressed, making them very optimal for just sending across the
38internet without having to archive, compress or decompress and install them.
39They allow for lightning-fast random-access reads once created, making them
40perfect for storing data that is written once (or rarely) and read many
41times, but the program does not want to have to read it all in at once.
42
43It also can encode and decode data structures in memory, as well as image
44data for saving to Eet files or sending across the network to other
45machines, or just writing to arbitrary files on the system. All data is
46encoded in a platform independent way and can be written and read by any
47architecture.
48
49.. _eet_main_next_steps:
50
51Next Steps
52----------
53
54After you understood what Eet is and installed it in your system
55you should proceed understanding the programming interface. We'd
56recommend you to take a while to learn Eina as it is very
57convenient and optimized, and Eet provides integration with it.
58
59.. _Eet_File_Image_Group:
60
61Image Store and Load
62--------------------
63
64Eet efficiently stores and loads images, including alpha
65channels and lossy compressions.
66
67Eet can handle both lossy compression with different levels of quality and
68non-lossy compression with different compression levels. It's also possible,
69given an image data, to only read its header to get the image information
70without decoding the entire content for it.
71
72The encode family of functions will take an image raw buffer and its
73parameters and compress it in memory, returning the new buffer.
74Likewise, the decode functions will read from the given location in memory
75and return the uncompressed image.
76
77The read and write functions will, respectively, encode and decode to or
78from an Eet file, under the specified key.
79
80These functions are fairly low level and the same functionality can be
81achieved using Evas and Edje, making it much easier to work with images
82as well as not needing to worry about things like scaling them.
83
84
85.. _Eet_Data_Group:
86
87Eet Data Serialization
88----------------------
89
90Convenience functions to serialize and parse complex data
91structures to binary blobs.
92
93While Eet core just handles binary blobs, it is often required
94to save some structured data of different types, such as
95strings, integers, lists, hashes and so on.
96
97Eet can serialize and then parse data types given some
98construction instructions. These are defined in two levels:
99
100- :ref:`Eet_Data_Descriptor_Class` to tell generic memory handling,
101 such as the size of the type, how to allocate memory, strings,
102 lists, hashes and so on.
103
104- :ref:`Eet_Data_Descriptor` to tell inside such type, the members and
105 their offsets inside the memory blob, their types and
106 names. These members can be simple types or other
107 #Eet_Data_Descriptor, allowing hierarchical types to be
108 defined.
109
110Given that C provides no introspection, this process can be
111quite cumbersome, so we provide lots of macros and convenience
112functions to aid creating the types.
113
114"""
115
116def init():
117 """
118
119 Initialize the EET library.
120
121 The first time this function is called, it will perform all the internal
122 initialization required for the library to function properly and increment
123 the initialization counter. Any subsequent call only increment this counter
124 and return its new value, so it's safe to call this function more than once.
125
126 :return: The new init count. Will be 0 if initialization failed.
127
128 :since: 1.0.0
129
130 """
131 return eet_init()
132
133def shutdown():
134 """
135
136 Shut down the EET library.
137
138 If eet_init() was called more than once for the running application,
139 eet_shutdown() will decrement the initialization counter and return its
140 new value, without doing anything else. When the counter reaches 0, all
141 of the internal elements will be shutdown and any memory used freed.
142
143 :return: The new init count.
144
145 :since: 1.0.0
146
147 """
148 return eet_shutdown()
149
150def clearcache():
151 """
152
153 Clear eet cache
154
155 For a faster access to previously accessed data, Eet keeps an internal
156 cache of files. These files will be freed automatically only when
157 they are unused and the cache gets full, in order based on the last time
158 they were used.
159 On systems with little memory this may present an unnecessary constraint,
160 so eet_clearcache() is available for users to reclaim the memory used by
161 files that are no longer needed. Those that were open using
162 EET_FILE_MODE_WRITE or EET_FILE_MODE_READ_WRITE and have modifications,
163 will be written down to disk before flushing them from memory.
164
165 :since: 1.0.0
166
167 """
168 eet_clearcache()
169
170cdef list eet_errors = [
171 "No error, it's all fine!",
172 "Given object or handle is NULL or invalid",
173 "There was nothing to do",
174 "Could not write to file or file is #EET_FILE_MODE_READ",
175 "Could not allocate memory",
176 "Failed to write data to destination",
177 "Failed to write file since it is too big",
178 "Failed to write due a generic Input/Output error",
179 "Failed to write due out of space",
180 "Failed to write because file was closed",
181 "Could not mmap file",
182 "Could not encode using X509",
183 "Could not validate signature",
184 "Signature is invalid",
185 "File or contents are not signed",
186 "Function is not implemented",
187 "Could not introduce random seed",
188 "Could not encrypt contents",
189 "Could not decrypt contents",
190]
191
192class EetError(Exception):
193 def __init__(self, code):
194 Exception.__init__(self, eet_errors[code])
195
196include "dictionary.pxi"
197include "file.pxi"
diff --git a/efl/eet/enums.pxd b/efl/eet/enums.pxd
new file mode 100644
index 0000000..ea4a9ab
--- /dev/null
+++ b/efl/eet/enums.pxd
@@ -0,0 +1,50 @@
1
2cdef extern from "Eet.h":
3
4 enum _Eet_Error:
5 EET_ERROR_NONE #No error, it's all fine!
6 EET_ERROR_BAD_OBJECT #Given object or handle is NULL or invalid
7 EET_ERROR_EMPTY #There was nothing to do
8 EET_ERROR_NOT_WRITABLE #Could not write to file or file is #EET_FILE_MODE_READ
9 EET_ERROR_OUT_OF_MEMORY #Could not allocate memory
10 EET_ERROR_WRITE_ERROR #Failed to write data to destination
11 EET_ERROR_WRITE_ERROR_FILE_TOO_BIG #Failed to write file since it is too big
12 EET_ERROR_WRITE_ERROR_IO_ERROR #Failed to write due a generic Input/Output error
13 EET_ERROR_WRITE_ERROR_OUT_OF_SPACE #Failed to write due out of space
14 EET_ERROR_WRITE_ERROR_FILE_CLOSED #Failed to write because file was closed
15 EET_ERROR_MMAP_FAILED #Could not mmap file
16 EET_ERROR_X509_ENCODING_FAILED #Could not encode using X509
17 EET_ERROR_SIGNATURE_FAILED #Could not validate signature
18 EET_ERROR_INVALID_SIGNATURE #Signature is invalid
19 EET_ERROR_NOT_SIGNED #File or contents are not signed
20 EET_ERROR_NOT_IMPLEMENTED #Function is not implemented
21 EET_ERROR_PRNG_NOT_SEEDED #Could not introduce random seed
22 EET_ERROR_ENCRYPT_FAILED #Could not encrypt contents
23 EET_ERROR_DECRYPT_FAILED #Could not decrypt contents
24
25 ctypedef _Eet_Error Eet_Error
26
27 ctypedef enum _Eet_Compression:
28 EET_COMPRESSION_NONE #No compression at all @since 1.7
29 EET_COMPRESSION_DEFAULT #Default compression (Zlib) @since 1.7
30 EET_COMPRESSION_LOW #Fast but minimal compression (Zlib) @since 1.7
31 EET_COMPRESSION_MED #Medium compression level (Zlib) @since 1.7
32 EET_COMPRESSION_HI #Slow but high compression level (Zlib) @since 1.7
33 EET_COMPRESSION_VERYFAST #Very fast, but lower compression ratio (LZ4HC) @since 1.7
34 EET_COMPRESSION_SUPERFAST #Very fast, but lower compression ratio (faster to compress than EET_COMPRESSION_VERYFAST) (LZ4) @since 1.7
35
36 EET_COMPRESSION_LOW2 #Space filler for compatibility. Don't use it @since 1.7
37 EET_COMPRESSION_MED1 #Space filler for compatibility. Don't use it @since 1.7
38 EET_COMPRESSION_MED2 #Space filler for compatibility. Don't use it @since 1.7
39 EET_COMPRESSION_HI1 #Space filler for compatibility. Don't use it @since 1.7
40 EET_COMPRESSION_HI2 #Space filler for compatibility. Don't use it @since 1.7
41
42 ctypedef _Eet_Compression Eet_Compression
43
44 ctypedef enum _Eet_File_Mode:
45 EET_FILE_MODE_INVALID
46 EET_FILE_MODE_READ #File is read-only.
47 EET_FILE_MODE_WRITE #File is write-only.
48 EET_FILE_MODE_READ_WRITE #File is for both read and write
49
50 ctypedef _Eet_File_Mode Eet_File_Mode
diff --git a/efl/eet/file.pxi b/efl/eet/file.pxi
new file mode 100644
index 0000000..b13a61f
--- /dev/null
+++ b/efl/eet/file.pxi
@@ -0,0 +1,1356 @@
1from libc.stdlib cimport free
2from cpython cimport PyUnicode_AsUTF8String
3from efl.utils.conversions cimport _ctouni, array_of_strings_to_python_list
4
5cimport efl.eet.enums as enums
6
7EET_FILE_MODE_INVALID = enums.EET_FILE_MODE_INVALID
8EET_FILE_MODE_READ = enums.EET_FILE_MODE_READ
9EET_FILE_MODE_WRITE = enums.EET_FILE_MODE_WRITE
10EET_FILE_MODE_READ_WRITE = enums.EET_FILE_MODE_READ_WRITE
11
12
13cdef class EetEntry(object):
14 """
15
16 Eet files may contains multiple Entries per file, this handle describe them. You can get that handle from an iterator given by eet_list_entries().
17
18 :see: eet_list_entries()
19 :since: 1.8.0
20
21 """
22
23 cdef Eet_Entry *ee
24
25 property name:
26 """The entry name"""
27 def __get__(self):
28 return _ctouni(self.ee.name)
29
30 def __set__(self, value):
31 if isinstance(value, unicode): value = PyUnicode_AsUTF8String(value)
32 self.ee.name = value
33
34 property offset:
35 """Where it start in the file"""
36 def __get__(self):
37 return self.ee.offset
38
39 def __set__(self, int value):
40 self.ee.offset = value
41
42 property size:
43 """The size on disk"""
44 def __get__(self):
45 return self.ee.size
46
47 def __set__(self, int value):
48 self.ee.size = value
49
50 property data_size:
51 """The decompressed size if relevant"""
52 def __get__(self):
53 return self.ee.data_size
54
55 def __set__(self, int value):
56 self.ee.data_size = value
57
58 property compression:
59 """Is this data compressed ?"""
60 def __get__(self):
61 return bool(self.ee.compression)
62
63 def __set__(self, bint value):
64 self.ee.compression = value
65
66 property ciphered:
67 """Is it ciphered ?"""
68 def __get__(self):
69 return bool(self.ee.ciphered)
70
71 def __set__(self, bint value):
72 self.ee.ciphered = value
73
74 property alias:
75 """Is it an alias ?"""
76 def __get__(self):
77 return bool(self.ee.alias)
78
79 def __set__(self, bint value):
80 self.ee.alias = value
81
82
83cdef class EetFile(object):
84
85 """
86
87 Opaque handle that defines an Eet file (or memory).
88
89 This handle will be returned by the functions eet_open() and
90 eet_memopen_read() and is used by every other function that affects the
91 file in any way. When you are done with it, call eet_close() to close it
92 and, if the file was open for writing, write down to disk any changes made
93 to it.
94
95 """
96
97 cdef:
98 Eet_File *ef
99
100 def __init__(self, filename, Eet_File_Mode mode):
101 """
102
103 Open an eet file on disk, and returns a handle to it.
104
105 :param file: The file path to the eet file. eg: @c "/tmp/file.eet".
106 :param mode: The mode for opening. Either #EET_FILE_MODE_READ,
107 #EET_FILE_MODE_WRITE or #EET_FILE_MODE_READ_WRITE.
108
109 :return: An opened eet file handle.
110
111 This function will open an exiting eet file for reading, and build
112 the directory table in memory and return a handle to the file, if it
113 exists and can be read, and no memory errors occur on the way, otherwise
114 NULL will be returned.
115
116 It will also open an eet file for writing. This will, if successful,
117 delete the original file and replace it with a new empty file, till
118 the eet file handle is closed or flushed. If it cannot be opened for
119 writing or a memory error occurs, NULL is returned.
120
121 You can also open the file for read/write. If you then write a key that
122 does not exist it will be created, if the key exists it will be replaced
123 by the new data.
124
125 If the same file is opened multiple times, then the same file handle will
126 be returned as eet maintains an internal list of all currently open
127 files. Note that it considers files opened for read only and those opened
128 for read/write and write only as 2 separate sets. Those that do not write
129 to the file and those that do. Eet will allow 2 handles to the same file
130 if they are in the 2 separate lists/groups. That means opening a file for
131 read only looks in the read only set, and returns a handle to that file
132 handle and increments its reference count. If you open a file for read/write
133 or write only it looks in the write set and returns a handle after
134 incrementing the reference count. You need to close an eet file handle
135 as many times as it has been opened to maintain correct reference counts.
136 Files whose modified timestamp or size do not match those of the existing
137 referenced file handles will not be returned and a new handle will be
138 returned instead.
139
140 :since: 1.0.0
141
142 """
143 if isinstance(filename, unicode): PyUnicode_AsUTF8String(filename)
144 self.ef = eet_open(filename, mode)
145
146 # @classmethod
147 # def mmap(self, file):
148 # """
149
150 # Open an eet file on disk from an Eina_File handle, and returns a handle to it.
151
152 # :param file: The Eina_File handle to map to an eet file.
153 # :return: An opened eet file handle.
154
155 # This function will open an exiting eet file for reading, and build
156 # the directory table in memory and return a handle to the file, if it
157 # exists and can be read, and no memory errors occur on the way, otherwise
158 # NULL will be returned.
159
160 # This function can't open file for writing only read only mode is supported for now.
161
162 # If the same file is opened multiple times, then the same file handle will
163 # be returned as eet maintains an internal list of all currently open
164 # files. That means opening a file for read only looks in the read only set,
165 # and returns a handle to that file handle and increments its reference count.
166 # You need to close an eet file handle as many times as it has been opened to
167 # maintain correct reference counts.
168
169 # :since: 1.8.0
170
171 # """
172 # Eet_File *eet_mmap(const Eina_File *file)
173
174 # @classmethod
175 # def memopen_read(self, data, size):
176 # """
177
178 # Open an eet file directly from a memory location. The data is not copied,
179 # so you must keep it around as long as the eet file is open. There is
180 # currently no cache for this kind of Eet_File, so it's reopened every time
181 # you use eet_memopen_read.
182
183 # :param data: Address of file in memory.
184 # :param size: Size of memory to be read.
185 # :return: A handle to the file.
186
187 # Files opened this way will always be in read-only mode.
188
189 # :since: 1.1.0
190
191 # """
192 # Eet_File *eet_memopen_read(const void *data, size_t size)
193
194 property mode:
195 """
196
197 Get the mode an Eet_File was opened with.
198
199 :type: Eet_File_Mode
200
201 :since: 1.0.0
202
203 """
204 def __get__(self):
205 return eet_mode_get(self.ef)
206
207 def close(self):
208 """
209
210 Close an eet file handle and flush pending writes.
211
212 :return: An eet error identifier.
213
214 This function will flush any pending writes to disk if the eet file
215 was opened for write, and free all data associated with the file handle
216 and file, and close the file. If it was opened for read (or read/write),
217 the file handle may still be held open internally for caching purposes.
218 To flush speculatively held eet file handles use eet_clearcache().
219
220 If the eet file handle is not valid nothing will be done.
221
222 :since: 1.0.0
223
224 :see: eet_clearcache()
225
226 """
227 cdef Eet_Error ret = eet_close(self.ef)
228 if ret != enums.EET_ERROR_NONE:
229 raise EetError(ret)
230
231 def sync(self):
232 """
233
234 Sync content of an eet file handle, flushing pending writes.
235
236 :return: An eet error identifier.
237
238 This function will flush any pending writes to disk. The eet file must
239 be opened for write.
240
241 If the eet file handle is not valid nothing will be done.
242
243 :since: 1.2.4
244
245 """
246 cdef Eet_Error ret = eet_sync(self.ef)
247 if ret != enums.EET_ERROR_NONE:
248 raise EetError(ret)
249
250 property dictionary:
251 """
252
253 Return a handle to the shared string dictionary of the Eet file
254
255 :return: A handle to the dictionary of the file
256
257 This function returns a handle to the dictionary of an Eet file whose
258 handle is @p ef, if a dictionary exists. NULL is returned otherwise or
259 if the file handle is known to be invalid.
260
261 :see: eet_dictionary_string_check() to know if given string came
262 from the dictionary or it was dynamically allocated using
263 the #Eet_Data_Descriptor_Class instructions.
264
265 :since: 1.0.0
266
267 """
268 def __get__(self):
269 cdef EetDictionary ret = EetDictionary.__new__(EetDictionary)
270 ret.ed = eet_dictionary_get(self.ef)
271 return ret
272
273 def read_string(self, name):
274 """
275
276 Read a specified entry from an eet file and return data
277
278 :param name: Name of the entry. eg: "/base/file_i_want".
279 :param size_ret: Number of bytes read from entry and returned.
280 :return: The data stored in that entry in the eet file.
281
282 This function finds an entry in the eet file that is stored under the
283 name specified, and returns that data, decompressed, if successful.
284 NULL is returned if the lookup fails or if memory errors are
285 encountered. It is the job of the calling program to call free() on
286 the returned data. The number of bytes in the returned data chunk are
287 placed in size_ret.
288
289 If the eet file handle is not valid NULL is returned and size_ret is
290 filled with 0.
291
292 :see: eet_read_cipher()
293
294 :since: 1.0.0
295
296 """
297 cdef:
298 void *buf
299 int size_ret
300
301 if isinstance(name, unicode): name = PyUnicode_AsUTF8String(name)
302
303 buf = eet_read(self.ef, name, &size_ret)
304
305 ret = <char *>buf
306
307 free(buf)
308
309 return ret
310
311 # def read_direct(self, name):
312 # """
313
314 # Read a specified entry from an eet file and return data
315
316 # :param name: Name of the entry. eg: "/base/file_i_want".
317 # :param size_ret: Number of bytes read from entry and returned.
318 # :return: The data stored in that entry in the eet file.
319
320 # This function finds an entry in the eet file that is stored under the
321 # name specified, and returns that data if not compressed and successful.
322 # NULL is returned if the lookup fails or if memory errors are
323 # encountered or if the data is compressed. The calling program must never
324 # call free() on the returned data. The number of bytes in the returned
325 # data chunk are placed in size_ret.
326
327 # If the eet file handle is not valid NULL is returned and size_ret is
328 # filled with 0.
329
330 # :since: 1.0.0
331
332 # """
333 # cdef:
334 # const_void *ret
335 # int size_ret
336
337 # if isinstance(name, unicode): name = PyUnicode_AsUTF8String(name)
338 # ret = eet_read_direct(self.ef, name, &size_ret)
339
340 # def write(self, name, data, int size, bint compress):
341 # """
342
343 # Write a specified entry to an eet file handle
344
345 # :param name: Name of the entry. eg: "/base/file_i_want".
346 # :param data: Pointer to the data to be stored.
347 # :param size: Length in bytes in the data to be stored.
348 # :param compress: Compression flags (1 == compress, 0 = don't compress).
349 # :return: bytes written on successful write, 0 on failure.
350
351 # This function will write the specified chunk of data to the eet file
352 # and return greater than 0 on success. 0 will be returned on failure.
353
354 # The eet file handle must be a valid file handle for an eet file opened
355 # for writing. If it is not, 0 will be returned and no action will be
356 # performed.
357
358 # Name, and data must not be NULL, and size must be > 0. If these
359 # conditions are not met, 0 will be returned.
360
361 # The data will be copied (and optionally compressed) in ram, pending
362 # a flush to disk (it will stay in ram till the eet file handle is
363 # closed though).
364
365 # :see: eet_write_cipher()
366
367 # :since: 1.0.0
368
369 # """
370 # cdef:
371 # const_void *ret
372 # int size_ret
373
374 # if isinstance(name, unicode): name = PyUnicode_AsUTF8String(name)
375
376 # ret = eet_write(self.ef, name, data, size, compress)
377 # if ret == 0:
378 # raise RuntimeError
379
380 def delete(self, name):
381 """
382
383 Delete a specified entry from an Eet file being written or re-written
384
385 :param name: Name of the entry. eg: "/base/file_i_want".
386 :return: Success or failure of the delete.
387
388 This function will delete the specified chunk of data from the eet file
389 and return greater than 0 on success. 0 will be returned on failure.
390
391 The eet file handle must be a valid file handle for an eet file opened
392 for writing. If it is not, 0 will be returned and no action will be
393 performed.
394
395 Name, must not be NULL, otherwise 0 will be returned.
396
397 :since: 1.0.0
398
399 """
400 if isinstance(name, unicode): name = PyUnicode_AsUTF8String(name)
401 if not eet_delete(self.ef, name):
402 raise RuntimeError
403
404 def alias(self, name, destination, int compress):
405 """
406
407 Alias a specific section to another one. Destination may exist or not,
408 no checks are done.
409
410 :param name: Name of the new entry. eg: "/base/file_i_want".
411 :param destination: Actual source of the aliased entry eg: "/base/the_real_stuff_i_want".
412 :param compress: Compression flags (1 == compress, 0 = don't compress).
413 :return: EINA_TRUE on success, EINA_FALSE on failure.
414
415 Name and Destination must not be NULL, otherwise EINA_FALSE will be returned.
416 The equivalent of this would be calling 'ln -s destination name'
417
418 :since: 1.3.3
419
420 """
421 if isinstance(name, unicode): name = PyUnicode_AsUTF8String(name)
422 if isinstance(destination, unicode):
423 destination = PyUnicode_AsUTF8String(destination)
424
425 if not eet_alias(self.ef, name, destination, compress):
426 raise RuntimeError
427
428 property filename:
429 """
430
431 Retrieve the filename of an Eet_File
432
433 :type: string
434
435 .. note::
436
437 This function will return None for files opened with
438 :py:meth:`memopen_read`
439
440 :since: 1.6
441
442 """
443 def __get__(self):
444 return _ctouni(eet_file_get(self.ef))
445
446 def alias_get(self, name):
447 """
448
449 Retrieve the destination name of an alias
450
451 :param name: Name of the entry. eg: "/base/file_i_want"
452 :return: Destination of the alias. eg: "/base/the_real_stuff_i_want", NULL on failure
453
454 Name must not be NULL, otherwise NULL will be returned.
455
456 :since: 1.5
457
458 """
459 if isinstance(name, unicode): name = PyUnicode_AsUTF8String(name)
460 return _ctouni(eet_alias_get(self.ef, name))
461
462 def list(self, glob):
463 """
464
465 List all entries in eet file matching shell glob.
466
467 :param glob: A shell glob to match against.
468 :param count_ret: Number of entries found to match.
469 :return: Pointer to an array of strings.
470
471 This function will list all entries in the eet file matching the
472 supplied shell glob and return an allocated list of their names, if
473 there are any, and if no memory errors occur.
474
475 The eet file handle must be valid and glob must not be NULL, or NULL
476 will be returned and count_ret will be filled with 0.
477
478 The calling program must call free() on the array returned, but NOT
479 on the string pointers in the array. They are taken as read-only
480 internals from the eet file handle. They are only valid as long as
481 the file handle is not closed. When it is closed those pointers in the
482 array are now not valid and should not be used.
483
484 On success the array returned will have a list of string pointers
485 that are the names of the entries that matched, and count_ret will have
486 the number of entries in this array placed in it.
487
488 Hint: an easy way to list all entries in an eet file is to use a glob
489 value of "*".
490
491 :since: 1.0.0
492
493 """
494 cdef:
495 int count_ret
496 char **cret
497 list ret
498
499 if isinstance(glob, unicode): glob = PyUnicode_AsUTF8String(glob)
500
501 cret = eet_list(self.ef, glob, &count_ret)
502 ret = array_of_strings_to_python_list(cret, count_ret)
503 free(cret)
504 return ret
505
506 # def list_entries(self):
507 # """
508
509 # Return an iterator that will describe each entry of an Eet_File.
510
511 # :return: An interator of Eet_Entry.
512
513 # :since: 1.8.0
514
515 # """
516
517 # Eina_Iterator *eet_list_entries(self.ef)
518
519 property num_entries:
520 """
521
522 Return the number of entries in the specified eet file.
523
524 :return: Number of entries in ef or -1 if the number of entries
525 cannot be read due to open mode restrictions.
526
527 :since: 1.0.0
528
529 """
530 def __get__(self):
531 return eet_num_entries(self.ef)
532
533 # def read_cipher(self, name, cipher_key):
534 # """
535
536 # Read a specified entry from an eet file and return data using a cipher.
537
538 # :param name: Name of the entry. eg: "/base/file_i_want".
539 # :param size_ret: Number of bytes read from entry and returned.
540 # :param cipher_key: The key to use as cipher.
541 # :return: The data stored in that entry in the eet file.
542
543 # This function finds an entry in the eet file that is stored under the
544 # name specified, and returns that data, decompressed, if successful.
545 # NULL is returned if the lookup fails or if memory errors are
546 # encountered. It is the job of the calling program to call free() on
547 # the returned data. The number of bytes in the returned data chunk are
548 # placed in size_ret.
549
550 # If the eet file handle is not valid NULL is returned and size_ret is
551 # filled with 0.
552
553 # :see: eet_read()
554
555 # :since: 1.0.0
556
557 # """
558 # void *
559 # eet_read_cipher(self.ef,
560 # const char *name,
561 # int *size_ret,
562 # const char *cipher_key)
563
564 # def write_cipher(self, name, data, size, compress, cipher_key):
565 # """
566
567 # Write a specified entry to an eet file handle using a cipher.
568
569 # :param name: Name of the entry. eg: "/base/file_i_want".
570 # :param data: Pointer to the data to be stored.
571 # :param size: Length in bytes in the data to be stored.
572 # :param compress: Compression flags (1 == compress, 0 = don't compress).
573 # :param cipher_key: The key to use as cipher.
574 # :return: bytes written on successful write, 0 on failure.
575
576 # This function will write the specified chunk of data to the eet file
577 # and return greater than 0 on success. 0 will be returned on failure.
578
579 # The eet file handle must be a valid file handle for an eet file opened
580 # for writing. If it is not, 0 will be returned and no action will be
581 # performed.
582
583 # Name, and data must not be NULL, and size must be > 0. If these
584 # conditions are not met, 0 will be returned.
585
586 # The data will be copied (and optionally compressed) in ram, pending
587 # a flush to disk (it will stay in ram till the eet file handle is
588 # closed though).
589
590 # :see: eet_write()
591
592 # :since: 1.0.0
593
594 # """
595 # int
596 # eet_write_cipher(self.ef,
597 # const char *name,
598 # const void *data,
599 # int size,
600 # int compress,
601 # const char *cipher_key)
602
603 # def data_image_header_read(self, name, w, h, alpha, compress, quality, lossy):
604 # """
605
606 # Read just the header data for an image and dont decode the pixels.
607
608 # :param name: Name of the entry. eg: "/base/file_i_want".
609 # :param w: A pointer to the unsigned int to hold the width in pixels.
610 # :param h: A pointer to the unsigned int to hold the height in pixels.
611 # :param alpha: A pointer to the int to hold the alpha flag.
612 # :param compress: A pointer to the int to hold the compression amount.
613 # :param quality: A pointer to the int to hold the quality amount.
614 # :param lossy: A pointer to the int to hold the lossiness flag.
615 # :return: 1 on successful decode, 0 otherwise
616
617 # Reads and decodes the image header data stored under the given key and
618 # Eet file.
619
620 # The information decoded is placed in each of the parameters, which must be
621 # provided. The width and height, measured in pixels, will be stored under
622 # the variables pointed by @p w and @p h, respectively. If the read or
623 # decode of the header fails, this values will be 0. The @p alpha parameter
624 # will be 1 or 0, denoting if the alpha channel of the image is used or not.
625 # If the image was losslessly compressed, the @p compress parameter will hold
626 # the compression amount used, ranging from 0 to 9 and @p lossy will be 0.
627 # In the case of lossy compression, @p lossy will be 1, and the compression
628 # quality will be placed under @p quality, with a value ranging from 0 to 100.
629
630 # :see: eet_data_image_header_decode()
631 # :see: eet_data_image_header_read_cipher()
632
633 # :since: 1.0.0
634
635 # """
636 # int
637 # eet_data_image_header_read(self.ef,
638 # const char *name,
639 # unsigned int *w,
640 # unsigned int *h,
641 # int *alpha,
642 # int *compress,
643 # int *quality,
644 # int *lossy)
645
646 # def data_image_read(self, name, w, h, alpha, compress, quality, lossy):
647 # """
648
649 # Read image data from the named key in the eet file.
650
651 # :param name: Name of the entry. eg: "/base/file_i_want".
652 # :param w: A pointer to the unsigned int to hold the width in pixels.
653 # :param h: A pointer to the unsigned int to hold the height in pixels.
654 # :param alpha: A pointer to the int to hold the alpha flag.
655 # :param compress: A pointer to the int to hold the compression amount.
656 # :param quality: A pointer to the int to hold the quality amount.
657 # :param lossy: A pointer to the int to hold the lossiness flag.
658 # :return: The image pixel data decoded
659
660 # Reads and decodes the image stored in the given Eet file under the named
661 # key.
662
663 # The returned pixel data is a linear array of pixels starting from the
664 # top-left of the image, scanning row by row from left to right. Each pile
665 # is a 32bit value, with the high byte being the alpha channel, the next being
666 # red, then green, and the low byte being blue.
667
668 # The rest of the parameters are the same as in eet_data_image_header_read().
669
670 # On success the function returns a pointer to the image data decoded. The
671 # calling application is responsible for calling free() on the image data
672 # when it is done with it. On failure NULL is returned and the parameter
673 # values may not contain any sensible data.
674
675 # :see: eet_data_image_header_read()
676 # :see: eet_data_image_decode()
677 # :see: eet_data_image_read_cipher()
678 # :see: eet_data_image_read_to_surface()
679
680 # :since: 1.0.0
681
682 # """
683 # void *
684 # eet_data_image_read(self.ef,
685 # const char *name,
686 # unsigned int *w,
687 # unsigned int *h,
688 # int *alpha,
689 # int *compress,
690 # int *quality,
691 # int *lossy)
692
693 # def data_image_read_to_surface(self, name, src_x, src_y, d, w, h, row_stride, alpha, compress, quality, lossy):
694 # """
695
696 # Read image data from the named key in the eet file and store it in the given buffer.
697
698 # :param name: Name of the entry. eg: "/base/file_i_want".
699 # :param src_x: The starting x coordinate from where to dump the stream.
700 # :param src_y: The starting y coordinate from where to dump the stream.
701 # :param d: A pointer to the pixel surface.
702 # :param w: The expected width in pixels of the pixel surface to decode.
703 # :param h: The expected height in pixels of the pixel surface to decode.
704 # :param row_stride: The length of a pixels line in the destination surface.
705 # :param alpha: A pointer to the int to hold the alpha flag.
706 # :param compress: A pointer to the int to hold the compression amount.
707 # :param quality: A pointer to the int to hold the quality amount.
708 # :param lossy: A pointer to the int to hold the lossiness flag.
709 # :return: 1 on success, 0 otherwise.
710
711 # Reads and decodes the image stored in the given Eet file, placing the
712 # resulting pixel data in the buffer pointed by the user.
713
714 # Like eet_data_image_read(), it takes the image data stored under the
715 # @p name key in the @p ef file, but instead of returning a new buffer with
716 # the pixel data, it places the result in the buffer pointed by @p d, which
717 # must be provided by the user and of sufficient size to hold the requested
718 # portion of the image.
719
720 # The @p src_x and @p src_y parameters indicate the top-left corner of the
721 # section of the image to decode. These have to be higher or equal than 0 and
722 # less than the respective total width and height of the image. The width
723 # and height of the section of the image to decode are given in @p w and @p h
724 # and also can't be higher than the total width and height of the image.
725
726 # The @p row_stride parameter indicates the length in bytes of each line in
727 # the destination buffer and it has to be at least @p w * 4.
728
729 # All the other parameters are the same as in eet_data_image_read().
730
731 # On success the function returns 1, and 0 on failure. On failure the
732 # parameter values may not contain any sensible data.
733
734 # :see: eet_data_image_read()
735 # :see: eet_data_image_decode()
736 # :see: eet_data_image_decode_to_surface()
737 # :see: eet_data_image_read_to_surface_cipher()
738
739 # :since: 1.0.2
740
741 # """
742 # int
743 # eet_data_image_read_to_surface(self.ef,
744 # const char *name,
745 # unsigned int src_x,
746 # unsigned int src_y,
747 # unsigned int *d,
748 # unsigned int w,
749 # unsigned int h,
750 # unsigned int row_stride,
751 # int *alpha,
752 # int *compress,
753 # int *quality,
754 # int *lossy)
755
756 # def data_image_write(self, name, data, w, h, alpha, compress, quality, lossy):
757 # """
758
759 # Write image data to the named key in an eet file.
760
761 # :param name: Name of the entry. eg: "/base/file_i_want".
762 # :param data: A pointer to the image pixel data.
763 # :param w: The width of the image in pixels.
764 # :param h: The height of the image in pixels.
765 # :param alpha: The alpha channel flag.
766 # :param compress: The compression amount.
767 # :param quality: The quality encoding amount.
768 # :param lossy: The lossiness flag.
769 # :return: Success if the data was encoded and written or not.
770
771 # This function takes image pixel data and encodes it in an eet file
772 # stored under the supplied name key, and returns how many bytes were
773 # actually written to encode the image data.
774
775 # The data expected is the same format as returned by eet_data_image_read.
776 # If this is not the case weird things may happen. Width and height must
777 # be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning
778 # the alpha values are not useful and 1 meaning they are). Compress can
779 # be from 0 to 9 (0 meaning no compression, 9 meaning full compression).
780 # This is only used if the image is not lossily encoded. Quality is used on
781 # lossy compression and should be a value from 0 to 100. The lossy flag
782 # can be 0 or 1. 0 means encode losslessly and 1 means to encode with
783 # image quality loss (but then have a much smaller encoding).
784
785 # On success this function returns the number of bytes that were required
786 # to encode the image data, or on failure it returns 0.
787
788 # :see: eet_data_image_read()
789 # :see: eet_data_image_encode()
790 # :see: eet_data_image_write_cipher()
791
792 # :since: 1.0.0
793
794 # """
795 # int
796 # eet_data_image_write(self.ef,
797 # const char *name,
798 # const void *data,
799 # unsigned int w,
800 # unsigned int h,
801 # int alpha,
802 # int compress,
803 # int quality,
804 # int lossy)
805
806 # def data_image_header_read_cipher(self, name, cipher_key, w, h, alpha, compress, quality, lossy):
807 # """
808
809 # Read just the header data for an image and dont decode the pixels using a cipher.
810
811 # :param name: Name of the entry. eg: "/base/file_i_want".
812 # :param cipher_key: The key to use as cipher.
813 # :param w: A pointer to the unsigned int to hold the width in pixels.
814 # :param h: A pointer to the unsigned int to hold the height in pixels.
815 # :param alpha: A pointer to the int to hold the alpha flag.
816 # :param compress: A pointer to the int to hold the compression amount.
817 # :param quality: A pointer to the int to hold the quality amount.
818 # :param lossy: A pointer to the int to hold the lossiness flag.
819 # :return: 1 on successful decode, 0 otherwise
820
821 # This function reads an image from an eet file stored under the named
822 # key in the eet file and return a pointer to the decompressed pixel data.
823
824 # The other parameters of the image (width, height etc.) are placed into
825 # the values pointed to (they must be supplied). The pixel data is a linear
826 # array of pixels starting from the top-left of the image scanning row by
827 # row from left to right. Each pixel is a 32bit value, with the high byte
828 # being the alpha channel, the next being red, then green, and the low byte
829 # being blue. The width and height are measured in pixels and will be
830 # greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
831 # that the alpha channel is not used. 1 denotes that it is significant.
832 # Compress is filled with the compression value/amount the image was
833 # stored with. The quality value is filled with the quality encoding of
834 # the image file (0 - 100). The lossy flags is either 0 or 1 as to if
835 # the image was encoded lossily or not.
836
837 # On success the function returns 1 indicating the header was read and
838 # decoded properly, or 0 on failure.
839
840 # :see: eet_data_image_header_read()
841
842 # :since: 1.0.0
843
844 # """
845 # int
846 # eet_data_image_header_read_cipher(self.ef,
847 # const char *name,
848 # const char *cipher_key,
849 # unsigned int *w,
850 # unsigned int *h,
851 # int *alpha,
852 # int *compress,
853 # int *quality,
854 # int *lossy)
855
856 # def data_image_read_cipher(self, name, cipher_key, w, h, alpha, compress, quality, lossy):
857 # """
858
859 # Read image data from the named key in the eet file using a cipher.
860
861 # :param name: Name of the entry. eg: "/base/file_i_want".
862 # :param cipher_key: The key to use as cipher.
863 # :param w: A pointer to the unsigned int to hold the width in pixels.
864 # :param h: A pointer to the unsigned int to hold the height in pixels.
865 # :param alpha: A pointer to the int to hold the alpha flag.
866 # :param compress: A pointer to the int to hold the compression amount.
867 # :param quality: A pointer to the int to hold the quality amount.
868 # :param lossy: A pointer to the int to hold the lossiness flag.
869 # :return: The image pixel data decoded
870
871 # This function reads an image from an eet file stored under the named
872 # key in the eet file and return a pointer to the decompressed pixel data.
873
874 # The other parameters of the image (width, height etc.) are placed into
875 # the values pointed to (they must be supplied). The pixel data is a linear
876 # array of pixels starting from the top-left of the image scanning row by
877 # row from left to right. Each pixel is a 32bit value, with the high byte
878 # being the alpha channel, the next being red, then green, and the low byte
879 # being blue. The width and height are measured in pixels and will be
880 # greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
881 # that the alpha channel is not used. 1 denotes that it is significant.
882 # Compress is filled with the compression value/amount the image was
883 # stored with. The quality value is filled with the quality encoding of
884 # the image file (0 - 100). The lossy flags is either 0 or 1 as to if
885 # the image was encoded lossily or not.
886
887 # On success the function returns a pointer to the image data decoded. The
888 # calling application is responsible for calling free() on the image data
889 # when it is done with it. On failure NULL is returned and the parameter
890 # values may not contain any sensible data.
891
892 # :see: eet_data_image_read()
893
894 # :since: 1.0.0
895
896 # """
897 # void *
898 # eet_data_image_read_cipher(self.ef,
899 # const char *name,
900 # const char *cipher_key,
901 # unsigned int *w,
902 # unsigned int *h,
903 # int *alpha,
904 # int *compress,
905 # int *quality,
906 # int *lossy)
907
908 # def data_image_read_to_surface_cipher(self, name, cipher_key, src_x, src_y, d, w, h, row_stride, alpha, compress, quality, lossy):
909 # """
910
911 # Read image data from the named key in the eet file using a cipher.
912
913 # :param name: Name of the entry. eg: "/base/file_i_want".
914 # :param cipher_key: The key to use as cipher.
915 # :param src_x: The starting x coordinate from where to dump the stream.
916 # :param src_y: The starting y coordinate from where to dump the stream.
917 # :param d: A pointer to the pixel surface.
918 # :param w: The expected width in pixels of the pixel surface to decode.
919 # :param h: The expected height in pixels of the pixel surface to decode.
920 # :param row_stride: The length of a pixels line in the destination surface.
921 # :param alpha: A pointer to the int to hold the alpha flag.
922 # :param compress: A pointer to the int to hold the compression amount.
923 # :param quality: A pointer to the int to hold the quality amount.
924 # :param lossy: A pointer to the int to hold the lossiness flag.
925 # :return: 1 on success, 0 otherwise.
926
927 # This function reads an image from an eet file stored under the named
928 # key in the eet file and return a pointer to the decompressed pixel data.
929
930 # The other parameters of the image (width, height etc.) are placed into
931 # the values pointed to (they must be supplied). The pixel data is a linear
932 # array of pixels starting from the top-left of the image scanning row by
933 # row from left to right. Each pixel is a 32bit value, with the high byte
934 # being the alpha channel, the next being red, then green, and the low byte
935 # being blue. The width and height are measured in pixels and will be
936 # greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
937 # that the alpha channel is not used. 1 denotes that it is significant.
938 # Compress is filled with the compression value/amount the image was
939 # stored with. The quality value is filled with the quality encoding of
940 # the image file (0 - 100). The lossy flags is either 0 or 1 as to if
941 # the image was encoded lossily or not.
942
943 # On success the function returns 1, and 0 on failure. On failure the
944 # parameter values may not contain any sensible data.
945
946 # :see: eet_data_image_read_to_surface()
947
948 # :since: 1.0.2
949
950 # """
951 # int
952 # eet_data_image_read_to_surface_cipher(self.ef,
953 # const char *name,
954 # const char *cipher_key,
955 # unsigned int src_x,
956 # unsigned int src_y,
957 # unsigned int *d,
958 # unsigned int w,
959 # unsigned int h,
960 # unsigned int row_stride,
961 # int *alpha,
962 # int *compress,
963 # int *quality,
964 # int *lossy)
965
966 # def data_image_write_cipher(self, name, cipher_key, data, w, h, alpha, compress, quality, lossy):
967 # """
968
969 # Write image data to the named key in an eet file using a cipher.
970
971 # :param name: Name of the entry. eg: "/base/file_i_want".
972 # :param cipher_key: The key to use as cipher.
973 # :param data: A pointer to the image pixel data.
974 # :param w: The width of the image in pixels.
975 # :param h: The height of the image in pixels.
976 # :param alpha: The alpha channel flag.
977 # :param compress: The compression amount.
978 # :param quality: The quality encoding amount.
979 # :param lossy: The lossiness flag.
980 # :return: Success if the data was encoded and written or not.
981
982 # This function takes image pixel data and encodes it in an eet file
983 # stored under the supplied name key, and returns how many bytes were
984 # actually written to encode the image data.
985
986 # The data expected is the same format as returned by eet_data_image_read.
987 # If this is not the case weird things may happen. Width and height must
988 # be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning
989 # the alpha values are not useful and 1 meaning they are). Compress can
990 # be from 0 to 9 (0 meaning no compression, 9 meaning full compression).
991 # This is only used if the image is not lossily encoded. Quality is used on
992 # lossy compression and should be a value from 0 to 100. The lossy flag
993 # can be 0 or 1. 0 means encode losslessly and 1 means to encode with
994 # image quality loss (but then have a much smaller encoding).
995
996 # On success this function returns the number of bytes that were required
997 # to encode the image data, or on failure it returns 0.
998
999 # :see: eet_data_image_write()
1000
1001 # :since: 1.0.0
1002
1003 # """
1004 # int
1005 # eet_data_image_write_cipher(self.ef,
1006 # const char *name,
1007 # const char *cipher_key,
1008 # const void *data,
1009 # unsigned int w,
1010 # unsigned int h,
1011 # int alpha,
1012 # int compress,
1013 # int quality,
1014 # int lossy)
1015
1016 # property identity:
1017 # """
1018
1019 # Set a key to sign a file
1020
1021
1022 # :param key: the key handle to set as identity.
1023 # :return: #EET_ERROR_BAD_OBJECT if @p ef is invalid or
1024 # #enums.EET_ERROR_NONE on success.
1025
1026 # :since: 1.2.0
1027
1028 # """
1029 # def __set__(self, key):
1030 # Eet_Error eet_identity_set(self.ef, Eet_Key *key)
1031
1032 # property identity_x509:
1033 # """
1034
1035 # Get the x509 der certificate associated with an Eet_File. Will return NULL
1036 # if the file is not signed.
1037
1038
1039 # :param der_length: The length of returned data, may be @c NULL.
1040 # :return: the x509 certificate or @c NULL on error.
1041
1042 # :since: 1.2.0
1043
1044 # """
1045 # def __get__(self):
1046 # const void *eet_identity_x509(self.ef, int *der_length)
1047
1048 # property identity_signature:
1049 # """
1050
1051 # Get the raw signature associated with an Eet_File. Will return NULL
1052 # if the file is not signed.
1053
1054
1055 # :param signature_length: The length of returned data, may be @c NULL.
1056 # :return: the raw signature or @c NULL on error.
1057
1058
1059 # """
1060 # const void *
1061 # eet_identity_signature(self.ef,
1062 # int *signature_length)
1063
1064 # property identity_sha1:
1065 # """
1066
1067 # Get the SHA1 associated with a file. Could be the one used to
1068 # sign the data or if the data where not signed, it will be the
1069 # SHA1 of the file.
1070
1071
1072 # :param sha1_length: The length of returned data, may be @c NULL.
1073 # :return: the associated SHA1 or @c NULL on error.
1074
1075 # :since: 1.2.0
1076
1077 # """
1078 # const void *
1079 # eet_identity_sha1(self.ef,
1080 # int *sha1_length)
1081
1082 # def data_read(self, EetDataDecriptor edd, name):
1083 # """
1084
1085 # Read a data structure from an eet file and decodes it.
1086
1087 # :param edd: The data descriptor handle to use when decoding.
1088 # :param name: The key the data is stored under in the eet file.
1089 # :return: A pointer to the decoded data structure.
1090
1091 # This function decodes a data structure stored in an eet file, returning
1092 # a pointer to it if it decoded successfully, or NULL on failure. This
1093 # can save a programmer dozens of hours of work in writing configuration
1094 # file parsing and writing code, as eet does all that work for the program
1095 # and presents a program-friendly data structure, just as the programmer
1096 # likes. Eet can handle members being added or deleted from the data in
1097 # storage and safely zero-fills unfilled members if they were not found
1098 # in the data. It checks sizes and headers whenever it reads data, allowing
1099 # the programmer to not worry about corrupt data.
1100
1101 # Once a data structure has been described by the programmer with the
1102 # fields they wish to save or load, storing or retrieving a data structure
1103 # from an eet file, or from a chunk of memory is as simple as a single
1104 # function call.
1105
1106 # :see: eet_data_read_cipher()
1107
1108 # :since: 1.0.0
1109
1110 # """
1111 # cdef:
1112 # void *ret
1113 # if isinstance(name, unicode): name = PyUnicode_AsUTF8String(name)
1114 # ret = eet_data_read(self.ef, edd.edd, name)
1115
1116 # def data_write(self, EetDataDecriptor edd, name, data, int compress):
1117 # """
1118
1119 # Write a data structure from memory and store in an eet file.
1120
1121 # :param edd: The data descriptor to use when encoding.
1122 # :param name: The key to store the data under in the eet file.
1123 # :param data: A pointer to the data structure to save and encode.
1124 # :param compress: Compression flags for storage.
1125 # :return: bytes written on successful write, 0 on failure.
1126
1127 # This function is the reverse of eet_data_read(), saving a data structure
1128 # to an eet file. The file must have been opening in write mode and the data
1129 # will be kept in memory until the file is either closed or eet_sync() is
1130 # called to flush any unwritten changes.
1131
1132 # :see: eet_data_write_cipher()
1133
1134 # :since: 1.0.0
1135
1136 # """
1137 # cdef void *cdata
1138 # if isinstance(name, unicode): name = PyUnicode_AsUTF8String(name)
1139 # int eet_data_write(self.ef, edd.edd, name, cdata, compress)
1140
1141 # def data_dump(self, name, dumpfunc, dumpdata):
1142 # """
1143
1144 # Dump an eet encoded data structure from an eet file into ascii text
1145
1146 # :param name: Name of the entry. eg: "/base/file_i_want".
1147 # :param dumpfunc: The function to call passed a string when new
1148 # data is converted to text
1149 # :param dumpdata: The data to pass to the @p dumpfunc callback.
1150 # :return: 1 on success, 0 on failure
1151
1152 # This function will take an open and valid eet file from
1153 # eet_open() request the data encoded by
1154 # eet_data_descriptor_encode() corresponding to the key @p name
1155 # and convert it into human readable ascii text. It does this by
1156 # calling the @p dumpfunc callback for all new text that is
1157 # generated. This callback should append to any existing text
1158 # buffer and will be passed the pointer @p dumpdata as a parameter
1159 # as well as a string with new text to be appended.
1160
1161 # :see: eet_data_dump_cipher()
1162
1163 # :since: 1.0.0
1164
1165 # """
1166 # int
1167 # eet_data_dump(self.ef,
1168 # const char *name,
1169 # Eet_Dump_Callback dumpfunc,
1170 # void *dumpdata)
1171
1172 # def data_undump(self, name, text, textlen, compress):
1173 # """
1174
1175 # Take an ascii encoding from eet_data_dump() and re-encode in binary.
1176
1177 # :param name: Name of the entry. eg: "/base/file_i_want".
1178 # :param text: The pointer to the string data to parse and encode.
1179 # :param textlen: The size of the string in bytes (not including 0
1180 # byte terminator).
1181 # :param compress: Compression flags (1 == compress, 0 = don't compress).
1182 # :return: 1 on success, 0 on failure
1183
1184 # This function will parse the string pointed to by @p text,
1185 # encode it the same way eet_data_descriptor_encode() takes an
1186 # in-memory data struct and encodes into a binary blob.
1187
1188 # The data (optionally compressed) will be in ram, pending a flush to
1189 # disk (it will stay in ram till the eet file handle is closed though).
1190
1191 # :see: eet_data_undump_cipher()
1192
1193 # :since: 1.0.0
1194
1195 # """
1196 # int
1197 # eet_data_undump(self.ef,
1198 # const char *name,
1199 # const char *text,
1200 # int textlen,
1201 # int compress)
1202
1203 # def data_read_cipher(self, edd, name, cipher_key):
1204 # """
1205
1206 # Read a data structure from an eet file and decodes it using a cipher.
1207
1208 # :param edd: The data descriptor handle to use when decoding.
1209 # :param name: The key the data is stored under in the eet file.
1210 # :param cipher_key: The key to use as cipher.
1211 # :return: A pointer to the decoded data structure.
1212
1213 # This function decodes a data structure stored in an eet file, returning
1214 # a pointer to it if it decoded successfully, or NULL on failure. This
1215 # can save a programmer dozens of hours of work in writing configuration
1216 # file parsing and writing code, as eet does all that work for the program
1217 # and presents a program-friendly data structure, just as the programmer
1218 # likes. Eet can handle members being added or deleted from the data in
1219 # storage and safely zero-fills unfilled members if they were not found
1220 # in the data. It checks sizes and headers whenever it reads data, allowing
1221 # the programmer to not worry about corrupt data.
1222
1223 # Once a data structure has been described by the programmer with the
1224 # fields they wish to save or load, storing or retrieving a data structure
1225 # from an eet file, or from a chunk of memory is as simple as a single
1226 # function call.
1227
1228 # :see: eet_data_read()
1229
1230 # :since: 1.0.0
1231
1232 # """
1233 # void *
1234 # eet_data_read_cipher(self.ef,
1235 # Eet_Data_Descriptor *edd,
1236 # const char *name,
1237 # const char *cipher_key)
1238
1239 # def data_write_cipher(self, edd, name, cipher_key, data, compress):
1240 # """
1241
1242 # Write a data structure from memory and store in an eet file
1243 # using a cipher.
1244
1245 # :param edd: The data descriptor to use when encoding.
1246 # :param name: The key to store the data under in the eet file.
1247 # :param cipher_key: The key to use as cipher.
1248 # :param data: A pointer to the data structure to save and encode.
1249 # :param compress: Compression flags for storage.
1250 # :return: bytes written on successful write, 0 on failure.
1251
1252 # This function is the reverse of eet_data_read_cipher(), saving a data structure
1253 # to an eet file.
1254
1255 # :since: 1.0.0
1256
1257 # """
1258 # int
1259 # eet_data_write_cipher(self.ef,
1260 # Eet_Data_Descriptor *edd,
1261 # const char *name,
1262 # const char *cipher_key,
1263 # const void *data,
1264 # int compress)
1265
1266 # def data_dump_cipher(self, name, cipher_key, dumpfunc, dumpdata):
1267 # """
1268
1269 # Dump an eet encoded data structure from an eet file into ascii
1270 # text using a cipher.
1271
1272 # :param name: Name of the entry. eg: "/base/file_i_want".
1273 # :param cipher_key: The key to use as cipher.
1274 # :param dumpfunc: The function to call passed a string when new
1275 # data is converted to text
1276 # :param dumpdata: The data to pass to the @p dumpfunc callback.
1277 # :return: 1 on success, 0 on failure
1278
1279 # This function will take an open and valid eet file from
1280 # eet_open() request the data encoded by
1281 # eet_data_descriptor_encode() corresponding to the key @p name
1282 # and convert it into human readable ascii text. It does this by
1283 # calling the @p dumpfunc callback for all new text that is
1284 # generated. This callback should append to any existing text
1285 # buffer and will be passed the pointer @p dumpdata as a parameter
1286 # as well as a string with new text to be appended.
1287
1288 # :see: eet_data_dump()
1289
1290 # :since: 1.0.0
1291
1292 # """
1293 # int
1294 # eet_data_dump_cipher(self.ef,
1295 # const char *name,
1296 # const char *cipher_key,
1297 # Eet_Dump_Callback dumpfunc,
1298 # void *dumpdata)
1299
1300 # def data_undump_cipher(self, name, cipher_key, dumpfunc, dumpdata):
1301 # """
1302
1303 # Take an ascii encoding from eet_data_dump() and re-encode in
1304 # binary using a cipher.
1305
1306 # :param name: Name of the entry. eg: "/base/file_i_want".
1307 # :param cipher_key: The key to use as cipher.
1308 # :param text: The pointer to the string data to parse and encode.
1309 # :param textlen: The size of the string in bytes (not including 0
1310 # byte terminator).
1311 # :param compress: Compression flags (1 == compress, 0 = don't compress).
1312 # :return: 1 on success, 0 on failure
1313
1314 # This function will parse the string pointed to by @p text,
1315 # encode it the same way eet_data_descriptor_encode() takes an
1316 # in-memory data struct and encodes into a binary blob.
1317
1318 # The data (optionally compressed) will be in ram, pending a flush to
1319 # disk (it will stay in ram till the eet file handle is closed though).
1320
1321 # :see: eet_data_undump()
1322
1323 # :since: 1.0.0
1324
1325 # """
1326 # int
1327 # eet_data_undump_cipher(self.ef,
1328 # const char *name,
1329 # const char *cipher_key,
1330 # const char *text,
1331 # int textlen,
1332 # int compress)
1333
1334 # def data_node_read_cipher(self, name, cipher_key):
1335 # """
1336
1337 # TODO FIX ME
1338
1339 # """
1340 # Eet_Node *
1341 # eet_data_node_read_cipher(self.ef,
1342 # const char *name,
1343 # const char *cipher_key)
1344
1345 # def data_node_write_cipher(self, name, cipher_key, node, compress):
1346 # """
1347
1348 # TODO FIX ME
1349
1350 # """
1351 # int
1352 # eet_data_node_write_cipher(self.ef,
1353 # const char *name,
1354 # const char *cipher_key,
1355 # Eet_Node *node,
1356 # int compress)
diff --git a/efl/eet/key.pxi b/efl/eet/key.pxi
new file mode 100644
index 0000000..5451077
--- /dev/null
+++ b/efl/eet/key.pxi
@@ -0,0 +1,80 @@
1
2
3
4"""
5
6@typedef Eet_Key
7Opaque handle that defines an identity (also known as key)
8in Eet's cipher system.
9
10"""
11typedef struct _Eet_Key Eet_Key;
12
13
14"""
15
16Callback used to request if needed the password of a private key.
17
18:param buffer: the buffer where to store the password.
19:param size: the maximum password size (size of buffer, including '@\0').
20:param rwflag: if the buffer is also readable or just writable.
21:param data: currently unused, may contain some context in future.
22:return: 1 on success and password was set to @p buffer, 0 on failure.
23
24:since: 1.2.0
25
26"""
27typedef int (*Eet_Key_Password_Callback)(char *buffer, int size, int rwflag, void *data);
28
29"""
30
31Create an Eet_Key needed for signing an eet file.
32
33The certificate should provide the public that match the private key.
34No verification is done to ensure that.
35
36:param certificate_file: The file where to find the certificate.
37:param private_key_file: The file that contains the private key.
38:param cb: Function to callback if password is required to unlock
39 private key.
40:return: A key handle to use, or @c NULL on failure.
41
42@see eet_identity_close()
43
44@warning You need to compile signature support in EET.
45:since: 1.2.0
46
47"""
48EAPI Eet_Key *
49eet_identity_open(const char *certificate_file,
50 const char *private_key_file,
51 Eet_Key_Password_Callback cb);