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 NEED_TO_SCHEDULE = 0x01;
66 EAPI const int OUTPUT_UPDATED = 0x02;
67 EAPI const int NEED_TO_CREATE = 0x01;
68 EAPI const int NEED_TO_DESTROY = 0x01;
69 EAPI const int LB_SYS_EVENT_FONT_CHANGED = 0x01;
70 EAPI const int LB_SYS_EVENT_LANG_CHANGED = 0x02;
71 EAPI const int LB_SYS_EVENT_PAUSED = 0x04;
72 EAPI const int LB_SYS_EVENT_RESUMED = 0x08;
74 EAPI struct livebox_desc *livebox_desc_open(const char *filename, int for_pd)
76 struct livebox_desc *handle;
79 handle = calloc(1, sizeof(*handle));
81 ErrPrint("Error: %s\n", strerror(errno));
87 len = strlen(filename) + strlen(".desc") + 1;
88 new_fname = malloc(len);
90 ErrPrint("Error: %s\n", strerror(errno));
94 snprintf(new_fname, len, "%s.desc", filename);
96 new_fname = strdup(filename);
98 ErrPrint("Error: %s\n", strerror(errno));
104 DbgPrint("Open a new file: %s\n", new_fname);
105 handle->fp = fopen(new_fname, "w+t");
108 ErrPrint("Failed to open a file: %s\n", strerror(errno));
116 EAPI int livebox_desc_close(struct livebox_desc *handle)
125 DbgPrint("Close and flush\n");
126 dlist_foreach_safe(handle->block_list, l, n, block) {
127 handle->block_list = dlist_remove(handle->block_list, l);
130 fprintf(handle->fp, "{\n");
132 fprintf(handle->fp, "type=%s\n", block->type);
133 DbgPrint("type=%s\n", block->type);
137 fprintf(handle->fp, "part=%s\n", block->part);
138 DbgPrint("part=%s\n", block->part);
142 fprintf(handle->fp, "data=%s\n", block->data);
143 DbgPrint("data=%s\n", block->data);
147 fprintf(handle->fp, "group=%s\n", block->group);
148 DbgPrint("group=%s\n", block->group);
152 fprintf(handle->fp, "id=%s\n", block->id);
153 DbgPrint("id=%s\n", block->id);
156 if (block->target_id) {
157 fprintf(handle->fp, "target=%s\n", block->target_id);
158 DbgPrint("target=%s\n", block->target_id);
161 fprintf(handle->fp, "}\n");
169 free(block->target_id);
178 EAPI int livebox_desc_set_category(struct livebox_desc *handle, const char *id, const char *category)
182 if (!handle || !category)
185 block = calloc(1, sizeof(*block));
189 block->type = strdup(LB_DESC_TYPE_INFO);
195 block->part = strdup("category");
202 block->data = strdup(category);
211 block->id = strdup(id);
221 block->idx = handle->last_idx++;
222 handle->block_list = dlist_append(handle->block_list, block);
226 EAPI int livebox_desc_set_size(struct livebox_desc *handle, const char *id, int w, int h)
234 block = calloc(1, sizeof(*block));
238 block->type = strdup(LB_DESC_TYPE_INFO);
244 block->part = strdup("size");
252 block->id = strdup(id);
261 snprintf(buffer, sizeof(buffer), "%dx%d", w, h);
262 block->data = strdup(buffer);
270 block->idx = handle->last_idx++;
271 handle->block_list = dlist_append(handle->block_list, block);
275 EAPI char *livebox_util_nl2br(const char *str)
302 tmp = realloc(ret, len);
329 EAPI int livebox_desc_set_id(struct livebox_desc *handle, int idx, const char *id)
334 dlist_foreach(handle->block_list, l, block) {
335 if (block->idx == idx) {
336 if (strcasecmp(block->type, LB_DESC_TYPE_SCRIPT)) {
337 ErrPrint("Invalid block is used\n");
341 free(block->target_id);
342 block->target_id = NULL;
344 if (!id || !strlen(id))
347 block->target_id = strdup(id);
348 if (!block->target_id) {
349 ErrPrint("Heap: %s\n", strerror(errno));
363 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)
367 if (!handle || !type)
376 block = calloc(1, sizeof(*block));
380 block->type = strdup(type);
386 block->part = strdup(part);
393 block->data = strdup(data);
402 block->group = strdup(group);
413 block->id = strdup(id);
424 block->idx = handle->last_idx++;
425 handle->block_list = dlist_append(handle->block_list, block);
429 EAPI int livebox_desc_del_block(struct livebox_desc *handle, int idx)
434 dlist_foreach(handle->block_list, l, block) {
435 if (block->idx == idx) {
436 handle->block_list = dlist_remove(handle->block_list, l);
442 free(block->target_id);
451 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)
454 struct livebox_buffer *handle;
458 if (!filename || !width || !height) {
459 ErrPrint("Invalid argument: %p(%dx%d)\n", filename, width, height);
463 uri_len = strlen(filename) + strlen(FILE_SCHEMA) + 1;
464 uri = malloc(uri_len);
466 ErrPrint("Heap: %s\n", strerror(errno));
470 snprintf(uri, uri_len, FILE_SCHEMA "%s", filename);
471 pkgname = livebox_find_pkgname(uri);
473 ErrPrint("Invalid Request\n");
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 int livebox_request_update(const char *filename)
491 ErrPrint("Invalid argument\n");
495 uri_len = strlen(filename) + strlen(FILE_SCHEMA) + 1;
496 uri = malloc(uri_len);
498 ErrPrint("Heap: %s\n", strerror(errno));
502 snprintf(uri, uri_len, FILE_SCHEMA "%s", filename);
503 ret = livebox_request_update_by_id(uri);
508 EAPI unsigned long livebox_pixmap_id(struct livebox_buffer *handle)
510 return provider_buffer_pixmap_id(handle);
513 EAPI int livebox_release_buffer(struct livebox_buffer *handle)
518 DbgPrint("Release buffer\n");
519 return provider_buffer_release(handle);
522 EAPI void *livebox_ref_buffer(struct livebox_buffer *handle)
527 DbgPrint("Ref buffer\n");
528 return provider_buffer_ref(handle);
531 EAPI int livebox_unref_buffer(void *buffer)
536 DbgPrint("Unref buffer\n");
537 return provider_buffer_unref(buffer);
540 EAPI int livebox_sync_buffer(struct livebox_buffer *handle)
548 pkgname = provider_buffer_pkgname(handle);
549 id = provider_buffer_id(handle);
550 if (!pkgname || !id) {
551 ErrPrint("Invalid buffer handler\n");
555 DbgPrint("Sync buffer\n");
556 provider_buffer_sync(handle);
557 provider_send_desc_updated(pkgname, id, NULL);