Merge lp:~awe/phablet-extras/ofono-nettime-plugin into lp:phablet-extras/ofono

Proposed by Tony Espy
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 46
Merged at revision: 45
Proposed branch: lp:~awe/phablet-extras/ofono-nettime-plugin
Merge into: lp:phablet-extras/ofono
Diff against target: 442 lines (+371/-1)
7 files modified
Makefile.am (+5/-0)
configure.ac (+5/-0)
debian/changelog (+5/-1)
include/dbus.h (+1/-0)
plugins/nettime.c (+274/-0)
test/get-network-time (+69/-0)
test/monitor-ofono (+12/-0)
To merge this branch: bzr merge lp:~awe/phablet-extras/ofono-nettime-plugin
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+171344@code.launchpad.net

Commit message

Added network time plugin which exposes RILD NITZ messages over DBus.

Description of the change

Add network time plugin.

This can be tested using a new test script get-network-time and modification to monitor-ofono.

To post a comment you must log in.
Revision history for this message
Tony Espy (awe) wrote :

Note, as I'm going to have to re-merge once the IMEI MR lands, I'll deal with the changelog at the same time...

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
44. By Tony Espy

Re-merge from trunk.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

476 + for member in ["NetworkTimeReceived"]:

This should be NetworkTimeChanged instead.

Other than that, code looks good.

review: Needs Fixing
45. By Tony Espy

[nettime] Fix NetworkTimeChanged signal in test/monitor-ofono.

Revision history for this message
Tony Espy (awe) wrote :

Nice catch... fixed.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
46. By Tony Espy

Re-merge from trunk.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Makefile.am'
--- Makefile.am 2013-04-12 20:04:45 +0000
+++ Makefile.am 2013-06-26 17:26:23 +0000
@@ -466,6 +466,11 @@
466endif466endif
467endif467endif
468468
469if NETTIME
470builtin_modules += nettime
471builtin_sources += plugins/nettime.c
472endif
473
469if PROVISION474if PROVISION
470builtin_sources += plugins/mbpi.h plugins/mbpi.c475builtin_sources += plugins/mbpi.h plugins/mbpi.c
471476
472477
=== modified file 'configure.ac'
--- configure.ac 2013-03-28 12:50:26 +0000
+++ configure.ac 2013-06-26 17:26:23 +0000
@@ -188,6 +188,11 @@
188AC_SUBST(BLUEZ_LIBS)188AC_SUBST(BLUEZ_LIBS)
189AM_CONDITIONAL(BLUETOOTH, test "${enable_bluetooth}" != "no")189AM_CONDITIONAL(BLUETOOTH, test "${enable_bluetooth}" != "no")
190190
191AC_ARG_ENABLE(nettime, AC_HELP_STRING([--disable-nettime],
192 [disable Nettime plugin]),
193 [enable_nettime=${enableval}])
194AM_CONDITIONAL(NETTIME, test "${enable_netttime}" != "no")
195
191AC_ARG_WITH([provisiondb], AC_HELP_STRING([--with-provisiondb=FILE],196AC_ARG_WITH([provisiondb], AC_HELP_STRING([--with-provisiondb=FILE],
192 [location of provision database]), [path_provisiondb=${withval}])197 [location of provision database]), [path_provisiondb=${withval}])
193198
194199
=== modified file 'debian/changelog'
--- debian/changelog 2013-06-26 15:49:07 +0000
+++ debian/changelog 2013-06-26 17:26:23 +0000
@@ -1,7 +1,11 @@
1ofono (1.12phablet7) UNRELEASED; urgency=low1ofono (1.12phablet7) saucy; urgency=low
22
3 [ Tony Espy ]
3 * gril/gril.c: Exit on RILD socket failures.4 * gril/gril.c: Exit on RILD socket failures.
45
6 [ Petri M. Gerdt <petri.gerdt@jollamobile.com> ]
7 * plugins/nettime.c: Added nettime plugin.
8
5 -- Tony Espy <espy@canonical.com> Tue, 25 Jun 2013 15:14:13 -04009 -- Tony Espy <espy@canonical.com> Tue, 25 Jun 2013 15:14:13 -0400
610
7ofono (1.12phablet6) saucy; urgency=low11ofono (1.12phablet6) saucy; urgency=low
812
=== modified file 'include/dbus.h'
--- include/dbus.h 2012-08-22 19:59:08 +0000
+++ include/dbus.h 2013-06-26 17:26:23 +0000
@@ -59,6 +59,7 @@
59#define OFONO_GNSS_INTERFACE "org.ofono.AssistedSatelliteNavigation"59#define OFONO_GNSS_INTERFACE "org.ofono.AssistedSatelliteNavigation"
60#define OFONO_GNSS_POSR_AGENT_INTERFACE "org.ofono.PositioningRequestAgent"60#define OFONO_GNSS_POSR_AGENT_INTERFACE "org.ofono.PositioningRequestAgent"
61#define OFONO_HANDSFREE_INTERFACE OFONO_SERVICE ".Handsfree"61#define OFONO_HANDSFREE_INTERFACE OFONO_SERVICE ".Handsfree"
62#define OFONO_NETWORK_TIME_INTERFACE OFONO_SERVICE ".NetworkTime"
6263
63/* CDMA Interfaces */64/* CDMA Interfaces */
64#define OFONO_CDMA_VOICECALL_MANAGER_INTERFACE "org.ofono.cdma.VoiceCallManager"65#define OFONO_CDMA_VOICECALL_MANAGER_INTERFACE "org.ofono.cdma.VoiceCallManager"
6566
=== added file 'plugins/nettime.c'
--- plugins/nettime.c 1970-01-01 00:00:00 +0000
+++ plugins/nettime.c 2013-06-26 17:26:23 +0000
@@ -0,0 +1,274 @@
1/*
2 *
3 * oFono - Open Source Telephony
4 *
5 * Copyright (C) 2012-2013 Jolla Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22#ifdef HAVE_CONFIG_H
23#include <config.h>
24#endif
25
26#include <string.h>
27#include <glib.h>
28#include <gdbus.h>
29
30#define OFONO_API_SUBJECT_TO_CHANGE
31#include <ofono/plugin.h>
32#include <ofono/log.h>
33#include <ofono/nettime.h>
34#include <ofono/types.h>
35
36#include "ofono.h"
37
38#include "common.h"
39
40struct nt_data {
41 gboolean time_available;
42 gboolean time_pending;
43
44 time_t nw_time_utc;
45 time_t received;
46
47 int dst;
48 int time_zone;
49
50 const char *mcc;
51 const char *mnc;
52 const char *path;
53};
54
55static struct nt_data *ntd = NULL;
56
57
58static void init_time(void)
59{
60 ntd = g_new0(struct nt_data, 1);
61
62 ntd->time_available = FALSE;
63 ntd->time_pending = FALSE;
64 ntd->dst = 0;
65 ntd->time_zone = 0;
66}
67
68static gboolean encode_time_format(const struct ofono_network_time *time,
69 struct tm *tm)
70{
71 if (time->year < 0)
72 return FALSE;
73
74 memset(tm, 0, sizeof(struct tm));
75 tm->tm_year = time->year - 1900;
76 tm->tm_mon = time->mon - 1;
77 tm->tm_mday = time->mday;
78 tm->tm_hour = time->hour;
79 tm->tm_min = time->min;
80 tm->tm_sec = time->sec;
81 tm->tm_gmtoff = time->utcoff;
82 tm->tm_isdst = time->dst;
83
84 return TRUE;
85}
86
87static time_t get_monotonic_time()
88{
89 struct timespec ts;
90 clock_gettime(CLOCK_MONOTONIC, &ts);
91 return ts.tv_sec;
92}
93
94static int fill_time_notification(DBusMessage *msg,
95 struct nt_data *ntd)
96{
97 DBusMessageIter iter, iter_array;
98 dbus_int64_t utc_long, received;
99 dbus_int32_t dst, timezone;
100 dbus_message_iter_init_append(msg, &iter);
101 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
102 "{sv}",
103 &iter_array);
104 if (ntd->time_pending) {
105 if (ntd->time_available) {
106 utc_long = (dbus_int64_t) ntd->nw_time_utc;
107 ofono_dbus_dict_append(&iter_array,
108 "UTC",
109 DBUS_TYPE_INT64,
110 &utc_long);
111 dst = (dbus_int32_t) ntd->dst;
112 ofono_dbus_dict_append(&iter_array,
113 "DST",
114 DBUS_TYPE_UINT32,
115 &dst);
116 received = (dbus_int64_t) ntd->received;
117 ofono_dbus_dict_append(&iter_array,
118 "Received",
119 DBUS_TYPE_INT64,
120 &received);
121 }
122
123 timezone = (dbus_int32_t) ntd->time_zone;
124 ofono_dbus_dict_append(&iter_array,
125 "Timezone",
126 DBUS_TYPE_INT32,
127 &timezone);
128
129 ofono_dbus_dict_append(&iter_array,
130 "MobileCountryCode",
131 DBUS_TYPE_STRING,
132 &ntd->mcc);
133
134 ofono_dbus_dict_append(&iter_array,
135 "MobileNetworkCode",
136 DBUS_TYPE_STRING,
137 &ntd->mnc);
138 } else {
139 DBG("fill_time_notification: time not available");
140 }
141
142 dbus_message_iter_close_container(&iter, &iter_array);
143 return 0;
144}
145
146static DBusMessage *get_network_time(DBusConnection *conn,
147 DBusMessage *msg, void *data)
148{
149 DBusMessage *reply;
150
151 reply = dbus_message_new_method_return(msg);
152 if (reply == NULL)
153 return NULL;
154 fill_time_notification(reply, ntd);
155 return reply;
156}
157
158static const GDBusMethodTable nettime_methods[] = {
159 { GDBUS_METHOD("GetNetworkTime",
160 NULL, GDBUS_ARGS({ "time", "a{sv}" }),
161 get_network_time) },
162 { }
163};
164
165static const GDBusSignalTable nettime_signals[] = {
166 { GDBUS_SIGNAL("NetworkTimeChanged",
167 GDBUS_ARGS({ "time", "a{sv}" })) },
168 { }
169};
170
171static int nettime_probe(struct ofono_nettime_context *context)
172{
173 DBusConnection *conn = ofono_dbus_get_connection();
174 const char *path = ofono_modem_get_path(context->modem);
175 DBG("Network time probe for modem: %p (%s)", context->modem, path);
176 init_time();
177 if (!g_dbus_register_interface(conn, path,
178 OFONO_NETWORK_TIME_INTERFACE, // name
179 nettime_methods, // methods
180 nettime_signals, // signals
181 NULL, // GDBusPropertyTable *properties
182 NULL, // user data
183 NULL)) { // GDBusDestroyFunction destroy
184 ofono_error("Networkt time: Could not register interface %s, path %s",
185 OFONO_NETWORK_TIME_INTERFACE, path);
186 return 1;
187 } else {
188 ofono_info("Network time: Registered inteface %s, path %s",
189 OFONO_NETWORK_TIME_INTERFACE, path);
190 }
191
192 ofono_modem_add_interface(context->modem, OFONO_NETWORK_TIME_INTERFACE);
193 return 0;
194}
195
196static void nettime_remove(struct ofono_nettime_context *context)
197{
198 DBusConnection *conn = ofono_dbus_get_connection();
199 const char *path = ofono_modem_get_path(context->modem);
200 DBG("Network time remove for modem: %p (%s)", context->modem, path);
201 if (!g_dbus_unregister_interface(conn, path, OFONO_NETWORK_TIME_INTERFACE)) {
202 ofono_error("Network time: could not unregister interface %s, path %s",
203 OFONO_NETWORK_TIME_INTERFACE, path);
204 }
205
206 ofono_modem_remove_interface(context->modem, OFONO_NETWORK_TIME_INTERFACE);
207 g_free(ntd);
208}
209
210static void send_signal(struct nt_data *ntd)
211{
212 DBusConnection *conn = ofono_dbus_get_connection();
213 DBusMessage *signal = dbus_message_new_signal(ntd->path,
214 OFONO_NETWORK_TIME_INTERFACE,
215 "NetworkTimeChanged");
216 fill_time_notification(signal, ntd);
217 g_dbus_send_message(conn, signal);
218}
219
220static void nettime_info_received(struct ofono_nettime_context *context,
221 struct ofono_network_time *info)
222{
223 struct ofono_netreg *netreg;
224 struct tm t;
225
226 if (info == NULL)
227 return;
228
229 netreg = __ofono_atom_get_data(__ofono_modem_find_atom(
230 context->modem, OFONO_ATOM_TYPE_NETREG));
231 ntd->path = ofono_modem_get_path(context->modem);
232 ntd->mcc = ofono_netreg_get_mcc(netreg);
233 ntd->mnc = ofono_netreg_get_mnc(netreg);
234 ntd->received = get_monotonic_time();
235 ntd->time_pending = TRUE;
236 ntd->dst = info->dst;
237 ntd->time_zone = info->utcoff;
238
239 ntd->time_available = encode_time_format(info, &t);
240 if (ntd->time_available == TRUE)
241 ntd->nw_time_utc = timegm(&t);
242
243 send_signal(ntd);
244 DBG("modem: %p (%s)", context->modem, ofono_modem_get_path(context->modem));
245 DBG("time: %04d-%02d-%02d %02d:%02d:%02d%c%02d:%02d (DST=%d)",
246 info->year, info->mon, info->mday, info->hour,
247 info->min, info->sec, info->utcoff > 0 ? '+' : '-',
248 abs(info->utcoff) / 3600, (abs(info->utcoff) % 3600) / 60,
249 info->dst);
250 DBG("UTC timestamp: %li, Received (monotonic time): %li",
251 ntd->nw_time_utc, ntd->received);
252 DBG("MCC: %s, MNC: %s", ntd->mcc, ntd->mnc);
253}
254
255static struct ofono_nettime_driver driver = {
256 .name = "Network Time",
257 .probe = nettime_probe,
258 .remove = nettime_remove,
259 .info_received = nettime_info_received,
260};
261
262static int nettime_init(void)
263{
264 return ofono_nettime_driver_register(&driver);
265}
266
267static void nettime_exit(void)
268{
269 ofono_nettime_driver_unregister(&driver);
270}
271
272OFONO_PLUGIN_DEFINE(nettime, "Network Time Plugin",
273 VERSION, OFONO_PLUGIN_PRIORITY_DEFAULT,
274 nettime_init, nettime_exit)
0275
=== added file 'test/get-network-time'
--- test/get-network-time 1970-01-01 00:00:00 +0000
+++ test/get-network-time 2013-06-26 17:26:23 +0000
@@ -0,0 +1,69 @@
1#!/usr/bin/python
2
3import dbus
4import sys
5_dbus2py = {
6 dbus.String : unicode,
7 dbus.UInt32 : int,
8 dbus.Int32 : int,
9 dbus.Int16 : int,
10 dbus.UInt16 : int,
11 dbus.UInt64 : int,
12 dbus.Int64 : int,
13 dbus.Byte : int,
14 dbus.Boolean : bool,
15 dbus.ByteArray : str,
16 dbus.ObjectPath : str
17 }
18
19def dbus2py(d):
20 t = type(d)
21 if t in _dbus2py:
22 return _dbus2py[t](d)
23 if t is dbus.Dictionary:
24 return dict([(dbus2py(k), dbus2py(v)) for k, v in d.items()])
25 if t is dbus.Array and d.signature == "y":
26 return "".join([chr(b) for b in d])
27 if t is dbus.Array or t is list:
28 return [dbus2py(v) for v in d]
29 if t is dbus.Struct or t is tuple:
30 return tuple([dbus2py(v) for v in d])
31 return d
32
33def pretty(d):
34 d = dbus2py(d)
35 t = type(d)
36
37 if t in (dict, tuple, list) and len(d) > 0:
38 if t is dict:
39 d = ", ".join(["%s = %s" % (k, pretty(v))
40 for k, v in d.items()])
41 return "{ %s }" % d
42
43 d = " ".join([pretty(e) for e in d])
44
45 if t is tuple:
46 return "( %s )" % d
47
48 if t is str:
49 return "%s" % d
50
51 return str(d)
52
53bus = dbus.SystemBus()
54
55manager = dbus.Interface(bus.get_object("org.ofono", "/"),
56 "org.ofono.Manager")
57
58modems = manager.GetModems()
59
60for path, properties in modems:
61 if "org.ofono.NetworkTime" in properties["Interfaces"]:
62 break
63
64net_time = dbus.Interface(bus.get_object('org.ofono', path),
65 'org.ofono.NetworkTime')
66
67time = net_time.GetNetworkTime()
68
69print pretty(time)
070
=== modified file 'test/monitor-ofono'
--- test/monitor-ofono 2013-01-28 16:25:32 +0000
+++ test/monitor-ofono 2013-06-26 17:26:23 +0000
@@ -74,6 +74,10 @@
74 print "{%s} [%s] %s %s (%s)" % (iface, path, member,74 print "{%s} [%s] %s %s (%s)" % (iface, path, member,
75 msg, pretty(args))75 msg, pretty(args))
7676
77def network_time_changed(time, member, path, interface):
78 iface = interface[interface.rfind(".") + 1:]
79 print "{%s} [%s] %s %s" % (iface, path, member, pretty(time))
80
77def ussd(msg, member, path, interface):81def ussd(msg, member, path, interface):
78 iface = interface[interface.rfind(".") + 1:]82 iface = interface[interface.rfind(".") + 1:]
79 print "{%s} [%s] %s %s" % (iface, path, member, msg)83 print "{%s} [%s] %s %s" % (iface, path, member, msg)
@@ -150,5 +154,13 @@
150 path_keyword="path",154 path_keyword="path",
151 interface_keyword="interface")155 interface_keyword="interface")
152156
157 for member in ["NetworkTimeChanged"]:
158 bus.add_signal_receiver(network_time_changed,
159 bus_name="org.ofono",
160 signal_name = member,
161 member_keyword="member",
162 path_keyword="path",
163 interface_keyword="interface")
164
153 mainloop = gobject.MainLoop()165 mainloop = gobject.MainLoop()
154 mainloop.run()166 mainloop.run()

Subscribers

People subscribed via source and target branches