Switch to gmodule from linux dl functions 55/67755/2
authorMu-Woong Lee <muwoong.lee@samsung.com>
Thu, 28 Apr 2016 07:31:05 +0000 (16:31 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Thu, 28 Apr 2016 07:45:55 +0000 (16:45 +0900)
Change-Id: I09541f9cf01581796a6b724287e4e7b6a1953b76
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
CMakeLists.txt
packaging/context-service.spec
src/ProviderLoader.cpp
src/ProviderLoader.h

index 9c142e7..5ee65eb 100644 (file)
@@ -11,6 +11,7 @@ MESSAGE("Sources: ${SRCS}")
 
 # Dependencies
 SET(DEPS
+       gmodule-2.0
        vconf
        capi-system-info
        capi-system-device
@@ -43,7 +44,7 @@ FOREACH(flag ${daemon_pkg_CFLAGS})
 ENDFOREACH(flag)
 
 ADD_EXECUTABLE(${target} ${SRCS})
-TARGET_LINK_LIBRARIES(${target} ${daemon_pkg_LDFLAGS} -ldl)
+TARGET_LINK_LIBRARIES(${target} ${daemon_pkg_LDFLAGS})
 
 # Installing Daemon
 INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_BINDIR})
index 5495f55..091dfb2 100644 (file)
@@ -16,6 +16,7 @@ ExcludeArch: %{arm} aarch64 %ix86 x86_64
 
 BuildRequires: cmake
 BuildRequires: sed
+BuildRequires: pkgconfig(gmodule-2.0)
 BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(capi-system-info)
 BuildRequires: pkgconfig(capi-system-device)
index b84ae93..10006a3 100644 (file)
@@ -14,7 +14,6 @@
  * limitations under the License.
  */
 
-#include <dlfcn.h>
 #include <set>
 #include <Types.h>
 #include <ContextProvider.h>
@@ -57,21 +56,24 @@ ContextProvider* ProviderLoader::__load(const char *soPath, const char *subject)
 {
        _SI("Load '%s' from '%s'", subject, soPath);
 
-       __soHandle = dlopen(soPath, RTLD_LAZY | RTLD_GLOBAL);
-       IF_FAIL_RETURN_TAG(__soHandle, NULL, _E, "%s", dlerror());
+       __soHandle = g_module_open(soPath, G_MODULE_BIND_LAZY);
+       IF_FAIL_RETURN_TAG(__soHandle, NULL, _E, "%s", g_module_error());
 
-       create_t create = reinterpret_cast<create_t>(dlsym(__soHandle, "create"));
-       if (!create) {
-               _E("%s", dlerror());
-               dlclose(__soHandle);
+       gpointer symbol;
+
+       if (!g_module_symbol(__soHandle, "create", &symbol) || symbol == NULL) {
+               _E("%s", g_module_error());
+               g_module_close(__soHandle);
                __soHandle = NULL;
                return NULL;
        }
 
+       create_t create = reinterpret_cast<create_t>(symbol);
+
        ContextProvider *prvd = create(subject);
        if (!prvd) {
                _W("No provider for '%s'", subject);
-               dlclose(__soHandle);
+               g_module_close(__soHandle);
                __soHandle = NULL;
                return NULL;
        }
@@ -84,7 +86,7 @@ void ProviderLoader::__unload()
        if (!__soHandle)
                return;
 
-       dlclose(__soHandle);
+       g_module_close(__soHandle);
        __soHandle = NULL;
 }
 
index 1eb303d..ab5a427 100644 (file)
@@ -17,6 +17,7 @@
 #ifndef _CONTEXT_PROVIDER_LOADER_H_
 #define _CONTEXT_PROVIDER_LOADER_H_
 
+#include <gmodule.h>
 #include <map>
 
 namespace ctx {
@@ -53,7 +54,7 @@ namespace ctx {
                ContextProvider* __load(const char *soPath, const char *subject);
                void __unload();
 
-               void *__soHandle;
+               GModule *__soHandle;
                static ProviderLibMap __providerLibMap;
        };