summaryrefslogtreecommitdiff
path: root/src/lib/eo
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@yahoo.com>2017-01-27 12:14:42 +0200
committerDaniel Zaoui <daniel.zaoui@yahoo.com>2017-06-05 08:55:38 +0300
commit3107e0d3eb4c4ee0e59873651c0b98f328c0a0ee (patch)
tree204c7cd575ec7b9715a58838ee28fc307f579272 /src/lib/eo
parent9e4708931121fb671cf9698311be8ea98f84c635 (diff)
Eo: add APIs to walk over classes and objects
These APIs are needed by Clouseau to get a list of classes and objects.
Diffstat (limited to 'src/lib/eo')
-rw-r--r--src/lib/eo/Eo.h27
-rw-r--r--src/lib/eo/eo.c121
2 files changed, 148 insertions, 0 deletions
diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h
index dd7ecabe1d..32c132edaa 100644
--- a/src/lib/eo/Eo.h
+++ b/src/lib/eo/Eo.h
@@ -1771,6 +1771,33 @@ efl_replace(Eo **storage, Eo *new_obj)
1771#include "efl_future.h" 1771#include "efl_future.h"
1772 1772
1773/** 1773/**
1774 * @addtogroup Eo_Iterators Eo iterators
1775 * @{
1776 */
1777
1778/**
1779 * @brief Get an iterator on the Eo classes
1780 *
1781 * You can use this function to walk over the Eo classes.
1782 *
1783 * @return an iterator on success, NULL otherwise
1784 */
1785EAPI Eina_Iterator *eo_classes_iterator_new(void);
1786
1787/**
1788 * @brief Get an iterator on the Eo objects
1789 *
1790 * You can use this function to walk over the Eo objects.
1791 *
1792 * @return an iterator on success, NULL otherwise
1793 */
1794EAPI Eina_Iterator *eo_objects_iterator_new(void);
1795
1796/**
1797 * @}
1798 */
1799
1800/**
1774 * @} 1801 * @}
1775 */ 1802 */
1776 1803
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index d4c3b49bae..55f00e1006 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -2934,3 +2934,124 @@ _eo_log_obj_shutdown(void)
2934 eina_inarray_flush(&_eo_log_objs_no_debug); 2934 eina_inarray_flush(&_eo_log_objs_no_debug);
2935} 2935}
2936#endif 2936#endif
2937
2938typedef struct
2939{
2940 Eina_Iterator iterator;
2941 unsigned int cur_kl_id;
2942} _Eo_Classes_Iterator;
2943
2944static Eina_Bool
2945_eo_classes_iterator_next(Eina_Iterator *it, void **data)
2946{
2947 _Eo_Classes_Iterator *eo_it = (_Eo_Classes_Iterator *)it;
2948
2949 if (eo_it->cur_kl_id == _eo_classes_last_id) return EINA_FALSE;
2950 *data = _eo_class_id_get(_eo_classes[eo_it->cur_kl_id]);
2951 eo_it->cur_kl_id++;
2952 return EINA_TRUE;
2953}
2954
2955static void
2956_eo_classes_iterator_free(Eina_Iterator *it)
2957{
2958 EINA_MAGIC_SET(it, EINA_MAGIC_NONE);
2959 free(it);
2960}
2961
2962EAPI Eina_Iterator *
2963eo_classes_iterator_new(void)
2964{
2965 _Eo_Classes_Iterator *it;
2966
2967 it = calloc(1, sizeof (*it));
2968 if (!it) return NULL;
2969
2970 it->iterator.version = EINA_ITERATOR_VERSION;
2971 it->iterator.next = _eo_classes_iterator_next;
2972 it->iterator.free = _eo_classes_iterator_free;
2973 EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);
2974
2975 return (Eina_Iterator *)it;
2976}
2977
2978typedef struct
2979{
2980 Eina_Iterator iterator;
2981 Eo_Id_Table_Data *tdata;
2982 Table_Index mid_table_id;
2983 Table_Index table_id;
2984 Table_Index entry_id;
2985} _Eo_Objects_Iterator;
2986
2987static Eina_Bool
2988_eo_objects_iterator_next(Eina_Iterator *it, void **data)
2989{
2990 Table_Index mid_table_id, table_id, entry_id;
2991 Eo_Id_Table_Data *tdata;
2992 _Eo_Objects_Iterator *eo_it = (_Eo_Objects_Iterator *)it;
2993 if (!eo_it->tdata) return EINA_FALSE;
2994
2995 tdata = eo_it->tdata;
2996 mid_table_id = eo_it->mid_table_id;
2997 table_id = eo_it->table_id;
2998 entry_id = eo_it->entry_id;
2999 while (mid_table_id < MAX_MID_TABLE_ID)
3000 {
3001 if (tdata->eo_ids_tables[mid_table_id])
3002 {
3003 while (table_id < MAX_TABLE_ID)
3004 {
3005 if (TABLE_FROM_IDS)
3006 {
3007 while (entry_id < MAX_ENTRY_ID)
3008 {
3009 _Eo_Id_Entry *entry = &(TABLE_FROM_IDS->entries[entry_id]);
3010 if (entry->active)
3011 {
3012 Eo *obj = _eo_header_id_get((Eo_Header *) entry->ptr);
3013 *data = obj;
3014 eo_it->mid_table_id = mid_table_id;
3015 eo_it->table_id = table_id;
3016 eo_it->entry_id = entry_id + 1;
3017 return EINA_TRUE;
3018 }
3019 entry_id++;
3020 }
3021 entry_id = 0;
3022 }
3023 table_id++;
3024 }
3025 table_id = 0;
3026 }
3027 mid_table_id++;
3028 }
3029 return EINA_FALSE;
3030}
3031
3032static void
3033_eo_objects_iterator_free(Eina_Iterator *it)
3034{
3035 EINA_MAGIC_SET(it, EINA_MAGIC_NONE);
3036 free(it);
3037}
3038
3039EAPI Eina_Iterator *
3040eo_objects_iterator_new(void)
3041{
3042 _Eo_Objects_Iterator *it;
3043 Eo_Id_Table_Data *tdata = _eo_table_data_table_get(_eo_table_data_get(), EFL_ID_DOMAIN_MAIN);
3044
3045 if (!tdata) return NULL;
3046
3047 it = calloc(1, sizeof (*it));
3048 if (!it) return NULL;
3049
3050 it->tdata = tdata;
3051 it->iterator.version = EINA_ITERATOR_VERSION;
3052 it->iterator.next = _eo_objects_iterator_next;
3053 it->iterator.free = _eo_objects_iterator_free;
3054 EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);
3055
3056 return (Eina_Iterator *)it;
3057}