From: Mu-Woong Date: Mon, 17 Aug 2015 13:13:59 +0000 (+0900) Subject: Switch to user-session daemon X-Git-Tag: submit/tizen_mobile/20150818.030430~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f02b971c2821e8811950ad08e6976d67bf1eb6ca;p=platform%2Fcore%2Fcontext%2Fcontext-service.git Switch to user-session daemon Change-Id: Iccc348aa4384817cbf76304587e9b7446c54ddb3 Signed-off-by: Mu-Woong --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 6028a35..65c48c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ MESSAGE("Sources: ${SRCS}") # Dependencies SET(DEPS + libtzplatform-config vconf libxml-2.0 sqlite3 diff --git a/data/template-json-to-sql.sh b/data/template-json-to-sql.sh deleted file mode 100644 index c5dba2c..0000000 --- a/data/template-json-to-sql.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -function print_sql { - echo "UPDATE context_trigger_template SET j_template='{$2 }' WHERE name='$1';" - echo "INSERT OR IGNORE INTO context_trigger_template (name, j_template) VALUES ('$1', '{$2 }');" -} - -echo "CREATE TABLE IF NOT EXISTS context_trigger_template (" -echo " name TEXT DEFAULT '' NOT NULL PRIMARY KEY," -echo " j_template TEXT DEFAULT '' NOT NULL);" - -template_json_file="$1" - -while read -r line -do - keyword=`echo $line | awk '{print $1}' | tr -cd '[:alpha:]'` - - if [[ $keyword = "name" ]]; then - - if [ -n "$template" ]; then - print_sql "$name" "$template" - template="" - fi - - name=`echo $line | tr -d '":,' | awk '{print $2}'` - fi - - if [[ $keyword = "name" ]] || [[ $keyword = "attributes" ]] || [[ $keyword = "option" ]]; then - template="$template $line" - fi - -done < "$template_json_file" - -print_sql "$name" "$template" diff --git a/data/trigger-template.json b/data/trigger-template.json deleted file mode 100644 index e515ecb..0000000 --- a/data/trigger-template.json +++ /dev/null @@ -1,93 +0,0 @@ -{ - "templates": [ - { - "name": "time/alarm", - "attributes": ["TimeOfDay", "DayOfWeek"] - }, - { - "name": "time/now", - "attributes": ["TimeOfDay", "DayOfWeek", "DayOfMonth"] - }, - { - "name": "system/battery", - "attributes": ["Level", "IsCharging"] - }, - { - "name": "system/charger", - "attributes": ["IsConnected"] - }, - { - "name": "system/gps", - "attributes": ["State"] - }, - { - "name": "system/headphone", - "attributes": ["IsConnected", "Type"] - }, - { - "name": "system/psmode", - "attributes": ["IsEnabled"] - }, - { - "name": "system/usb", - "attributes": ["IsConnected"] - }, - { - "name": "system/wifi", - "attributes": ["State", "BSSID"] - }, - { - "name": "social/call", - "attributes": ["Medium", "State", "Address"] - }, - { - "name": "social/email", - "attributes": ["Event"] - }, - { - "name": "social/message", - "attributes": ["Event", "Type", "Address"] - }, - { - "name": "activity/stationary", - "attributes": ["Event", "Accuracy"] - }, - { - "name": "activity/walking", - "attributes": ["Event", "Accuracy"] - }, - { - "name": "activity/running", - "attributes": ["Event", "Accuracy"] - }, - { - "name": "activity/in_vehicle", - "attributes": ["Event", "Accuracy"] - }, - { - "name": "place/geofence", - "attributes": ["Event"], - "option": ["PlaceId"] - }, - { - "name": "stats/app/frequency", - "attributes": ["Rank", "TotalCount"], - "option": ["AppId", "TimeOfDay", "DayOfWeek"] - }, - { - "name": "stats/contact/frequency", - "attributes": ["Rank", "TotalCount"], - "option": ["Address", "TimeOfDay", "DayOfWeek"] - }, - { - "name": "stats/music/frequency", - "attributes": ["TotalCount"], - "option": ["TimeOfDay", "DayOfWeek"] - }, - { - "name": "stats/video/frequency", - "attributes": ["TotalCount"], - "option": ["TimeOfDay", "DayOfWeek"] - } - ] -} diff --git a/packaging/context-service.service b/packaging/context-service.service index 5b5a845..ba392a5 100644 --- a/packaging/context-service.service +++ b/packaging/context-service.service @@ -3,12 +3,10 @@ Description=Contextual Service Framework Daemon [Service] Type=dbus -User=system -Group=system BusName=org.tizen.context ExecStart=/usr/bin/contextd Restart=always RestartSec=1 [Install] -WantedBy=graphical.target +WantedBy=default.target diff --git a/packaging/context-service.spec b/packaging/context-service.spec index 9d4bcb8..12721c3 100644 --- a/packaging/context-service.spec +++ b/packaging/context-service.spec @@ -13,6 +13,7 @@ Source2: org.tizen.context.conf BuildRequires: cmake BuildRequires: sed +BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(sqlite3) @@ -39,7 +40,6 @@ BuildRequires: pkgconfig(place-context-provider) Requires(preun): /usr/bin/systemctl Requires(post): sys-assert Requires(post): /usr/bin/systemctl -Requires(post): /usr/bin/sqlite3 Requires(postun): /usr/bin/systemctl %description @@ -72,48 +72,38 @@ make %{?jobs:-j%jobs} rm -rf %{buildroot} %make_install -mkdir -p %{buildroot}%{_unitdir} +mkdir -p %{buildroot}%{_unitdir_user} mkdir -p %{buildroot}%{_datadir}/license mkdir -p %{buildroot}%{_datadir}/packages -mkdir -p %{buildroot}/opt/dbspace mkdir -p %{buildroot}/opt/data/context-service -sqlite3 %{buildroot}/opt/dbspace/.context-service.db "PRAGMA journal_mode = PERSIST;" -sqlite3 %{buildroot}/opt/dbspace/.context-service.db "CREATE TABLE VERSION (VERSION TEXT);" -sqlite3 %{buildroot}/opt/dbspace/.context-service.db "INSERT INTO VERSION VALUES ('%{version}');" -install -m 0644 %{SOURCE1} %{buildroot}%{_unitdir} +install -m 0644 %{SOURCE1} %{buildroot}%{_unitdir_user} cp LICENSE %{buildroot}%{_datadir}/license/%{name} #sed -i "s/^\tversion=\".*\"/\tversion=\"%{version}\"/g" packaging/context-service.xml #cp packaging/context-service.xml %{buildroot}%{_datadir}/packages/ -cp data/trigger-template.json %{buildroot}/opt/data/context-service/ -sh data/template-json-to-sql.sh data/trigger-template.json > %{buildroot}/opt/data/context-service/trigger-template.sql -mkdir -p %{buildroot}%{_sysconfdir}/dbus-1/system.d -install -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/dbus-1/system.d/ +mkdir -p %{buildroot}%{_sysconfdir}/dbus-1/session.d +install -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/dbus-1/session.d/ %post -sqlite3 -echo /opt/dbspace/.context-service.db < /opt/data/context-service/trigger-template.sql -mkdir -p %{_unitdir}/graphical.target.wants -ln -s ../context-service.service %{_unitdir}/graphical.target.wants/ +mkdir -p %{_unitdir_user}/default.target.wants +ln -s ../context-service.service %{_unitdir_user}/default.target.wants/ /sbin/ldconfig -systemctl daemon-reload +#systemctl daemon-reload %preun -if [ $1 == 0 ]; then - systemctl stop context-service -fi +#if [ $1 == 0 ]; then +# systemctl stop context-service +#fi %postun -rm -f %{_unitdir}/graphical.target.wants/context-service.service -systemctl daemon-reload +rm -f %{_unitdir_user}/default.target.wants/context-service.service +#systemctl daemon-reload /sbin/ldconfig %files %manifest packaging/%{name}.manifest -%config %{_sysconfdir}/dbus-1/system.d/* +%config %{_sysconfdir}/dbus-1/session.d/* %{_bindir}/* -%{_unitdir}/context-service.service +%{_unitdir_user}/context-service.service %{_datadir}/license/%{name} #%{_datadir}/packages/*.xml -%defattr(0600,system,system,-) -/opt/data/context-service/* -%config(noreplace) /opt/dbspace/.context-service.db* diff --git a/packaging/org.tizen.context.conf b/packaging/org.tizen.context.conf index be59b20..2455458 100644 --- a/packaging/org.tizen.context.conf +++ b/packaging/org.tizen.context.conf @@ -1,7 +1,7 @@ - + diff --git a/src/db_mgr_impl.cpp b/src/db_mgr_impl.cpp index a75f292..a271049 100644 --- a/src/db_mgr_impl.cpp +++ b/src/db_mgr_impl.cpp @@ -19,12 +19,12 @@ #include #include #include +#include #include #include "server.h" #include "db_mgr_impl.h" -//TODO: conf file for this kind of env. params. -#define CONTEXT_DB_PATH "/opt/dbspace/.context-service.db" +#define CONTEXT_DB_PATH tzplatform_mkpath(TZ_USER_DB, ".context-service.db") static bool initialized = false; static GThread *mainthread = NULL; @@ -71,7 +71,7 @@ bool ctx::db_manager_impl::open() sqlite3 *db = NULL; int r = sqlite3_open(CONTEXT_DB_PATH, &db); - IF_FAIL_RETURN_TAG(r == SQLITE_OK, false, _E, "DB Error: %s", sqlite3_errmsg(db)); + IF_FAIL_RETURN_TAG(r == SQLITE_OK, false, _E, "Path: %s / Error: %s", CONTEXT_DB_PATH, sqlite3_errmsg(db)); db_handle = db; return true; diff --git a/src/dbus_server_impl.cpp b/src/dbus_server_impl.cpp index aeee103..dec5335 100644 --- a/src/dbus_server_impl.cpp +++ b/src/dbus_server_impl.cpp @@ -173,7 +173,7 @@ bool ctx::dbus_server_impl::init() dbus_node_info = g_dbus_node_info_new_for_xml(introspection_xml, NULL); IF_FAIL_RETURN_TAG(dbus_node_info != NULL, false, _E, "Initialization failed"); - dbus_owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, DBUS_DEST, G_BUS_NAME_OWNER_FLAGS_NONE, + dbus_owner_id = g_bus_own_name(G_BUS_TYPE_SESSION, DBUS_DEST, G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL); _instance = this;