summaryrefslogtreecommitdiff
path: root/legacy/eet
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2010-04-02 13:51:00 +0000
committerCedric BAIL <cedric.bail@free.fr>2010-04-02 13:51:00 +0000
commitaa015979bbdf5f27fb43256898aa4fdb3b2dcfac (patch)
treede7bf42185667f9fb7290c3f408f559b63a8af32 /legacy/eet
parent3efbdeee6dfb3fac828884dd01b31c5dd1297b74 (diff)
* eet: Add Eet_Connection.
This will help people that want to use Eet over any kind of link. SVN revision: 47688
Diffstat (limited to 'legacy/eet')
-rw-r--r--legacy/eet/ChangeLog5
-rw-r--r--legacy/eet/src/lib/Eet.h111
-rw-r--r--legacy/eet/src/lib/Makefile.am3
-rw-r--r--legacy/eet/src/tests/eet_suite.c128
4 files changed, 246 insertions, 1 deletions
diff --git a/legacy/eet/ChangeLog b/legacy/eet/ChangeLog
index 0fa83ed8a3..43f52a8399 100644
--- a/legacy/eet/ChangeLog
+++ b/legacy/eet/ChangeLog
@@ -341,3 +341,8 @@
3412010-03-15 Adam Simpkins / Cedric BAIL 3412010-03-15 Adam Simpkins / Cedric BAIL
342 342
343 * Fix clearcache race condition. 343 * Fix clearcache race condition.
344
3452010-04-02 Cedric BAIL
346
347 * Fix eet_data_node_read_cipher return type.
348 * Add Eet_Connection.
diff --git a/legacy/eet/src/lib/Eet.h b/legacy/eet/src/lib/Eet.h
index 607d459048..23f1997e82 100644
--- a/legacy/eet/src/lib/Eet.h
+++ b/legacy/eet/src/lib/Eet.h
@@ -2643,6 +2643,117 @@ extern "C" {
2643 2643
2644 EAPI void *eet_node_walk(void *parent, const char *name, Eet_Node *root, Eet_Node_Walk *cb, void *user_data); 2644 EAPI void *eet_node_walk(void *parent, const char *name, Eet_Node *root, Eet_Node_Walk *cb, void *user_data);
2645 2645
2646 /*******/
2647
2648 /**
2649 * @defgroup Eet_Connection_Group Helper function to use eet over a network link
2650 *
2651 * Function that reconstruct and prepare packet of @ref Eet_Data_Group to be send.
2652 *
2653 */
2654
2655 /**
2656 * @typedef Eet_Connection
2657 * Opaque handle to track paquet for a specific connection.
2658 *
2659 * @ingroup Eet_Connection_Group
2660 */
2661 typedef struct _Eet_Connection Eet_Connection;
2662
2663 /**
2664 * @typedef Eet_Read_Cb
2665 * Called back when an @ref Eet_Data_Group has been received completly and could be used.
2666 *
2667 * @ingroup Eet_Connection_Group
2668 */
2669 typedef Eina_Bool Eet_Read_Cb(const void *eet_data, size_t size, void *user_data);
2670
2671 /**
2672 * @typedef Eet_Write_Cb
2673 * Called back when a packet containing @ref Eet_Data_Group data is ready to be send.
2674 *
2675 * @ingroup Eet_Connection_Group
2676 */
2677 typedef Eina_Bool Eet_Write_Cb(const void *data, size_t size, void *user_data);
2678
2679 /**
2680 * Instanciate a new connection to track.
2681 * @oaram eet_read_cb Function to call when one Eet_Data packet has been fully assemble.
2682 * @param eet_write_cb Function to call when one Eet_Data packet is ready to be send over the wire.
2683 * @param user_data Pointer provided to both functions to be used as a context handler.
2684 * @return NULL on failure, or a valid Eet_Connection handler.
2685 *
2686 * For every connection to track you will need a separate Eet_Connection provider.
2687 *
2688 * @since 1.2.4
2689 * @ingroup Eet_Connection_Group
2690 */
2691 Eet_Connection *eet_connection_new(Eet_Read_Cb *eet_read_cb, Eet_Write_Cb *eet_write_cb, const void *user_data);
2692
2693 /**
2694 * Process a raw packet received over the link
2695 * @oaram conn Connection handler to track.
2696 * @param data Raw data packet.
2697 * @param size The size of that packet.
2698 * @return 0 on complete success, any other value indicate where in the stream it got wrong (It could be before that packet).
2699 *
2700 * Every time you receive a packet related to your connection, you should pass
2701 * it to that function so that it could process and assemble packet has you
2702 * receive it. It will automatically call Eet_Read_Cb when one is fully received.
2703 *
2704 * @since 1.2.4
2705 * @ingroup Eet_Connection_Group
2706 */
2707 int eet_connection_received(Eet_Connection *conn, const void *data, size_t size);
2708
2709 /**
2710 * Convert a complex structure and prepare it to be send.
2711 * @oaram conn Connection handler to track.
2712 * @param edd The data descriptor to use when encoding.
2713 * @param data_in The pointer to the struct to encode into data.
2714 * @param cipher_key The key to use as cipher.
2715 * @return EINA_TRUE if the data where correctly send, EINA_FALSE if they don't.
2716 *
2717 * This function serialize data_in with edd, assemble the packet and call
2718 * Eet_Write_Cb when ready. The data passed Eet_Write_Cb are temporary allocated
2719 * and will vanish just after the return of the callback.
2720 *
2721 * @see eet_data_descriptor_encode_cipher
2722 *
2723 * @since 1.2.4
2724 * @ingroup Eet_Connection_Group
2725 */
2726 Eina_Bool eet_connection_send(Eet_Connection *conn, Eet_Data_Descriptor *edd, const void *data_in, const char *cipher_key);
2727
2728 /**
2729 * Convert a Eet_Node tree and prepare it to be send.
2730 * @oaram conn Connection handler to track.
2731 * @param node The data tree to use when encoding.
2732 * @param cipher_key The key to use as cipher.
2733 * @return EINA_TRUE if the data where correctly send, EINA_FALSE if they don't.
2734 *
2735 * This function serialize node, assemble the packet and call
2736 * Eet_Write_Cb when ready. The data passed Eet_Write_Cb are temporary allocated
2737 * and will vanish just after the return of the callback.
2738 *
2739 * @see eet_data_node_encode_cipher
2740 *
2741 * @since 1.2.4
2742 * @ingroup Eet_Connection_Group
2743 */
2744 Eina_Bool eet_connection_node_send(Eet_Connection *conn, Eet_Node *node, const char *cipher_key);
2745
2746 /**
2747 * Close a connection and lost its track.
2748 * @oaram conn Connection handler to close.
2749 * @param on_going Signal if a partial packet wasn't completed.
2750 * @return the user_data passed to both callback.
2751 *
2752 * @since 1.2.4
2753 * @ingroup Eet_Connection_Group
2754 */
2755 void *eet_connection_close(Eet_Connection *conn, Eina_Bool *on_going);
2756
2646/***************************************************************************/ 2757/***************************************************************************/
2647 2758
2648#ifdef __cplusplus 2759#ifdef __cplusplus
diff --git a/legacy/eet/src/lib/Makefile.am b/legacy/eet/src/lib/Makefile.am
index 54835077ea..35bff744ec 100644
--- a/legacy/eet/src/lib/Makefile.am
+++ b/legacy/eet/src/lib/Makefile.am
@@ -27,7 +27,8 @@ eet_image.c \
27eet_cipher.c \ 27eet_cipher.c \
28eet_dictionary.c \ 28eet_dictionary.c \
29eet_node.c \ 29eet_node.c \
30eet_utils.c 30eet_utils.c \
31eet_connection.c
31 32
32if EET_AMALGAMATION 33if EET_AMALGAMATION
33nodist_libeet_la_SOURCES = eet_amalgamation.c 34nodist_libeet_la_SOURCES = eet_amalgamation.c
diff --git a/legacy/eet/src/tests/eet_suite.c b/legacy/eet/src/tests/eet_suite.c
index 8ace0d00cb..1176c4cbd3 100644
--- a/legacy/eet/src/tests/eet_suite.c
+++ b/legacy/eet/src/tests/eet_suite.c
@@ -1470,6 +1470,130 @@ START_TEST(eet_cache_concurrency)
1470} 1470}
1471END_TEST 1471END_TEST
1472 1472
1473typedef struct _Eet_Connection_Data Eet_Connection_Data;
1474struct _Eet_Connection_Data
1475{
1476 Eet_Connection *conn;
1477 Eet_Data_Descriptor *edd;
1478 Eina_Bool test;
1479};
1480
1481static Eina_Bool
1482_eet_connection_read(const void *eet_data, size_t size, void *user_data)
1483{
1484 Eet_Connection_Data *dt = user_data;
1485 Eet_Test_Ex_Type *result;
1486 Eet_Node *node;
1487 int test;
1488
1489 result = eet_data_descriptor_decode(dt->edd, eet_data, size);
1490 node = eet_data_node_decode_cipher(eet_data, NULL, size);
1491
1492 /* Test the resulting data. */
1493 fail_if(!node);
1494 fail_if(_eet_test_ex_check(result, 0) != 0);
1495 fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
1496 fail_if(eina_list_data_get(result->ilist) == NULL);
1497 fail_if(*((int*)eina_list_data_get(result->ilist)) != 42);
1498 fail_if(eina_list_data_get(result->slist) == NULL);
1499 fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
1500 fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL);
1501 fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0);
1502 fail_if(strcmp(result->charray[0], "test") != 0);
1503
1504 test = 0;
1505 if (result->hash) eina_hash_foreach(result->hash, func, &test);
1506 fail_if(test != 0);
1507 if (result->ihash) eina_hash_foreach(result->ihash, func7, &test);
1508 fail_if(test != 0);
1509
1510 if (!dt->test)
1511 {
1512 dt->test = EINA_TRUE;
1513 fail_if(!eet_connection_node_send(dt->conn, node, NULL));
1514 }
1515
1516 return EINA_TRUE;
1517}
1518
1519static Eina_Bool
1520_eet_connection_write(const void *data, size_t size, void *user_data)
1521{
1522 Eet_Connection_Data *dt = user_data;
1523 int still;
1524
1525 if (!dt->test)
1526 {
1527 int step = size / 3;
1528
1529 eet_connection_received(dt->conn, data, step);
1530 eet_connection_received(dt->conn, (char*) data + step, step);
1531 size -= 2 * step;
1532 still = eet_connection_received(dt->conn, (char*) data + 2 * step, size);
1533 }
1534 else
1535 still = eet_connection_received(dt->conn, data, size);
1536 fail_if(still);
1537
1538 return EINA_TRUE;
1539}
1540
1541START_TEST(eet_connection_check)
1542{
1543 Eet_Connection *conn;
1544 Eet_Data_Descriptor *edd;
1545 Eet_Data_Descriptor_Class eddc;
1546 Eet_Connection_Data ecd;
1547 Eet_Test_Ex_Type etbt;
1548 Eina_Bool on_going;
1549
1550 eet_init();
1551
1552 _eet_test_ex_set(&etbt, 0);
1553 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
1554 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
1555 etbt.hash = eina_hash_string_superfast_new(NULL);
1556 eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2));
1557 eina_hash_add(etbt.hash, EET_TEST_KEY2, _eet_test_ex_set(NULL, 2));
1558 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
1559 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
1560 etbt.ihash = eina_hash_string_superfast_new(NULL);
1561 eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
1562 eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7);
1563 etbt.slist = eina_list_prepend(NULL, "test");
1564 etbt.shash = eina_hash_string_superfast_new(NULL);
1565 eina_hash_add(etbt.shash, EET_TEST_KEY1, "test");
1566 memset(&etbt.charray, 0, sizeof(etbt.charray));
1567 etbt.charray[0] = "test";
1568
1569 eet_eina_file_data_descriptor_class_set(&eddc, "Eet_Test_Ex_Type", sizeof(Eet_Test_Ex_Type));
1570
1571 edd = eet_data_descriptor_file_new(&eddc);
1572 fail_if(!edd);
1573
1574 _eet_build_ex_descriptor(edd);
1575
1576 /* Create a connection. */
1577 conn = eet_connection_new(_eet_connection_read, _eet_connection_write, &ecd);
1578 fail_if(!conn);
1579
1580 /* Init context. */
1581 ecd.test = EINA_FALSE;
1582 ecd.conn = conn;
1583 ecd.edd = edd;
1584
1585 /* Test the connection. */
1586 fail_if(!eet_connection_send(conn, edd, &etbt, NULL));
1587
1588 fail_if(!ecd.test);
1589
1590 fail_if(!eet_connection_close(conn, &on_going));
1591
1592 fail_if(on_going);
1593
1594 eet_shutdown();
1595}
1596END_TEST
1473 1597
1474Suite * 1598Suite *
1475eet_suite(void) 1599eet_suite(void)
@@ -1519,6 +1643,10 @@ eet_suite(void)
1519 tcase_add_test(tc, eet_cache_concurrency); 1643 tcase_add_test(tc, eet_cache_concurrency);
1520 suite_add_tcase(s, tc); 1644 suite_add_tcase(s, tc);
1521 1645
1646 tc = tcase_create("Eet Connection");
1647 tcase_add_test(tc, eet_connection_check);
1648 suite_add_tcase(s, tc);
1649
1522 return s; 1650 return s;
1523} 1651}
1524 1652