renew pui prototype
[platform/core/uifw/libpui.git] / backends / default_backend.c
1 #include <PUI.h>
2 #include <PUI_backend.h>
3
4 pui_backend_ani_func *ani_func = NULL;
5
6 enum
7 {
8         None,
9         Linear,
10         EaseInSine,
11         EaseOutSine,
12         EaseInQuart,
13         EaseOutQuart
14 } pui_effect_func;
15
16 typedef struct _default_ani_data default_ani_data;
17 struct _default_ani_data
18 {
19         pui_id id;
20         pui_ani_status status;
21         pui_ani_control_buffer *buffer;
22         unsigned int repeat;
23
24         unsigned int key_frame_idx;
25         unsigned int num_key_frames;
26         double interval;
27         pui_effect_func effect_func;
28
29         Eina_Bool (*frame_cb)(void *data);
30
31 /*
32         void *frame_cb_data;
33         double expire;
34         Ecore_Timer *frame_cb_timer;
35 */
36 };
37
38 static void
39 _start_frame(pui_ani_mgr *ani_mgr)
40 {
41         //TODO
42 }
43
44 static Eina_Bool
45 _frame_cb(void *data)
46 {
47         //TODO
48         //_get_next_frame();
49         //pui_backend_ani_get_buffer();
50         //pui_backend_ani_update();
51 }
52
53 pui_int_error
54 get_ani_data_from_collection(default_ani_data *data, pui_id id)
55 {
56         pui_int_error e = PUI_INT_ERROR_NONE;
57
58         //TODO
59         //ex> data->id = id;
60         //ex> data->interval = 30;
61
62         return e;
63 }
64
65 pui_backend_ani_data *
66 _ani_create(pui_ani_mgr *ani_mgr, pui_id id)
67 {
68         pui_int_error e = PUI_INT_ERROR_NONE; 
69         default_ani_data *data = (default_ani_data *)calloc(1, sizeof(default_ani_data));
70
71         if (!data)
72         {
73                 pui_err("Failed to allocate memory !\n");
74                 return NULL;
75         }
76
77         e = get_ani_data_from_collection(data, id);
78
79         if (PUI_INT_ERROR_NONE != e)
80         {
81                 pui_err("Failed to get ani data from collection !\n");
82                 goto err;
83         }
84         
85         return (pui_backend_ani_data *)default_ani_data;
86
87 err:
88         if (data)
89                 free(data);
90
91         return NULL;
92 }
93
94 pui_error
95 _ani_start(pui_ani_mgr *ani_mgr, int repeat)
96 {
97         pui_int_error e = PUI_INT_ERROR_NONE;
98
99         default_ani_data *data = (default_ani_data *)ani_mgr->ani_data;
100
101         //TODO
102         //start_frame(ani_mgr);
103         //pui_backend_ani_add_frame_cb(data->frame_cb);
104
105         return e;
106 }
107
108 pui_error
109 _ani_stop(pui_ani_mgr *ani_mgr)
110 {
111         pui_int_error e = PUI_INT_ERROR_NONE;
112
113         default_ani_data *data = (default_ani_data *)ani_mgr->ani_data;
114
115         //TODO
116         //pui_backend_ani_remove_frame_cb(data->frame_cb);
117
118         return e;
119 }
120
121 pui_int_error
122 _create_ani_collection(void)
123 {
124         pui_int_error e = PUI_INT_ERROR_NONE;
125
126         //TODO
127
128         return e;
129 }
130
131 pui_int_error
132 _is_ani_supported(pui_id id)
133 {
134         pui_int_error e = PUI_INT_ERROR_NONE;
135
136         //TODO
137         /* if the given id is not supported, return PUI_INT_ERROR_ID_NOT_SUPPORTED. */
138
139         return e;
140 }
141
142 pui_backend_ani_func *
143 _get_ani_func(pui_id id)
144 {
145         if (ani_func)
146                 return ani_func;
147
148         ani_func = pui_backend_ani_alloc_ani_func();
149
150         if (!ani_func)
151         {
152                 pui_err("Failed to allocate memory !\n");
153                 return NULL;
154         }
155
156         /* Assign each function pointer that corresponds to the given id */
157         ani_func->ani_create = _ani_create;
158         ani_func->ani_start = _ani_start;
159         ani_func->ani_stop = _ani_stop;
160
161         ani_func->reserved1 = NULL;
162         ani_func->reserved2 = NULL;
163         ani_func->reserved3 = NULL;
164         ani_func->reserved4 = NULL;
165         ani_func->reserved5 = NULL;
166         ani_func->reserved6 = NULL;
167         ani_func->reserved7 = NULL;
168         ani_func->reserved8 = NULL;
169         ani_func->reserved9 = NULL;
170         ani_func->reserved10 = NULL;
171
172         return ani_func;
173 }
174
175 static pui_backend_module_data *
176 pui_default_backend_init(void)
177 {
178         pui_backend_module_data *backend_data = NULL;
179
180         backend_data = (pui_backend_module_data *)calloc(1, sizeof(pui_backend_module_data));
181
182         if (!backend_data)
183         {
184                 pui_err("Failed to allocate memory for pui backend module data !\n");
185                 return NULL;
186         }
187
188         /* Allocate backend specific data if needed. Now it will be empty. */
189         backend_data->data = NULL;
190
191         backend_data->create_ani_collection = _create_ani_collection;
192         backend_data->is_ani_supported = _is_ani_supported;
193         backend_data->get_ani_func = _get_ani_func;
194
195         return backend_data;
196
197 err:
198         if (backend_data)
199         {
200                 if (backend_data->data)
201                 {
202                         free(backend_data->data);
203                 }
204
205                 free(backend_data);
206         }
207
208         return NULL;
209 }
210
211 static void
212 pui_default_backend_deinit(pui_backend_module_data *backend_data)
213 {
214         if (!backend_data)
215                 return;
216
217         if (backend_data->data)
218         {
219                 //TODO : free variables of backend_data
220
221                 free(backend_data->data);
222         }
223
224         if (backend_data->get_ani_func && ani_func)
225         {
226                 pui_backend_ani_free_ani_func(ani_func);
227                 ani_func = NULL;
228         }
229
230         backend_data->get_ani_func = NULL;
231         backend_data->create_ani_collection = NULL;
232         backend_data->is_ani_supported = NULL;
233
234         free(backend_data);
235         backend_data = NULL;
236 }
237
238 pui_backend_module pui_backend_module_info = {
239         "tizen_ref_speaker",
240         "Samsung",
241         PUI_BACKEND_SET_ABI_VERSION(1, 0),
242         pui_default_backend_init,
243         pui_default_backend_deinit
244 };
245