provides library to support unused function for memory issue 11/170311/4
authorSameer Prakash Pradhan <sp.pradhan@samsung.com>
Thu, 12 Jul 2018 10:26:48 +0000 (15:56 +0530)
committerSameer Prakash Pradhan <sp.pradhan@samsung.com>
Thu, 12 Jul 2018 10:26:48 +0000 (15:56 +0530)
phonenumber-utils occupies a large amount of memory because phonenumber-utils provides a function using big size library but the function seems not to be used by inhouse application
so provides library to support unused function for memory issue

Signed-off-by: Gwangbok Kim <gwangbok.kim@samsung.com>
Change-Id: I1acc41fac65d65b66d29c0f260d857599c8333bf

CMakeLists.txt
daemon/CMakeLists.txt
daemon/phnd-dbus.c
daemon/phnd-libphonenumber.cpp [changed mode: 0644->0755]
daemon/phnd-libphonenumber.h
libgeocoding/CMakeLists.txt [new file with mode: 0644]
libgeocoding/phn-libgeocoding.cpp [new file with mode: 0644]
libgeocoding/phn-libgeocoding.h [new file with mode: 0644]
packaging/phonenumber-utils.spec

index 33d60f959c78fdff2dccc2d9826481f7a908dd98..c4efa290881ee612f1d8f2853b7b123762acf3e9 100644 (file)
@@ -17,4 +17,4 @@ ADD_SUBDIRECTORY(common)
 ADD_SUBDIRECTORY(daemon)
 ADD_SUBDIRECTORY(client)
 ADD_SUBDIRECTORY(test)
-
+ADD_SUBDIRECTORY(libgeocoding)
index b84584adf5b1f0359bd2a38142c2203f112c2ef0..f0621e29e3d34ef3b83b625bccc00feb2bddfec7 100644 (file)
@@ -27,7 +27,7 @@ ADD_DEFINITIONS("-D_PHONENUMBER_UTILS_DBUS_SERVER")
 
 ADD_EXECUTABLE(${DAEMON} ${DAEMON_SRCS})
 ADD_DEPENDENCIES(${DAEMON} GENERATED_DBUS_CODE)
-TARGET_LINK_LIBRARIES(${DAEMON} ${daemon_pkgs_LIBRARIES} m phonenumber geocoding)
+TARGET_LINK_LIBRARIES(${DAEMON} ${daemon_pkgs_LIBRARIES} m phonenumber -ldl)
 
 INSTALL(TARGETS ${DAEMON} DESTINATION ${BIN_INSTALL_DIR})
 
index d2a7366585c0ece049bcaa6af8c66501c1544bf4..f3d9584a6e22f6036a2e6e03a864deb036dff3a0 100644 (file)
@@ -371,5 +371,7 @@ unsigned int phnd_dbus_init()
 void phnd_dbus_deinit(unsigned int id)
 {
        g_bus_unown_name(id);
+
+       phn_close_dlopen_handle();
 }
 
old mode 100644 (file)
new mode 100755 (executable)
index 2a31a07..094061d
 #include <stdio.h>
 #include <string.h>
 #include <glib.h>
+#include <dlfcn.h>
 #include <TapiUtility.h>
 #include <ITapiNetwork.h>
 #include <phonenumbers/phonenumberutil.h>
 #include <phonenumbers/asyoutypeformatter.h>
-#include <phonenumbers/geocoding/phonenumber_offline_geocoder.h>
-
 #include "phone_number_errors.h"
 #include "phnd.h"
 #include "phnd-libphonenumber.h"
 
 #define MCC_LEN 3
+#define LIBRARY_PATH "/usr/lib/libphonenumber-utils-geocoding.so"
+
 using namespace i18n::phonenumbers;
 
 typedef struct {
@@ -41,22 +42,30 @@ static int _cc = 0;
 static TapiHandle **_tapi_handle = NULL;
 static int _modem_num = 0;
 static int _phn_get_cc(bool reload, int *out_cc);
+static void *_dlopen_handle = NULL;
 
 int phn_get_location_from_number(const char *number, const char *region,
                const char *language, char **location)
 {
-       PhoneNumber phNumber;
-       const PhoneNumberUtil& pn_instance = *PhoneNumberUtil::GetInstance();
-       const PhoneNumberUtil::ErrorType status = pn_instance.Parse(
-                       number, region, &phNumber);
-       RETVM_IF(status != PhoneNumberUtil::NO_PARSING_ERROR, PHONE_NUMBER_ERROR_NO_DATA,
-                       "PhoneNumberUtil::Parse() Fail(%d)", status);
+       if (NULL == _dlopen_handle) {
+               _dlopen_handle = dlopen(LIBRARY_PATH, RTLD_LAZY);
+               if (!_dlopen_handle) {
+                       fprintf(stderr, "%s\n", dlerror());
+                       exit(1);
+               }
+       }
+
+       typedef int (*func_t) (const char *number, const char *region, const char *language, char **location);
+       func_t phn_geocoding_get_location_from_number = (func_t) dlsym(_dlopen_handle, "phn_geocoding_get_location_from_number");
+       char *error;
+       if ((error = dlerror()) != NULL)  {
+               fprintf(stderr, "%s\n", error);
+               exit(1);
+       }
 
-       std::string description = PhoneNumberOfflineGeocoder().GetDescriptionForNumber(phNumber,
-                       icu::Locale(language));
-       *location = g_strdup((gchar *)description.c_str());
+       int result = phn_geocoding_get_location_from_number(number, region, language, location);
 
-       return PHONE_NUMBER_ERROR_NONE;
+       return result;
 }
 
 int phn_get_formatted_number(const char *number, const char *region,
@@ -76,6 +85,14 @@ int phn_get_formatted_number(const char *number, const char *region,
        return PHONE_NUMBER_ERROR_NONE;
 }
 
+void phn_close_dlopen_handle(void)
+{
+       if (NULL != _dlopen_handle) {
+               dlclose(_dlopen_handle);
+               _dlopen_handle = NULL;
+       }
+}
+
 static void _phn_cc_changed_cb(TapiHandle *handle, const char *noti_id, void *data,
                void *user_data)
 {
index 1f2c44b3c95838de5c8e546d49a3fa0bfa774110..1938fe0e13bdde7d401099a13c2d6d27fcb2855d 100644 (file)
@@ -29,6 +29,7 @@ int phn_get_location_from_number(const char *number, const char *region,
                const char *language, char **location);
 int phn_get_normalized_number(const char *number, char **out_e164);
 
+void phn_close_dlopen_handle(void);
 
 #ifdef __cplusplus
 }
diff --git a/libgeocoding/CMakeLists.txt b/libgeocoding/CMakeLists.txt
new file mode 100644 (file)
index 0000000..908d12c
--- /dev/null
@@ -0,0 +1,21 @@
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+
+SET(GEOCODING "${PROJECT_NAME}-geocoding")
+
+FILE(GLOB GEOCODING_SRCS *.cpp)
+
+pkg_check_modules(geocoding_pkgs REQUIRED dlog icu-i18n capi-system-info)
+
+INCLUDE_DIRECTORIES(${geocoding_pkgs_INCLUDE_DIRS})
+LINK_DIRECTORIES(${geocoding_pkgs_LIBRARY_DIRS})
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--hash-style=both -pie")
+
+ADD_LIBRARY(${GEOCODING} SHARED ${GEOCODING_SRCS})
+
+TARGET_LINK_LIBRARIES(${GEOCODING} ${geocoding_pkgs_LIBRARIES} geocoding)
+
+INSTALL(TARGETS ${GEOCODING} DESTINATION ${LIB_INSTALL_DIR})
diff --git a/libgeocoding/phn-libgeocoding.cpp b/libgeocoding/phn-libgeocoding.cpp
new file mode 100644 (file)
index 0000000..82151fb
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Phonenumber Utils
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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 "phn-libgeocoding.h"
+
+#include <string.h>
+
+#include <phonenumbers/phonenumberutil.h>
+#include <phonenumbers/geocoding/phonenumber_offline_geocoder.h>
+
+#include "phone_number_errors.h"
+#include "phn-log.h"
+
+using namespace i18n::phonenumbers;
+
+EXPORT_API int phn_geocoding_get_location_from_number(const char* number, const char* region, const char* language, char** location)
+{
+       PhoneNumber phNumber;
+       const PhoneNumberUtil& pn_instance = *PhoneNumberUtil::GetInstance();
+       const PhoneNumberUtil::ErrorType status = pn_instance.Parse(number, region, &phNumber);
+       RETVM_IF(status != PhoneNumberUtil::NO_PARSING_ERROR, PHONE_NUMBER_ERROR_NO_DATA, "PhoneNumberUtil::Parse() Fail(%d)", status);
+
+       std::string description = PhoneNumberOfflineGeocoder().GetDescriptionForNumber(phNumber, icu::Locale(language));
+       *location = strdup((char*)description.c_str());
+
+       return PHONE_NUMBER_ERROR_NONE;
+}
diff --git a/libgeocoding/phn-libgeocoding.h b/libgeocoding/phn-libgeocoding.h
new file mode 100644 (file)
index 0000000..788fdb5
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
+#ifndef __PHONENUMBER_UTILS_LIB_GEOCODING_H__
+#define __PHONENUMBER_UTILS_LIB_GEOCODING_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+       int phn_geocoding_get_location_from_number(const char* number, const char* region, const char* language, char** location);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*__PHONENUMBER_UTILS_LIB_GEOCODING_H__*/
index 1d01e6bfac343ae91ad62751ba8c2ce72a792515..c8f20da5d69f142c59794a3977d419096dac2ded 100644 (file)
@@ -1,6 +1,6 @@
 Name:       phonenumber-utils
 Summary:    Phone Number Utilities
-Version:    0.2.9
+Version:    0.2.10
 Release:    0
 Group:      Telephony/Utilities
 License:    Apache-2.0
@@ -63,7 +63,6 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
        -DPHND_SYS_DB=%{TZ_SYS_GLOBALUSER_DB} \
        -DDBUS_INTERFACE=%{_dbus_name}
 
-
 %install
 rm -rf %{buildroot}
 
@@ -99,6 +98,7 @@ systemctl daemon-reload
 %{_bindir}/%{name}-daemon
 %{_datadir}/dbus-1/system-services/%{_dbus_name}.service
 %{_libdir}/lib%{name}.so.*
+%{_libdir}/lib%{name}-geocoding.so
 %license LICENSE.APLv2
 %config %{_sysconfdir}/dbus-1/system.d/%{name}.conf
 
@@ -115,4 +115,3 @@ systemctl daemon-reload
 %manifest %{name}-test.manifest
 %{_bindir}/%{name}-test
 %license LICENSE.APLv2
-