2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://www.tizenopensource.org/license
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.
19 #include <stdlib.h> /* malloc */
20 #include <string.h> /* strdup */
24 #include <livebox-service.h>
26 #include <provider_buffer.h>
33 #define EAPI __attribute__((visibility("default")))
35 #define FILE_SCHEMA "file://"
38 * \brief This function is defined by the data-provider-slave
40 extern const char *livebox_find_pkgname(const char *filename);
41 extern int livebox_request_update_by_id(const char *uri);
59 unsigned int last_idx;
61 struct dlist *block_list;
64 EAPI const int DONE = 0x00;
65 EAPI const int OUTPUT_UPDATED = 0x02;
66 EAPI const int USE_NET = 0x04;
68 EAPI const int NEED_TO_SCHEDULE = 0x01;
69 EAPI const int NEED_TO_CREATE = 0x01;
70 EAPI const int NEED_TO_DESTROY = 0x01;
71 EAPI const int NEED_TO_UPDATE = 0x01;
73 EAPI const int LB_SYS_EVENT_FONT_CHANGED = 0x01;
74 EAPI const int LB_SYS_EVENT_LANG_CHANGED = 0x02;
75 EAPI const int LB_SYS_EVENT_TIME_CHANGED = 0x04;
76 EAPI const int LB_SYS_EVENT_PAUSED = 0x0100;
77 EAPI const int LB_SYS_EVENT_RESUMED = 0x0200;
79 EAPI struct livebox_desc *livebox_desc_open(const char *filename, int for_pd)
81 struct livebox_desc *handle;
84 handle = calloc(1, sizeof(*handle));
86 ErrPrint("Error: %s\n", strerror(errno));
92 len = strlen(filename) + strlen(".desc") + 1;
93 new_fname = malloc(len);
95 ErrPrint("Error: %s\n", strerror(errno));
99 snprintf(new_fname, len, "%s.desc", filename);
101 new_fname = strdup(filename);
103 ErrPrint("Error: %s\n", strerror(errno));
109 DbgPrint("Open a new file: %s\n", new_fname);
110 handle->fp = fopen(new_fname, "w+t");
113 ErrPrint("Failed to open a file: %s\n", strerror(errno));
121 EAPI int livebox_desc_close(struct livebox_desc *handle)
130 DbgPrint("Close and flush\n");
131 dlist_foreach_safe(handle->block_list, l, n, block) {
132 handle->block_list = dlist_remove(handle->block_list, l);
135 fprintf(handle->fp, "{\n");
137 fprintf(handle->fp, "type=%s\n", block->type);
138 DbgPrint("type=%s\n", block->type);
142 fprintf(handle->fp, "part=%s\n", block->part);
143 DbgPrint("part=%s\n", block->part);
147 fprintf(handle->fp, "data=%s\n", block->data);
148 DbgPrint("data=%s\n", block->data);
152 fprintf(handle->fp, "option=%s\n", block->option);
153 DbgPrint("option=%s\n", block->option);
157 fprintf(handle->fp, "id=%s\n", block->id);
158 DbgPrint("id=%s\n", block->id);
161 if (block->target_id) {
162 fprintf(handle->fp, "target=%s\n", block->target_id);
163 DbgPrint("target=%s\n", block->target_id);
166 fprintf(handle->fp, "}\n");
174 free(block->target_id);
183 EAPI int livebox_desc_set_category(struct livebox_desc *handle, const char *id, const char *category)
187 if (!handle || !category)
190 block = calloc(1, sizeof(*block));
194 block->type = strdup(LB_DESC_TYPE_INFO);
200 block->part = strdup("category");
207 block->data = strdup(category);
216 block->id = strdup(id);
226 block->idx = handle->last_idx++;
227 handle->block_list = dlist_append(handle->block_list, block);
231 EAPI int livebox_desc_set_size(struct livebox_desc *handle, const char *id, int w, int h)
239 block = calloc(1, sizeof(*block));
243 block->type = strdup(LB_DESC_TYPE_INFO);
249 block->part = strdup("size");
257 block->id = strdup(id);
266 snprintf(buffer, sizeof(buffer), "%dx%d", w, h);
267 block->data = strdup(buffer);
275 block->idx = handle->last_idx++;
276 handle->block_list = dlist_append(handle->block_list, block);
280 EAPI char *livebox_util_nl2br(const char *str)
294 ret = malloc(len + 1);
307 tmp = realloc(ret, len + 1);
334 EAPI int livebox_desc_set_id(struct livebox_desc *handle, int idx, const char *id)
339 dlist_foreach(handle->block_list, l, block) {
340 if (block->idx == idx) {
341 if (strcasecmp(block->type, LB_DESC_TYPE_SCRIPT)) {
342 ErrPrint("Invalid block is used\n");
346 free(block->target_id);
347 block->target_id = NULL;
349 if (!id || !strlen(id))
352 block->target_id = strdup(id);
353 if (!block->target_id) {
354 ErrPrint("Heap: %s\n", strerror(errno));
368 EAPI int livebox_desc_add_block(struct livebox_desc *handle, const char *id, const char *type, const char *part, const char *data, const char *option)
372 if (!handle || !type)
381 block = calloc(1, sizeof(*block));
385 block->type = strdup(type);
391 block->part = strdup(part);
398 block->data = strdup(data);
407 block->option = strdup(option);
408 if (!block->option) {
418 block->id = strdup(id);
429 block->idx = handle->last_idx++;
430 handle->block_list = dlist_append(handle->block_list, block);
434 EAPI int livebox_desc_del_block(struct livebox_desc *handle, int idx)
439 dlist_foreach(handle->block_list, l, block) {
440 if (block->idx == idx) {
441 handle->block_list = dlist_remove(handle->block_list, l);
447 free(block->target_id);
456 EAPI struct livebox_buffer *livebox_acquire_buffer(const char *filename, int is_pd, int width, int height, int (*handler)(struct livebox_buffer *, enum buffer_event, double, double, double, void *), void *data)
459 struct livebox_buffer *handle;
463 if (!filename || !width || !height) {
464 ErrPrint("Invalid argument: %p(%dx%d)\n", filename, width, height);
468 uri_len = strlen(filename) + strlen(FILE_SCHEMA) + 1;
469 uri = malloc(uri_len);
471 ErrPrint("Heap: %s\n", strerror(errno));
475 snprintf(uri, uri_len, FILE_SCHEMA "%s", filename);
476 pkgname = livebox_find_pkgname(uri);
478 ErrPrint("Invalid Request\n");
483 handle = provider_buffer_acquire((!!is_pd) ? TYPE_PD : TYPE_LB, pkgname, uri, width, height, sizeof(int), handler, data);
484 DbgPrint("Acquire buffer for PD(%s), %s, %p\n", pkgname, uri, handle);
489 EAPI int livebox_request_update(const char *filename)
496 ErrPrint("Invalid argument\n");
500 uri_len = strlen(filename) + strlen(FILE_SCHEMA) + 1;
501 uri = malloc(uri_len);
503 ErrPrint("Heap: %s\n", strerror(errno));
507 snprintf(uri, uri_len, FILE_SCHEMA "%s", filename);
508 ret = livebox_request_update_by_id(uri);
513 EAPI unsigned long livebox_pixmap_id(struct livebox_buffer *handle)
515 return provider_buffer_pixmap_id(handle);
518 EAPI int livebox_release_buffer(struct livebox_buffer *handle)
523 DbgPrint("Release buffer\n");
524 return provider_buffer_release(handle);
527 EAPI void *livebox_ref_buffer(struct livebox_buffer *handle)
532 DbgPrint("Ref buffer\n");
533 return provider_buffer_ref(handle);
536 EAPI int livebox_unref_buffer(void *buffer)
541 DbgPrint("Unref buffer\n");
542 return provider_buffer_unref(buffer);
545 EAPI int livebox_sync_buffer(struct livebox_buffer *handle)
553 pkgname = provider_buffer_pkgname(handle);
554 id = provider_buffer_id(handle);
555 if (!pkgname || !id) {
556 ErrPrint("Invalid buffer handler\n");
560 DbgPrint("Sync buffer\n");
561 provider_buffer_sync(handle);
562 provider_send_desc_updated(pkgname, id, NULL);