summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/doxygen/data/head.html2
-rw-r--r--doc/smman.dox.in79
-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
6 files changed, 231 insertions, 17 deletions
diff --git a/doc/doxygen/data/head.html b/doc/doxygen/data/head.html
index af2e0ea..e94f339 100644
--- a/doc/doxygen/data/head.html
+++ b/doc/doxygen/data/head.html
@@ -36,7 +36,7 @@ $extrastylesheet
36 <li><a href="group__Lib-Conf.html">Conf Library</a></li> 36 <li><a href="group__Lib-Conf.html">Conf Library</a></li>
37 <li><a href="group__Lib-Spy.html">Spy Library</a></li> 37 <li><a href="group__Lib-Spy.html">Spy Library</a></li>
38 <li><a href="group__Lib-Rules.html">Rules library</a></li> 38 <li><a href="group__Lib-Rules.html">Rules library</a></li>
39 <li><a href="pages.html">Extra Pages</a></li> 39 <li><a href="group__Lib-Store.html">Store library</a></li>
40 </ul> 40 </ul>
41 </div> 41 </div>
42 </div> 42 </div>
diff --git a/doc/smman.dox.in b/doc/smman.dox.in
index a855dfc..65b40a2 100644
--- a/doc/smman.dox.in
+++ b/doc/smman.dox.in
@@ -221,7 +221,7 @@
221 * return EINA_TRUE; 221 * return EINA_TRUE;
222 * } 222 * }
223 * 223 *
224 * int main(int argc EINA_UNUSED, char **argv EINA_UNUSED) 224 * int main(int argc, char **argv)
225 * { 225 * {
226 * Spy *spy; 226 * Spy *spy;
227 * Ecore_Event_Handler *eeh; 227 * Ecore_Event_Handler *eeh;
@@ -286,3 +286,80 @@
286 * @li @ref Lib-Rules-Functions 286 * @li @ref Lib-Rules-Functions
287 * @defgroup Lib-Rules-Functions API functions 287 * @defgroup Lib-Rules-Functions API functions
288 */ 288 */
289
290
291/**
292 * @defgroup Lib-Store Store Library
293 *
294 * @section Lib-Store-Introduction Introduction
295 * Store is an asynchronous library for the sending of data to an HTTP
296 * URL.
297 *
298 * @section Lib-Store-Algorithm
299 * All calls in this library are made inside the main loop.<br />
300 * We do so because we dont have any heavy operations to do like I/O,
301 * or heavy work on strings. We just send data and wait for server
302 * to answer.
303 * @msc
304 * App,Store,Ecore,Ecore_Con;
305 * App=>Store [ label = "store_add()", URL = "@ref store_add" ];
306 * Store=>Ecore [ label = "ecore_event_handler_add()" ];
307 * Store=>Ecore [ label = "ecore_event_handler_add()" ];
308 * Store=>Ecore_Con [ label = "ecore_con_url_post()" ];
309 * --- [ label = "From here, we wait for events" ];
310 * Ecore_Con=>Store [ label = "store_event_data()" ];
311 * Ecore_Con=>Store [ label = "store_event_complete()" ];
312 * Store=>App [ label = "done_cb()" ];
313 * @endmsc
314 *
315 * @section Lib-Store-Code Code documentation
316 * @li @ref Lib-Store-Functions
317 * @li @ref Lib-Store-Example
318 * @defgroup Lib-Store-Functions API functions
319 * @defgroup Lib-Store-Example Basic Example
320 * @section Lib-Store-Example-Sample-App Sample program
321 * This program will send a given string to a local elasticsearch server.
322 * @code
323 * #include <Store.h>
324 *
325 * void
326 * done_cb(void *data EINA_UNUSED,
327 * Store *store EINA_UNUSED,
328 * char *answer,
329 * size_t len EINA_UNUSED)
330 * {
331 * printf("Done_Cb : %s\n", answer);
332 *
333 * }
334 *
335 * void
336 * error_cb(void *data EINA_UNUSED,
337 * Store *store EINA_UNUSED,
338 * char *strerr)
339 * {
340 * printf("Error_Cb : %s\n", strerr);
341 * }
342 *
343 * int main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
344 * {
345 * Store *store;
346 *
347 * if (argc != 2)
348 * {
349 * fprintf(stderr, "You need to provide a string to store\n");
350 * return 1;
351 * }
352 *
353 * store_init();
354 *
355 * store = store_new("http://localhost:9200/logsmanager/");
356 * store_add(store, argv[1], strlen(argv[1]),
357 * done_cb, error_cb, store);
358 *
359 * ecore_main_loop_begin();
360 *
361 * store_shutdown();
362 * return 0;
363 * }
364 * @endcode
365 */
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 */