Import the livebox library from a local git
authorSung-jae Park <nicesj.park@samsung.com>
Thu, 17 May 2012 05:05:08 +0000 (14:05 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Thu, 17 May 2012 05:05:08 +0000 (14:05 +0900)
Change-Id: I9b59033f254e75b3a701eee23f2ed71eac89f343

17 files changed:
CMakeLists.txt [new file with mode: 0644]
data/CMakeLists.txt [new file with mode: 0644]
debian/changelog [new file with mode: 0644]
debian/compat [new file with mode: 0644]
debian/control [new file with mode: 0644]
debian/liblivebox-dev.install.in [new file with mode: 0644]
debian/liblivebox.install.in [new file with mode: 0644]
debian/rules [new file with mode: 0755]
include/debug.h [new file with mode: 0644]
include/dlist.h [new file with mode: 0644]
include/livebox.h [new file with mode: 0644]
include/livebox_PG.h [new file with mode: 0644]
include/util.h [new file with mode: 0644]
livebox.pc.in [new file with mode: 0644]
src/dlist.c [new file with mode: 0644]
src/livebox.c [new file with mode: 0644]
src/util.c [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..5a71236
--- /dev/null
@@ -0,0 +1,59 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(livebox C)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(PROJECT_NAME "${PROJECT_NAME}")
+SET(LIBDIR "\${exec_prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include/${PROJECT_NAME}")
+SET(VERSION_MAJOR 0)
+SET(VERSION "${VERSION_MAJOR}.0.1")
+
+set(CMAKE_SKIP_BUILD_RPATH true)
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED
+       dlog
+)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+#ADD_DEFINITIONS("-Werror")
+#ADD_DEFINITIONS("-Wall")
+#ADD_DEFINITIONS("-Wextra")
+#ADD_DEFINITIONS("-ansi")
+#ADD_DEFINITIONS("-pedantic")
+
+ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
+ADD_DEFINITIONS("-DLOG_TAG=\"${PROJECT_NAME}\"")
+ADD_DEFINITIONS("-DLIVE_IMAGE_FOLDER=\"/opt/share/live_magazine/\"")
+ADD_DEFINITIONS("-DNDEBUG")
+ADD_DEFINITIONS("-DMASTER_PKGNAME=\"com.samsung.data-provider-master\"")
+ADD_DEFINITIONS("-DSLAVE_PKGNAME=\"com.samsung.data-provider-slave\"")
+
+ADD_LIBRARY(${PROJECT_NAME} SHARED
+       src/dlist.c
+       src/livebox.c
+       src/util.c
+)
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-lpthread")
+
+CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
+SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}.pc")
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/livebox.h DESTINATION include/${PROJECT_NAME})
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/livebox_PG.h DESTINATION /usr/share/doc/${PROJECT_NAME})
+
+ADD_SUBDIRECTORY(data)
diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/debian/changelog b/debian/changelog
new file mode 100644 (file)
index 0000000..11a0a28
--- /dev/null
@@ -0,0 +1,9 @@
+livebox (0.0.1) unstable; urgency=low
+
+  * Initial Release.
+
+  * Git: slp/pkgs/l/livebox
+  * Tag: livebox_0.0.1
+
+ -- Sung-jae Park <nicesj.park@samsung.com>  Mon, 27 Feb 2012 14:14:00 +0900
+
diff --git a/debian/compat b/debian/compat
new file mode 100644 (file)
index 0000000..7ed6ff8
--- /dev/null
@@ -0,0 +1 @@
+5
diff --git a/debian/control b/debian/control
new file mode 100644 (file)
index 0000000..74c7cbd
--- /dev/null
@@ -0,0 +1,25 @@
+Source: livebox
+Section: libs
+Priority: optional
+Maintainer: Sung-jae Park <nicesj.park@samsung.com>, Young-joo Park <yjoo93.park@samsung.com>
+Build-Depends: debhelper (>= 5), dlog-dev
+Standards-Version: 0.1.0
+
+Package: liblivebox
+Section: libs
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: Livebox development helper library (shared object)
+
+Package: liblivebox-dev
+Section: libs
+Architecture: any
+Depends: liblivebox (= ${Source-Version})
+Description: Livebox development helper library (development)
+
+Package: liblivebox-dbg
+Section: debug
+Architecture: any
+Depends: ${misc:Depends}, liblivebox (= ${Source-Version})
+Description: Livebox development helper library (unstripped)
+
diff --git a/debian/liblivebox-dev.install.in b/debian/liblivebox-dev.install.in
new file mode 100644 (file)
index 0000000..ed41960
--- /dev/null
@@ -0,0 +1,3 @@
+@PREFIX@/include/@PROJECT_NAME@/livebox.h
+@PREFIX@/share/doc/@PROJECT_NAME@/livebox_PG.h
+@PREFIX@/lib/pkgconfig/*.pc
diff --git a/debian/liblivebox.install.in b/debian/liblivebox.install.in
new file mode 100644 (file)
index 0000000..bf766f0
--- /dev/null
@@ -0,0 +1 @@
+@PREFIX@/lib/*.so*
diff --git a/debian/rules b/debian/rules
new file mode 100755 (executable)
index 0000000..126c856
--- /dev/null
@@ -0,0 +1,116 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+CFLAGS += -Wall -Werror -Winline
+LDFLAGS +=
+PREFIX ?= /usr
+DATADIR ?= /opt
+PROJECT_NAME ?= livebox
+
+BUILDDIR ?= $(CURDIR)/cmake-tmp
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+       CFLAGS += -O0
+else
+       CFLAGS += -O2
+endif
+
+LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed -lm
+
+configure: configure-stamp
+configure-stamp:
+       dh_testdir
+       # Add here commands to configure the package.
+       mkdir -p $(BUILDDIR) && cd $(BUILDDIR) && CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" cmake .. -DCMAKE_INSTALL_PREFIX=$(PREFIX)
+
+       touch configure-stamp
+
+build: build-stamp
+
+build-stamp: configure-stamp
+       dh_testdir
+
+       # Add here commands to compile the package.
+       cd $(BUILDDIR) && $(MAKE)
+       #docbook-to-man debian/wavplayer.sgml > wavplayer.1
+
+       for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
+               cat $$f > $${f%.in}; \
+               sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \
+               sed -i -e "s#@PROJECT_NAME@#$(PROJECT_NAME)#g" $${f%.in}; \
+               sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \
+       done
+
+
+       touch $@
+
+clean:
+       dh_testdir
+       dh_testroot
+       rm -f build-stamp configure-stamp
+
+       # Add here commands to clean up after the build process.
+       rm -rf $(BUILDDIR)
+       #rm -rf CMakeCache.txt CMakeFiles cmake_install.cmake Makefile install_manifest.txt
+
+       for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
+               rm -f $${f%.in}; \
+       done
+
+       dh_clean
+
+install: build
+       dh_testdir
+       dh_testroot
+       dh_clean -k
+       dh_installdirs
+
+       # Add here commands to install the package into debian/wavplayer.
+       cd $(BUILDDIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
+
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+       dh_testdir
+       dh_testroot
+       #dh_installchangelogs
+       #dh_installdocs
+       #dh_installexamples
+       dh_install --sourcedir=debian/tmp
+#      dh_installmenu
+#      dh_installdebconf
+#      dh_installlogrotate
+#      dh_installemacsen
+#      dh_installpam
+#      dh_installmime
+#      dh_python
+#      dh_installinit
+#      dh_installcron
+#      dh_installinfo
+       dh_installman
+       dh_link
+       dh_strip --dbg-package=liblivebox-dbg
+       dh_compress
+       dh_fixperms
+#      dh_perl
+       dh_makeshlibs
+       dh_installdeb
+       dh_shlibdeps
+       dh_gencontrol
+       dh_md5sums
+       dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
diff --git a/include/debug.h b/include/debug.h
new file mode 100644 (file)
index 0000000..7e63c42
--- /dev/null
@@ -0,0 +1,3 @@
+#define DbgPrint(format, arg...)       LOGD("[\e[32m%s/%s\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
+#define ErrPrint(format, arg...)       LOGE("[\e[32m%s/%s\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
+/* End of a file */
diff --git a/include/dlist.h b/include/dlist.h
new file mode 100644 (file)
index 0000000..4a02fed
--- /dev/null
@@ -0,0 +1,27 @@
+#define dlist_remove_data(list, data) do { \
+       struct dlist *l; \
+       l = dlist_find_data(list, data); \
+       list = dlist_remove(list, l); \
+} while (0)
+
+#define dlist_foreach(list, l, data) \
+       for ((l) = (list); ((data) = dlist_data(l)); (l) = dlist_next(l))
+
+#define dlist_foreach_safe(list, l, n, data) \
+       for ((l) = (list), (n) = dlist_next(l); \
+               ((data) = dlist_data(l)); \
+               (l) = (n), (n) = dlist_next(l))
+
+struct dlist;
+
+extern struct dlist *dlist_append(struct dlist *list, void *data);
+extern struct dlist *dlist_prepend(struct dlist *list, void *data);
+extern struct dlist *dlist_remove(struct dlist *list, struct dlist *l);
+extern struct dlist *dlist_find_data(struct dlist *list, void *data);
+extern void *dlist_data(struct dlist *l);
+extern struct dlist *dlist_next(struct dlist *l);
+extern struct dlist *dlist_prev(struct dlist *l);
+extern int dlist_count(struct dlist *l);
+extern struct dlist *dlist_nth(struct dlist *l, int nth);
+
+/* End of a file */
diff --git a/include/livebox.h b/include/livebox.h
new file mode 100644 (file)
index 0000000..fc475ff
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef __LIVEBOX_HELPER_H
+#define __LIVEBOX_HELPER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern const int DONE;
+extern const int NEED_TO_SCHEDULE;
+extern const int OUTPUT_UPDATED;
+extern const int NEED_TO_CREATE;
+extern const int NEED_TO_DESTROY;
+
+struct livebox_desc;
+
+extern struct livebox_desc *livebox_desc_open(const char *filename, int for_pd);
+extern int livebox_desc_close(struct livebox_desc *handle);
+
+extern int livebox_desc_set_category(struct livebox_desc *handle, const char *id, const char *category);
+extern int livebox_desc_set_size(struct livebox_desc *handle, const char *id, int w, int h);
+
+/*!
+ * \return idx
+ */
+extern int livebox_desc_add_block(struct livebox_desc *handle, const char *id, const char *type, const char *part, const char *data, const char *group);
+extern int livebox_desc_del_block(struct livebox_desc *handle, int idx);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* End of a file */
diff --git a/include/livebox_PG.h b/include/livebox_PG.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/include/util.h b/include/util.h
new file mode 100644 (file)
index 0000000..6202410
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * com.samsung.live-magazine
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Sung-jae Park <nicesj.park@samsung.com>, Youngjoo Park <yjoo93.park@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+extern int util_check_extension(const char *filename, const char *check_ptr);
+extern double util_get_timestamp(void);
+
+/* End of a file */
diff --git a/livebox.pc.in b/livebox.pc.in
new file mode 100644 (file)
index 0000000..7384a09
--- /dev/null
@@ -0,0 +1,10 @@
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: livebox
+Description: livebox supporting library
+Version: @VERSION@
+Libs: -L${libdir} -llivebox
+Cflags: -I${includedir}
diff --git a/src/dlist.c b/src/dlist.c
new file mode 100644 (file)
index 0000000..c8f62c3
--- /dev/null
@@ -0,0 +1,138 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "dlist.h"
+
+struct dlist {
+       struct dlist *next;
+       struct dlist *prev;
+       void *data;
+};
+
+struct dlist *dlist_append(struct dlist *list, void *data)
+{
+       struct dlist *item;
+
+       item = malloc(sizeof(*item));
+       if (!item)
+               return NULL;
+
+       item->next = NULL;
+       item->data = data;
+
+       if (!list) {
+               item->prev = item;
+
+               list = item;
+       } else {
+               item->prev = list->prev;
+               item->prev->next = item;
+
+               list->prev = item;
+       }
+
+       assert(!list->prev->next && "item NEXT");
+
+       return list;
+}
+
+struct dlist *dlist_prepend(struct dlist *list, void *data)
+{
+       struct dlist *item;
+
+       item = malloc(sizeof(*item));
+       if (!item)
+               return NULL;
+
+       if (!list) {
+               item->prev = item;
+               item->next = NULL;
+       } else {
+               item->prev = list->prev;
+               list->prev = item;
+               item->next = list;
+       }
+
+       return item;
+}
+
+struct dlist *dlist_remove(struct dlist *list, struct dlist *l)
+{
+       if (!list || !l)
+               return NULL;
+
+       if (l == list) {
+               l->prev = list->prev;
+               list = l->next;
+       } else {
+               l->prev->next = l->next;
+       }
+
+       if (l->next)
+               l->next->prev = l->prev;
+
+       free(l);
+       return list;
+}
+
+struct dlist *dlist_find_data(struct dlist *list, void *data)
+{
+       struct dlist *l;
+       void *_data;
+
+       dlist_foreach(list, l, _data) {
+               if (data == _data)
+                       return l;
+       }
+
+       return NULL;
+}
+
+void *dlist_data(struct dlist *l)
+{
+       return l ? l->data : NULL;
+}
+
+struct dlist *dlist_next(struct dlist *l)
+{
+       return l ? l->next : NULL;
+}
+
+struct dlist *dlist_prev(struct dlist *l)
+{
+       return l ? l->prev : NULL;
+}
+
+int dlist_count(struct dlist *l)
+{
+       register int i;
+       struct dlist *n;
+       void *data;
+
+       i = 0;
+       dlist_foreach(l, n, data) {
+               i++;
+       }
+
+       return i;
+}
+
+struct dlist *dlist_nth(struct dlist *l, int nth)
+{
+       register int i;
+       struct dlist *n;
+       void *data;
+
+       i = 0;
+       dlist_foreach(l, n, data) {
+               if (i == nth)
+                       return l;
+
+               i++;
+       }
+
+       return NULL;
+}
+
+/* End of a file */
diff --git a/src/livebox.c b/src/livebox.c
new file mode 100644 (file)
index 0000000..4afc059
--- /dev/null
@@ -0,0 +1,321 @@
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h> /* malloc */
+#include <string.h> /* strdup */
+#include <libgen.h>
+
+#include <dlog.h>
+
+#include "debug.h"
+#include "livebox.h"
+#include "dlist.h"
+#include "util.h"
+
+#define EAPI __attribute__((visibility("default")))
+
+struct block {
+       unsigned int idx;
+
+       char *type;
+       char *part;
+       char *data;
+       char *group;
+       char *id;
+       char *file;
+};
+
+struct livebox_desc {
+       FILE *fp;
+       int for_pd;
+
+       unsigned int last_idx;
+
+       struct dlist *block_list;
+};
+
+EAPI const int DONE = 0x00;
+EAPI const int NEED_TO_SCHEDULE = 0x01;
+EAPI const int OUTPUT_UPDATED = 0x02;
+EAPI const int NEED_TO_CREATE = 0x01;
+EAPI const int NEED_TO_DESTROY = 0x01;
+
+EAPI struct livebox_desc *livebox_desc_open(const char *filename, int for_pd)
+{
+       struct livebox_desc *handle;
+       char *new_fname;
+
+       handle = calloc(1, sizeof(*handle));
+       if (!handle) {
+               ErrPrint("Error: %s\n", strerror(errno));
+               return NULL;
+       }
+
+       if (for_pd) {
+               int len;
+               len = strlen(filename) + strlen(".desc") + 1;
+               new_fname = malloc(len);
+               if (!new_fname) {
+                       ErrPrint("Error: %s\n", strerror(errno));
+                       free(handle);
+                       return NULL;
+               }
+               snprintf(new_fname, len, "%s.desc", filename);
+       } else {
+               new_fname = strdup(filename);
+               if (!new_fname) {
+                       ErrPrint("Error: %s\n", strerror(errno));
+                       free(handle);
+                       return NULL;
+               }
+       }
+
+       DbgPrint("Open a new file: %s\n", new_fname);
+       handle->fp = fopen(new_fname, "w+t");
+       free(new_fname);
+       if (!handle->fp) {
+               ErrPrint("Failed to open a file: %s (%s)\n", new_fname, strerror(errno));
+               free(handle);
+               return NULL;
+       }
+
+       return handle;
+}
+
+EAPI int livebox_desc_close(struct livebox_desc *handle)
+{
+       struct dlist *l;
+       struct dlist *n;
+       struct block *block;
+
+       if (!handle)
+               return -EINVAL;
+
+       DbgPrint("Close and flush\n");
+       dlist_foreach_safe(handle->block_list, l, n, block) {
+               handle->block_list = dlist_remove(handle->block_list, l);
+
+               DbgPrint("{\n");
+               fprintf(handle->fp, "{\n");
+               if (block->type) {
+                       fprintf(handle->fp, "type=%s\n", block->type);
+                       DbgPrint("type=%s\n", block->type);
+               }
+
+               if (block->part) {
+                       fprintf(handle->fp, "part=%s\n", block->part);
+                       DbgPrint("part=%s\n", block->part);
+               }
+
+               if (block->data) {
+                       fprintf(handle->fp, "data=%s\n", block->data);
+                       DbgPrint("data=%s\n", block->data);
+               }
+
+               if (block->group) {
+                       fprintf(handle->fp, "group=%s\n", block->group);
+                       DbgPrint("group=%s\n", block->group);
+               }
+
+               if (block->id) {
+                       fprintf(handle->fp, "id=%s\n", block->id);
+                       DbgPrint("id=%s\n", block->id);
+               }
+
+               fprintf(handle->fp, "}\n");
+               DbgPrint("}\n");
+
+               free(block->type);
+               free(block->part);
+               free(block->data);
+               free(block->group);
+               free(block->id);
+               free(block);
+       }
+
+       fclose(handle->fp);
+       free(handle);
+       return 0;
+}
+
+EAPI int livebox_desc_set_category(struct livebox_desc *handle, const char *id, const char *category)
+{
+       struct block *block;
+
+       if (!handle || !category)
+               return -EINVAL;
+
+       block = calloc(1, sizeof(*block));
+       if (!block)
+               return -ENOMEM;
+
+       block->type = strdup("info");
+       if (!block->type) {
+               free(block);
+               return -ENOMEM;
+       }
+
+       block->part = strdup("category");
+       if (!block->part) {
+               free(block->type);
+               free(block);
+               return -ENOMEM;
+       }
+
+       block->data = strdup(category);
+       if (!block->data) {
+               free(block->type);
+               free(block->part);
+               free(block);
+               return -ENOMEM;
+       }
+
+       if (id) {
+               block->id = strdup(id);
+               if (!block->id) {
+                       free(block->data);
+                       free(block->type);
+                       free(block->part);
+                       free(block);
+                       return -ENOMEM;
+               }
+       }
+
+       block->idx = handle->last_idx++;
+       handle->block_list = dlist_append(handle->block_list, block);
+       return block->idx;
+}
+
+EAPI int livebox_desc_set_size(struct livebox_desc *handle, const char *id, int w, int h)
+{
+       struct block *block;
+       char buffer[BUFSIZ];
+
+       if (!handle)
+               return -EINVAL;
+
+       block = calloc(1, sizeof(*block));
+       if (!block)
+               return -ENOMEM;
+
+       block->type = strdup("info");
+       if (!block->type) {
+               free(block);
+               return -ENOMEM;
+       }
+
+       block->part = strdup("size");
+       if (!block->part) {
+               free(block->type);
+               free(block);
+               return -ENOMEM;
+       }
+
+       if (id) {
+               block->id = strdup(id);
+               if (!block->id) {
+                       free(block->part);
+                       free(block->type);
+                       free(block);
+                       return -ENOMEM;
+               }
+       }
+
+       snprintf(buffer, sizeof(buffer), "%dx%d", w, h);
+       block->data = strdup(buffer);
+       if (!block->data) {
+               free(block->part);
+               free(block->type);
+               free(block);
+               return -ENOMEM;
+       }
+
+       block->idx = handle->last_idx++;
+       handle->block_list = dlist_append(handle->block_list, block);
+       return block->idx;
+}
+
+/*!
+ * \return idx
+ */
+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)
+{
+       struct block *block;
+
+       if (!handle || !type || !part || !data)
+               return -EINVAL;
+
+       block = calloc(1, sizeof(*block));
+       if (!block)
+               return -ENOMEM;
+
+       block->type = strdup(type);
+       if (!block->type) {
+               free(block);
+               return -ENOMEM;
+       }
+
+       block->part = strdup(part);
+       if (!block->part) {
+               free(block->type);
+               free(block);
+               return -ENOMEM;
+       }
+
+       block->data = strdup(data);
+       if (!block->data) {
+               free(block->type);
+               free(block->part);
+               free(block);
+               return -ENOMEM;
+       }
+
+       if (group) {
+               block->group = strdup(group);
+               if (!block->group) {
+                       free(block->data);
+                       free(block->type);
+                       free(block->part);
+                       free(block);
+                       return -ENOMEM;
+               }
+       }
+
+       if (id) {
+               block->id = strdup(id);
+               if (!block->id) {
+                       free(block->group);
+                       free(block->data);
+                       free(block->type);
+                       free(block->part);
+                       free(block);
+                       return -ENOMEM;
+               }
+       }
+
+       block->idx = handle->last_idx++;
+       handle->block_list = dlist_append(handle->block_list, block);
+       return block->idx;
+}
+
+EAPI int livebox_desc_del_block(struct livebox_desc *handle, int idx)
+{
+       struct dlist *l;
+       struct block *block;
+
+       dlist_foreach(handle->block_list, l, block) {
+               if (block->idx == idx) {
+                       handle->block_list = dlist_remove(handle->block_list, l);
+                       free(block->type);
+                       free(block->part);
+                       free(block->data);
+                       free(block->group);
+                       free(block->id);
+                       free(block);
+                       return 0;
+               }
+       }
+
+       return -ENOENT;
+}
+
+/* End of a file */
diff --git a/src/util.c b/src/util.c
new file mode 100644 (file)
index 0000000..61d3a13
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * com.samsung.live-magazine
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Sung-jae Park <nicesj.park@samsung.com>, Youngjoo Park <yjoo93.park@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/time.h>
+
+#include <dlog.h>
+
+#include "debug.h"
+#include "util.h"
+
+int errno;
+
+int util_check_extension(const char *filename, const char *check_ptr)
+{
+       int name_len;
+
+       name_len = strlen(filename);
+       while (--name_len >= 0 && *check_ptr) {
+               if (filename[name_len] != *check_ptr)
+                       return -EINVAL;
+
+               check_ptr ++;
+       }
+
+       return 0;
+}
+
+double util_get_timestamp(void)
+{
+       struct timeval tv;
+
+       gettimeofday(&tv, NULL);
+
+       return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
+}
+
+/* End of a file */