From 884a24d5641a53aa1e4bb23d56bb0675fb4bc58f Mon Sep 17 00:00:00 2001 From: "jk7744.park" Date: Sun, 1 Feb 2015 13:54:56 +0900 Subject: [PATCH] tizen 2.3 release --- .gitignore | 38 +++ CMakeLists.txt | 36 +-- README | 6 + debian/changelog | 39 ---- debian/compat | 1 - debian/control | 20 -- debian/copyright | 6 - debian/dirs | 2 - debian/docs | 0 debian/rules | 117 ---------- debian/telephony-daemon.install.in | 2 - debian/telephony-daemon.postinst | 5 - packaging/telephony-daemon.service | 14 ++ packaging/telephony-daemon.spec | 47 ++-- src/main.c | 465 ++++++++++++++++++++++++------------- src/monitor.c | 156 +++++++++---- src/monitor.h | 8 +- systemd/telephony.service | 10 - telephony-daemon.manifest | 108 ++++++++- 19 files changed, 630 insertions(+), 450 deletions(-) create mode 100644 .gitignore create mode 100644 README delete mode 100644 debian/changelog delete mode 100644 debian/compat delete mode 100644 debian/control delete mode 100644 debian/copyright delete mode 100644 debian/dirs delete mode 100644 debian/docs delete mode 100755 debian/rules delete mode 100644 debian/telephony-daemon.install.in delete mode 100755 debian/telephony-daemon.postinst create mode 100644 packaging/telephony-daemon.service delete mode 100644 systemd/telephony.service mode change 100644 => 100755 telephony-daemon.manifest diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..41d4a92 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +.* +!.gitignore +*~ + +*~ +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +.elc +auto-save-list +tramp +.\#* + +# Org-mode +.org-id-locations +*_archive + +# Object files +*.o + +# Libraries +*.lib +*.a + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app + +# Patches +*.patch +*.diff diff --git a/CMakeLists.txt b/CMakeLists.txt index 4098ad7..f3268c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ SET(INCLUDEDIR "\${prefix}/include") # Set required packages INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED glib-2.0 gobject-2.0 tcore dlog libsystemd-daemon) +pkg_check_modules(pkgs REQUIRED glib-2.0 vconf tcore dlog) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") @@ -16,29 +16,39 @@ ENDFOREACH(flag) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Werror -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wcast-align") +SET(ADDITIONAL_CFLAGS "-Wno-array-bounds -Wno-empty-body -Wno-ignored-qualifiers -Wshadow -Wwrite-strings -Wswitch-default -Wno-unused-but-set-parameter -Wno-unused-but-set-variable") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Werror -Wextra -Wall -Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wcast-align -Wcast-qual") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ADDITIONAL_CFLAGS}") ADD_DEFINITIONS("-DFEATURE_TLOG_DEBUG") -ADD_DEFINITIONS("-DTCORE_LOG_TAG=\"TELEPHONY_DAEMON\"") +ADD_DEFINITIONS("-DTCORE_LOG_TAG=\"DAEMON\"") ADD_DEFINITIONS("-DDAEMON_VERSION=\"${VERSION}\"") +ADD_DEFINITIONS("-DDEFAULT_PLUGINS_PATH=\"/usr/lib/telephony/plugins/\"") + +IF (TIZEN_DEBUG_ENABLE) + ADD_DEFINITIONS ("-DTIZEN_DEBUG_ENABLE") +ENDIF (TIZEN_DEBUG_ENABLE) + MESSAGE(${CMAKE_C_FLAGS}) MESSAGE(${pkgs_LDFLAGS}) +IF (TIZEN_DEBUG_ENABLE) SET(SRCS - src/main.c - src/monitor.c + src/main.c + src/monitor.c ) - +ELSE (TIZEN_DEBUG_ENABLE) +SET(SRCS + src/main.c +) +ENDIF (TIZEN_DEBUG_ENABLE) # binary build -ADD_EXECUTABLE(telephony-daemon ${SRCS}) -TARGET_LINK_LIBRARIES(telephony-daemon ${pkgs_LDFLAGS} "-ldl") - +ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-ldl") # install -INSTALL(TARGETS telephony-daemon - RUNTIME DESTINATION bin) - +INSTALL(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION /usr/share/license RENAME telephony-daemon) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/telephony.service DESTINATION /usr/lib/systemd/system) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/packaging/telephony-daemon.service DESTINATION /usr/lib/systemd/system) diff --git a/README b/README new file mode 100644 index 0000000..3b9b6d8 --- /dev/null +++ b/README @@ -0,0 +1,6 @@ +## Restart Telephony Daemon +systemctl restart telephony-daemon.service + +## Stop Telephony Daemon +systemctl stop telephony-daemon.service + diff --git a/debian/changelog b/debian/changelog deleted file mode 100644 index 2c7856a..0000000 --- a/debian/changelog +++ /dev/null @@ -1,39 +0,0 @@ -telephony-daemon (0.1.4) unstable; urgency=low - - * version up for code sync with public binary - * Git: slp/pkgs/t/telephony-daemon - * Tag: telephony-daemon_0.1.4 - - -- Kyeongchul Kim Mon, 02 Apr 2012 14:27:25 +0900 - -telephony-daemon (0.1.3) unstable; urgency=low - - * Fix prefix (TAPI_ to TCORE_) - * Git: slp/pkgs/t/telephony-daemon - * Tag: telephony-daemon_0.1.3 - - -- Inho Oh Tue, 27 Mar 2012 22:25:04 +0900 - -telephony-daemon (0.1.2) unstable; urgency=low - - * Add debug feature (kill -USR1 ) - * Git: slp/pkgs/t/telephony-daemon - * Tag: telephony-daemon_0.1.2 - - -- Inho Oh Mon, 19 Mar 2012 21:08:42 +0900 - -telephony-daemon (0.1.1) unstable; urgency=low - - * Add autorun script (/etc/...) - * Git: slp/pkgs/t/telephony-daemon - * Tag: telephony-daemon_0.1.1 - - -- Inho Oh Fri, 16 Mar 2012 03:19:19 +0900 - -telephony-daemon (0.1.0) unstable; urgency=low - - * Initial - * Git: slp/pkgs/t/telephony-daemon - * Tag: telephony-daemon_0.1.0 - - -- Inho Oh Thu, 15 Mar 2012 23:40:55 +0900 diff --git a/debian/compat b/debian/compat deleted file mode 100644 index 7ed6ff8..0000000 --- a/debian/compat +++ /dev/null @@ -1 +0,0 @@ -5 diff --git a/debian/control b/debian/control deleted file mode 100644 index abef159..0000000 --- a/debian/control +++ /dev/null @@ -1,20 +0,0 @@ -Source: telephony-daemon -Section: libs -Priority: extra -Maintainer: Jongman Park -Uploaders: Jayoung Gu , Kyeongchul Kim , Youngman Park , Inho Oh , DongHoo Park -Build-Depends: debhelper (>= 5), libglib2.0-dev, libtcore-dev, dlog-dev -Standards-Version: 0.0.0 - -Package: telephony-daemon -Section: libs -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, -Description: telephony client API library (Shared Object) - -Package: telephony-daemon-dbg -Section: debug -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, telephony-daemon (= ${Source-Version}) -Description: telephony client API library (dbg package) - diff --git a/debian/copyright b/debian/copyright deleted file mode 100644 index efd61ff..0000000 --- a/debian/copyright +++ /dev/null @@ -1,6 +0,0 @@ -Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - -This program is free software; you can redistribute it and/or modify -it under the terms of the the Apache License, Version 2.0 (the "License"); -You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0. diff --git a/debian/dirs b/debian/dirs deleted file mode 100644 index ca882bb..0000000 --- a/debian/dirs +++ /dev/null @@ -1,2 +0,0 @@ -usr/bin -usr/sbin diff --git a/debian/docs b/debian/docs deleted file mode 100644 index e69de29..0000000 diff --git a/debian/rules b/debian/rules deleted file mode 100755 index 7b8a0c5..0000000 --- a/debian/rules +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/make -f -# -*- makefile -*- -# Sample debian/rules that uses debhelper. -# This file was originally written by Joey Hess and Craig Small. -# As a special exception, when this file is copied by dh-make into a -# dh-make output file, you may use that output file without restriction. -# This special exception was added by Craig Small in version 0.37 of dh-make. - -# Uncomment this to turn on verbose mode. -#export DH_VERBOSE=1 - -CFLAGS ?= -Wall -g -CXXFLAGS ?= -Wall -g -LDFLAGS ?= -PREFIX ?= /usr -DATADIR ?= /opt - -ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) - CFLAGS += -O0 - CXXFLAGS += -O0 -else - CFLAGS += -O2 - CXXFLAGS += -O2 -endif - -CFLAGS += -fvisibility=hidden -fPIC -LDFLAGS += -ldl -rdynamic -fPIC -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed -#LDFLAGS += -Wl,--unresolved-symbols=ignore-in-shared-libs,--as-needed - -CMAKE_TMP_DIR = $(CURDIR)/cmake_tmp - -configure: configure-stamp -configure-stamp: - dh_testdir - # Add here commands to configure the package. - mkdir -p $(CMAKE_TMP_DIR); - cd $(CMAKE_TMP_DIR); CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" cmake .. -DCMAKE_INSTALL_PREFIX=$(PREFIX) - - touch configure-stamp - -build: build-stamp - -build-stamp: configure-stamp - dh_testdir - - # Add here commands to compile the package. - cd $(CMAKE_TMP_DIR) && $(MAKE) all - - for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ - cat $$f > $${f%.in}; \ - sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \ - sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \ - done - - touch $@ - -clean: - dh_testdir - dh_testroot - rm -f build-stamp configure-stamp - - # Add here commands to clean up after the build process. - rm -rf $(CMAKE_TMP_DIR) - - for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ - rm -f $${f%.in}; \ - done - - dh_clean - -install: build - dh_testdir - dh_testroot - dh_clean -k - dh_installdirs - - # Add here commands to install the package into debian/wavplayer. - cd $(CMAKE_TMP_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install - - -# Build architecture-independent files here. -binary-indep: build install -# We have nothing to do by default. - -# Build architecture-dependent files here. -binary-arch: build install - dh_testdir - dh_testroot - dh_installchangelogs - dh_installdocs - dh_installexamples - dh_install --sourcedir=debian/tmp -# dh_installmenu -# dh_installdebconf -# dh_installlogrotate -# dh_installemacsen -# dh_installpam -# dh_installmime -# dh_python -# dh_installinit -# dh_installcron -# dh_installinfo - dh_installman - dh_link - dh_strip --dbg-package=telephony-daemon-dbg - dh_compress - dh_fixperms -# dh_perl - dh_makeshlibs - dh_installdeb - dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info - dh_gencontrol - dh_md5sums - dh_builddeb - -binary: binary-indep binary-arch -.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/debian/telephony-daemon.install.in b/debian/telephony-daemon.install.in deleted file mode 100644 index d9e1d81..0000000 --- a/debian/telephony-daemon.install.in +++ /dev/null @@ -1,2 +0,0 @@ -@PREFIX@/bin/* -etc/* diff --git a/debian/telephony-daemon.postinst b/debian/telephony-daemon.postinst deleted file mode 100755 index 219048b..0000000 --- a/debian/telephony-daemon.postinst +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -if [ ${USER} == "root" ] -then - chown root:root /etc/rc.d/init.d/telephony-daemon -fi diff --git a/packaging/telephony-daemon.service b/packaging/telephony-daemon.service new file mode 100644 index 0000000..24a81d1 --- /dev/null +++ b/packaging/telephony-daemon.service @@ -0,0 +1,14 @@ +[Unit] +Description=Telephony daemon +Requires=dbus.socket +After=factory-reset.service secure-storage.service dlog_logger.service shutdown.target + +[Service] +Type=simple +ExecStart=/usr/bin/telephony-daemon +Restart=always +RestartSec=0 +KillMode=none + +[Install] +WantedBy=multi-user.target diff --git a/packaging/telephony-daemon.spec b/packaging/telephony-daemon.spec index 4d81ab4..0bb74ec 100644 --- a/packaging/telephony-daemon.spec +++ b/packaging/telephony-daemon.spec @@ -1,40 +1,45 @@ -Name: telephony-daemon -Summary: Telephony daemon -Version: 0.1.13 -Release: 2 -Group: System/Telephony -License: Apache-2.0 -Source0: %{name}-%{version}.tar.gz +%define major 1 +%define minor 3 +%define patchlevel 18 + +Name: telephony-daemon +Version: %{major}.%{minor}.%{patchlevel} +Release: 2 +License: Apache +Summary: Telephony Daemon +Group: System/Telephony +Source0: %{name}-%{version}.tar.gz BuildRequires: cmake +BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(gobject-2.0) BuildRequires: pkgconfig(tcore) -BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(libsystemd-daemon) +BuildRequires: pkgconfig(vconf) Requires(post): sys-assert -%{?systemd_requires} %description -Description: Telephony daemon +Description: Telephony Daemon %prep %setup -q %build -%cmake . -DVERSION=%{version} -make %{?jobs:-j%jobs} +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DVERSION=%{version} \ + -DTIZEN_DEBUG_ENABLE=1 \ + +make %{?_smp_mflags} %install + %make_install -mkdir -p %{buildroot}%{_prefix}/lib/systemd/system/multi-user.target.wants -ln -s ../telephony.service %{buildroot}%{_prefix}/lib/systemd/system/multi-user.target.wants/telephony.service -mkdir -p %{buildroot}/usr/share/license -cp LICENSE %{buildroot}/usr/share/license/%{name} +mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants +ln -s %{_libdir}/systemd/system/telephony-daemon.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/telephony-daemon.service + +%post -p /sbin/ldconfig %files %manifest telephony-daemon.manifest %defattr(-,root,root,-) %{_bindir}/telephony-daemon -%{_prefix}/lib/systemd/system/telephony.service -%{_prefix}/lib/systemd/system/multi-user.target.wants/telephony.service -/usr/share/license/%{name} +%attr(644,root,root) %{_libdir}/systemd/system/telephony-daemon.service +%attr(644,root,root) %{_libdir}/systemd/system/multi-user.target.wants/telephony-daemon.service +%{_datadir}/license/telephony-daemon diff --git a/src/main.c b/src/main.c index efd2959..0bf2e76 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,7 @@ /* * telephony-daemon * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved. * * Contact: Ja-young Gu * @@ -18,83 +18,255 @@ * limitations under the License. */ -#include +#ifdef TIZEN_DEBUG_ENABLE +#include "monitor.h" +#endif + +#include #include #include -#include -#include -#include -#include + #include #include -#include #include #include #include -#include #include +#include #include #include #include -#include -#include - -#include "monitor.h" #ifndef DAEMON_VERSION #define DAEMON_VERSION "unknown" #endif -static Server *_server; +#ifndef DEFAULT_PLUGINS_PATH +#define DEFAULT_PLUGINS_PATH "/usr/lib/telephony/plugins/" +#endif + +#define NOTUSED(var) (var = var) + +/* Internal vconf to maintain telephony load info (Number of times telephony daemon is loaded) */ +#define VCONFKEY_TELEPHONY_DAEMON_LOAD_COUNT "memory/private/telephony/daemon_load_count" + +static Server *_server = NULL; + +static void __usage_info(const char *exec) +{ + printf("Usage: %s [OPTION]... [PLUGIN_PATH]\n", exec); + printf("\n"); + printf(" -T, --testload\t run with plugin load test mode and exit\n"); + printf(" -h, --help\t\t display this help and exit\n"); + printf("\n"); +} void tcore_log(enum tcore_log_type type, enum tcore_log_priority priority, const char *tag, const char *fmt, ...) { va_list ap; char buf[1024]; - va_start(ap, fmt); - vsnprintf(buf, 1023, fmt, ap); - va_end(ap); + switch (type) { + case TCORE_LOG_TYPE_RADIO: { + if (priority >= TCORE_LOG_INFO) { + va_start(ap, fmt); + vsnprintf(buf, 1023, fmt, ap); + va_end(ap); + __dlog_print(LOG_ID_RADIO, priority, tag, buf); + } else { + #ifdef TIZEN_DEBUG_ENABLE + va_start(ap, fmt); + vsnprintf(buf, 1023, fmt, ap); + va_end(ap); + __dlog_print(LOG_ID_RADIO, priority, tag, buf); + #endif + } + } break; + + case TCORE_LOG_TYPE_TIME_CHECK: { + #ifdef TIZEN_DEBUG_ENABLE /* User Mode should not log performance data */ + float a = 0.00, b = 0.00; + int next = 0; + FILE *fp = fopen("/proc/uptime", "r"); + g_return_if_fail(NULL != fp); + + if(fscanf(fp, "%f %f", &a, &b)){}; + fclose(fp); + next = sprintf(buf, "[UPTIME] %f ", a); + if (next < 0) + return; + + va_start(ap, fmt); + vsnprintf(buf + next, 1023 - next, fmt, ap); + va_end(ap); + __dlog_print(LOG_ID_RADIO, priority, tag, buf); + #endif + } break; + + default: + break; + } +} + +static void glib_log(const gchar *log_domain, GLogLevelFlags log_level, + const gchar *msg, gpointer user_data) +{ + NOTUSED(log_domain); + NOTUSED(log_level); + NOTUSED(user_data); + + __dlog_print (LOG_ID_RADIO, DLOG_ERROR, "GLIB", msg); +} + +#ifdef TIZEN_DEBUG_ENABLE +static void telephony_signal_handler(int signo) +{ + if (!_server) + return; + + switch (signo) { + case SIGUSR1: { + monitor_server_state(_server); + } break; + + case SIGTERM: { + tcore_server_exit(_server); + } break; - __dlog_print(type, priority, tag, buf); + default: { + warn("*~*~*~* Unhandled Signal: [%d] *~*~*~*", signo); + } break; + } /* end switch */ + + return; +} +#endif + +static void __log_uptime() +{ + float a = 0.00, b = 0.00; + FILE *fp = fopen("/proc/uptime", "r"); + g_return_if_fail(NULL != fp); + info("scanned %d items", fscanf(fp, "%f %f", &a, &b)); + info("proc uptime = %f idletime = %f\n", a, b); + fclose(fp); +} + +static gboolean __init_plugin(TcorePlugin *plugin) +{ + const struct tcore_plugin_define_desc *desc = tcore_plugin_get_description(plugin); + + if (!desc || !desc->init) + return FALSE; + + if (!desc->init(plugin)) { /* TODO: Remove plugin from server */ + char *plugin_name = tcore_plugin_get_filename(plugin); + if (NULL != plugin_name) { + err("plugin(%s) init failed.", plugin_name); + free(plugin_name); + } + return FALSE; + } + + return TRUE; } -static gboolean load_plugins(Server *s, const char *path, int flag_test_load) +static gboolean init_plugins(Server *s) { - const gchar *file; - char *filename; - GDir *dir; - void *handle; - GSList *list; + GSList *list = tcore_server_ref_plugins(s); + + while (list != NULL) { + if (G_UNLIKELY(FALSE == __init_plugin(list->data))) { + list = g_slist_next(list); + continue; + } + list = g_slist_next(list); + } + + return TRUE; +} + +static void *__load_plugin(const gchar *filename, struct tcore_plugin_define_desc **desc_out) +{ + void *handle = NULL; + struct tcore_plugin_define_desc *desc = NULL; struct stat stat_buf; char file_date[27]; - TcorePlugin *p; - struct tcore_plugin_define_desc *desc; + handle = dlopen(filename, RTLD_LAZY); + if (G_UNLIKELY(NULL == handle)) { + err("fail to load '%s': %s", filename, dlerror()); + return NULL; + } + + desc = dlsym(handle, "plugin_define_desc"); + if (G_UNLIKELY(NULL == desc)) { + err("fail to load symbol: %s", dlerror()); + dlclose(handle); + return NULL; + } + + dbg("%s plugin", desc->name); + dbg(" - path = %s", filename); + dbg(" - version = %d", desc->version); + dbg(" - priority = %d", desc->priority); + + memset(&stat_buf, 0x00, sizeof(stat_buf)); + memset(&file_date, '\0', sizeof(file_date)); + + if (0 == stat(filename, &stat_buf)) { + if (NULL != ctime_r(&stat_buf.st_mtime, file_date)) { + if (1 < strlen(file_date)) + file_date[strlen(file_date)-1] = '\0'; + dbg(" - date = %s", file_date); + } + } + + if (G_LIKELY(desc->load)) { + if (G_UNLIKELY(FALSE == desc->load())) { + warn("false return from load(). skip this plugin"); + dlclose(handle); + return NULL; + } + } + + if (NULL != desc_out) + *desc_out = desc; + + return handle; +} + +static gboolean load_plugins(Server *s, const char *path, gboolean flag_test_load) +{ + const gchar *file = NULL; + gchar *filename = NULL; + GDir *dir = NULL; + void *handle = NULL; + struct tcore_plugin_define_desc *desc = NULL; - if ((path == NULL) || (s == NULL)) + if (!path || !s) return FALSE; dir = g_dir_open(path, 0, NULL); - if (dir == NULL) + if (!dir) return FALSE; while ((file = g_dir_read_name(dir)) != NULL) { if (g_str_has_prefix(file, "lib") == TRUE - || g_str_has_suffix(file, ".so") == FALSE) + || g_str_has_suffix(file, ".so") == FALSE) continue; filename = g_build_filename(path, file, NULL); - handle = dlopen(filename, RTLD_NOW); - if (handle == NULL) { - dbg("fail to load '%s': %s", filename, dlerror()); + /* Load a plugin */ + if (G_UNLIKELY((handle = __load_plugin(filename, &desc)) == NULL)) { g_free(filename); continue; } + /* Don't add to server if flag_test_load */ if (flag_test_load) { dbg("success to load '%s'", filename); dlclose(handle); @@ -102,148 +274,97 @@ static gboolean load_plugins(Server *s, const char *path, int flag_test_load) continue; } - desc = dlsym(handle, "plugin_define_desc"); - if (desc == NULL) { - dbg("fail to load symbol: %s", dlerror()); - dlclose(handle); - g_free(filename); - continue; - } - - dbg("%s plugin", desc->name); - dbg(" - path = %s", filename); - dbg(" - version = %d", desc->version); - dbg(" - priority = %d", desc->priority); - - memset(&stat_buf, 0, sizeof(struct stat)); - if (stat(filename, &stat_buf) == 0) { - if (ctime_r(&stat_buf.st_mtime, file_date) != NULL) { - if (strlen(file_date) > 1) - file_date[strlen(file_date)-1] = '\0'; - - dbg(" - date = %s", file_date); - } - } - - if (desc->load) { - if (desc->load() == FALSE) { - dbg("false return from load(). skip this plugin"); - dlclose(handle); - g_free(filename); - continue; - } - } - - p = tcore_plugin_new(s, desc, filename, handle); - tcore_server_add_plugin(s, p); + tcore_server_add_plugin(s, tcore_plugin_new(s, desc, filename, handle)); dbg("%s added", desc->name); g_free(filename); } g_dir_close(dir); - info("plugin load finished"); - - list = tcore_server_ref_plugins(s); - for (; list; list = list->next) { - p = list->data; - if (p == NULL) - continue; - - desc = (struct tcore_plugin_define_desc *)tcore_plugin_get_description(p); - if (desc == NULL) - continue; - - if (desc->init == NULL) - continue; - - if (desc->init(p) == FALSE) { - dbg("plugin(%s) init failed.", tcore_plugin_get_filename(p)); - } - } - - info("plugin init finished"); - return TRUE; } -static void usage(const char *name) -{ - printf("Usage: %s [OPTION]... [PLUGIN_PATH]\n", name); - printf("\n"); - printf(" -T, --testload\t run with plugin load test mode and exit\n"); - printf(" -h, --help\t\t display this help and exit\n"); - printf("\n"); -} - -static void on_signal_usr1(int signo) -{ - if (_server == NULL) - return; - - monitor_server_state(_server); -} - int main(int argc, char *argv[]) { - struct sigaction sigact_usr1; - Server *s; - int flag_test_load = 0; - int opt; - int opt_index; +#ifdef TIZEN_DEBUG_ENABLE + struct sigaction sigact; +#endif + Server *s = NULL; + gboolean flag_test_load = FALSE; + int opt = 0, opt_index = 0, ret_code = EXIT_SUCCESS; + int daemon_load_count = 0; struct option options[] = { - { "help", 0, 0, 0 }, - { "testload", 0, &flag_test_load, 1 }, - { 0, 0, 0, 0 } + { "help", 0, 0, 0 }, + { "testload", 0, &flag_test_load, 1 }, + { 0, 0, 0, 0 } }; - char *plugin_path = "/usr/lib/telephony/plugins/"; - char *tcore_ver; - struct sysinfo info; + const char *plugin_path = DEFAULT_PLUGINS_PATH; + char *tcore_ver = NULL; + struct sysinfo sys_info; - if (sysinfo(&info) == 0) { - info("uptime: %ld secs", info.uptime); - } + TIME_CHECK("Starting Telephony"); - info("daemon version: %s", DAEMON_VERSION); + /* System Uptime */ + if (0 == sysinfo(&sys_info)) + info("uptime: %ld secs", sys_info.uptime); + __log_uptime(); + /* Version Info */ tcore_ver = tcore_util_get_version(); + info("daemon version: %s", DAEMON_VERSION); info("libtcore version: %s", tcore_ver); free(tcore_ver); - - sigact_usr1.sa_handler = on_signal_usr1; - sigemptyset(&sigact_usr1.sa_mask); - sigaddset(&sigact_usr1.sa_mask, SIGUSR1); - sigact_usr1.sa_flags = 0; - - if (sigaction(SIGUSR1, &sigact_usr1, NULL) < 0) { + info("glib version: %u.%u.%u", glib_major_version, glib_minor_version, glib_micro_version); + + /* Telephony reset handling*/ + vconf_get_int(VCONFKEY_TELEPHONY_DAEMON_LOAD_COUNT,&daemon_load_count); + daemon_load_count++; + vconf_set_int(VCONFKEY_TELEPHONY_DAEMON_LOAD_COUNT,daemon_load_count); + dbg("daemon load count = [%d]", daemon_load_count); + +#ifdef TIZEN_DEBUG_ENABLE + /* Signal Registration */ + sigact.sa_handler = telephony_signal_handler; + sigemptyset(&sigact.sa_mask); + sigact.sa_flags = 0; + if (sigaction(SIGTERM, &sigact, NULL) < 0) + warn("sigaction(SIGTERM) failed."); + if (sigaction(SIGUSR1, &sigact, NULL) < 0) warn("sigaction(SIGUSR1) failed."); - } +#endif - while (1) { + /* Commandline option parser TODO: Replace with GOptionContext */ + while (TRUE) { opt = getopt_long(argc, argv, "hT", options, &opt_index); - if (opt == -1) + if (-1 == opt) break; switch (opt) { - case 0: - switch (opt_index) { - case 0: // help - usage(argv[0]); - return 0; - break; - } - break; - - case 'h': - usage(argv[0]); + case 0: { + switch (opt_index) { + case 0: { + __usage_info(argv[0]); return 0; - break; - - case 'T': - flag_test_load = 1; - break; - } + } break; + default: { + warn("unhandled opt_index."); + } break; + } /* end switch */ + } break; + + case 'h': { + __usage_info(argv[0]); + return 0; + } break; + + case 'T': { + flag_test_load = TRUE; + } break; + default: { + warn("unhandled opt case."); + } break; + } /* end switch */ } if (optind < argc) @@ -251,43 +372,53 @@ int main(int argc, char *argv[]) info("plugin_path: [%s]", plugin_path); -#if !GLIB_CHECK_VERSION(2,35,0) +#if !GLIB_CHECK_VERSION(2, 35, 0) g_type_init(); #endif -#if !GLIB_CHECK_VERSION (2, 31, 0) +#if !GLIB_CHECK_VERSION(2, 31, 0) g_thread_init(NULL); #endif s = tcore_server_new(); - if (s == NULL) { + if (G_UNLIKELY(NULL == s)) { err("server_new failed."); - goto end; + ret_code = EXIT_FAILURE; + goto END; } _server = s; - if (load_plugins(s, plugin_path, flag_test_load) == FALSE) - goto free_end; + g_log_set_default_handler(glib_log, s); - if (flag_test_load) - goto free_end; + /* Load Plugins */ + if (G_UNLIKELY(FALSE == load_plugins(s, (const char *)plugin_path, flag_test_load))) { + err("load_plugins failed."); + ret_code = EXIT_FAILURE; + goto END; + } - info("server mainloop start"); + TIME_CHECK("Loading Plugins Complete"); - /* Notification to systemd */ - sd_notify(0, "READY=1"); + if (flag_test_load) { + ret_code = EXIT_SUCCESS; + goto END; + } - if (tcore_server_run(s) == FALSE) { - err("server_run failed."); + /* Initialize Plugins */ + if (G_UNLIKELY(FALSE == init_plugins(s))) { + err("init_plugins failed."); + ret_code = EXIT_FAILURE; + goto END; } - /* - * RUNNING - */ + info("server mainloop start"); + TIME_CHECK("Initializing Plugins Complete. Starting Daemon"); -free_end: - info("server end"); - tcore_server_free(s); + if (G_UNLIKELY(TCORE_RETURN_SUCCESS != tcore_server_run(s))) { + err("server_run failed."); + ret_code = EXIT_FAILURE; + } -end: - return EXIT_SUCCESS; +END: + tcore_server_free(s); _server = NULL; + return ret_code; } diff --git a/src/monitor.c b/src/monitor.c index c0bf9da..b65defd 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -1,7 +1,7 @@ /* * telephony-daemon * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved. * * Contact: Ja-young Gu * @@ -18,45 +18,69 @@ * limitations under the License. */ -#include -#include -#include -#include -#include -#include -#include -#include +#include "monitor.h" +#include #include -#include -#include -#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include +#include +#include -#include "monitor.h" +#define NOTUSED(var) (var = var) -/* Hacking TcoreQueue */ +/* hacking TcoreQueue */ struct tcore_queue_type { TcorePlugin *plugin; GQueue *gq; }; +static void _hash_dump(gpointer key, gpointer value, gpointer user_data) +{ + NOTUSED(user_data); + + msg(" - %s: [%s]", key, value); +} + +static void _monitor_core_objects(GSList *list) +{ + CoreObject *co; + GHashTable *prop; + + do { + co = list->data; + + msg(" Name: [%s]", tcore_object_ref_name(co)); + msg(" - addr: %p", co); + msg(" - type: %p", tcore_object_get_type(co)); + msg(" - hal: %p", tcore_object_get_hal(co)); + + prop = tcore_object_ref_property_hash(co); + if (prop) { + msg(" - Properties: %d", g_hash_table_size(prop)); + g_hash_table_foreach(prop, _hash_dump, NULL); + } + + list = list->next; + } while(list); +} + static void _monitor_plugin(Server *s) { GSList *list; + GSList *co_list; TcorePlugin *p; char *str; msg("-- Plugins --"); list = tcore_server_ref_plugins(s); - if (list == NULL) + if (!list) return; do { @@ -65,17 +89,26 @@ static void _monitor_plugin(Server *s) msg("Name: [%s]", tcore_plugin_get_description(p)->name); str = tcore_plugin_get_filename(p); - msg(" - file: %s", str); - if (str) + if (str) { + msg(" - file: %s", str); free(str); + } msg(" - addr: %p", p); msg(" - userdata: %p", tcore_plugin_ref_user_data(p)); - msg(""); + co_list = tcore_plugin_get_core_objects(p); + if (co_list) { + msg(" - core_object list: %d", g_slist_length(co_list)); + + _monitor_core_objects(co_list); + g_slist_free(co_list); + } + + msg(""); list = list->next; - } while (list); + } while(list); } static void _monitor_storage(Server *s) @@ -86,7 +119,7 @@ static void _monitor_storage(Server *s) msg("-- Storages --"); list = tcore_server_ref_storages(s); - if (list == NULL) + if (!list) return; do { @@ -97,7 +130,7 @@ static void _monitor_storage(Server *s) msg(""); list = list->next; - } while (list); + } while(list); } static void _monitor_communicator(Server *s) @@ -105,10 +138,10 @@ static void _monitor_communicator(Server *s) GSList *list; Communicator *comm; - msg("-- Communicators --"); + msg("-- Coomunicators --"); list = tcore_server_ref_communicators(s); - if (list == NULL) + if (!list) return; do { @@ -121,27 +154,72 @@ static void _monitor_communicator(Server *s) msg(""); list = list->next; - } while (list); + } while(list); } -static void _monitor_modems(Server *s) +static void _monitor_hal(Server *s) { GSList *list; - TcorePlugin *p; + TcoreHal *h; + TcoreQueue *q; + TcorePending *pending; + UserRequest *ur; + char *str; + int qlen; + int i; + void *data; + unsigned int data_len; - msg("-- Modems --"); + msg("-- Hals --"); - list = tcore_server_ref_plugins(s); - if (list == NULL) + list = tcore_server_ref_hals(s); + if (!list) return; - for (; list != NULL; list = g_slist_next(list)) { - p = list->data; - if (p == NULL) + do { + h = list->data; + + str = tcore_hal_get_name(h); + if (str) { + msg("Name: [%s]", str); + free(str); + } + msg(" - addr: %p", h); + msg(" - parent_plugin: %p", tcore_hal_ref_plugin(h)); + msg(" - userdata: %p", tcore_hal_ref_user_data(h)); + + q = tcore_hal_ref_queue(h); + if (!q) { + msg(""); + list = list->next; continue; + } - tcore_server_print_modems(p); - } + if (!(q->gq)) { + msg(""); + list = list->next; + continue; + } + + qlen = tcore_queue_get_length(q); + msg(" - queue: %p, length: %d", q, qlen); + msg(" queue_head: %p", g_queue_peek_head(q->gq)); + for (i = 0; i < qlen; i++) { + pending = g_queue_peek_nth(q->gq, i); + ur = tcore_pending_ref_user_request(pending); + msg(" [%02d] pending=%p, id=0x%x, ur=%p", i, pending, tcore_pending_get_id(pending), ur); + if (ur) { + msg(" ur request command = 0x%x", tcore_user_request_get_command(ur)); + } + data_len = 0; + data = tcore_pending_ref_request_data(pending, &data_len); + msg(" data=%p, data_len=%d", data, data_len); + } + msg(" queue_tail: %p", g_queue_peek_tail(q->gq)); + msg(""); + + list = list->next; + } while(list); } void monitor_server_state(Server *s) @@ -149,5 +227,5 @@ void monitor_server_state(Server *s) _monitor_plugin(s); _monitor_storage(s); _monitor_communicator(s); - _monitor_modems(s); + _monitor_hal(s); } diff --git a/src/monitor.h b/src/monitor.h index ac76bdf..e0c93f1 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -1,7 +1,7 @@ /* * telephony-daemon * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved. * * Contact: Ja-young Gu * @@ -18,10 +18,8 @@ * limitations under the License. */ -#ifndef __MONITIR_H__ -#define __MONITOR_H__ +#pragma once +#include void monitor_server_state(Server *s); - -#endif diff --git a/systemd/telephony.service b/systemd/telephony.service deleted file mode 100644 index ffd44e3..0000000 --- a/systemd/telephony.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Telephony daemon -After=modem.service vconf-setup.service - -[Service] -Type=notify -ExecStart=/usr/bin/telephony-daemon - -[Install] -WantedBy=multi-user.target diff --git a/telephony-daemon.manifest b/telephony-daemon.manifest old mode 100644 new mode 100755 index afc9248..41514ef --- a/telephony-daemon.manifest +++ b/telephony-daemon.manifest @@ -1,6 +1,6 @@ - + + + + + + + @@ -27,8 +38,99 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.7.4