summaryrefslogtreecommitdiff
path: root/src/lib/emodel/Emodel.h
blob: 43c0b9c9b9ec634d1ce8ca8f1c5e008724883722 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
    @brief Emodel Library Public API Calls
    These routines are used for MVC (Model View Controller) Library interaction.
 */
/**
 * @page emodel_main Emodel
 *
 * @date 2014 (created)
 * @section toc Table of Contents
 *
 * @li @ref emodel_main_intro
 * @li @ref emodel_main_intro_example
 *
 * @section emodel_main_intro Introduction
 *
 * The Emodel(model) generic object system for Emodel View Controller.
 *
 * @section emodel_main_work How does Emodel work?
 *
 * The Model notifies Views and Controllers when there is a change in its state.
 * The other way around is also true and the Model can be passive and be poolled
 * for update rather than generating output representations.
 *
 * Concrete objects can implement functionalities by overriding Emodel's API, abstracting its complexities from
 * applications that can keep focus on higher level implementation.
 *
 * Examples of concrete implementations that can make use Emodel:
 *
 * Filesystem and I/O operations;
 * Database management;
 * GUI forms, lists and trees.
 *
 * Application code tends to be small in number of lines,
 * more simple and code readability is improved.
 *
 * Emodel use EO Events. Views and Controllers must register
 * in events to be able to recieve notifications about state changes in Emodel.
 * Some of currently available events are:
 *
 *   EMODEL_EVENT_LOAD_STATUS
 *   EMODEL_EVENT_PROPERTIES_CHANGED
 *   EMODEL_EVENT_CHILD_ADDED
 *   EMODEL_EVENT_CHILD_REMOVED
 *   EMODEL_EVENT_CHILDREN_COUNT_CHANGED
 *
 *   Example code using Emodel_Eio that returns the number of files in '/tmp' directory:
 *
 *   @code
 * static Eina_Bool
 * _children_count_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
 * {
 *    size_t *len = event_info;
 *    fprintf(stdout, "Children count len=%lu\n", *len);
 *    return EINA_TRUE;
 * }
 *
 * int
 * main(int argc, const char **argv)
 * {
 *    size_t total;
 *    Eo *model;
 *    if(!ecore_init())
 *    {
 *       fprintf(stderr, "ERROR: Cannot init Ecore!\n");
 *       return 1;
 *    }
 *    if(!eio_init())
 *    {
 *       fprintf(stderr, "ERROR: Cannot init Eio!\n");
 *       return 1;
 *    }
 *
 *    model = eo_add_custom(EIO_MODEL_CLASS, NULL, eio_model_constructor("/tmp"));
 *    eo_do(model, eo_event_callback_add(EMODEL_EVENT_CHILDREN_COUNT_CHANGED, _children_count_cb, NULL));
 *    eo_do(model, emodel_children_count_get(&total));
 *    fprintf(stdout, "total=%lu\n", total);
 *
 *    ecore_main_loop_begin();
 *    eo_unref(model);
 *    eio_shutdown();
 *    ecore_shutdown();
 *    return 0;
 * }
 *   @endcode
 *
 *   In previous example the concrete Emodel_Eio counts, asynchronously, the number of files in given directory,
 *   emodel_children_count_get() returns into 'total' pointer the last known number of children. In the meantime
 *   when background count is finished _children_count_cb() is invoked receiving the number of files as event_info data.
 *   This is achieved by registering the Model as EMODEL_EVENT_CHILDREN_COUNT_CHANGED event listener and every time
 *   the count (number of children) changes, the event is disptached to listeners.
 *
 *   The principles may remain the same for different events and the logic remains.
 *
 * @li @ref emodel_main_intro_example
 *
 * @include emodel_test_file.c
 *
 * Recommended reading:
 *
 * @li @ref Eo, where you'll understand how Eo Events work.
 * @li @ref Eio, where you'll find EFL Eio implementation and interfaces.
 * @li @ref Emodel_Eio, the concrete EIO implementation using both Emodel and Eio.
 * @li @ref Ecore, You'll get more information about I/O filesystem events.
 *
 * @defgroup Emodel
 *
 * @addtogroup Emodel
 * @{
 */

#ifndef _EMODEL_H
#define _EMODEL_H

#include <Efl_Config.h>
#include <Eo.h>
#include <Emodel_Common.h>

#ifdef __cplusplus
extern "C" {
#endif

#include <emodel.eo.h>

#ifdef __cplusplus
}
#endif
#endif //_EMODEL_H