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_TIME_CHANGED = 0x04;
72 EAPI const int LB_SYS_EVENT_PAUSED = 0x0100;
73 EAPI const int LB_SYS_EVENT_RESUMED = 0x0200;
75 EAPI struct livebox_desc *livebox_desc_open(const char *filename, int for_pd)
77 struct livebox_desc *handle;
80 handle = calloc(1, sizeof(*handle));
82 ErrPrint("Error: %s\n", strerror(errno));
88 len = strlen(filename) + strlen(".desc") + 1;
89 new_fname = malloc(len);
91 ErrPrint("Error: %s\n", strerror(errno));
95 snprintf(new_fname, len, "%s.desc", filename);
97 new_fname = strdup(filename);
99 ErrPrint("Error: %s\n", strerror(errno));
105 DbgPrint("Open a new file: %s\n", new_fname);
106 handle->fp = fopen(new_fname, "w+t");
109 ErrPrint("Failed to open a file: %s\n", strerror(errno));
117 EAPI int livebox_desc_close(struct livebox_desc *handle)
126 DbgPrint("Close and flush\n");
127 dlist_foreach_safe(handle->block_list, l, n, block) {
128 handle->block_list = dlist_remove(handle->block_list, l);
131 fprintf(handle->fp, "{\n");
133 fprintf(handle->fp, "type=%s\n", block->type);
134 DbgPrint("type=%s\n", block->type);
138 fprintf(handle->fp, "part=%s\n", block->part);
139 DbgPrint("part=%s\n", block->part);
143 fprintf(handle->fp, "data=%s\n", block->data);
144 DbgPrint("data=%s\n", block->data);
148 fprintf(handle->fp, "group=%s\n", block->group);
149 DbgPrint("group=%s\n", block->group);
153 fprintf(handle->fp, "id=%s\n", block->id);
154 DbgPrint("id=%s\n", block->id);
157 if (block->target_id) {
158 fprintf(handle->fp, "target=%s\n", block->target_id);
159 DbgPrint("target=%s\n", block->target_id);
162 fprintf(handle->fp, "}\n");
170 free(block->target_id);
179 EAPI int livebox_desc_set_category(struct livebox_desc *handle, const char *id, const char *category)
183 if (!handle || !category)
186 block = calloc(1, sizeof(*block));
190 block->type = strdup(LB_DESC_TYPE_INFO);
196 block->part = strdup("category");
203 block->data = strdup(category);
212 block->id = strdup(id);
222 block->idx = handle->last_idx++;
223 handle->block_list = dlist_append(handle->block_list, block);
227 EAPI int livebox_desc_set_size(struct livebox_desc *handle, const char *id, int w, int h)
235 block = calloc(1, sizeof(*block));
239 block->type = strdup(LB_DESC_TYPE_INFO);
245 block->part = strdup("size");
253 block->id = strdup(id);
262 snprintf(buffer, sizeof(buffer), "%dx%d", w, h);
263 block->data = strdup(buffer);
271 block->idx = handle->last_idx++;
272 handle->block_list = dlist_append(handle->block_list, block);
276 EAPI char *livebox_util_nl2br(const char *str)
290 ret = malloc(len + 1);
303 tmp = realloc(ret, len + 1);
330 EAPI int livebox_desc_set_id(struct livebox_desc *handle, int idx, const char *id)
335 dlist_foreach(handle->block_list, l, block) {
336 if (block->idx == idx) {
337 if (strcasecmp(block->type, LB_DESC_TYPE_SCRIPT)) {
338 ErrPrint("Invalid block is used\n");
342 free(block->target_id);
343 block->target_id = NULL;
345 if (!id || !strlen(id))
348 block->target_id = strdup(id);
349 if (!block->target_id) {
350 ErrPrint("Heap: %s\n", strerror(errno));
364 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)
368 if (!handle || !type)
377 block = calloc(1, sizeof(*block));
381 block->type = strdup(type);
387 block->part = strdup(part);
394 block->data = strdup(data);
403 block->group = strdup(group);
414 block->id = strdup(id);
425 block->idx = handle->last_idx++;
426 handle->block_list = dlist_append(handle->block_list, block);
430 EAPI int livebox_desc_del_block(struct livebox_desc *handle, int idx)
435 dlist_foreach(handle->block_list, l, block) {
436 if (block->idx == idx) {
437 handle->block_list = dlist_remove(handle->block_list, l);
443 free(block->target_id);
452 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)
455 struct livebox_buffer *handle;
459 if (!filename || !width || !height) {
460 ErrPrint("Invalid argument: %p(%dx%d)\n", filename, width, height);
464 uri_len = strlen(filename) + strlen(FILE_SCHEMA) + 1;
465 uri = malloc(uri_len);
467 ErrPrint("Heap: %s\n", strerror(errno));
471 snprintf(uri, uri_len, FILE_SCHEMA "%s", filename);
472 pkgname = livebox_find_pkgname(uri);
474 ErrPrint("Invalid Request\n");
479 handle = provider_buffer_acquire((!!is_pd) ? TYPE_PD : TYPE_LB, pkgname, uri, width, height, sizeof(int), handler, data);
480 DbgPrint("Acquire buffer for PD(%s), %s, %p\n", pkgname, uri, handle);
485 EAPI int livebox_request_update(const char *filename)
492 ErrPrint("Invalid argument\n");
496 uri_len = strlen(filename) + strlen(FILE_SCHEMA) + 1;
497 uri = malloc(uri_len);
499 ErrPrint("Heap: %s\n", strerror(errno));
503 snprintf(uri, uri_len, FILE_SCHEMA "%s", filename);
504 ret = livebox_request_update_by_id(uri);
509 EAPI unsigned long livebox_pixmap_id(struct livebox_buffer *handle)
511 return provider_buffer_pixmap_id(handle);
514 EAPI int livebox_release_buffer(struct livebox_buffer *handle)
519 DbgPrint("Release buffer\n");
520 return provider_buffer_release(handle);
523 EAPI void *livebox_ref_buffer(struct livebox_buffer *handle)
528 DbgPrint("Ref buffer\n");
529 return provider_buffer_ref(handle);
532 EAPI int livebox_unref_buffer(void *buffer)
537 DbgPrint("Unref buffer\n");
538 return provider_buffer_unref(buffer);
541 EAPI int livebox_sync_buffer(struct livebox_buffer *handle)
549 pkgname = provider_buffer_pkgname(handle);
550 id = provider_buffer_id(handle);
551 if (!pkgname || !id) {
552 ErrPrint("Invalid buffer handler\n");
556 DbgPrint("Sync buffer\n");
557 provider_buffer_sync(handle);
558 provider_send_desc_updated(pkgname, id, NULL);