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