From a88c3f10f7c15485a3596006cb9c19eb6d38bb5d Mon Sep 17 00:00:00 2001 From: Young-Ae Kang Date: Fri, 12 Jun 2015 18:44:46 +0900 Subject: [PATCH] Added missed files. Signed-off-by: Young-Ae Kang Change-Id: I2e14e4a1ae0227cc1a862adbf2785774744e16dc --- CMakeLists.txt | 43 + lbs-server/CMakeLists.txt | 40 + .../script/vconf-internal-location-keys.sh | 46 + lbs-server/src/data_connection.c | 359 +++++ lbs-server/src/data_connection.h | 39 + lbs-server/src/debug_util.h | 48 + lbs-server/src/dump_log.c | 116 ++ lbs-server/src/dump_log.h | 33 + lbs-server/src/gps_plugin_module.c | 99 ++ lbs-server/src/gps_plugin_module.h | 31 + lbs-server/src/last_position.c | 118 ++ lbs-server/src/last_position.h | 33 + lbs-server/src/lbs_server.c | 1387 +++++++++++++++++ lbs-server/src/lbs_server.h | 177 +++ lbs-server/src/nmea_logger.c | 138 ++ lbs-server/src/nmea_logger.h | 34 + lbs-server/src/nps_plugin_module.c | 161 ++ lbs-server/src/nps_plugin_module.h | 34 + lbs-server/src/server.c | 1286 +++++++++++++++ lbs-server/src/server.h | 90 ++ lbs-server/src/setting.c | 187 +++ lbs-server/src/setting.h | 55 + module/CMakeLists.txt | 28 + packaging/lbs-server.changes | 1090 +++++++++++++ packaging/lbs-server.manifest | 71 + packaging/location-lbs-server.manifest | 5 + 26 files changed, 5748 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 lbs-server/CMakeLists.txt create mode 100644 lbs-server/script/vconf-internal-location-keys.sh create mode 100644 lbs-server/src/data_connection.c create mode 100644 lbs-server/src/data_connection.h create mode 100644 lbs-server/src/debug_util.h create mode 100644 lbs-server/src/dump_log.c create mode 100644 lbs-server/src/dump_log.h create mode 100644 lbs-server/src/gps_plugin_module.c create mode 100644 lbs-server/src/gps_plugin_module.h create mode 100644 lbs-server/src/last_position.c create mode 100644 lbs-server/src/last_position.h create mode 100644 lbs-server/src/lbs_server.c create mode 100644 lbs-server/src/lbs_server.h create mode 100644 lbs-server/src/nmea_logger.c create mode 100644 lbs-server/src/nmea_logger.h create mode 100644 lbs-server/src/nps_plugin_module.c create mode 100644 lbs-server/src/nps_plugin_module.h create mode 100644 lbs-server/src/server.c create mode 100644 lbs-server/src/server.h create mode 100644 lbs-server/src/setting.c create mode 100644 lbs-server/src/setting.h create mode 100644 module/CMakeLists.txt create mode 100644 packaging/lbs-server.changes create mode 100644 packaging/lbs-server.manifest create mode 100644 packaging/location-lbs-server.manifest diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..54ecc77 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,43 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(com.samsung.lbs-server C) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +#SET(LIB_DIR "${PREFIX}/lib") +#SET(INCLUDE_DIR "${PREFIX}/include") +SET(BIN_DIR "${PREFIX}/bin") + +#Dependencies +SET(common_dp "glib-2.0 lbs-dbus dlog gio-2.0") +SET(server_dp "${common_dp} network tapi vconf vconf-internal-keys gthread-2.0 gio-unix-2.0 capi-network-wifi") +SET(module_dp "${common_dp} gmodule-2.0 lbs-location") + +# Set required packages +INCLUDE(FindPkgConfig) + +## SERVER +pkg_check_modules(server_pkgs REQUIRED ${server_dp}) +FOREACH(flag ${server_pkgs_CFLAGS}) + SET(SERVER_EXTRA_CFLAGS "${SERVER_EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +## MODULE +pkg_check_modules(module_pkgs REQUIRED ${module_dp}) +FOREACH(flag ${module_pkgs_CFLAGS}) + SET(MODULE_EXTRA_CFLAGS "${MODULE_EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs -fvisibility=hidden ") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wextra -fvisibility=hidden -fPIC") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter -Wno-missing-field-initializers -Wno-missing-declarations -Wall -Wcast-align -Wno-sign-compare") + +ADD_DEFINITIONS("-DFEATURE_DLOG_DEBUG") +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS(" -DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\" ") + +MESSAGE(${CMAKE_C_FLAGS}) +MESSAGE(${CMAKE_EXE_LINKER_FLAGS}) + +ADD_SUBDIRECTORY(module) +ADD_SUBDIRECTORY(lbs-server) diff --git a/lbs-server/CMakeLists.txt b/lbs-server/CMakeLists.txt new file mode 100644 index 0000000..a6df38e --- /dev/null +++ b/lbs-server/CMakeLists.txt @@ -0,0 +1,40 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.0) +PROJECT(lbs-server C CXX) + +SET(SERVER_SRCS_DIR "src") +SET(server_pkgs_LDFLAGS "${server_pkgs_LDFLAGS} -ldl") +SET(SERVER_EXTRA_CFLAGS "${SERVER_EXTRA_CFLAGS} -D_GNU_SOURCE") + +SET(SERVER_SRCS + ${SERVER_SRCS_DIR}/lbs_server.c + ${SERVER_SRCS_DIR}/server.c + ${SERVER_SRCS_DIR}/data_connection.c + ${SERVER_SRCS_DIR}/nmea_logger.c + ${SERVER_SRCS_DIR}/gps_plugin_module.c + ${SERVER_SRCS_DIR}/last_position.c + ${SERVER_SRCS_DIR}/setting.c + ${SERVER_SRCS_DIR}/dump_log.c + ${SERVER_SRCS_DIR}/nps_plugin_module.c +) + +INCLUDE_DIRECTORIES( + src + include +) + +CONFIGURE_FILE(org.tizen.lbs.Providers.LbsServer.service.in org.tizen.lbs.Providers.LbsServer.service @ONLY) +INSTALL(FILES org.tizen.lbs.Providers.LbsServer.service DESTINATION /usr/share/dbus-1/system-services) +#INSTALL(FILES lbs-server.provider DESTINATION /usr/share/lbs) +INSTALL(FILES script/lbs-server DESTINATION /etc/rc.d/init.d) + +CONFIGURE_FILE(lbs-server-plugin.pc.in lbs-server-plugin.pc @ONLY) +INSTALL(FILES lbs-server-plugin.pc DESTINATION ${LIB_DIR}/pkgconfig) + +ADD_EXECUTABLE(${PROJECT_NAME} ${SERVER_SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${server_pkgs_LDFLAGS} -lm) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS ${SERVER_EXTRA_CFLAGS}) +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") + +INSTALL(DIRECTORY include/ DESTINATION ${INCLUDE_DIR}/lbs-server-plugin FILES_MATCHING PATTERN "*.h") + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BIN_DIR}) \ No newline at end of file diff --git a/lbs-server/script/vconf-internal-location-keys.sh b/lbs-server/script/vconf-internal-location-keys.sh new file mode 100644 index 0000000..586bb45 --- /dev/null +++ b/lbs-server/script/vconf-internal-location-keys.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +/usr/bin/vconftool2 set -t int "db/location/setting/Usemylocation" "1" -s "tizen::vconf::location::enable" -i -g 6514 +/usr/bin/vconftool2 set -t int "db/location/setting/GpsEnabled" "1" -s "tizen::vconf::location::enable" -i -g 6514 +/usr/bin/vconftool2 set -t int "db/location/setting/NetworkEnabled" "1" -s "tizen::vconf::location::enable" -i -g 6514 +/usr/bin/vconftool2 set -t int "db/location/setting/GpsPopup" "1" -s "tizen::vconf::location::enable" -i -g 6514 +/usr/bin/vconftool2 set -t int "memory/location/position/state" "0" -s "tizen::vconf::public::r::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t int "memory/location/gps/state" "0" -s "tizen::vconf::public::r::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t int "memory/location/wps/state" "0" -s "tizen::vconf::public::r::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t int "memory/location/last/gps/Timestamp" "0" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t double "memory/location/last/gps/Latitude" "0.0" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t double "memory/location/last/gps/Longitude" "0.0" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t double "memory/location/last/gps/Altitude" "0.0" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t double "memory/location/last/gps/Speed" "0.0" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t double "memory/location/last/gps/Direction" "0.0" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t double "memory/location/last/gps/HorAccuracy" "0.0" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t double "memory/location/last/gps/VerAccuracy" "0.0" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t double "memory/location/last/wps/Timestamp" "0.0" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t double "memory/location/last/wps/Latitude" "0.0" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t double "memory/location/last/wps/Longitude" "0.0" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t double "memory/location/last/wps/Altitude" "0.0" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t double "memory/location/last/wps/Speed" "0.0" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t double "memory/location/last/wps/Direction" "0.0" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t double "memory/location/last/wps/HorAccuracy" "0.0" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t int "db/location/last/gps/LocTimestamp" "0" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t int "db/location/last/wps/LocTimestamp" "0" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t string "db/location/last/gps/Location" "0.0;0.0;0.0;0.0;0.0;0.0;0.0;" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t string "db/location/last/wps/Location" "0.0;0.0;0.0;0.0;0.0;0.0;" -s "tizen::vconf::location" -i -g 6514 +/usr/bin/vconftool2 set -t int "db/location/nmea/LoggingEnabled" "0" -s "tizen::vconf::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t int "db/location/replay/ReplayEnabled" "0" -s "tizen::vconf::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t int "db/location/replay/ReplayMode" "1" -s "tizen::vconf::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t string "db/location/replay/FileName" "nmea_replay.log" -s "tizen::vconf::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t double "db/location/replay/ManualLatitude" "0.0" -s "tizen::vconf::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t double "db/location/replay/ManualLongitude" "0.0" -s "tizen::vconf::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t double "db/location/replay/ManualAltitude" "0.0" -s "tizen::vconf::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t double "db/location/replay/ManualHAccuracy" "0.0" -s "tizen::vconf::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t int "db/location/gps/Operation" "1" -s "tizen::vconf::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t int "db/location/gps/OperationTest" "0" -s "tizen::vconf::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t int "db/location/gps/Starting" "0" -s "tizen::vconf::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t int "db/location/gps/Session" "1" -s "tizen::vconf::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t double "db/location/gps/XtraDownloadTime" "0.0" -s "tizen::vconf::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t string "db/location/supl/Server" "" -s "tizen::vconf::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t string "db/location/supl/Port" "7275" -s "tizen::vconf::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t int "db/location/supl/SslEnabled" "1" -s "tizen::vconf::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t int "db/location/supl/FQDNType" "0" -s "tizen::vconf::platform::rw" -i -g 6514 +/usr/bin/vconftool2 set -t int "db/location/supl/Version" "0" -s "tizen::vconf::platform::rw" -i -g 6514 \ No newline at end of file diff --git a/lbs-server/src/data_connection.c b/lbs-server/src/data_connection.c new file mode 100644 index 0000000..0ca05c2 --- /dev/null +++ b/lbs-server/src/data_connection.c @@ -0,0 +1,359 @@ +/* + * lbs-server + * + * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Minjune Kim + * Genie Kim + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "data_connection.h" +#include +#include "debug_util.h" + +int noti_resp_init(int *noti_pipe_fds); +int noti_resp_wait(int *noti_pipe_fds); +int noti_resp_check(int *noti_pipe_fds); +int noti_resp_noti(int *noti_pipe_fds, int result); +int noti_resp_deinit(int *noti_pipe_fds); + +unsigned int g_ipaddr; +static int pdp_pipe_fds[2]; + +typedef enum { + DEACTIVATED, + ACTIVATING, + ACTIVATED, + DEACTIVATING +} pdp_status; + +char profile_name[NET_PROFILE_NAME_LEN_MAX + 1]; + +pdp_status act_level; + +char *PdpStat[] = { "Deactivated", "Activating", "Activated", "Deactivating" }; + +static void set_connection_status(pdp_status i) +{ + act_level = i; + LOG_GPS(DBG_LOW, "==Status: %s\n", PdpStat[i]); +} + +static pdp_status get_connection_status() +{ + return act_level; +} + +static void pdp_proxy_conf() +{ + net_proxy_t proxy; + int ret; + ret = net_get_active_proxy(&proxy); + + if (ret == NET_ERR_NONE) { + if (strncmp(proxy.proxy_addr, "0.0.0.0", 7)) { + char buf[100]; + snprintf(buf, sizeof(buf), "http://%s/", proxy.proxy_addr); + setenv("http_proxy", buf, 1); + } else { + unsetenv("http_proxy"); + } + } else { + LOG_GPS(DBG_ERR, "Fail to get proxy\n"); + } +} + +void pdp_evt_cb(net_event_info_t *event_cb, void *user_data) +{ + switch (event_cb->Event) { + case NET_EVENT_OPEN_RSP: { + LOG_GPS(DBG_LOW, "event_cb->Error : [%d]\n", event_cb->Error); + if (get_connection_status() != ACTIVATING) { + LOG_GPS(DBG_LOW, "Not Activating status\n"); + } else if (event_cb->Error == NET_ERR_NONE || event_cb->Error == NET_ERR_ACTIVE_CONNECTION_EXISTS) { + LOG_GPS(DBG_LOW, "Successful PDP Activation\n"); + net_profile_info_t *prof_info = NULL; + net_dev_info_t *net_info = NULL; + + prof_info = (net_profile_info_t *) event_cb->Data; + net_info = &(prof_info->ProfileInfo.Pdp.net_info); + + strncpy(profile_name, net_info->ProfileName, NET_PROFILE_NAME_LEN_MAX); + + set_connection_status(ACTIVATED); + pdp_proxy_conf(); + noti_resp_noti(pdp_pipe_fds, TRUE); + } else { + LOG_GPS(DBG_ERR, " PDP Activation Failed - PDP Error[%d]\n", event_cb->Error); + set_connection_status(DEACTIVATED); + noti_resp_noti(pdp_pipe_fds, FALSE); + } + } + break; + + case NET_EVENT_CLOSE_RSP: + if (get_connection_status() != ACTIVATED && get_connection_status() != DEACTIVATING) { + LOG_GPS(DBG_ERR, "Not Activated && Deactivating status\n"); + } else if (event_cb->Error == NET_ERR_NONE || event_cb->Error == NET_ERR_UNKNOWN) { + LOG_GPS(DBG_LOW, "Successful PDP De-Activation\n"); + set_connection_status(DEACTIVATED); + noti_resp_noti(pdp_pipe_fds, TRUE); + } else { + LOG_GPS(DBG_ERR, " PDP DeActivation Failed - PDP Error[%d]\n", event_cb->Error); + noti_resp_noti(pdp_pipe_fds, FALSE); + } + break; + + case NET_EVENT_CLOSE_IND: + if (get_connection_status() != ACTIVATED && get_connection_status() != DEACTIVATING) { + LOG_GPS(DBG_ERR, "Not Activated && Deactivating status\n"); + } else if (event_cb->Error == NET_ERR_NONE || event_cb->Error == NET_ERR_UNKNOWN) { + LOG_GPS(DBG_LOW, "Successful PDP De-Activation\n"); + set_connection_status(DEACTIVATED); + noti_resp_noti(pdp_pipe_fds, TRUE); + } else { + LOG_GPS(DBG_ERR, " PDP DeActivation Failed - PDP Error[%d]\n", event_cb->Error); + noti_resp_noti(pdp_pipe_fds, FALSE); + } + break; + case NET_EVENT_OPEN_IND: + break; + default: + break; + } +} + +unsigned int start_pdp_connection(void) +{ + int err = -1; + + set_connection_status(DEACTIVATED); + if (noti_resp_init(pdp_pipe_fds)) { + LOG_GPS(DBG_LOW, "Success start_pdp_connection\n"); + } else { + LOG_GPS(DBG_ERR, "ERROR in noti_resp_init()\n"); + return FALSE; + } + + err = net_register_client((net_event_cb_t) pdp_evt_cb, NULL); + + if (err == NET_ERR_NONE || err == NET_ERR_APP_ALREADY_REGISTERED) { + LOG_GPS(DBG_LOW, "Client registration is succeed\n"); + } else { + LOG_GPS(DBG_WARN, "Error in net_register_client [%d]\n", err); + noti_resp_deinit(pdp_pipe_fds); + return FALSE; + } + + set_connection_status(ACTIVATING); + err = net_open_connection_with_preference(NET_SERVICE_INTERNET); + + if (err == NET_ERR_NONE) { + LOG_GPS(DBG_LOW, "Sent PDP Activation.\n"); + } else { + LOG_GPS(DBG_WARN, "Error in net_open_connection_with_preference() [%d]\n", err); + set_connection_status(DEACTIVATED); + err = net_deregister_client(); + if (err == NET_ERR_NONE) { + LOG_GPS(DBG_LOW, "Client deregistered successfully\n"); + } else { + LOG_GPS(DBG_ERR, "Error deregistering the client\n"); + } + noti_resp_deinit(pdp_pipe_fds); + return FALSE; + } + + if (noti_resp_wait(pdp_pipe_fds) > 0) { + if (noti_resp_check(pdp_pipe_fds)) { + LOG_GPS(DBG_LOW, "PDP Activation Successful\n"); + noti_resp_deinit(pdp_pipe_fds); + return TRUE; + } else { + LOG_GPS(DBG_ERR, "PDP failed\n"); + noti_resp_deinit(pdp_pipe_fds); + + err = net_deregister_client(); + if (err == NET_ERR_NONE) { + LOG_GPS(DBG_LOW, "Client deregistered successfully\n"); + } else { + LOG_GPS(DBG_ERR, "Error deregistering the client\n"); + } + return FALSE; + } + } else { + LOG_GPS(DBG_ERR, "NO Pdp Act Response or Some error in select.\n"); + noti_resp_deinit(pdp_pipe_fds); + + err = net_deregister_client(); + if (err == NET_ERR_NONE) { + LOG_GPS(DBG_LOW, "Client deregistered successfully\n"); + } else { + LOG_GPS(DBG_ERR, "Error deregistering the client\n"); + } + return FALSE; + } +} + +unsigned int stop_pdp_connection(void) +{ + int err; + pdp_status pStatus = get_connection_status(); + if (pStatus == DEACTIVATED || pStatus == DEACTIVATING) { + LOG_GPS(DBG_ERR, "pdp stop progressing already. pStatus[%d] \n", pStatus); + return TRUE; + } + + if (noti_resp_init(pdp_pipe_fds)) { + LOG_GPS(DBG_LOW, "Success stop_pdp_connection\n"); + } else { + LOG_GPS(DBG_ERR, "ERROR in noti_resp_init()\n"); + return FALSE; + } + + set_connection_status(DEACTIVATING); + err = net_close_connection(profile_name); + if (err == NET_ERR_NONE) { + LOG_GPS(DBG_LOW, "Success net_close_connection\n"); + } else { + LOG_GPS(DBG_WARN, "Error in sending net_close_connection error=%d\n", err); + set_connection_status(pStatus); + noti_resp_deinit(pdp_pipe_fds); + return FALSE; + } + if (noti_resp_wait(pdp_pipe_fds) > 0) { + if (noti_resp_check(pdp_pipe_fds)) { + LOG_GPS(DBG_LOW, "Close Connection success\n"); + } else { + LOG_GPS(DBG_ERR, "Close connection failed\n"); + } + } + + noti_resp_deinit(pdp_pipe_fds); + + set_connection_status(DEACTIVATED); + + err = net_deregister_client(); + if (err == NET_ERR_NONE) { + LOG_GPS(DBG_LOW, "Client deregistered successfully\n"); + } else { + LOG_GPS(DBG_WARN, "Error deregistering the client\n"); + return FALSE; + } + + return TRUE; +} + +unsigned int query_dns(char *pdns_lookup_addr, unsigned int *ipaddr, int *port) +{ + FUNC_ENTRANCE_SERVER; + /*int dns_id; */ + unsigned int ret = 0; + struct hostent *he; + + char *colon = strchr(pdns_lookup_addr, ':'); + char *last = NULL; + if (colon != NULL) { + char *ptr = (char *)strtok_r(pdns_lookup_addr, ":", &last); + pdns_lookup_addr = ptr; + + ptr = (char *)strtok_r(NULL, ":", &last); + *port = atoi(ptr); + } + + he = gethostbyname(pdns_lookup_addr); + + if (he != NULL) { + LOG_GPS(DBG_LOW, "g_agps_ipaddr: %u\n", g_ipaddr); + *ipaddr = g_ipaddr; + + ret = TRUE; + } else { + LOG_GPS(DBG_ERR, "//gethostbyname : Error getting host information\n"); + ret = FALSE; + } + + return ret; + +} + +int noti_resp_init(int *noti_pipe_fds) +{ + if (pipe(noti_pipe_fds) < 0) { + return 0; + } else { + return 1; + } +} + +int noti_resp_wait(int *noti_pipe_fds) +{ + fd_set rfds; + fd_set wfds; + FD_ZERO(&rfds); + FD_ZERO(&wfds); + FD_SET(*noti_pipe_fds, &rfds); + return select(*noti_pipe_fds + 1, &rfds, &wfds, NULL, NULL); +} + +int noti_resp_noti(int *noti_pipe_fds, int result) +{ + return write(*(noti_pipe_fds + 1), &result, sizeof(int)); +} + +int noti_resp_check(int *noti_pipe_fds) +{ + int activation = 0; + ssize_t ret_val = 0; + ret_val = read(*noti_pipe_fds, &activation, sizeof(int)); + if (ret_val == 0) { + LOG_GPS(DBG_ERR, "No data"); + } + return activation; +} + +int noti_resp_deinit(int *noti_pipe_fds) +{ + int err; + err = close(*noti_pipe_fds); + if (err != 0) { + LOG_GPS(DBG_ERR, "ERROR closing fds1.\n"); + } + + err = close(*(noti_pipe_fds + 1)); + if (err != 0) { + LOG_GPS(DBG_ERR, "ERROR closing fds2.\n"); + } + + return err; +} diff --git a/lbs-server/src/data_connection.h b/lbs-server/src/data_connection.h new file mode 100644 index 0000000..a98f6f6 --- /dev/null +++ b/lbs-server/src/data_connection.h @@ -0,0 +1,39 @@ +/* + * lbs-server + * + * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Minjune Kim + * Genie Kim + * + * 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 _DATA_CONNECTION_H_ +#define _DATA_CONNECTION_H_ + +/* Total Number of seconds in years between NTP Reference time(1900) to UTC reference time(1970)*/ +#define UTC_NTP_BIAS 2208988800 +/* Total Number of seconds in years between UTC reference time(1970) to GPS Refernce time(1980)*/ +#define UTC_GPS_BIAS 315964800 + +#define MAX_NUMBER_OF_URLS 3 + +#include + +unsigned int start_pdp_connection(void); +unsigned int stop_pdp_connection(void); + +unsigned int query_dns(char *pdns_lookup_addr, unsigned int *ipaddr, int *port); + +#endif diff --git a/lbs-server/src/debug_util.h b/lbs-server/src/debug_util.h new file mode 100644 index 0000000..fc59c02 --- /dev/null +++ b/lbs-server/src/debug_util.h @@ -0,0 +1,48 @@ +/* + * lbs-server + * + * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Minjune Kim + * Genie Kim + * + * 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 _DEBUG_UTIL_H_ +#define _DEBUG_UTIL_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#define TAG_GPS_MANAGER "LBS_SERVER_GPS" +#define TAG_NPS_MANAGER "LBS_SERVER_NPS" + +#define DBG_LOW LOG_DEBUG +#define DBG_INFO LOG_INFO +#define DBG_WARN LOG_WARN +#define DBG_ERR LOG_ERROR + +#define LOG_GPS(dbg_lvl,fmt,args...) SLOG(dbg_lvl, TAG_GPS_MANAGER, fmt, ##args) +#define LOG_NPS(dbg_lvl,fmt,args...) SLOG(dbg_lvl, TAG_NPS_MANAGER, fmt,##args) +#define FUNC_ENTRANCE_SERVER LOG_GPS(DBG_LOW, "[%s] Entered!!", __func__); + +#ifdef __cplusplus +} +#endif +#endif /* _DEBUG_UTIL_H_ */ diff --git a/lbs-server/src/dump_log.c b/lbs-server/src/dump_log.c new file mode 100644 index 0000000..b3213b3 --- /dev/null +++ b/lbs-server/src/dump_log.c @@ -0,0 +1,116 @@ +/* + * lbs-server + * + * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Minjune Kim + * Genie Kim + * + * 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 +#include +#include +#include +#include +#include +#include + +#include "debug_util.h" + +#define GPG_DUMP_LOG "/tmp/dump_gps.log" + +int fd = -1; + +struct tm *__get_current_time() { + time_t now; + struct tm *cur_time; + + time(&now); + cur_time = localtime(&now); + return cur_time; +} + +void gps_init_log() +{ + LOG_GPS(DBG_ERR, "gps_init_log"); + int ret = -1; + struct tm *cur_time = NULL; + char buf[256] = {0, }; + fd = open(GPG_DUMP_LOG, O_RDWR | O_APPEND | O_CREAT, 0644); + if (fd < 0) { + LOG_GPS(DBG_ERR, "Fail to open file[%s]", GPG_DUMP_LOG); + return; + } + + cur_time = __get_current_time(); + if (!cur_time) { + LOG_GPS(DBG_ERR, "Can't get current time[%s]", GPG_DUMP_LOG); + return; + } + + g_snprintf(buf, 256, "[%02d:%02d:%02d] -- START GPS -- \n", cur_time->tm_hour, cur_time->tm_min, cur_time->tm_sec); + ret = write(fd, buf, strlen(buf)); + if (ret == -1) { + LOG_GPS(DBG_ERR, "Fail to write file[%s]", GPG_DUMP_LOG); + } +} + +void gps_deinit_log() +{ + LOG_GPS(DBG_ERR, "gps_deinit_log"); + if (fd < 0) return; + int ret = -1; + struct tm *cur_time = __get_current_time(); + char buf[256] = {0, }; + + if (!cur_time) { + LOG_GPS(DBG_ERR, "Can't get current time[%s]", GPG_DUMP_LOG); + } else { + g_snprintf(buf, 256, "[%02d:%02d:%02d] -- END GPS -- \n", cur_time->tm_hour, cur_time->tm_min, cur_time->tm_sec); + ret = write(fd, buf, strlen(buf)); + if (ret == -1) { + LOG_GPS(DBG_ERR, "Fail to write file[%s]", GPG_DUMP_LOG); + } + } + close(fd); + fd = -1; +} + +void gps_dump_log(const char *str, const char *app_id) +{ + if (fd < 0) { + LOG_GPS(DBG_ERR, "Not available fd[%d]", fd); + return; + } + int ret = -1; + char buf[256] = {0, }; + struct tm *cur_time = __get_current_time(); + + if (!cur_time) { + LOG_GPS(DBG_ERR, "Can't get current time[%s]", GPG_DUMP_LOG); + return; + } + + if (app_id == NULL) { + g_snprintf(buf, 256, "[%02d:%02d:%02d] %s\n", cur_time->tm_hour, cur_time->tm_min, cur_time->tm_sec, str); + } else { + g_snprintf(buf, 256, "[%02d:%02d:%02d] %s from [%s]\n", cur_time->tm_hour, cur_time->tm_min, cur_time->tm_sec, str, app_id); + } + LOG_GPS(DBG_ERR, "Add dump log [%s", buf); + ret = write(fd, buf, strlen(buf)); + if (ret == -1) { + LOG_GPS(DBG_ERR, "Fail to write file[%s]", GPG_DUMP_LOG); + } +} diff --git a/lbs-server/src/dump_log.h b/lbs-server/src/dump_log.h new file mode 100644 index 0000000..1bc5fa9 --- /dev/null +++ b/lbs-server/src/dump_log.h @@ -0,0 +1,33 @@ +/* + * lbs-server + * + * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Minjune Kim + * Genie Kim + * + * 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 _DUMP_LOG_H_ +#define _DUMP_LOG_H_ + +#include + +void gps_init_log(); + +void gps_deinit_log(); + +void gps_dump_log(const char *str, const char *app_id); + +#endif /* _DUMP_LOG_H_ */ diff --git a/lbs-server/src/gps_plugin_module.c b/lbs-server/src/gps_plugin_module.c new file mode 100644 index 0000000..7332fe3 --- /dev/null +++ b/lbs-server/src/gps_plugin_module.c @@ -0,0 +1,99 @@ +/* + * lbs_server + * + * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Minjune Kim + * Genie Kim + * + * 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 +#include +#include +#include +#include +#include +#include "gps_plugin_module.h" +#include "setting.h" +#include "debug_util.h" + +#define SPECIFIC_PLUGIN_PATH_PREFIX "/usr/lib/libSLP-lbs-plugin-" +#define SPECIFIC_PLUGIN_PATH_POSTFIX ".so" + +static const gps_plugin_interface *g_plugin = NULL; + +int load_plugin_module(char *specific_name, void **plugin_handle) +{ + char plugin_path[256]; + + if (specific_name[0] == '\0') { + strncpy(plugin_path, GPS_PLUGIN_PATH, sizeof(plugin_path)); + } else { + snprintf(plugin_path, sizeof(plugin_path), + SPECIFIC_PLUGIN_PATH_PREFIX"%s" + SPECIFIC_PLUGIN_PATH_POSTFIX, + specific_name); + + struct stat st = {0}; + + if (stat(plugin_path, &st) != 0) { + strncpy(plugin_path, GPS_PLUGIN_PATH, sizeof(plugin_path)); + setting_set_int(VCONFKEY_LOCATION_REPLAY_ENABLED, 1); + } + } + + *plugin_handle = dlopen(plugin_path, RTLD_NOW); + if (!*plugin_handle) { + LOG_GPS(DBG_ERR, "Failed to load plugin module: %s", plugin_path); + /* LOG_GPS(DBG_ERR, "%s", dlerror()); */ + return FALSE; + } + + const gps_plugin_interface *(*get_gps_plugin_interface)(); + get_gps_plugin_interface = dlsym(*plugin_handle, "get_gps_plugin_interface"); + if (!get_gps_plugin_interface) { + LOG_GPS(DBG_ERR, "Failed to find entry symbol in plugin module."); + dlclose(*plugin_handle); + return FALSE; + } + + g_plugin = get_gps_plugin_interface(); + + if (!g_plugin) { + LOG_GPS(DBG_ERR, "Failed to find load symbol in plugin module."); + dlclose(*plugin_handle); + return FALSE; + } + LOG_GPS(DBG_LOW, "Success to load plugin module"); + + return TRUE; +} + +int unload_plugin_module(void *plugin_handle) +{ + if (plugin_handle == NULL) { + LOG_GPS(DBG_ERR, "plugin_handle is already NULL."); + return FALSE; + } + + dlclose(plugin_handle); + + return TRUE; +} + +const gps_plugin_interface *get_plugin_module(void) +{ + return g_plugin; +} diff --git a/lbs-server/src/gps_plugin_module.h b/lbs-server/src/gps_plugin_module.h new file mode 100644 index 0000000..62a675c --- /dev/null +++ b/lbs-server/src/gps_plugin_module.h @@ -0,0 +1,31 @@ +/* + * lbs-server + * + * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Minjune Kim + * Genie Kim + * + * 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 _GPS_PLUGIN_MODULE_H_ +#define _GPS_PLUGIN_MODULE_H_ + +#include "gps_plugin_intf.h" + +int load_plugin_module(char *specific_name, void **plugin_handle); +int unload_plugin_module(void *plugin_handle); +const gps_plugin_interface *get_plugin_module(void); + +#endif /* _GPS_PLUGIN_MODULE_H_ */ diff --git a/lbs-server/src/last_position.c b/lbs-server/src/last_position.c new file mode 100644 index 0000000..b876459 --- /dev/null +++ b/lbs-server/src/last_position.c @@ -0,0 +1,118 @@ +/* + * lbs-server + * + * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Minjune Kim + * Genie Kim + * + * 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 +#include +#include +#include + +#include "gps_plugin_data_types.h" +#include "last_position.h" +#include "debug_util.h" +#include "setting.h" + +#define MAX_GPS_LOC_ITEM 7 +#define UPDATE_INTERVAL 60 + +void gps_set_last_position(const pos_data_t *pos) +{ + if (pos == NULL) return; + + LOG_GPS(DBG_LOW, "set_last_position[%d]", pos->timestamp); + + char location[128] = {0,}; + snprintf(location, sizeof(location), "%.6lf;%.6lf;%.2lf;%.2lf;%.2lf;%.2lf;%.2lf;", pos->latitude, pos->longitude, pos->altitude, pos->speed, pos->bearing, pos->hor_accuracy, pos->ver_accuracy); + + setting_set_int(VCONFKEY_LOCATION_NV_LAST_GPS_TIMESTAMP, pos->timestamp); + setting_set_string(VCONFKEY_LOCATION_NV_LAST_GPS_LOCATION, location); +} + +void gps_set_position(const pos_data_t *pos) +{ + if (pos == NULL) + return; + + LOG_GPS(DBG_LOW, "set_position[%d]", pos->timestamp); + int last_timestamp = 0; + int timestamp = pos->timestamp; + double lat = pos->latitude; + double lon = pos->longitude; + double alt = pos->altitude; + double spd = pos->speed; + double dir = pos->bearing; + double h_acc = pos->hor_accuracy; + double v_acc = pos->ver_accuracy; + + setting_set_int(VCONFKEY_LOCATION_LAST_GPS_TIMESTAMP, timestamp); + setting_set_double(VCONFKEY_LOCATION_LAST_GPS_LATITUDE, lat); + setting_set_double(VCONFKEY_LOCATION_LAST_GPS_LONGITUDE, lon); + setting_set_double(VCONFKEY_LOCATION_LAST_GPS_ALTITUDE, alt); + setting_set_double(VCONFKEY_LOCATION_LAST_GPS_SPEED, spd); + setting_set_double(VCONFKEY_LOCATION_LAST_GPS_DIRECTION, dir); + setting_set_double(VCONFKEY_LOCATION_LAST_GPS_HOR_ACCURACY, h_acc); + setting_set_double(VCONFKEY_LOCATION_LAST_GPS_VER_ACCURACY, v_acc); + + setting_get_int(VCONFKEY_LOCATION_NV_LAST_GPS_TIMESTAMP, &last_timestamp); + + if ((timestamp - last_timestamp) > UPDATE_INTERVAL) { + gps_set_last_position(pos); + } +} + +void gps_get_last_position(pos_data_t *last_pos) +{ + if (last_pos == NULL) + return; + + int timestamp; + char location[128] = {0,}; + char *last_location[MAX_GPS_LOC_ITEM] = {0,}; + char *last = NULL; + char *str = NULL; + int index = 0; + + setting_get_int(VCONFKEY_LOCATION_LAST_GPS_TIMESTAMP, ×tamp); + str = setting_get_string(VCONFKEY_LOCATION_NV_LAST_GPS_LOCATION); + if (str == NULL) { + return; + } + snprintf(location, sizeof(location), "%s", str); + free(str); + + last_location[index] = (char *)strtok_r(location, ";", &last); + while (last_location[index++] != NULL) { + if (index == MAX_GPS_LOC_ITEM) + break; + last_location[index] = (char *)strtok_r(NULL, ";", &last); + } + index = 0; + + last_pos->timestamp = timestamp; + last_pos->latitude = strtod(last_location[index++], NULL); + last_pos->longitude = strtod(last_location[index++], NULL); + last_pos->altitude = strtod(last_location[index++], NULL); + last_pos->speed = strtod(last_location[index++], NULL); + last_pos->bearing = strtod(last_location[index++], NULL); + last_pos->hor_accuracy = strtod(last_location[index++], NULL); + last_pos->ver_accuracy = strtod(last_location[index], NULL); + + LOG_GPS(DBG_LOW, "get_last_position[%d]", last_pos->timestamp); +} diff --git a/lbs-server/src/last_position.h b/lbs-server/src/last_position.h new file mode 100644 index 0000000..00e7f95 --- /dev/null +++ b/lbs-server/src/last_position.h @@ -0,0 +1,33 @@ +/* + * lbs-server + * + * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Minjune Kim + * Genie Kim + * + * 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 _LAST_POSITON_H_ +#define _LAST_POSITON_H_ + +#include "gps_plugin_data_types.h" + +void gps_set_last_position(const pos_data_t *pos); + +void gps_set_position(const pos_data_t *pos); + +void gps_get_last_position(pos_data_t *last_pos); + +#endif /* _LAST_POSITON_H_ */ diff --git a/lbs-server/src/lbs_server.c b/lbs-server/src/lbs_server.c new file mode 100644 index 0000000..a2e44d8 --- /dev/null +++ b/lbs-server/src/lbs_server.c @@ -0,0 +1,1387 @@ +/* + * lbs-server + * + * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Minjune Kim + * Genie Kim + * + * 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 +#include +#include +#include +#include +#include + +#include +#include "setting.h" +#include + +#include "gps_plugin_data_types.h" +#include "lbs_server.h" + +#include "nps_plugin_module.h" +#include "nps_plugin_intf.h" + +#include "server.h" +#include "last_position.h" +#include "debug_util.h" +#include "dump_log.h" + + +typedef struct { + /* gps variables */ + pos_data_t position; + batch_data_t batch; + sv_data_t satellite; + nmea_data_t nmea; + gboolean sv_used; + gboolean nmea_used; + + gboolean is_gps_running; + gint gps_client_count; + + /* nps variables */ + NpsManagerHandle handle; + unsigned long period; + NpsManagerPositionExt pos; + NpsManagerLastPositionExt last_pos; + Plugin_LocationInfo location; + + gboolean is_nps_running; + gint nps_client_count; + unsigned char *token; + + /* shared variables */ + GMainLoop *loop; + GMutex mutex; + GCond cond; + LbsStatus status; + + /* dynamic interval update */ + GHashTable *dynamic_interval_table; + guint *optimized_interval_array; + guint temp_minimum_interval; + gboolean is_needed_changing_interval; + + lbs_server_dbus_h lbs_dbus_server; +} lbs_server_s; + +typedef struct { + lbs_server_s *lbs_server; + int method; +} dynamic_interval_updator_user_data; + +static gboolean gps_remove_all_clients(lbs_server_s *lbs_server); + +static void __setting_gps_cb(keynode_t *key, gpointer user_data) +{ + LOG_GPS(DBG_LOW, "ENTER >>>"); + lbs_server_s *lbs_server = (lbs_server_s *)user_data; + int onoff = 0; + gboolean ret = FALSE; + + setting_get_int(VCONFKEY_LOCATION_ENABLED, &onoff); + + if (onoff == 0) { + ret = gps_remove_all_clients(lbs_server); + if (ret == FALSE) { + LOG_GPS(DBG_LOW, "already removed."); + } + } +} + +static void nps_set_last_position(NpsManagerPositionExt pos) +{ + LOG_NPS(DBG_LOW, "nps_set_last_position[%d]", pos.timestamp); + + char location[128] = {0,}; + snprintf(location, sizeof(location), "%.6lf;%.6lf;%.2lf;%.2lf;%.2lf;%.2lf;", pos.latitude, pos.longitude, pos.altitude, pos.speed, pos.direction, pos.hor_accuracy); + + setting_set_int(VCONFKEY_LOCATION_NV_LAST_WPS_TIMESTAMP, pos.timestamp); + setting_set_string(VCONFKEY_LOCATION_NV_LAST_WPS_LOCATION, location); +} + +static void nps_set_position(lbs_server_s *lbs_server_nps, NpsManagerPositionExt pos) +{ + LOG_NPS(DBG_LOW, "set position timestamp : %d", pos.timestamp); + lbs_server_nps->last_pos.timestamp = pos.timestamp; + setting_set_int(VCONFKEY_LOCATION_LAST_WPS_TIMESTAMP, lbs_server_nps->last_pos.timestamp); + + if ((lbs_server_nps->last_pos.latitude != pos.latitude) || (lbs_server_nps->last_pos.longitude != pos.longitude)) { + lbs_server_nps->last_pos.latitude = pos.latitude; + lbs_server_nps->last_pos.longitude = pos.longitude; + lbs_server_nps->last_pos.altitude = pos.altitude; + lbs_server_nps->last_pos.hor_accuracy = pos.hor_accuracy; + lbs_server_nps->last_pos.speed = pos.speed; + lbs_server_nps->last_pos.direction = pos.direction; + + setting_set_double(VCONFKEY_LOCATION_LAST_WPS_LATITUDE, lbs_server_nps->last_pos.latitude); + setting_set_double(VCONFKEY_LOCATION_LAST_WPS_LONGITUDE, lbs_server_nps->last_pos.longitude); + setting_set_double(VCONFKEY_LOCATION_LAST_WPS_ALTITUDE, lbs_server_nps->last_pos.altitude); + setting_set_double(VCONFKEY_LOCATION_LAST_WPS_SPEED, lbs_server_nps->last_pos.speed); + setting_set_double(VCONFKEY_LOCATION_LAST_WPS_DIRECTION, lbs_server_nps->last_pos.direction); + setting_set_double(VCONFKEY_LOCATION_LAST_WPS_HOR_ACCURACY, lbs_server_nps->last_pos.hor_accuracy); + } + + int last_timestamp = 0; + setting_get_int(VCONFKEY_LOCATION_NV_LAST_WPS_TIMESTAMP, &last_timestamp); + + LOG_NPS(DBG_LOW, "last_time stamp: %d, pos.timestamp: %d, UPDATE_INTERVAL: %d ", last_timestamp, pos.timestamp, UPDATE_INTERVAL); + if ((pos.timestamp - last_timestamp) > UPDATE_INTERVAL) { + nps_set_last_position(pos); + } + +} + +static void nps_set_status(lbs_server_s *lbs_server, LbsStatus status) +{ + if (!lbs_server) { + LOG_NPS(DBG_ERR, "lbs_server is NULL!!"); + return; + } + LOG_NPS(DBG_LOW, "nps_set_status[%d]", status); + if (lbs_server->status == status) { + LOG_NPS(DBG_ERR, "Donot update NPS status"); + return; + } + + lbs_server->status = status; + + if (lbs_server->status == LBS_STATUS_AVAILABLE) { + setting_set_int(VCONFKEY_LOCATION_WPS_STATE, POSITION_CONNECTED); + } else if (lbs_server->status == LBS_STATUS_ACQUIRING) { + setting_set_int(VCONFKEY_LOCATION_WPS_STATE, POSITION_SEARCHING); + } else { + setting_set_int(VCONFKEY_LOCATION_WPS_STATE, POSITION_OFF); + } + + if (status != LBS_STATUS_AVAILABLE) { + lbs_server->pos.fields = LBS_POSITION_FIELDS_NONE; + } + + lbs_server_emit_status_changed(lbs_server->lbs_dbus_server, LBS_SERVER_METHOD_NPS, status); +} + +static void nps_update_position(lbs_server_s *lbs_server_nps, NpsManagerPositionExt pos) +{ + if (!lbs_server_nps) { + LOG_NPS(DBG_ERR, "lbs-server is NULL!!"); + return; + } + + GVariant *accuracy = NULL; + + LOG_NPS(DBG_LOW, "nps_update_position"); + lbs_server_nps->pos.fields = pos.fields; + lbs_server_nps->pos.timestamp = pos.timestamp; + lbs_server_nps->pos.latitude = pos.latitude; + lbs_server_nps->pos.longitude = pos.longitude; + lbs_server_nps->pos.altitude = pos.altitude; + lbs_server_nps->pos.hor_accuracy = pos.hor_accuracy; + lbs_server_nps->pos.ver_accuracy = pos.ver_accuracy; + + accuracy = g_variant_ref_sink(g_variant_new("(idd)", lbs_server_nps->pos.acc_level, lbs_server_nps->pos.hor_accuracy, lbs_server_nps->pos.ver_accuracy)); + + LOG_NPS(DBG_LOW, "time:%d", lbs_server_nps->pos.timestamp); + + lbs_server_emit_position_changed(lbs_server_nps->lbs_dbus_server, LBS_SERVER_METHOD_NPS, + lbs_server_nps->pos.fields, lbs_server_nps->pos.timestamp, lbs_server_nps->pos.latitude, + lbs_server_nps->pos.longitude, lbs_server_nps->pos.altitude, lbs_server_nps->pos.speed, + lbs_server_nps->pos.direction, 0.0, accuracy); + + g_variant_unref(accuracy); +} + +static gboolean nps_report_callback(gpointer user_data) +{ + LOG_NPS(DBG_LOW, "ENTER >>>"); + double vertical_accuracy = -1.0; /* vertical accuracy's invalid value is -1 */ + Plugin_LocationInfo location; + memset(&location, 0x00, sizeof(Plugin_LocationInfo)); + lbs_server_s *lbs_server_nps = (lbs_server_s *) user_data; + if (NULL == lbs_server_nps) { + LOG_GPS(DBG_ERR, "lbs_server_s is NULL!!"); + return FALSE; + } + time_t timestamp; + + g_mutex_lock(&lbs_server_nps->mutex); + memcpy(&location, &lbs_server_nps->location, sizeof(Plugin_LocationInfo)); + g_mutex_unlock(&lbs_server_nps->mutex); + + time(×tamp); + if (timestamp == lbs_server_nps->last_pos.timestamp) { + return FALSE; + } + + nps_set_status(lbs_server_nps, LBS_STATUS_AVAILABLE); + + NpsManagerPositionExt pos; + memset(&pos, 0x00, sizeof(NpsManagerPositionExt)); + + pos.timestamp = timestamp; + + if (location.latitude) { + pos.fields |= LBS_POSITION_EXT_FIELDS_LATITUDE; + pos.latitude = location.latitude; + } + + if (location.longitude) { + pos.fields |= LBS_POSITION_EXT_FIELDS_LONGITUDE; + pos.longitude = location.longitude; + } + + if (location.altitude) { + pos.fields |= LBS_POSITION_EXT_FIELDS_ALTITUDE; + pos.altitude = location.altitude; + } + + if (location.speed >= 0) { + pos.fields |= LBS_POSITION_EXT_FIELDS_SPEED; + pos.speed = location.speed; + } + if (location.bearing >= 0) { + pos.fields |= LBS_POSITION_EXT_FIELDS_DIRECTION; + pos.direction = location.bearing; + } + + pos.acc_level = LBS_ACCURACY_LEVEL_STREET; + pos.hor_accuracy = location.hpe; + pos.ver_accuracy = vertical_accuracy; + + nps_update_position(lbs_server_nps, pos); + + nps_set_position(lbs_server_nps, pos); + + return FALSE; +} + +static void __nps_callback(void *arg, const Plugin_LocationInfo *location, const void *reserved) +{ + LOG_NPS(DBG_LOW, "ENTER >>>"); + lbs_server_s *lbs_server = (lbs_server_s *)arg; + if (!lbs_server) { + LOG_NPS(DBG_ERR, "lbs_server is NULL!!"); + return; + } + + if (!location) { + LOG_NPS(DBG_LOW, "NULL is returned from plugin..."); + /* sometimes plugin returns NULL even if it is connected... */ + /*nps_set_status (lbs_server , LBS_STATUS_ACQUIRING); */ + return; + } + + g_mutex_lock(&lbs_server->mutex); + memcpy(&lbs_server->location, location, sizeof(Plugin_LocationInfo)); + g_mutex_unlock(&lbs_server->mutex); + + g_main_context_invoke(NULL, nps_report_callback, arg); +} + +static void _nps_token_callback(void *arg, const unsigned char *token, unsigned tokenSize) +{ + LOG_NPS(DBG_LOW, "ENTER >>>"); + lbs_server_s *lbs_server_nps = (lbs_server_s *)arg; + if (NULL == lbs_server_nps) { + LOG_NPS(DBG_ERR, "lbs-server is NULL!!"); + return; + } + + if (token == NULL) { + LOG_NPS(DBG_ERR, "*** no token to save\n"); + } else { + /* save the token in persistent storage */ + g_mutex_lock(&lbs_server_nps->mutex); + lbs_server_nps->token = g_new0(unsigned char, tokenSize); + if (lbs_server_nps->token) { + memcpy(lbs_server_nps->token, token, tokenSize); + } + g_mutex_unlock(&lbs_server_nps->mutex); + } + LOG_NPS(DBG_LOW, "_nps_token_callback ended"); +} + +static void _network_enabled_cb(keynode_t *key, void *user_data) +{ + LOG_GPS(DBG_LOW, "ENTER >>>"); + int enabled = 0; + + setting_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &enabled); + + /* This is vestige of nps-server + lbs_server_s *lbs_server_nps = (lbs_server_s *)user_data; + + if (enabled == 0) { + if (lbs_server_nps->loop != NULL) { + g_main_loop_quit(lbs_server_nps->loop); + } + } + */ +} +static gboolean nps_offline_location(lbs_server_s *lbs_server) +{ + LOG_NPS(DBG_LOW, "ENTER >>>"); + if (NULL == lbs_server) { + LOG_GPS(DBG_ERR, "lbs-server is NULL!!"); + return FALSE; + } + char key[NPS_UNIQUE_ID_LEN] = { 0, }; + + if (setting_get_unique_id(key)) { + LOG_NPS(DBG_LOW, "key = %s", key); + get_nps_plugin_module()->getOfflineToken((unsigned char *)key, NPS_UNIQUE_ID_LEN, + _nps_token_callback, lbs_server); + if (lbs_server->token != NULL) { + LOG_NPS(DBG_LOW, "Token = %s", lbs_server->token); + int ret = get_nps_plugin_module()->offlineLocation((unsigned char *)key, + NPS_UNIQUE_ID_LEN, lbs_server->token, 0, + __nps_callback, lbs_server); + if (ret) { + if (lbs_server->is_nps_running) { + LOG_NPS(DBG_LOW, "offlineLocation() called nps_callback successfully."); + return TRUE; + } + } + } else { + LOG_NPS(DBG_ERR, "getOfflineToken(): Token is NULL"); + } + } else { + LOG_NPS(DBG_ERR, "lbs_get_unique_id() failed."); + } + return TRUE; +} + +static void __nps_cancel_callback(void *arg) +{ + LOG_NPS(DBG_LOW, "__nps_cancel_callback"); + lbs_server_s *lbs_server = (lbs_server_s *) arg; + if (!lbs_server) { + LOG_NPS(DBG_ERR, "lbs-server is NULL!!"); + return; + } + + g_mutex_lock(&lbs_server->mutex); + lbs_server->is_nps_running = FALSE; + g_cond_signal(&lbs_server->cond); + g_mutex_unlock(&lbs_server->mutex); +} + +static void start_batch_tracking(lbs_server_s *lbs_server, int batch_interval, int batch_period) +{ + g_mutex_lock(&lbs_server->mutex); + lbs_server->gps_client_count++; + g_mutex_unlock(&lbs_server->mutex); + + if (lbs_server->is_gps_running == TRUE) { + LOG_GPS(DBG_LOW, "Batch: gps is already running"); + return; + } + LOG_GPS(DBG_LOW, "Batch: start_tracking GPS"); + lbs_server->status = LBS_STATUS_ACQUIRING; + + if (request_start_batch_session(batch_interval, batch_period) == TRUE) { + g_mutex_lock(&lbs_server->mutex); + lbs_server->is_gps_running = TRUE; + g_mutex_unlock(&lbs_server->mutex); + + lbs_server->is_needed_changing_interval = FALSE; + + /* ADD notify */ + setting_notify_key_changed(VCONFKEY_LOCATION_ENABLED, __setting_gps_cb, lbs_server); + } else { + LOG_GPS(DBG_ERR, "Batch: Fail to request_start_batch_session"); + } +} + +static void stop_batch_tracking(lbs_server_s *lbs_server) +{ + LOG_GPS(DBG_LOW, "ENTER >>>"); + + g_mutex_lock(&lbs_server->mutex); + lbs_server->gps_client_count--; + g_mutex_unlock(&lbs_server->mutex); + + if (lbs_server->is_gps_running == FALSE) { + LOG_GPS(DBG_LOW, "Batch: gps- is already stopped"); + return; + } + + if (lbs_server->gps_client_count <= 0) { + g_mutex_lock(&lbs_server->mutex); + lbs_server->gps_client_count = 0; + + if (request_stop_batch_session() == TRUE) { + lbs_server->is_gps_running = FALSE; + lbs_server->sv_used = FALSE; + /* remove notify */ + setting_ignore_key_changed(VCONFKEY_LOCATION_ENABLED, __setting_gps_cb); + g_mutex_unlock(&lbs_server->mutex); + } + } + + lbs_server->status = LBS_STATUS_UNAVAILABLE; + lbs_server_emit_status_changed(lbs_server->lbs_dbus_server, LBS_SERVER_METHOD_GPS, LBS_STATUS_UNAVAILABLE); +} + +static void start_tracking(lbs_server_s *lbs_server, lbs_server_method_e method) +{ + switch (method) { + case LBS_SERVER_METHOD_GPS: + + g_mutex_lock(&lbs_server->mutex); + lbs_server->gps_client_count++; + g_mutex_unlock(&lbs_server->mutex); + + if (lbs_server->is_gps_running == TRUE) { + LOG_GPS(DBG_LOW, "gps is already running"); + return; + } + LOG_GPS(DBG_LOW, "start_tracking GPS"); + lbs_server->status = LBS_STATUS_ACQUIRING; + + if (request_start_session((int)(lbs_server->optimized_interval_array[method])) == TRUE) { + g_mutex_lock(&lbs_server->mutex); + lbs_server->is_gps_running = TRUE; + g_mutex_unlock(&lbs_server->mutex); + + lbs_server->is_needed_changing_interval = FALSE; + + /* ADD notify */ + setting_notify_key_changed(VCONFKEY_LOCATION_ENABLED, __setting_gps_cb, lbs_server); + } else { + LOG_GPS(DBG_ERR, "Fail to request_start_session"); + } + + break; + + case LBS_SERVER_METHOD_NPS: + g_mutex_lock(&lbs_server->mutex); + lbs_server->nps_client_count++; + g_mutex_unlock(&lbs_server->mutex); + + if (lbs_server->is_nps_running == TRUE) { + LOG_NPS(DBG_LOW, "nps is already running"); + return; + } + + LOG_NPS(DBG_LOW, "start_tracking - LBS_SERVER_METHOD_NPS"); + nps_set_status(lbs_server, LBS_STATUS_ACQUIRING); + + void *handle_str = NULL; + int ret = get_nps_plugin_module()->start(lbs_server->period, __nps_callback, lbs_server, &(handle_str)); + LOG_NPS(DBG_LOW, "after get_nps_plugin_module()->location"); + + if (ret) { + lbs_server->handle = handle_str; + g_mutex_lock(&lbs_server->mutex); + lbs_server->is_nps_running = TRUE; + g_mutex_unlock(&lbs_server->mutex); + vconf_ignore_key_changed(VCONFKEY_LOCATION_NETWORK_ENABLED, _network_enabled_cb); + return; + } + + if (nps_is_dummy_plugin_module() != TRUE) { + nps_offline_location(lbs_server); + } + + LOG_NPS(DBG_ERR, "FAILS WPS START"); + nps_set_status(lbs_server, LBS_STATUS_ERROR); + break; + + default: + LOG_GPS(DBG_LOW, "start_tracking Invalid"); + } + +} + +static gboolean nps_stop(lbs_server_s *lbs_server_nps) +{ + LOG_NPS(DBG_LOW, "ENTER >>>"); + if (!lbs_server_nps) { + LOG_NPS(DBG_ERR, "lbs-server is NULL!!"); + return FALSE; + } + + int ret = get_nps_plugin_module()->stop(lbs_server_nps->handle, __nps_cancel_callback, lbs_server_nps); + if (ret) { + g_mutex_lock(&lbs_server_nps->mutex); + while (lbs_server_nps->is_nps_running) { + g_cond_wait(&lbs_server_nps->cond, &lbs_server_nps->mutex); + } + lbs_server_nps->is_nps_running = FALSE; + g_mutex_unlock(&lbs_server_nps->mutex); + } + /* This is vestige of nps-server + else { + if (lbs_server_nps->loop != NULL) { + LOG_NPS(DBG_ERR, "module->stop() is failed. nps is cloesed."); + g_main_loop_quit(lbs_server_nps->loop); + return FALSE; + } + } + */ + + nps_set_status(lbs_server_nps, LBS_STATUS_UNAVAILABLE); + + return TRUE; +} + +static void stop_tracking(lbs_server_s *lbs_server, lbs_server_method_e method) +{ + switch (method) { + case LBS_SERVER_METHOD_GPS: + LOG_GPS(DBG_LOW, "stop_tracking GPS"); + + gps_set_last_position(&lbs_server->position); + + g_mutex_lock(&lbs_server->mutex); + lbs_server->gps_client_count--; + g_mutex_unlock(&lbs_server->mutex); + + if (lbs_server->is_gps_running == FALSE) { + LOG_GPS(DBG_LOW, "gps- is already stopped"); + return; + } + + if (lbs_server->gps_client_count <= 0) { + g_mutex_lock(&lbs_server->mutex); + lbs_server->gps_client_count = 0; + + if (request_stop_session() == TRUE) { + lbs_server->is_gps_running = FALSE; + lbs_server->sv_used = FALSE; + /* remove notify */ + setting_ignore_key_changed(VCONFKEY_LOCATION_ENABLED, __setting_gps_cb); + g_mutex_unlock(&lbs_server->mutex); + } + } + + lbs_server->status = LBS_STATUS_UNAVAILABLE; + lbs_server_emit_status_changed(lbs_server->lbs_dbus_server, LBS_SERVER_METHOD_GPS, + LBS_STATUS_UNAVAILABLE); + + break; + case LBS_SERVER_METHOD_NPS: + LOG_NPS(DBG_LOW, "stop_tracking NPS"); + + g_mutex_lock(&lbs_server->mutex); + lbs_server->nps_client_count--; + g_mutex_unlock(&lbs_server->mutex); + + if (lbs_server->is_nps_running == FALSE) { + LOG_NPS(DBG_LOW, "nps- is already stopped"); + return; + } + + if (lbs_server->nps_client_count <= 0) { + g_mutex_lock(&lbs_server->mutex); + lbs_server->nps_client_count = 0; + g_mutex_unlock(&lbs_server->mutex); + + LOG_NPS(DBG_LOW, "lbs_server_nps Normal stop"); + nps_stop(lbs_server); + } + + break; + default: + LOG_GPS(DBG_LOW, "stop_tracking Invalid"); + } +} + +static void update_dynamic_interval_table_foreach_cb(gpointer key, gpointer value, gpointer userdata) +{ + guint *interval_array = (guint *)value; + dynamic_interval_updator_user_data *updator_ud = (dynamic_interval_updator_user_data *)userdata; + lbs_server_s *lbs_server = updator_ud->lbs_server; + int method = updator_ud->method; + + LOG_GPS(DBG_LOW, "foreach dynamic-interval. method:[%d], key:[%s]-interval:[%u], current optimized interval [%u]", method, (char *)key, interval_array[method], lbs_server->optimized_interval_array[method]); + if ((lbs_server->temp_minimum_interval > interval_array[method])) { + lbs_server->temp_minimum_interval = interval_array[method]; + } +} + +static gboolean update_pos_tracking_interval(lbs_server_interval_manipulation_type type, const gchar *client, int method, guint interval, gpointer userdata) +{ + LOG_GPS(DBG_LOW, "ENTER >>>"); + if (userdata == NULL) return FALSE; + if (client == NULL) { + LOG_GPS(DBG_ERR, "client is NULL"); + return FALSE; + } + + if (method < LBS_SERVER_METHOD_GPS || method >= LBS_SERVER_METHOD_SIZE) { + LOG_GPS(DBG_ERR, "unavailable method [%d]", method); + return FALSE; + } + + gboolean ret_val = FALSE; + lbs_server_s *lbs_server = (lbs_server_s *)userdata; + + /* manipulate logic for dynamic-interval hash table */ + switch (type) { + case LBS_SERVER_INTERVAL_ADD: { + LOG_GPS(DBG_LOW, "ADD, client[%s], method[%d], interval[%u]", client, method, interval); + gchar *client_cpy = NULL; + client_cpy = g_strdup(client); + + guint *interval_array = (guint *) g_hash_table_lookup(lbs_server->dynamic_interval_table, client_cpy); + if (!interval_array) { + LOG_GPS(DBG_LOW, "first add key[%s] to interval-table", client); + interval_array = (guint *)g_malloc0(LBS_SERVER_METHOD_SIZE * sizeof(guint)); + if (!interval_array) { + LOG_GPS(DBG_ERR, "interval_array is NULL"); + g_free(client_cpy); + return FALSE; + } + g_hash_table_insert(lbs_server->dynamic_interval_table, (gpointer)client_cpy, (gpointer)interval_array); + } + interval_array[method] = interval; + lbs_server->temp_minimum_interval = interval; + LOG_GPS(DBG_LOW, "ADD done"); + break; + } + + case LBS_SERVER_INTERVAL_REMOVE: { + LOG_GPS(DBG_LOW, "REMOVE, client[%s], method[%d]", client, method); + lbs_server->temp_minimum_interval = 120; /* interval max value */ + guint *interval_array = (guint *) g_hash_table_lookup(lbs_server->dynamic_interval_table, client); + if (!interval_array) { + LOG_GPS(DBG_INFO, "Client[%s] Method[%d] is already removed from interval-table", client, method); + break; + } + LOG_GPS(DBG_LOW, "Found interval_array[%d](%p):[%u] from interval-table", method, interval_array, interval_array[method]); + interval_array[method] = 0; + + int i = 0; + guint interval_each = 0; + gboolean is_need_remove_client_from_table = TRUE; + for (i = 0; i < LBS_SERVER_METHOD_SIZE; i++) { + interval_each = interval_array[i]; + if (interval_each != 0) { + LOG_GPS(DBG_LOW, "[%s] method[%d]'s interval is not zero - interval: %d. It will not be removed.", client, i, interval_each); + is_need_remove_client_from_table = FALSE; + break; + } + } + + if (is_need_remove_client_from_table) { + LOG_GPS(DBG_LOW, "is_need_remove_client_from_table is TRUE"); + if (!g_hash_table_remove(lbs_server->dynamic_interval_table, client)) { + LOG_GPS(DBG_ERR, "g_hash_table_remove is failed."); + } + LOG_GPS(DBG_LOW, "REMOVE done."); + } + break; + } + + case LBS_SERVER_INTERVAL_UPDATE: { + LOG_GPS(DBG_LOW, "UPDATE client[%s], method[%d], interval[%u]", client, method, interval); + guint *interval_array = (guint *) g_hash_table_lookup(lbs_server->dynamic_interval_table, client); + if (!interval_array) { + LOG_GPS(DBG_LOW, "Client[%s] is not exist in interval-table", client, method); + break; + } + interval_array[method] = interval; + lbs_server->temp_minimum_interval = interval; + LOG_GPS(DBG_LOW, "UPDATE done."); + break; + } + + default: { + LOG_GPS(DBG_ERR, "unhandled interval-update type"); + return FALSE; + } + } + + /* update logic for optimized-interval value */ + if (g_hash_table_size(lbs_server->dynamic_interval_table) == 0) { + LOG_GPS(DBG_LOW, "dynamic_interval_table size is zero. It will be updated all value as 0"); + int i = 0; + for (i = 0; i < LBS_SERVER_METHOD_SIZE; i++) { + lbs_server->optimized_interval_array[i] = 0; + } + ret_val = FALSE; + } else { + LOG_GPS(DBG_LOW, "dynamic_interval_table size is not zero."); + + dynamic_interval_updator_user_data updator_user_data; + updator_user_data.lbs_server = lbs_server; + updator_user_data.method = method; + + g_hash_table_foreach(lbs_server->dynamic_interval_table, (GHFunc)update_dynamic_interval_table_foreach_cb, (gpointer)&updator_user_data); + + if (lbs_server->optimized_interval_array[method] != lbs_server->temp_minimum_interval) { + LOG_GPS(DBG_INFO, "Changing optimized_interval value [%u -> %u] for method [%d]", + lbs_server->optimized_interval_array[method], lbs_server->temp_minimum_interval, method); + lbs_server->optimized_interval_array[method] = lbs_server->temp_minimum_interval; + + /* need to send message to provider device */ + lbs_server->is_needed_changing_interval = TRUE; + } + + if (lbs_server->is_needed_changing_interval) { + ret_val = TRUE; + } else { + ret_val = FALSE; + } + } + LOG_GPS(DBG_LOW, "update_pos_tracking_interval done."); + return ret_val; +} + +static void request_change_pos_update_interval(int method, gpointer userdata) +{ + LOG_GPS(DBG_LOW, "ENTER >>>"); + if (!userdata) return; + + lbs_server_s *lbs_server = (lbs_server_s *)userdata; + switch (method) { + case LBS_SERVER_METHOD_GPS: + request_change_pos_update_interval_standalone_gps(lbs_server->optimized_interval_array[method]); + break; + default: + break; + } +} + +static void get_nmea(int *timestamp, gchar **nmea_data, gpointer userdata) +{ + LOG_GPS(DBG_LOW, "ENTER >>>"); + if (!userdata) return; + + get_nmea_from_server(timestamp, nmea_data); + + LOG_GPS(DBG_LOW, "timestmap: %d, nmea_data: %s", *timestamp, *nmea_data); +} + +static void set_options(GVariant *options, const gchar *client, gpointer userdata) +{ + LOG_GPS(DBG_LOW, "ENTER >>>"); + lbs_server_s *lbs_server = (lbs_server_s *)userdata; + + GVariantIter iter; + gchar *key = NULL; + GVariant *value = NULL; + gboolean ret = FALSE; +#ifdef _TIZEN_PUBLIC_ + char *msg_header = NULL; + char *msg_body = NULL; + int size = 0; +#endif + gsize length = 0; + char *option = NULL; + char *app_id = NULL; + guint interval = 0; + + lbs_server_method_e method = 0; + + g_variant_iter_init(&iter, options); + ret = g_variant_iter_next(&iter, "{&sv}", &key, &value); + if (ret == FALSE) { + LOG_GPS(DBG_ERR, "Invalid GVariant"); + return; + } + if (!g_strcmp0(key, "CMD")) { + LOG_GPS(DBG_LOW, "set_options [%s]", g_variant_get_string(value, &length)); + if (!g_strcmp0(g_variant_get_string(value, &length), "START")) { + + while (g_variant_iter_next(&iter, "{&sv}", &key, &value)) { + if (!g_strcmp0(key, "METHOD")) { + method = g_variant_get_int32(value); + LOG_GPS(DBG_LOW, "METHOD [%d]", method); + } + + if (!g_strcmp0(key, "INTERVAL")) { + interval = g_variant_get_uint32(value); + LOG_GPS(DBG_LOW, "INTERVAL [%u]", interval); + } + + if (!g_strcmp0(key, "APP_ID")) { + app_id = g_variant_dup_string(value, &length); + LOG_GPS(DBG_LOW, "APP_ID [%s]", app_id); + } + } + + if (client) { + update_pos_tracking_interval(LBS_SERVER_INTERVAL_ADD, client, method, interval, lbs_server); + } + + if (app_id) { + if (LBS_SERVER_METHOD_GPS == method) { + gps_dump_log("START GPS", app_id); + } + free(app_id); + } + + start_tracking(lbs_server, method); + + if (lbs_server->is_needed_changing_interval) { + lbs_server->is_needed_changing_interval = FALSE; + request_change_pos_update_interval(method, (gpointer)lbs_server); + } + } else if (!g_strcmp0(g_variant_get_string(value, &length), "STOP")) { + + while (g_variant_iter_next(&iter, "{&sv}", &key, &value)) { + if (!g_strcmp0(key, "METHOD")) { + method = g_variant_get_int32(value); + LOG_GPS(DBG_LOW, "METHOD [%d]", method); + } + + if (!g_strcmp0(key, "APP_ID")) { + app_id = g_variant_dup_string(value, &length); + LOG_GPS(DBG_LOW, "APP_ID [%s]", app_id); + } + } + + if (client) { + update_pos_tracking_interval(LBS_SERVER_INTERVAL_REMOVE, client, method, interval, lbs_server); + } + + if (app_id) { + if (LBS_SERVER_METHOD_GPS == method) { + gps_dump_log("STOP GPS", app_id); + } + free(app_id); + } + + stop_tracking(lbs_server, method); + + if (lbs_server->is_needed_changing_interval) { + lbs_server->is_needed_changing_interval = FALSE; + request_change_pos_update_interval(method, (gpointer)lbs_server); + } + } else if (!g_strcmp0(g_variant_get_string(value, &length), "START_BATCH")) { + + int batch_interval = 0; + int batch_period = 0; + while (g_variant_iter_next(&iter, "{&sv}", &key, &value)) { + + if (!g_strcmp0(key, "BATCH_INTERVAL")) { + batch_interval = g_variant_get_int32(value); + LOG_GPS(DBG_LOW, "BATCH_INTERVAL [%d]", batch_interval); + } else if (!g_strcmp0(key, "BATCH_PERIOD")) { + batch_period = g_variant_get_int32(value); + LOG_GPS(DBG_LOW, "BATCH_PERIOD [%d]", batch_period); + } + } + + if (client) { + update_pos_tracking_interval(LBS_SERVER_INTERVAL_ADD, client, method, batch_interval, lbs_server); + } + + start_batch_tracking(lbs_server, batch_interval, batch_period); + + if (lbs_server->is_needed_changing_interval) { + lbs_server->is_needed_changing_interval = FALSE; + request_change_pos_update_interval(method, (gpointer)lbs_server); + } + + } else if (!g_strcmp0(g_variant_get_string(value, &length), "STOP_BATCH")) { + + if (client) { + update_pos_tracking_interval(LBS_SERVER_INTERVAL_REMOVE, client, method, interval, lbs_server); + } + + stop_batch_tracking(lbs_server); + + if (lbs_server->is_needed_changing_interval) { + lbs_server->is_needed_changing_interval = FALSE; + request_change_pos_update_interval(method, (gpointer)lbs_server); + } + } +#ifdef _TIZEN_PUBLIC_ + } else if (!g_strcmp0(g_variant_get_string(value, &length), "SUPLNI")) { + while (g_variant_iter_next(&iter, "{&sv}", &key, &value)) { + if (!g_strcmp0(key, "HEADER")) { + msg_header = g_variant_dup_string(value, &length); + } else if (!g_strcmp0(key, "BODY")) { + size = (int) g_variant_get_size(value); + msg_body = (char *) g_malloc0(sizeof(char) * size); + memcpy(msg_body, g_variant_get_data(value), size); + } else if (!g_strcmp0(key, "SIZE")) { + size = (int) g_variant_get_int32(value); + } + } + request_supl_ni_session(msg_header, msg_body, size); + if (msg_header) g_free(msg_header); + if (msg_body) g_free(msg_body); + } +#endif + else if (!g_strcmp0(g_variant_get_string(value, &length), "SET:OPT")) { + LOG_GPS(DBG_LOW, "SET:OPT is called"); + gboolean is_update_interval = FALSE, is_update_interval_method = FALSE; + + while (g_variant_iter_next(&iter, "{&sv}", &key, &value)) { + + if (!g_strcmp0(key, "OPTION")) { + option = g_variant_dup_string(value, &length); + LOG_GPS(DBG_ERR, "option [%s]", option); + + if (!g_strcmp0(option, "DELGPS")) { + if (request_delete_gps_data() != TRUE) { + LOG_GPS(DBG_ERR, "Fail to request_delete_gps_data"); + } + } else if (!g_strcmp0(option, "USE_SV")) { + g_mutex_lock(&lbs_server->mutex); + if (lbs_server->sv_used == FALSE) + lbs_server->sv_used = TRUE; + g_mutex_unlock(&lbs_server->mutex); + } + g_free(option); + } + + if (!g_strcmp0(key, "METHOD")) { + method = g_variant_get_int32(value); + LOG_GPS(DBG_LOW, "METHOD [%d]", method); + is_update_interval_method = TRUE; + } + + if (!g_strcmp0(key, "INTERVAL_UPDATE")) { + interval = g_variant_get_uint32(value); + LOG_GPS(DBG_LOW, "INTERVAL_UPDATE [%u]", interval); + is_update_interval = TRUE; + } + } + + if (is_update_interval && is_update_interval_method && client) { + update_pos_tracking_interval(LBS_SERVER_INTERVAL_UPDATE, client, method, interval, lbs_server); + if (lbs_server->is_needed_changing_interval) { + lbs_server->is_needed_changing_interval = FALSE; + request_change_pos_update_interval(method, (gpointer)lbs_server); + } + } + } +} +} + +static gboolean gps_remove_all_clients(lbs_server_s *lbs_server) +{ + LOG_GPS(DBG_LOW, "remove_all_clients GPS"); + if (lbs_server->gps_client_count <= 0) { + lbs_server->gps_client_count = 0; + return FALSE; + } + + lbs_server->gps_client_count = 0; + stop_tracking(lbs_server, LBS_SERVER_METHOD_GPS); + + return TRUE; +} + +static void shutdown(gpointer userdata, gboolean *shutdown_arr) +{ + LOG_GPS(DBG_LOW, "shutdown callback gps:%d nps:%d", shutdown_arr[LBS_SERVER_METHOD_GPS], shutdown_arr[LBS_SERVER_METHOD_NPS]); + lbs_server_s *lbs_server = (lbs_server_s *)userdata; + + if (shutdown_arr[LBS_SERVER_METHOD_GPS]) { + LOG_GPS(DBG_LOW, "-> shutdown GPS"); + if (lbs_server->is_gps_running) { + if (gps_remove_all_clients(lbs_server)) { + LOG_GPS(DBG_ERR, "<<<< Abnormal shutdown >>>>"); + } + } + } + + if (shutdown_arr[LBS_SERVER_METHOD_NPS]) { + LOG_NPS(DBG_LOW, "-> shutdown NPS"); + if (lbs_server->is_nps_running) { + LOG_NPS(DBG_ERR, "lbs_server_nps is running. nps_stop"); + nps_stop(lbs_server); + } + } + + /* + int enabled = 0; + setting_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &enabled); + if (enabled == 0) { + if (lbs_server->loop != NULL) { + g_main_loop_quit(lbs_server->loop); + } + } else { + if (vconf_notify_key_changed(VCONFKEY_LOCATION_NETWORK_ENABLED, _network_enabled_cb, lbs_server)) { + LOG_NPS(DBG_ERR, "fail to notify VCONFKEY_LOCATION_NETWORK_ENABLED"); + } + } + */ +} + +static void gps_update_position_cb(pos_data_t *pos, gps_error_t error, void *user_data) +{ + LOG_GPS(DBG_LOW, "ENTER >>>"); + + GVariant *accuracy = NULL; + LbsPositionExtFields fields; + + lbs_server_s *lbs_server = (lbs_server_s *)(user_data); + + memcpy(&lbs_server->position, pos, sizeof(pos_data_t)); + + if (lbs_server->status != LBS_STATUS_AVAILABLE) { + lbs_server_emit_status_changed(lbs_server->lbs_dbus_server, LBS_SERVER_METHOD_GPS, LBS_STATUS_AVAILABLE); + lbs_server->status = LBS_STATUS_AVAILABLE; + } + + fields = (LBS_POSITION_EXT_FIELDS_LATITUDE | LBS_POSITION_EXT_FIELDS_LONGITUDE | LBS_POSITION_EXT_FIELDS_ALTITUDE | LBS_POSITION_EXT_FIELDS_SPEED | LBS_POSITION_EXT_FIELDS_DIRECTION); + + accuracy = g_variant_new("(idd)", LBS_ACCURACY_LEVEL_DETAILED, pos->hor_accuracy, pos->ver_accuracy); + if (NULL == accuracy) { + LOG_GPS(DBG_LOW, "accuracy is NULL"); + } + + lbs_server_emit_position_changed(lbs_server->lbs_dbus_server, LBS_SERVER_METHOD_GPS, + fields, pos->timestamp, pos->latitude, pos->longitude, pos->altitude, + pos->speed, pos->bearing, 0.0, accuracy); +} + +static void gps_update_batch_cb(batch_data_t *batch, void *user_data) +{ + LOG_GPS(DBG_LOW, "ENTER >>>"); + lbs_server_s *lbs_server = (lbs_server_s *)(user_data); + memcpy(&lbs_server->batch, batch, sizeof(batch_data_t)); + + if (lbs_server->status != LBS_STATUS_AVAILABLE) { + lbs_server_emit_status_changed(lbs_server->lbs_dbus_server, LBS_SERVER_METHOD_GPS, LBS_STATUS_AVAILABLE); + lbs_server->status = LBS_STATUS_AVAILABLE; + } + + lbs_server_emit_batch_changed(lbs_server->lbs_dbus_server, batch->num_of_location); +} + +static void gps_update_satellite_cb(sv_data_t *sv, void *user_data) +{ + lbs_server_s *lbs_server = (lbs_server_s *)(user_data); + if (lbs_server->sv_used == FALSE) { + /*LOG_GPS(DBG_LOW, "sv_used is FALSE"); */ + return; + } + + LOG_GPS(DBG_LOW, "ENTER >>>"); + int index; + int timestamp = 0; + int satellite_used = 0; + GVariant *used_prn = NULL; + GVariantBuilder *used_prn_builder = NULL; + GVariant *satellite_info = NULL; + GVariantBuilder *satellite_info_builder = NULL; + + memcpy(&lbs_server->satellite, sv, sizeof(sv_data_t)); + timestamp = sv->timestamp; + + used_prn_builder = g_variant_builder_new(G_VARIANT_TYPE("ai")); + for (index = 0; index < sv->num_of_sat; ++index) { + if (sv->sat[index].used) { + g_variant_builder_add(used_prn_builder, "i", sv->sat[index].prn); + ++satellite_used; + } + } + used_prn = g_variant_builder_end(used_prn_builder); + + satellite_info_builder = g_variant_builder_new(G_VARIANT_TYPE("a(iiii)")); + for (index = 0; index < sv->num_of_sat; ++index) { + g_variant_builder_add(satellite_info_builder, "(iiii)", sv->sat[index].prn, + sv->sat[index].elevation, sv->sat[index].azimuth, sv->sat[index].snr); + } + satellite_info = g_variant_builder_end(satellite_info_builder); + + lbs_server_emit_satellite_changed(lbs_server->lbs_dbus_server, timestamp, satellite_used, sv->num_of_sat, + used_prn, satellite_info); +} + +static void gps_update_nmea_cb(nmea_data_t *nmea, void *user_data) +{ + lbs_server_s *lbs_server = (lbs_server_s *)(user_data); + + if (lbs_server->nmea.data) { + g_free(lbs_server->nmea.data); + lbs_server->nmea.len = 0; + lbs_server->nmea.data = NULL; + } + lbs_server->nmea.timestamp = lbs_server->position.timestamp; + lbs_server->nmea.data = g_malloc(nmea->len + 1); + g_return_if_fail(lbs_server->nmea.data); + + g_memmove(lbs_server->nmea.data, nmea->data, nmea->len); + lbs_server->nmea.data[nmea->len] = '\0'; + lbs_server->nmea.len = nmea->len; + + if (lbs_server->nmea_used == FALSE) { + /*LOG_GPS(DBG_LOW, "nmea_used is FALSE"); */ + return; + } + LOG_GPS(DBG_LOW, "[%d] %s", lbs_server->nmea.timestamp, lbs_server->nmea.data); + lbs_server_emit_nmea_changed(lbs_server->lbs_dbus_server, lbs_server->nmea.timestamp, lbs_server->nmea.data); +} + +int gps_update_geofence_transition(int geofence_id, geofence_zone_state_t transition, double latitude, double longitude, double altitude, double speed, double bearing, double hor_accuracy, void *data) +{ + lbs_server_s *lbs_server = (lbs_server_s *)data; + lbs_server_emit_gps_geofence_changed(lbs_server->lbs_dbus_server, geofence_id, transition, latitude, longitude, altitude, speed, bearing, hor_accuracy); + return 0; +} + +int gps_update_geofence_service_status(int status, void *data) +{ + lbs_server_s *lbs_server = (lbs_server_s *)data; + lbs_server_emit_gps_geofence_status_changed(lbs_server->lbs_dbus_server, status); + return 0; +} + +static void add_fence(gint fence_id, gdouble latitude, gdouble longitude, gint radius, gint last_state, gint monitor_states, gint notification_responsiveness, gint unknown_timer, gpointer userdata) +{ + request_add_geofence(fence_id, latitude, longitude, radius, last_state, monitor_states, notification_responsiveness, unknown_timer); +} + +static void remove_fence(gint fence_id, gpointer userdata) +{ + request_delete_geofence(fence_id); +} + +static void pause_fence(gint fence_id, gpointer userdata) +{ + request_pause_geofence(fence_id); +} + +static void resume_fence(gint fence_id, gint monitor_states, gpointer userdata) +{ + request_resume_geofence(fence_id, monitor_states); +} + +static void nps_init(lbs_server_s *lbs_server_nps); + +static void lbs_server_init(lbs_server_s *lbs_server) +{ + LOG_GPS(DBG_LOW, "lbs_server_init"); + + lbs_server->status = LBS_STATUS_UNAVAILABLE; + g_mutex_init(&lbs_server->mutex); + + memset(&lbs_server->position, 0x00, sizeof(pos_data_t)); + memset(&lbs_server->satellite, 0x00, sizeof(sv_data_t)); + memset(&lbs_server->nmea, 0x00, sizeof(nmea_data_t)); + + lbs_server->is_gps_running = FALSE; + lbs_server->sv_used = FALSE; + lbs_server->nmea_used = FALSE; + lbs_server->gps_client_count = 0; + + nps_init(lbs_server); + + /* create resource for dynamic-interval */ + lbs_server->dynamic_interval_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + lbs_server->optimized_interval_array = (guint *)g_malloc0(LBS_SERVER_METHOD_SIZE * sizeof(guint)); + lbs_server->is_needed_changing_interval = FALSE; +} + +static void nps_get_last_position(lbs_server_s *lbs_server_nps) +{ + int timestamp; + char location[128] = {0,}; + char *last_location[MAX_NPS_LOC_ITEM] = {0,}; + char *last = NULL; + char *str = NULL; + int index = 0; + + setting_get_int(VCONFKEY_LOCATION_NV_LAST_WPS_TIMESTAMP, ×tamp); + str = setting_get_string(VCONFKEY_LOCATION_NV_LAST_WPS_LOCATION); + if (str == NULL) { + return; + } + snprintf(location, sizeof(location), "%s", str); + free(str); + + last_location[index] = (char *)strtok_r(location, ";", &last); + while (last_location[index++] != NULL) { + if (index == MAX_NPS_LOC_ITEM) + break; + last_location[index] = (char *)strtok_r(NULL, ";", &last); + } + index = 0; + + lbs_server_nps->last_pos.timestamp = timestamp; + lbs_server_nps->last_pos.latitude = strtod(last_location[index++], NULL); + lbs_server_nps->last_pos.longitude = strtod(last_location[index++], NULL); + lbs_server_nps->last_pos.altitude = strtod(last_location[index++], NULL); + lbs_server_nps->last_pos.speed = strtod(last_location[index++], NULL); + lbs_server_nps->last_pos.direction = strtod(last_location[index++], NULL); + lbs_server_nps->last_pos.hor_accuracy = strtod(last_location[index], NULL); + + LOG_NPS(DBG_LOW, "get nps_last_position timestamp : %d", lbs_server_nps->last_pos.timestamp); +} + +static void nps_init(lbs_server_s *lbs_server_nps) +{ + LOG_NPS(DBG_LOW, "nps_init"); + + lbs_server_nps->handle = NULL; + lbs_server_nps->period = 5000; + nps_set_status(lbs_server_nps, LBS_STATUS_UNAVAILABLE); + + lbs_server_nps->pos.fields = LBS_POSITION_EXT_FIELDS_NONE; + lbs_server_nps->pos.timestamp = 0; + lbs_server_nps->pos.latitude = 0.0; + lbs_server_nps->pos.longitude = 0.0; + lbs_server_nps->pos.altitude = 0.0; + lbs_server_nps->pos.acc_level = LBS_POSITION_EXT_FIELDS_NONE; + lbs_server_nps->pos.hor_accuracy = -1.0; + lbs_server_nps->pos.ver_accuracy = -1.0; + + lbs_server_nps->last_pos.timestamp = 0; + lbs_server_nps->last_pos.latitude = 0.0; + lbs_server_nps->last_pos.longitude = 0.0; + lbs_server_nps->last_pos.altitude = 0.0; + lbs_server_nps->last_pos.hor_accuracy = 0.0; + lbs_server_nps->last_pos.speed = 0.0; + lbs_server_nps->last_pos.direction = 0.0; + +#if !GLIB_CHECK_VERSION (2, 31, 0) + GMutex *mutex_temp = g_mutex_new(); + lbs_server_nps->mutex = *mutex_temp; + GCond *cond_temp = g_cond_new(); + lbs_server_nps->cond = *cond_temp; +#endif + + g_mutex_init(&lbs_server_nps->mutex); + g_cond_init(&lbs_server_nps->cond); + + lbs_server_nps->is_nps_running = FALSE; + lbs_server_nps->nps_client_count = 0; + + if (!get_nps_plugin_module()->load()) { + LOG_NPS(DBG_ERR, "lbs_server_nps plugin load() failed."); + return ; + } + + nps_get_last_position(lbs_server_nps); +} + +static void nps_deinit(lbs_server_s *lbs_server_nps) +{ + LOG_NPS(DBG_LOW, "nps_deinit"); + if (get_nps_plugin_module()->unload()) { + if (lbs_server_nps->is_nps_running) { + g_mutex_lock(&lbs_server_nps->mutex); + lbs_server_nps->is_nps_running = FALSE; + g_cond_signal(&lbs_server_nps->cond); + g_mutex_unlock(&lbs_server_nps->mutex); + } + + if (lbs_server_nps->token) { + g_mutex_lock(&lbs_server_nps->mutex); + g_free(lbs_server_nps->token); + g_mutex_unlock(&lbs_server_nps->mutex); + } + } else { + LOG_NPS(DBG_ERR, "unload() failed."); + } + + lbs_server_nps->handle = NULL; + lbs_server_nps->is_nps_running = FALSE; + lbs_server_nps->nps_client_count = 0; + +#if !GLIB_CHECK_VERSION (2, 31, 0) + g_cond_free(&lbs_server_nps->cond); + g_mutex_free(&lbs_server_nps->mutex); +#endif + + g_cond_clear(&lbs_server_nps->cond); + g_mutex_clear(&lbs_server_nps->mutex); + + nps_set_status(lbs_server_nps, LBS_STATUS_UNAVAILABLE); +} + +static void _glib_log(const gchar *log_domain, GLogLevelFlags log_level, + const gchar *msg, gpointer user_data) +{ + LOG_NPS(DBG_ERR, "GLIB[%d] : %s", log_level, msg); +} + +int main(int argc, char **argv) +{ + lbs_server_s *lbs_server = NULL; + struct gps_callbacks cb; + int ret_code = 0; + cb.pos_cb = gps_update_position_cb; + cb.batch_cb = gps_update_batch_cb; + cb.sv_cb = gps_update_satellite_cb; + cb.nmea_cb = gps_update_nmea_cb; + +#if !GLIB_CHECK_VERSION (2, 31, 0) + if (!g_thread_supported()) { + g_thread_init(NULL); + } +#endif + +#if !GLIB_CHECK_VERSION (2, 35, 0) + g_type_init(); +#endif + + ret_code = initialize_server(argc, argv); + if (ret_code != 0) { + LOG_GPS(DBG_ERR, "initialize_server failed"); + return 1; + } + + lbs_server = g_new0(lbs_server_s, 1); + if (!lbs_server) { + LOG_GPS(DBG_ERR, "lbs_server_s create fail"); + return 1; + } + lbs_server_init(lbs_server); + gps_init_log(); + + register_update_callbacks(&cb, lbs_server); + + g_log_set_default_handler(_glib_log, lbs_server); + + /* create lbs-dbus server */ + ret_code = lbs_server_create(SERVICE_NAME, SERVICE_PATH, "lbs-server", "lbs-server", + &(lbs_server->lbs_dbus_server), set_options, shutdown, update_pos_tracking_interval, + request_change_pos_update_interval, get_nmea, + add_fence, remove_fence, pause_fence, resume_fence, (gpointer)lbs_server); + if (ret_code != LBS_SERVER_ERROR_NONE) { + LOG_GPS(DBG_ERR, "lbs_server_create failed"); + return 1; + } + + LOG_GPS(DBG_LOW, "lbs_server_create called"); + + lbs_server->loop = g_main_loop_new(NULL, TRUE); + g_main_loop_run(lbs_server->loop); + + LOG_GPS(DBG_LOW, "lbs_server deamon Stop...."); + + gps_deinit_log(); + + /* destroy resource for dynamic-interval */ + g_free(lbs_server->optimized_interval_array); + g_hash_table_destroy(lbs_server->dynamic_interval_table); + + /* destroy lbs-dbus server */ + lbs_server_destroy(lbs_server->lbs_dbus_server); + LOG_GPS(DBG_LOW, "lbs_server_destroy called"); + + g_main_loop_unref(lbs_server->loop); + + nps_deinit(lbs_server); + g_free(lbs_server); + + deinitialize_server(); + + return 0; +} diff --git a/lbs-server/src/lbs_server.h b/lbs-server/src/lbs_server.h new file mode 100644 index 0000000..9c33b19 --- /dev/null +++ b/lbs-server/src/lbs_server.h @@ -0,0 +1,177 @@ +/* + * lbs-server + * + * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Minjune Kim + * Genie Kim + * + * 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 _LBS_SERVER_H_ +#define _LBS_SERVER_H_ + +#include +#include + +#define SERVICE_NAME "org.tizen.lbs.Providers.LbsServer" +#define SERVICE_PATH "/org/tizen/lbs/Providers/LbsServer" + +#define MAX_NPS_LOC_ITEM 6 +#define MAX_GPS_LOC_ITEM 7 + +#define UPDATE_INTERVAL 60 + +typedef enum { + LBS_SERVER_METHOD_GPS = 0, + LBS_SERVER_METHOD_NPS, + LBS_SERVER_METHOD_AGPS, + LBS_SERVER_METHOD_GEOFENCE, + LBS_SERVER_METHOD_SIZE, +} lbs_server_method_e; + +/** + * This callback is called with position data. + * + * @param[in] pos Position data + * @param[in] error Error report + * @param[in] user_data User defined data + */ +typedef void (*gps_pos_cb)(pos_data_t *pos, gps_error_t error, void *user_data); + +/** + * This callback is called with batch data. + * + * @param[in] batch Batch data + * @param[in] user_data User defined data + */ +typedef void (*gps_batch_cb)(batch_data_t *batch, void *user_data); + +/** + * This callback is called with satellite data. + * + * @param[in] sv Satellite data + * @param[in] user_data User defined data + */ +typedef void (*gps_sv_cb)(sv_data_t *sv, void *user_data); + +/** + * This callback is called with nmea. + * + * @param[in] nmea NMEA data + * @param[in] user_data User defined data + */ +typedef void (*gps_nmea_cb)(nmea_data_t *nmea, void *user_data); + +/** + * GPS callback structure. + */ +struct gps_callbacks { + gps_pos_cb pos_cb; /**< Callback function for reporting position data */ + gps_batch_cb batch_cb; /**< Callback function for reporting batch data */ + gps_sv_cb sv_cb; /**< Callback function for reporting satellite data */ + gps_nmea_cb nmea_cb; /**< Callback function for reporting NMEA data */ +}; +typedef struct gps_callbacks gps_callbacks_t; + +/** + * LbsStatus + * + * defines the provider status + **/ +typedef enum { + LBS_STATUS_ERROR, + LBS_STATUS_UNAVAILABLE, + LBS_STATUS_ACQUIRING, + LBS_STATUS_AVAILABLE, + LBS_STATUS_BATCH +} LbsStatus; + +/** + * LbsPositionExtFields: + * + * LbsPositionExtFields is a bitfield that defines the validity of + * Position & Velocity values. + **/ +typedef enum { + LBS_POSITION_EXT_FIELDS_NONE = 0, + LBS_POSITION_EXT_FIELDS_LATITUDE = 1 << 0, + LBS_POSITION_EXT_FIELDS_LONGITUDE = 1 << 1, + LBS_POSITION_EXT_FIELDS_ALTITUDE = 1 << 2, + LBS_POSITION_EXT_FIELDS_SPEED = 1 << 3, + LBS_POSITION_EXT_FIELDS_DIRECTION = 1 << 4, + LBS_POSITION_EXT_FIELDS_CLIMB = 1 << 5 +} LbsPositionExtFields; + +/** + * LbsAccuracyLevel: + * + * Enum values used to define the approximate accuracy of + * Position or Address information. + **/ +typedef enum { + LBS_ACCURACY_LEVEL_NONE = 0, + LBS_ACCURACY_LEVEL_COUNTRY, + LBS_ACCURACY_LEVEL_REGION, + LBS_ACCURACY_LEVEL_LOCALITY, + LBS_ACCURACY_LEVEL_POSTALCODE, + LBS_ACCURACY_LEVEL_STREET, + LBS_ACCURACY_LEVEL_DETAILED, +} LbsAccuracyLevel; + +typedef enum { + GEOFENCE_ADD_FENCE = 0, + GEOFENCE_DELETE_FENCE, + GEOFENCE_PAUSE_FENCE, + GEOFENCE_RESUME_FENCE +} geofence_event_e; + +int gps_update_geofence_transition(int geofence_id, geofence_zone_state_t transition, double latitude, double longitude, double altitude, double speed, double bearing, double hor_accuracy, void *data); +int gps_update_geofence_service_status(int status, void *data); + +/* NPS */ + +typedef enum { + LBS_POSITION_FIELDS_NONE = 0, + LBS_POSITION_FIELDS_LATITUDE = 1 << 0, + LBS_POSITION_FIELDS_LONGITUDE = 1 << 1, + LBS_POSITION_FIELDS_ALTITUDE = 1 << 2 +} LbsPositionFields; /* not used */ + +typedef struct { + LbsPositionExtFields fields; + int timestamp; + double latitude; + double longitude; + double altitude; + double speed; + double direction; + LbsAccuracyLevel acc_level; + double hor_accuracy; + double ver_accuracy; +} NpsManagerPositionExt; + +typedef struct { + int timestamp; + double latitude; + double longitude; + double altitude; + double speed; + double direction; + double hor_accuracy; +} NpsManagerLastPositionExt; + +typedef void *NpsManagerHandle; + +#endif diff --git a/lbs-server/src/nmea_logger.c b/lbs-server/src/nmea_logger.c new file mode 100644 index 0000000..94f6145 --- /dev/null +++ b/lbs-server/src/nmea_logger.c @@ -0,0 +1,138 @@ +/* + * lbs-server + * + * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Minjune Kim + * Genie Kim + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include "nmea_logger.h" +#include "debug_util.h" + +#define MAX_NMEA_RAW_DATA_LOG_FILE_CNT (999) +#define MAX_NMEA_LOG_FILE_PATH (100) + +#define PHONE_FOLDER "/opt/usr/media" +#define GPS_FOLDER PHONE_FOLDER"/lbs-server" +#define NMEA_FOLDER GPS_FOLDER"/NMEA" +#define NMEA_LOGGING_FILE_PATH NMEA_FOLDER"/nmea_data" + +int raw_nmea_fd = -1; + +static int generate_nmea_log_file(char *); + +void start_nmea_log() +{ + char filepath[MAX_NMEA_LOG_FILE_PATH]; + + /* File Open */ + struct stat st = {0}; + + if (stat(GPS_FOLDER, &st) == -1) { + if (mkdir(GPS_FOLDER, 0777) == -1) { + LOG_GPS(DBG_ERR, "Fail to make lbs-server folder"); + raw_nmea_fd = -1; + return; + } else { + if (mkdir(NMEA_FOLDER, 0777) == -1) { + LOG_GPS(DBG_ERR, "Fail to make NMEA folder"); + raw_nmea_fd = -1; + return; + } + } + } else { + if (stat(NMEA_FOLDER, &st) == -1) { + if (mkdir(NMEA_FOLDER, 0777) == -1) { + LOG_GPS(DBG_ERR, "Fail to make NMEA folder"); + raw_nmea_fd = -1; + return; + } + } + } + + if (generate_nmea_log_file(filepath) == -1) { + LOG_GPS(DBG_ERR, "Starting LBS Logging for RAW NMEA data FAILED!"); + raw_nmea_fd = -1; + return; + } + + raw_nmea_fd = open(filepath, O_RDWR | O_APPEND | O_CREAT, 0644); + + if (raw_nmea_fd < 0) { + LOG_GPS(DBG_ERR, "FAILED to open nmea_data file, error[%d]", errno); + } else { + LOG_GPS(DBG_LOW, "Success :: raw_nmea_fd [%d]", raw_nmea_fd); + } + + return; +} + +void stop_nmea_log() +{ + int close_ret_val = 0; + + LOG_GPS(DBG_LOW, "raw_nmea_fd [%d]", raw_nmea_fd); + + if (raw_nmea_fd != -1) { + close_ret_val = close(raw_nmea_fd); + if (close_ret_val < 0) { + LOG_GPS(DBG_ERR, "FAILED to close raw_nmea_fd[%d], error[%d]", raw_nmea_fd, errno); + } + raw_nmea_fd = -1; + } + return; +} + +void write_nmea_log(char *data, int len) +{ + int write_ret_val = 0; + + if (raw_nmea_fd != -1) { + write_ret_val = write(raw_nmea_fd, data, len); + if (write_ret_val < 0) { + LOG_GPS(DBG_ERR, "FAILED to write[%d], error[%d]", raw_nmea_fd, errno); + close(raw_nmea_fd); + raw_nmea_fd = -1; + } + } + return; +} + +static int generate_nmea_log_file(char *filepath) +{ + int idx = 0; + int fd = 0; + char fn[MAX_NMEA_LOG_FILE_PATH]; + + for (idx = 0; idx < MAX_NMEA_RAW_DATA_LOG_FILE_CNT; idx++) { + g_snprintf(fn, MAX_NMEA_LOG_FILE_PATH, "%s%03d.txt", NMEA_LOGGING_FILE_PATH, idx); + if ((fd = access(fn, R_OK)) == -1) { + LOG_GPS(DBG_LOW, "Next log file [%s]", fn); + g_strlcpy(filepath, fn, strlen(fn)); + return 0; + } + } + LOG_GPS(DBG_LOW, "All NMEA RAW Data logging files are used. New log file can not be created"); + return -1; +} diff --git a/lbs-server/src/nmea_logger.h b/lbs-server/src/nmea_logger.h new file mode 100644 index 0000000..f9132c8 --- /dev/null +++ b/lbs-server/src/nmea_logger.h @@ -0,0 +1,34 @@ +/* + * lbs-server + * + * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Minjune Kim + * Genie Kim + * + * 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 _NMEA_LOGGER_H_ +#define _NMEA_LOGGER_H_ + +/* Start NMEA logging */ +void start_nmea_log(); + +/* Stop NMEA logging */ +void stop_nmea_log(); + +/* Write NMEA data to logging file */ +void write_nmea_log(char *data, int len); + +#endif /* _NMEA_LOGGER_H_ */ diff --git a/lbs-server/src/nps_plugin_module.c b/lbs-server/src/nps_plugin_module.c new file mode 100644 index 0000000..d83ce7d --- /dev/null +++ b/lbs-server/src/nps_plugin_module.c @@ -0,0 +1,161 @@ +/* + * lbs-server + * + * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Youngae Kang , Dong Wei , + * Genie Kim , Minjune Kim , + * Ming Zhu , Congyi Shi + * + * 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 +#include +#include +#include +#include "nps_plugin_module.h" +#include "setting.h" +#include "debug_util.h" + +#define PLUGIN_PATH_POSTFIX ".so" + + +static const nps_plugin_interface *g_plugin = NULL; +static int g_is_nps_dummy_module = FALSE; + +int dummy_load(void); +int dummy_unload(void); +int dummy_start(unsigned long period, LocationCallback cb, void *arg, void **handle); +int dummy_stop(void *handle, CancelCallback cb, void *arg); +void dummy_get_offline_token(const unsigned char *key, unsigned int keyLengh, OfflineTokenCallback cb, void *arg); +int dummy_offline_location(const unsigned char *key, unsigned int keyLength, const unsigned char *token, unsigned int tokenSize, LocationCallback cb, void *arg); +void dummy_cell_location(LocationCallback callback, void *arg); + +static nps_plugin_interface g_dummy = { + .load = dummy_load, + .unload = dummy_unload, + .start = dummy_start, + .stop = dummy_stop, + .getOfflineToken = dummy_get_offline_token, + .offlineLocation = dummy_offline_location, + .cellLocation = dummy_cell_location +}; + +int nps_is_dummy_plugin_module() +{ + return g_is_nps_dummy_module; +} + +int nps_load_plugin_module(void **plugin_handle) +{ + LOG_NPS(DBG_LOW, "Begin to load plugin module"); + + char plugin_path[256] = {0}; + + strncpy(plugin_path, NPS_PLUGIN_PATH, sizeof(plugin_path)); + + if (access(plugin_path, R_OK) != 0) { + LOG_NPS(DBG_ERR, "Failed to access plugin module. [%s]", plugin_path); + LOG_NPS(DBG_LOW, "load dummy"); + g_plugin = &g_dummy; + g_is_nps_dummy_module = TRUE; + return TRUE; + } + + *plugin_handle = dlopen(plugin_path, RTLD_NOW); + if (!*plugin_handle) { + LOG_NPS(DBG_ERR, "Failed to load plugin module. [%s]", plugin_path); + /* LOG_NPS(DBG_ERR, "%s", dlerror()); */ + return FALSE; + } + + const nps_plugin_interface *(*get_nps_plugin_interface)(); + get_nps_plugin_interface = dlsym(*plugin_handle, "get_nps_plugin_interface"); + if (!get_nps_plugin_interface) { + LOG_NPS(DBG_ERR, "Failed to find entry symbol in plugin module."); + dlclose(*plugin_handle); + return FALSE; + } + + g_plugin = get_nps_plugin_interface(); + + if (!g_plugin) { + LOG_NPS(DBG_ERR, "Failed to find load symbol in plugin module."); + dlclose(*plugin_handle); + return FALSE; + } + LOG_NPS(DBG_LOW, "Success to load plugin module (%s).", plugin_path); + + return TRUE; +} + +int nps_unload_plugin_module(void *plugin_handle) +{ + if (plugin_handle == NULL) { + LOG_NPS(DBG_ERR, "plugin_handle is already NULL."); + return FALSE; + } + + dlclose(plugin_handle); + + if (g_plugin) { + g_plugin = NULL; + } + return TRUE; +} + +const nps_plugin_interface *get_nps_plugin_module(void) +{ + return g_plugin; +} + +int dummy_load(void) +{ + LOG_NPS(DBG_ERR, "Dummy func."); + return FALSE; +} + +int dummy_unload(void) +{ + LOG_NPS(DBG_ERR, "Dummy func."); + return FALSE; +} + +int dummy_start(unsigned long period, LocationCallback cb, void *arg, void **handle) +{ + LOG_NPS(DBG_ERR, "Dummy func."); + return FALSE; +} + +int dummy_stop(void *handle, CancelCallback cb, void *arg) +{ + LOG_NPS(DBG_ERR, "Dummy func."); + return FALSE; +} + +void dummy_get_offline_token(const unsigned char *key, unsigned int keyLengh, OfflineTokenCallback cb, void *arg) +{ + LOG_NPS(DBG_ERR, "Dummy func."); +} + +int dummy_offline_location(const unsigned char *key, unsigned int keyLength, const unsigned char *token, unsigned int tokenSize, LocationCallback cb, void *arg) +{ + LOG_NPS(DBG_ERR, "Dummy func."); + return FALSE; +} + +void dummy_cell_location(LocationCallback callback, void *arg) +{ + LOG_NPS(DBG_ERR, "Dummy func."); +} diff --git a/lbs-server/src/nps_plugin_module.h b/lbs-server/src/nps_plugin_module.h new file mode 100644 index 0000000..3428a9b --- /dev/null +++ b/lbs-server/src/nps_plugin_module.h @@ -0,0 +1,34 @@ +/* + * lbs-server + * + * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Youngae Kang , Dong Wei , + * Genie Kim , Minjune Kim , + * Ming Zhu , Congyi Shi + * + * 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 _NPS_PLUGIN_MODULE_H_ +#define _NPS_PLUGIN_MODULE_H_ + +#include "nps_plugin_intf.h" + +int nps_load_plugin_module(void **plugin_handle); +int nps_unload_plugin_module(void *plugin_handle); +int nps_is_dummy_plugin_module(); +const nps_plugin_interface *get_nps_plugin_module(void); + +#endif /* _NPS_PLUGIN_MODULE_H_ */ diff --git a/lbs-server/src/server.c b/lbs-server/src/server.c new file mode 100644 index 0000000..b96cfc8 --- /dev/null +++ b/lbs-server/src/server.c @@ -0,0 +1,1286 @@ +/* + * lbs-server + * + * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Minjune Kim + * Genie Kim + * + * 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 +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "server.h" +#include "gps_plugin_data_types.h" +#include "gps_plugin_intf.h" +#include "nmea_logger.h" +#include "data_connection.h" +#include "setting.h" +#include "gps_plugin_module.h" +#include "debug_util.h" +#include "last_position.h" +#include "dump_log.h" + +#include "nps_plugin_module.h" +#include "nps_plugin_intf.h" + +#ifdef _TIZEN_PUBLIC_ +#include +#include +#include +#endif + +#include +#include +#include + +#include +#include +#if !GLIB_CHECK_VERSION (2, 31, 0) +#include +#endif + +#define REPLAY_MODULE "replay" + +#define PLATFORM_PATH "/sys/devices/platform" +#define BRCM4752_PATH PLATFORM_PATH"/bcm4752" +#define BRCM47520_PATH PLATFORM_PATH"/bcm47520" +#define BRCM47511_PATH PLATFORM_PATH"/bcm47511" +#define CSR_PATH PLATFORM_PATH"/gsd4t" +#define QCOM8210_PATH PLATFORM_PATH"/msm8210_gps" +#define QCOM8x30_PATH PLATFORM_PATH"/msm8x30_gps" +#define QCOM9x15_PATH PLATFORM_PATH"/msm9x15_gps" +#define QCOM8974_PATH PLATFORM_PATH"/msm8974_gps" +#define QCOM8226_PATH PLATFORM_PATH"/msm8226_gps" +#define QCOM8916_PATH PLATFORM_PATH"/msm8916_gps" + +#define MPS_TO_KMPH 3.6 /* 1 m/s = 3.6 km/h */ + +struct gps_callbacks g_update_cb; +void *g_user_data; + +typedef struct { + void *handle; + char *name; +} gps_plugin_handler_t; + +typedef struct { + void *handle; +} nps_plugin_handler_t; + +typedef struct { + gps_session_state_t session_state; + int dnet_used; + gboolean logging_enabled; + gboolean replay_enabled; + +#ifdef _TIZEN_PUBLIC_ + pthread_t msg_thread; /* Register SUPL NI cb to msg server Thread */ + pthread_t popup_thread; /* Register SUPL NI cb to msg server Thread */ + int msg_thread_status; +#endif + + gps_plugin_handler_t gps_plugin; + + pos_data_t *pos_data; + batch_data_t *batch_data; + sv_data_t *sv_data; + nmea_data_t *nmea_data; +} gps_server_t; + +gps_server_t *g_gps_server = NULL; + +nps_plugin_handler_t g_nps_plugin; + +static void __nps_plugin_handler_deinit(void) +{ + if (g_nps_plugin.handle != NULL) { + g_nps_plugin.handle = NULL; + } +} + +static int _gps_server_gps_event_cb(gps_event_info_t *gps_event_info, void *user_data); + +static void _gps_nmea_changed_cb(keynode_t *key, void *data) +{ + gps_server_t *server = (gps_server_t *)data; + int int_val; + if (setting_get_int(VCONFKEY_LOCATION_NMEA_LOGGING, &int_val) == FALSE) { + LOG_GPS(DBG_ERR, "//ERROR!! get VCONFKEY_LOCATION_NMEA_LOGGING setting"); + int_val = 0; + } + server->logging_enabled = (int_val == 1) ? TRUE : FALSE; + return; +} + +static gboolean get_replay_enabled() +{ + int int_val; + gboolean ret; + + if (setting_get_int(VCONFKEY_LOCATION_REPLAY_ENABLED, &int_val) == FALSE) { + LOG_GPS(DBG_ERR, "//ERROR get VCONFKEY_LOCATION_REPLAY_ENABLED setting"); + int_val = 0; + } + + ret = (int_val == 1) ? TRUE : FALSE; + + return ret; +} + +static void reload_plugin_module(gps_server_t *server) +{ + char *module_name; + gps_failure_reason_t ReasonCode = GPS_FAILURE_CAUSE_NORMAL; + + if (server->replay_enabled == TRUE) { + module_name = REPLAY_MODULE; + } else { + module_name = server->gps_plugin.name; + } + + LOG_GPS(DBG_LOW, "Loading plugin.name : %s", module_name); + + if (!get_plugin_module()->deinit(&ReasonCode)) { + LOG_GPS(DBG_ERR, "Fail to GPS plugin deinit"); + } else { + unload_plugin_module(&server->gps_plugin.handle); + if (!load_plugin_module(module_name, &server->gps_plugin.handle)) { + LOG_GPS(DBG_ERR, "Fail to load %s plugin", module_name); + } else { + if (!get_plugin_module()->init(_gps_server_gps_event_cb, (void *)server)) { + LOG_GPS(DBG_ERR, "Fail to %s plugin init", module_name); + return; + } + } + } +} + +static void _gps_replay_changed_cb(keynode_t *key, void *data) +{ + gps_server_t *server = (gps_server_t *)data; + server->replay_enabled = get_replay_enabled(); + reload_plugin_module(server); + + return; +} + +static int _gps_server_get_gps_state() +{ + int val; + + if (setting_get_int(VCONFKEY_LOCATION_GPS_STATE, &val) == FALSE) { + val = POSITION_OFF; + } + + return val; +} + +static void _gps_server_set_gps_state(int gps_state) +{ + int ret; + + switch (gps_state) { + case POSITION_CONNECTED: + ret = setting_set_int(VCONFKEY_LOCATION_GPS_STATE, POSITION_CONNECTED); + gps_dump_log("GPS state : POSITION_CONNECTED", NULL); + break; + case POSITION_SEARCHING: + ret = setting_set_int(VCONFKEY_LOCATION_GPS_STATE, POSITION_SEARCHING); + gps_dump_log("GPS state : POSITION_SEARCHING", NULL); + break; + case POSITION_OFF: + ret = setting_set_int(VCONFKEY_LOCATION_GPS_STATE, POSITION_OFF); + gps_dump_log("GPS state : POSITION_OFF", NULL); + break; + default: + ret = setting_set_int(VCONFKEY_LOCATION_GPS_STATE, POSITION_OFF); + break; + } + + if (ret == TRUE) { + LOG_GPS(DBG_LOW, "Succesee to set VCONFKEY_LOCATION_GPS_STATE"); + } else { + LOG_GPS(DBG_ERR, "Fail to set VCONF_LOCATION_GPS_STATE"); + } +} + +int request_change_pos_update_interval_standalone_gps(unsigned int interval) +{ + LOG_GPS(DBG_INFO, "request_change_pos_update_interval_standalone_gps. interval[%u]", interval); + gboolean status = TRUE; + gps_failure_reason_t reason_code = GPS_FAILURE_CAUSE_NORMAL; + gps_server_t *server = g_gps_server; + + if (server->session_state == GPS_SESSION_STARTING || server->session_state == GPS_SESSION_STARTED) { + gps_action_change_interval_data_t gps_change_interval_data; + gps_change_interval_data.interval = (int)interval; + status = get_plugin_module()->request(GPS_ACTION_CHANGE_INTERVAL, &gps_change_interval_data, &reason_code); + LOG_GPS(DBG_INFO, "requested go GPS module done. gps_change_interval_data.interval [%d]", gps_change_interval_data.interval); + + if (status == FALSE) { + LOG_GPS(DBG_ERR, "Main: sending GPS_ACTION_CHANGE_INTERVAL Fail !"); + return FALSE; + } + LOG_GPS(DBG_INFO, "Main: sending GPS_ACTION_CHANGE_INTERVAL OK !"); + return TRUE; + } + return FALSE; +} + +int request_start_session(int interval) +{ + LOG_GPS(DBG_INFO, "GPS start with interval [%d]", interval); + + gboolean status = TRUE; + gps_failure_reason_t reason_code = GPS_FAILURE_CAUSE_NORMAL; + gps_server_t *server = g_gps_server; + gps_action_start_data_t gps_start_data; + + if (server->session_state != GPS_SESSION_STOPPED && server->session_state != GPS_SESSION_STOPPING) { + LOG_GPS(DBG_WARN, "Main: GPS Session Already Started!"); + return TRUE; + } + + server->session_state = GPS_SESSION_STARTING; + LOG_GPS(DBG_LOW, "==GPSSessionState[%d]", server->session_state); + gps_start_data.interval = interval; + status = get_plugin_module()->request(GPS_ACTION_START_SESSION, &gps_start_data, &reason_code); + + if (status == FALSE) { + LOG_GPS(DBG_ERR, "Main: sending GPS_ACTION_START_SESSION Fail !"); + return FALSE; + } + + LOG_GPS(DBG_INFO, "Main: sending GPS_ACTION_START_SESSION OK !"); + + setting_ignore_key_changed(VCONFKEY_LOCATION_REPLAY_ENABLED, _gps_replay_changed_cb); + + return TRUE; +} + +int request_stop_session() +{ + gboolean status = TRUE; + gboolean cur_replay_enabled = FALSE; + gps_failure_reason_t reason_code = GPS_FAILURE_CAUSE_NORMAL; + gps_server_t *server = g_gps_server; + + LOG_GPS(DBG_LOW, "Main: Stop GPS Session, ==GPSSessionState[%d]", server->session_state); + if (server->session_state == GPS_SESSION_STARTED || server->session_state == GPS_SESSION_STARTING) { + status = get_plugin_module()->request(GPS_ACTION_STOP_SESSION, NULL, &reason_code); + if (status) { + server->session_state = GPS_SESSION_STOPPING; + LOG_GPS(DBG_LOW, "==GPSSessionState[%d]", server->session_state); + cur_replay_enabled = get_replay_enabled(); + if (server->replay_enabled != cur_replay_enabled) { + server->replay_enabled = cur_replay_enabled; + reload_plugin_module(server); + } + setting_notify_key_changed(VCONFKEY_LOCATION_REPLAY_ENABLED, _gps_replay_changed_cb, (void *)server); + } else { + LOG_GPS(DBG_ERR, "plugin->request to LBS_GPS_STOP_SESSION Failed, reasonCode =%d", reason_code); + } + } else { + /* If request is not sent, keep the client registed */ + LOG_GPS(DBG_LOW, "LBS_GPS_STOP_SESSION is not sent because the GPS state is not started, keep the client registed"); + } + return status; +} + +int request_start_batch_session(int batch_interval, int batch_period) +{ + LOG_GPS(DBG_INFO, "Batch: GPS start with interval[%d]", batch_interval); + + gboolean status = TRUE; + gps_failure_reason_t reason_code = GPS_FAILURE_CAUSE_NORMAL; + gps_server_t *server = g_gps_server; + gps_action_start_data_t gps_start_data; + + if (server->session_state != GPS_SESSION_STOPPED && server->session_state != GPS_SESSION_STOPPING) { + LOG_GPS(DBG_WARN, "Batch: GPS Session Already Started!"); + return TRUE; + } + + server->session_state = GPS_SESSION_STARTING; + LOG_GPS(DBG_LOW, "==GPSSessionState[%d]", server->session_state); + gps_start_data.interval = batch_interval; + gps_start_data.period = batch_period; + status = get_plugin_module()->request(GPS_ACTION_START_BATCH, &gps_start_data, &reason_code); + + if (status == FALSE) { + LOG_GPS(DBG_ERR, "Batch: sending GPS_ACTION_START_SESSION Fail !"); + return FALSE; + } + + LOG_GPS(DBG_INFO, "Batch: sending GPS_ACTION_START_SESSION OK !"); + + setting_ignore_key_changed(VCONFKEY_LOCATION_REPLAY_ENABLED, _gps_replay_changed_cb); + + return TRUE; +} + +int request_stop_batch_session() +{ + gboolean status = TRUE; + gboolean cur_replay_enabled = FALSE; + gps_failure_reason_t reason_code = GPS_FAILURE_CAUSE_NORMAL; + gps_server_t *server = g_gps_server; + + LOG_GPS(DBG_LOW, "Batch: Stop GPS Session, ==GPSSessionState[%d]", server->session_state); + if (server->session_state == GPS_SESSION_STARTED || server->session_state == GPS_SESSION_STARTING) { + status = get_plugin_module()->request(GPS_ACTION_STOP_BATCH, NULL, &reason_code); + if (status) { + server->session_state = GPS_SESSION_STOPPING; + LOG_GPS(DBG_LOW, "==GPSSessionState[%d]", server->session_state); + cur_replay_enabled = get_replay_enabled(); + if (server->replay_enabled != cur_replay_enabled) { + server->replay_enabled = cur_replay_enabled; + reload_plugin_module(server); + } + setting_notify_key_changed(VCONFKEY_LOCATION_REPLAY_ENABLED, _gps_replay_changed_cb, (void *)server); + } else { + LOG_GPS(DBG_ERR, "plugin->request to LBS_GPS_STOP_SESSION Failed, reasonCode =%d", reason_code); + } + } else { + /* If request is not sent, keep the client registed */ + LOG_GPS(DBG_LOW, " LBS_GPS_STOP_SESSION is not sent because the GPS state is not started, keep the client registed "); + } + return status; +} + +int request_add_geofence(int fence_id, double latitude, double longitude, int radius, int last_state, int monitor_states, int notification_responsiveness, int unknown_timer) +{ + gboolean status = FALSE; + gps_failure_reason_t reason_code = GPS_FAILURE_CAUSE_NORMAL; + geofence_action_data_t action_data; + + action_data.geofence.geofence_id = fence_id; + action_data.geofence.latitude = latitude; + action_data.geofence.longitude = longitude; + action_data.geofence.radius = radius; + action_data.last_state = last_state; + action_data.monitor_states = monitor_states; + /* Default value : temp */ + action_data.notification_responsiveness_ms = 5000; + action_data.unknown_timer_ms = 30000; + /*action_data.notification_responsiveness_ms = notification_responsiveness; */ + /*action_data.unknown_timer_ms = unknown_timer; */ + + LOG_GPS(DBG_LOW, "request_add_geofence with geofence_id [%d]", fence_id); + status = get_plugin_module()->request(GPS_ACTION_ADD_GEOFENCE, &action_data, &reason_code); + + return status; +} + +int request_delete_geofence(int fence_id) +{ + gboolean status = FALSE; + gps_failure_reason_t reason_code = GPS_FAILURE_CAUSE_NORMAL; + + LOG_GPS(DBG_LOW, "request_delete_geofence with geofence_id [%d]", fence_id); + status = get_plugin_module()->request(GPS_ACTION_DELETE_GEOFENCE, &fence_id, &reason_code); + + return status; +} + +int request_pause_geofence(int fence_id) +{ + gboolean status = FALSE; + gps_failure_reason_t reason_code = GPS_FAILURE_CAUSE_NORMAL; + + LOG_GPS(DBG_LOW, "request_pause_geofence with geofence_id [%d]", fence_id); + status = get_plugin_module()->request(GPS_ACTION_PAUSE_GEOFENCE, &fence_id, &reason_code); + + return status; +} + +int request_resume_geofence(int fence_id, int monitor_states) +{ + gboolean status = FALSE; + gps_failure_reason_t reason_code = GPS_FAILURE_CAUSE_NORMAL; + geofence_action_data_t action_data; + + action_data.geofence.geofence_id = fence_id; + action_data.monitor_states = monitor_states; + + LOG_GPS(DBG_LOW, "request_resume_geofence with geofence_id [%d]", fence_id); + status = get_plugin_module()->request(GPS_ACTION_RESUME_GEOFENCE, &action_data, &reason_code); + + return status; +} + +int request_delete_gps_data() +{ + gboolean status = TRUE; + gps_failure_reason_t reason_code = GPS_FAILURE_CAUSE_NORMAL; + + status = get_plugin_module()->request(GPS_ACTION_DELETE_GPS_DATA, NULL, &reason_code); + + if (status == FALSE) { + LOG_GPS(DBG_ERR, "Fail : GPS_ACTION_DELETE_GPS_DATA [%d]", reason_code); + return FALSE; + } + + LOG_GPS(DBG_LOW, "Success to GPS_ACTION_DELETE_GPS_DATA"); + return TRUE; +} + +int get_nmea_from_server(int *timestamp, char **nmea_data) +{ + LOG_GPS(DBG_INFO, "ENTER >>>"); + + gps_server_t *server = g_gps_server; + + if (server->session_state == GPS_SESSION_STARTING || server->session_state == GPS_SESSION_STARTED) { + *timestamp = (int) server->nmea_data->timestamp; + *nmea_data = g_strndup(server->nmea_data->data, server->nmea_data->len); + } + LOG_GPS(DBG_LOW, "=== timestmap: %d, nmea_data: %s", *timestamp, *nmea_data); + return TRUE; +} + +static void _gps_plugin_handler_init(gps_server_t *server, char *module_name) +{ + if (module_name == NULL) { + LOG_GPS(DBG_ERR, "Fail : module_name is NULL"); + return; + } + + server->gps_plugin.handle = NULL; + server->gps_plugin.name = (char *)malloc(strlen(module_name) + 1); + g_return_if_fail(server->gps_plugin.name); + + g_strlcpy(server->gps_plugin.name, module_name, strlen(module_name) + 1); +} + +static void _gps_plugin_handler_deinit(gps_server_t *server) +{ + if (server->gps_plugin.handle != NULL) { + server->gps_plugin.handle = NULL; + } + + if (server->gps_plugin.name != NULL) { + free(server->gps_plugin.name); + server->gps_plugin.name = NULL; + } +} + +static void _gps_get_nmea_replay_mode(gps_server_t *server) +{ + int int_val = 0; + + if (setting_get_int(VCONFKEY_LOCATION_NMEA_LOGGING, &int_val) == FALSE) { + LOG_GPS(DBG_ERR, "//ERROR!! get VCONFKEY_LOCATION_NMEA_LOGGING setting"); + int_val = 0; + } + server->logging_enabled = (int_val == 1) ? TRUE : FALSE; + + if (setting_get_int(VCONFKEY_LOCATION_REPLAY_ENABLED, &int_val) == FALSE) { + LOG_GPS(DBG_ERR, "//ERROR!! get VCONFKEY_LOCATION_REPLAY_ENABLED setting"); + int_val = 0; + } + server->replay_enabled = (int_val == 1) ? TRUE : FALSE; +} + +static void _gps_notify_params(gps_server_t *server) +{ + setting_notify_key_changed(VCONFKEY_LOCATION_NMEA_LOGGING, _gps_nmea_changed_cb, (void *)server); + setting_notify_key_changed(VCONFKEY_LOCATION_REPLAY_ENABLED, _gps_replay_changed_cb, (void *)server); +} + +static void _gps_ignore_params() +{ + setting_ignore_key_changed(VCONFKEY_LOCATION_NMEA_LOGGING, _gps_nmea_changed_cb); + setting_ignore_key_changed(VCONFKEY_LOCATION_REPLAY_ENABLED, _gps_replay_changed_cb); +} + +static void _gps_server_start_event(gps_server_t *server) +{ + LOG_GPS(DBG_LOW, "==GPSSessionState [%d] -> [%d]", server->session_state, GPS_SESSION_STARTED); + server->session_state = GPS_SESSION_STARTED; + + if (server->logging_enabled) { + LOG_GPS(DBG_LOW, "NMEA STARTED"); + start_nmea_log(); + } + + if (server->pos_data == NULL) { + server->pos_data = (pos_data_t *) malloc(sizeof(pos_data_t)); + if (server->pos_data == NULL) { + LOG_GPS(DBG_WARN, "//callback: server->pos_data re-malloc Failed!!"); + } else { + memset(server->pos_data, 0x00, sizeof(pos_data_t)); + } + } + if (server->batch_data == NULL) { + server->batch_data = (batch_data_t *) malloc(sizeof(batch_data_t)); + if (server->batch_data == NULL) { + LOG_GPS(DBG_WARN, "//callback: server->batch_data re-malloc Failed!!"); + } else { + memset(server->batch_data, 0x00, sizeof(batch_data_t)); + } + } + if (server->sv_data == NULL) { + server->sv_data = (sv_data_t *) malloc(sizeof(sv_data_t)); + if (server->sv_data == NULL) { + LOG_GPS(DBG_WARN, "//callback: server->sv_data re-malloc Failed!!"); + } else { + memset(server->sv_data, 0x00, sizeof(sv_data_t)); + } + } + if (server->nmea_data == NULL) { + server->nmea_data = (nmea_data_t *) malloc(sizeof(nmea_data_t)); + if (server->nmea_data == NULL) { + LOG_GPS(DBG_WARN, "//callback: server->nmea_data re-malloc Failed!!"); + } else { + memset(server->nmea_data, 0x00, sizeof(nmea_data_t)); + } + } + + _gps_server_set_gps_state(POSITION_SEARCHING); +#ifdef _TIZEN_PUBLIC_ + pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0); +#endif +} + +static void _gps_server_stop_event(gps_server_t *server) +{ + LOG_GPS(DBG_LOW, "==GPSSessionState [%d] -> [%d]", server->session_state, GPS_SESSION_STOPPED); + server->session_state = GPS_SESSION_STOPPED; + + _gps_server_set_gps_state(POSITION_OFF); +#ifdef _TIZEN_PUBLIC_ + pm_unlock_state(LCD_OFF, PM_RESET_TIMER); +#endif + + if (server->logging_enabled) { + LOG_GPS(DBG_LOW, "NMEA STOPPED"); + stop_nmea_log(); + } +} + +static void _report_pos_event(gps_server_t *server, gps_event_info_t *gps_event) +{ + if (server->pos_data != NULL) { + memset(server->pos_data, 0x00, sizeof(pos_data_t)); /* Moved: the address of server->pos_data sometimes returns 0 when stopping GPS */ + memcpy(server->pos_data, &(gps_event->event_data.pos_ind.pos), sizeof(pos_data_t)); + /* change m/s to km/h */ + server->pos_data->speed = server->pos_data->speed * MPS_TO_KMPH; + gps_set_position(server->pos_data); + g_update_cb.pos_cb(server->pos_data, gps_event->event_data.pos_ind.error, g_user_data); + } else { + LOG_GPS(DBG_ERR, "server->pos_data is NULL"); + } +} + +static void _report_batch_event(gps_server_t *server, gps_event_info_t *gps_event) +{ + if (server->batch_data != NULL) { + memset(server->batch_data, 0x00, sizeof(batch_data_t)); + memcpy(server->batch_data, &(gps_event->event_data.batch_ind.batch), sizeof(batch_data_t)); + g_update_cb.batch_cb(server->batch_data, g_user_data); + } else { + LOG_GPS(DBG_ERR, "server->batch_data is NULL"); + } +} + +static void _report_sv_event(gps_server_t *server, gps_event_info_t *gps_event) +{ + if (server->sv_data != NULL) { + memset(server->sv_data, 0x00, sizeof(sv_data_t)); + memcpy(server->sv_data, &(gps_event->event_data.sv_ind.sv), sizeof(sv_data_t)); + g_update_cb.sv_cb(server->sv_data, g_user_data); + } else { + LOG_GPS(DBG_ERR, "server->sv_data is NULL"); + } +} + +static void _report_nmea_event(gps_server_t *server, gps_event_info_t *gps_event) +{ + if (server->nmea_data == NULL) { + LOG_GPS(DBG_ERR, "server->nmea_data is NULL"); + return; + } + + if (server->nmea_data->data) { + free(server->nmea_data->data); + server->nmea_data->data = NULL; + } + + /*LOG_GPS(DBG_LOW, "server->nmea_data->len : [%d]", gps_event->event_data.nmea_ind.nmea.len); */ + server->nmea_data->len = gps_event->event_data.nmea_ind.nmea.len; + server->nmea_data->data = (char *)malloc(server->nmea_data->len); + if (server->nmea_data->data == NULL) { + LOG_GPS(DBG_ERR, "Fail to malloc of server->nmea_data->data"); + return; + } + memset(server->nmea_data->data, 0x00, server->nmea_data->len); + memcpy(server->nmea_data->data, gps_event->event_data.nmea_ind.nmea.data, server->nmea_data->len); + g_update_cb.nmea_cb(server->nmea_data, g_user_data); + + if (server->logging_enabled) { + int nmea_len; + char *p_nmea_data; + nmea_len = gps_event->event_data.nmea_ind.nmea.len; + p_nmea_data = gps_event->event_data.nmea_ind.nmea.data; + write_nmea_log(p_nmea_data, nmea_len); + } +} + +static int _gps_server_open_data_connection(gps_server_t *server) +{ + LOG_GPS(DBG_LOW, "Enter _gps_server_open_data_connection"); + + server->dnet_used++; + + if (server->dnet_used > 1) { + LOG_GPS(DBG_LOW, "dnet_used : count[ %d ]", server->dnet_used); + return TRUE; + } else { + LOG_GPS(DBG_LOW, "First open the data connection"); + } + + unsigned char result; + + result = start_pdp_connection(); + + if (result == TRUE) { + LOG_GPS(DBG_LOW, "//Open PDP Conn for SUPL Success."); + } else { + LOG_GPS(DBG_ERR, "//Open PDP Conn for SUPL Fail."); + return FALSE; + } + return TRUE; +} + +static int _gps_server_close_data_connection(gps_server_t *server) +{ + LOG_GPS(DBG_LOW, "Enter _gps_server_close_data_connection"); + + if (server->dnet_used > 0) { + server->dnet_used--; + } + + if (server->dnet_used != 0) { + LOG_GPS(DBG_LOW, "Cannot stop the data connection! [ dnet_used : %d ]", server->dnet_used); + return TRUE; + } else { + LOG_GPS(DBG_LOW, "Close the data connection"); + } + + unsigned char result; + + result = stop_pdp_connection(); + if (result == TRUE) { + LOG_GPS(DBG_LOW, "Close PDP Conn for SUPL Success."); + } else { + LOG_GPS(DBG_ERR, "//Close PDP Conn for SUPL Fail."); + return FALSE; + } + + return TRUE; +} + +static int _gps_server_resolve_dns(char *domain) +{ + LOG_GPS(DBG_LOW, "Enter _gps_server_resolve_dns"); + + unsigned char result; + gps_failure_reason_t reason_code = GPS_FAILURE_CAUSE_NORMAL; + unsigned int ipaddr; + int port; + + result = query_dns(domain, &ipaddr, &port); + if (result == TRUE) { + LOG_GPS(DBG_LOW, "Success to resolve domain name [ %s ] / ipaddr [ %u ]", domain, ipaddr); + get_plugin_module()->request(GPS_INDI_SUPL_DNSQUERY, (void *)(&ipaddr), &reason_code); + } else { + ipaddr = 0; + LOG_GPS(DBG_ERR, "Fail to resolve domain name [ %s ] / ipaddr [ %u ]", domain, ipaddr); + get_plugin_module()->request(GPS_INDI_SUPL_DNSQUERY, (void *)(&ipaddr), &reason_code); + return FALSE; + } + + return TRUE; +} + +static void _gps_server_send_facttest_result(double snr_data, int prn, unsigned short result) +{ +} + +static void _report_geofence_transition(int geofence_id, geofence_zone_state_t transition, double latitude, double longitude, double altitude, double speed, double bearing, double hor_accuracy) +{ + gps_update_geofence_transition(geofence_id, transition, latitude, longitude, altitude, speed, bearing, hor_accuracy, (void *)g_user_data); +} + +static void _report_geofence_service_status(int status) +{ + gps_update_geofence_service_status(status, (void *)g_user_data); +} + +static void _gps_server_send_geofence_result(geofence_event_e event, int geofence_id, int result) +{ + if (result != 0) { + LOG_GPS(DBG_ERR, "result is [%d]", result); + return; + } + + switch (event) { + case GEOFENCE_ADD_FENCE: + LOG_GPS(DBG_LOW, "Geofence ID[%d], Success ADD_GEOFENCE", geofence_id); + break; + case GEOFENCE_DELETE_FENCE: + LOG_GPS(DBG_LOW, "Geofence ID[%d], Success DELETE_GEOFENCE", geofence_id); + break; + case GEOFENCE_PAUSE_FENCE: + LOG_GPS(DBG_LOW, "Geofence ID[%d], Success PAUSE_GEOFENCE", geofence_id); + break; + case GEOFENCE_RESUME_FENCE: + LOG_GPS(DBG_LOW, "Geofence ID[%d], Success RESUME_GEOFENCE", geofence_id); + break; + default: + break; + } +} + +static int _gps_server_gps_event_cb(gps_event_info_t *gps_event_info, void *user_data) +{ + /*FUNC_ENTRANCE_SERVER; */ + gps_server_t *server = (gps_server_t *)user_data; + int result = TRUE; + if (gps_event_info == NULL) { + LOG_GPS(DBG_WARN, "//NULL pointer variable passed"); + return result; + } + + switch (gps_event_info->event_id) { + case GPS_EVENT_START_SESSION: + LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_START_SESSION :::::::::::::::"); + if (gps_event_info->event_data.start_session_rsp.error == GPS_ERR_NONE) { + _gps_server_start_event(server); + } else { + LOG_GPS(DBG_ERR, "//Start Session Failed, error : %d", + gps_event_info->event_data.start_session_rsp.error); + } + break; + case GPS_EVENT_SET_OPTION: { + LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_SET_OPTION :::::::::::::::"); + if (gps_event_info->event_data.set_option_rsp.error != GPS_ERR_NONE) { + LOG_GPS(DBG_ERR, "//Set Option Failed, error : %d", + gps_event_info->event_data.set_option_rsp.error); + } + } + break; + + case GPS_EVENT_STOP_SESSION: + LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_STOP_SESSION :::::::::::::::"); + if (gps_event_info->event_data.stop_session_rsp.error == GPS_ERR_NONE) { + _gps_server_close_data_connection(server); + _gps_server_stop_event(server); + } else { + LOG_GPS(DBG_ERR, "//Stop Session Failed, error : %d", + gps_event_info->event_data.stop_session_rsp.error); + } + + break; + case GPS_EVENT_CHANGE_INTERVAL: + LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_CHANGE_INTERVAL :::::::::::::::"); + if (gps_event_info->event_data.change_interval_rsp.error == GPS_ERR_NONE) { + LOG_GPS(DBG_LOW, "Change interval success."); + } else { + LOG_GPS(DBG_ERR, "//Change interval Failed, error : %d", + gps_event_info->event_data.change_interval_rsp.error); + } + break; + case GPS_EVENT_REPORT_POSITION: + LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_POSITION :::::::::::::::"); + if (gps_event_info->event_data.pos_ind.error == GPS_ERR_NONE) { + _report_pos_event(server, gps_event_info); + } else { + LOG_GPS(DBG_ERR, "GPS_EVENT_POSITION Failed, error : %d", gps_event_info->event_data.pos_ind.error); + } + break; + case GPS_EVENT_REPORT_BATCH: + LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_BATCH :::::::::::::::"); + if (gps_event_info->event_data.batch_ind.error == GPS_ERR_NONE) { + _report_batch_event(server, gps_event_info); + } else { + LOG_GPS(DBG_ERR, "GPS_EVENT_BATCH Failed, error : %d", gps_event_info->event_data.batch_ind.error); + } + break; + case GPS_EVENT_REPORT_SATELLITE: + if (gps_event_info->event_data.sv_ind.error == GPS_ERR_NONE) { + if (gps_event_info->event_data.sv_ind.sv.pos_valid) { + if (_gps_server_get_gps_state() != POSITION_CONNECTED) + _gps_server_set_gps_state(POSITION_CONNECTED); + } else { + LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_SATELLITE :::::::::::::::"); + if (_gps_server_get_gps_state() != POSITION_SEARCHING) + _gps_server_set_gps_state(POSITION_SEARCHING); + } + _report_sv_event(server, gps_event_info); + } else { + LOG_GPS(DBG_ERR, "GPS_EVENT_SATELLITE Failed, error : %d", gps_event_info->event_data.sv_ind.error); + } + break; + case GPS_EVENT_REPORT_NMEA: + if (_gps_server_get_gps_state() != POSITION_CONNECTED) { + /*LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_NMEA :::::::::::::::"); */ + } + + if (gps_event_info->event_data.nmea_ind.error == GPS_ERR_NONE) { + _report_nmea_event(server, gps_event_info); + } else { + LOG_GPS(DBG_ERR, "GPS_EVENT_NMEA Failed, error : %d", gps_event_info->event_data.nmea_ind.error); + } + break; + case GPS_EVENT_ERR_CAUSE: + break; + case GPS_EVENT_AGPS_VERIFICATION_INDI: + break; + case GPS_EVENT_GET_IMSI: + break; + case GPS_EVENT_GET_REF_LOCATION: + break; + case GPS_EVENT_OPEN_DATA_CONNECTION: { + LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_OPEN_DATA_CONNECTION :::::::::::::::"); + result = _gps_server_open_data_connection(server); + } + break; + case GPS_EVENT_CLOSE_DATA_CONNECTION: { + LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_CLOSE_DATA_CONNECTION :::::::::::::::"); + result = _gps_server_close_data_connection(server); + } + break; + case GPS_EVENT_DNS_LOOKUP_IND: + LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_DNS_LOOKUP_IND :::::::::::::::"); + if (gps_event_info->event_data.dns_query_ind.error == GPS_ERR_NONE) { + result = _gps_server_resolve_dns(gps_event_info->event_data.dns_query_ind.domain_name); + } else { + result = FALSE; + } + if (result == TRUE) { + LOG_GPS(DBG_LOW, "Success to get the DNS Query about [ %s ]", + gps_event_info->event_data.dns_query_ind.domain_name); + } + break; + case GPS_EVENT_FACTORY_TEST: + LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_FACTORY_TEST :::::::::::::::"); + if (gps_event_info->event_data.factory_test_rsp.error == GPS_ERR_NONE) { + LOG_GPS(DBG_LOW, "[LBS server] Response Factory test result success"); + _gps_server_send_facttest_result(gps_event_info->event_data.factory_test_rsp.snr, + gps_event_info->event_data.factory_test_rsp.prn, TRUE); + } else { + LOG_GPS(DBG_ERR, "//[LBS server] Response Factory test result ERROR"); + _gps_server_send_facttest_result(gps_event_info->event_data.factory_test_rsp.snr, + gps_event_info->event_data.factory_test_rsp.prn, FALSE); + } + break; + case GPS_EVENT_GEOFENCE_TRANSITION: + LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_GEOFENCE_TRANSITION :::::::::::::::"); + _report_geofence_transition(gps_event_info->event_data.geofence_transition_ind.geofence_id, + gps_event_info->event_data.geofence_transition_ind.state, + gps_event_info->event_data.geofence_transition_ind.pos.latitude, + gps_event_info->event_data.geofence_transition_ind.pos.longitude, + gps_event_info->event_data.geofence_transition_ind.pos.altitude, + gps_event_info->event_data.geofence_transition_ind.pos.speed, + gps_event_info->event_data.geofence_transition_ind.pos.bearing, + gps_event_info->event_data.geofence_transition_ind.pos.hor_accuracy); + break; + case GPS_EVENT_GEOFENCE_STATUS: + LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_GEOFENCE_STATUS :::::::::::::::"); + _report_geofence_service_status(gps_event_info->event_data.geofence_status_ind.status); + break; + case GPS_EVENT_ADD_GEOFENCE: + LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_ADD_GEOFENCE :::::::::::::::"); + _gps_server_send_geofence_result(GEOFENCE_ADD_FENCE, + gps_event_info->event_data.geofence_event_rsp.geofence_id, + gps_event_info->event_data.geofence_event_rsp.error); + break; + case GPS_EVENT_DELETE_GEOFENCE: + LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_DELETE_GEOFENCE :::::::::::::::"); + _gps_server_send_geofence_result(GEOFENCE_DELETE_FENCE, + gps_event_info->event_data.geofence_event_rsp.geofence_id, + gps_event_info->event_data.geofence_event_rsp.error); + break; + case GPS_EVENT_PAUSE_GEOFENCE: + LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_PAUSE_GEOFENCE :::::::::::::::"); + _gps_server_send_geofence_result(GEOFENCE_PAUSE_FENCE, + gps_event_info->event_data.geofence_event_rsp.geofence_id, + gps_event_info->event_data.geofence_event_rsp.error); + break; + case GPS_EVENT_RESUME_GEOFENCE: + LOG_GPS(DBG_LOW, "<<::::::::::: GPS_EVENT_RESUME_GEOFENCE :::::::::::::::"); + _gps_server_send_geofence_result(GEOFENCE_RESUME_FENCE, + gps_event_info->event_data.geofence_event_rsp.geofence_id, + gps_event_info->event_data.geofence_event_rsp.error); + break; + default: + LOG_GPS(DBG_WARN, "//Error: Isettingalid Event Type %d", gps_event_info->event_id); + break; + } + return result; +} + +#ifndef _TIZEN_PUBLIC_ +int request_supl_ni_session(const char *header, const char *body, int size) +{ + agps_supl_ni_info_t info; + gps_failure_reason_t reason_code; + + info.msg_body = (char *)body; + info.msg_size = size; + info.status = TRUE; + + if (!get_plugin_module()->request(GPS_ACTION_REQUEST_SUPL_NI, &info, &reason_code)) { + LOG_GPS(DBG_ERR, "Failed to request SUPL NI (code:%d)", reason_code); + return FALSE; + } + + return TRUE; +} +#else +static void *request_supl_ni_session(void *data) +{ + gps_ni_data_t *ni_data = (gps_ni_data_t *) data; + agps_supl_ni_info_t info; + gps_failure_reason_t reason_code; + + info.msg_body = (char *)ni_data->msg_body; + info.msg_size = ni_data->msg_size; + info.status = TRUE; + + if (!get_plugin_module()->request(GPS_ACTION_REQUEST_SUPL_NI, &info, &reason_code)) { + LOG_GPS(DBG_ERR, "Failed to request SUPL NI (code:%d)", reason_code); + } + + free(ni_data); + + return NULL; +} + +static void _gps_supl_networkinit_smscb(msg_handle_t hMsgHandle, msg_struct_t msg, void *user_param) +{ + LOG_GPS(DBG_ERR, "_gps_supl_networkinit_smscb is called"); + gps_server_t *server = (gps_server_t *)user_param; + + gps_ni_data_t *new_message = NULL; + + new_message = (gps_ni_data_t *)malloc(sizeof(gps_ni_data_t)); + memset(new_message, 0x00, sizeof(gps_ni_data_t)); + msg_get_int_value(msg, MSG_MESSAGE_DATA_SIZE_INT, &new_message->msg_size); + msg_get_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, new_message->msg_body, new_message->msg_size); + + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + if (pthread_create(&server->popup_thread, &attr, request_supl_ni_session, new_message) != 0) { + LOG_GPS(DBG_WARN, "Can not make pthread......"); + } +} + +static void _gps_supl_networkinit_wappushcb(msg_handle_t hMsgHandle, const char *pPushHeader, const char *pPushBody, + int pushBodyLen, void *user_param) +{ + gps_server_t *server = (gps_server_t *)user_param; + char *str; + + LOG_GPS(DBG_ERR, "_gps_supl_networkinit_wappushcb is called"); + + if (strstr(pPushHeader, "application/vnd.omaloc-supl-init") != NULL) { + str = strstr(pPushHeader, "X-Wap-Application-Id:"); + + if (strncmp(str + 22, "x-oma-application:ulp.ua", 24) != 0) { + LOG_GPS(DBG_ERR, "Wrong Application-ID"); + return; + } + } + + gps_ni_data_t *new_message = NULL; + + new_message = (gps_ni_data_t *) malloc(sizeof(gps_ni_data_t)); + new_message->msg_body = (char *)pPushBody; + new_message->msg_size = pushBodyLen; + + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + if (pthread_create(&server->popup_thread, &attr, request_supl_ni_session, new_message) != 0) { + LOG_GPS(DBG_WARN, "Can not make pthread......"); + } +} + +static void *_gps_register_msgfwcb(void *data) +{ + gps_server_t *server = (gps_server_t *)data; + msg_handle_t msgHandle = NULL; + msg_error_t err = MSG_SUCCESS; + + int setValue = 0; + int ret; + + int cnt = 60; + + while (cnt > 0) { + ret = vconf_get_bool(VCONFKEY_MSG_SERVER_READY, &setValue); + + if (ret == -1) { + LOG_GPS(DBG_WARN, "Fail to get VCONFKEY_MSG_SERVER_READY"); + return NULL; + } + + if (setValue) { + LOG_GPS(DBG_LOW, "MSG server is READY!!"); + cnt = -1; + } else { + sleep(5); + cnt--; + if (cnt == 0) { + LOG_GPS(DBG_WARN, "Never connect to MSG Server for 300 secs."); + return NULL; + } + } + } + + err = msg_open_msg_handle(&msgHandle); + + if (err != MSG_SUCCESS) { + LOG_GPS(DBG_WARN, "Fail to MsgOpenMsgHandle. Error type = [ %d ]", err); + return NULL; + } + + err = msg_reg_sms_message_callback(msgHandle, &_gps_supl_networkinit_smscb, 7275, (void *)server); + + if (err != MSG_SUCCESS) { + LOG_GPS(DBG_WARN, "Fail to MsgRegSmsMessageCallback. Error type = [ %d ]", err); + return NULL; + } + + err = msg_reg_lbs_message_callback(msgHandle, &_gps_supl_networkinit_wappushcb, (void *)server); + + if (err != MSG_SUCCESS) { + LOG_GPS(DBG_WARN, "Fail to MsgRegLBSMessageCallback. Error type = [ %d ]", err); + return NULL; + } + + LOG_GPS(DBG_LOW, "Success to lbs_register_msgfwcb"); + return NULL; + +} +#endif + +void check_plugin_module(char *module_name) +{ + if (get_replay_enabled() == TRUE) { + g_strlcpy(module_name, "replay", strlen("replay") + 1); + LOG_GPS(DBG_LOW, "REPLAY_ENABELD is TRUE"); + } else if (access(BRCM4752_PATH, F_OK) == 0 || access(BRCM47520_PATH, F_OK) == 0) { + g_strlcpy(module_name, "brcm", strlen("brcm") + 1); + } else if (access(BRCM47511_PATH, F_OK) == 0) { + g_strlcpy(module_name, "brcm-legacy", strlen("brcm-legacy") + 1); + } else if (access(CSR_PATH, F_OK) == 0) { + g_strlcpy(module_name, "csr", strlen("csr") + 1); + } else if (access(QCOM8x30_PATH, F_OK) == 0 || access(QCOM9x15_PATH, F_OK) == 0 || + access(QCOM8974_PATH, F_OK) == 0 || access(QCOM8210_PATH, F_OK) == 0 || + access(QCOM8226_PATH, F_OK) == 0 || access(QCOM8916_PATH, F_OK) == 0) { + g_strlcpy(module_name, "qcom", strlen("qcom") + 1); + } else { + g_strlcpy(module_name, "replay", strlen("replay") + 1); + } + + LOG_GPS(DBG_LOW, "module name : %s", module_name); +} + +static gps_server_t *_initialize_gps_data(void) +{ + g_gps_server = (gps_server_t *) malloc(sizeof(gps_server_t)); + if (g_gps_server == NULL) { + LOG_GPS(DBG_ERR, "Failed to alloc g_gps_server"); + return NULL; + } + memset(g_gps_server, 0x00, sizeof(gps_server_t)); + + g_gps_server->session_state = GPS_SESSION_STOPPED; + g_gps_server->dnet_used = 0; + g_gps_server->logging_enabled = FALSE; + g_gps_server->replay_enabled = FALSE; +#ifdef _TIZEN_PUBLIC_ + g_gps_server->msg_thread = 0; + g_gps_server->popup_thread = 0; +#endif + + memset(&g_gps_server->gps_plugin, 0x00, sizeof(gps_plugin_handler_t)); + + if (g_gps_server->pos_data == NULL) { + g_gps_server->pos_data = (pos_data_t *) malloc(sizeof(pos_data_t)); + if (g_gps_server->pos_data == NULL) { + LOG_GPS(DBG_ERR, "Failed to alloc g_gps_server->pos_data"); + return NULL; + } else { + memset(g_gps_server->pos_data, 0x00, sizeof(pos_data_t)); + } + } + + if (g_gps_server->batch_data == NULL) { + g_gps_server->batch_data = (batch_data_t *) malloc(sizeof(batch_data_t)); + if (g_gps_server->batch_data == NULL) { + LOG_GPS(DBG_ERR, "Failed to alloc g_gps_server->batch_data"); + return NULL; + } else { + memset(g_gps_server->batch_data, 0x00, sizeof(batch_data_t)); + } + } + + if (g_gps_server->sv_data == NULL) { + g_gps_server->sv_data = (sv_data_t *) malloc(sizeof(sv_data_t)); + if (g_gps_server->sv_data == NULL) { + LOG_GPS(DBG_ERR, "Failed to alloc g_gps_server->sv_data"); + return NULL; + } else { + memset(g_gps_server->sv_data, 0x00, sizeof(sv_data_t)); + } + } + + if (g_gps_server->nmea_data == NULL) { + g_gps_server->nmea_data = (nmea_data_t *) malloc(sizeof(nmea_data_t)); + if (g_gps_server->nmea_data == NULL) { + LOG_GPS(DBG_ERR, "Failed to alloc g_gps_server->nmea_data"); + return NULL; + } else { + memset(g_gps_server->nmea_data, 0x00, sizeof(nmea_data_t)); + } + } + + return g_gps_server; +} + +static void _deinitialize_gps_data(void) +{ + if (g_gps_server->pos_data != NULL) { + free(g_gps_server->pos_data); + g_gps_server->pos_data = NULL; + } + + if (g_gps_server->batch_data != NULL) { + free(g_gps_server->batch_data); + g_gps_server->batch_data = NULL; + } + + if (g_gps_server->sv_data != NULL) { + free(g_gps_server->sv_data); + g_gps_server->sv_data = NULL; + } + + if (g_gps_server->nmea_data != NULL) { + if (g_gps_server->nmea_data->data != NULL) { + free(g_gps_server->nmea_data->data); + g_gps_server->nmea_data->data = NULL; + } + free(g_gps_server->nmea_data); + g_gps_server->nmea_data = NULL; + } + + if (g_gps_server != NULL) { + free(g_gps_server); + g_gps_server = NULL; + } +} + +int initialize_server(int argc, char **argv) +{ + FUNC_ENTRANCE_SERVER; + + gps_server_t *server; + char module_name[16]; + + server = _initialize_gps_data(); + if (server == NULL) + return -1; + check_plugin_module(module_name); + _gps_plugin_handler_init(server, module_name); + _gps_get_nmea_replay_mode(server); + _gps_notify_params(server); + + if (!load_plugin_module(server->gps_plugin.name, &server->gps_plugin.handle)) { + LOG_GPS(DBG_ERR, "Fail to load plugin module."); + return -1; + } + + if (!get_plugin_module()->init(_gps_server_gps_event_cb, (void *)server)) { + LOG_GPS(DBG_WARN, "Fail to gps module initialization"); + return -1; + } + +#ifdef _TIZEN_PUBLIC_ + if (pthread_create(&g_gps_server->msg_thread, NULL, _gps_register_msgfwcb, g_gps_server) != 0) { + LOG_GPS(DBG_WARN, "Can not make pthread......"); + } +#endif + + LOG_GPS(DBG_LOW, "Initialization-gps is completed."); + + if (!nps_load_plugin_module(&g_nps_plugin.handle)) { + LOG_NPS(DBG_ERR, "Fail to load lbs_server_NPS plugin module."); + __nps_plugin_handler_deinit(); + return 0; /* TBD: how to deal with this error situation */ + } + + LOG_NPS(DBG_LOW, "Initialization-nps is completed."); + + return 0; +} + +int deinitialize_server() +{ + gps_failure_reason_t ReasonCode = GPS_FAILURE_CAUSE_NORMAL; + +#ifdef _TIZEN_PUBLIC_ + pthread_join(g_gps_server->msg_thread, (void *)&g_gps_server->msg_thread_status); +#endif + + _gps_ignore_params(); + + if (!get_plugin_module()->deinit(&ReasonCode)) { + LOG_GPS(DBG_WARN, "Fail to gps module de-initialization"); + } + unload_plugin_module(g_gps_server->gps_plugin.handle); + + _gps_plugin_handler_deinit(g_gps_server); + _deinitialize_gps_data(); + + nps_unload_plugin_module(g_nps_plugin.handle); + __nps_plugin_handler_deinit(); + + return 0; +} + +int register_update_callbacks(struct gps_callbacks *gps_callback, void *user_data) +{ + g_update_cb = *gps_callback; + g_user_data = user_data; + return 0; +} diff --git a/lbs-server/src/server.h b/lbs-server/src/server.h new file mode 100644 index 0000000..3584020 --- /dev/null +++ b/lbs-server/src/server.h @@ -0,0 +1,90 @@ +/* + * lbs-server + * + * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Minjune Kim + * Genie Kim + * + * 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 _SERVER_H_ +#define _SERVER_H_ + +#include "lbs_server.h" + +#define SUPL_SERVER_URL_DEFAULT "your.supl-server.com" +#define SUPL_SERVER_PORT_DEFAULT 7275 + +/*This structure must be synchronized with State of mctxlDef.h */ +typedef enum { + GPS_STATE_AVAILABLE, + GPS_STATE_OUT_OF_SERVICE, + GPS_STATE_TEMPORARILY_UNAVAILABLE, +} gps_state_t; + +typedef enum { + GPS_SESSION_STOPPED, + GPS_SESSION_STARTING, + GPS_SESSION_STARTED, + GPS_SESSION_STOPPING, +} gps_session_state_t; + +typedef enum { + AGPS_VERIFICATION_YES = 0x00, /**< Specifies Confirmation yes. */ + AGPS_VERIFICATION_NO = 0x01, /**< Specifies Confirmation no. */ + AGPS_VERIFICATION_NORESPONSE = 0x02, /**< Specifies Confirmation no response. */ +} agps_verification_t; + +typedef enum { + GPS_MAIN_NOTIFY_NO_VERIFY = 0x00, + GPS_MAIN_NOTIFY_ONLY = 0x01, + GPS_MAIN_NOTIFY_ALLOW_NORESPONSE = 0x02, + GPS_MAIN_NOTIFY_NOTALLOW_NORESPONSE = 0x03, + GPS_MAIN_NOTIFY_PRIVACY_NEEDED = 0x04, + GPS_MAIN_NOTIFY_PRIVACY_OVERRIDE = 0x05, +} gps_main_notify_type_t; + +typedef struct { + char requester_name[50]; /**< Specifies Requester name*/ + char client_name[50]; /**< Specifies Client name */ +} gps_main_verif_info_t; + +typedef struct { + void *msg_body; + int msg_size; +} gps_ni_data_t; + +int initialize_server(int argc, char **argv); +int deinitialize_server(); + +int request_change_pos_update_interval_standalone_gps(unsigned int interval); +int request_start_batch_session(int batch_interval, int batch_period); +int request_stop_batch_session(void); +int request_start_session(int interval); +int request_stop_session(void); +#ifndef _TIZEN_PUBLIC_ +int request_supl_ni_session(const char *header, const char *body, int size); +#endif +int register_update_callbacks(struct gps_callbacks *gps_callback, void *user_data); + +int request_add_geofence(int fence_id, double latitude, double longitude, int radius, int last_state, int monitor_states, int notification_responsiveness, int unknown_timer); +int request_delete_geofence(int fence_id); +int request_pause_geofence(int fence_id); +int request_resume_geofence(int fence_id, int monitor_states); +int request_delete_gps_data(void); + +int get_nmea_from_server(int *timestamp, char **nmea_data); + +#endif /* _SERVER_H_ */ diff --git a/lbs-server/src/setting.c b/lbs-server/src/setting.c new file mode 100644 index 0000000..5829ac1 --- /dev/null +++ b/lbs-server/src/setting.c @@ -0,0 +1,187 @@ +/* + * lbs-server + * + * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Minjune Kim + * Genie Kim + * + * 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 +#include "setting.h" +#include "debug_util.h" + +#include +#include +#include +#include + +int setting_set_int(const char *path, int val) +{ + int ret = vconf_set_int(path, val); + if (ret == 0) { + ret = TRUE; + } else { + LOG_GPS(DBG_ERR, "vconf_set_int failed, [%s]", path); + ret = FALSE; + } + return ret; +} + +int setting_get_int(const char *path, int *val) +{ + int ret = vconf_get_int(path, val); + if (ret == 0) { + ret = TRUE; + } else { + LOG_GPS(DBG_ERR, "vconf_get_int failed, [%s]", path); + ret = FALSE; + } + return ret; +} + +int setting_set_double(const char *path, double val) +{ + int ret = vconf_set_dbl(path, val); + if (ret == 0) { + ret = TRUE; + } else { + LOG_GPS(DBG_ERR, "vconf_set_dbl failed, [%s]", path); + ret = FALSE; + } + return ret; +} + +int setting_get_double(const char *path, double *val) +{ + int ret = vconf_get_dbl(path, val); + if (ret == 0) { + ret = TRUE; + } else { + LOG_GPS(DBG_ERR, "vconf_get_int failed, [%s]", path); + ret = FALSE; + } + return ret; +} + +int setting_set_string(const char *path, const char *val) +{ + int ret = vconf_set_str(path, val); + if (ret == 0) { + ret = TRUE; + } else { + LOG_GPS(DBG_ERR, "vconf_set_str failed, [%s]", path); + ret = FALSE; + } + return ret; +} + +char *setting_get_string(const char *path) +{ + return vconf_get_str(path); +} + +int setting_notify_key_changed(const char *path, void *key_changed_cb, void *data) +{ + int ret = TRUE; + if (vconf_notify_key_changed(path, key_changed_cb, data) != 0) { + LOG_GPS(DBG_ERR, "Fail to vconf_notify_key_changed [%s]", path); + ret = FALSE; + } + return ret; +} + +int setting_ignore_key_changed(const char *path, void *key_changed_cb) +{ + int ret = TRUE; + if (vconf_ignore_key_changed(path, key_changed_cb) != 0) { + LOG_GPS(DBG_ERR, "Fail to vconf_ignore_key_changed [%s]", path); + ret = FALSE; + } + return ret; +} + + +static unsigned char _get_mac_address(char *mac) +{ + int rv = 0; + char *mac_addr = NULL; + + rv = wifi_get_mac_address(&mac_addr); + if (rv != WIFI_ERROR_NONE) + return FALSE; + + g_strlcpy(mac, mac_addr, NPS_UNIQUE_ID_LEN); + g_free(mac_addr); + + return TRUE; +} + +static unsigned char _get_device_name(char *device_name) +{ + char *ret_str; + + ret_str = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR); + if (ret_str == NULL) { + return FALSE; + } + + memcpy(device_name, ret_str, strlen(ret_str) + 1); + + return TRUE; +} + +/* +Basic : Use BT address +BT Address : 12 digits (1234567890AB) +UNIQUEID : X X X 4 0 X 1 6 X 7 5 X 2 8 X A B 3 9 +X: Model Name + +Alternative 1: Use WiFi MAC Address +Cause : We can get local address and name only when bluetooth is on. +MAC Address : 17 digits +UNIQUEID : X X X 4 0 X 1 6 X 7 5 X 2 8 X A B 3 9 +X: Device Name (We can't get the model name, setting is using system string.) +*/ +unsigned char setting_get_unique_id(char *unique_id) +{ + char *mac_addr; + char *device_name; + + mac_addr = g_malloc0(NPS_UNIQUE_ID_LEN); + if (!_get_mac_address(mac_addr)) { + g_free(mac_addr); + return FALSE; + } + + device_name = g_malloc0(NPS_UNIQUE_ID_LEN); + if (!_get_device_name(device_name)) { + g_free(mac_addr); + g_free(device_name); + return FALSE; + } + + snprintf(unique_id, NPS_UNIQUE_ID_LEN, "%1.X%1.X%1.X%1.X%1.X%1.X%1.X%1.X%1.X%1.X%1.X%1.X%1.X%1.X%1.X%1.X%1.X%1.X%1.X", + device_name[0] & 0xF, device_name[1] & 0xF, device_name[2] & 0xF, mac_addr[3] & 0xF, + mac_addr[9] & 0xF, device_name[3] & 0xF, mac_addr[0] & 0xF, mac_addr[5] & 0xF, + device_name[4] & 0xF, mac_addr[6] & 0xF, mac_addr[4] & 0xF, device_name[5] & 0xF, + mac_addr[1] & 0xF, mac_addr[7] & 0xF, device_name[6] & 0xF, mac_addr[9] & 0xF, + mac_addr[10] & 0xF, mac_addr[2] & 0xF, mac_addr[8] & 0xF); + g_free(mac_addr); + g_free(device_name); + + return TRUE; +} + diff --git a/lbs-server/src/setting.h b/lbs-server/src/setting.h new file mode 100644 index 0000000..8aa6cd0 --- /dev/null +++ b/lbs-server/src/setting.h @@ -0,0 +1,55 @@ +/* + * lbs-server + * + * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Minjune Kim + * Genie Kim + * + * 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 _SETTING_H_ +#define _SETTING_H_ + +#include +#include + +#include + +#define NPS_UNIQUE_ID_LEN (20) + +/*#define NPS_MANAGER_PLUGIN_PATH "/usr/lib/libSLP-nps-plugin.so" */ + +typedef enum { + POSITION_OFF = 0, + POSITION_SEARCHING, + POSITION_CONNECTED, + POSITION_MAX +} pos_state_t; + +int setting_set_int(const char *path, int val); +int setting_get_int(const char *path, int *val); +int setting_set_double(const char *path, double val); +int setting_get_double(const char *path, double *val); +int setting_set_string(const char *path, const char *val); +char *setting_get_string(const char *path); + +typedef void (*key_changed_cb)(keynode_t *key, void *data); + +int setting_notify_key_changed(const char *path, void *key_changed_cb, void *data); +int setting_ignore_key_changed(const char *path, void *key_changed_cb); + +unsigned char setting_get_unique_id(char *unique_id); + +#endif /* _SETTING_H_ */ diff --git a/module/CMakeLists.txt b/module/CMakeLists.txt new file mode 100644 index 0000000..78675b8 --- /dev/null +++ b/module/CMakeLists.txt @@ -0,0 +1,28 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.0) +PROJECT(client C) + +SET(gps_module "gps") +SET(nps_module "wps") +SET(companion_module "companion") + + +SET(CLIENT_SRCS_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +SET(module_pkgs_LDFLAGS "${module_pkgs_LDFLAGS} -ldl") +SET(MODULE_EXTRA_CFLAGS "${MODULE_EXTRA_CFLAGS} -D_GNU_SOURCE") + +ADD_LIBRARY(${gps_module} SHARED ${CLIENT_SRCS_DIR}/gps_module.c) +TARGET_LINK_LIBRARIES(${gps_module} ${module_pkgs_LDFLAGS}) +SET_TARGET_PROPERTIES(${gps_module} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER} CLEAN_DIRECT_OUTPUT 1) +SET_TARGET_PROPERTIES(${gps_module} PROPERTIES COMPILE_FLAGS ${MODULE_EXTRA_CFLAGS}) + +INSTALL(TARGETS ${gps_module} DESTINATION ${LIB_DIR}/location/module) + +IF (ENABLE_WPS) +SET(nps_module "wps") +ADD_LIBRARY(${nps_module} SHARED ${CLIENT_SRCS_DIR}/nps_module.c) +TARGET_LINK_LIBRARIES(${nps_module} ${module_pkgs_LDFLAGS}) +SET_TARGET_PROPERTIES(${nps_module} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER} CLEAN_DIRECT_OUTPUT 1) +SET_TARGET_PROPERTIES(${nps_module} PROPERTIES COMPILE_FLAGS ${MODULE_EXTRA_CFLAGS}) + +INSTALL(TARGETS ${nps_module} DESTINATION ${LIB_DIR}/location/module) +ENDIF (ENABLE_WPS) diff --git a/packaging/lbs-server.changes b/packaging/lbs-server.changes new file mode 100644 index 0000000..9855b03 --- /dev/null +++ b/packaging/lbs-server.changes @@ -0,0 +1,1090 @@ +[Version] lbs-server_0.6.7 +[Date] 12 Jun 2015 +[Title] The user and group of lbs-server process was changed to system when it is activated by DBus automatically. + Install directory was change from /usr/libexec to /usr/bin + manifest files was moved to packaging directory +[Developer] Young-Ae Kang + +================================================================================ + +[Version] lbs-server_0.6.4 +[Date] 17 Apr 2015 +[Title] Dbus path changed to support auto activation +[Developer] Kyoungjun Sung + +================================================================================ +[Version] lbs-server_0.6.3 +[Date] 19 Mar 2015 +[Title] Permission changed to system for non-root daemon, Vconf permission changed + +================================================================================ +[Version] lbs-server_0.5.4 +[date] 24 Jul 2014 +[Title] Change a smack label of GPS Indicator value, location_fw::vconf to location_fw::client +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Youngho Jeon + +================================================================================ + +[Version] lbs-server_0.5.3 +[date] 16 May 2014 +[Title] adjust codes on geofence features +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Haena Kim + +================================================================================ + +[Version] lbs-server_0.5.1 +[date] 31 Mar 2014 +[Title] Making gps&nps manager to one server +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Haena Kim + +================================================================================ + +[Version] gps-manager_0.4.13 +[date] 20 Dec 2013 +[Title] Fix memory leaks at satellite callback +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.4.12 +[date] 20 Dec 2013 +[Title] Fix MDM bug +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.4.11 +[date] 4 Dec 2013 +[Title] Disable MDM_PHASE2 feature +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.4.10 +[date] 25 Nov 2013 +[Title] Use full path for script +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.4.9 +[date] 19 Nov 2013 +[Title] Add dump gps log +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.4.8 +[date] 18 Nov 2013 +[Title] Add smack rule, system::vconf_setting, system::vconf +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.4.7 +[date] 14 Nov 2013 +[Title] Add smack rule, location_fw::maps +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + + +[Version] gps-manager_0.4.6 +[date] 12 Nov 2013 +[Title] Fix memory leak +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.4.5 +[date] 9 Nov 2013 +[Title] Add 'USE SV' option for sv update callback +[Issue#] NA +[Problem] Power consumption +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.4.4 +[date] 31 Oct 2013 +[Title] prevent memory leaks +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.4.3 +[date] 31 Oct 2013 +[Title] Enable dlog +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.4.2 +[date] 24 Oct 2013 +[Title] Check returned value at stop +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.4.1 +[date] 30 Sep 2013 +[Title] Add smack rule, location_fw::client +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.4.0 +[date] 30 Sep 2013 +[Title] remove set/get devname in module +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.3.5-1 +[date] 27 Sep 2013 +[Title] add set_option for 'Delete GPS' +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.3.4-1 +[date] 24 Sep 2013 +[Title] Add connman on rule +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.3.3-1 +[date] 23 Sep 2013 +[Title] change booting script to launch gps-manager at booting time for SUPL +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.3.2-1 +[date] 5 Sep 2013 +[Title] change service file for SUPL NI +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.3.1-1 +[date] 22 Aug 2013 +[Title] add smack rule +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.3.0-1 +[date] 22 Aug 2013 +[Title] Support HW geofence +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.2.61-1 +[date] 10 July 2013 +[Title] Stop tracking at GPS off +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.2.60-1 +[date] 10 July 2013 +[Title] add geofence interface +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.59-1 +[date] 9 July 2013 +[Title] bug fix for speed +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.58-1 +[date] 1 July 2013 +[Title] change last position key to use memory +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.57-1 +[date] 27 June 2013 +[Title] Apply dbus smack +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.2.56-1 +[date] 27 June 2013 +[Title] Change on_signal_callback as lbs_client_cb +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.2.55-1 +[date] 26 June 2013 +[Title] add msm8974 plugin node +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.54-1 +[date] 11 June 2013 +[Title] call lbs_client_stop in shutdown to prevent destroy called without stop called +[Title] add SECURE_LOG +[Issue#] P130605-8140 +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Ming Zhu + +================================================================================ + +[Version] gps-manager_0.2.53-1 +[date] 7 June 2013 +[Title] set gps_manager into NULL after free +[Issue#] P130605-8140 +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.2.52-1 +[date] 31 May 2013 +[Title] remove checking push header of SUPL NI + change service file and remove rc3 file for serviced +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.51-1 +[date] 31 May 2013 +[Title] Altitude can have nonpositive value +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.50-1 +[date] 22 May 2013 +[Title] Fix PLM P130516-7622. +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Congyi Shi + +================================================================================ + +[Version] gps-manager_0.2.49-1 +[date] 20 May 2013 +[Title] change accuracy data type from int to double +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.48-1 +[date] 15 May 2013 +[Title] Fix PLM +[Issue#] P130506-6200 +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.2.47-1 +[date] 13 May 2013 +[Title] Change the DoCoMo location logs saving mechanism. +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Congyi Shi + +================================================================================ + +[Version] gps-manager_0.2.46-1 +[date] 10 May 2013 +[Title] Add smack label to vconf +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.2.45-1 +[date] 10 May 2013 +[Title] add liblodg when GPS is started/stoped, Add smack label to vconf +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.44-1 +[date] 8 May 2013 +[Title] add msm_8x30 gps module +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.43-1 +[date] 7 May 2013 +[Title] change g_variant from {ss} to {sv} for SUPL NI message +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.42-1 +[date] 3 May 2013 +[Title] add smack requires : use_internet for getting XTRA data from network +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Patrick Song + +================================================================================ + +[Version] gps-manager_0.2.41-1 +[date] 2 May 2013 +[Title] use set_option "SUPLNI" +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.40-1 +[date] 25 Apr 2013 +[Title] [temporary] Do not get 'Advanced GPS' options for SUPL +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.39-1 +[date] 24 Apr 2013 +[Title] add update interval for set_last_position +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.37-1 +[date] 16 Apr 2013 +[Title] fix bug for mkdir nmea logging folder +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.36-1 +[date] 16 Apr 2013 +[Title] fix PLM issue : satellite callback has NULL data after stop event +[Issue#] P130415-6024 +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.35-1 +[date] 12 Apr 2013 +[Title] fix bug for user_data of setting_notify_cb +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.34-1 +[date] 08 Apr 2013 +[Title] remove gps_last_pos and fix a crash when updating nmea +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.2.33-1 +[date] 05 Apr 2013 +[Title] add DOCOMO supl server address +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.32-1 +[date] 01 Apr 2013 +[Title] remove display lock (move to plugin) +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.31-2 +[date] 28 Mar 2013 +[Title] change pmapi to deviced package and smack label of dbus service +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.31-1 +[date] 26 Mar 2013 +[Title] Add default vconf value for SUPL Version & prevent gps-manager from blocking Application ID of SUPL Message when it is HEXA code. +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Patrick Song + +================================================================================ + +[Version] gps-manager_0.2.30-1 +[date] 26 Feb 2013 +[Title] change speed unit from m/s to km/h in gps-manager module +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.29-1 +[date] 20 Feb 2013 +[Title] add mdm_register_policy for GPS +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.28-1 +[date] 14 Feb 2013 +[Title] add smack requires : default label for location-gps-manager +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Minjune Kim + +================================================================================ + +[Version] gps-manager_0.2.27-1 +[date] 6 Feb 2013 +[Title] change node name : mdm9x15(add qcom plugin) +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.26-1 +[date] 5 Feb 2013 +[Title] add smack requires : sys-assert +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.25-1 +[date] 31 Jan 2013 +[Title] remove location_fw::brcm in manifest +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.24-1 +[date] 26 Jan 2013 +[Title] fixed prevent defect +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.23-1 +[date] 24 Jan 2013 +[Title] change boilerplate +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] change boilerplate +[Developer] Genie Kim + +================================================================================ + +[Version] gps-manager_0.2.22-1 +[date] 14 Jan 2013 +[Title] fix power state for starting/stopping + remove debian folder and add .changes file +[Issue#] P130109-2556 +[Problem] power comsumption issue +[Cause] lock/unlock power state are different +[Solution] change power state are same +[Developer] Genie Kim + +================================================================================ + +gps-manager (0.2.21-1) precise; urgency=low + + * fix gps icon issue in indicator + * Tag: gps-manager_0.2.21-1 + + -- Genie Kim Thu, 10 Jan 2013 22:13:48 +0900 + +gps-manager (0.2.20-1) precise; urgency=low + + * Support PositionVelocity interface + * Tag: gps-manager_0.2.20-1 + + -- Minjune Kim Fri, 04 Jan 2013 16:43:32 +0900 + +gps-manager (0.2.19-1) precise; urgency=low + + * change sequence of callback funcation(pos > vel) + * Tag: gps-manager_0.2.19-1 + + -- Genie Kim Fri, 14 Dec 2012 17:24:59 +0900 + +gps-manager (0.2.18-1) precise; urgency=low + + * fix bug for accuracy + * Tag: gps-manager_0.2.18-1 + + -- Genie Kim Thu, 13 Dec 2012 22:02:12 +0900 + +gps-manager (0.2.17-1) unstable; urgency=low + + * Check application ID of SUPL NI Push header message + * Tag: gps-manager_0.2.17-1 + + -- Patrick Song Fri, 07 Dec 2012 13:56:58 +0900 + +gps-manager (0.2.16-1) unstable; urgency=low + + * fix bug when REPLAY mode is enabled + * remove supl popup code(move to plugin) + * Tag: gps-manager_0.2.16-1 + + -- Genie Kim Mon, 03 Dec 2012 14:25:45 +0900 + +gps-manager (0.2.15-1) unstable; urgency=low + + * Add default vconf value for Server FQDN Type + * Tag: gps-manager_0.2.15-1 + + -- Patrick Song Tue, 27 Nov 2012 18:42:33 +0900 + +gps-manager (0.2.14-1) unstable; urgency=low + + * bug fix for initialize position state key + * Tag: gps-manager_0.2.14-1 + + -- Genie Kim Mon, 19 Nov 2012 13:38:56 +0900 + +gps-manager (0.2.13-1) unstable; urgency=low + + * change to set only gps state(unset position state) + * Tag: gps-manager_0.2.13-1 + + -- Genie Kim Sat, 10 Nov 2012 14:52:03 +0900 + +gps-manager (0.2.12-1) unstable; urgency=low + + * fixed prevent defect + * Tag: gps-manager_0.2.12-1 + + -- Genie Kim Tue, 06 Nov 2012 16:00:42 +0900 + +gps-manager (0.2.11-1) unstable; urgency=low + + * Fix S1-9851, used the wrong index for finding used satellites. + * Tag: gps-manager_0.2.11-1 + + -- Minjune Kim Mon, 05 Nov 2012 13:43:40 +0900 + +gps-manager (0.2.10-1) unstable; urgency=low + + * Prevent to emit status_cb after destroying an object. + * Tag: gps-manager_0.2.10-1 + + -- Minjune Kim Mon, 22 Oct 2012 14:51:09 +0900 + +gps-manager (0.2.9-1) unstable; urgency=low + + * Remove heynoti for hibernation + * Tag: gps-manager_0.2.9-1 + + -- Minjune Kim Wed, 17 Oct 2012 13:33:23 +0900 + +gps-manager (0.2.8-1) unstable; urgency=low + + * change message code for DFMS + * Tag: gps-manager_0.2.8-1 + + -- Genie Kim Mon, 08 Oct 2012 21:13:26 +0900 + +gps-manager (0.2.7-1) unstable; urgency=low + + * change gps-manager init time from booting time to position start time + * Tag: gps-manager_0.2.7-1 + + -- Genie Kim Thu, 27 Sep 2012 16:09:53 +0900 + +gps-manager (0.2.6-1) unstable; urgency=low + + * add manifest file for smack + * Tag: gps-manager_0.2.6-1 + + -- Genie Kim Fri, 21 Sep 2012 11:17:19 +0900 + +gps-manager (0.2.5-1) unstable; urgency=low + + * Fix crash when stopping GPS + * Tag: gps-manager_0.2.5-1 + + -- Minjune Kim Mon, 17 Sep 2012 21:15:47 +0900 + +gps-manager (0.2.4-1) unstable; urgency=low + + * brcm plugin name is changed from old to legacy + * Tag: gps-manager_0.2.4-1 + + -- Genie Kim Fri, 14 Sep 2012 18:11:36 +0900 + +gps-manager (0.2.3-1) unstable; urgency=low + + * seperate brcm47511 & brcm4752 in script + * Tag: gps-manager_0.2.3-1 + + -- Genie Kim Thu, 06 Sep 2012 17:06:02 +0900 + +gps-manager (0.2.2-1) unstable; urgency=low + + * brcm4752 is released(change gps manager script) + * Tag: gps-manager_0.2.2-1 + + -- Genie Kim Tue, 21 Aug 2012 14:50:10 +0900 + +gps-manager (0.2.1-12) unstable; urgency=low + + * Apply the modification of msg-service. + * Tag: gps-manager_0.2.1-12 + + -- Minjune Kim Tue, 07 Aug 2012 11:22:00 +0900 + +gps-manager (0.2.1-11) unstable; urgency=low + + * Update velocity before a position. + * Tag: gps-manager_0.2.1-11 + + -- Minjune Kim Fri, 03 Aug 2012 16:43:19 +0900 + +gps-manager (0.2.1-10) unstable; urgency=low + + * Support wps for an emulator. + * Tag: gps-manager_0.2.1-10 + + -- Minjune Kim Fri, 13 Jul 2012 14:52:34 +0900 + +gps-manager (0.2.1-9) unstable; urgency=low + + * Strip /usr/libexec/gps-manager + * Tag: gps-manager_0.2.1-9 + + -- Minjune Kim Wed, 11 Jul 2012 21:43:02 +0900 + +gps-manager (0.2.1-8) unstable; urgency=low + + * change NMEA saved directory and prevent saving NMEA log for each session while running TTFF test + * Tag: gps-manager_0.2.1-8 + + -- sunggyu lee Fri, 29 Jun 2012 18:10:42 +0900 + +gps-manager (0.2.1-7) unstable; urgency=low + + * Apply new glib + * Tag: gps-manager_0.2.1-7 + + -- Minjune Kim Mon, 18 Jun 2012 21:14:04 +0900 + +gps-manager (0.2.1-6) unstable; urgency=low + + * adjust broadcom supl server + * change directory path of config files to /etc(for FOTA) + * Tag: gps-manager_0.2.1-6 + + -- Genie Kim Fri, 15 Jun 2012 14:27:30 +0900 + +gps-manager (0.2.1-5) unstable; urgency=low + + * remove sensor module and disable sensor aiding + * Tag: gps-manager_0.2.1-5 + + -- Genie Kim Tue, 12 Jun 2012 20:31:41 +0900 + +gps-manager (0.2.1-4) unstable; urgency=low + + * change to set gps status for indicator(separate position/gps/wps status) + * Tag: gps-manager_0.2.1-4 + + -- Genie Kim Thu, 07 Jun 2012 23:23:00 +0900 + +gps-manager (0.2.1-3) unstable; urgency=low + + * changes start & stop gps-manager to use set_options + * Tag: gps-manager_0.2.1-3 + + -- Genie Kim Sun, 03 Jun 2012 20:56:56 +0900 + +gps-manager (0.2.1-2) unstable; urgency=low + + * remove vconf depends in plugin dev pc file + * Tag: gps-manager_0.2.1-2 + + -- Genie Kim Fri, 25 May 2012 22:56:24 +0900 + +gps-manager (0.2.1-1) unstable; urgency=low + + * load gps-manager sensor plugin(pdr) + * Tag: gps-manager_0.2.1-1 + + -- Genie Kim Thu, 24 May 2012 21:26:05 +0900 + +gps-manager (0.2.0-3) unstable; urgency=low + + * fix bug for vconf key(gps/wps state) + * Tag: gps-manager_0.2.0-3 + + -- Genie Kim Thu, 24 May 2012 11:45:16 +0900 + +gps-manager (0.2.0-2) unstable; urgency=low + + * fix build break in i386(remove pdr feature) + * Tag: gps-manager_0.2.0-2 + + -- Genie Kim Wed, 16 May 2012 11:49:51 +0900 + +gps-manager (0.2.0-1) unstable; urgency=low + + * add pdr feature and change vconf key + * Tag: gps-manager_0.2.0-1 + + -- Genie Kim Tue, 15 May 2012 20:03:33 +0900 + +gps-manager (0.1.6-7) unstable; urgency=low + + * fixed bug for setting replay mode on emulator + * Tag: gps-manager_0.1.6-7 + + -- Genie Kim Fri, 06 Apr 2012 11:16:43 +0900 + +gps-manager (0.1.6-6) unstable; urgency=low + + * check abnormal value of speed and direction in last velocity + * Tag: gps-manager_0.1.6-6 + + -- Genie Kim Mon, 02 Apr 2012 17:12:29 +0900 + +gps-manager (0.1.6-5) unstable; urgency=low + + * Read vconf to get last_position and last_velocity on module + * Tag: gps-manager_0.1.6-5 + + -- Minjune Kim Tue, 27 Mar 2012 11:14:08 +0900 + +gps-manager (0.1.6-4) unstable; urgency=low + + * fixed bug for setting replay mode + * Tag: gps-manager_0.1.6-4 + + -- Genie Kim Fri, 23 Mar 2012 10:56:10 +0900 + +gps-manager (0.1.6-3) unstable; urgency=low + + * Move object_new to ref_gps_mananger in last_pos, last_vel and last_sat + * Tag: gps-manager_0.1.6-3 + + -- Minjune Kim Tue, 20 Mar 2012 13:14:23 +0900 + +gps-manager (0.1.6-2) unstable; urgency=low + + * Fix the bug that timestamp in satellite info had been wrong. + * Tag: gps-manager_0.1.6-2 + + -- Minjune Kim Mon, 19 Mar 2012 16:43:05 +0900 + +gps-manager (0.1.6-1) unstable; urgency=low + + * bug fix for last_pos/vel/sat functions + * Tag: gps-manager_0.1.6-1 + + -- Genie Kim Thu, 08 Mar 2012 22:15:53 +0900 + +gps-manager (0.1.5-3) unstable; urgency=low + + * Delete useless . in gps-manager.postinst.in + * Tag: gps-manager_0.1.5-3 + + -- Youngae Kang Thu, 08 Mar 2012 10:16:39 +0900 + +gps-manager (0.1.5-2) unstable; urgency=low + + * Remove checking a sat_cb to support an emulator. + * Tag: gps-manager_0.1.5-2 + + -- Minjune Kim Wed, 07 Mar 2012 10:57:03 +0900 + +gps-manager (0.1.5-1) unstable; urgency=low + + * add feature for pos/vel/sat + * add satellite callback in module + * Tag: gps-manager_0.1.5-1 + + -- Genie Kim Mon, 27 Feb 2012 21:54:47 +0900 + +gps-manager (0.1.4-2) unstable; urgency=low + + * Fix a crash while init WPS module on emulator + * Tag: gps-manager_0.1.4-2 + + -- Minjune Kim Mon, 20 Feb 2012 22:36:47 +0900 + +gps-manager (0.1.4-1) unstable; urgency=low + + * change indicator state to using gps and wps + * Tag: gps-manager_0.1.4-1 + + -- Minjune Kim Fri, 17 Feb 2012 17:08:22 +0900 + +gps-manager (0.1.3-2) unstable; urgency=low + + * add qcom plugin in script + * Tag: gps-manager_0.1.3-2 + + -- Genie Kim Thu, 16 Feb 2012 11:18:58 +0900 + +gps-manager (0.1.3-1) unstable; urgency=low + + * fixed bug at snprintf + * Tag: gps-manager_0.1.3-1 + + -- Genie Kim Mon, 13 Feb 2012 12:37:29 +0900 + +gps-manager (0.1.2-1) unstable; urgency=low + + * adjust replay plugin + * Tag: gps-manager_0.1.2-1 + + -- Genie Kim Wed, 01 Feb 2012 16:30:55 +0900 + +gps-manager (0.1.1-0) unstable; urgency=low + + * add last position and change setting key path + * Tag: gps-manager_0.1.1-0 + + -- Genie Kim Thu, 26 Jan 2012 17:30:31 +0900 + +gps-manager (0.1.0-1) unstable; urgency=low + + * Refactor source code. + * Tag: gps-manager_0.1.0-1 + + -- Yunhan Kim Wed, 21 Dec 2011 17:01:05 +0900 + +gps-manager (0.1.0-0) unstable; urgency=low + + * Initial release + * Tag: gps-manager_0.1.0-0 + + -- Yunhan Kim Thu, 06 Oct 2011 14:41:51 +0900 diff --git a/packaging/lbs-server.manifest b/packaging/lbs-server.manifest new file mode 100644 index 0000000..e975c4a --- /dev/null +++ b/packaging/lbs-server.manifest @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packaging/location-lbs-server.manifest b/packaging/location-lbs-server.manifest new file mode 100644 index 0000000..a76fdba --- /dev/null +++ b/packaging/location-lbs-server.manifest @@ -0,0 +1,5 @@ + + + + + -- 2.34.1