2. geofence-server.service for systemd is added.
3. DBUS_SYSTEM_BUS is replaced with DBUS_SESSION_BUS.
4. Directory for dbus service files was changed from /usr/share/dbus-1/system-services/ to /usr/share/dbus-1/services/
Signed-off-by: Young-Ae Kang <youngae.kang@samsung.com>
Change-Id: I989844fca494289a094e42f75a88640eaa2a8916
#Dependencies
SET(common_dp "glib-2.0 geofence-dbus dlog gio-2.0 capi-appfw-app-manager")
-SET(server_dp "${common_dp} network vconf vconf-internal-keys gthread-2.0 gio-unix-2.0 sqlite3 db-util alarm-service deviced capi-location-manager capi-network-bluetooth capi-network-wifi libcore-context-manager")
+SET(server_dp "${common_dp} network vconf vconf-internal-keys gthread-2.0 gio-unix-2.0 sqlite3 db-util alarm-service deviced capi-location-manager capi-network-bluetooth capi-network-wifi libcore-context-manager libtzplatform-config")
SET(module_dp "${common_dp} gmodule-2.0 capi-geofence-manager")
# Set required packages
INCLUDE_DIRECTORIES(src include)
+#Process will be launched by systemd. TODO: checking dbus auto activation
CONFIGURE_FILE(org.tizen.lbs.Providers.GeofenceServer.service.in org.tizen.lbs.Providers.GeofenceServer.service @ONLY)
-INSTALL(FILES org.tizen.lbs.Providers.GeofenceServer.service DESTINATION /usr/share/dbus-1/system-services)
-INSTALL(FILES config/geofence-server.conf DESTINATION ${SYSCONF_DIR}/dbus-1/system.d)
+#INSTALL(FILES org.tizen.lbs.Providers.GeofenceServer.service DESTINATION /usr/share/dbus-1/system-services)
+#INSTALL(FILES config/geofence-server.conf DESTINATION ${SYSCONF_DIR}/dbus-1/system.d)
+INSTALL(FILES org.tizen.lbs.Providers.GeofenceServer.service DESTINATION /usr/share/dbus-1/services)
+INSTALL(FILES config/geofence-server.conf DESTINATION ${SYSCONF_DIR}/dbus-1/session.d)
ADD_EXECUTABLE(${PROJECT_NAME} ${SERVER_SRCS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${server_pkgs_LDFLAGS} -lm)
<policy context="default">
<allow own="org.tizen.lbs.Providers.GeofenceServer"/>
- <allow send_destination="org.tizen.lbs.Providers.GeofenceServer"/>
+ <deny send_destination="org.tizen.lbs.Providers.GeofenceServer"/>
+ <check send_destination="org.tizen.lbs.Providers.GeofenceServer"
+ send_interface="org.tizen.lbs.Geofence"
+ privilege="http://tizen.org/privilege/location" />
<allow receive_sender="org.tizen.lbs.Providers.GeofenceServer"/>
</policy>
</busconfig>
[D-BUS Service]
Name=org.tizen.lbs.Providers.GeofenceServer
Exec=@BIN_DIR@/geofence-server
-User=system
-Group=system
+#User=system
+#Group=system
#include <string.h>
#include <bluetooth.h>
#include <wifi.h>
+#include <tzplatform_config.h>
+#include <sys/types.h>
+#include <fcntl.h>
#include "debug_util.h"
#include "geofence_server.h"
#include "geofence_server_db.h"
#include "geofence_server_private.h"
-#define GEOFENCE_SERVER_DB_FILE ".geofence-server.db"
-#define GEOFENCE_SERVER_DB_PATH "/opt/dbspace/"GEOFENCE_SERVER_DB_FILE
+/* dbspace path for Tizen 3.0 was changed.
+#define GEOFENCE_SERVER_DB_FILE ".geofence-server.db"
+#define GEOFENCE_SERVER_DB_PATH "/opt/dbspace/"GEOFENCE_SERVER_DB_FILE
+*/
+
+#define GEOFENCE_DB_NAME ".geofence-server.db"
+#define GEOFENCE_DB_FILE tzplatform_mkpath(TZ_USER_DB, GEOFENCE_DB_NAME)
#define MAX_DATA_NAME 20
#define DATA_LEN 20
return FENCE_ERR_NONE;
}
-static int __geofence_manager_open_db_handle(void)
+static int __geofence_manager_open_db_handle(const int open_flag)
{
LOGI_GEOFENCE("enter");
int ret = SQLITE_OK;
- ret = db_util_open_with_options(GEOFENCE_SERVER_DB_PATH, &db_info_s.handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX, NULL);
+ ret = db_util_open_with_options(GEOFENCE_DB_FILE, &db_info_s.handle, open_flag, NULL);
if (ret != SQLITE_OK) {
LOGI_GEOFENCE("sqlite3_open_v2 Error[%d] : %s", ret, sqlite3_errmsg(db_info_s.handle));
return FENCE_ERR_SQLITE_FAIL;
int ret;
begin_transaction();
+ ret = __geofence_manager_db_create_places_table();
+ if (ret < 0) {
+ rollback_transaction();
+ return;
+ }
+
ret = __geofence_manager_db_create_geofence_table();
if (ret < 0) {
rollback_transaction();
LOGD_GEOFENCE("result : %s", result);
}
+
+static int __check_db_file()
+{
+ int fd = -1;
+
+ fd = open(GEOFENCE_DB_FILE, O_RDONLY);
+ if (fd < 0) {
+ LOGW_GEOFENCE("DB file(%s) is not exist.", GEOFENCE_DB_FILE);
+ return -1;
+ }
+ close(fd);
+ return 0;
+}
+
/**
* This function in DB and create GeoFence/FenceGeocoordinate /FenceCurrentLocation four table on DB if necessary.
*
{
FUNC_ENTRANCE_SERVER;
struct stat stat;
+ int open_flag = 0;
- if (__geofence_manager_open_db_handle() != FENCE_ERR_NONE) {
- LOGI_GEOFENCE("Fail to location_geofence_open_db_handle");
- return FENCE_ERR_SQLITE_FAIL;
- }
+ /*
+ geofence_db_file = g_strdup_printf("%s/%s", GEOFENCE_DB_PATH, GEOFENCE_DB_FILE);
+ */
- if (lstat(GEOFENCE_SERVER_DB_PATH, &stat) < 0) {
- LOGI_GEOFENCE("lstat is ERROR!!!");
- db_util_close(db_info_s.handle);
- db_info_s.handle = NULL;
- return FENCE_ERR_SQLITE_FAIL;
+ if (__check_db_file()) {
+ LOGW_GEOFENCE("db(%s) file doesn't exist.", GEOFENCE_DB_FILE);
+ open_flag = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE| SQLITE_OPEN_FULLMUTEX;
+ }
+ else {
+ if (lstat(GEOFENCE_DB_FILE, &stat) < 0) {
+ LOGE_GEOFENCE("Can't get db(%s) information.", GEOFENCE_DB_FILE);
+ return FENCE_ERR_SQLITE_FAIL;
+ }
+ open_flag = SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX;
}
- if (!S_ISREG(stat.st_mode)) {
- LOGI_GEOFENCE("Invalid file");
- db_util_close(db_info_s.handle);
- db_info_s.handle = NULL;
+ if (__geofence_manager_open_db_handle(open_flag) != FENCE_ERR_NONE) {
+ LOGI_GEOFENCE("Fail to create db file(%s).", GEOFENCE_DB_FILE);
return FENCE_ERR_SQLITE_FAIL;
}
[Unit]
Description=Geofence server daemon
-After=tizen-runtime.target
-Requires=tizen-runtime.target
+Requires=geofence-server.service
[Service]
-#Type=forking
-#ExecStart=/etc/rc.d/rc5.d/S91geofence-server
+EnvironmentFile=/run/tizen-system-env
+Type=single
ExecStart=/usr/bin/geofence-server
MemoryLimit=10M
-User=system
-Group=system
-#SmackProcessLabel=location_fw
-
-[Install]
-WantedBy=multi-user.target
+Restart=always
+RestartSec=1
Name: geofence-server
Summary: Geofence Server for Tizen
-Version: 0.4.0
+Version: 0.4.1
Release: 1
Group: Location/Service
License: Apache-2.0
#BuildRequires: pkgconfig(capi-telephony-network-info)
#BuildRequires: pkgconfig(capi-context-manager)
BuildRequires: pkgconfig(capi-geofence-manager)
+BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: capi-geofence-manager-plugin-devel
Requires: sys-assert
rm -rf %{buildroot}
%make_install
+#[Workaround] create service file for systemd
+mkdir -p %{buildroot}%{_unitdir_user}/default.target.wants
+install -m 644 %{SOURCE1} %{buildroot}%{_unitdir_user}/geofence-server.service
+ln -s ../geofence-server.service %{buildroot}%{_unitdir_user}/default.target.wants/geofence-server.service
+
+%if 0
if [ ! -e "$GEOFENCE_SERVER_DB_PATH" ]
then
CREATE TABLE FenceGeopointWifi ( fence_id INTEGER, bssid TEXT, ssid TEXT, FOREIGN KEY(fence_id) REFERENCES GeoFence(fence_id) ON DELETE CASCADE);
CREATE TABLE FenceBssid ( fence_id INTEGER, bssid TEXT, ssid TEXT, FOREIGN KEY(fence_id) REFERENCES Geofence(fence_id) ON DELETE CASCADE);'
fi
+%endif
%clean
rm -rf %{buildroot}
%post
+
+%if 0
GEOFENCE_SERVER_DB_PATH="/opt/dbspace/.geofence-server.db"
# geofence-server db file
chown system:system /opt/dbspace/.geofence-server.db
chown system:system /opt/dbspace/.geofence-server.db-journal
-## Change geofence-server db file permissions
+# Change geofence-server db file permissions
chmod 660 /opt/dbspace/.geofence-server.db
chmod 660 /opt/dbspace/.geofence-server.db-journal
+%endif
%postun -p /sbin/ldconfig
%files
%manifest geofence-server.manifest
-%defattr(-,system,system,-)
+%defattr(-,root,root,-)
/usr/bin/geofence-server
-/usr/share/dbus-1/system-services/org.tizen.lbs.Providers.GeofenceServer.service
-/opt/dbspace/.*.db*
-%config %{_sysconfdir}/dbus-1/system.d/geofence-server.conf
+
+/usr/share/dbus-1/services/org.tizen.lbs.Providers.GeofenceServer.service
+#/opt/dbspace/.*.db*
+%config %{_sysconfdir}/dbus-1/session.d/geofence-server.conf
+
+#[Workaround] create service file for systemd
+%{_unitdir_user}/geofence-server.service
+%{_unitdir_user}/default.target.wants/geofence-server.service
+
%package -n location-geofence-server
Summary: Geofence Server for Tizen