summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Friloux <guillaume.friloux@gmail.com>2014-01-02 15:01:57 +0100
committerGuillaume Friloux <guillaume.friloux@gmail.com>2014-01-02 15:01:57 +0100
commitbf21906254dfb862b288bf9185140699f56e07ed (patch)
treef940f802b4974b23a0ebd7dcd7e55358c6139eb9 /src
parent408065485d8534a5126ee02ca0786c625e3cc66e (diff)
More doc.
Diffstat (limited to 'src')
-rw-r--r--src/lib/store/store_event.c35
-rw-r--r--src/lib/store/store_main.c62
-rw-r--r--src/lib/store/store_private.h46
-rw-r--r--src/lib/store/store_utils.c24
4 files changed, 152 insertions, 15 deletions
diff --git a/src/lib/store/store_event.c b/src/lib/store/store_event.c
index 73533f4..c46a296 100644
--- a/src/lib/store/store_event.c
+++ b/src/lib/store/store_event.c
@@ -1,5 +1,24 @@
1#include "store_private.h" 1#include "store_private.h"
2 2
3/**
4 * @addtogroup Lib-Store-Functions
5 * @{
6 */
7
8/**
9 * @cond IGNORE
10 */
11
12/**
13 * @brief Store received data from ElasticSearch server.
14 * @param data Store_Add structure.
15 * @param type UNUSED.
16 * @param event_info Ecore_Con_Event_Url_Data structure.
17 * @return EINA_TRUE.
18 *
19 * This function is called by ecore_con_url for every data block
20 * received from web server.
21 */
3Eina_Bool 22Eina_Bool
4store_event_data(void *data, 23store_event_data(void *data,
5 int type EINA_UNUSED, 24 int type EINA_UNUSED,
@@ -16,11 +35,15 @@ store_event_data(void *data,
16 eina_strbuf_append_length(sa->data.buf, 35 eina_strbuf_append_length(sa->data.buf,
17 (const char *)url_data->data, 36 (const char *)url_data->data,
18 url_data->size); 37 url_data->size);
19 sa->data.len += url_data->size;
20
21 return EINA_TRUE; 38 return EINA_TRUE;
22} 39}
23 40
41/**
42 * @brief Storing is over and we got total answer.
43 * @param data Store_Add structure.
44 * @param type UNUSED.
45 * @param event_info Ecore_Con_Event_Url_Complete.
46 */
24Eina_Bool 47Eina_Bool
25store_event_complete(void *data, 48store_event_complete(void *data,
26 int type EINA_UNUSED, 49 int type EINA_UNUSED,
@@ -53,3 +76,11 @@ store_event_complete(void *data,
53 store_add_free(sa); 76 store_add_free(sa);
54 return EINA_TRUE; 77 return EINA_TRUE;
55} 78}
79
80/**
81 * @endcond
82 */
83
84/**
85 * @}
86 */
diff --git a/src/lib/store/store_main.c b/src/lib/store/store_main.c
index 912c8f9..68afa0f 100644
--- a/src/lib/store/store_main.c
+++ b/src/lib/store/store_main.c
@@ -1,9 +1,21 @@
1#include "store_private.h" 1#include "store_private.h"
2 2
3/**
4 * @addtogroup Lib-Store-Functions
5 * @{
6 */
7
8/**
9 * @cond IGNORE
10 */
11
3static int _store_init_count = 0; 12static int _store_init_count = 0;
4int _store_log_dom_global = -1; 13int _store_log_dom_global = -1;
5 14
6 15/**
16 * @brief Frees a Store_Add structure.
17 * @param sa Store_Add structure to free.
18 */
7void 19void
8store_add_free(Store_Add *sa) 20store_add_free(Store_Add *sa)
9{ 21{
@@ -14,6 +26,21 @@ store_add_free(Store_Add *sa)
14 free(sa); 26 free(sa);
15} 27}
16 28
29/**
30 * @endcond
31 */
32
33/**
34 * @brief Store given data to store's url.
35 * @param store Store structure.
36 * @param buf Buffer to store.
37 * @param len Length of @buf.
38 * @param done_cb Callback to call when data is stored.
39 * @param error_cb Callback to call if an error occured.
40 * @param data Data to pass to callbacks.
41 * @return EINA_TRUE if we try to store data.
42 * EINA_FALSE if an error occured when creating storing process.
43 */
17Eina_Bool 44Eina_Bool
18store_add(Store *store, 45store_add(Store *store,
19 const char *buf, 46 const char *buf,
@@ -89,18 +116,33 @@ sa_free:
89 return EINA_FALSE; 116 return EINA_FALSE;
90} 117}
91 118
119/**
120 * @brief Attach given data to the Store structure.
121 * @param store Store structure to attach data to.
122 * @param data Data to attach to structure.
123 */
92void 124void
93store_data_set(Store *store, const void *data) 125store_data_set(Store *store, const void *data)
94{ 126{
95 store->data = data; 127 store->data = data;
96} 128}
97 129
130/**
131 * @brief Get unmodified data attached to the store structure.
132 * @param store Store structure.
133 * @return Pointer to attached data.
134 */
98void * 135void *
99store_data_get(Store *store) 136store_data_get(Store *store)
100{ 137{
101 return (void *)store->data; 138 return (void *)store->data;
102} 139}
103 140
141/**
142 * @brief Create a new store structure.
143 * @param url URL for storing data.
144 * @return Pointer to newly created Store structure.
145 */
104Store * 146Store *
105store_new(const char *url) 147store_new(const char *url)
106{ 148{
@@ -126,6 +168,10 @@ store_free:
126 return NULL; 168 return NULL;
127} 169}
128 170
171/**
172 * @brief Frees an allocated Store structure.
173 * @param store Store structure to free.
174 */
129void 175void
130store_free(Store *store) 176store_free(Store *store)
131{ 177{
@@ -135,6 +181,10 @@ store_free(Store *store)
135 free(store); 181 free(store);
136} 182}
137 183
184/**
185 * @brief Initialize the store library and all it's required submodules.
186 * @return 1 or greater on success, 0 otherwise.
187 */
138int 188int
139store_init(void) 189store_init(void)
140{ 190{
@@ -189,6 +239,12 @@ shutdown_eina:
189 return --_store_init_count; 239 return --_store_init_count;
190} 240}
191 241
242/**
243 * @brief Shutdown store and all it's submodules if possible.
244 * @return 0 if store shuts down, greater than 0 otherwise.
245 * This function shuts down all things set up in store_init()
246 * and cleans up its memory.
247 */
192int 248int
193store_shutdown(void) 249store_shutdown(void)
194{ 250{
@@ -209,3 +265,7 @@ store_shutdown(void)
209 eina_shutdown(); 265 eina_shutdown();
210 return _store_init_count; 266 return _store_init_count;
211} 267}
268
269/**
270 * @}
271 */
diff --git a/src/lib/store/store_private.h b/src/lib/store/store_private.h
index 3f09f25..6112293 100644
--- a/src/lib/store/store_private.h
+++ b/src/lib/store/store_private.h
@@ -1,5 +1,13 @@
1#include <Store.h> 1#include <Store.h>
2 2
3/**
4 * @addtogroup Lib-Store-Functions
5 * @{
6 */
7
8/**
9 * @cond IGNORE
10 */
3extern int _store_log_dom_global; 11extern int _store_log_dom_global;
4 12
5#define ERR(...) EINA_LOG_DOM_ERR(_store_log_dom_global, __VA_ARGS__) 13#define ERR(...) EINA_LOG_DOM_ERR(_store_log_dom_global, __VA_ARGS__)
@@ -8,35 +16,41 @@ extern int _store_log_dom_global;
8#define WRN(...) EINA_LOG_DOM_WARN(_store_log_dom_global, __VA_ARGS__) 16#define WRN(...) EINA_LOG_DOM_WARN(_store_log_dom_global, __VA_ARGS__)
9#define CRI(...) EINA_LOG_DOM_CRIT(_store_log_dom_global, __VA_ARGS__) 17#define CRI(...) EINA_LOG_DOM_CRIT(_store_log_dom_global, __VA_ARGS__)
10 18
11 19/**
20 * @brief Main structure.
21 */
12struct _Store 22struct _Store
13{ 23{
14 const char *url; 24 const char *url; /*!< URL to store data to. */
15 const void *data; 25 const void *data; /*!< Unmodified user data attached to structure. */
16}; 26};
17 27
28/**
29 * @brief Store_Add structure.
30 *
31 * This structure helps to manage storage of data.
32 */
18typedef struct _Store_Add 33typedef struct _Store_Add
19{ 34{
20 Store *store; 35 Store *store; /*!< Store structure */
21 Ecore_Con_Url *ec; 36 Ecore_Con_Url *ec; /*!< Ecore_Con_Url structure used for storage */
22 37
23 struct 38 struct
24 { 39 {
25 Eina_Strbuf *buf; 40 Eina_Strbuf *buf; /*!< Buffer for data reception */
26 size_t len;
27 } data; 41 } data;
28 42
29 struct 43 struct
30 { 44 {
31 const void *data; 45 const void *data; /*!< Unmodified user data attached to storage */
32 Store_Done_Cb done; 46 Store_Done_Cb done; /*!< Callback to call when storage is over */
33 Store_Error_Cb error; 47 Store_Error_Cb error; /*!< Callback to call if an error occured */
34 } cb; 48 } cb;
35 49
36 struct 50 struct
37 { 51 {
38 Ecore_Event_Handler *ed, 52 Ecore_Event_Handler *ed, /*!< Event handler for data reception */
39 *ec; 53 *ec; /*!< Event handler for complete http query */
40 } ev; 54 } ev;
41} Store_Add; 55} Store_Add;
42 56
@@ -46,3 +60,11 @@ Eina_Bool store_event_data(void *data, int type, void *event_info);
46Eina_Bool store_event_complete(void *data, int type, void *event_info); 60Eina_Bool store_event_complete(void *data, int type, void *event_info);
47 61
48char * store_utils_dupf(const char *s, ...); 62char * store_utils_dupf(const char *s, ...);
63
64/**
65 * @endcond
66 */
67
68/**
69 * @}
70 */
diff --git a/src/lib/store/store_utils.c b/src/lib/store/store_utils.c
index 18cdf64..00b89d0 100644
--- a/src/lib/store/store_utils.c
+++ b/src/lib/store/store_utils.c
@@ -3,6 +3,22 @@
3 3
4#include "store_private.h" 4#include "store_private.h"
5 5
6
7/**
8 * @addtogroup Lib-Store-Functions
9 * @{
10 */
11
12/**
13 * @cond IGNORE
14 */
15
16
17/**
18 * @brief Creates a new string from a format string.
19 * @param s the NULL-terminated format string to retrieve an instance of.
20 * @return A pointer to the allocated buffer. NULL on failure.
21 */
6char * 22char *
7store_utils_dupf(const char *s, ...) 23store_utils_dupf(const char *s, ...)
8{ 24{
@@ -19,3 +35,11 @@ store_utils_dupf(const char *s, ...)
19 35
20 return str; 36 return str;
21} 37}
38
39/**
40 * @endcond
41 */
42
43/**
44 * @}
45 */