From: Sung-jae Park Date: Wed, 22 Aug 2012 00:00:58 +0000 (+0900) Subject: Add live-viewer X-Git-Tag: submit/tizen_mobile/20150527.071719~1^2~30^2~14^2~125 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3ee2d41ff65e30f4300bf40eb7dade8f643cb177;p=platform%2Fcore%2Fappfw%2Fwidget-viewer.git Add live-viewer Change-Id: I3a938ba5f34410f91824de164fcca669e925144f --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 79acd4a..e406b02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,5 +58,3 @@ 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-viewer_PG.h DESTINATION /usr/share/doc/${PROJECT_NAME}) - -#ADD_SUBDIRECTORY(live-viewer) diff --git a/debian/liblivebox-viewer.install.in b/debian/liblivebox-viewer.install.in index bf766f0..b853589 100644 --- a/debian/liblivebox-viewer.install.in +++ b/debian/liblivebox-viewer.install.in @@ -1 +1,2 @@ @PREFIX@/lib/*.so* +@PREFIX@/bin/* diff --git a/live-viewer/CMakeLists.txt b/live-viewer/CMakeLists.txt new file mode 100644 index 0000000..2499bbb --- /dev/null +++ b/live-viewer/CMakeLists.txt @@ -0,0 +1,45 @@ +PROJECT(live-viewer CXX) +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "/${prefix}/bin") +SET(PROJECT_NAME "${PROJECT_NAME}") +SET(VERSION_MAJOR 0) +SET(VERSION "${VERSION_MAJOR}.0.1") + +set(CMAKE_SKIP_BUILD_RPATH true) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/live-viewer/include) + +INCLUDE(FindPkgConfig) +pkg_check_modules(livepkgs REQUIRED + dlog + ail + elementary + eocre-x + appcore-efl + glib-2.0 + gio-2.0 + livebox-viewer +) + +FOREACH(flag ${livepkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -Werror -Winline -g") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${livepkgs_LDFLAGS}) +ADD_EXECUTABLE(${PROJECT_NAME} SHARED + src/CLiveBox.cpp + src/CLiveBoxMgr.cpp + src/CMain.cpp + src/CResourceMgr.cpp + src/CUtil.cpp + src/dlist.cpp +) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) + +ADD_SUBDIRECTORY(res) diff --git a/live-viewer/include/CLiveBox.h b/live-viewer/include/CLiveBox.h new file mode 100644 index 0000000..9ed9c29 --- /dev/null +++ b/live-viewer/include/CLiveBox.h @@ -0,0 +1,32 @@ +class CLiveBox { +public: + CLiveBox(const char *pkgname, const char *content, const char *cluster, const char *category, double period); + CLiveBox(struct livebox *handler); + virtual ~CLiveBox(void); + + void OnCreate(struct livebox *handler); + + void OnUpdateLB(void); + void OnUpdatePD(void); + + void OnPeriodChanged(void); + void OnGroupChanged(void); + void OnPinupChanged(void); + + void SetHandler(struct livebox *handler) { m_pHandler = handler; } + struct livebox *Handler(void) { return m_pHandler; } + + int CreatePD(void); + int DestroyPD(void); + +private: + static int m_OnCreate(void); + + struct livebox *m_pHandler; + + Evas_Object *m_pIconSlot; + Evas_Object *m_pLBImage; + Evas_Object *m_pPDImage; +}; + +/* End of a file */ diff --git a/live-viewer/include/CLiveBoxMgr.h b/live-viewer/include/CLiveBoxMgr.h new file mode 100644 index 0000000..78d7191 --- /dev/null +++ b/live-viewer/include/CLiveBoxMgr.h @@ -0,0 +1,11 @@ +class CLiveBoxMgr { +public: + CLiveBoxMgr(void); + virtual ~CLiveBoxMgr(void); + + static int OnEvent(struct livebox *handler, const char *event, void *data); + static int OnFaultEvent(const char *event, const char *pkgname, const char *id, const char *funcname, void *data); + +private: + static struct dlist *s_pBoxList; +}; diff --git a/live-viewer/include/CMain.h b/live-viewer/include/CMain.h new file mode 100644 index 0000000..a39b106 --- /dev/null +++ b/live-viewer/include/CMain.h @@ -0,0 +1,24 @@ +class CMain +{ +public: + CMain(); + virtual ~CMain(); + + static int OnCreate(void *_this); + static int OnTerminate(void *_this); + static int OnPause(void *_this); + static int OnResume(void *_this); + static int OnReset(bundle *b, void *_this); + +private: + int m_OnCreate(void); + int m_OnTerminate(void); + int m_OnPause(void); + int m_OnResume(void); + int m_OnReset(bundle *b); + + int m_fVerbose; + CLiveBoxMgr *m_pLiveBoxMgr; +}; + +/* End of a file */ diff --git a/live-viewer/include/CResourceMgr.h b/live-viewer/include/CResourceMgr.h new file mode 100644 index 0000000..30cc7df --- /dev/null +++ b/live-viewer/include/CResourceMgr.h @@ -0,0 +1,15 @@ +class CResourceMgr { +public: + static CResourceMgr *GetInstance(void); + + int RegisterObject(const char *tag, void *data); + void *UnregisterObject(const char *tag); + void *GetObject(const char *tag); + +private: + CResourceMgr(void); + virtual ~CResourceMgr(void); + + static CResourceMgr *m_pInstance; + struct dlist *m_pList; +}; diff --git a/live-viewer/include/CUtil.h b/live-viewer/include/CUtil.h new file mode 100644 index 0000000..019cbf4 --- /dev/null +++ b/live-viewer/include/CUtil.h @@ -0,0 +1,29 @@ +#if defined(LOG_TAG) +#undef LOG_TAG +#define LOG_TAG "live-viewer" +#endif + +#if !defined(FLOG) +#define DbgPrint(format, arg...) LOGD("[%s/%s:%d] " format, util_basename(__FILE__), __func__, __LINE__, ##arg) +#define ErrPrint(format, arg...) LOGE("[%s/%s:%d] " format, util_basename(__FILE__), __func__, __LINE__, ##arg) +#else +extern FILE *__file_log_fp; +#define DbgPrint(format, arg...) do { fprintf(__file_log_fp, "[LOG] [%s/%s:%d] " format, util_basename(__FILE__), __func__, __LINE__, ##arg); fflush(__file_log_fp); } while (0) + +#define ErrPrint(format, arg...) do { fprintf(__file_log_fp, "[ERR] [%s/%s:%d] " format, util_basename(__FILE__), __func__, __LINE__, ##arg); fflush(__file_log_fp); } while (0) +#endif + +class CUtil { +public: + static char *GetIconFile(const char *pkgname); + static Evas_Object *CreateCanvasImage(Evas_Object *parent, int w, int h); + + static int UpdateCanvasImage(Evas_Object *image, void *data, int w, int h); + static int UpdateCanvasImage(Evas_Object *image, const char *filename, int w, int h); + +private: + /* This class is not able to be instantiated */ + CUtil(void); + virtual ~CUtil(void); +}; + diff --git a/live-viewer/include/dlist.h b/live-viewer/include/dlist.h new file mode 100644 index 0000000..5c583e6 --- /dev/null +++ b/live-viewer/include/dlist.h @@ -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); (l) && ((data) = dlist_data(l)); (l) = dlist_next(l)) + +#define dlist_foreach_safe(list, l, n, data) \ + for ((l) = (list), (n) = dlist_next(l); \ + (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/live-viewer/res/CMakeLists.txt b/live-viewer/res/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/live-viewer/res/icon_slot.edc b/live-viewer/res/icon_slot.edc new file mode 100644 index 0000000..e69de29 diff --git a/live-viewer/src/CLiveBox.cpp b/live-viewer/src/CLiveBox.cpp new file mode 100644 index 0000000..b21ca0c --- /dev/null +++ b/live-viewer/src/CLiveBox.cpp @@ -0,0 +1,415 @@ +#include + +#include + +#include "dlist.h" + +#include "CUtil.h" +#include "CResourceMgr.h" +#include "CLiveBox.h" + +static void s_OnEdjeEvent(void *data, Evas_Object *obj, const char *emission, const char *source) +{ + CLiveBox *box = data; + struct livebox *handler; + + handler = box->Handler(); + DbgPrint("handler[%p] emission[%s] source[%s]\n", handler, emission, source); +} + +static void s_OnLBMouseDown(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + Evas_Event_Mouse_Down *down = event_info; + CLiveBox *box = (CLiveBox *)data; + struct livebox *handler; + int ix, iy, iw, ih; + double rx; + double ry; + + handler = box->Handler(); + if (!handler) + return; + + evas_object_geometry_get(obj, &ix, &iy, &iw, &ih); + + rx = (double)(down->canvas.x - ix) / (double)iw; + ry = (double)(down->canvas.y - iy) / (double)ih; + + livebox_content_event(handler, LB_MOUSE_DOWN, rx, ry); +} + +static void s_OnLBMouseMove(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + Evas_Event_Mouse_Move *move = event_info; + CLiveBox *box = (CLiveBox *)data; + struct livebox *handler; + int ix, iy, iw, ih; + double rx, ry; + + handler = box->Handler(); + if (!handler) + return; + + evas_object_geometry_get(obj, &ix, &iy, &iw, &ih); + + rx = (double)(move->cur.canvas.x - ix) / (double)iw; + ry = (double)(move->cur.canvas.y - iy) / (double)ih; + + livebox_content_event(handler, LB_MOUSE_MOVE, rx, ry); +} + +static void s_OnLBMouseUp(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + Evas_Event_Mouse_Up *up = event_info; + CLiveBox *box = (CLiveBox *)data; + struct livebox *handler; + int ix, iy, iw, ih; + double rx, ry; + + handler = box->Handler(); + if (!handler) + return; + + evas_object_geometry_get(obj, &ix, &iy, &iw, &ih); + + rx = (double)(up->canvas.x - ix) / (double)iw; + ry = (double)(up->canvas.y - iy) / (double)ih; + + livebox_content_event(handler, LB_MOUSE_UP, rx, ry); +} + +static void s_OnPDMouseDown(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + Evas_Event_Mouse_Down *down = event_info; + CLiveBox *box = (CLiveBox *)data; + struct livebox *handler; + int ix, iy, iw, ih; + double rx; + double ry; + + handler = box->Handler(); + if (!handler) + return; + + evas_object_geometry_get(obj, &ix, &iy, &iw, &ih); + + rx = (double)(down->canvas.x - ix) / (double)iw; + ry = (double)(down->canvas.y - iy) / (double)ih; + + livebox_content_event(handler, PD_MOUSE_DOWN, rx, ry); +} + +static void s_OnPDMouseMove(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + Evas_Event_Mouse_Move *move = event_info; + CLiveBox *box = (CLiveBox *)data; + struct livebox *handler; + int ix, iy, iw, ih; + double rx, ry; + + handler = box->Handler(); + if (!handler) + return; + + evas_object_geometry_get(obj, &ix, &iy, &iw, &ih); + + rx = (double)(move->cur.canvas.x - ix) / (double)iw; + ry = (double)(move->cur.canvas.y - iy) / (double)ih; + + livebox_content_event(handler, PD_MOUSE_MOVE, rx, ry); +} + +static void s_OnPDMouseUp(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + Evas_Event_Mouse_Up *up = event_info; + CLiveBox *box = (CLiveBox *)data; + struct livebox *handler; + int ix, iy, iw, ih; + double rx, ry; + + handler = box->Handler(); + if (!handler) + return; + + evas_object_geometry_get(obj, &ix, &iy, &iw, &ih); + + rx = (double)(up->canvas.x - ix) / (double)iw; + ry = (double)(up->canvas.y - iy) / (double)ih; + + livebox_content_event(handler, PD_MOUSE_UP, rx, ry); +} + +static void s_OnCreate(struct livebox *handle, int ret, void *data) +{ + CLiveBox *box; + + box = (CLiveBox *)data; + if (!box) { + ErrPrint("Unknown livebox\n"); + return; + } + + DbgPrint("Live box CREATE returns %d\n", ret); + if (ret < 0) { + delete box; + } else { + if (box->OnCreate(handle) < 0) + delete box; + } +} + +CLiveBox::CLiveBox(const char *pkgname, const char *content, const char *cluster, const char *category, double period) +: m_pHandler(NULL) +, m_pIconSlot(NULL) +, m_pLBImage(NULL) +, m_pPDImage(NULL) +{ + struct livebox *handler; + handler = livebox_add(pkgname, content, cluster, category, period, s_OnCreate, this); + if (!handler) /* Do not set this as a m_pHandler */ + throw EFAULT; +} + +CLiveBox::~CLiveBox(void) +{ + if (m_pIconSlot) { + Evas_Object *image; + + image = elm_object_part_content_unset(m_pIconSlot, "livebox"); + if (image != m_pLBImage) { + DbgPrint("Something goes to wrong :(\n"); + if (image) + evas_object_del(image); + } + + image = elm_object_part_content_unset(m_pIconSlot, "pd"); + if (image != m_pPDImage) { + DbgPrint("Something goes to wrong :(\n"); + if (image) + evas_object_del(image); + } + + evas_object_del(m_pIconSlot); + } + + if (m_pLBImage) + evas_object_del(m_pLBImage); + + if (m_pPDImage) + evas_object_del(m_pPDImage); + + if (m_pHandler) + livebox_del(m_pHandler, NULL, NULL); +} + +CLiveBox::CLiveBox(struct livebox *handler) +: m_pHandler(handler) +{ + if (m_OnCreate() < 0) + throw EFAULT; + + livebox_set_data(m_pHandler, this); +} + +int CLiveBox::CreatePD(void) +{ + if (m_pPDImage) { + DbgPrint("PD is already created\n"); + return 0; + } + + m_pPDImage = CUtil::CreateCanvasImage(w, h >> 1); + if (!m_pPDImage) + return -EFAULT; + + evas_object_event_callback_add(m_pPDImage, EVAS_CALLBACK_MOUSE_DOWN, s_OnPDMouseDown, this); + evas_object_event_callback_add(m_pPDImage, EVAS_CALLBACK_MOUSE_MOVE, s_OnPDMouseMove, this); + evas_object_event_callback_add(m_pPDImage, EVAS_CALLBACK_MOUSE_UP, s_OnPDMouseUp, this); + + elm_object_part_content_set(m_pIconSlot, "pd", m_pPDImage); + + return OnUpdatePD(); +} + +int CLiveBox::DestroyPD(void) +{ + Evas_Object *pd; + + pd = elm_object_part_content_unset(m_pIconSlot, "pd"); + if (pd != m_pPDImage) { + DbgPrint("Swallowed object is not matched\n"); + if (m_pPDImage) + evas_object_del(m_pPDImage); + } + + if (pd) + evas_object_del(pd); + + m_pPDImage = NULL; + return 0; +} + +int CLiveBox::OnCreate(struct livebox *handler) +{ + int ret; + + m_pHandler = handler; + livebox_set_data(m_pHandler, this); + + ret = m_OnCreate(); + if (ret < 0) { + livebox_set_data(m_pHandler, NULL); + /*! + * \note + * Keep the m_pHandler to delete it from the destructor + */ + } + + return ret; +} + +void CLiveBox::OnUpdateLB(void) +{ + int w; + int h; + char size_str[] = "size_0000x0000"; + + if (!m_pIconSlot || !m_pLBImage) + return -EFAULT; + + if (livebox_get_size(m_pHandler, &w, &h) < 0) + return -EFAULT; + + if (w < 0 || h < 0) + return -EINVAL; + + if ((w / 1000) || (h / 1000)) + return -EINVAL; + + if (w == 0 && h == 0) + return 0; + + if (livebox_lb_type(m_pHandler) == LB_TYPE_BUFFER) { + void *data; + + data = livebox_acquire_fb(m_pHandler); + if (!data) + return 0; + + CUtil::UpdateCanvasImage(m_pLBImage, data, w, h); + + livebox_release_fb(data); + } else { + const char *filename; + + filename = livebox_filename(m_pHandler); + if (!filename) + return 0; + + CUtil::UpdateCanvasImage(m_pLBImage, filename, w, h); + } + + snprintf(size_str, "size_%dx%d", w, h); + DbgPrint("Size string: %s\n", size_str); + + edje_object_signal_emit(elm_layout_edje_get(m_pIconSlot), size_str, "lb,resize,to"); + return 0; +} + +void CLiveBox::OnUpdatePD(void) +{ + int w; + int h; + char size_str[] = "size_0000x0000"; + + if (!m_pPDImage) + return -EFAULT; + + if (livebox_get_pdsize(m_pHandler, &w, &h) < 0) + return -EFAULT; + + if (w < 0 || h < 0) + return -EINVAL; + + if ((w / 1000) || (h / 1000)) + return -EINVAL; + + if (w == 0 && h == 0) + return 0; + + if (livebox_pd_type(m_pHandler) == PD_TYPE_BUFFER) { + void *data; + + data = livebox_acquire_pdfb(m_pHandler); + if (!data) + return 0; + CUtil::UpdateCanvasImage(m_pPDImage, data, w, h); + livebox_release_pdfb(data); + } else { + ErrPrint("Unsupported media format\n"); + } + + return 0; +} + +void CLiveBox::OnPeriodChanged(void) +{ +} + +void CLiveBox::OnGroupChanged(void) +{ +} + +void CLiveBox::OnPinupChanged(void) +{ +} + +int CLiveBox::m_OnCreate(void) +{ + Evas_Object *win; + int w; + int h; + + win = CResourceMgr::GetInstance()->GetObject("window"); + if (!win) + return -EFAULT; + + evas_object_geometry_get(win, NULL, NULL, &w, &h); + + m_pIconSlot = elm_layout_add(win); + if (!m_pIconSlot) { + ErrPrint("Failed to append a new layout\n"); + return -EFAULT; + } + + if (!elm_layout_file_set(m_pIconSlot, "/usr/share/live-viewer/icon_slot.edj", "icon,slot")) { + ErrPrint("Failed to load an icon slot EDJE\n"); + evas_object_del(m_pIconSlot); + m_pIconSlot = NULL; + return -EIO; + } + + edje_object_signal_callback_add(elm_layout_edje_get(m_pIconSlot), "*", "*", s_OnEdjeEvent, this); + + m_pLBImage = CUtil::CreateCanvasImage(w, h >> 1); + if (!m_pLBImage) { + evas_object_del(m_pIconSlot); + m_pIconSlot = NULL; + return -EFAULT; + } + + evas_object_event_callback_add(m_pLBImage, EVAS_CALLBACK_MOUSE_DOWN, s_OnLBMouseDown, this); + evas_object_event_callback_add(m_pLBImage, EVAS_CALLBACK_MOUSE_MOVE, s_OnLBMouseMove, this); + evas_object_event_callback_add(m_pLBImage, EVAS_CALLBACK_MOUSE_UP, s_OnLBMouseUp, this); + + elm_object_part_content_set(m_pIconSlot, "livebox", m_pLBImage); + + evas_object_move(m_pIconSlot, 0, 0); + evas_object_resize(m_pIconSlot, w, (h >> 1)); + evas_object_show(m_pIconSlot); + + /* Try to update content */ + return OnUpdateLB(); +} + +/* End of a file */ diff --git a/live-viewer/src/CLiveBoxMgr.cpp b/live-viewer/src/CLiveBoxMgr.cpp new file mode 100644 index 0000000..e69db43 --- /dev/null +++ b/live-viewer/src/CLiveBoxMgr.cpp @@ -0,0 +1,109 @@ +#include + +#include +#include + +#include "dlist.h" +#include "CUtil.h" +#include "CLiveBox.h" +#include "CLiveBoxMgr.h" + +struct dlist *CLiveBoxMgr::s_pBoxList = NULL; + +CLiveBoxMgr::CLiveBoxMgr(void) +{ + livebox_init(); +} + +CLiveBoxMgr::~CLiveBoxMgr(void) +{ + struct dlist *l; + struct dlist *n; + CLiveBox *box; + + dlist_foreach_safe(s_pBoxList, l, n, box) { + s_pBoxList = dlist_remove(m_pBox_list, box); + delete box; + } + + livebox_fini(); +} + +int CLiveBoxMgr::OnEvent(struct livebox *handler, const char *event, void *data) +{ + CLiveBox *box; + int ret; + + if (!strcmp(event, "lb,created")) { + try { + box = new CLiveBox(handler); + } catch (...) { + return -EFAULT; + } + + s_pBoxList = dlist_append(s_pBoxList, box); + ret = 0; + } else if (!strcmp(event, "lb,updated")) { + box = (CLiveBox *)livebox_get_data(handler); + if (!box) + return -EINVAL; + + ret = box->OnUpdateLB(); + } else if (!strcmp(event, "lb,deleted")) { + box = (CLiveBox *)livebox_get_data(handler); + if (!box) + return -EINVAL; + + s_pBoxList = dlist_remove(s_pBoxList, box); + box->SetHandler(NULL); /* To prevent to delete a livebox again */ + delete box; + ret = 0; + } else if (!strcmp(event, "pd,updated")) { + box = (CLiveBox *)livebox_get_data(handler); + if (!box) + return -EINVAL; + + ret = box->OnUpdatePD(); + } else if (!strcmp(event, "group,changed")) { + box = (CLiveBox *)livebox_get_data(handler); + if (!box) + return -EINVAL; + + ret = box->OnGroupChanged(); + } else if (!strcmp(event, "pinup,changed")) { + box = (CLiveBox *)livebox_get_data(handler); + if (!box) + return -EINVAL; + + ret = box->OnPinupChanged(); + } else if (!strcmp(event, "period,changed")) { + box = (CLiveBox *)livebox_get_data(handler); + if (!box) + return -EINVAL; + + ret = box->OnPeriodChanged(); + } else { + DbgPrint("Unknown event: %s\n", event); + ret = -ENOSYS; + } + + return ret; +} + +int CLiveBoxMgr::OnFaultEvent(const char *event, const char *pkgname, const char *id, const char *funcname, void *data) +{ + ErrPrint("Fault event: %s (%s)\n", event, pkgname); + + if (!strcmp(event, "deactivated")) { + DbgPrint("Instance: %s\n", id); + DbgPrint("Function: %s\n", funcname); + } else if (!strcmp(event, "provider,disconnected")) { + DbgPrint("Provider is disconnected\n"); + } else { + ErrPrint("Unknown event: %s\n", event); + } + + return 0; +} + +/* End of a file */ diff --git a/live-viewer/src/CMain.cpp b/live-viewer/src/CMain.cpp new file mode 100644 index 0000000..694d79e --- /dev/null +++ b/live-viewer/src/CMain.cpp @@ -0,0 +1,171 @@ +#include +#include + +#include +#include + +#include + +#include "dlist.h" +#include "CUtil.h" +#include "CResourceMgr.h" +#include "CLiveBoxMgr.h" +#include "CMain.h" + +int errno; + +CMain::CMain() +: m_fVerbose(0) +, m_pLiveBoxMgr(NULL) +{ +} + +CMain::~CMain() +{ +} + +int CMain::OnCreate(void *_this) +{ + CMain *inst = _this; + if (!inst) + return -EINVAL; + + return inst->m_OnCreate(); +} + +int CMain::OnTerminate(void *_this) +{ + CMain *inst = _this; + if (!inst) + return -EINVAL; + + return inst->m_OnTerminate(); +} + +int CMain::OnPause(void *_this) +{ + CMain *inst = _this; + if (!inst) + return -EINVAL; + + return inst->m_OnPause(); +} + +int CMain::OnResume(void *_this) +{ + CMain *inst = _this; + if (!inst) + return -EINVAL; + + return inst->m_OnResume(); +} + +int CMain::OnReset(bundle *b, void *_this) +{ + CMain *inst = _this; + if (!inst) + return -EINVAL; + + return inst->m_OnReset(b); +} + +int CMain::m_OnCreate(void) +{ + Evas_Object *win; + int w; + int h; + + /* Getting the entire screen(root window) size */ + ecore_x_window_size_get(0, &w, &h); + + win = elm_win_add("Live viewer", ELM_WIN_BASIC); + if (!win) { + ErrPrint("Failed to create a new window\n"); + return -EFAULT; + } + evas_object_move(win, 0, 0); + evas_object_resize(win, w, h); + evas_object_show(win); + + try { + m_pLiveBoxMgr = new CLiveBoxMgr(); + } catch (...) { + ErrPrint("Failed to allocate a new livebox manager\n"); + evas_object_del(win); + return -EFAULT; + } + + CResourceMgr::GetInstance()->RegisterObject("window", win); + return 0; +} + +int CMain::m_OnTerminate(void) +{ + Evas_Object *win; + + delete m_pLiveBoxMgr; + + win = CResourceMgr::GetInstance()->UnregisterObject("window"); + if (win) + evas_object_del(win); + + return 0; +} + +int CMain::m_OnPause(void) +{ + return 0; +} + +int CMain::m_OnResume(void) +{ + return 0; +} + +int CMain::m_OnReset(bundle *b) +{ + const char *tmp; + const char *pkgname; + const char *cluster; + const char *category; + const char *content; + double period; + + pkgname = bundle_get_val(b, "pkgname"); + if (!pkgname) { + DbgPrint("reset ignored\n"); + return 0; + } + + cluster = bundle_get_val(b, "cluster"); + if (!cluster) + cluster = "user,created"; + + category = bundle_get_val(b, "category"); + if (!category) + category = "default"; + + content = bundle_get_val(b, "content"); + if (!content) + content = NULL; + + tmp = bundle_get_val(b, "verbose"); + if (!tmp || sscanf(tmp, "%d", &m_fVerbose) != 1) + m_fVerbose = 0; + + tmp = bundle_get_val(b, "period"); + if (!tmp || sscanf(tmp, "%lf", &period) != 1) + period = DEFAULT_PERIOD; + + DbgPrint("App reset (dump info)\n"); + DbgPrint("pkgname: %s\n", pkgname); + DbgPrint("cluster: %s\n", cluster); + DbgPrint("category: %s\n", category); + DbgPrint("content: %s\n", content); + DbgPrint("period: %lf\n", period); + DbgPrint("verbose: %d\n", m_fVerbose); + + return 0; +} + +/* End of a file */ diff --git a/live-viewer/src/CResourceMgr.cpp b/live-viewer/src/CResourceMgr.cpp new file mode 100644 index 0000000..608bca3 --- /dev/null +++ b/live-viewer/src/CResourceMgr.cpp @@ -0,0 +1,102 @@ +#include + +#include + +#include "dlist.h" + +#include "CUtil.h" +#include "CResourceMgr.h" + +int errno; + +struct item_info { + item_info(const char *tag, void *data) { + this->tag = strdup(tag); + if (!this->tag) { + ErrPrint("Heap: %s\n", strerror(errno)); + throw -ENOMEM; + } + + this->data = data; + } + + virtual ~item_info() { free(this->tag); } + + char *tag; + void *data; +}; + +CResourceMgr *CResourceMgr::m_pInstance = NULL; + +CResourceMgr::CResourceMgr *GetInstance(void) +{ + if (!CResourceMgr::m_pInstance) + CResourceMgr::m_pInstance = new CResourceMgr(); + + return CResourceMgr::m_pInstance; +} + +CResourceMgr::CResourceMgr(void) +: m_pList(NULL) +{ +} + +CResourceMgr::~CResourceMgr(void) +{ +} + +int CResourceMgr::RegisterObject(const char *tag, void *data) +{ + struct item *info; + + if (!data || !tag) + return -EINVAL; + + if (GetObject(tag)) + return -EEXIST; + + try { + info = new item(tag, data); + } catch (...) { + ErrPrint("Failed to allocate a new item\n"); + return -EFAULT; + } + + m_pList = dlist_append(m_pList, info); + return 0; +} + +void *CResourceMgr::UnregisterObject(const char *tag) +{ + struct dlist *l; + struct dlist *n; + struct item *info; + void *ret; + + dlist_foreach_safe(m_pList, l, n, info) { + if (!strcmp(info->tag, tag)) { + m_pList = dlist_remove(m_pList, info); + ret = info->data; + delete info; + + return ret; + } + } + + return NULL; +} + +void *CResourceMgr::GetObject(const char *tag) +{ + struct dlist *l; + struct item *info; + + dlist_foreach(m_pList, l, info) { + if (!strcmp(info->tag, tag)) + return info->data; + } + + return NULL; +} + +/* End of a file */ diff --git a/live-viewer/src/CUtil.cpp b/live-viewer/src/CUtil.cpp new file mode 100644 index 0000000..93489aa --- /dev/null +++ b/live-viewer/src/CUtil.cpp @@ -0,0 +1,93 @@ +#include + +#include +#include + +#include "dlist.h" +#include "CUtil.h" + +CUtil::CUtil(void) +{ +} + +CUtil::~CUtil(void) +{ +} + +char *CUtil::GetIconFile(const char *pkgname) +{ + ail_appinfo_h handle; + ail_error_e ret; + char *iconfile; + char *ret_iconfile; + + ret = ail_package_get_appinfo(pkgname, &handle); + if (ret != AIL_ERROR_OK) { + ErrPrint("ail get pkgname = %s\n", pkgname); + return NULL; + } + + ret = ail_appinfo_get_str(handle, AIL_PROP_ICON_STR, &iconfile); + if (ret != AIL_ERROR_OK) { + ret = ail_package_destroy_appinfo(handle); + ErrPrint("Get iconfile from pkgname = %s\n", pkgname); + return NULL; + } + + ret_iconfile = strdup(iconfile); + if (!ret_iconfile) + ErrPrint("Error: %s\n", strerror(errno)); + + ret = ail_package_destroy_appinfo(handle); + if (ret != AIL_ERROR_OK) { + if (ret_iconfile) + free(ret_iconfile); + ErrPrint("Failed to destory appinfo\n"); + return NULL; + } + + return ret_iconfile; +} + +Evas_Object *CUtil::CreateCanvasImage(Evas_Object *parent, int w, int h) +{ + Evas_Object *pCanvasImage; + pCanvasImage = evas_object_image_filled_add(evas_object_get_evas(parent)); + if (!pCanvasImage) + return NULL; + + evas_object_image_colorspace_set(pCanvasImage, EVAS_COLORSPACE_ARGB8888); + evas_object_image_alpha_set(pCanvasImage, EINA_TRUE); + + evas_object_move(pCanvasImage, 0, 0); + evas_object_resize(pCanvasImage, w, h); + + return pCanvasImage; +} + +int CUtil::UpdateCanvasImage(Evas_Object *image, void *data, int w, int h) +{ + evas_object_image_size_set(image, w, h); + evas_object_image_fill_set(image, 0, 0, w, h); + evas_object_data_copy_set(image, data); + evas_object_image_data_update_add(image, 0, 0, w, h); + + evas_object_resize(image, w, h); + return 0; +} + +int CUtil::UpdateCanvasImage(Evas_Object *image, const char *filename, int w, int h) +{ + const char *pOldFilename; + + evas_object_image_file_get(image, &pOldFilename); + if (pOldFilename && !strcmp(filename, pOldFilename)) + evas_object_image_reload(image); + else + evas_object_image_file_set(image, filename, NULL); + + evas_object_resize(image, w, h); + return 0; +} + +/*!< End of a file */ diff --git a/live-viewer/src/dlist.cpp b/live-viewer/src/dlist.cpp new file mode 100644 index 0000000..a8ee2d1 --- /dev/null +++ b/live-viewer/src/dlist.cpp @@ -0,0 +1,164 @@ +#include +#include +#include + +#include "dlist.h" + +/*! + * \brief + * This dlist is called Modified Doubly Linked List. + * + * Noramlly, The dobule linked list contains address of previous and next element. + * This dlist also contains them, but the tail element only contains prev address. + * + * The head element's prev pointer indicates the last element. + * But the last element's next pointer indicates NIL. + * + * So we can find the last element while crawling this DList + * But we have to remember the address of the head element. + */ + +struct dlist { + struct dlist *next; + struct dlist *prev; + void *data; +}; + +struct dlist *dlist_append(struct dlist *list, void *data) +{ + struct dlist *item; + + item = (struct dlist *)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 = (struct dlist *)malloc(sizeof(*item)); + if (!item) + return NULL; + + item->data = data; + + if (!list) { + item->prev = item; + item->next = NULL; + } else { + if (list->prev->next) + list->prev->next = item; + + item->prev = list->prev; + item->next = list; + + list->prev = item; + + } + + return item; +} + +struct dlist *dlist_remove(struct dlist *list, struct dlist *l) +{ + if (!list || !l) + return NULL; + + if (l == list) + list = l->next; + else + l->prev->next = l->next; + + if (l->next) + l->next->prev = l->prev; + /*! + * \note + * If the removed entry 'l' has no next element, it is the last element. + * In this case, check the existence of the list first, + * and if the list is not empty, update the 'prev' of the list (which is a head element of the list) + * + * If we didn't care about this, the head element(list) can indicates the invalid element. + */ + else if (list) + list->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; + + i = 0; + for (n = l; n; n = n->next) { + if (i == nth) + return n; + i++; + } + + return NULL; +} + +/* End of a file */ diff --git a/packaging/liblivebox-viewer.spec b/packaging/liblivebox-viewer.spec index 0668785..1996f9d 100644 --- a/packaging/liblivebox-viewer.spec +++ b/packaging/liblivebox-viewer.spec @@ -11,6 +11,7 @@ BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(com-core) +BuildRequires: pkgconfig(elementary) %description Livebox viewer development library @@ -30,15 +31,24 @@ Livebox viewer development library (dev) cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} make %{?jobs:-j%jobs} +cd live-viewer +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} +make %{?jobs:-j%jobs} +cd .. + %install rm -rf %{buildroot} %make_install +cd live-viewer +%make_install +cd .. %post %files %defattr(-,root,root,-) /usr/lib/*.so* +/usr/bin/* %files devel %defattr(-,root,root,-) diff --git a/sample/sample.c b/sample/sample.c index 585798b..68aa083 100644 --- a/sample/sample.c +++ b/sample/sample.c @@ -97,15 +97,15 @@ static void lb_mouse_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_ static void lb_mouse_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) { - Evas_Event_Mouse_Up *up = event_info; + Evas_Event_Mouse_Move *move = event_info; Evas_Coord x, y, w, h; double rx, ry; struct box_info *info = data; evas_object_geometry_get(obj, &x, &y, &w, &h); - rx = (double)(up->canvas.x - x) / (double)w; - ry = (double)(up->canvas.y - y) / (double)h; + rx = (double)(move->canvas.x - x) / (double)w; + ry = (double)(move->canvas.y - y) / (double)h; livebox_content_event(info->handler, LB_MOUSE_MOVE, rx, ry); }