Update coding convention
[platform/framework/web/livebox-cpp.git] / src / livebox.cpp
1 /*
2  * Copyright 2013  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <errno.h>
19
20 #include <dlog.h>
21 #include <livebox.h>
22 #include <livebox-errno.h>
23
24 #include "livebox-cpp.h"
25 #include "livebox-impl.h"
26 #include "CModule.h"
27 #include "c-abi.h"
28
29 #define EAPI __attribute__((visibility("default")))
30
31 EAPI int livebox_initialize(const char *pkgname)
32 {
33         CModule *module;
34
35         module = CModule::FindModule(pkgname);
36         if (module) {
37                 return LB_STATUS_SUCCESS;
38         }
39
40         module = CModule::Load(pkgname);
41         if (!module) {
42                 return LB_STATUS_ERROR_FAULT;
43         }
44
45         return LB_STATUS_SUCCESS;
46 }
47
48 EAPI int livebox_finalize(const char *pkgname)
49 {
50         CModule *module;
51
52         module = CModule::FindModule(pkgname);
53         if (!module) {
54                 return LB_STATUS_ERROR_NOT_EXIST;
55         }
56
57         module->Unload();
58         return LB_STATUS_SUCCESS;
59 }
60
61 EAPI int livebox_create(const char *pkgname, const char *id, const char *content, const char *cluster, const char *category)
62 {
63         CLiveBoxImpl *box;
64         CModule *module;
65         int ret;
66
67         module = CModule::FindModule(pkgname);
68         if (!module) {
69                 return LB_STATUS_ERROR_INVALID;
70         }
71
72         box = module->FindLiveBox(id);
73         if (box) {
74                 return LB_STATUS_ERROR_NOT_EXIST;
75         }
76
77         ret = module->Create(id, content, cluster, category);
78         return ret;
79 }
80
81 EAPI int livebox_destroy(const char *pkgname, const char *id)
82 {
83         CModule *module;
84         CLiveBoxImpl *box;
85         int ret;
86
87         module = CModule::FindModule(pkgname);
88         if (!module) {
89                 return LB_STATUS_ERROR_INVALID;
90         }
91
92         box = module->FindLiveBox(id);
93         if (!box) {
94                 return LB_STATUS_ERROR_NOT_EXIST;
95         }
96
97         ret = module->Destroy(box);
98         return ret;
99 }
100
101 EAPI int livebox_need_to_update(const char *pkgname, const char *id)
102 {
103         CLiveBoxImpl *box;
104         CModule *module;
105
106         module = CModule::FindModule(pkgname);
107         if (!module) {
108                 return LB_STATUS_ERROR_INVALID;
109         }
110
111         box = module->FindLiveBox(id);
112         if (!box) {
113                 return LB_STATUS_ERROR_NOT_EXIST;
114         }
115
116         return box->NeedToUpdate();
117 }
118
119 EAPI int livebox_need_to_destroy(const char *pkgname, const char *id)
120 {
121         CLiveBoxImpl *box;
122         CModule *module;
123
124         module = CModule::FindModule(pkgname);
125         if (!module) {
126                 return LB_STATUS_ERROR_INVALID;
127         }
128
129         box = module->FindLiveBox(id);
130         if (!box) {
131                 return LB_STATUS_ERROR_NOT_EXIST;
132         }
133         
134         return box->NeedToDestroy();
135 }
136
137 EAPI int livebox_update_content(const char *pkgname, const char *id)
138 {
139         CLiveBoxImpl *box;
140         CModule *module;
141
142         module = CModule::FindModule(pkgname);
143         if (!module) {
144                 return LB_STATUS_ERROR_INVALID;
145         }
146
147         box = module->FindLiveBox(id);
148         if (!box) {
149                 return LB_STATUS_ERROR_NOT_EXIST;
150         }
151         
152         return box->UpdateContent();
153 }
154
155 EAPI int livebox_clicked(const char *pkgname, const char *id, const char *event, double timestamp, double x, double y)
156 {
157         CLiveBoxImpl *box;
158         CModule *module;
159
160         module = CModule::FindModule(pkgname);
161         if (!module) {
162                 return LB_STATUS_ERROR_INVALID;
163         }
164
165         box = module->FindLiveBox(id);
166         if (!box) {
167                 return LB_STATUS_ERROR_NOT_EXIST;
168         }
169
170         return box->Clicked(event, timestamp, x, y);
171 }
172
173 EAPI int livebox_content_event(const char *pkgname, const char *id, const char *emission, const char *source, struct event_info *event_info)
174 {
175         CLiveBoxImpl *box;
176         CModule *module;
177
178         module = CModule::FindModule(pkgname);
179         if (!module) {
180                 return LB_STATUS_ERROR_INVALID;
181         }
182
183         box = module->FindLiveBox(id);
184         if (!box) {
185                 return LB_STATUS_ERROR_NOT_EXIST;
186         }
187
188         return box->ContentEvent(emission, source, event_info);
189 }
190
191 EAPI int livebox_resize(const char *pkgname, const char *id, int type)
192 {
193         CLiveBoxImpl *box;
194         CModule *module;
195
196         module = CModule::FindModule(pkgname);
197         if (!module) {
198                 return LB_STATUS_ERROR_INVALID;
199         }
200
201         box = module->FindLiveBox(id);
202         if (!box) {
203                 return LB_STATUS_ERROR_NOT_EXIST;
204         }
205
206         return box->Resize(type);
207 }
208
209 EAPI int livebox_change_group(const char *pkgname, const char *id, const char *cluster, const char *category)
210 {
211         CLiveBoxImpl *box;
212         CModule *module;
213
214         module = CModule::FindModule(pkgname);
215         if (!module) {
216                 return LB_STATUS_ERROR_INVALID;
217         }
218
219         box = module->FindLiveBox(id);
220         if (!box) {
221                 return LB_STATUS_ERROR_NOT_EXIST;
222         }
223
224         return box->ChangeGroup(cluster, category);
225 }
226
227 EAPI int livebox_get_info(const char *pkgname, const char *id, int *w, int *h, double *priority, char **content, char **title)
228 {
229         CLiveBoxImpl *box;
230         CModule *module;
231
232         module = CModule::FindModule(pkgname);
233         if (!module) {
234                 return LB_STATUS_ERROR_INVALID;
235         }
236
237         box = module->FindLiveBox(id);
238         if (!box) {
239                 return LB_STATUS_ERROR_NOT_EXIST;
240         }
241
242         return box->GetInfo(w, h, priority, content, title);
243 }
244
245 EAPI int livebox_need_to_create(const char *pkgname, const char *cluster, const char *category)
246 {
247         CModule *module;
248
249         module = CModule::FindModule(pkgname);
250         if (!module) {
251                 return LB_STATUS_ERROR_INVALID;
252         }
253
254         return module->NeedToCreate(cluster, category);
255 }
256
257 EAPI char *livebox_pinup(const char *pkgname, const char *id, int pinup)
258 {
259         CLiveBoxImpl *box;
260         CModule *module;
261
262         module = CModule::FindModule(pkgname);
263         if (!module) {
264                 return NULL;
265         }
266
267         box = module->FindLiveBox(id);
268         if (!box) {
269                 return NULL;
270         }
271
272         return box->PinUp(pinup);
273 }
274
275 EAPI int livebox_is_pinned_up(const char *pkgname, const char *id)
276 {
277         CLiveBoxImpl *box;
278         CModule *module;
279
280         module = CModule::FindModule(pkgname);
281         if (!module) {
282                 return NULL;
283         }
284
285         box = module->FindLiveBox(id);
286         if (!box) {
287                 return NULL;
288         }
289
290         return box->IsPinnedUp();
291 }
292
293 EAPI int livebox_system_event(const char *pkgname, const char *id, int event)
294 {
295         CLiveBoxImpl *box;
296         CModule *module;
297
298         module = CModule::FindModule(pkgname);
299         if (!module) {
300                 return NULL;
301         }
302
303         box = module->FindLiveBox(id);
304         if (!box) {
305                 return NULL;
306         }
307
308         return box->SystemEvent(event);
309 }
310
311 /* End of a file */