From: Sameer Prakash Pradhan Date: Thu, 12 Jul 2018 10:26:48 +0000 (+0530) Subject: provides library to support unused function for memory issue X-Git-Tag: submit/tizen/20181214.061228~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fee24cda98f3ea057ffd35e8075efe9529cb87b5;p=platform%2Fcore%2Ftelephony%2Fphonenumber-utils.git provides library to support unused function for memory issue 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 Change-Id: I1acc41fac65d65b66d29c0f260d857599c8333bf --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 33d60f9..c4efa29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,4 +17,4 @@ ADD_SUBDIRECTORY(common) ADD_SUBDIRECTORY(daemon) ADD_SUBDIRECTORY(client) ADD_SUBDIRECTORY(test) - +ADD_SUBDIRECTORY(libgeocoding) diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index b84584a..f0621e2 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -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}) diff --git a/daemon/phnd-dbus.c b/daemon/phnd-dbus.c index d2a7366..f3d9584 100644 --- a/daemon/phnd-dbus.c +++ b/daemon/phnd-dbus.c @@ -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(); } diff --git a/daemon/phnd-libphonenumber.cpp b/daemon/phnd-libphonenumber.cpp old mode 100644 new mode 100755 index 2a31a07..094061d --- a/daemon/phnd-libphonenumber.cpp +++ b/daemon/phnd-libphonenumber.cpp @@ -19,17 +19,18 @@ #include #include #include +#include #include #include #include #include -#include - #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) { diff --git a/daemon/phnd-libphonenumber.h b/daemon/phnd-libphonenumber.h index 1f2c44b..1938fe0 100644 --- a/daemon/phnd-libphonenumber.h +++ b/daemon/phnd-libphonenumber.h @@ -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 index 0000000..908d12c --- /dev/null +++ b/libgeocoding/CMakeLists.txt @@ -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 index 0000000..82151fb --- /dev/null +++ b/libgeocoding/phn-libgeocoding.cpp @@ -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 + +#include +#include + +#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 index 0000000..788fdb5 --- /dev/null +++ b/libgeocoding/phn-libgeocoding.h @@ -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__*/ diff --git a/packaging/phonenumber-utils.spec b/packaging/phonenumber-utils.spec index 1d01e6b..c8f20da 100644 --- a/packaging/phonenumber-utils.spec +++ b/packaging/phonenumber-utils.spec @@ -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 -