Update License
[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         module = CModule::Load(pkgname);
40         if (!module)
41                 return LB_STATUS_ERROR_FAULT;
42
43         return LB_STATUS_SUCCESS;
44 }
45
46 EAPI int livebox_finalize(const char *pkgname)
47 {
48         CModule *module;
49
50         module = CModule::FindModule(pkgname);
51         if (!module)
52                 return LB_STATUS_ERROR_NOT_EXIST;
53
54         module->Unload();
55         return LB_STATUS_SUCCESS;
56 }
57
58 EAPI int livebox_create(const char *pkgname, const char *filename, const char *content, const char *cluster, const char *category)
59 {
60         CLiveBoxImpl *box;
61         CModule *module;
62         int ret;
63
64         module = CModule::FindModule(pkgname);
65         if (!module)
66                 return LB_STATUS_ERROR_INVALID;
67
68         box = module->FindLiveBox(filename);
69         if (box)
70                 return LB_STATUS_ERROR_NOT_EXIST;
71
72         ret = module->Create(filename, content, cluster, category);
73         return ret;
74 }
75
76 EAPI int livebox_destroy(const char *pkgname, const char *filename)
77 {
78         CModule *module;
79         CLiveBoxImpl *box;
80         int ret;
81
82         module = CModule::FindModule(pkgname);
83         if (!module)
84                 return LB_STATUS_ERROR_INVALID;
85
86         box = module->FindLiveBox(filename);
87         if (!box)
88                 return LB_STATUS_ERROR_NOT_EXIST;
89
90         ret = module->Destroy(box);
91         return ret;
92 }
93
94 EAPI int livebox_need_to_update(const char *pkgname, const char *filename)
95 {
96         CLiveBoxImpl *box;
97         CModule *module;
98
99         module = CModule::FindModule(pkgname);
100         if (!module)
101                 return LB_STATUS_ERROR_INVALID;
102
103         box = module->FindLiveBox(filename);
104         if (!box)
105                 return LB_STATUS_ERROR_NOT_EXIST;
106
107         return box->NeedToUpdate();
108 }
109
110 EAPI int livebox_need_to_destroy(const char *pkgname, const char *filename)
111 {
112         CLiveBoxImpl *box;
113         CModule *module;
114
115         module = CModule::FindModule(pkgname);
116         if (!module)
117                 return LB_STATUS_ERROR_INVALID;
118
119         box = module->FindLiveBox(filename);
120         if (!box)
121                 return LB_STATUS_ERROR_NOT_EXIST;
122         
123         return box->NeedToDestroy();
124 }
125
126 EAPI int livebox_update_content(const char *pkgname, const char *filename)
127 {
128         CLiveBoxImpl *box;
129         CModule *module;
130
131         module = CModule::FindModule(pkgname);
132         if (!module)
133                 return LB_STATUS_ERROR_INVALID;
134
135         box = module->FindLiveBox(filename);
136         if (!box)
137                 return LB_STATUS_ERROR_NOT_EXIST;
138         
139         return box->UpdateContent();
140 }
141
142 EAPI int livebox_clicked(const char *pkgname, const char *filename, const char *event, double timestamp, double x, double y)
143 {
144         CLiveBoxImpl *box;
145         CModule *module;
146
147         module = CModule::FindModule(pkgname);
148         if (!module)
149                 return LB_STATUS_ERROR_INVALID;
150
151         box = module->FindLiveBox(filename);
152         if (!box)
153                 return LB_STATUS_ERROR_NOT_EXIST;
154
155         return box->Clicked(event, timestamp, x, y);
156 }
157
158 EAPI int livebox_content_event(const char *pkgname, const char *filename, const char *emission, const char *source, struct event_info *event_info)
159 {
160         CLiveBoxImpl *box;
161         CModule *module;
162
163         module = CModule::FindModule(pkgname);
164         if (!module)
165                 return LB_STATUS_ERROR_INVALID;
166
167         box = module->FindLiveBox(filename);
168         if (!box)
169                 return LB_STATUS_ERROR_NOT_EXIST;
170
171         return box->ContentEvent(emission, source, event_info);
172 }
173
174 EAPI int livebox_resize(const char *pkgname, const char *filename, int type)
175 {
176         CLiveBoxImpl *box;
177         CModule *module;
178
179         module = CModule::FindModule(pkgname);
180         if (!module)
181                 return LB_STATUS_ERROR_INVALID;
182
183         box = module->FindLiveBox(filename);
184         if (!box)
185                 return LB_STATUS_ERROR_NOT_EXIST;
186
187         return box->Resize(type);
188 }
189
190 EAPI int livebox_change_group(const char *pkgname, const char *filename, const char *cluster, const char *category)
191 {
192         CLiveBoxImpl *box;
193         CModule *module;
194
195         module = CModule::FindModule(pkgname);
196         if (!module)
197                 return LB_STATUS_ERROR_INVALID;
198
199         box = module->FindLiveBox(filename);
200         if (!box)
201                 return LB_STATUS_ERROR_NOT_EXIST;
202
203         return box->ChangeGroup(cluster, category);
204 }
205
206 EAPI int livebox_get_info(const char *pkgname, const char *filename, int *w, int *h, double *priority, char **content, char **title)
207 {
208         CLiveBoxImpl *box;
209         CModule *module;
210
211         module = CModule::FindModule(pkgname);
212         if (!module)
213                 return LB_STATUS_ERROR_INVALID;
214
215         box = module->FindLiveBox(filename);
216         if (!box)
217                 return LB_STATUS_ERROR_NOT_EXIST;
218
219         return box->GetInfo(w, h, priority, content, title);
220 }
221
222 EAPI int livebox_need_to_create(const char *pkgname, const char *cluster, const char *category)
223 {
224         CModule *module;
225
226         module = CModule::FindModule(pkgname);
227         if (!module)
228                 return LB_STATUS_ERROR_INVALID;
229
230         return module->NeedToCreate(cluster, category);
231 }
232
233 EAPI char *livebox_pinup(const char *pkgname, const char *filename, int pinup)
234 {
235         CLiveBoxImpl *box;
236         CModule *module;
237
238         module = CModule::FindModule(pkgname);
239         if (!module)
240                 return NULL;
241
242         box = module->FindLiveBox(filename);
243         if (!box)
244                 return NULL;
245
246         return box->PinUp(pinup);
247 }
248
249 EAPI int livebox_is_pinned_up(const char *pkgname, const char *filename)
250 {
251         CLiveBoxImpl *box;
252         CModule *module;
253
254         module = CModule::FindModule(pkgname);
255         if (!module)
256                 return NULL;
257
258         box = module->FindLiveBox(filename);
259         if (!box)
260                 return NULL;
261
262         return box->IsPinnedUp();
263 }
264
265 EAPI int livebox_system_event(const char *pkgname, const char *filename, int event)
266 {
267         CLiveBoxImpl *box;
268         CModule *module;
269
270         module = CModule::FindModule(pkgname);
271         if (!module)
272                 return NULL;
273
274         box = module->FindLiveBox(filename);
275         if (!box)
276                 return NULL;
277
278         return box->SystemEvent(event);
279 }
280
281 /* End of a file */