Implement buffer management code.
authorSung-jae Park <nicesj.park@samsung.com>
Fri, 19 Oct 2012 01:47:12 +0000 (10:47 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Mon, 22 Oct 2012 13:35:54 +0000 (22:35 +0900)
This patch will make the livbox can control the buffer of the PD area
Now the inhouse livebox can use the buffer directly to render its
contents on the screen (but, only for the PD)

Remove the livebox_root_path.

Change-Id: Ie3e92788ccd1bb9aa579a4fbde08d52216f2757b

CMakeLists.txt
include/livebox.h
packaging/liblivebox.spec
src/livebox.c

index f43c6ae..bf6020f 100644 (file)
@@ -17,6 +17,7 @@ INCLUDE(FindPkgConfig)
 pkg_check_modules(pkgs REQUIRED
        dlog
        livebox-service
+       provider
 )
 
 FOREACH(flag ${pkgs_CFLAGS})
@@ -35,7 +36,6 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -g")
 
 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\"")
index 372b9ed..5849651 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+struct livebox_buffer; /* Defined by provider */
+
 /*!
  * \brief
  * Return values of livebox programming interfaces.
@@ -97,12 +99,65 @@ extern int livebox_desc_del_block(struct livebox_desc *handle, int idx);
  */
 extern char *livebox_util_nl2br(const char *str);
 
+
+/*!
+ * Interfaces for direct buffer management (Available only for the PD area)
+ */
+
+
+#ifndef __PROVIDER_BUFFER_H
+/*!
+ * \NOTE
+ * This enumeration value should be sync'd with provider
+ */
+enum buffer_event {
+       BUFFER_EVENT_ENTER, /*!< */
+       BUFFER_EVENT_LEAVE, /*!< */
+       BUFFER_EVENT_DOWN, /*!< */
+       BUFFER_EVENT_MOVE, /*!< */
+       BUFFER_EVENT_UP, /*!< */
+};
+#endif
+
 /*!
- * \brief Get the root path of given application package.
- * \param[in] pkgname application package name
- * \param[out] char* Allocated string, root path of given package.
+ * \brief
+ * \param[in] filename
+ * \param[in] width
+ * \param[in] height
+ * \param[in] handler
+ * \param[in] data
+ * \return handler
  */
-extern char *livebox_root_path(const char *pkgname);
+extern struct livebox_buffer *livebox_acquire_buffer(const char *filename, int width, int height, int (*handler)(struct livebox_buffer *, enum buffer_event, double, double, double, void *), void *data);
+
+/*!
+ * \brief
+ * \param[in] handle
+ * \return int
+ */
+extern int livebox_release_buffer(struct livebox_buffer *handle);
+
+/*!
+ * \brief
+ * \param[in] handle
+ * \return void* buffer
+ */
+extern void *livebox_ref_buffer(struct livebox_buffer *handle);
+
+/*!
+ * \brief
+ * \param[in] buffer
+ * \return int
+ */
+extern int livebox_unref_buffer(void *buffer);
+
+/*!
+ * \brief
+ * \param[in] handler
+ * \return int
+ */
+extern int livebox_sync_buffer(struct livebox_buffer *handle);
+
 #ifdef __cplusplus
 }
 #endif
index 61b0993..89eadec 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox
 Summary: Library for the development of a livebox 
-Version: 0.0.10
+Version: 0.1.0
 Release: 1
 Group: main/app
 License: Samsung Proprietary License
@@ -8,6 +8,7 @@ Source0: %{name}-%{version}.tar.gz
 BuildRequires: cmake, gettext-tools
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(livebox-service)
+BuildRequires: pkgconfig(provider)
 
 %description
 Livebox development library
index 57c3346..014a19b 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <dlog.h>
 #include <livebox-service.h>
+#include <provider_buffer.h>
 
 #include "debug.h"
 #include "livebox.h"
 
 #define EAPI __attribute__((visibility("default")))
 
+/*!
+ * \brief This function is defined by the data-provider-slave
+ */
+extern const char *livebox_find_pkgname(const char *filename);
+
 struct block {
        unsigned int idx;
 
@@ -373,25 +379,88 @@ EAPI int livebox_desc_del_block(struct livebox_desc *handle, int idx)
        return -ENOENT;
 }
 
-EAPI char *livebox_root_path(const char *pkgname)
+EAPI struct livebox_buffer *livebox_acquire_buffer(const char *filename, int width, int height, int (*handler)(struct livebox_buffer *, enum buffer_event, double, double, double, void *), void *data)
 {
-       char *ret;
-       char *appid;
-       int len;
+       const char *pkgname;
+       struct livebox_buffer *handle;
+       char *uri;
+       int uri_len;
 
-       appid = livebox_service_appid(pkgname);
-       if (!appid)
+       if (!filename || !width || !height) {
+               ErrPrint("Invalid argument: %p(%dx%d)\n", filename, width, height);
                return NULL;
+       }
 
-       len = strlen("/opt/apps//") + strlen(appid) + 1;
-       ret = malloc(len);
-       if (!ret) {
-               DbgPrint("Heap: %s\n", strerror(errno));
+       uri_len = strlen(filename) + strlen("file://") + 1;
+       uri = malloc(uri_len);
+       if (!uri) {
+               ErrPrint("Heap: %s\n", strerror(errno));
                return NULL;
        }
 
-       snprintf(ret, len, "/opt/apps/%s/", appid);
-       return ret;
+       snprintf(uri, uri_len, "file://%s", filename);
+       DbgPrint("Before call the livebox_find_pkgname\n");
+       pkgname = livebox_find_pkgname(uri);
+       DbgPrint("After call the livebox_find_pkgname\n");
+       if (!pkgname) {
+               ErrPrint("Invalid Request\n");
+               free(uri);
+               return NULL;
+       }
+
+       DbgPrint("URI: %s\n", uri);
+       handle = provider_buffer_acquire(TYPE_PD, pkgname, uri, width, height, sizeof(int), handler, data);
+       DbgPrint("Acquire buffer for PD(%s), %s, %p\n", pkgname, uri, handle);
+       free(uri);
+       return handle;
+}
+
+EAPI int livebox_release_buffer(struct livebox_buffer *handle)
+{
+       if (!handle)
+               return -EINVAL;
+
+       DbgPrint("Release buffer\n");
+       return provider_buffer_release(handle);
+}
+
+EAPI void *livebox_ref_buffer(struct livebox_buffer *handle)
+{
+       if (!handle)
+               return -EINVAL;
+
+       DbgPrint("Ref buffer\n");
+       return provider_buffer_ref(handle);
+}
+
+EAPI int livebox_unref_buffer(void *buffer)
+{
+       if (!buffer)
+               return -EINVAL;
+
+       DbgPrint("Unref buffer\n");
+       return provider_buffer_unref(buffer);
+}
+
+EAPI int livebox_sync_buffer(struct livebox_buffer *handle)
+{
+       const char *pkgname;
+       const char *id;
+
+       if (!handle)
+               return -EINVAL;
+
+       pkgname = provider_buffer_pkgname(handle);
+       id = provider_buffer_id(handle);
+       if (!pkgname || !id) {
+               ErrPrint("Invalid buffer handler\n");
+               return -EINVAL;
+       }
+
+       DbgPrint("Sync buffer\n");
+       provider_buffer_sync(handle);
+       provider_send_desc_updated(pkgname, id, NULL);
+       return 0;
 }
 
 /* End of a file */