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")))
36 * \brief This function is defined by the data-provider-slave
38 extern const char *livebox_find_pkgname(const char *filename);
56 unsigned int last_idx;
58 struct dlist *block_list;
61 EAPI const int DONE = 0x00;
62 EAPI const int NEED_TO_SCHEDULE = 0x01;
63 EAPI const int OUTPUT_UPDATED = 0x02;
64 EAPI const int NEED_TO_CREATE = 0x01;
65 EAPI const int NEED_TO_DESTROY = 0x01;
66 EAPI const int LB_SYS_EVENT_FONT_CHANGED = 0x01;
67 EAPI const int LB_SYS_EVENT_LANG_CHANGED = 0x02;
68 EAPI const int LB_SYS_EVENT_PAUSED = 0x04;
69 EAPI const int LB_SYS_EVENT_RESUMED = 0x08;
71 EAPI struct livebox_desc *livebox_desc_open(const char *filename, int for_pd)
73 struct livebox_desc *handle;
76 handle = calloc(1, sizeof(*handle));
78 ErrPrint("Error: %s\n", strerror(errno));
84 len = strlen(filename) + strlen(".desc") + 1;
85 new_fname = malloc(len);
87 ErrPrint("Error: %s\n", strerror(errno));
91 snprintf(new_fname, len, "%s.desc", filename);
93 new_fname = strdup(filename);
95 ErrPrint("Error: %s\n", strerror(errno));
101 DbgPrint("Open a new file: %s\n", new_fname);
102 handle->fp = fopen(new_fname, "w+t");
105 ErrPrint("Failed to open a file: %s\n", strerror(errno));
113 EAPI int livebox_desc_close(struct livebox_desc *handle)
122 DbgPrint("Close and flush\n");
123 dlist_foreach_safe(handle->block_list, l, n, block) {
124 handle->block_list = dlist_remove(handle->block_list, l);
127 fprintf(handle->fp, "{\n");
129 fprintf(handle->fp, "type=%s\n", block->type);
130 DbgPrint("type=%s\n", block->type);
134 fprintf(handle->fp, "part=%s\n", block->part);
135 DbgPrint("part=%s\n", block->part);
139 fprintf(handle->fp, "data=%s\n", block->data);
140 DbgPrint("data=%s\n", block->data);
144 fprintf(handle->fp, "group=%s\n", block->group);
145 DbgPrint("group=%s\n", block->group);
149 fprintf(handle->fp, "id=%s\n", block->id);
150 DbgPrint("id=%s\n", block->id);
153 if (block->target_id) {
154 fprintf(handle->fp, "target=%s\n", block->target_id);
155 DbgPrint("target=%s\n", block->target_id);
158 fprintf(handle->fp, "}\n");
166 free(block->target_id);
175 EAPI int livebox_desc_set_category(struct livebox_desc *handle, const char *id, const char *category)
179 if (!handle || !category)
182 block = calloc(1, sizeof(*block));
186 block->type = strdup(LB_DESC_TYPE_INFO);
192 block->part = strdup("category");
199 block->data = strdup(category);
208 block->id = strdup(id);
218 block->idx = handle->last_idx++;
219 handle->block_list = dlist_append(handle->block_list, block);
223 EAPI int livebox_desc_set_size(struct livebox_desc *handle, const char *id, int w, int h)
231 block = calloc(1, sizeof(*block));
235 block->type = strdup(LB_DESC_TYPE_INFO);
241 block->part = strdup("size");
249 block->id = strdup(id);
258 snprintf(buffer, sizeof(buffer), "%dx%d", w, h);
259 block->data = strdup(buffer);
267 block->idx = handle->last_idx++;
268 handle->block_list = dlist_append(handle->block_list, block);
272 EAPI char *livebox_util_nl2br(const char *str)
299 tmp = realloc(ret, len);
326 EAPI int livebox_desc_set_id(struct livebox_desc *handle, int idx, const char *id)
331 dlist_foreach(handle->block_list, l, block) {
332 if (block->idx == idx) {
333 if (strcasecmp(block->type, LB_DESC_TYPE_SCRIPT)) {
334 ErrPrint("Invalid block is used\n");
338 free(block->target_id);
339 block->target_id = NULL;
341 if (!id || !strlen(id))
344 block->target_id = strdup(id);
345 if (!block->target_id) {
346 ErrPrint("Heap: %s\n", strerror(errno));
360 EAPI int livebox_desc_add_block(struct livebox_desc *handle, const char *id, const char *type, const char *part, const char *data, const char *group)
364 if (!handle || !type)
373 block = calloc(1, sizeof(*block));
377 block->type = strdup(type);
383 block->part = strdup(part);
390 block->data = strdup(data);
399 block->group = strdup(group);
410 block->id = strdup(id);
421 block->idx = handle->last_idx++;
422 handle->block_list = dlist_append(handle->block_list, block);
426 EAPI int livebox_desc_del_block(struct livebox_desc *handle, int idx)
431 dlist_foreach(handle->block_list, l, block) {
432 if (block->idx == idx) {
433 handle->block_list = dlist_remove(handle->block_list, l);
439 free(block->target_id);
448 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)
451 struct livebox_buffer *handle;
455 if (!filename || !width || !height) {
456 ErrPrint("Invalid argument: %p(%dx%d)\n", filename, width, height);
460 uri_len = strlen(filename) + strlen("file://") + 1;
461 uri = malloc(uri_len);
463 ErrPrint("Heap: %s\n", strerror(errno));
467 snprintf(uri, uri_len, "file://%s", filename);
468 DbgPrint("Before call the livebox_find_pkgname\n");
469 pkgname = livebox_find_pkgname(uri);
470 DbgPrint("After call the livebox_find_pkgname\n");
472 ErrPrint("Invalid Request\n");
477 DbgPrint("URI: %s\n", uri);
478 handle = provider_buffer_acquire((!!is_pd) ? TYPE_PD : TYPE_LB, pkgname, uri, width, height, sizeof(int), handler, data);
479 DbgPrint("Acquire buffer for PD(%s), %s, %p\n", pkgname, uri, handle);
484 EAPI unsigned long livebox_pixmap_id(struct livebox_buffer *handle)
486 return provider_buffer_pixmap_id(handle);
489 EAPI int livebox_release_buffer(struct livebox_buffer *handle)
494 DbgPrint("Release buffer\n");
495 return provider_buffer_release(handle);
498 EAPI void *livebox_ref_buffer(struct livebox_buffer *handle)
503 DbgPrint("Ref buffer\n");
504 return provider_buffer_ref(handle);
507 EAPI int livebox_unref_buffer(void *buffer)
512 DbgPrint("Unref buffer\n");
513 return provider_buffer_unref(buffer);
516 EAPI int livebox_sync_buffer(struct livebox_buffer *handle)
524 pkgname = provider_buffer_pkgname(handle);
525 id = provider_buffer_id(handle);
526 if (!pkgname || !id) {
527 ErrPrint("Invalid buffer handler\n");
531 DbgPrint("Sync buffer\n");
532 provider_buffer_sync(handle);
533 provider_send_desc_updated(pkgname, id, NULL);