Use dynamic loading to load feedback library.
authorSanghyup Lee <sh53.lee@samsung.com>
Mon, 1 Jul 2013 02:08:36 +0000 (11:08 +0900)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Mon, 1 Jul 2013 05:46:31 +0000 (05:46 +0000)
[Title] Use dynamic loading to load feedback library.
[Issue#] N/A
[Problem] Feedback library have a potential problem about constructor.
[Cause] N/A
[Solution] To avoid feedback library dependency, use dynamic loading.

Change-Id: Ib29a56ca0374207b6137334fba4c5285f280a9dd

Source/WebCore/PlatformTizen.cmake
Source/WebCore/platform/efl/tizen/TizenLinkEffect.cpp
Source/cmake/Findfeedback.cmake

index 60e8a96..622cd75 100755 (executable)
@@ -46,7 +46,6 @@ LIST(APPEND WebCore_LIBRARIES
     ${Pmapi_LIBRARIES}
     ${SESSION_LIBRARIES}
     ${VConf_LIBRARIES}
-    ${feedback_LIBRARY}
 )
 
 LIST(APPEND WebCore_USER_AGENT_STYLE_SHEETS
index 2b8222a..6158a09 100644 (file)
 #include "config.h"
 #include "TizenLinkEffect.h"
 
+#if ENABLE(TIZEN_LINK_EFFECT)
 #include "feedback.h"
+#include <dlfcn.h>
 
-#if ENABLE(TIZEN_LINK_EFFECT)
 namespace WebCore {
 
+static int (*feedback_initialize)();
+static int (*feedback_play)(int);
+static int (*feedback_deinitialize)();
+
+static void* getHandle()
+{
+    void* handle = dlopen("libfeedback.so.0", RTLD_NOW);
+    if (!handle)
+        return 0;
+
+    feedback_initialize = (int(*)(void))dlsym(handle, "feedback_initialize");
+    if (!feedback_initialize) {
+        dlclose(handle);
+        return 0;
+    }
+
+    feedback_play = (int(*)(int))dlsym(handle, "feedback_play");
+    if (!feedback_play) {
+        dlclose(handle);
+        return 0;
+    }
+
+    feedback_deinitialize = (int(*)(void))dlsym(handle, "feedback_deinitialize");
+    if (!feedback_deinitialize) {
+        dlclose(handle);
+        return 0;
+    }
+
+    return handle;
+}
+
 void TizenLinkEffect::playLinkEffect()
 {
+    static void* handle = getHandle();
+
+    if (!handle)
+        return;
+
     feedback_initialize();
     feedback_play(FEEDBACK_PATTERN_TAP);
     feedback_deinitialize();
index 6d2b5c9..28c8f8b 100644 (file)
@@ -3,7 +3,6 @@
 #
 #  feedback_FOUND - system has feedback
 #  feedback_INCLUDE_DIRS - the feedback include directories
-#  feedback_LIBRARIES - link these to use feedback
 
 include(LibFindMacros)
 
@@ -17,14 +16,5 @@ find_path(feedback_INCLUDE_DIR
   PATH_SUFFIXES feedback
 )
 
-# Finally the library itself
-find_library(feedback_LIBRARY
-  NAMES feedback
-  PATHS ${feedback_PKGCONF_LIBRARY_DIRS}
-)
-
-# Set the include dir variables and the libraries and let libfind_process do the rest.
-# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
+# Set the include dir variables.
 set(feedback_PROCESS_INCLUDES feedback_INCLUDE_DIR feddback_INCLUDE_DIRS)
-set(feedback_PROCESS_LIBS feedback_LIBRARY feedback_LIBRARIES)
-libfind_process(libfeedback)