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
ADD_SUBDIRECTORY(daemon)
ADD_SUBDIRECTORY(client)
ADD_SUBDIRECTORY(test)
-
+ADD_SUBDIRECTORY(libgeocoding)
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})
void phnd_dbus_deinit(unsigned int id)
{
g_bus_unown_name(id);
+
+ phn_close_dlopen_handle();
}
#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 {
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,
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)
{
const char *language, char **location);
int phn_get_normalized_number(const char *number, char **out_e164);
+void phn_close_dlopen_handle(void);
#ifdef __cplusplus
}
--- /dev/null
+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})
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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__*/
Name: phonenumber-utils
Summary: Phone Number Utilities
-Version: 0.2.9
+Version: 0.2.10
Release: 0
Group: Telephony/Utilities
License: Apache-2.0
-DPHND_SYS_DB=%{TZ_SYS_GLOBALUSER_DB} \
-DDBUS_INTERFACE=%{_dbus_name}
-
%install
rm -rf %{buildroot}
%{_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
%manifest %{name}-test.manifest
%{_bindir}/%{name}-test
%license LICENSE.APLv2
-