ab13717e3387c29f6849ed7a64263fabd87f9105
[platform/core/uifw/libpui.git] / backends / default_backend.c
1 //#include <PUI.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <PUI_backend.h>
5
6 typedef enum
7 {
8         None,
9         Linear,
10         EaseInSine,
11         EaseOutSine,
12         EaseInQuart,
13         EaseOutQuart
14 } pui_effect_func;
15
16 typedef struct _default_ani_info default_ani_info;
17 struct _default_ani_info
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
30 pui_backend_ani_data *g_ani_data = NULL;
31
32 static pui_bool
33 _frame_cb(void *data, int serial)
34 {
35         pui_ani_t *ani = (pui_ani_t *)data;
36
37         //TODO
38         (void) ani;
39         //_get_next_frame();
40         //pui_backend_ani_get_buffer();
41         //pui_backend_ani_update();
42
43         return (pui_bool)1;
44 }
45
46 pui_int_error
47 get_ani_info_from_ani_collection(default_ani_info *info, pui_id id)
48 {
49         pui_int_error e = PUI_INT_ERROR_NONE;
50
51         //TODO
52         //ex> data->id = id;
53         //ex> data->interval = 30;
54
55         return e;
56 }
57
58 pui_error
59 _ani_start(pui_ani_t *ani, int repeat)
60 {
61         pui_int_error e = PUI_INT_ERROR_NONE;
62         pui_backend_ani_data *ani_data = NULL;
63
64         ani_data = pui_backend_ani_get_ani_data(ani);
65         default_ani_info *info = (default_ani_info *)ani_data->ani_info;
66
67         //TODO
68         (void) info;
69
70         pui_backend_ani_status_update(ani, PUI_ANI_STATUS_STARTED);
71         pui_backend_ani_add_frame_cb(ani, _frame_cb, 0.1);
72
73         return e;
74 }
75
76 pui_error
77 _ani_stop(pui_ani_t *ani)
78 {
79         pui_int_error e = PUI_INT_ERROR_NONE;
80         pui_backend_ani_data *ani_data = NULL;
81
82         ani_data = pui_backend_ani_get_ani_data(ani);
83         default_ani_info *info = (default_ani_info *)ani_data->ani_info;
84
85         //TODO
86         (void) info;
87
88         pui_backend_ani_remove_frame_cb(ani);
89         pui_backend_ani_status_update(ani, PUI_ANI_STATUS_STOPPED);
90
91         return e;
92 }
93
94 pui_int_error
95 _create_ani_collection(void)
96 {
97         pui_int_error e = PUI_INT_ERROR_NONE;
98
99         //TODO
100
101         return e;
102 }
103
104 pui_int_error
105 _is_ani_supported(pui_id id)
106 {
107         pui_int_error e = PUI_INT_ERROR_NONE;
108
109         //TODO
110         /* if the given id is not supported, return PUI_INT_ERROR_ID_NOT_SUPPORTED. */
111
112         return e;
113 }
114
115 pui_backend_ani_data *
116 _ani_create(pui_id id)
117 {
118         pui_int_error e = PUI_INT_ERROR_NONE;
119
120         pui_backend_ani_data *ani_data = NULL;
121         pui_backend_ani_func *ani_func = NULL;
122
123         /* backend's animation specific info */
124         default_ani_info *ani_info = NULL;
125
126         //TODO : return NULL if the animation correspond to the given id dones't exist.
127
128         /* allocation of the structure of function pointers that will be called from pui_ani_control() */
129         ani_func = pui_backend_ani_alloc_ani_func();
130
131         if (!ani_func)
132         {
133                 pui_err("Failed to allocate memory ! (pui backend ani func)\n");
134                 return NULL;
135         }
136
137         /* Assign each function pointer that corresponds to the given id if needed. */
138         ani_func->ani_start = _ani_start;
139         ani_func->ani_stop = _ani_stop;
140
141         ani_func->reserved1 = NULL;
142         ani_func->reserved2 = NULL;
143         ani_func->reserved3 = NULL;
144         ani_func->reserved4 = NULL;
145         ani_func->reserved5 = NULL;
146         ani_func->reserved6 = NULL;
147         ani_func->reserved7 = NULL;
148         ani_func->reserved8 = NULL;
149         ani_func->reserved9 = NULL;
150         ani_func->reserved10 = NULL;
151
152         /* backend's animation specific info */
153         ani_info = (default_ani_info *)calloc(1, sizeof(default_ani_info));
154
155         if (!ani_info)
156         {
157                 pui_err("Failed to allocate memory ! (backend's ani specific info)\n");
158                 goto err;
159         }
160
161         /* fill animation info associate with the given id from animation collection */
162         e = get_ani_info_from_ani_collection(ani_info, id);
163         
164         if (PUI_INT_ERROR_NONE != e)
165         {
166                 pui_err("Failed to get ani info from animation collection !\n");
167                 goto err;
168         }
169
170         /* allocate backend ani_data and return it to pui ani core */
171         ani_data = (pui_backend_ani_data *)calloc(1, sizeof(pui_backend_ani_data));
172         
173         if (!ani_data)
174         {
175                 pui_err("Failed to allocate memory for pui backend ani data !\n");
176                 goto err;
177         }
178         
179         ani_data->ani_func = ani_func;
180         ani_data->ani_info = (pui_backend_ani_info *)ani_info;
181
182         g_ani_data = ani_data;
183
184         return ani_data;
185
186 err:
187         if (ani_func)
188         {
189                 pui_backend_ani_free_ani_func(ani_func);
190                 ani_func = NULL;
191         }
192
193         if (ani_info)
194         {
195                 //TODO : free if anything needs to be done with ani_info
196
197                 free(ani_info);
198         }
199
200         return NULL;
201 }
202
203 void
204 _ani_destroy(pui_backend_ani_data *ani_data)
205 {
206         if (!ani_data)
207                 return;
208
209         pui_backend_ani_free_ani_func(ani_data->ani_func);
210
211         //TODO : free if anything needs to be done with ani_info
212         free(ani_data->ani_info);
213
214         ani_data->ani_func = NULL;
215         ani_data->ani_info = NULL;
216
217         g_ani_data = NULL;
218 }
219
220 static pui_backend_module_data *
221 pui_default_backend_init(void)
222 {
223         pui_backend_module_data *backend_data = NULL;
224
225         backend_data = (pui_backend_module_data *)calloc(1, sizeof(pui_backend_module_data));
226
227         if (!backend_data)
228         {
229                 pui_err("Failed to allocate memory for pui backend module data !\n");
230                 return NULL;
231         }
232
233         backend_data->create_ani_collection = _create_ani_collection;
234         backend_data->ani_create = _ani_create;
235         backend_data->ani_destroy = _ani_destroy;
236
237         /* Allocate backend specific data if needed. Now it will be empty. */
238         backend_data->data = NULL;
239
240         return backend_data;
241 }
242
243 static void
244 pui_default_backend_deinit(pui_backend_module_data *backend_data)
245 {
246         if (!backend_data)
247                 return;
248
249         if (backend_data->data)
250         {
251                 //TODO : free variables of backend_data
252
253                 free(backend_data->data);
254         }
255
256         if (g_ani_data)
257         {
258                 if (g_ani_data->ani_func)
259                 {
260                         pui_backend_ani_free_ani_func(g_ani_data->ani_func);
261                         g_ani_data->ani_func = NULL;
262                 }
263
264                 if (g_ani_data->ani_info)
265                 {
266                         //TODO : free if anything needs to be done with ani_info
267                         free(g_ani_data->ani_info);
268                         g_ani_data->ani_info = NULL;
269                 }
270         }
271
272         backend_data->create_ani_collection = NULL;
273         backend_data->ani_create = NULL;
274         backend_data->ani_destroy = NULL;
275
276         free(backend_data);
277         backend_data = NULL;
278 }
279
280 pui_backend_module pui_backend_module_info = {
281         "Tizen Reference Speaker Backend",
282         "Samsung",
283         PUI_BACKEND_SET_ABI_VERSION(1, 0),
284         pui_default_backend_init,
285         pui_default_backend_deinit
286 };
287