[meego-commits] 15067: Changes to Trunk/libiodata

Rolla Selbak no_reply at build.meego.com
Mon Mar 21 21:14:54 UTC 2011


Hi,
I have made the following changes to libiodata in project Trunk. Please review and accept ASAP.

Thank You,
Rolla Selbak

[This message was auto-generated]

---

Request #15067:

  submit:   Trunk:Testing/timed(r2) -> Trunk/timed
  submit:   Trunk:Testing/libiodata(r2) -> Trunk/libiodata


Message:
    Trunk promotion

State:   new          2011-03-21T14:14:46 rolla
Comment: None



changes files:
--------------
--- timed.changes
+++ timed.changes
@@ -0,0 +1,9 @@
+* Fri Mar 04 2011 Tapio Rantala <ext-tapio.rantala at nokia.com> 2.37-1
+- New upstream version (FEA#5513)
+- Add cellular-separation patch, fix incomplete defines
+- Add compiler-fix patch, fix "cannot call constructor directly"
+- Add uid-creds patch, uid credentials support (BMC#14696)
+- Drop add-missing-if patch, upstream implementation changed
+- Drop libcreds3-meego patch
+- Refresh patches
+
@@ -8 +17 @@
-- Drop init script, part of fix for BMC#12898
+- Drop init script, part of fix for (BMC#12898)

old:
----
  timed-2.27-enable-creds.patch
  timed-2.31-add-missing-if.patch
  timed-2.35-libcreds3-meego.patch
  timed-2.35.tar.bz2

new:
----
  timed-2.37-cellular-separation.patch
  timed-2.37-compiler-fix.patch
  timed-2.37-uid-creds.patch
  timed-2.37.tar.bz2

spec files:
-----------
--- timed.spec
+++ timed.spec
@@ -1,6 +1,6 @@
 Name:     timed
-Version:  2.35
-Release:  2
+Version:  2.37
+Release:  1
 Summary:  Time daemon
 Group:    System/System Control
 License:  LGPLv2
@@ -8,25 +8,23 @@
 Source0:  %{name}-%{version}.tar.bz2
 Source1:  %{name}.conf
 Patch1:   %{name}-2.11-run-as-system-service.patch
-Patch2:   %{name}-2.27-enable-creds.patch
 Patch3:   %{name}-2.27-debugflag-fix.patch
 Patch5:   %{name}-2.27-typofix.patch
-Patch6:   %{name}-2.31-add-missing-if.patch
-Patch7:	  %{name}-2.35-libcreds3-meego.patch
+Patch6:   %{name}-2.37-cellular-separation.patch
+Patch7:   %{name}-2.37-compiler-fix.patch
+Patch8:   %{name}-2.37-uid-creds.patch
+
 BuildRequires: pkgconfig(contextprovider-1.0)
 BuildRequires: pkgconfig(dsme_dbus_if)
 BuildRequires: pkgconfig(libpcrecpp)
-BuildRequires: pkgconfig(QtCore) >= 4.6
+BuildRequires: pkgconfig(QtCore) >= 4.7
 BuildRequires: asciidoc
 BuildRequires: dblatex
 BuildRequires: docbook-style-xsl
-BuildRequires: doxygen
 BuildRequires: graphviz
-BuildRequires: libcreds3-devel >= 1.3.0
-BuildRequires: libiodata-devel
-BuildRequires: libqmlog-devel >= 0.0.9
+BuildRequires: libiodata-devel >= 0.17
+BuildRequires: libqmlog-devel >= 0.10
 BuildRequires: libxslt
-BuildRequires: python >= 2.5
 
 Requires: tzdata
 
@@ -66,13 +64,14 @@
 %prep
 %setup -q
 %patch1 -p1
-%patch2 -p1
 %patch3 -p1
 %patch5 -p1
 %patch6 -p1
 %patch7 -p1
+%patch8 -p1
 
 %build
+export TIMED_VERSION=`head -n1 debian/changelog | sed "s/.*(\([^)+]*\).*/\1/"`
 mkdir -p src/h
 ln -s ../server src/h/daemon
 ln -s ../lib    src/h/timed
@@ -86,7 +85,6 @@
 cd src/political
 INSTALL_ROOT=%{buildroot} ./debian-install.sh
 cd ../..
-ln -s %{_bindir}/%{name} %{buildroot}/%{_bindir}/cute-timed
 install -m 644 -D src/doc/timed.8 %{buildroot}/%{_mandir}/man8/timed.8
 install -m 644 -D src/doc/libtimed.3 %{buildroot}/%{_mandir}/man3/libtimed.3
 install -m 644 src/doc/libtimed-voland.3 %{buildroot}/%{_mandir}/man3/libtimed-voland.3
@@ -104,7 +102,6 @@
 %config(noreplace) %{_sysconfdir}/dbus-1/system.d/%{name}.conf
 %{_sysconfdir}/osso-cud-scripts/timed-clear-device.sh
 %{_sysconfdir}/osso-rfs-scripts/timed-restore-original-settings.sh
-%{_bindir}/cute-timed
 %{_bindir}/%{name}
 %{_libdir}/libtimed.so.*
 %{_libdir}/libtimed-voland.so.*
@@ -113,7 +110,6 @@
 %{_mandir}/man3/libtimed.3.gz
 %{_mandir}/man3/libtimed-voland.3.gz
 %{_mandir}/man8/timed.8.gz
-%{_datadir}/%{name}/typeinfo/*.type
 %{_datadir}/tzdata-timed/*.data
 %{_datadir}/zoneinfo/Mobile/UTC*
 %{_localstatedir}/cache/timed/

other changes:
--------------

++++++ timed-2.11-run-as-system-service.patch
--- timed-2.11-run-as-system-service.patch
+++ timed-2.11-run-as-system-service.patch
@@ -1,8 +1,8 @@
 diff --git a/src/lib/interface.h b/src/lib/interface.h
-index d021e50..2cb617b 100644
+index 21a9a7d..f4b4e06 100644
 --- a/src/lib/interface.h
 +++ b/src/lib/interface.h
-@@ -54,7 +54,7 @@ namespace Maemo
+@@ -58,7 +58,7 @@ namespace Maemo
      }
      inline QDBusConnection bus()
      {
@@ -10,7 +10,7 @@
 +      return QDBusConnection::systemBus() ;
      }
      // struct signal_receiver ;
-     class Interface : public QDBusInterface
+     class Interface : public QDBusAbstractInterface
 diff --git a/src/server/com.nokia.time.context b/src/server/com.nokia.time.context
 index e94de1a..655d63c 100644
 --- a/src/server/com.nokia.time.context
@@ -45,15 +45,15 @@
  
  # vim:tw=0:
 diff --git a/src/voland/interface.h b/src/voland/interface.h
-index 501c727..ed8224e 100644
+index 8d770de..5195677 100644
 --- a/src/voland/interface.h
 +++ b/src/voland/interface.h
-@@ -50,7 +50,7 @@ namespace Maemo
+@@ -54,7 +54,7 @@ namespace Maemo
        }
        inline QDBusConnection bus()
        {
 -        return QDBusConnection::sessionBus() ;
 +        return QDBusConnection::systemBus() ;
        }
-       class Interface : public QDBusInterface
+       class Interface : public QDBusAbstractInterface
        {

++++++ timed-2.27-debugflag-fix.patch
--- timed-2.27-debugflag-fix.patch
+++ timed-2.27-debugflag-fix.patch
@@ -1,11 +1,11 @@
 diff --git a/src/server/f.h b/src/server/f.h
-index 8bb7f21..c687a62 100644
+index 4b36e8f..c4ee442 100644
 --- a/src/server/f.h
 +++ b/src/server/f.h
-@@ -26,6 +26,7 @@
- 
+@@ -27,6 +27,7 @@
  #if __MEEGO__
- #  define F_CREDS_AEGIS_LIBCREDS 1
+ #  define F_CREDS_UID 1
+ //#  define F_CREDS_NOBODY 1
 +#  define F_FORCE_DEBUG_PATH "/var/cache/timed/DEBUG"
  #endif
  

++++++ timed-2.27-typofix.patch
--- timed-2.27-typofix.patch
+++ timed-2.27-typofix.patch
@@ -1,8 +1,8 @@
 diff --git a/src/server/timed.cpp b/src/server/timed.cpp
-index 13520ca..4ddd8a6 100644
+index 601a394..def3319 100644
 --- a/src/server/timed.cpp
 +++ b/src/server/timed.cpp
-@@ -157,7 +157,7 @@ void Timed::init_scratchbox_mode()
+@@ -170,7 +170,7 @@ void Timed::init_scratchbox_mode()
    scratchbox_mode = path && strstr(path, "scratchbox") ; // XXX: more robust sb detection?
    log_info("%s" "SCRATCHBOX detected", scratchbox_mode ? "" : "no ") ;
  #else

++++++ timed-2.37-cellular-separation.patch (new)
--- timed-2.37-cellular-separation.patch
+++ timed-2.37-cellular-separation.patch
+diff --git a/src/lib/interface.h b/src/lib/interface.h
+index f4b4e06..c7c767f 100644
+--- a/src/lib/interface.h
++++ b/src/lib/interface.h
+@@ -96,10 +96,12 @@ namespace Maemo
+       qtdbus_method(pid, (void)) ;
+       qtdbus_method(parse, (const QString &text), text) ;
+       qtdbus_method(customization_values, (void)) ;
++#if __HARMATTAN__
+       qtdbus_method(fake_nitz_signal, (int mcc, int offset, int time, int dst), mcc, offset, time, dst) ;
+       qtdbus_method(fake_operator_signal, (const QString &mcc, const QString &mnc), mcc, mnc) ;
+       qtdbus_method(fake_csd_time_signal, (const QString &mcc, const QString &mnc, int offset, int time, int dst, int seconds, int nano_seconds), mcc, mnc, offset, time, dst, seconds, nano_seconds) ;
+       qtdbus_method(fake_csd_time_signal_now, (const QString &mcc, const QString &mnc, int offset, int time, int dst), mcc, mnc, offset, time, dst) ;
++#endif // __HARMATTAN__
+       qtdbus_method(get_log_level, (void)) ;
+       qtdbus_method(set_log_level, (int n), n) ;
+     } ;
+diff --git a/src/server/adaptor.h b/src/server/adaptor.h
+index 31909e9..ddcd073 100644
+--- a/src/server/adaptor.h
++++ b/src/server/adaptor.h
+@@ -198,6 +198,7 @@ public slots:
+     timed->halt(string_q_to_std(what)) ;
+   }
+ 
++#if F_CSD
+   bool fake_csd_time_signal(const QString &mcc, const QString &mnc, int offset, int time, int dst, int seconds, int nano_seconds)
+   {
+     log_notice("(fake_csd_time_signal) mcc='%s' mnc='%s' offset=%d time=%d dst=%d seconds=%d nano_seconds=%d", mcc.toStdString().c_str(), mnc.toStdString().c_str(), offset, time, dst, seconds, nano_seconds) ;
+@@ -247,6 +248,7 @@ public slots:
+     timed->csd->process_csd_network_operator(mcc, mnc) ;
+     return true ;
+   }
++#endif // F_CSD
+ 
+   int get_log_level(const QDBusMessage &message)
+   {
+diff --git a/src/server/timed.cpp b/src/server/timed.cpp
+index def3319..37e184b 100644
+--- a/src/server/timed.cpp
++++ b/src/server/timed.cpp
+@@ -129,7 +129,10 @@ Timed::Timed(int ac, char **av) : QCoreApplication(ac, av)
+   init_load_events() ;
+   log_debug() ;
+ 
++#if F_CSD
+   init_cellular_services() ;
++#endif // F_CSD
++
+   log_debug() ;
+ 
+   init_dst_checker() ;
+@@ -527,6 +530,7 @@ void Timed::init_start_event_machine()
+   am->start() ;
+ }
+ 
++#if F_CSD
+ void Timed::init_cellular_services()
+ {
+ #if 0
+@@ -553,6 +557,7 @@ void Timed::init_cellular_services()
+   QObject::connect(nitz_object, SIGNAL(cellular_data_received(const cellular_info_t &)), tz_oracle, SLOT(nitz_data(const cellular_info_t &))) ;
+ #endif
+ }
++#endif // F_CSD
+ 
+ void Timed::init_dst_checker()
+ {
+diff --git a/src/ticker/ticker.h b/src/ticker/ticker.h
+index a959059..8a53722 100644
+--- a/src/ticker/ticker.h
++++ b/src/ticker/ticker.h
+@@ -91,6 +91,7 @@ static string str_printf(const char *format, ...)
+ 
+   return formatted ;
+ }
++#if USE_CELLULAR_QT
+ static string csd_network_time_info_to_string(const Cellular::NetworkTimeInfo &nti)
+ {
+   if (not nti.isValid())
+@@ -120,7 +121,7 @@ static string csd_network_time_info_to_string(const Cellular::NetworkTimeInfo &n
+ 
+   return os.str() ;
+ }
+-
++#endif // USE_CELLULAR_QT
+ 
+ class ticker : public QCoreApplication
+ {

++++++ timed-2.37-compiler-fix.patch (new)
--- timed-2.37-compiler-fix.patch
+++ timed-2.37-compiler-fix.patch
+diff --git a/src/ntp/ntp.h b/src/ntp/ntp.h
+index 911e340..b514650 100644
+--- a/src/ntp/ntp.h
++++ b/src/ntp/ntp.h
+@@ -175,10 +175,10 @@ struct ntp_datagram_t
+     root_delay = ntp_short_t::from_uint32(U32(4)) ;
+     root_dispersion = ntp_short_t::from_uint32(U32(8)) ;
+     reference_id = U32(0xC) ;
+-    reference = ntp_time_t::ntp_time_t(U3232(0x10)) ;
+-    origin = ntp_time_t::ntp_time_t(U3232(0x18)) ;
+-    receive = ntp_time_t::ntp_time_t(U3232(0x20)) ;
+-    transmit = ntp_time_t::ntp_time_t(U3232(0x28)) ;
++    reference = ntp_time_t(U3232(0x10)) ;
++    origin = ntp_time_t(U3232(0x18)) ;
++    receive = ntp_time_t(U3232(0x20)) ;
++    transmit = ntp_time_t(U3232(0x28)) ;
+     return true ; // XXX: do some check ???
+   }
+   void to_strings(std::vector<std::string> &res)

++++++ timed-2.37-uid-creds.patch (new)
--- timed-2.37-uid-creds.patch
+++ timed-2.37-uid-creds.patch
+diff --git a/src/server/credentials.cpp b/src/server/credentials.cpp
+index 9fed739..4879211 100644
+--- a/src/server/credentials.cpp
++++ b/src/server/credentials.cpp
+@@ -24,12 +24,20 @@
+ #include "f.h"
+ 
+ #include <stdlib.h>
++#if F_CREDS_AEGIS_LIBCREDS
+ #include <sys/creds.h>
++#endif // F_CREDS_AEGIS_LIBCREDS
+ 
+ #include <QDBusReply>
+ 
+ #include <qmlog>
+ 
++#if F_CREDS_UID
++#include <pwd.h>
++#include <grp.h>
++#include "timed/interface"
++#endif // F_CREDS_UID
++
+ #include "credentials.h"
+ 
+ #include "aegis.h"
+@@ -84,6 +92,42 @@ uint32_t get_name_owner_from_dbus_sync(const QDBusConnection &bus, const QString
+ 
+ #endif // F_DBUS_INFO_AS_CREDENTIALS
+ 
++uid_t nameToUid(string name)
++{
++  passwd *info = getpwnam(name.c_str()) ;
++  if (info)
++    return info->pw_uid ;
++  // couldn't get uid for username
++  return -1 ;
++}
++
++string uidToName(uid_t u)
++{
++  passwd *info = getpwuid(u) ;
++  if (info)
++    return info->pw_name ;
++  // couldn't get name for uid
++  return "nobody" ;
++}
++
++gid_t nameToGid(string name)
++{
++  group *info = getgrnam(name.c_str()) ;
++  if (info)
++    return info->gr_gid ;
++  // couldn't get gid for groupname
++  return -1 ;
++}
++
++string gidToName(gid_t g)
++{
++  group *info = getgrgid(g) ;
++  if (info)
++    return info->gr_name ;
++  // couldn't get name for gid
++  return "nogroup" ;
++}
++
+ bool credentials_t::apply() const
+ {
+ #if F_CREDS_AEGIS_LIBCREDS
+@@ -97,8 +141,15 @@ bool credentials_t::apply() const
+   creds_free(aegis_creds_want) ;
+ 
+   return res ;
+-#else // F_CREDS_AEGIS_LIBCREDS
+-#error credentials_t::apply() is only implemented for F_CREDS_AEGIS_LIBCREDS
++#elif F_CREDS_UID
++  if (setgid(nameToGid(gid)) != 0 || setuid(nameToUid(uid)) != 0)
++  {
++    log_error("uid cred_set() failed") ;
++    return false ;
++  }
++  return true ;
++#else
++#error unimplemented credentials type
+ #endif
+ }
+ 
+@@ -142,10 +193,14 @@ bool credentials_t::apply_and_compare()
+     os << "}" ;
+ 
+   bool equal = id_matches and all_accrued and all_dropped ;
++  bool ret = id_matches and all_dropped ;
+ 
+ #undef COMMA_A
+ #undef COMMA_D
+ 
++#else
++  bool equal = id_matches ;
++  bool ret =  id_matches ;
+ #endif // F_TOKENS_AS_CREDENTIALS
+ 
+ #undef COMMA
+@@ -153,7 +208,7 @@ bool credentials_t::apply_and_compare()
+   if(!equal)
+     log_warning("applied and wanted credentials differ: %s", os.str().c_str()) ;
+ 
+-  return id_matches and all_dropped ;
++  return ret ;
+ }
+ 
+ credentials_t credentials_t::from_given_process(pid_t pid)
+@@ -165,14 +220,23 @@ credentials_t credentials_t::from_given_process(pid_t pid)
+   creds_free(aegis_creds) ;
+ 
+   return creds ;
+-#else // not F_CREDS_AEGIS_LIBCREDS
+-#error credentials_t::from_given_process(pid_t) is only implemented for F_CREDS_AEGIS_LIBCREDS
++#elif F_CREDS_UID
++// TODO: currently nobody:nobody is reported for all processes
++  return credentials_t() ;
++#else
++#error unimplemented credentials type
+ #endif
+ }
+ 
+ credentials_t credentials_t::from_current_process()
+ {
++#if F_CREDS_AEGIS_LIBCREDS
+   return credentials_t::from_given_process(0) ;
++#elif F_CREDS_UID
++  return credentials_t(uidToName(getuid()), gidToName(getgid())) ;
++#else
++#error unimplemented credentials type
++#endif
+ }
+ 
+ // TODO: F_CREDS_UID
+@@ -185,9 +249,25 @@ credentials_t credentials_t::from_current_process()
+ // TODO: F_CREDS_AEGIS_LIBCREDS --- make this function #ifdef'ed
+ 
+ credentials_t::credentials_t(const QDBusMessage &message)
++: uid("nobody"), gid("nobody")
+ {
+ #if F_CREDS_AEGIS_LIBCREDS
+   *this = Aegis::credentials_from_dbus_connection(message) ;
++#elif F_CREDS_UID
++  QString sender = message.service() ;
++  uint32_t user_id = get_name_owner_from_dbus_sync(Maemo::Timed::bus(), sender) ;
++
++  if (user_id == ~0u)
++    log_warning("can't get user (uid) of the caller, already terminated?") ;
++  else
++  {
++    passwd *info = getpwuid(user_id) ;
++    if (info)
++    {
++      uid = info->pw_name ;
++      gid = gidToName(info->pw_gid) ;
++    }
++  }
+ #else
+ #error credentials_t;:from_dbus_connection is only implemented for aegis
+ #endif
+diff --git a/src/server/credentials.h b/src/server/credentials.h
+index 893d5cb..1632e46 100644
+--- a/src/server/credentials.h
++++ b/src/server/credentials.h
+@@ -33,7 +33,6 @@
+ using namespace std ;
+ 
+ #include <sys/types.h>
+-#include <sys/creds.h>
+ #include <QDBusMessage>
+ #include <QDBusConnection>
+ 
+@@ -49,6 +48,7 @@ struct credentials_t
+   // TODO: make nobody/nogroup run-time option: /etc/timed.rc
+   credentials_t() : uid("nobody"), gid("nogroup") { }
+   credentials_t(const credentials_t &x) : uid(x.uid), gid(x.gid), tokens(x.tokens) { }
++  credentials_t(const string &u, const string &g) : uid(u), gid(g) { }
+ 
+   bool apply() const ; // set the credentials for the current process
+   bool apply_and_compare() ; // set the credentials and check if they are really set

++++++ timed-2.35.tar.bz2 -> timed-2.37.tar.bz2
--- debian/changelog
+++ debian/changelog
@@ -1,3 +1,29 @@
+timed (2.37) unstable; urgency=low
+
+  * compiling .type files into the timed binary
+  * NTP client is working, no interface yet
+  * Changing log level on the fly
+  * Logging in unmountable directory
+  * Fixes: NB#225485 - cancel_events()
+  * some minor stuff
+
+ -- Ilya Dogolazky <ilya.dogolazky at nokia.com>  Thu, 17 Feb 2011 11:31:02 +0200
+
+timed (2.36) unstable; urgency=low
+
+  * new csd layer, better cellular stuff logging
+  * new methods: fake_csd_time_signal, fake_csd_time_signal_now
+  * new tzdata layer (needs only 3 data base files)
+  * peer information asked from dbus daemon for logging
+  * a better algorithm for time zone guessing by cellular info
+  * ticker tool: working in background
+  * two new packages: invalid-time, timed-log
+  * many small fixes
+  * Fixes: NB#212572 - workaround for nitz signal coming before operator
+  * Fixes: NB#219005 - timezone guess doesn't work in America
+
+ -- Ilya Dogolazky <ilya.dogolazky at nokia.com>  Thu, 20 Jan 2011 18:12:56 +0200
+
 timed (2.35) unstable; urgency=low
 
   * Fixes: NB#208557 - sleeping in shutdown / reboot modes
--- debian/control
+++ debian/control
@@ -139,3 +139,22 @@
 Depends: timed-tools (= ${binary:Version}), ${misc:Depends}
 Description: timed-tools debugging symbols
  Debugging symbols for commad line time daemon tools
+
+Package: timed-log
+Architecture: any
+Depends: ${misc:Depends}
+Description: enables verbose logging of time daemon
+ Contains the file /var/cache/timed/DEBUG, switching the logging of time daemon on
+
+Package: timed-home-log
+Architecture: any
+Depends: ${misc:Depends}, timed-log (= ${binary:Version})
+Description: creeates a second copy of the log file, in the user home directory tree
+ Contains the file /var/cache/timed/HOME_LOG, enabling the additional log file in user directory
+
+Package: invalid-time
+Architecture: any
+Depends: ${misc:Depends}
+Description: makes the system time invalid
+ Contains the file /var/cache/timed/SYSTEM_TIME_LOST
+ marking the system time as invalid
--- debian/copyright
+++ debian/copyright
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- debian/invalid-time.install
+++ debian/invalid-time.install
+/var/cache/timed/SYSTEM_TIME_LOST
--- debian/rules
+++ debian/rules
@@ -44,6 +44,10 @@
 	dh_testdir
 	dh_installdirs
 	cd src && make install INSTALL_ROOT=$(CURDIR)/debian/tmp
+	mkdir -p -m 0755 $(CURDIR)/debian/tmp/var/cache/timed
+	touch $(CURDIR)/debian/tmp/var/cache/timed/SYSTEM_TIME_LOST
+	touch $(CURDIR)/debian/tmp/var/cache/timed/DEBUG
+	touch $(CURDIR)/debian/tmp/var/cache/timed/HOME_LOG
 	# cd src/political && INSTALL_ROOT=$(CURDIR)/debian/tmp ./debian-install.sh
 	# ln -sf timed $(CURDIR)/debian/tmp/usr/bin/cute-timed
 	dh_link -ptimed usr/bin/timed usr/bin/cute-timed
--- debian/timed-home-log.install
+++ debian/timed-home-log.install
+/var/cache/timed/HOME_LOG
--- debian/timed-log.install
+++ debian/timed-log.install
+/var/cache/timed/DEBUG
--- debian/timed.install
+++ debian/timed.install
@@ -1,7 +1,8 @@
 # the old: usr/bin/timed
 usr/bin/timed
 
-usr/share/timed/typeinfo
+# compiled in, don't install
+# usr/share/timed/typeinfo
 
 usr/share/contextkit/providers/com.nokia.time.context
 
--- prefix
+++ prefix
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/fake-dialog-ui/fake-dialog-ui.cpp
+++ src/fake-dialog-ui/fake-dialog-ui.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/fake-dialog-ui/fake-dialog-ui.h
+++ src/fake-dialog-ui/fake-dialog-ui.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/aliases.cpp
+++ src/lib/aliases.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/aliases.h
+++ src/lib/aliases.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/event-declarations.h
+++ src/lib/event-declarations.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/event-io.cpp
+++ src/lib/event-io.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/event-io.h
+++ src/lib/event-io.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/event-pimple.cpp
+++ src/lib/event-pimple.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/event-pimple.h
+++ src/lib/event-pimple.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/exception.cpp
+++ src/lib/exception.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/exception.h
+++ src/lib/exception.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/imagetype.cpp
+++ src/lib/imagetype.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/imagetype.h
+++ src/lib/imagetype.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/interface.cpp
+++ src/lib/interface.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/interface.h
+++ src/lib/interface.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -37,6 +37,8 @@
 #include <timed/wallclock>
 #include <timed/qmacro.h>
 
+Q_DECLARE_METATYPE(QList<uint>) ;
+
 namespace Maemo
 {
   namespace Timed
@@ -79,6 +81,7 @@
       qtdbus_method(add_event, (const Maemo::Timed::Event &e), e.dbus_output(__PRETTY_FUNCTION__)) ;
       qtdbus_method(add_events, (const Maemo::Timed::Event::List &ee), ee.dbus_output()) ;
       qtdbus_method(cancel, (uint32_t cookie), cookie) ;
+      qtdbus_method(cancel_events, (const QList<uint> &cookies), QVariant::fromValue(cookies)) ;
       qtdbus_method(replace_event, (const Maemo::Timed::Event &e, uint32_t cookie), e.dbus_output(__PRETTY_FUNCTION__), cookie) ;
       qtdbus_method(query, (const QMap<QString,QVariant> &attr), QVariant::fromValue(attr)) ;
       qtdbus_method(query_attributes, (uint32_t cookie), cookie) ;
@@ -95,6 +98,10 @@
       qtdbus_method(customization_values, (void)) ;
       qtdbus_method(fake_nitz_signal, (int mcc, int offset, int time, int dst), mcc, offset, time, dst) ;
       qtdbus_method(fake_operator_signal, (const QString &mcc, const QString &mnc), mcc, mnc) ;
+      qtdbus_method(fake_csd_time_signal, (const QString &mcc, const QString &mnc, int offset, int time, int dst, int seconds, int nano_seconds), mcc, mnc, offset, time, dst, seconds, nano_seconds) ;
+      qtdbus_method(fake_csd_time_signal_now, (const QString &mcc, const QString &mnc, int offset, int time, int dst), mcc, mnc, offset, time, dst) ;
+      qtdbus_method(get_log_level, (void)) ;
+      qtdbus_method(set_log_level, (int n), n) ;
     } ;
   }
 }
--- src/lib/junk/action.cpp
+++ src/lib/junk/action.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/junk/action.h
+++ src/lib/junk/action.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/junk/button.cpp
+++ src/lib/junk/button.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/junk/button.h
+++ src/lib/junk/button.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/junk/event.cpp
+++ src/lib/junk/event.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/junk/recurrence.cpp
+++ src/lib/junk/recurrence.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/junk/recurrence.h
+++ src/lib/junk/recurrence.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/log.cpp
+++ src/lib/log.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/log.h
+++ src/lib/log.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/nanotime.cpp
+++ src/lib/nanotime.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -31,6 +31,18 @@
 #include "nanotime.h"
 #include "log.h"
 
+nanotime_t nanotime_t::div2() const
+{
+  uint32_t y = nano() / 2 ;
+  time_t x = sec() ;
+  if (x%2 != 0)
+    x--, y+=NANO/2 ;
+  x /= 2 ;
+  while (y>=NANO)
+    ++x, y-=NANO ;
+  return nanotime_t(x,y) ;
+}
+
 nanotime_t nanotime_t::systime_at_zero() // TODO: rename it to start_up_time()
 {
   nanotime_t s = systime_now() ;
--- src/lib/nanotime.h
+++ src/lib/nanotime.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -54,7 +54,10 @@
   nanotime_t operator+(const nanotime_t &x) const { nanotime_t y=*this ; return y+=x ; }
   nanotime_t operator-(const nanotime_t &x) const { nanotime_t y=*this ; return y-=x ; }
   nanotime_t operator-() const { return ns ? nanotime_t(-s-1,NANO-ns) : nanotime_t(-s,0) ; }
+  nanotime_t div2() const ;
   bool operator<(int32_t x) const { return sec() < x ; }
+  bool operator<(const nanotime_t x) const { return sec()<x.sec() or (sec()==x.sec() and nano()<x.nano()) ; }
+  bool operator>(const nanotime_t x) const { return sec()>x.sec() or (sec()==x.sec() and nano()>x.nano()) ; }
 
   bool is_normalized() const { return NANO > nano() ; }
   void invalidate() { s=~0, ns=~0 ; }
--- src/lib/qmacro.h
+++ src/lib/qmacro.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/wall-declarations.h
+++ src/lib/wall-declarations.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/wall-info.cpp
+++ src/lib/wall-info.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/wall-info.h
+++ src/lib/wall-info.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/lib/wall-settings.cpp
+++ src/lib/wall-settings.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -130,12 +130,18 @@
 {
   if(p==NULL)
     return "{ NULL }" ;
+  else
+    return p->str() ;
+}
+
+QString Maemo::Timed::WallClock::wall_settings_pimple_t::str() const
+{
   QString res ;
   QTextStream os(&res) ;
   os << "{ opcodes='" ;
   bool first = true ;
   using namespace WallOpcode ;
-#define _x(x) if(p->opcodes&x){if(!first)os<<"+";first=false;os<<#x;}
+#define _x(x) if(opcodes&x){if(!first)os<<"+";first=false;os<<#x;}
   _x(Op_Set_Time_Nitz) ;
   _x(Op_Set_Time_Manual) ;
   _x(Op_Set_Time_Manual_Val) ;
@@ -149,11 +155,11 @@
   _x(Op_Set_12) ;
 #undef _x
   os << "', " ;
-  os << " time_at_zero=" << p->time_at_zero.sec() << "," << p->time_at_zero.nano() ;
+  os << " time_at_zero=" << time_at_zero.sec() << "," << time_at_zero.nano() ;
   os << "', " ;
-  os << " offset=" << p->offset << ", " ;
-  os << " zone='" << p->zone << "'" ;
-  os << " valid=" << p->valid << "}" << flush ;
+  os << " offset=" << offset << ", " ;
+  os << " zone='" << zone << "'" ;
+  os << " valid=" << valid << "}" << flush ;
   return res ;
 }
 
--- src/lib/wall-settings.h
+++ src/lib/wall-settings.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -44,6 +44,7 @@
     opcodes = 0 ;
     offset = 0 ;
   }
+  QString str() const ;
 } ;
 
 declare_qtdbus_io(Maemo::Timed::WallClock::wall_settings_pimple_t) ;
--- src/logging-test/logging-test.cpp
+++ src/logging-test/logging-test.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/memory/memory.cpp
+++ src/memory/memory.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/memory/memory.h
+++ src/memory/memory.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/ntp/ntp.cpp
+++ src/ntp/ntp.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -21,10 +21,17 @@
 **   License along with Timed. If not, see http://www.gnu.org/licenses/   **
 **                                                                        **
 ***************************************************************************/
+#include <vector>
+#include <string>
+using namespace std ;
+
 #include <QCoreApplication>
 
 #include <qmlog>
 
+#include <timed/nanotime.h>
+
+#include "xxd.h"
 #include "ntp.h"
 
 void ntp_receiver_t::read_datagram()
@@ -40,14 +47,46 @@
   }
 }
 
+#if 0
+static char print_char(unsigned char ch)
+{
+  if (ch<0x20 or ch>0x7E)
+    return '.' ;
+  return ch ;
+}
+#endif
+
 void ntp_receiver_t::process(const QByteArray &d, const QHostAddress &a, uint16_t port)
 {
-  log_debug("received %d bytes from %s:%d", d.size(), a.toString().toStdString().c_str(), port) ;
+  log_notice("received %d bytes from %s:%d", d.size(), a.toString().toStdString().c_str(), port) ;
+  vector<string> dump ;
+  xxd(d.data(), d.size(), 8, dump) ;
+  for (unsigned i=0; i<dump.size(); ++i)
+    log_notice("Data: %s", dump[i].c_str()) ;
+#if 0
+  for (int k=0; k<d.size(); k+=8)
+  {
+    char buf[80] = "" ;
+    int remains = d.size() - k ;
+    int len = remains < 8 ? remains : 8 ;
+    for (int ii=0, i; i=k+ii, ii<len; ++ii)
+      sprintf(buf+strlen(buf), "%02X ", d.at(i)) ;
+    for (int i=0; i<8-len; ++i)
+      sprintf(buf+strlen(buf), "%2s ", "") ;
+    sprintf(buf+strlen(buf), "| ") ;
+    for (int ii=0, i; i=k+ii, ii<len; ++ii)
+      sprintf(buf+strlen(buf), "%c", print_char(d.at(i))) ;
+    for (int i=0; i<8-len; ++i)
+      sprintf(buf+strlen(buf), " ") ;
+    sprintf(buf+strlen(buf), " | %2x", k) ;
+    log_notice("Data: %s", buf) ;
+  }
+#endif
 }
 
 void ntp_receiver_t::bind()
 {
-  socket -> bind(QHostAddress::LocalHost, 123) ;
+  socket -> bind(QHostAddress("0.0.0.0"), 123) ;
 }
 
 ntp_receiver_t::ntp_receiver_t()
@@ -61,9 +100,11 @@
   delete socket ;
 }
 
+#if 0
 int main(int ac, char **av)
 {
   QCoreApplication a(ac, av) ;
   ntp_receiver_t S ;
   return a.exec() ;
 }
+#endif
--- src/ntp/ntp.h
+++ src/ntp/ntp.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -25,11 +25,18 @@
 #define MAEMO_TIMED_NTP_NTP_H
 
 #include <stdint.h>
+#include <arpa/inet.h>
 
 #include <QUdpSocket>
 #include <QHostAddress>
 #include <QByteArray>
 
+#include <qmlog>
+
+#include <timed/nanotime.h>
+
+#include "xxd.h"
+
 struct ntp_receiver_t : public QObject
 {
   Q_OBJECT ;
@@ -43,5 +50,147 @@
   void read_datagram() ;
 } ;
 
+struct ntp_time_t
+{
+  uint32_t sec, frac ;
+  ntp_time_t() { sec = frac = 0 ; }
+  ntp_time_t(uint32_t s) { sec = s, frac = 0 ; }
+  ntp_time_t(uint32_t s, uint32_t f) { sec = s, frac = f ; }
+  static const uint32_t  epoch1900 = 2208988800u ; // seconds in years 1900..1969
+  static const double nano_to_fraction = 4294967296e-9 ; // = 2^32 / 10^9
+  static ntp_time_t from_nanotime(const nanotime_t &t)
+  {
+    uint32_t sec = (uint32_t)t.sec() + epoch1900 ; // overfolow condition: sec<=epoch1900
+    uint32_t frac = t.nano() * nano_to_fraction + 0.5 ; // will not overflow for 0 <= nano < 10^9
+    return ntp_time_t(sec, frac) ;
+  }
+  nanotime_t to_nanotime() const
+  {
+    nanotime_t res(sec-epoch1900, (uint32_t) (frac / nano_to_fraction + 0.5)) ;
+    res.fix_overflow() ; // overflow:  2^31-1 --> 999999999.7 -> 1000000000
+    return res ;
+  }
+  static ntp_time_t systime_now() { return from_nanotime(nanotime_t::systime_now()) ; }
+} ;
+
+struct ntp_short_t
+{
+  uint16_t sec, frac ;
+  ntp_short_t() { sec = frac = 0 ; }
+  ntp_short_t(uint16_t s) { sec = s, frac = 0 ; }
+  ntp_short_t(uint16_t s, uint16_t f) { sec = s, frac = f ; }
+  uint32_t to_uint32() const { return (sec<<16) | frac ; }
+  static ntp_short_t from_uint32(uint32_t x) { return ntp_short_t(x>>16, x & 0xFFFF) ; }
+  std::string str() { return nanotime_t(sec, frac/65536e-9).str() ; }
+} ;
+
+struct ntp_datagram_t
+{
+  short leap_indicator, version_number, mode ;
+  uint8_t stratum ;
+  int8_t poll, precision ;
+  ntp_short_t root_delay, root_dispersion ;
+  uint32_t reference_id ;
+  ntp_time_t reference, origin, receive, transmit ;
+  uint8_t *data ;
+  unsigned length ;
+
+  ntp_datagram_t() :
+    leap_indicator(3), // unknown
+    version_number(4),
+    mode(3), // client
+    stratum(0),
+    poll(3),
+    precision(-6),
+    root_delay(1,0),
+    root_dispersion(1,0),
+    reference_id(0),
+    reference(0,0),
+    origin(0,0),
+    receive(0,0),
+    transmit(0,0)
+  {
+    data = NULL ;
+    length = 0 ;
+  }
+
+  ~ntp_datagram_t()
+  {
+    delete data ;
+  }
+  void allocate(int len)
+  {
+    log_assert(data==NULL, "datagram buffer already allocated") ;
+    length = len, data = new uint8_t[len] ;
+  }
+  void allocate_minimal()
+  {
+    allocate(48) ;
+  }
+  void write_uint32(uint32_t x, unsigned offset)
+  {
+    log_assert(data and length >= offset + 4, "out of bounds: 4 bytes requested, length=%d, offset=%d", length, offset) ;
+    uint32_t big = htonl(x) ;
+    memcpy(data+offset, &big, 4) ;
+  }
+  void write_timestamp_short(const ntp_short_t &x, unsigned offset)
+  {
+    write_uint32(x.to_uint32(), offset) ;
+  }
+  void write_timestamp(const ntp_time_t &x, unsigned offset)
+  {
+    write_uint32(x.sec, offset) ;
+    write_uint32(x.frac, offset+4) ;
+  }
+  void write_fields()
+  {
+    // First word: LI:2, VN:3, Mode:3, stratum:8, poll:8, precision:8
+    uint32_t word0 = (leap_indicator << 30) | (version_number << 27) | (mode << 24)
+      | ((uint8_t)stratum << 16) | ((uint8_t)poll << 8) | ((uint8_t)precision) ;
+    write_uint32(word0, 0x0) ;
+    write_timestamp_short(root_delay, 0x4) ;
+    write_timestamp_short(root_dispersion, 0x8) ;
+    write_uint32(reference_id, 0xC) ;
+    write_timestamp(reference, 0x10) ;
+    write_timestamp(origin, 0x18) ;
+    write_timestamp(receive, 0x20) ;
+    write_timestamp(transmit, 0x28) ;
+  }
+  bool read_minimal(const QByteArray &data)
+  {
+    if (data.size()<48)
+    {
+      log_error("Datagram is too short: %d bytes", data.size()) ;
+      return false ;
+    }
+    if (data.size()>48)
+      log_warning("datagram is too large (%d bytes), using only first 48 bytes", data.size()) ;
+    const uint8_t *p = reinterpret_cast<const uint8_t *> (data.data()) ;
+    leap_indicator = (p[0] & 0300 ) >> 6 ;
+    version_number = (p[0] & 0070 ) >> 3 ;
+    mode = p[0] & 0007 ;
+    stratum = p[1], poll = p[2], precision = p[3] ;
+#define U32(i) ntohl(*(const uint32_t*)(p+(i)))
+#define U3232(i) U32(i),U32((i)+4)
+    root_delay = ntp_short_t::from_uint32(U32(4)) ;
+    root_dispersion = ntp_short_t::from_uint32(U32(8)) ;
+    reference_id = U32(0xC) ;
+    reference = ntp_time_t::ntp_time_t(U3232(0x10)) ;
+    origin = ntp_time_t::ntp_time_t(U3232(0x18)) ;
+    receive = ntp_time_t::ntp_time_t(U3232(0x20)) ;
+    transmit = ntp_time_t::ntp_time_t(U3232(0x28)) ;
+    return true ; // XXX: do some check ???
+  }
+  void to_strings(std::vector<std::string> &res)
+  {
+    res.push_back(str_printf("LI=%d VN=%d MD=%d STR=%d POLL=%d PREC=%d DEL=%s DISP=%s REFID=%08X",
+          leap_indicator, version_number, mode, stratum, poll, precision,
+          root_delay.str().c_str(), root_dispersion.str().c_str(), reference_id)) ;
+    res.push_back(str_printf("reference: %s", reference.to_nanotime().str().c_str())) ;
+    res.push_back(str_printf("origin   : %s", origin   .to_nanotime().str().c_str())) ;
+    res.push_back(str_printf("receive  : %s", receive  .to_nanotime().str().c_str())) ;
+    res.push_back(str_printf("transmit : %s", transmit .to_nanotime().str().c_str())) ;
+  }
+} ;
 
 #endif
--- src/ntp/ntp.pro
+++ src/ntp/ntp.pro
@@ -8,14 +8,14 @@
 
 INCLUDEPATH += ../h
 
-# QMAKE_LIBDIR_FLAGS += -L../lib -L../voland
-# LIBS += -ltimed -ltimed-voland
+QMAKE_LIBDIR_FLAGS += -L../lib # -L../voland
+LIBS += -ltimed
 
 CONFIG += qmlog link_pkgconfig
 PKGCONFIG += libpcrecpp
 
-SOURCES = ntp.cpp
-HEADERS = ntp.h
+SOURCES = ntp.cpp resolver.cpp xxd.cpp # main.cpp
+HEADERS = ntp.h   resolver.h   xxd.h
 
 INSTALLS += target
 target.path = $$(DESTDIR)/usr/bin
--- src/ntp/resolver.cpp
+++ src/ntp/resolver.cpp
+#include <string>
+#include <vector>
+#include <set>
+using namespace std ;
+
+#include "resolver.h"
+#include "ntp.h"
+
+resolver_t::resolver_t()
+{
+}
+
+void resolver_t::add_name(const string &host)
+{
+  names.insert(host) ;
+}
+
+void resolver_t::start()
+{
+  for (set<string>::const_iterator it=names.begin(); it!=names.end(); ++it)
+  {
+    QString host(it->c_str()) ;
+    // first try to parse it, may be we don't need DNS lookup
+    QHostAddress a(host) ;
+    if (not a.isNull())
+    {
+      emit address(a) ;
+      continue ;
+    }
+
+    // starting DNS lookup
+    lookup_t *lookup = new lookup_t(*it) ;
+    QObject::connect(lookup, SIGNAL(address_received(QHostAddress)), this, SIGNAL(address(QHostAddress))) ;
+    QObject::connect(lookup, SIGNAL(lookup_done(int)), this, SLOT(lookup_done(int)), Qt::QueuedConnection) ;
+    int id = QHostInfo::lookupHost(host, lookup, SLOT(lookup_done(const QHostInfo &))) ;
+    pending.insert(id) ;
+  }
+}
+
+void resolver_t::lookup_done(int id)
+{
+  pending.erase(id) ;
+  if (pending.empty())
+    emit resolving_done() ;
+}
+
+#include <QCoreApplication>
+
+int main(int ac, char **av)
+{
+  qmlog::enable() ;
+  qmlog::stderr()->disable_fields(qmlog::Pid | qmlog::Name | qmlog::Timezone_Symlink) ;
+  qmlog::stderr()->enable_fields(qmlog::Time_Micro) ;
+  my_app a(ac, av) ;
+  resolver_t R ;
+  concentrator_t C(50, 900, 5) ;
+  ntp_receiver_t N ;
+  N.bind() ;
+  for (int i=1; i<ac; ++i)
+    R.add_name(av[i]) ;
+  // QObject::connect(&R, SIGNAL(resolving_done()), &a, SLOT(quit_after_5sec())) ;
+  QObject::connect(&R, SIGNAL(address(QHostAddress)), &C, SLOT(add_address(QHostAddress))) ;
+  QObject::connect(&R, SIGNAL(resolving_done()), &C, SLOT(last_address())) ;
+  QObject::connect(&C, SIGNAL(send_address(QHostAddress)), &a, SLOT(address(QHostAddress))) ;
+  R.start() ;
+  return a.exec() ;
+}
--- src/ntp/resolver.h
+++ src/ntp/resolver.h
+#ifndef MAEMO_TIMED_NTP_RESOLVER_H
+#define MAEMO_TIMED_NTP_RESOLVER_H
+
+#include <stdint.h>
+
+#include <string>
+#include <vector>
+#include <set>
+
+#include <QObject>
+#include <QHostAddress>
+#include <QHostInfo>
+#include <QTimer>
+#include <QCoreApplication>
+#include <QUdpSocket>
+
+#include <qmlog>
+
+#include "ntp.h"
+#include "xxd.h"
+
+template<typename value_t>
+value_t uniform(std::vector<value_t> &array)
+{
+  // TODO: srandom
+  if (unsigned N=array.size())
+  {
+    unsigned i = random() % N ;
+    value_t result = array[i] ;
+    if (i!=N-1)
+      array[i] = array[N-1] ;
+    array.resize(N-1) ;
+    return result ;
+  }
+  return value_t() ;
+}
+
+struct lookup_t : public QObject
+{
+  std::string hostname ;
+  lookup_t(const std::string &h) : hostname(h) { }
+  Q_OBJECT ;
+public Q_SLOTS:
+  void lookup_done(const QHostInfo &info)
+  {
+    if (info.error() != QHostInfo::NoError)
+      log_error("lookup (id=%d) failed for host '%s': %s", info.lookupId(), hostname.c_str(), info.errorString().toStdString().c_str()) ;
+
+    QList<QHostAddress> list = info.addresses() ;
+    for (QList<QHostAddress>::iterator it = list.begin(); it != list.end(); ++it)
+    {
+      // log_debug("address for host '%s': <%s>", hostname.c_str(), it->toString().toStdString().c_str()) ;
+      emit address_received(*it) ;
+    }
+
+    emit lookup_done(info.lookupId()) ;
+  }
+Q_SIGNALS:
+  void lookup_done(int lookup_id) ;
+  void address_received(QHostAddress a) ;
+} ;
+
+struct resolver_t : public QObject
+{
+  std::set<int> pending ;
+  std::set<std::string> names ;
+
+  resolver_t() ;
+  void add_name(const std::string &host) ;
+  void start() ;
+  Q_OBJECT ;
+public Q_SLOTS:
+  void lookup_done(int lookup_id) ;
+Q_SIGNALS:
+  void address(QHostAddress a) ;
+  void resolving_done() ;
+} ;
+
+struct concentrator_t : public QObject
+{
+  int primary_pause, secondary_pause, first_bunch ;
+  int received, sent ;
+  std::vector<QHostAddress> queue ;
+  std::set<std::string> known ;
+  QTimer *timer ;
+  enum { WAIT, BUNCH, REGULAR, EMPTY } state ;
+  concentrator_t(int p1, int p2, int b, QObject *p=NULL) : QObject(p)
+  {
+    primary_pause = p1, secondary_pause = p2, first_bunch = b ;
+    received = sent = 0 ;
+    timer = new QTimer ;
+    timer->setSingleShot(true) ;
+    state = WAIT ;
+    connect(timer, SIGNAL(timeout()), this, SLOT(send())) ;
+  }
+  Q_OBJECT ;
+public Q_SLOTS:
+  void send()
+  {
+    timer->stop() ;
+    if (queue.empty())
+    {
+      state = EMPTY ;
+      return ;
+    }
+    QHostAddress a = uniform(queue) ;
+    emit send_address(a) ;
+    if (++sent==first_bunch)
+      state = REGULAR ;
+    timer->start(state==BUNCH ? primary_pause : secondary_pause) ;
+  }
+  void add_address(QHostAddress ip)
+  {
+    std::string ip_string = ip.toString().toStdString() ;
+    if (known.count(ip_string)>0)
+      return ;
+    known.insert(ip_string) ;
+    queue.push_back(ip) ;
+    log_notice("added '%s' to queue, %d elemants now", ip_string.c_str(), queue.size()) ;
+    if (state==WAIT and (int)queue.size()==first_bunch)
+      state = BUNCH ;
+    if (not timer->isActive() and state!=WAIT)
+      timer->start(state==BUNCH ? primary_pause : state==REGULAR ? secondary_pause : 0) ;
+  }
+  void last_address()
+  {
+    if (state==WAIT)
+    {
+      state = BUNCH ;
+      timer->start(primary_pause) ;
+    }
+  }
+Q_SIGNALS:
+  void send_address(QHostAddress ip) ;
+} ;
+
+struct ntp_request_t : public QObject
+{
+  QHostAddress server ;
+  QUdpSocket *socket ;
+  enum { NEW, RUNNING, DONE, FAILED } state ;
+  nanotime_t value ; // time at zero according to NTP server response
+  nanotime_t sent ; // host's system time while sending request
+  int period ;
+  ntp_datagram_t reply ;
+  ntp_request_t(QHostAddress ip, int timeout_ms, QObject *parent=NULL) : QObject(parent)
+  {
+    server = ip ;
+    socket = new QUdpSocket(this) ;
+    socket->bind() ; // default IP=0.0.0.0, port=0
+    QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(read_datagram())) ;
+    period = timeout_ms ;
+    state = NEW ;
+  }
+  void start()
+  {
+    log_assert(state==NEW, "can't start a request unless in NEW state") ;
+    ntp_datagram_t D ;
+    D.allocate_minimal() ;
+    D.transmit = ntp_time_t::systime_now() ;
+    D.write_fields() ;
+    nanotime_t t1 = nanotime_t::systime_now() ;
+    qint64 res = socket->writeDatagram(reinterpret_cast<const char *>(D.data), D.length, server, 123) ;
+    nanotime_t t2 = nanotime_t::systime_now() ;
+    if (res==(qint64)D.length)
+    {
+      log_notice("sent %d bytes to server %s", (int)res, server.toString().toStdString().c_str()) ;
+      state = RUNNING ;
+      nanotime_t half_delta = (t2-t1).div2() ;
+      sent = t1 + half_delta ;
+      QTimer::singleShot(period, this, SLOT(timeout())) ;
+    }
+    else
+    {
+      log_error("failed to send datagram to server %s: %s", server.toString().toStdString().c_str(), socket->errorString().toStdString().c_str()) ;
+      state = FAILED ;
+      emit finished(this) ;
+    }
+  }
+  Q_OBJECT ;
+public Q_SLOTS:
+  void read_datagram()
+  {
+    nanotime_t now = nanotime_t::systime_now() ;
+    while(socket->hasPendingDatagrams())
+    {
+      QByteArray data(socket->pendingDatagramSize(), '\0') ;
+      QHostAddress sender ;
+      uint16_t port ;
+      socket->readDatagram(data.data(), data.size(), &sender, &port) ;
+      log_notice("(%s) %s %d bytes from %s:%d", server.toString().toStdString().c_str(), (state==RUNNING?"received":"ignored"), data.size(), sender.toString().toStdString().c_str(), port) ;
+      if (state!=RUNNING)
+        continue ;
+
+      if (reply.read_minimal(data))
+      {
+        std::vector<std::string> dump ;
+#if 0
+        xxd(data.data(), data.size(), 8, dump) ;
+#endif
+        reply.to_strings(dump) ;
+        for (unsigned i=0; i<dump.size(); ++i)
+          log_notice("%s", dump[i].c_str()) ;
+        log_notice("<sent it>  %s", sent.str().c_str()) ;
+        log_notice("<receive>  %s", now.str().c_str()) ;
+        nanotime_t d1 = now-reply.transmit.to_nanotime(), d2 = sent-reply.receive.to_nanotime() ;
+        nanotime_t delta = (d1+d2).div2() ;
+        value = nanotime_t::systime_at_zero() - delta ;
+        log_notice("< delta >  %s", delta.str().c_str()) ;
+        state = DONE ;
+      }
+      else
+        state = FAILED ;
+      emit finished(this) ;
+    }
+  }
+  void timeout()
+  {
+    if (state!=RUNNING)
+      return ;
+    state = FAILED ;
+    log_error("(%s): no response after %dms, giving up", server.toString().toStdString().c_str(), period) ;
+    emit finished(this) ;
+  }
+Q_SIGNALS:
+  void finished(ntp_request_t*) ;
+} ;
+
+struct my_app : public QCoreApplication
+{
+  my_app(int ac, char **av) : QCoreApplication(ac, av) { }
+  Q_OBJECT ;
+  std::set<ntp_request_t*> pending ;
+public Q_SLOTS:
+  void address(QHostAddress ip)
+  {
+    log_notice("starting request to address: %s", ip.toString().toStdString().c_str()) ;
+    ntp_request_t *r = new ntp_request_t(ip, 1500, this) ;
+    pending.insert(r) ;
+    r->start() ;
+  }
+  void request_done(ntp_request_t *)
+  {
+  }
+  void quit_after_5sec()
+  {
+    log_notice("5 seconds to quit....") ;
+    QTimer::singleShot(5000, this, SLOT(quit())) ;
+  }
+} ;
+
+
+#endif//MAEMO_TIMED_NTP_RESOLVER_H
+
--- src/ntp/xxd.cpp
+++ src/ntp/xxd.cpp
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include <qmlog>
+
+#include "xxd.h"
+
+using namespace std ;
+
+string str_printf(const char *format, ...)
+{
+  const int buf_len = 1024, max_buf_len = buf_len*1024 ;
+  char buf[buf_len], *p = buf ;
+  va_list varg ;
+  va_start(varg, format) ;
+  int iteration = 0, printed = false ;
+  string formatted ;
+  do
+  {
+    int size = buf_len << iteration ;
+    if(size>max_buf_len)
+    {
+      log_error("Can't format string, the result is too long") ;
+      return format ;
+    }
+    if(iteration>0)
+      p = new char[size] ;
+    int res = vsnprintf(p, size, format, varg) ;
+    if(res < 0)
+    {
+      log_error("Can't format string, vsnprintf() failed") ;
+      return format ;
+    }
+    if(res < size)
+    {
+      printed = true ;
+      formatted = p ;
+    }
+    if(iteration > 0)
+      delete[] p ;
+    ++ iteration ;
+  } while(!printed) ;
+
+  return formatted ;
+}
+
+static char print_char(unsigned char ch)
+{
+  if (ch<0x20 or ch>0x7E)
+    return '.' ;
+  return ch ;
+}
+
+void xxd(const char *data, unsigned len, unsigned bpl, vector<string> &res)
+{
+  for (unsigned k=0; k<len; k+=bpl)
+  {
+    unsigned remains = len - k ;
+    unsigned L = remains < bpl ? remains : bpl ;
+    unsigned P = bpl - L ;
+    string s1, s2 ;
+    for (unsigned ii=0, i; i=k+ii, ii<L; ++ii)
+    {
+      s1 += str_printf("%02X ", data[i]) ;
+      s2 += str_printf("%c", print_char(data[i])) ;
+    }
+    for (unsigned i=0; i<P; ++i)
+    {
+      s1 += "   " ;
+      s2 += "." ;
+    }
+    res.push_back(s1 + "| " + s2 + str_printf(" | %2x", k)) ;
+  }
+}
--- src/ntp/xxd.h
+++ src/ntp/xxd.h
+#include <vector>
+#include <string>
+
+#ifndef MAEMO_TIMED_XXD_H
+#define MAEMO_TIMED_XXD_H
+
+void xxd(const char *data, unsigned len, unsigned bpl, std::vector<std::string> &res) ;
+std::string str_printf(const char *format, ...) ;
+
+#endif//MAEMO_TIMED_XXD_H
--- src/political/simple-dump.cpp
+++ src/political/simple-dump.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/adaptor.h
+++ src/server/adaptor.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -40,10 +40,25 @@
 
 #include "timed.h"
 #include "misc.h"
+#include "csd.h"
 #include "credentials.h"
+#include "peer.h"
 
 #include <timed/interface> // TODO: is Maemo::Timed::bus() the correct way?
 
+#define SQC str().toStdString().c_str()
+#define QC toStdString().c_str()
+#define CC c_str()
+#define PEER timed->peer->info(message.service().toStdString()).c_str()
+
+static QDateTime time_t_to_qdatetime(time_t t)
+{
+  struct tm tm ;
+  if(gmtime_r(&t, &tm) != &tm)
+    return QDateTime() ;
+  return QDateTime(QDate(tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday), QTime(tm.tm_hour,tm.tm_min,tm.tm_sec), Qt::UTC) ;
+}
+
 class com_nokia_time : public QDBusAbstractAdaptor
 {
   Q_OBJECT ;
@@ -62,32 +77,32 @@
   void settings_changed_1(bool) ;
 
 public slots:
-  Maemo::Timed::WallClock::Info get_wall_clock_info()
+  Maemo::Timed::WallClock::Info get_wall_clock_info(const QDBusMessage &message)
   {
-    log_debug() ;
+    log_notice("DBUS::com.nokia.time.get_wall_clock_info() by %s", PEER) ;
     return timed->settings->get_wall_clock_info(nanotime_t()) ;
   }
 
-  bool wall_clock_settings(const Maemo::Timed::WallClock::wall_settings_pimple_t &p)
+  bool wall_clock_settings(const Maemo::Timed::WallClock::wall_settings_pimple_t &p, const QDBusMessage &message)
   {
-    log_debug() ;
+    log_notice("DBUS::com.nokia.time.wall_clock_settings(%s) by %s", p.SQC, PEER) ;
     // log_debug("%s", string_std_to_q(p.str()).c_str()) ;
     return timed->settings->wall_clock_settings(p) ;
   }
 
   uint add_event(const Maemo::Timed::event_io_t &x, const QDBusMessage &message)
   {
+    log_notice("DBUS::com.nokia.time.add_event(APP='%s') by %s", x.attr.txt["APPLICATION"].QC, PEER) ;
     // TODO: here we're not asking about credentials immediately
     //       because an event could contain empty action set
     //       --> forwarding the QDBusMessage to Timed::add_even
     //       -->                        then to machine::add_event
-    log_debug() ;
     return timed->add_event(cookie_t(), x, message).value() ;
   }
 
   void add_events(const Maemo::Timed::event_list_io_t &lst, const QDBusMessage &message, QList<QVariant> &res)
   {
-    log_debug() ;
+    log_notice("DBUS::com.nokia.time.add_events([%d]) by %s", lst.ee.size(), PEER) ;
     // TODO: is Maemo::Timed::bus() the correct way?
     //       yes, but:
     //       Let's see, if there is a better way
@@ -96,37 +111,43 @@
 
   uint replace_event(const Maemo::Timed::event_io_t &x, uint old, const QDBusMessage &message)
   {
-    log_debug() ;
+    log_notice("DBUS::com.nokia.time.replace_event(APP='%s', cookie=%u) by %s", x.attr.txt["APPLICATION"].QC, old, PEER) ;
     return timed->add_event(cookie_t(old), x, message).value() ;
   }
 
-  bool dialog_response(uint cookie, int value)
+  bool dialog_response(uint cookie, int value, const QDBusMessage &message)
   {
-    log_debug() ;
+    log_notice("DBUS::com.nokia.time.dialog_response(cookie=%u, value=%d) by %s", cookie, value, PEER) ;
     return timed->dialog_response(cookie_t(cookie), value) ;
   }
 
-  void query(const QMap<QString,QVariant> &words, QList<QVariant> &res)
+  void query(const QMap<QString,QVariant> &words, const QDBusMessage &message, QList<QVariant> &res)
   {
-    log_debug() ;
+    log_notice("DBUS::com.nokia.time.query(...) by %s", PEER) ;
     timed->am->query(words, res) ;
   }
 
-  void query_attributes(uint cookie, QMap<QString,QVariant> &a)
+  void query_attributes(uint cookie, const QDBusMessage &message, QMap<QString,QVariant> &a)
   {
-    log_debug() ;
+    log_notice("DBUS::com.nokia.time.query_attributes(cookie=%u, ...) by %s", cookie, PEER) ;
     timed->am->get_event_attributes(cookie_t(cookie), a) ;
   }
 
-  bool cancel(uint cookie)
+  bool cancel(uint cookie, const QDBusMessage &message)
   {
-    log_debug() ;
+    log_notice("DBUS::com.nokia.time.cancel(cookie=%u) by %s", cookie, PEER) ;
     return timed->cancel(cookie_t(cookie)) ;
   }
 
-  QString ping()
+  void cancel_events(const QList<uint> &cookies, const QDBusMessage &message, QList<uint> &failed)
+  {
+    log_notice("DBUS::com.nokia.time.cancel_events([%d]) by %s", cookies.size(), PEER) ;
+    timed->cancel_events(cookies, failed) ;
+  }
+
+  QString ping(const QDBusMessage &message)
   {
-    log_debug() ;
+    log_notice("DBUS::com.nokia.time.ping() by %s", PEER) ;
     iodata::record *r = timed->am->save(false) ; // false = not for backup
     std::ostringstream s ;
     s << *r ;
@@ -134,62 +155,111 @@
     return string_std_to_q(s.str()) ;
   }
 
-  QString parse(QString text)
+  QString parse(QString text, const QDBusMessage &message)
   {
-    log_debug() ;
+    log_notice("DBUS::com.nokia.time.parse(text='%s') by %s", text.QC, PEER) ;
     return iodata::parse_and_print(text) ;
   }
 
-  int pid()
+  int pid(const QDBusMessage &message)
   {
-    log_debug() ;
+    log_notice("DBUS::com.nokia.time.pid() by %s", PEER) ;
     return getpid() ;
   }
 
-  void enable_alarms(bool enable)
+  void enable_alarms(bool enable, const QDBusMessage &message)
   {
-    log_debug() ;
+    log_notice("DBUS::com.nokia.time.enable_alarms(%s) by %s", enable?"true":"false", PEER) ;
     timed->settings->alarms_are_enabled = enable ;
     timed->alarm_gate(enable) ;
   }
 
-  bool alarms_enabled()
+  bool alarms_enabled(const QDBusMessage &message)
   {
-    log_debug() ;
+    log_notice("DBUS::com.nokia.time.alarms_enabled() by %s", PEER) ;
     return timed->settings->alarms_are_enabled ;
   }
 
-  bool set_default_snooze(int value)
+  bool set_default_snooze(int value, const QDBusMessage &message)
   {
-    log_debug() ;
+    log_notice("DBUS::com.nokia.time.set_default_snooze(value=%d) by %s", value, PEER) ;
     return timed->default_snooze(value)==value ;
   }
 
-  int get_default_snooze()
+  int get_default_snooze(const QDBusMessage &message)
   {
-    log_debug() ;
+    log_notice("DBUS::com.nokia.time.get_default_snooze() by %s", PEER) ;
     return timed->default_snooze(0) ;
   }
 
-  void halt(const QString &what)
+  void halt(const QString &what, const QDBusMessage &message)
   {
-    log_info("halt('%s') requested, going to sleep soon...", what.toStdString().c_str()) ;
+    log_notice("DBUS::com.nokia.time.halt(what='%s') by %s", what.QC, PEER) ;
     timed->halt(string_q_to_std(what)) ;
   }
 
+  bool fake_csd_time_signal(const QString &mcc, const QString &mnc, int offset, int time, int dst, int seconds, int nano_seconds)
+  {
+    log_notice("(fake_csd_time_signal) mcc='%s' mnc='%s' offset=%d time=%d dst=%d seconds=%d nano_seconds=%d", mcc.toStdString().c_str(), mnc.toStdString().c_str(), offset, time, dst, seconds, nano_seconds) ;
+    QDateTime qdt = time_t_to_qdatetime((time_t)time) ;
+    if (not qdt.isValid())
+    {
+      log_error("invalid time=%d parameter in in fake_csd_time_signal()", time) ;
+      return false ;
+    }
+    Cellular::NetworkTimeInfo nti(qdt, dst, offset, seconds, nano_seconds, mnc, mcc) ;
+    log_notice("FAKE_CSD::csd_time_s %s", csd_t::csd_network_time_info_to_string(nti).c_str()) ;
+    timed->csd->process_csd_network_time_info(nti) ;
+    return true ;
+  }
+
+  bool fake_csd_time_signal_now(const QString &mcc, const QString &mnc, int offset, int time, int dst)
+  {
+    log_notice("(fake_csd_time_signal_now) mcc='%s' mnc='%s' offset=%d time=%d dst=%d", mcc.toStdString().c_str(), mnc.toStdString().c_str(), offset, time, dst) ;
+    nanotime_t now = nanotime_t::monotonic_now() ;
+    return fake_csd_time_signal(mcc, mnc, offset, time, dst, now.sec(), now.nano()) ;
+  }
+
   bool fake_nitz_signal(int mcc, int offset, int time, int dst)
   {
-    log_debug("(fake) mcc=%d offset=%d time=%d dst=%d", mcc, offset, time, dst) ;
+    log_notice("(fake_nitz_signal) mcc=%d offset=%d time=%d dst=%d", mcc, offset, time, dst) ;
+#if 0
     cellular_handler::object()->fake_nitz_signal(mcc, offset, time, dst) ;
     return true ; // TODO make above method returning bool (not void) and check parameters
+#endif
+    QDateTime qdt = time_t_to_qdatetime((time_t)time) ;
+    if (not qdt.isValid())
+    {
+      log_error("invalid time=%d parameter in in fake_nitz_signal()", time) ;
+      return false ;
+    }
+    nanotime_t now = nanotime_t::monotonic_now() ;
+    QString mcc_s = str_printf("%d", mcc).c_str() ;
+    Cellular::NetworkTimeInfo nti(qdt, dst, offset, now.sec(), now.nano(), "mnc", mcc_s) ;
+    log_notice("FAKE_CSD::csd_time_s %s", csd_t::csd_network_time_info_to_string(nti).c_str()) ;
+    timed->csd->process_csd_network_time_info(nti) ;
+    return true ;
   }
 
   bool fake_operator_signal(const QString &mcc, const QString &mnc)
   {
-    log_debug("(fake) mcc='%s' mnc='%s'", mcc.toStdString().c_str(), mnc.toStdString().c_str()) ;
-    cellular_handler::object()->new_operator(mcc, mnc) ;
+    log_notice("FAKE_CSD::csd_operator_s {mcc='%s', mnc='%s'}", mcc.toStdString().c_str(), mnc.toStdString().c_str()) ;
+    timed->csd->process_csd_network_operator(mcc, mnc) ;
     return true ;
   }
+
+  int get_log_level(const QDBusMessage &message)
+  {
+    log_notice("DBUS::com.nokia.time.get_log_level(return=%d) by %s", qmlog::log_level(), PEER) ;
+    return qmlog::log_level() ;
+  }
+
+  void set_log_level(int n, const QDBusMessage &message)
+  {
+    log_notice("DBUS::com.nokia.time.set_log_level(%d) by %s", n, PEER) ;
+    qmlog::log_level(n) ;
+    log_notice("New log level: %d", qmlog::log_level()) ;
+  }
 } ;
 
 #endif
--- src/server/aegis.cpp
+++ src/server/aegis.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/aegis.h
+++ src/server/aegis.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/backup.cpp
+++ src/server/backup.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -24,6 +24,9 @@
 #include <iodata/iodata>
 #include <iodata/storage>
 
+#include "queue.type.h"
+#include "settings.type.h"
+
 #include "backup.h"
 
 // The directory name, must match the path mentioned in timedbackup.conf:
@@ -108,7 +111,7 @@
   iodata::storage *backup = new iodata::storage ;
 
   backup->set_primary_path(path) ;
-  backup->set_validator(timed->event_queue_type(), "event_queue_t") ;
+  backup->set_validator(events_data_validator(), "event_queue_t") ;
   int res = backup->save(r) ;
 
   delete backup ;
@@ -133,7 +136,7 @@
   iodata::storage *backup = new iodata::storage ;
 
   backup->set_primary_path(backup_queue) ;
-  backup->set_validator(timed->event_queue_type(), "event_queue_t") ;
+  backup->set_validator(events_data_validator(), "event_queue_t") ;
 
   iodata::record *r = backup->load() ;
 
@@ -173,7 +176,7 @@
   iodata::storage *backup = new iodata::storage ;
 
   backup->set_primary_path(path) ;
-  backup->set_validator(timed->settings_file_type(), "settings_t") ;
+  backup->set_validator(settings_data_validator(), "settings_t") ;
   int res = backup->save(r) ;
 
   delete backup ;
--- src/server/backup.h
+++ src/server/backup.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/cellular.cpp
+++ src/server/cellular.cpp
+/***************************************************************************
+**                                                                        **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
+**                                                                        **
+**   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
+**   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
+**   Author: Victor Portnov <ext-victor.portnov at nokia.com>                **
+**                                                                        **
+**     This file is part of Timed                                         **
+**                                                                        **
+**     Timed is free software; you can redistribute it and/or modify      **
+**     it under the terms of the GNU Lesser General Public License        **
+**     version 2.1 as published by the Free Software Foundation.          **
+**                                                                        **
+**     Timed is distributed in the hope that it will be useful, but       **
+**     WITHOUT ANY WARRANTY;  without even the implied warranty  of       **
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               **
+**     See the GNU Lesser General Public License  for more details.       **
+**                                                                        **
+**   You should have received a copy of the GNU  Lesser General Public    **
+**   License along with Timed. If not, see http://www.gnu.org/licenses/   **
+**                                                                        **
+***************************************************************************/
+#include <string>
+#include <sstream>
+using namespace std;
+
+#include <pcrecpp.h>
+#include <qmlog>
+
+#if F_CSD
+#include <NetworkTime>
+#include <NetworkOperator>
+#endif
+
+#include "f.h"
+#include "cellular.h"
+#include "misc.h"
+#include "tzdata.h"
+
+#if F_CSD
+#include "csd.h"
+#endif
+
+cellular_operator_t::cellular_operator_t()
+{
+}
+
+cellular_operator_t::cellular_operator_t(const string &mcc_s, const string &mnc_s) :
+  mcc(mcc_s), mnc(mnc_s)
+{
+  init() ;
+}
+
+#if F_CSD
+cellular_operator_t::cellular_operator_t(const QString &mcc_s, const QString &mnc_s)
+{
+  mcc = mcc_s.toStdString(), mnc = mnc_s.toStdString() ;
+  init() ;
+}
+
+cellular_operator_t::cellular_operator_t(const Cellular::NetworkTimeInfo &cnti)
+{
+  if (cnti.isValid())
+  {
+    mcc = cnti.mcc().toStdString(), mnc = cnti.mnc().toStdString() ;
+    init() ;
+  }
+}
+#endif
+
+bool cellular_operator_t::operator==(const cellular_operator_t &x) const // same mcc & mnc
+{
+  return mcc==x.mcc and mnc==x.mnc ;
+}
+
+bool cellular_operator_t::operator!=(const cellular_operator_t &x) const
+{
+  return not operator==(x) ;
+}
+
+string cellular_operator_t::id() const
+{
+  return empty() ? "" : mcc+"/"+mnc ;
+}
+
+string cellular_operator_t::location() const
+{
+  return known_mcc() ? alpha2 : empty() ? "" : "("+id()+")" ;
+}
+
+bool cellular_operator_t::known_mcc() const
+{
+  return not alpha2.empty() ;
+}
+
+bool cellular_operator_t::empty() const
+{
+  return mcc.empty() and mnc.empty() ;
+}
+
+string cellular_operator_t::str() const
+{
+  ostringstream os ;
+  os << "{mcc=" << "'" << mcc << "'" ;
+  os << ", mnc=" << "'" << mnc << "'" ;
+  if (known_mcc())
+    os << ", location='" << alpha2 << "'" ;
+  os << "}" ;
+  return os.str() ;
+}
+
+void cellular_operator_t::init()
+{
+  alpha2 = tzdata::iso_3166_1_alpha2_by_mcc(mcc) ;
+#if 0
+  static pcrecpp::RE integer = "(\\d+)" ;
+  if (p[0]=='\0') //empty string
+    mcc_value = 0 ;
+  else if (not integer.FullMatch(mcc, &mcc_value))
+    mcc_value = -1 ;
+#endif
+}
+
+cellular_time_t::cellular_time_t() :
+  value(0), ts(0)
+{
+  log_debug("constructed %s by default", str().c_str()) ;
+}
+
+#if F_CSD
+cellular_time_t::cellular_time_t(const Cellular::NetworkTimeInfo &cnti) :
+  value(0), ts(0)
+{
+  if (cnti.isValid() and cnti.dateTime().isValid())
+  {
+    value = cnti.dateTime().toTime_t() ;
+    ts = nanotime_t::from_timespec (*cnti.timestamp()) ;
+  }
+  log_debug("constructed %s out of %s", str().c_str(), csd_t::csd_network_time_info_to_string(cnti).c_str()) ;
+}
+#endif
+
+string cellular_time_t::str() const
+{
+  if (not is_valid())
+    return "{cellular_time_t::invalid}" ;
+  else
+  {
+    ostringstream os ;
+    os << "{value=" << value << "=" << str_iso8601(value) ;
+    os << ", received=" << ts.str() << "}" ;
+    return os.str() ;
+  }
+}
+
+cellular_offset_t::cellular_offset_t() :
+  offset(0), dst(-1), timestamp(0), sender_time(false)
+{
+  log_debug("constructed %s by default", str().c_str()) ;
+}
+
+#if F_CSD
+cellular_offset_t::cellular_offset_t(const Cellular::NetworkTimeInfo &cnti) :
+  oper(cnti),
+  offset(0), dst(-1), timestamp(0), sender_time(false)
+{
+  log_debug() ;
+  if (cnti.isValid())
+  {
+    offset = cnti.offsetFromUtc() ;
+
+    // first of all check, if we can support this offset
+    static const int offset_threshold = 15*3600 ; // 15 hours from Greenwich
+    bool too_large = offset < -offset_threshold or offset_threshold < offset ;
+    bool not_divisible = offset % (15*60) ;
+    if (too_large or not_divisible)
+    {
+      log_error("GMT offset %d seconds is not supported", offset) ;
+      return ;
+    }
+
+    dst = cnti.daylightAdjustment() ;
+
+    if (cnti.dateTime().isValid() and cnti.dateTime().timeSpec()==Qt::UTC)
+    {
+      sender_time = true ;
+      timestamp = cnti.dateTime().toTime_t() ;
+    }
+    else
+    {
+      // the exact moment of sending isn't clear, let's guess it
+      nanotime_t monotonic_received = nanotime_t::from_timespec(*cnti.timestamp()) ;
+      nanotime_t system_received = nanotime_t::systime_at_zero() + monotonic_received ;
+      timestamp = system_received.sec() ;
+    }
+  }
+  log_debug("constructed %s out of %s", str().c_str(), csd_t::csd_network_time_info_to_string(cnti).c_str()) ;
+}
+#endif
+
+string cellular_offset_t::str() const
+{
+  ostringstream os ;
+  if (is_valid())
+  {
+    os << "{offset=" << offset ;
+    if (offset)
+    {
+      int offset_min = offset / 60 ;
+      os << "=" << (offset_min<0 ? (offset_min=-offset_min, "-") : "+") ;
+      int hour = offset_min / 60 ;
+      os << hour ;
+      if (int mins = offset_min % 60)
+        os << str_printf(":%02d", mins) ;
+      else
+        os << "h" ;
+    }
+    os << ", dst=" ;
+    if (dst<0)
+      os << "n/a" ;
+    else
+      os << dst ;
+
+    os << ", " << (sender_time ? "sender" : "receiver") << " time=" << timestamp << "=" << str_iso8601(timestamp) ;
+    os << " by " << oper.str() << "}" ;
+  }
+  else
+    os << "{cellular_offset_t::invalid}" ;
+  return os.str() ;
+}
--- src/server/cellular.h
+++ src/server/cellular.h
+/***************************************************************************
+**                                                                        **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
+**                                                                        **
+**   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
+**   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
+**   Author: Victor Portnov <ext-victor.portnov at nokia.com>                **
+**                                                                        **
+**     This file is part of Timed                                         **
+**                                                                        **
+**     Timed is free software; you can redistribute it and/or modify      **
+**     it under the terms of the GNU Lesser General Public License        **
+**     version 2.1 as published by the Free Software Foundation.          **
+**                                                                        **
+**     Timed is distributed in the hope that it will be useful, but       **
+**     WITHOUT ANY WARRANTY;  without even the implied warranty  of       **
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               **
+**     See the GNU Lesser General Public License  for more details.       **
+**                                                                        **
+**   You should have received a copy of the GNU  Lesser General Public    **
+**   License along with Timed. If not, see http://www.gnu.org/licenses/   **
+**                                                                        **
+***************************************************************************/
+#ifndef MAEMO_TIMED_CELLULAR_H
+#define MAEMO_TIMED_CELLULAR_H
+
+#include <QString>
+
+#include "f.h"
+
+#if F_CSD
+#include <NetworkTime>
+#include <NetworkOperator>
+#endif
+
+#include "timed/nanotime.h"
+
+struct cellular_operator_t
+{
+  std::string mcc, mnc ;
+  std::string alpha2 ;
+  // int mcc_value ; // =0, if mcc="", -1, else if mcc is not a number
+  cellular_operator_t() ;
+  cellular_operator_t(const std::string &mcc_s, const std::string &mnc_s) ;
+#if F_CSD
+  cellular_operator_t(const QString &mcc_s, const QString &mnc_s) ;
+  cellular_operator_t(const Cellular::NetworkTimeInfo &cnti) ;
+#endif
+  bool operator==(const cellular_operator_t &x) const ; // same mcc & mnc
+  bool operator!=(const cellular_operator_t &x) const ; // mcc or mnc differ
+  std::string id() const ; // like "310/07"
+  std::string location() const ; // "FI" or "001/10" for invalid MCC
+  bool known_mcc() const ; // location()==iso_3166_location()
+  bool empty() const ;
+  std::string str() const ;
+private:
+  void init() ;
+} ;
+
+struct cellular_time_t
+{
+  time_t value ;
+  nanotime_t ts ;
+  cellular_time_t() ;
+#if F_CSD
+  cellular_time_t(const Cellular::NetworkTimeInfo &cnti) ;
+#endif
+  bool is_valid() const { return (bool)value ; }
+  std::string str() const ;
+} ;
+
+struct cellular_offset_t
+{
+  cellular_operator_t oper ;
+  int offset ;
+  int dst ;
+  time_t timestamp ;
+  bool sender_time ; // is timestamp received in the same NITZ package as UTC time
+  cellular_offset_t() ;
+#if F_CSD
+  cellular_offset_t(const Cellular::NetworkTimeInfo &cnti) ;
+#endif
+  std::string str() const ;
+  bool is_valid() const { return (bool)timestamp ; }
+} ;
+
+#if 0
+struct cellular_info_t
+{
+  bool flag_offset, flag_time, flag_dst, flag_mcc, flag_mnc ;
+
+  nanotime_t time_at_zero_value, timestamp_value ;
+  int offset_value, dst_value ;
+  int mcc_value ;
+  string mnc_value ;
+
+  bool has_offset() const { return flag_offset ; }
+  bool has_time() const { return flag_time ; }
+  bool has_dst() const { return flag_dst ; }
+  bool has_mcc() const { return flag_mcc ; }
+  bool has_mnc() const { return flag_mnc ; }
+
+  nanotime_t timestamp() const { return timestamp_value ; }
+  int offset() const { log_assert(has_offset()) ; return offset_value ; }
+  nanotime_t time_at_zero() const { log_assert(has_time()) ; return time_at_zero_value ; }
+  int dst() const { log_assert(has_dst()) ; return dst_value ; }
+  int mcc() const { log_assert(has_mcc()) ; return mcc_value ; }
+  string mnc() const { log_assert(has_mnc()) ; return mnc_value ; }
+
+  cellular_info_t()
+  {
+    flag_offset = flag_time = flag_dst = flag_mcc = flag_mnc = false ;
+  } ;
+
+  string to_string() const
+  {
+    ostringstream os ;
+    os << str_printf("{ ts=%d.%09u", timestamp().sec(), timestamp().nano()) ;
+    if(has_mcc())
+      os << ", mcc=" << mcc() ;
+    if(has_mnc())
+      os << ", mnc='" << mnc() << "'" ;
+    if(has_offset())
+      os << ", offset=" << offset() ;
+    if(has_time())
+      os << ", time_at_zero=" << str_printf("%d.%09u", time_at_zero().sec(), time_at_zero().nano()) ;
+    if(has_dst())
+      os << ", dst=" << dst() ;
+    os << "}" ;
+    return os.str() ;
+  }
+} ;
+#endif
+
+#endif//MAEMO_TIMED_CELLULAR_H
--- src/server/cluster.cpp
+++ src/server/cluster.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/cluster.h
+++ src/server/cluster.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/config.type
+++ src/server/config.type
@@ -1,3 +1,5 @@
+_function = "etc_timed_rc_validator",
+
 /*
 
 const_t =
--- src/server/credentials.cpp
+++ src/server/credentials.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -57,6 +57,7 @@
    */
 uint32_t get_name_owner_from_dbus_sync(const QDBusConnection &bus, const QString &name)
 {
+  // TODO make 'dbus_daemon' interface via QDBusAbstractInterface
   QString service   =  "org.freedesktop.DBus" ;
   QString path      = "/org/freedesktop/DBus" ;
   QString interface =  "org.freedesktop.DBus" ;
@@ -155,20 +156,25 @@
   return id_matches and all_dropped ;
 }
 
-credentials_t credentials_t::from_current_process()
+credentials_t credentials_t::from_given_process(pid_t pid)
 {
 #if F_CREDS_AEGIS_LIBCREDS
-  creds_t aegis_creds = creds_gettask(0) ;
+  creds_t aegis_creds = creds_gettask(pid) ;
   credentials_t creds = Aegis::credentials_from_creds_t(aegis_creds) ;
 
   creds_free(aegis_creds) ;
 
   return creds ;
 #else // not F_CREDS_AEGIS_LIBCREDS
-#error credentials_t::from_current_process() is only implemented for F_CREDS_AEGIS_LIBCREDS
+#error credentials_t::from_given_process(pid_t) is only implemented for F_CREDS_AEGIS_LIBCREDS
 #endif
 }
 
+credentials_t credentials_t::from_current_process()
+{
+  return credentials_t::from_given_process(0) ;
+}
+
 // TODO: F_CREDS_UID
 //       implement the same function without aegis, asking UID of the caller and
 //       setting this UID and the caller's default GID as only available credentials
@@ -212,3 +218,17 @@
     tokens.insert(tok->get(i)->str()) ;
 #endif
 }
+
+string credentials_t::str() const
+{
+  ostringstream os ;
+  os << "{uid='" << uid << "', gid='" << gid << "'" ;
+#if F_TOKENS_AS_CREDENTIALS
+  bool first = true ;
+  for (set<string>::const_iterator it=tokens.begin(); it!=tokens.end(); ++it)
+    os << (first ? first=false, ", tokens=[" : ", ") << *it ;
+  os << (first ? "no tokens" : "]") ;
+#endif
+  os << "}" ;
+  return os.str() ;
+}
--- src/server/credentials.h
+++ src/server/credentials.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -54,10 +54,13 @@
   bool apply_and_compare() ; // set the credentials and check if they are really set
 
   static credentials_t from_current_process() ; // get the credentials of the current process
+  static credentials_t from_given_process(pid_t) ; // get the credentials of some other process
   credentials_t(const QDBusMessage &msg) ; // get from dbus client
 
   iodata::record *save() const ;
   credentials_t(const iodata::record *r) ; // load
+
+  std::string str() const ;
 } ;
 
 #endif // CREDENTIALS_H
--- src/server/csd.cpp
+++ src/server/csd.cpp
+/***************************************************************************
+**                                                                        **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
+**                                                                        **
+**   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
+**   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
+**   Author: Victor Portnov <ext-victor.portnov at nokia.com>                **
+**                                                                        **
+**     This file is part of Timed                                         **
+**                                                                        **
+**     Timed is free software; you can redistribute it and/or modify      **
+**     it under the terms of the GNU Lesser General Public License        **
+**     version 2.1 as published by the Free Software Foundation.          **
+**                                                                        **
+**     Timed is distributed in the hope that it will be useful, but       **
+**     WITHOUT ANY WARRANTY;  without even the implied warranty  of       **
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               **
+**     See the GNU Lesser General Public License  for more details.       **
+**                                                                        **
+**   You should have received a copy of the GNU  Lesser General Public    **
+**   License along with Timed. If not, see http://www.gnu.org/licenses/   **
+**                                                                        **
+***************************************************************************/
+#include "f.h"
+
+#include "timed.h"
+
+#include "csd.h"
+
+#if F_CSD
+
+#include <NetworkTime>
+#include <NetworkOperator>
+
+csd_t::csd_t(Timed *owner)
+{
+  timed = owner ;
+  nt = new Cellular::NetworkTime ;
+  op = new Cellular::NetworkOperator ;
+  static const char *time_signal1 = SIGNAL(timeInfoChanged(const NetworkTimeInfo &)) ;
+  static const char *time_signal2 = SIGNAL(timeInfoQueryCompleted(const NetworkTimeInfo &)) ;
+  static const char *time_slot1 = SLOT(csd_time_s(const NetworkTimeInfo &)) ;
+  static const char *time_slot2 = SLOT(csd_time_q(const NetworkTimeInfo &)) ;
+  bool res1 = QObject::connect(nt, time_signal1, this, time_slot1) ;
+  bool res2 = QObject::connect(nt, time_signal2, this, time_slot2) ;
+
+  if(res1 && res2)
+    log_info("succesfully connected to csd time signals") ;
+  else
+    log_error("connection to cellular csd signals failed: %s %s", res1?"":time_signal1, res2?"":time_signal2) ;
+
+  static const char *operator_signal = SIGNAL(operatorChanged(const QString &, const QString &)) ;
+  static const char *operator_slot = SLOT(csd_operator_s(const QString &, const QString &)) ;
+  int res_op = QObject::connect(op, operator_signal, this, operator_slot) ;
+  if(res_op)
+    log_info("succesfully connected to csd network operator signal") ;
+  else
+    log_error("connection to csd network operator signal failed") ;
+
+  nt->queryTimeInfo() ;
+  QMetaObject::invokeMethod(this, "csd_operator_q", Qt::QueuedConnection) ;
+
+  timer = new QTimer ;
+  timer->setSingleShot(true) ;
+  QObject::connect(timer, SIGNAL(timeout()), this, SLOT(wait_for_operator_timeout())) ;
+
+  time = NULL ;
+  offs = NULL ;
+}
+
+csd_t::~csd_t()
+{
+  delete nt ;
+  delete op ;
+  delete timer ;
+  delete offs ;
+  delete time ;
+}
+
+void csd_t::csd_operator_q()
+{
+  QString mcc = op->mcc(), mnc = op->mnc() ;
+  log_notice("CSD::csd_operator_q {mcc='%s', mnc='%s'}", mcc.toStdString().c_str(), mnc.toStdString().c_str()) ;
+  process_csd_network_operator(mcc, mnc) ;
+}
+
+void csd_t::csd_operator_s(const QString &mnc, const QString &mcc)
+{
+  log_notice("CSD::csd_operator_s {mcc='%s', mnc='%s'}", mcc.toStdString().c_str(), mnc.toStdString().c_str()) ;
+  process_csd_network_operator(mcc, mnc) ;
+}
+
+void csd_t::csd_time_q(const Cellular::NetworkTimeInfo &nti)
+{
+  log_notice("CSD::csd_time_q %s", csd_network_time_info_to_string(nti).c_str()) ;
+  process_csd_network_time_info(nti) ;
+}
+
+void csd_t::csd_time_s(const Cellular::NetworkTimeInfo &nti)
+{
+  log_notice("CSD::csd_time_s %s", csd_network_time_info_to_string(nti).c_str()) ;
+  process_csd_network_time_info(nti) ;
+}
+
+void csd_t::input_csd_network_time_info(const Cellular::NetworkTimeInfo &nti)
+{
+  timer->stop() ;
+  cellular_time_t new_time(nti) ;
+  if (offs)
+    delete offs ;
+  offs = new cellular_offset_t(nti) ;
+  if (new_time.is_valid())
+  {
+    if (time)
+      delete time ;
+    time = new cellular_time_t(new_time) ;
+  }
+}
+
+void csd_t::output_csd_network_time_info()
+{
+  timer->stop() ; // paranoia
+  if (offs)
+  {
+    emit csd_cellular_offset(*offs) ;
+    delete offs ;
+    offs = NULL ;
+  }
+  if (time)
+  {
+    emit csd_cellular_time(*time) ;
+    delete time ;
+    time = NULL ;
+  }
+}
+
+const nanotime_t csd_t::old_nitz_threshold(2,0) ;
+
+void csd_t::process_csd_network_time_info(const Cellular::NetworkTimeInfo &nti)
+{
+  if (not nti.isValid())
+  {
+    log_notice("empty time info, ignoring it") ;
+    return ;
+  }
+  nanotime_t actuality = nanotime_t::monotonic_now() - nanotime_t::from_timespec (*nti.timestamp()) ;
+  input_csd_network_time_info(nti) ;
+
+  // Decide if the data is to be sent immediately or to wait for operator change signal
+  bool current_operator = offs->oper.mcc == oper.mcc and offs->oper.mnc == oper.mnc ;
+  bool empty_operator = offs->oper.mcc.empty() and offs->oper.mnc.empty() ;
+  bool input_is_old = actuality > old_nitz_threshold ;
+  bool send_now = input_is_old or (current_operator and not empty_operator) ;
+
+  log_debug("offs->oper=%s, oper=%s, actuality=%s", offs->oper.str().c_str(), oper.str().c_str(), actuality.str().c_str()) ;
+  log_debug("current_operator=%d, empty_operator=%d, input_is_old=%d", current_operator, empty_operator, input_is_old) ;
+  log_debug("send_now=%d", send_now) ;
+
+  if (send_now)
+    output_csd_network_time_info() ;
+  else
+    timer->start(operator_wait_ms) ;
+}
+
+void csd_t::process_csd_network_operator(const QString &mcc, const QString &mnc)
+{
+  timer->stop() ;
+  oper = cellular_operator_t(mcc, mnc) ;
+  if (offs)
+    offs->oper = oper ;
+  output_csd_network_time_info() ; // if needed
+  emit csd_cellular_operator(oper) ;
+}
+
+void csd_t::wait_for_operator_timeout() // timer slot
+{
+  timer->stop() ; // paranoia
+  output_csd_network_time_info() ; // probably needed
+}
+
+string csd_t::csd_network_time_info_to_string(const Cellular::NetworkTimeInfo &nti)
+{
+  if (not nti.isValid())
+    return "{invalid}" ;
+
+  ostringstream os ;
+
+  os << "{zone=" << nti.offsetFromUtc() ;
+
+  QDateTime t = nti.dateTime() ;
+  if (t.isValid())
+  {
+    string utc = str_printf("%04d-%02d-%02d,%02d:%02d:%02d", t.date().year(), t.date().month(), t.date().day(), t.time().hour(), t.time().minute(), t.time().second())  ;
+    os << ", utc=" << utc ;
+  }
+
+  int dst = nti.daylightAdjustment() ;
+  if (dst!=-1)
+    os << ", dst=" << dst ;
+
+  os << ", mcc='" << nti.mcc().toStdString() << "'" ;
+  os << ", mnc='" << nti.mnc().toStdString() << "'" ;
+
+  os << ", received=" << str_printf("%lld.%09lu", (long long)nti.timestamp()->tv_sec, nti.timestamp()->tv_nsec) ;
+
+  os << "}" ;
+
+  return os.str() ;
+}
+#endif//F_CSD
--- src/server/csd.h
+++ src/server/csd.h
+/***************************************************************************
+**                                                                        **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
+**                                                                        **
+**   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
+**   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
+**   Author: Victor Portnov <ext-victor.portnov at nokia.com>                **
+**                                                                        **
+**     This file is part of Timed                                         **
+**                                                                        **
+**     Timed is free software; you can redistribute it and/or modify      **
+**     it under the terms of the GNU Lesser General Public License        **
+**     version 2.1 as published by the Free Software Foundation.          **
+**                                                                        **
+**     Timed is distributed in the hope that it will be useful, but       **
+**     WITHOUT ANY WARRANTY;  without even the implied warranty  of       **
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               **
+**     See the GNU Lesser General Public License  for more details.       **
+**                                                                        **
+**   You should have received a copy of the GNU  Lesser General Public    **
+**   License along with Timed. If not, see http://www.gnu.org/licenses/   **
+**                                                                        **
+***************************************************************************/
+#ifndef MAEMO_TIMED_CSD_H
+#define MAEMO_TIMED_CSD_H
+
+#include "f.h"
+
+#if F_CSD
+
+#include <string>
+
+#include <QTimer>
+
+#include <NetworkTime>
+#include <NetworkOperator>
+using Cellular::NetworkTimeInfo ;
+
+#include "timed/nanotime.h"
+
+#include "cellular.h"
+
+class Timed ;
+
+struct csd_t : public QObject
+{
+  Q_OBJECT ;
+  static const nanotime_t old_nitz_threshold ;
+  static const int operator_wait_ms = 1000 ;
+  Timed *timed ;
+  Cellular::NetworkTime *nt ;
+  Cellular::NetworkOperator *op ;
+  Q_INVOKABLE void csd_operator_q() ;
+  QTimer *timer ;
+  cellular_time_t *time ;
+  cellular_offset_t *offs ;
+  cellular_operator_t oper ;
+Q_SIGNALS:
+  void csd_cellular_time(const cellular_time_t) ;
+  void csd_cellular_offset(const cellular_offset_t) ;
+  void csd_cellular_operator(const cellular_operator_t) ;
+private Q_SLOTS:
+  void csd_time_q(const NetworkTimeInfo &nti) ;
+  void csd_time_s(const NetworkTimeInfo &nti) ;
+  void csd_operator_s(const QString &mnc, const QString &mcc) ;
+  void wait_for_operator_timeout() ;
+private:
+  void process_csd_network_time_info(const NetworkTimeInfo &nti) ;
+  void process_csd_network_operator(const QString &mcc, const QString &mnc) ;
+  friend class com_nokia_time ; // these private functions can be used by dbus fake
+private:
+  void input_csd_network_time_info(const NetworkTimeInfo &nti) ;
+  void output_csd_network_time_info() ;
+
+public:
+  csd_t(Timed *owner) ;
+  static std::string csd_network_time_info_to_string(const NetworkTimeInfo &nti) ;
+  virtual ~csd_t() ;
+} ;
+
+#endif//F_CSD
+
+#endif//MAEMO_TIMED_CSD_H
--- src/server/customization.cpp
+++ src/server/customization.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/customization.h
+++ src/server/customization.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/customization.type
+++ src/server/customization.type
@@ -1,3 +1,5 @@
+_function = "customization_data_validator",
+
 customization_t =
 [
   { name = "format24", type = $bytes, value = "True" },
--- src/server/event.cpp
+++ src/server/event.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -603,11 +603,14 @@
       int bus = (a.flags & ActionFlags::Use_System_Bus) ? 0 : 1 ;
       QDBusConnection * &c = conn[bus] ;
 
+      log_debug() ;
       if (c==NULL) // not used yes, have to create object and connect
       {
         QDBusConnection::BusType ctype = bus==0 ? QDBusConnection::SystemBus : QDBusConnection::SessionBus ;
+        log_debug() ;
         c = new QDBusConnection(QDBusConnection::connectToBus(ctype, cname)) ;
       }
+      log_debug() ;
 
       if (c->send(message))
         log_debug("%u[%d]: D-Bus Message sent", cookie.value(), acts_i) ;
@@ -752,7 +755,9 @@
 
 pid_t event_t::fork_and_set_credentials_v3(const action_t &action)
 {
+  log_debug("forking for action execution") ;
   pid_t pid = fork() ;
+  log_debug("fork() returned %d", pid) ;
 
   if (pid<0) // can't fork
   {
@@ -775,9 +780,11 @@
       throw event_exception("can't detach from session") ;
     }
 
+    log_debug() ;
     if (!drop_privileges(action))
       throw event_exception("can't drop privileges") ;
 
+    log_debug() ;
     if (!accrue_privileges(action))
       log_warning("can't accrue privileges, still continuing") ;
 
@@ -788,6 +795,7 @@
 
     // That's it then, isn't it?
 
+    log_notice("set credentais to %s", credentials_t::from_current_process().str().c_str()) ;
     return pid ;
   }
 }
--- src/server/event.h
+++ src/server/event.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/f.h
+++ src/server/f.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -31,11 +31,13 @@
 
 #if __HARMATTAN__
 #  define F_CREDS_AEGIS_LIBCREDS 1
-#  define F_CELLULAR_QT 1
+#  define F_CSD 1
 #  define F_SCRATCHBOX 1
 #  define F_ACTING_DEAD 1
 #  define F_IMAGE_TYPE 1
+#  define F_HOME_LOG 1
 #  define F_FORCE_DEBUG_PATH "/var/cache/timed/DEBUG"
+#  define F_FORCE_HOME_LOG_PATH "/var/cache/timed/HOME_LOG"
 #endif
 
 #if F_CREDS_AEGIS_LIBCREDS
--- src/server/flags.h
+++ src/server/flags.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/interfaces.h
+++ src/server/interfaces.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/machine.cpp
+++ src/server/machine.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -290,8 +290,9 @@
       continue ;
     }
     abstract_state_t *old_state = e->get_state() ;
-    log_assert(new_state!=old_state, "New state is the same as the old one (%s)", old_state->name()) ;
     log_notice("State transition %d:'%s'->'%s'", e->cookie.value(), state_name(old_state), state_name(new_state)) ;
+    if (new_state==old_state)
+      log_critical("Event %d: new_state=old_state='%s'", e->cookie.value(), old_state->name()) ;
 #undef state_name
     if(old_state)
       old_state->leave(e) ;
@@ -640,6 +641,23 @@
   }
 }
 
+void machine_t::cancel_events(const QList<uint> &cookies, QList<uint> &failed)
+{
+  pause_t x(this) ;
+  set<unsigned> done ;
+  for (int i=0; i<cookies.size(); ++i)
+  {
+    unsigned ci = cookies[i] ;
+    cookie_t c(ci) ;
+    if (done.count(ci)>0)
+      continue ;
+    done.insert(ci) ;
+    if (not cancel_by_cookie(c))
+      failed.append(ci) ;
+  }
+}
+
+
 void machine_t::cancel_event(event_t *e)
 {
   // TODO: assert (queue is paused)
--- src/server/machine.h
+++ src/server/machine.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -70,6 +70,7 @@
   void query(const QMap<QString,QVariant> &words, QList<QVariant> &res ) ;
   void get_event_attributes(cookie_t c, QMap<QString,QVariant> &a) ;
   bool cancel_by_cookie(cookie_t c) ;
+  void cancel_events(const QList<uint> &cookies, QList<uint> &failed) ;
   void cancel_event(event_t *e) ;
   event_t *find_event(cookie_t c) ;
   void alarm_gate(bool open) ;
--- src/server/main.cpp
+++ src/server/main.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -72,6 +72,16 @@
   qmlog::log_file *varlog = new qmlog::log_file(log_file, varlog_level) ;
   varlog->enable_fields(qmlog::Monotonic_Milli | qmlog::Time_Milli) ;
 
+#if F_HOME_LOG
+  bool log_file_at_home = access(F_FORCE_HOME_LOG_PATH, F_OK) == 0 ;
+  if (log_file_at_home)
+  {
+    system("touch /home/user/MyDocs/timed.log") ;
+    qmlog::log_file *home = new qmlog::log_file("/home/user/MyDocs/timed.log", varlog_level) ;
+    home->enable_fields(qmlog::Monotonic_Milli | qmlog::Time_Milli | qmlog::Close_After_Write | qmlog::Cache_If_Cant_Open | qmlog::Dont_Create_File | qmlog::Retry_If_Failed) ;
+  }
+#endif
+
   bool isatty_2 = isatty(2) ;
 
   if (not isatty_2 or cwd_is_root) // stderr is not a terminal or started by upstart -> no stderr logging
--- src/server/misc.cpp
+++ src/server/misc.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -73,6 +73,15 @@
   }
 }
 
+string str_iso8601(time_t t) // 2008-05-11T15:30:00Z
+{
+  struct tm tm ;
+  if (gmtime_r(&t, &tm)!=&tm)
+    return "n/a" ;
+  else
+    return str_printf("%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec) ;
+}
+
 string str_printf(const char *format, ...)
 {
   const int buf_len = 1024, max_buf_len = buf_len*1024 ;
--- src/server/misc.h
+++ src/server/misc.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -40,6 +40,7 @@
 void map_q_to_std(const QMap<QString, QString> &from, std::map<std::string, std::string> &to) ;
 void map_std_to_q(const std::map<std::string, std::string> &from, QMap<QString, QString> &to) ;
 
+std::string str_iso8601(time_t t) ;
 std::string str_printf(const char *format, ...) __attribute__((format(printf,1,2))) ;
 
 inline int n_bits_64(uint64_t x)
--- src/server/olson.cpp
+++ src/server/olson.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -28,6 +28,7 @@
 #include <qmlog>
 
 #include "timeutil.h"
+#include "misc.h"
 #include "olson.h"
 
 map<string, olson*> *olson::zonetab = NULL ;
@@ -46,6 +47,27 @@
   return it->second ;
 }
 
+olson *olson::by_offset(int offset)
+{
+  int min15 = 15*60, units = offset/min15 ;
+  if (offset%min15)
+  {
+    log_error("can't find a time zone by offset=%d (not divisible by 15min unit)", offset) ;
+    return NULL ;
+  }
+  if (units < -60 || 60 < units)
+  {
+    log_error("can't find a time zone by offset=%d (exceeds 15h boundary)", offset) ;
+    return NULL ;
+  }
+  int sec = offset ;
+  char sign = sec<0 ? (sec=-sec, '-') : '+' ;
+  int m = sec/60, hour = m/60, min = m%60 ;
+  string name = str_printf("Iso8601/%c%02d%02d", sign, hour, min) ;
+  log_info("mapping offset=%d to zone '%s'", offset, name.c_str()) ;
+  return by_name(name) ;
+}
+
 bool olson::match(time_t at, int offset, int dst_flag)
 {
   switch_timezone xx(zone_name) ;
--- src/server/olson.h
+++ src/server/olson.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -37,6 +37,7 @@
 public:
   std::string name() { return zone_name ; }
   static olson *by_name(const std::string &) ;
+  static olson *by_offset(int offset) ;
   static void destructor() ;
   bool match(time_t at, int offset, int dst_flag) ;
 } ;
--- src/server/onitz.cpp
+++ src/server/onitz.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -34,7 +34,8 @@
 
 cellular_handler::cellular_handler()
 {
-#if F_CELLULAR_QT
+#if 0
+#if F_CSD
   cnt = new Cellular::NetworkTime ;
   cop = new Cellular::NetworkOperator ;
   const char *signal1 = SIGNAL(timeInfoChanged(const NetworkTimeInfo &)) ;
@@ -58,16 +59,19 @@
   cnt->queryTimeInfo() ;
   QMetaObject::invokeMethod(this, "emulate_operator_signal", Qt::QueuedConnection) ;
 #endif
+#endif
 }
 
+#if 0
 void cellular_handler::emulate_operator_signal()
 {
-#if F_CELLULAR_QT
+#if F_CSD
   log_debug() ;
   new_operator(cop->mnc(), cop->mcc()) ;
   log_debug() ;
 #endif
 }
+#endif
 
 cellular_handler *cellular_handler::static_object = NULL ;
 
@@ -88,10 +92,13 @@
 
 cellular_handler::~cellular_handler()
 {
+#if 0
   delete cop ;
   delete cnt ;
+#endif
 }
 
+#if 0
 void cellular_handler::fake_nitz_signal(int mcc, int offset, int time, int dst)
 {
   log_debug("fake nitz requested: mcc=%d offset=%d, time=%d, dst=%d", mcc, offset, time, dst) ;
@@ -118,9 +125,10 @@
   emit cellular_data_received(ci) ;
   log_debug() ;
 }
+#endif
 
-
-#if F_CELLULAR_QT
+#if 0
+#if F_CSD
 void cellular_handler::new_nitz_signal(const NetworkTimeInfo &cnti)
 {
   log_debug() ;
@@ -193,7 +201,9 @@
   log_debug() ;
 }
 #endif
+#endif
 
+#if 0
 void cellular_handler::new_operator(const QString &mnc, const QString &mcc)
 {
   log_debug("mnc='%s', mcc='%s'", string_q_to_std(mnc).c_str(), string_q_to_std(mcc).c_str()) ;
@@ -224,3 +234,4 @@
   emit cellular_data_received(ci) ;
   log_debug() ;
 }
+#endif
--- src/server/onitz.h
+++ src/server/onitz.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -35,7 +35,7 @@
 
 #include <qmlog>
 
-#if F_CELLULAR_QT
+#if F_CSD
 #  include <NetworkTime>
 #  include <NetworkOperator>
 using Cellular::NetworkTimeInfo ;
@@ -46,6 +46,8 @@
 
 #include "misc.h"
 
+#include "cellular.h"
+#if 0
 struct cellular_info_t
 {
   bool flag_offset, flag_time, flag_dst, flag_mcc, flag_mnc ;
@@ -91,6 +93,7 @@
     return os.str() ;
   }
 } ;
+#endif
 
 struct cellular_handler : public QObject
 {
@@ -98,23 +101,33 @@
 private:
   static cellular_handler *static_object ;
   virtual ~cellular_handler() ;
-#if F_CELLULAR_QT
+#if 0
+#if F_CSD
   Cellular::NetworkTime *cnt ;
   Cellular::NetworkOperator *cop ;
 #endif
+#endif
   cellular_handler() ;
+#if 0
   Q_INVOKABLE void emulate_operator_signal() ;
+#endif
+
 signals:
+#if 0
   void cellular_data_received(const cellular_info_t &) ;
+#endif
+
 public:
   static cellular_handler *object() ;
   static void uninitialize() ;
   void fake_nitz_signal(int mcc, int offset, int time, int dst) ;
 public slots:
-#if F_CELLULAR_QT
+#if 0
+#if F_CSD
   void new_nitz_signal(const NetworkTimeInfo &) ; // { log_assert(false, "to be implemented") ; }
 #endif
   void new_operator(const QString &mnc, const QString &mcc) ;
+#endif
 } ;
 
 #endif
--- src/server/peer.cpp
+++ src/server/peer.cpp
+/***************************************************************************
+**                                                                        **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
+**                                                                        **
+**   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
+**   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
+**   Author: Victor Portnov <ext-victor.portnov at nokia.com>                **
+**                                                                        **
+**     This file is part of Timed                                         **
+**                                                                        **
+**     Timed is free software; you can redistribute it and/or modify      **
+**     it under the terms of the GNU Lesser General Public License        **
+**     version 2.1 as published by the Free Software Foundation.          **
+**                                                                        **
+**     Timed is distributed in the hope that it will be useful, but       **
+**     WITHOUT ANY WARRANTY;  without even the implied warranty  of       **
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               **
+**     See the GNU Lesser General Public License  for more details.       **
+**                                                                        **
+**   You should have received a copy of the GNU  Lesser General Public    **
+**   License along with Timed. If not, see http://www.gnu.org/licenses/   **
+**                                                                        **
+***************************************************************************/
+#include <QDBusPendingReply>
+
+
+#include <qmlog>
+
+#include <timed/interface>
+#include "credentials.h"
+
+#include "misc.h"
+#include "peer.h"
+
+#if 0
+pid_t peer::pid_by_dbus_message(const QDBusMessage &message)
+{
+  QString sender = message.service() ;
+  uint32_t owner_id = get_name_owner_from_dbus_sync(Maemo::Timed::bus(), sender) ;
+
+  if (owner_id == ~0u)
+  {
+    log_warning("can't get owner (pid) of the caller, already terminated?") ;
+    return -1 ;
+  }
+
+  pid_t pid = owner_id ;
+  return pid ;
+}
+#endif
+
+static string cmdline_by_pid(pid_t pid)
+{
+  const int max_len = 1024 ;
+  char buf[max_len+1] = "<no-cmd-line>" ;
+  if(FILE *fp = fopen(str_printf("/proc/%d/cmdline", pid).c_str(), "r"))
+  {
+    size_t n = fread(buf, 1, max_len,fp) ;
+    if (n>0)
+    {
+      buf[n]='\0' ;
+      for (unsigned i=0; i+1<n; ++i)
+        if (not buf[i])
+          buf[i]=' ' ;
+    }
+    fclose(fp) ;
+  }
+  return (string) buf ;
+}
+
+#if 0
+string peer::info_by_dbus_message(const QDBusMessage &message)
+{
+  pid_t pid = peer::pid_by_dbus_message(message) ;
+  ostringstream os ;
+  os << "{cmd='" << cmdline_by_pid(pid) << "', pid=" << pid << ", cred=" ;
+  os << credentials_t::from_given_process(pid).str() << "}" ;
+  return os.str() ;
+}
+#endif
+
+peer_t::peer_t(bool mode)
+{
+  enabled = mode ;
+}
+
+peer_t::~peer_t()
+{
+  for (map<string, peer_entry_t*>::const_iterator it=entries.begin(); it!=entries.end(); ++it)
+    delete it->second ;
+}
+
+string peer_t::info(const string &name)
+{
+  const peer_entry_t *entry = NULL ;
+  if (enabled)
+  {
+    map<string, peer_entry_t*>::const_iterator it = entries.find(name) ;
+    if (it!=entries.end())
+      entry = it->second ;
+    else
+      entry = entries[name] = new peer_entry_t(name) ;
+  }
+  return str_printf("PEER::%s %s", name.c_str(), entry ? entry->get_info().c_str() : "DISABLED") ;
+}
+
+peer_entry_t::peer_entry_t(const string &new_name, QObject *parent) :
+  QObject(parent), name(new_name)
+{
+  QString service   =  "org.freedesktop.DBus" ;
+  QString path      = "/org/freedesktop/DBus" ;
+  QString interface =  "org.freedesktop.DBus" ;
+  QString method    = "GetConnectionUnixProcessID" ;
+  QDBusMessage req  = QDBusMessage::createMethodCall(service, path, interface, method) ;
+  req << (QString)name.c_str() ;
+
+  watcher = new QDBusPendingCallWatcher(Maemo::Timed::bus().asyncCall(req)) ;
+  bool ok = QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(reply_slot(QDBusPendingCallWatcher*))) ;
+  log_assert(ok, "oops, connection failed in peer_entry_t contructor") ;
+}
+
+void peer_entry_t::reply_slot(QDBusPendingCallWatcher *w)
+{
+  if (w!=watcher)
+    log_critical("QDBusPendingCallWatcher mismatch: w=%p, watcher=%p", w, watcher) ;
+  QDBusPendingReply<uint> reply = *w ;
+  if (reply.isError())
+  {
+    QDBusError e = reply.error() ;
+#define QC toStdString().c_str()
+    info = str_printf("ERROR: [name='%s', message='%s', type=%d]", e.name().QC, e.message().QC, e.type()) ;
+#undef QC
+  }
+  else
+  {
+    uint unix_process_id = reply.value() ;
+    if (unix_process_id==~0)
+      info = str_printf("pid: unknown") ;
+    else
+    {
+      pid_t pid = unix_process_id ;
+      string cmd_line = cmdline_by_pid(pid) ;
+      credentials_t cred = credentials_t::from_given_process(pid) ;
+      info = str_printf("pid=%d, cmdline='%s', creds=%s", pid, cmd_line.c_str(), cred.str().c_str()) ;
+    }
+  }
+  delete watcher ;
+  watcher = NULL ;
+  log_notice("PEER::%s %s", name.c_str(), info.c_str()) ;
+}
+
+peer_entry_t::~peer_entry_t()
+{
+  delete watcher ;
+}
--- src/server/peer.h
+++ src/server/peer.h
+/***************************************************************************
+**                                                                        **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
+**                                                                        **
+**   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
+**   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
+**   Author: Victor Portnov <ext-victor.portnov at nokia.com>                **
+**                                                                        **
+**     This file is part of Timed                                         **
+**                                                                        **
+**     Timed is free software; you can redistribute it and/or modify      **
+**     it under the terms of the GNU Lesser General Public License        **
+**     version 2.1 as published by the Free Software Foundation.          **
+**                                                                        **
+**     Timed is distributed in the hope that it will be useful, but       **
+**     WITHOUT ANY WARRANTY;  without even the implied warranty  of       **
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               **
+**     See the GNU Lesser General Public License  for more details.       **
+**                                                                        **
+**   You should have received a copy of the GNU  Lesser General Public    **
+**   License along with Timed. If not, see http://www.gnu.org/licenses/   **
+**                                                                        **
+***************************************************************************/
+#ifndef MAEMO_TIMED_PEER_H
+#define MAEMO_TIMED_PEER_H
+
+#include <string>
+#include <QDBusMessage>
+#include <QDBusPendingCallWatcher>
+
+struct peer_t ;
+struct peer_entry_t ;
+
+struct peer_t
+{
+  peer_t(bool mode) ;
+  ~peer_t() ;
+  std::string info(const std::string &) ;
+private:
+  bool enabled ;
+  std::map<std::string, peer_entry_t*> entries ;
+} ;
+
+struct peer_entry_t : public QObject
+{
+  peer_entry_t(const std::string &new_name, QObject *parent=NULL) ;
+  virtual ~peer_entry_t() ;
+  bool is_pending() const { return watcher != NULL ; }
+  std::string get_info() const { return info ; }
+
+  std::string name, info ;
+  QDBusPendingCallWatcher *watcher ;
+
+  Q_OBJECT ;
+private Q_SLOTS:
+  void reply_slot(QDBusPendingCallWatcher *w) ;
+} ;
+
+#if 0
+namespace peer
+{
+  pid_t pid_by_dbus_message(const QDBusMessage &message) ;
+  std::string cmdline_by_pid(pid_t pid) ;
+  std::string info_by_dbus_message(const QDBusMessage &message) ;
+}
+#endif
+#endif//MAEMO_TIMED_PEER_H
--- src/server/pinguin.h
+++ src/server/pinguin.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/queue.type
+++ src/server/queue.type
@@ -1,3 +1,5 @@
+_function = "events_data_validator",
+
 event_queue_t =
 [
  { name = "next_cookie",    type = $integer, value = 1 },
--- src/server/server.pro
+++ src/server/server.pro
@@ -12,8 +12,10 @@
 LIBS += -ltimed -ltimed-voland
 CONFIG += qmlog
 
-HEADERS += interfaces.h adaptor.h timed.h state.h cluster.h machine.h singleshot.h pinguin.h unix-signal.h onitz.h
-SOURCES += cluster.cpp machine.cpp state.cpp main.cpp timed.cpp timeutil.cpp event.cpp misc.cpp settings.cpp unix-signal.cpp onitz.cpp
+IODATA_TYPES = queue.type config.type settings.type customization.type tzdata.type
+
+HEADERS += peer.h settings.h csd.h interfaces.h adaptor.h timed.h state.h cluster.h machine.h singleshot.h pinguin.h unix-signal.h onitz.h
+SOURCES += peer.cpp tzdata.cpp cellular.cpp csd.cpp cluster.cpp machine.cpp state.cpp main.cpp timed.cpp timeutil.cpp event.cpp misc.cpp settings.cpp unix-signal.cpp onitz.cpp
 
 SOURCES += credentials.cpp aegis.cpp
 HEADERS += credentials.h
@@ -32,8 +34,8 @@
 xml.files  = com.nokia.time.context
 xml.path = $$(DESTDIR)/usr/share/contextkit/providers
 
-typeinfo.files = queue.type config.type settings.type customization.type tzdata.type timed-cust-rc.type
-typeinfo.path = $$(DESTDIR)/usr/share/timed/typeinfo
+# typeinfo.files = queue.type config.type settings.type customization.type tzdata.type timed-cust-rc.type
+# typeinfo.path = $$(DESTDIR)/usr/share/timed/typeinfo
 
 backupconf.files = timedbackup.conf
 backupconf.path = $$(DESTDIR)/usr/share/backup-framework/applications
@@ -44,7 +46,7 @@
 rfs.files = timed-restore-original-settings.sh
 rfs.path = $$(DESTDIR)/etc/osso-rfs-scripts
 
-INSTALLS += target xml typeinfo backupconf cud rfs
+INSTALLS += target xml backupconf cud rfs
 
 CONFIG(MEEGO) \
 {
--- src/server/settings.cpp
+++ src/server/settings.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -89,7 +89,7 @@
   return r ;
 }
 
-source_settings::source_settings(Timed *owner)
+source_settings::source_settings(Timed *owner) : QObject(owner)
 {
   log_debug() ;
   o = owner ;
@@ -654,6 +654,33 @@
   log_debug("Time change: %s", log.str().c_str()) ;
 }
 
+void source_settings::cellular_time_slot(const cellular_time_t &T)
+{
+  nanotime_t time_at_zero = nanotime_t(T.value) - T.ts ;
+  log_debug("time_at_zero=%s, (T=%s)", time_at_zero.str().c_str(), T.str().c_str()) ;
+  nitz_utc->value = time_at_zero ;
+  if(time_nitz) // we want to use nitz as time source
+  {
+    set_system_time(nitz_utc->value_at_zero()) ;
+    o->open_epoch() ;
+  }
+}
+
+void source_settings::cellular_zone_slot(olson *tz, suggestion_t s, bool sure)
+{
+  (void) sure ;
+  log_debug("time zone '%s' magicaly detected", tz->name().c_str()) ;
+  cellular_zone->value = tz->name() ;
+  cellular_zone->suggestions = s ;
+  if(local_cellular)
+  {
+    fix_etc_localtime() ;
+    // TODO: update_oracle_context(true) ;
+  }
+  o->invoke_signal() ;
+}
+
+#if 0
 void source_settings::cellular_information(const cellular_info_t &ci)
 {
   log_debug() ;
@@ -668,3 +695,4 @@
     }
   }
 }
+#endif
--- src/server/settings.h
+++ src/server/settings.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -130,12 +130,13 @@
 struct cellular_zone_t : public zone_source_t
 {
   virtual ~cellular_zone_t() { }
-  tz_suggestions_t suggestions ;
+  suggestion_t suggestions ;
   const char *name() const { return "cellular_zone" ; }
   // void load(const iodata::record *) ;
   // iodata::record *save() const ;
 } ;
 
+#if 0
 // TODO: remove this?
 struct customization_settings
 {
@@ -160,8 +161,9 @@
   static QByteArray get_hash();
 
 };
+#endif
 
-struct source_settings
+struct source_settings : public QObject
 {
   source_settings(Timed *owner) ;
   virtual ~source_settings() ;
@@ -205,8 +207,13 @@
   void postload_fix_manual_zone() ;
   void postload_fix_manual_offset() ;
 
+#if 0
   void cellular_information(const cellular_info_t &ci) ;
-
+#endif
+  Q_OBJECT ;
+public Q_SLOTS:
+  void cellular_time_slot(const cellular_time_t &T) ;
+  void cellular_zone_slot(olson *tz, suggestion_t s, bool sure) ;
 } ;
 
 #endif
--- src/server/settings.type
+++ src/server/settings.type
@@ -1,3 +1,5 @@
+_function = "settings_data_validator",
+
 settings_t =
 [
   // The value '-1' means: use default value given by customization
--- src/server/singleshot.h
+++ src/server/singleshot.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/state.cpp
+++ src/server/state.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/state.h
+++ src/server/state.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/timed.cpp
+++ src/server/timed.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -36,12 +36,19 @@
 #include <timed/interface>
 #include <qmlog>
 
+#include "queue.type.h"
+#include "config.type.h"
+#include "customization.type.h"
+#include "settings.type.h"
+
 #include "interfaces.h"
 #include "adaptor.h"
 #include "backup.h"
 #include "timed.h"
 #include "settings.h"
 #include "tz.h"
+#include "tzdata.h"
+#include "csd.h"
 
 static void spam()
 {
@@ -83,6 +90,9 @@
   init_unix_signal_handler() ;
   log_debug() ;
 
+  init_dbus_peer_info() ;
+  log_debug() ;
+
   init_scratchbox_mode() ;
   log_debug() ;
 
@@ -145,6 +155,13 @@
   signal_object->handle(SIGCHLD) ;
 }
 
+// * Enable questioning of Dbus peers
+void Timed::init_dbus_peer_info()
+{
+  // TODO: make it depening on qmlog::enabled() ?
+  peer =  new peer_t(true) ;
+}
+
 // * Condition "running inside of scratchbox" is detected
 void Timed::init_scratchbox_mode()
 {
@@ -276,7 +293,7 @@
 {
   iodata::storage *config_storage = new iodata::storage ;
   config_storage->set_primary_path(configuration_path()) ;
-  config_storage->set_validator(configuration_type(), "config_t") ;
+  config_storage->set_validator(etc_timed_rc_validator(), "config_t") ;
 
   iodata::record *c = config_storage->load() ;
   log_assert(c, "loading configuration settings failed") ;
@@ -310,7 +327,7 @@
 {
   iodata::storage *storage = new iodata::storage ;
   storage->set_primary_path(customization_path()) ;
-  storage->set_validator(customization_type(), "customization_t") ;
+  storage->set_validator(customization_data_validator(), "customization_t") ;
 
   iodata::record *c = storage->load() ;
   log_assert(c, "loading customization settings failed") ;
@@ -343,7 +360,7 @@
   settings_storage = new iodata::storage ;
   settings_storage->set_primary_path(settings_path) ;
   settings_storage->set_secondary_path(settings_path+".bak") ;
-  settings_storage->set_validator(settings_file_type(), "settings_t") ;
+  settings_storage->set_validator(settings_data_validator(), "settings_t") ;
 
   iodata::record *tree = settings_storage->load() ;
 
@@ -489,7 +506,7 @@
   event_storage = new iodata::storage ;
   event_storage->set_primary_path(events_path) ;
   event_storage->set_secondary_path(events_path+".bak") ;
-  event_storage->set_validator(event_queue_type(), "event_queue_t") ;
+  event_storage->set_validator(events_data_validator(), "event_queue_t") ;
 
   iodata::record *events = event_storage->load() ;
 
@@ -512,13 +529,29 @@
 
 void Timed::init_cellular_services()
 {
-  cellular_handler *nitz_object = cellular_handler::object() ;
+#if 0
+  nitz_object = cellular_handler::object() ;
   int nitzrez = QObject::connect(nitz_object, SIGNAL(cellular_data_received(const cellular_info_t &)), this, SLOT(nitz_notification(const cellular_info_t &))) ;
   log_debug("nitzrez=%d", nitzrez) ;
-
+#endif
+  tzdata::init(tz_by_default) ;
+  csd = new csd_t(this) ;
   tz_oracle = new tz_oracle_t ;
+
+  int res1 = QObject::connect(csd, SIGNAL(csd_cellular_time(const cellular_time_t &)), settings, SLOT(cellular_time_slot(const cellular_time_t &))) ;
+  int res2 = QObject::connect(csd, SIGNAL(csd_cellular_offset(const cellular_offset_t &)), tz_oracle, SLOT(cellular_offset(const cellular_offset_t &))) ;
+  int res3 = QObject::connect(csd, SIGNAL(csd_cellular_operator(const cellular_operator_t &)), tz_oracle, SLOT(cellular_operator(const cellular_operator_t &))) ;
+  int res4 = QObject::connect(tz_oracle, SIGNAL(cellular_zone_detected(olson *, suggestion_t, bool)), settings, SLOT(cellular_zone_slot(olson *, suggestion_t, bool))) ;
+
+  log_assert(res1) ;
+  log_assert(res2) ;
+  log_assert(res3) ;
+  log_assert(res4) ;
+
+#if 0
   QObject::connect(tz_oracle, SIGNAL(tz_detected(olson *, tz_suggestions_t)), this, SLOT(tz_by_oracle(olson *, tz_suggestions_t))) ;
   QObject::connect(nitz_object, SIGNAL(cellular_data_received(const cellular_info_t &)), tz_oracle, SLOT(nitz_data(const cellular_info_t &))) ;
+#endif
 }
 
 void Timed::init_dst_checker()
@@ -744,7 +777,10 @@
   save_settings() ;
   settings->fix_etc_localtime() ;
   sent_signature = dst_signature(time(NULL)) ;
-  emit settings_changed(settings->get_wall_clock_info(diff), !diff.is_zero()) ;
+  Maemo::Timed::WallClock::Info info(settings->get_wall_clock_info(diff)) ;
+  log_notice("sending signal 'settings_changed': %s", info.str().toStdString().c_str()) ;
+  emit settings_changed(info, not diff.is_zero()) ;
+  log_notice("signal 'settings_changed' sent") ;
   // emit settings_changed_1(systime) ;
   am->reshuffle_queue(diff) ;
   if(q_pause)
@@ -836,6 +872,7 @@
   }
 }
 
+#if 0
 void Timed::nitz_notification(const cellular_info_t &ci)
 {
   log_debug() ;
@@ -843,7 +880,9 @@
   settings->cellular_information(ci) ;
   log_debug() ;
 }
+#endif
 
+#if 0
 void Timed::tz_by_oracle(olson *tz, tz_suggestions_t s)
 {
   log_debug("time zone '%s' magicaly detected", tz->name().c_str()) ;
@@ -856,9 +895,12 @@
   }
   invoke_signal() ;
 }
+#endif
 
-void Timed::update_oracle_context(bool set)
+void Timed::update_oracle_context(bool s)
 {
+  log_warning("update_oracle_context(%d): NOT IMPLEMENTED", s) ;
+#if 0
   static ContextProvider::Property oracle_p("/com/nokia/time/time_zone/oracle") ;
   static const char * const uncertain_key = "uncertain" ;
   static const char * const primary_key = "primary_candidates" ;
@@ -890,6 +932,7 @@
   }
 
   oracle_p.setValue(map) ;
+#endif
 }
 
 void Timed::open_epoch()
--- src/server/timed.h
+++ src/server/timed.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -42,20 +42,22 @@
 #include "olson.h"
 #include "machine.h"
 #include "tz.h"
+#include "csd.h"
 #include "event.h"
+#include "peer.h"
 
 struct Timed : public QCoreApplication
 {
 public:
   inline const char *configuration_path() { return  "/etc/timed.config" ; }
-  inline const char *configuration_type() { return  "/usr/share/timed/typeinfo/config.type" ; }
+  // inline const char *configuration_type() { return  "/usr/share/timed/typeinfo/config.type" ; }
 
   inline const char *customization_path() { return  "/usr/share/timed/customization.data" ; } // TODO: make it configurable
-  inline const char *customization_type() { return  "/usr/share/timed/typeinfo/customization.type" ; }
+  // inline const char *customization_type() { return  "/usr/share/timed/typeinfo/customization.type" ; }
 
-  inline const char *settings_file_type() { return  "/usr/share/timed/typeinfo/settings.type" ; }
+  // inline const char *settings_file_type() { return  "/usr/share/timed/typeinfo/settings.type" ; }
 
-  inline const char *event_queue_type() { return  "/usr/share/timed/typeinfo/queue.type" ; }
+  // inline const char *event_queue_type() { return  "/usr/share/timed/typeinfo/queue.type" ; }
 
 private:
   bool act_dead_mode ;
@@ -78,6 +80,7 @@
 
   // init_* methods, to be called by constructor only
   void init_unix_signal_handler() ;
+  void init_dbus_peer_info() ;
   void init_scratchbox_mode() ;
   void init_act_dead() ;
   void init_configuration() ;
@@ -106,6 +109,11 @@
   machine_t *am ;
   pinguin *ping ;
   source_settings *settings ;
+  cellular_handler *nitz_object ;
+#if F_CSD
+  csd_t *csd ;
+#endif
+  peer_t *peer ;
 
   void load_events() ;
   void check_voland_service() ;
@@ -113,6 +121,7 @@
   void add_events(const Maemo::Timed::event_list_io_t &events, QList<QVariant> &res, const QDBusMessage &message) ;
   bool dialog_response(cookie_t c, int value) ;
   bool cancel(cookie_t c) { return am->cancel_by_cookie(c) ; }
+  void cancel_events(const QList<uint> &cookies, QList<uint> &failed) { am->cancel_events(cookies, failed) ;}
   void alarm_gate(bool value) { return am->alarm_gate(value) ; }
   int default_snooze(int value) { return settings->default_snooze(value) ; }
   QDBusConnectionInterface *ses_iface ;
@@ -170,9 +179,11 @@
 private Q_SLOTS:
   void queue_threshold_timeout() ;
   void unix_signal(int signo) ;
+#if 0
   void nitz_notification(const cellular_info_t &) ;
-  void check_dst() ;
   void tz_by_oracle(olson *tz, tz_suggestions_t) ;
+#endif
+  void check_dst() ;
 public:
   void update_oracle_context(bool set) ;
   void open_epoch() ;
--- src/server/timeutil.cpp
+++ src/server/timeutil.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/timeutil.h
+++ src/server/timeutil.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/tz.cpp
+++ src/server/tz.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -22,7 +22,9 @@
 **                                                                        **
 ***************************************************************************/
 #include "tz.h"
+#include "tzdata.h"
 
+#if 0
 iodata::validator *tz_oracle_t::validator()
 {
   static iodata::validator *v = NULL ;
@@ -30,7 +32,9 @@
     v = iodata::validator::from_file("/usr/share/timed/typeinfo/tzdata.type") ;
   return v ;
 }
+#endif
 
+#if 0
 iodata::record *tz_oracle_t::open_database(const char *path, const char *type)
 {
   iodata::storage file ;
@@ -38,11 +42,13 @@
   file.set_primary_path(path) ;
   return file.load() ;
 }
+#endif
 
 tz_oracle_t::tz_oracle_t()
 {
-  mcc = 0 ;
+  history = new history_t ;
 
+#if 0
   if(iodata::record *single = open_database("/usr/share/tzdata-timed/single.data", "tz_single_t"))
   {
     tz_single = new tz_single_t(single) ;
@@ -68,19 +74,24 @@
   // log_assert(false, "please initialize xy_to_tz!") ;
 
   read_timezones_by_country() ;
+#endif
 
-  delay = new QTimer ;
-  delay->setSingleShot(true) ;
+  timer = new QTimer ;
+  timer->setSingleShot(true) ;
 }
 
 tz_oracle_t::~tz_oracle_t()
 {
+  delete history ;
+#if 0
   delete tz_single ;
   delete tz_distinct ;
-  delete delay ;
   delete validator() ;
+#endif
+  delete timer ;
 }
 
+#if 0
 void tz_oracle_t::read_timezones_by_country()
 {
   iodata::record *rec = open_database("/usr/share/tzdata-timed/zones-by-country.data", "zones_by_country_t") ;
@@ -103,12 +114,16 @@
   }
   delete rec ;
 }
+#endif
 
+#if 0
 void tz_oracle_t::mcc_delay_timeout()
 {
   log_assert(false, "oops") ;
 }
+#endif
 
+#if 0
 void tz_oracle_t::nitz_data(const cellular_info_t &ci)
 {
   log_debug() ;
@@ -119,7 +134,9 @@
   else
     log_critical("oops") ;
 }
+#endif
 
+#if 0
 void tz_oracle_t::handle_offset(const cellular_info_t &ci)
 {
   // preliminary implementation:
@@ -189,7 +206,9 @@
     return ;
   }
 }
+#endif
 
+#if 0
 string tz_oracle_t::mcc_to_xy(int mcc_value)
 {
   static bool loaded = false ;
@@ -215,7 +234,10 @@
   map<int, string>::const_iterator it = mcc_to_xy.find(mcc_value) ;
   return it==mcc_to_xy.end() ? "" : it->second ;
 }
+#endif
 
+#if 0
+TODO something like that
 void tz_oracle_t::user_input(olson *tz)
 {
   // not used yet, no UI for that
@@ -223,7 +245,9 @@
   s.gq = Reliable ;
   emit tz_detected(tz, s) ;
 }
+#endif
 
+#if 0
 void tz_oracle_t::mcc_data(int new_mcc, const string & /* mnc not used */)
 {
   if(new_mcc == 0) // offline => do nothing
@@ -256,7 +280,146 @@
 
   emit tz_detected(olson::by_name("Antarctica/DumontDUrville"), s) ;
 }
+#endif
 
+void tz_oracle_t::output(olson *zone)
+{
+  output(zone, new suggestion_t, true) ;
+}
+
+void tz_oracle_t::output(olson *zone, suggestion_t *s, bool sure)
+{
+  log_notice("Time zone magically detected: '%s' (%s" "sure)", zone->name().c_str(), sure?"":"not ") ;
+  emit cellular_zone_detected(zone, *s, sure) ;
+
+  delete s ;
+}
+
+void tz_oracle_t::set_by_offset(const cellular_offset_t &data)
+{
+  if (oper.known_mcc())
+  {
+    set<olson*> m, r, result ; // main, real
+    tzdata::by_country(oper.location(), tzdata::Main_Zones, m) ;
+    tzdata::by_country(oper.location(), tzdata::Real_Zones, r) ;
+    set<olson*>  rm = r ; // real minus main
+    set_change<olson*>(rm, m, false) ; // false: rm-=m
+    bool found = false ;
+    if (data.dst<=0) // sometimes '-1' means "winter time", i.e. set dst to zero
+    {
+      found = found or tzdata::filter(m, data.timestamp, data.offset, 0, result) ;
+      log_debug("after try 1: found=%d", found) ;
+      found = found or tzdata::filter(rm, data.timestamp, data.offset, 0, result) ;
+      log_debug("after try 2: found=%d", found) ;
+    }
+    if (data.dst!=0) // either "summer" (>0) or really not specified (<0)
+    {
+      found = found or tzdata::filter(m, data.timestamp, data.offset, data.dst, result) ;
+      log_debug("after try 3: found=%d", found) ;
+      found = found or tzdata::filter(rm, data.timestamp, data.offset, data.dst, result) ;
+      log_debug("after try 4: found=%d", found) ;
+    }
+    if (not data.sender_time) // sender time not really known, try plus/minus day
+    {
+      const int day = 60*60*24 ;
+      found = found or tzdata::filter(r, data.timestamp-day, data.offset, data.dst, result) ;
+      log_debug("after try 5: found=%d", found) ;
+      found = found or tzdata::filter(r, data.timestamp+day, data.offset, data.dst, result) ;
+      log_debug("after try 6: found=%d", found) ;
+    }
+    log_notice("%d candidates selected: %s", result.size(), tzdata::set_str(result).c_str()) ;
+    olson *zone = NULL ;
+    if (result.size()==0)
+    {
+      zone = olson::by_offset(data.offset) ;
+      if (zone==NULL)
+      {
+        log_error("failed to set time zome by offset=%d", data.offset) ;
+        return ;
+      }
+    }
+    else
+    {
+      zone = * result.begin() ;
+      for (set<olson*>::const_iterator it=result.begin(); it!=result.end(); ++it)
+        if (*it==stat.last_zone)
+        {
+          zone = *it ;
+          break ;
+        }
+    }
+    suggestion_t *s =  new suggestion_t ;
+    for (set<olson*>::const_iterator it=rm.begin(); it!=rm.end(); ++it)
+      s->add(*it, 20) ;
+    for (set<olson*>::const_iterator it=m.begin(); it!=m.end(); ++it)
+      s->add(*it, 10) ;
+    s->add(tzdata::device_default(), 10) ;
+    for (set<olson*>::const_iterator it=result.begin(); it!=result.end(); ++it)
+      s->add(*it, 5) ;
+    output(zone, s, result.size()==1) ;
+  }
+  else // some weird operator, or even empty
+  {
+    log_notice("setting timezone %s for a strange operator %s", data.str().c_str(), oper.str().c_str()) ;
+    olson *zone = olson::by_offset(data.offset) ;
+    if (zone==NULL)
+    {
+      log_error("failed to set time zone by offset=%d", data.offset) ;
+      return ;
+    }
+    output(zone) ;
+    // TODO: find by offset worldwide ???
+  }
+}
+
+void tz_oracle_t::set_by_operator()
+{
+  // bool known = oper.known_mcc() ;
+
+  if (oper.known_mcc())
+  {
+    set<olson*> all_zones, main_zones, real_zones ;
+    tzdata::by_country(oper.location(), tzdata::All_Zones, all_zones) ;
+    tzdata::by_country(oper.location(), tzdata::Main_Zones, main_zones) ;
+    tzdata::by_country(oper.location(), tzdata::Real_Zones, real_zones) ;
+    olson *guess = NULL ;
+    if (stat.last_zone and all_zones.count(stat.last_zone)) // zone contained in this country: take it
+      guess = stat.last_zone ;
+    else
+    {
+      stat.last_zone = NULL ;
+      guess = tzdata::device_default() ;
+      if (not all_zones.count(guess)) // we're not in home country
+        if (olson *first = tzdata::country_default(oper.location())) // let's be paranoid
+          guess = first ;
+    }
+    log_assert(guess, "oops, guessed NULL pointer") ;
+    log_info("zone '%s' magically guessed by operator identity", guess->name().c_str()) ;
+    bool sure = real_zones.size()==1 ; // it's saingle zone country
+    suggestion_t *s = new suggestion_t ;
+    for (set<olson*>::const_iterator it=real_zones.begin(); it!=real_zones.end(); ++it)
+      s->add(*it, 20) ;
+    for (set<olson*>::const_iterator it=main_zones.begin(); it!=main_zones.end(); ++it)
+      s->add(*it, 10) ;
+    s->add(tzdata::device_default(), 10) ;
+    output(guess, s, sure) ;
+  }
+  else // some weird operator located nowhere
+  {
+    if (stat.last_zone==NULL)
+    {
+      log_notice("can't guess zone for operator %s", oper.str().c_str()) ;
+      return ;
+    }
+    else
+    {
+      log_notice("guessing last used zone '%s' for operator %s", stat.last_zone->name().c_str(), oper.str().c_str()) ;
+      output(stat.last_zone) ;
+    }
+  }
+}
+
+#if 0
 tz_single_t::tz_single_t(const iodata::record *list_r)
 {
   log_debug() ;
@@ -325,6 +488,81 @@
 
   return tzlist[0] ;
 }
+#endif
+
+void tz_oracle_t::cellular_offset(const cellular_offset_t &data)
+{
+  timer->stop() ; // preventing setting tz by operator only
+  if (data.oper.empty())
+    log_error("opratorless NITZ received: %s", data.str().c_str()) ;
+  else if (oper != data.oper)
+  {
+    log_error("unexpected operator change in NITZ package %s (current operator %s)", data.str().c_str(), oper.str().c_str()) ;
+    history->save_status(stat, oper) ;
+    oper = data.oper ;
+    history->load_status(stat, oper) ;
+  }
+  set_by_offset(data) ;
+}
+
+void tz_oracle_t::cellular_operator(const cellular_operator_t &o)
+{
+  timer->stop() ;
+#if 0
+  delete waiting_oper ;
+  waiting_oper = NULL ;
+#endif
+
+  bool empty = o.empty() ;
+  bool same = o==oper ;
+  bool same_country = o.known_mcc() and o.location()==oper.location() ;
+
+  log_debug("o=%s, empty=%d, same=%d, same_country=%d", o.str().c_str(), empty, same, same_country) ;
+  if (empty) // disconnected: do nothing
+  {
+    log_debug("empty operator") ;
+    have_oper = false ;
+    return ;
+  }
+  else
+    have_oper = true ; // TODO: oper = o ;
+
+  if (same) // same as current or same as last: do nothing
+    return ;
 
-// --------------------------------------------------
+  // now the operator is changing, first we have to save status
+  history->save_status(stat, oper) ;
 
+  oper = o ;
+
+  history->load_status(stat, oper) ;
+  log_debug() ;
+
+  if(same_country) // nothing to do?
+    return ;
+
+  bool small_country = oper.known_mcc() and tzdata::is_single_zone_country(oper.location()) ;
+
+  if (small_country and stat.regular)
+    set_by_operator() ;
+  else
+    timer->start(nitz_wait_ms) ;
+}
+
+void tz_oracle_t::waiting_for_nitz_timeout()
+{
+  timer->stop() ;
+  set_by_operator() ;
+}
+
+#if 0
+int tz_oracle_t::basic_mcc(int mcc)
+{
+  return mcc ; // TODO: USA->310 etc etc
+}
+#endif
+
+void suggestion_t::add(olson *zone, int score)
+{
+  s[zone] = score ;
+}
--- src/server/tz.h
+++ src/server/tz.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -30,21 +30,30 @@
 
 #include <QTimer>
 
-#include <iodata/validator>
-#include <iodata/storage>
 
 #include "onitz.h"
 #include "olson.h"
+#include "cellular.h"
 
-struct tz_single_t ;
-struct tz_distinct_t ;
+struct status_t
+{
+  olson *last_zone ;
+  bool regular ;
+} ;
+
+// fake history implementation doing nothing
+struct history_t
+{
+  void save_status(const status_t &/*s*/, const cellular_operator_t &/*op*/) { }
+  void load_status(status_t &s, const cellular_operator_t &/*op*/) { s.last_zone=NULL, s.regular=true ; }
+} ;
 
 enum guess_quality
 {
   Uncertain, Reliable, Confirmed, Canceled, Waiting, Initial
 } ;
 
-struct tz_suggestions_t
+struct tz_suggestions_t // obsolete
 {
   vector <olson*> zones ;
   guess_quality gq ;
@@ -54,40 +63,89 @@
   tz_suggestions_t() { gq = Uncertain ; }
 } ;
 
+struct suggestion_t
+{
+  std::map<olson *, int> s ;
+  void add(olson *zone, int score) ;
+} ;
+
 struct tz_oracle_t : public QObject
 {
-  int mcc ;
+  static const int nitz_wait_ms = 1000 ;
+#if 0
   bool connected ;
   enum guess_quality gq ;
-  QTimer *delay ; // TODO: make a fuzzy timer
+#endif
+
+  QTimer *timer ;
+#if 0
+  cellular_operator_t *waiting_oper ;
+#endif
+  history_t *history ;
+
+  cellular_operator_t oper ;
+  bool have_oper ;
+  status_t stat ;
 
   tz_oracle_t() ;
  ~tz_oracle_t() ;
 public slots:
-  void mcc_delay_timeout() ;
+  void waiting_for_nitz_timeout() ;
+#if 0
   void nitz_data(const cellular_info_t &) ;
+#else
+  void cellular_operator(const cellular_operator_t &data) ;
+  void cellular_offset(const cellular_offset_t &data) ;
+#endif
+
+#if 0
+TODO:
   void user_input(olson *tz) ;
+#endif
+
+#if 0
   void mcc_data(int mcc, const string &mnc) ;
+#endif
 
 signals:
+  void cellular_zone_detected(olson *, suggestion_t, bool) ;
+#if 0
   void tz_detected(olson *tz, tz_suggestions_t) ;
+#endif
 
 private:
+#if 0
   void handle_offset(const cellular_info_t &) ;
+#endif
+
+#if 0
   string mcc_to_xy(int mcc) ; // maps mcc to country code (2 chars)
   map<string, vector<string> > xy_to_tz ; // time zones by country code
   iodata::validator *validator() ;
   iodata::record *open_database(const char *path, const char *type) ;
   void read_timezones_by_country() ;
+#endif
 
+#if 0
   tz_single_t *tz_single ;
   tz_distinct_t *tz_distinct ;
+#endif
 
+#if 0
   bool is_single(int mcc) ;
+#endif
+
+  void set_by_offset(const cellular_offset_t &data) ;
+  // void set_by_operator(const cellular_operator_t &o) ;
+  void set_by_operator() ;
+
+  void output(olson *zone, suggestion_t *s, bool sure) ;
+  void output(olson *zone) ;
 
   Q_OBJECT ;
 } ;
 
+#if 0
 struct tz_distinct_t
 {
   olson * guess_timezone(int mcc, tz_suggestions_t &list) ;
@@ -101,5 +159,6 @@
   tz_single_t(const iodata::record *) ;
   map<int, string> mcc_to_tz ;
 } ;
+#endif
 
 #endif
--- src/server/tzdata.cpp
+++ src/server/tzdata.cpp
+/***************************************************************************
+**                                                                        **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
+**                                                                        **
+**   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
+**   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
+**   Author: Victor Portnov <ext-victor.portnov at nokia.com>                **
+**                                                                        **
+**     This file is part of Timed                                         **
+**                                                                        **
+**     Timed is free software; you can redistribute it and/or modify      **
+**     it under the terms of the GNU Lesser General Public License        **
+**     version 2.1 as published by the Free Software Foundation.          **
+**                                                                        **
+**     Timed is distributed in the hope that it will be useful, but       **
+**     WITHOUT ANY WARRANTY;  without even the implied warranty  of       **
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               **
+**     See the GNU Lesser General Public License  for more details.       **
+**                                                                        **
+**   You should have received a copy of the GNU  Lesser General Public    **
+**   License along with Timed. If not, see http://www.gnu.org/licenses/   **
+**                                                                        **
+***************************************************************************/
+#include <iodata/validator>
+#include <iodata/storage>
+
+#include <string>
+#include <sstream>
+#include <set>
+#include <map>
+using namespace std ;
+
+#include <qmlog>
+
+#include "olson.h"
+#include "misc.h"
+
+#include "tzdata.h"
+
+#if DEADCODE
+struct tz_single_t ;
+struct tz_distinct_t ;
+
+struct tz_distinct_t
+{
+  olson * guess_timezone(int mcc, tz_suggestions_t &list) ;
+  tz_distinct_t(const iodata::record *) ;
+  map<int, vector<olson*> > mcc_to_tzlist ;
+} ;
+
+struct tz_single_t
+{
+  olson * guess_timezone(int mcc) ;
+  tz_single_t(const iodata::record *) ;
+  map<int, string> mcc_to_tz ;
+} ;
+
+
+string mcc_to_xy(int mcc) ; // maps mcc to country code (2 chars)
+map<string, vector<string> > xy_to_tz ; // time zones by country code
+iodata::validator *validator() ;
+iodata::record *open_database(const char *path, const char *type) ;
+void read_timezones_by_country() ;
+
+#endif
+
+// we need some some data structures...
+
+// 1. Mapping mcc to alpha-2 code: 310=>US
+map<string,string> mcc_to_xy ;
+// 2. Mapping alpha-2 to zone to importance (0,1,2,3): US=>(New_York=>0, Chicago=>1, Phoenix=>2, Zaporozhye=>3)
+map<string,map<string,int> > xy_to_zone_to_level ;
+// 3. Mapping alpha-2 to main zone: US=>New_York
+map<string,string> xy_to_zone0 ;
+// 4. Default country (alpha-2) and zone based on default time zome customization
+string home_country ;
+olson *home_zone=NULL ;
+// 5. Set of alpha-2 of single zone counties (only 0,1,2 count; 3 doesn't)
+set<string> small_countries ;
+
+string tzdata::iso_3166_1_alpha2_by_mcc(const string &mcc)
+{
+  map<string,string>::const_iterator it = mcc_to_xy.find(mcc) ;
+  return it==mcc_to_xy.end() ? "" : it->second ;
+}
+
+int tzdata::by_country(const string &alpha2, enum tzdata::zone_type type, set<olson*> &out)
+{
+  map<string,map<string,int> >::const_iterator it = xy_to_zone_to_level.find(alpha2) ;
+  if (it==xy_to_zone_to_level.end())
+    return 0 ;
+
+  int counter = 0 ;
+  int threshold = type==tzdata::Main_Zones ? 1 : type==tzdata::Real_Zones ? 2 : 3 ; // all by default
+  const map<string,int> &zone_to_level = it->second ;
+
+  for (map<string,int>::const_iterator jt=zone_to_level.begin(); jt!=zone_to_level.end(); ++jt)
+    if (jt->second <= threshold)
+      out.insert(olson::by_name(jt->first)), ++counter ;
+
+  return counter ;
+}
+
+olson *tzdata::country_default(const string &alpha2)
+{
+  map<string,string>::const_iterator it = xy_to_zone0.find(alpha2) ;
+  return it==xy_to_zone0.end() ? NULL : olson::by_name(it->second) ;
+}
+
+olson *tzdata::device_default()
+{
+  return home_zone ;
+}
+
+int tzdata::filter(const set<olson*> &in, time_t moment, int offset, int dst, set<olson*> &out)
+{
+  int counter = 0 ;
+  for (set<olson*>::const_iterator it=in.begin(); it!=in.end(); ++it)
+    if ((*it)->match(moment, offset, dst))
+      ++counter, out.insert(*it) ;
+  return counter ;
+}
+
+bool tzdata::is_single_zone_country(const string &alpha2)
+{
+  return small_countries.find(alpha2) != small_countries.end() ;
+}
+
+string tzdata::set_str(const set<olson*> &x)
+{
+  ostringstream os ;
+  bool first = true ;
+  for (set<olson*>::const_iterator it=x.begin(); it!=x.end(); ++it)
+    os << (first ? first=false, "{" : ", " ) << (*it)->name() ;
+  os << (first ? "{ }" : "}") ;
+  return os.str() ;
+}
+
+// --- initialization ---
+
+#include "tzdata.type.h"
+
+#if 0
+static struct tz_distinct_t
+{
+  // olson * guess_timezone(int mcc, tz_suggestions_t &list) ;
+  tz_distinct_t(const iodata::record *) ;
+  map<int, vector<olson*> > mcc_to_tzlist ;
+}
+*tz_distinct=NULL ;
+
+static struct tz_single_t
+{
+  // olson * guess_timezone(int mcc) ;
+  tz_single_t(const iodata::record *) ;
+  map<int, string> mcc_to_tz ;
+}
+tz_single_t *tz_single=NULL ;
+#endif
+
+static iodata::record *open_database(const char *path, const char *type)
+{
+  log_notice("opening file '%s', reading record of type '%s'", path, type) ;
+  iodata::storage file ;
+  file.set_validator(tzdata_validator(), type) ;
+  file.set_primary_path(path) ;
+  if (iodata::record *res = file.load())
+    return res ;
+  log_abort("file '%s' corrupted or not present", path) ;
+  // return NULL ; TODO: just print an error in init() and continue
+}
+
+static void process_zone(const string &xy, const string &tz, int i_value)
+{
+  if (i_value==0)
+    xy_to_zone0[xy] = tz ; // capital
+  if (tz==home_zone->name())
+    home_country = xy ;
+  xy_to_zone_to_level[xy][tz] = i_value ;
+}
+
+void tzdata::init(const string &default_tz)
+{
+  home_zone = olson::by_name(default_tz) ;
+
+  iodata::record *A = open_database("/usr/share/tzdata-timed/country-by-mcc.data", "mcc_to_xy_t") ;
+  iodata::record *B = open_database("/usr/share/tzdata-timed/single.data", "tz_single_t") ;
+  iodata::record *C = open_database("/usr/share/tzdata-timed/zones-by-country.data", "zones_by_country_t") ;
+
+  const iodata::array *a = A->get("mcc_to_xy")->arr() ;
+  for(unsigned i=0; i<a->size(); ++i)
+  {
+    int mcc_d = a->get(i)->get("mcc")->value() ;
+    string mcc = str_printf("%d", mcc_d) ;
+    string xy = a->get(i)->get("country")->str() ;
+    mcc_to_xy[mcc] = xy ;
+  }
+
+  const iodata::array *b = B->get("list")->arr() ; // TODO: rename list->tz_single (here and in tzdata script)
+  for(unsigned i=0; i<b->size(); ++i)
+  {
+    int mcc_d = b->get(i)->get("mcc")->value() ;
+    string mcc = str_printf("%d", mcc_d) ;
+    string xy = tzdata::iso_3166_1_alpha2_by_mcc(mcc) ;
+    if (xy.empty())
+    {
+      log_critical("Iso-3166 alpha-2 ID not found for MCC=%d", mcc_d) ;
+      continue ;
+    }
+    small_countries.insert(xy) ;
+    string tz = b->get(i)->get("tz")->str() ;
+    process_zone(xy, tz, 0) ; // 0 is 'capital'
+  }
+
+  const iodata::array *c = C->get("xy_to_tz")->arr() ;
+  for(unsigned i=0; i<c->size(); ++i)
+  {
+    // log_debug("i=%d", i) ;
+    string xy = c->get(i)->get("xy")->str() ;
+    for (int important=1; important<=2; ++important)
+    {
+      // log_debug("i=%d important=%d", i, important) ;
+      const char *key = important==1 ? "major" : "minor" ;
+      const iodata::array *list = c->get(i)->get(key)->arr() ;
+      for (unsigned j=0; j<list->size(); ++j)
+      {
+        // log_debug("i=%d important=%d j=%d", i, important, j) ;
+        int i_value = (important==1 and j==0) ? 0 : important ; // the very first is the capital
+        process_zone(xy, list->get(j)->str(), i_value) ;
+      }
+    }
+  }
+
+  delete A ;
+  delete B ;
+  delete C ;
+}
--- src/server/tzdata.h
+++ src/server/tzdata.h
+/***************************************************************************
+**                                                                        **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
+**                                                                        **
+**   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
+**   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
+**   Author: Victor Portnov <ext-victor.portnov at nokia.com>                **
+**                                                                        **
+**     This file is part of Timed                                         **
+**                                                                        **
+**     Timed is free software; you can redistribute it and/or modify      **
+**     it under the terms of the GNU Lesser General Public License        **
+**     version 2.1 as published by the Free Software Foundation.          **
+**                                                                        **
+**     Timed is distributed in the hope that it will be useful, but       **
+**     WITHOUT ANY WARRANTY;  without even the implied warranty  of       **
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               **
+**     See the GNU Lesser General Public License  for more details.       **
+**                                                                        **
+**   You should have received a copy of the GNU  Lesser General Public    **
+**   License along with Timed. If not, see http://www.gnu.org/licenses/   **
+**                                                                        **
+***************************************************************************/
+#ifndef MAEMO_TIMED_TZDATA_H
+#define MAEMO_TIMED_TZDATA_H
+
+#include <string>
+#include <set>
+
+class olson ;
+
+namespace tzdata
+{
+  enum zone_type { All_Zones, Main_Zones, Real_Zones } ;
+
+  std::string iso_3166_1_alpha2_by_mcc(const std::string &mcc) ;
+  int by_country(const std::string &alpha2, enum zone_type type, std::set<olson*> &out) ;
+  olson* country_default(const std::string &alpha2) ;
+  olson* device_default() ;
+  int filter(const std::set<olson*> &in, time_t moment, int offset, int dst, std::set<olson*> &out) ;
+  bool is_single_zone_country(const std::string &alpha2) ;
+
+  std::string set_str(const std::set<olson*> &) ;
+  void init(const std::string &default_tz) ;
+}
+
+#endif//MAEMO_TIMED_TZDATA_H
--- src/server/tzdata.type
+++ src/server/tzdata.type
@@ -1,6 +1,8 @@
 # TODO: check the names before moving stuff to tzdata package
 #       "list" is a horrible name, other are not much better!
 
+_function = "tzdata_validator",
+
 tz_single_t = [ { name="list", type=$array|$record|$mandatory, record="tz_single_info_t" } ],
 tz_distinct_t = [ { name="list", type=$array|$record|$mandatory, record="tz_distinct_info_t" } ],
 
--- src/server/unix-signal.cpp
+++ src/server/unix-signal.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/unix-signal.h
+++ src/server/unix-signal.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/server/wrappers.h
+++ src/server/wrappers.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/simple-client/client.cpp
+++ src/simple-client/client.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/ticker/ticker.cpp
+++ src/ticker/ticker.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -21,9 +21,32 @@
 **   License along with Timed. If not, see http://www.gnu.org/licenses/   **
 **                                                                        **
 ***************************************************************************/
+#include <sys/types.h>
+#include <sys/stat.h>
+
 #include "ticker.h"
 
 int main(int ac, char **av)
 {
+  if (ac>1 && (string)av[1]=="start")
+  {
+    pid_t pid = fork() ;
+    if (pid<0)
+    {
+      fprintf(stderr, "fork() failed: %m\n") ;
+      return 1 ;
+    }
+    if (pid>0)
+    {
+      fprintf(stderr, "started as pid=%d\n", pid) ;
+      return 0 ;
+    }
+    umask(0) ;
+    setsid() ; // don't check for failure
+    chdir("/") ;
+    freopen( "/dev/null", "r", stdin) ;
+    freopen( "/dev/null", "w", stdout) ;
+    freopen( "/dev/null", "w", stderr) ;
+  }
   return ticker(ac,av).exec() ;
 }
--- src/ticker/ticker.h
+++ src/ticker/ticker.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
@@ -55,6 +55,73 @@
 using Cellular::NetworkTimeInfo ;
 #endif
 
+static string str_printf(const char *format, ...)
+{
+  const int buf_len = 1024, max_buf_len = buf_len*1024 ;
+  char buf[buf_len], *p = buf ;
+  va_list varg ;
+  va_start(varg, format) ;
+  int iteration = 0, printed = false ;
+  string formatted ;
+  do
+  {
+    int size = buf_len << iteration ;
+    if(size>max_buf_len)
+    {
+      log_error("Can't format string, the result is too long") ;
+      return format ;
+    }
+    if(iteration>0)
+      p = new char[size] ;
+    int res = vsnprintf(p, size, format, varg) ;
+    if(res < 0)
+    {
+      log_error("Can't format string, vsnprintf() failed") ;
+      return format ;
+    }
+    if(res < size)
+    {
+      printed = true ;
+      formatted = p ;
+    }
+    if(iteration > 0)
+      delete[] p ;
+    ++ iteration ;
+  } while(!printed) ;
+
+  return formatted ;
+}
+static string csd_network_time_info_to_string(const Cellular::NetworkTimeInfo &nti)
+{
+  if (not nti.isValid())
+    return "{invalid}" ;
+
+  ostringstream os ;
+
+  os << "{zone=" << nti.offsetFromUtc() ;
+
+  QDateTime t = nti.dateTime() ;
+  if (t.isValid())
+  {
+    string utc = str_printf("%04d-%02d-%02d,%02d:%02d:%02d", t.date().year(), t.date().month(), t.date().day(), t.time().hour(), t.time().minute(), t.time().second())  ;
+    os << ", utc=" << utc ;
+  }
+
+  int dst = nti.daylightAdjustment() ;
+  if (dst!=-1)
+    os << ", dst=" << dst ;
+
+  os << ", mcc='" << nti.mcc().toStdString() << "'" ;
+  os << ", mnc='" << nti.mnc().toStdString() << "'" ;
+
+  os << ", received=" << str_printf("%lld.%09lu", (long long)nti.timestamp()->tv_sec, nti.timestamp()->tv_nsec) ;
+
+  os << "}" ;
+
+  return os.str() ;
+}
+
+
 class ticker : public QCoreApplication
 {
   Q_OBJECT ;
@@ -67,12 +134,19 @@
 public:
   ticker(int ac, char **av) : QCoreApplication(ac,av), abbreviation("[N/A]")
   {
+    // set up logging
+    // qmlog::syslog()->reduce_max_level(qmlog::Warning) ;
+    qmlog::stderr()->reduce_max_level(qmlog::Notice) ;
+    qmlog::log_file *logfile = new qmlog::log_file("/ticker.log", qmlog::Debug) ;
+    logfile->enable_fields(qmlog::Monotonic_Nano | qmlog::Time_Micro) ;
+    logfile->disable_fields(qmlog::Multiline|qmlog::Line|qmlog::Function) ;
+
     timed = new Maemo::Timed::Interface ;
 
     QDBusReply<Maemo::Timed::WallClock::Info> x = timed->get_wall_clock_info_sync() ;
     if(x.isValid())
     {
-      cout << "Timed clock settings:\n" << x.value().str().toStdString().c_str() << endl ;
+      log_notice("Timed clock settings: %s", x.value().str().toStdString().c_str()) ;
       abbreviation = x.value().tzAbbreviation() ;
     }
     else
@@ -80,7 +154,7 @@
 
     bool a = timed->settings_changed_connect(this, SLOT(settings(const Maemo::Timed::WallClock::Info &, bool))) ;
     if(a)
-      cout << "connected to D-Bus signal, waiting for time settings change signal" << endl ;
+      log_notice("connected to D-Bus signal, waiting for time settings change signal") ;
     else
       log_critical("not connected to D-Bus signal, no time change signal will be delivered!") ;
 
@@ -90,7 +164,7 @@
     QString signal = "next_bootup_event" ;
     bool aa = dsme_bus.connect("", path, iface, signal, this, SLOT(dsme(int))) ;
     if(aa)
-      cout << "connected to system bus signal '" << signal.toStdString() << "'" << endl ;
+      log_notice("connected to system bus signal '%s'", signal.toStdString().c_str()) ;
     else
       log_critical("not connected to system bus signal '%s'",signal.toStdString().c_str()) ;
 
@@ -106,8 +180,16 @@
     int cel2 = QObject::connect(cellular_time, SIGNAL(timeInfoQueryCompleted(const Cellular::NetworkTimeInfo &)), this, SLOT(cellular_queried(const Cellular::NetworkTimeInfo &))) ;
 #    endif
 
-    qDebug() << "connection to timeInfoChanged:" << (cel1 ? "ok" : "failed" ) ;
-    qDebug() << "connection to timeInfoQueryCompleted:" << (cel2 ? "ok" : "failed" ) ;
+    if (cel1)
+      log_notice("connected to 'timeInfoChanged' cellular signal") ;
+    else
+      log_warning("can't connect to 'timeInfoChanged' cellular signal") ;
+    if (cel2)
+      log_notice("connected to 'timeInfoQueryCompleted' cellular signal") ;
+    else
+      log_warning("can't connect to 'timeInfoQueryCompleted' cellular signal") ;
+
+    cellular_time->queryTimeInfo() ;
 #  else
 
     int cel = QObject::connect(cellular_time, SIGNAL(dateTimeChanged(QDateTime, int, int)), this, SLOT(cellular_changed(QDateTime, int, int))) ;
@@ -124,7 +206,7 @@
   void print_cellular_info(const char *signal, const Cellular::NetworkTimeInfo &nti)
   {
     cout << endl ;
-    qDebug() << "Signal" << signal << "received:" << nti ;
+    log_notice("Signal '%s' received: %s", signal, csd_network_time_info_to_string(nti).c_str()) ;
   }
 #endif // NEW_CELLULAR
 public slots:
@@ -137,10 +219,8 @@
     struct tm tm ;
     time_t now = time(NULL) ;
     localtime_r(&now, &tm) ;
-    os << " [" << (1900+tm.tm_year) << "-" << (1+tm.tm_mon) << "-" << tm.tm_mday <<
-      " " << tm.tm_hour << ":" << tm.tm_min << ":" << tm.tm_sec << "]" << " "  ;
-    os << "(isdst=" << tm.tm_isdst << ", gmtoff=" << tm.tm_gmtoff << ", zone='" << tm.tm_zone
-      << "')" ;
+    os << str_printf(" [%04d-%02d-%02d %02d:%02d:%02d] ", (1900+tm.tm_year), (1+tm.tm_mon), tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec) ;
+    os << "(isdst=" << tm.tm_isdst << ", gmtoff=" << tm.tm_gmtoff << ", zone='" << tm.tm_zone << "')" ;
     string s = os.str() ;
     int len = s.length() ;
     string spaces = "" ;
@@ -153,24 +233,25 @@
     for(int i=0; i<len; ++i)
       cout << (char)8 ; // ^H
     cout.flush() ;
+    log_info("*** tick ***") ;
   }
   void settings(const Maemo::Timed::WallClock::Info &info, bool time)
   {
     abbreviation = info.tzAbbreviation() ;
     cout << endl ;
-    cout << "Settings change signalled (system time " << (time ? "" : "not ") << "changed), new settings:" << endl ;
-    cout << info.str().toStdString().c_str() << endl ;
+    log_notice("Settings change signalled (system time %schanged), new settings: %s", time ? "" : "not ", info.str().toStdString().c_str()) ;
   }
   void dsme(int value)
   {
-    cout << endl ;
-    cout << "Signal for dsme detected: value=" << value ;
+    ostringstream os ;
+    os << "Signal for dsme detected: value=" << value ;
     if(value>1)
     {
       time_t now = time(NULL) ;
-      cout << " (now=" << now << " delta=value-now=" << value-now << ")" ;
+      os << " (now=" << now << " delta=value-now=" << value-now << ")" ;
     }
     cout << endl ;
+    log_notice("%s", os.str().c_str()) ;
   }
 #if NEW_CELLULAR
 
--- src/voland/interface.cpp
+++ src/voland/interface.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/voland/interface.h
+++ src/voland/interface.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/voland/reminder-pimple.cpp
+++ src/voland/reminder-pimple.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/voland/reminder-pimple.h
+++ src/voland/reminder-pimple.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **
--- src/voland/reminder.h
+++ src/voland/reminder.h
@@ -1,6 +1,6 @@
 /***************************************************************************
 **                                                                        **
-**   Copyright (C) 2009-2010 Nokia Corporation.                           **
+**   Copyright (C) 2009-2011 Nokia Corporation.                           **
 **                                                                        **
 **   Author: Ilya Dogolazky <ilya.dogolazky at nokia.com>                    **
 **   Author: Simo Piiroinen <simo.piiroinen at nokia.com>                    **

++++++ deleted files:
--- timed-2.27-enable-creds.patch
--- timed-2.31-add-missing-if.patch
--- timed-2.35-libcreds3-meego.patch




More information about the MeeGo-commits mailing list