Merge lp:~awe/phablet-extras/ofono-nettime-plugin into lp:phablet-extras/ofono
- ofono-nettime-plugin
- Merge into ofono
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 |
Related bugs: |
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.
Tony Espy (awe) wrote : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:43
http://
Executed test runs:
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:44
http://
Executed test runs:
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Ricardo Salveti (rsalveti) wrote : | # |
476 + for member in ["NetworkTimeRe
This should be NetworkTimeChanged instead.
Other than that, code looks good.
Tony Espy (awe) wrote : | # |
Nice catch... fixed.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:45
http://
Executed test runs:
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:46
http://
Executed test runs:
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'Makefile.am' | |||
2 | --- Makefile.am 2013-04-12 20:04:45 +0000 | |||
3 | +++ Makefile.am 2013-06-26 17:26:23 +0000 | |||
4 | @@ -466,6 +466,11 @@ | |||
5 | 466 | endif | 466 | endif |
6 | 467 | endif | 467 | endif |
7 | 468 | 468 | ||
8 | 469 | if NETTIME | ||
9 | 470 | builtin_modules += nettime | ||
10 | 471 | builtin_sources += plugins/nettime.c | ||
11 | 472 | endif | ||
12 | 473 | |||
13 | 469 | if PROVISION | 474 | if PROVISION |
14 | 470 | builtin_sources += plugins/mbpi.h plugins/mbpi.c | 475 | builtin_sources += plugins/mbpi.h plugins/mbpi.c |
15 | 471 | 476 | ||
16 | 472 | 477 | ||
17 | === modified file 'configure.ac' | |||
18 | --- configure.ac 2013-03-28 12:50:26 +0000 | |||
19 | +++ configure.ac 2013-06-26 17:26:23 +0000 | |||
20 | @@ -188,6 +188,11 @@ | |||
21 | 188 | AC_SUBST(BLUEZ_LIBS) | 188 | AC_SUBST(BLUEZ_LIBS) |
22 | 189 | AM_CONDITIONAL(BLUETOOTH, test "${enable_bluetooth}" != "no") | 189 | AM_CONDITIONAL(BLUETOOTH, test "${enable_bluetooth}" != "no") |
23 | 190 | 190 | ||
24 | 191 | AC_ARG_ENABLE(nettime, AC_HELP_STRING([--disable-nettime], | ||
25 | 192 | [disable Nettime plugin]), | ||
26 | 193 | [enable_nettime=${enableval}]) | ||
27 | 194 | AM_CONDITIONAL(NETTIME, test "${enable_netttime}" != "no") | ||
28 | 195 | |||
29 | 191 | AC_ARG_WITH([provisiondb], AC_HELP_STRING([--with-provisiondb=FILE], | 196 | AC_ARG_WITH([provisiondb], AC_HELP_STRING([--with-provisiondb=FILE], |
30 | 192 | [location of provision database]), [path_provisiondb=${withval}]) | 197 | [location of provision database]), [path_provisiondb=${withval}]) |
31 | 193 | 198 | ||
32 | 194 | 199 | ||
33 | === modified file 'debian/changelog' | |||
34 | --- debian/changelog 2013-06-26 15:49:07 +0000 | |||
35 | +++ debian/changelog 2013-06-26 17:26:23 +0000 | |||
36 | @@ -1,7 +1,11 @@ | |||
38 | 1 | ofono (1.12phablet7) UNRELEASED; urgency=low | 1 | ofono (1.12phablet7) saucy; urgency=low |
39 | 2 | 2 | ||
40 | 3 | [ Tony Espy ] | ||
41 | 3 | * gril/gril.c: Exit on RILD socket failures. | 4 | * gril/gril.c: Exit on RILD socket failures. |
42 | 4 | 5 | ||
43 | 6 | [ Petri M. Gerdt <petri.gerdt@jollamobile.com> ] | ||
44 | 7 | * plugins/nettime.c: Added nettime plugin. | ||
45 | 8 | |||
46 | 5 | -- Tony Espy <espy@canonical.com> Tue, 25 Jun 2013 15:14:13 -0400 | 9 | -- Tony Espy <espy@canonical.com> Tue, 25 Jun 2013 15:14:13 -0400 |
47 | 6 | 10 | ||
48 | 7 | ofono (1.12phablet6) saucy; urgency=low | 11 | ofono (1.12phablet6) saucy; urgency=low |
49 | 8 | 12 | ||
50 | === modified file 'include/dbus.h' | |||
51 | --- include/dbus.h 2012-08-22 19:59:08 +0000 | |||
52 | +++ include/dbus.h 2013-06-26 17:26:23 +0000 | |||
53 | @@ -59,6 +59,7 @@ | |||
54 | 59 | #define OFONO_GNSS_INTERFACE "org.ofono.AssistedSatelliteNavigation" | 59 | #define OFONO_GNSS_INTERFACE "org.ofono.AssistedSatelliteNavigation" |
55 | 60 | #define OFONO_GNSS_POSR_AGENT_INTERFACE "org.ofono.PositioningRequestAgent" | 60 | #define OFONO_GNSS_POSR_AGENT_INTERFACE "org.ofono.PositioningRequestAgent" |
56 | 61 | #define OFONO_HANDSFREE_INTERFACE OFONO_SERVICE ".Handsfree" | 61 | #define OFONO_HANDSFREE_INTERFACE OFONO_SERVICE ".Handsfree" |
57 | 62 | #define OFONO_NETWORK_TIME_INTERFACE OFONO_SERVICE ".NetworkTime" | ||
58 | 62 | 63 | ||
59 | 63 | /* CDMA Interfaces */ | 64 | /* CDMA Interfaces */ |
60 | 64 | #define OFONO_CDMA_VOICECALL_MANAGER_INTERFACE "org.ofono.cdma.VoiceCallManager" | 65 | #define OFONO_CDMA_VOICECALL_MANAGER_INTERFACE "org.ofono.cdma.VoiceCallManager" |
61 | 65 | 66 | ||
62 | === added file 'plugins/nettime.c' | |||
63 | --- plugins/nettime.c 1970-01-01 00:00:00 +0000 | |||
64 | +++ plugins/nettime.c 2013-06-26 17:26:23 +0000 | |||
65 | @@ -0,0 +1,274 @@ | |||
66 | 1 | /* | ||
67 | 2 | * | ||
68 | 3 | * oFono - Open Source Telephony | ||
69 | 4 | * | ||
70 | 5 | * Copyright (C) 2012-2013 Jolla Ltd. | ||
71 | 6 | * | ||
72 | 7 | * This program is free software; you can redistribute it and/or modify | ||
73 | 8 | * it under the terms of the GNU General Public License version 2 as | ||
74 | 9 | * published by the Free Software Foundation. | ||
75 | 10 | * | ||
76 | 11 | * This program is distributed in the hope that it will be useful, | ||
77 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
78 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
79 | 14 | * GNU General Public License for more details. | ||
80 | 15 | * | ||
81 | 16 | * You should have received a copy of the GNU General Public License | ||
82 | 17 | * along with this program; if not, write to the Free Software | ||
83 | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
84 | 19 | * | ||
85 | 20 | */ | ||
86 | 21 | |||
87 | 22 | #ifdef HAVE_CONFIG_H | ||
88 | 23 | #include <config.h> | ||
89 | 24 | #endif | ||
90 | 25 | |||
91 | 26 | #include <string.h> | ||
92 | 27 | #include <glib.h> | ||
93 | 28 | #include <gdbus.h> | ||
94 | 29 | |||
95 | 30 | #define OFONO_API_SUBJECT_TO_CHANGE | ||
96 | 31 | #include <ofono/plugin.h> | ||
97 | 32 | #include <ofono/log.h> | ||
98 | 33 | #include <ofono/nettime.h> | ||
99 | 34 | #include <ofono/types.h> | ||
100 | 35 | |||
101 | 36 | #include "ofono.h" | ||
102 | 37 | |||
103 | 38 | #include "common.h" | ||
104 | 39 | |||
105 | 40 | struct nt_data { | ||
106 | 41 | gboolean time_available; | ||
107 | 42 | gboolean time_pending; | ||
108 | 43 | |||
109 | 44 | time_t nw_time_utc; | ||
110 | 45 | time_t received; | ||
111 | 46 | |||
112 | 47 | int dst; | ||
113 | 48 | int time_zone; | ||
114 | 49 | |||
115 | 50 | const char *mcc; | ||
116 | 51 | const char *mnc; | ||
117 | 52 | const char *path; | ||
118 | 53 | }; | ||
119 | 54 | |||
120 | 55 | static struct nt_data *ntd = NULL; | ||
121 | 56 | |||
122 | 57 | |||
123 | 58 | static void init_time(void) | ||
124 | 59 | { | ||
125 | 60 | ntd = g_new0(struct nt_data, 1); | ||
126 | 61 | |||
127 | 62 | ntd->time_available = FALSE; | ||
128 | 63 | ntd->time_pending = FALSE; | ||
129 | 64 | ntd->dst = 0; | ||
130 | 65 | ntd->time_zone = 0; | ||
131 | 66 | } | ||
132 | 67 | |||
133 | 68 | static gboolean encode_time_format(const struct ofono_network_time *time, | ||
134 | 69 | struct tm *tm) | ||
135 | 70 | { | ||
136 | 71 | if (time->year < 0) | ||
137 | 72 | return FALSE; | ||
138 | 73 | |||
139 | 74 | memset(tm, 0, sizeof(struct tm)); | ||
140 | 75 | tm->tm_year = time->year - 1900; | ||
141 | 76 | tm->tm_mon = time->mon - 1; | ||
142 | 77 | tm->tm_mday = time->mday; | ||
143 | 78 | tm->tm_hour = time->hour; | ||
144 | 79 | tm->tm_min = time->min; | ||
145 | 80 | tm->tm_sec = time->sec; | ||
146 | 81 | tm->tm_gmtoff = time->utcoff; | ||
147 | 82 | tm->tm_isdst = time->dst; | ||
148 | 83 | |||
149 | 84 | return TRUE; | ||
150 | 85 | } | ||
151 | 86 | |||
152 | 87 | static time_t get_monotonic_time() | ||
153 | 88 | { | ||
154 | 89 | struct timespec ts; | ||
155 | 90 | clock_gettime(CLOCK_MONOTONIC, &ts); | ||
156 | 91 | return ts.tv_sec; | ||
157 | 92 | } | ||
158 | 93 | |||
159 | 94 | static int fill_time_notification(DBusMessage *msg, | ||
160 | 95 | struct nt_data *ntd) | ||
161 | 96 | { | ||
162 | 97 | DBusMessageIter iter, iter_array; | ||
163 | 98 | dbus_int64_t utc_long, received; | ||
164 | 99 | dbus_int32_t dst, timezone; | ||
165 | 100 | dbus_message_iter_init_append(msg, &iter); | ||
166 | 101 | dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, | ||
167 | 102 | "{sv}", | ||
168 | 103 | &iter_array); | ||
169 | 104 | if (ntd->time_pending) { | ||
170 | 105 | if (ntd->time_available) { | ||
171 | 106 | utc_long = (dbus_int64_t) ntd->nw_time_utc; | ||
172 | 107 | ofono_dbus_dict_append(&iter_array, | ||
173 | 108 | "UTC", | ||
174 | 109 | DBUS_TYPE_INT64, | ||
175 | 110 | &utc_long); | ||
176 | 111 | dst = (dbus_int32_t) ntd->dst; | ||
177 | 112 | ofono_dbus_dict_append(&iter_array, | ||
178 | 113 | "DST", | ||
179 | 114 | DBUS_TYPE_UINT32, | ||
180 | 115 | &dst); | ||
181 | 116 | received = (dbus_int64_t) ntd->received; | ||
182 | 117 | ofono_dbus_dict_append(&iter_array, | ||
183 | 118 | "Received", | ||
184 | 119 | DBUS_TYPE_INT64, | ||
185 | 120 | &received); | ||
186 | 121 | } | ||
187 | 122 | |||
188 | 123 | timezone = (dbus_int32_t) ntd->time_zone; | ||
189 | 124 | ofono_dbus_dict_append(&iter_array, | ||
190 | 125 | "Timezone", | ||
191 | 126 | DBUS_TYPE_INT32, | ||
192 | 127 | &timezone); | ||
193 | 128 | |||
194 | 129 | ofono_dbus_dict_append(&iter_array, | ||
195 | 130 | "MobileCountryCode", | ||
196 | 131 | DBUS_TYPE_STRING, | ||
197 | 132 | &ntd->mcc); | ||
198 | 133 | |||
199 | 134 | ofono_dbus_dict_append(&iter_array, | ||
200 | 135 | "MobileNetworkCode", | ||
201 | 136 | DBUS_TYPE_STRING, | ||
202 | 137 | &ntd->mnc); | ||
203 | 138 | } else { | ||
204 | 139 | DBG("fill_time_notification: time not available"); | ||
205 | 140 | } | ||
206 | 141 | |||
207 | 142 | dbus_message_iter_close_container(&iter, &iter_array); | ||
208 | 143 | return 0; | ||
209 | 144 | } | ||
210 | 145 | |||
211 | 146 | static DBusMessage *get_network_time(DBusConnection *conn, | ||
212 | 147 | DBusMessage *msg, void *data) | ||
213 | 148 | { | ||
214 | 149 | DBusMessage *reply; | ||
215 | 150 | |||
216 | 151 | reply = dbus_message_new_method_return(msg); | ||
217 | 152 | if (reply == NULL) | ||
218 | 153 | return NULL; | ||
219 | 154 | fill_time_notification(reply, ntd); | ||
220 | 155 | return reply; | ||
221 | 156 | } | ||
222 | 157 | |||
223 | 158 | static const GDBusMethodTable nettime_methods[] = { | ||
224 | 159 | { GDBUS_METHOD("GetNetworkTime", | ||
225 | 160 | NULL, GDBUS_ARGS({ "time", "a{sv}" }), | ||
226 | 161 | get_network_time) }, | ||
227 | 162 | { } | ||
228 | 163 | }; | ||
229 | 164 | |||
230 | 165 | static const GDBusSignalTable nettime_signals[] = { | ||
231 | 166 | { GDBUS_SIGNAL("NetworkTimeChanged", | ||
232 | 167 | GDBUS_ARGS({ "time", "a{sv}" })) }, | ||
233 | 168 | { } | ||
234 | 169 | }; | ||
235 | 170 | |||
236 | 171 | static int nettime_probe(struct ofono_nettime_context *context) | ||
237 | 172 | { | ||
238 | 173 | DBusConnection *conn = ofono_dbus_get_connection(); | ||
239 | 174 | const char *path = ofono_modem_get_path(context->modem); | ||
240 | 175 | DBG("Network time probe for modem: %p (%s)", context->modem, path); | ||
241 | 176 | init_time(); | ||
242 | 177 | if (!g_dbus_register_interface(conn, path, | ||
243 | 178 | OFONO_NETWORK_TIME_INTERFACE, // name | ||
244 | 179 | nettime_methods, // methods | ||
245 | 180 | nettime_signals, // signals | ||
246 | 181 | NULL, // GDBusPropertyTable *properties | ||
247 | 182 | NULL, // user data | ||
248 | 183 | NULL)) { // GDBusDestroyFunction destroy | ||
249 | 184 | ofono_error("Networkt time: Could not register interface %s, path %s", | ||
250 | 185 | OFONO_NETWORK_TIME_INTERFACE, path); | ||
251 | 186 | return 1; | ||
252 | 187 | } else { | ||
253 | 188 | ofono_info("Network time: Registered inteface %s, path %s", | ||
254 | 189 | OFONO_NETWORK_TIME_INTERFACE, path); | ||
255 | 190 | } | ||
256 | 191 | |||
257 | 192 | ofono_modem_add_interface(context->modem, OFONO_NETWORK_TIME_INTERFACE); | ||
258 | 193 | return 0; | ||
259 | 194 | } | ||
260 | 195 | |||
261 | 196 | static void nettime_remove(struct ofono_nettime_context *context) | ||
262 | 197 | { | ||
263 | 198 | DBusConnection *conn = ofono_dbus_get_connection(); | ||
264 | 199 | const char *path = ofono_modem_get_path(context->modem); | ||
265 | 200 | DBG("Network time remove for modem: %p (%s)", context->modem, path); | ||
266 | 201 | if (!g_dbus_unregister_interface(conn, path, OFONO_NETWORK_TIME_INTERFACE)) { | ||
267 | 202 | ofono_error("Network time: could not unregister interface %s, path %s", | ||
268 | 203 | OFONO_NETWORK_TIME_INTERFACE, path); | ||
269 | 204 | } | ||
270 | 205 | |||
271 | 206 | ofono_modem_remove_interface(context->modem, OFONO_NETWORK_TIME_INTERFACE); | ||
272 | 207 | g_free(ntd); | ||
273 | 208 | } | ||
274 | 209 | |||
275 | 210 | static void send_signal(struct nt_data *ntd) | ||
276 | 211 | { | ||
277 | 212 | DBusConnection *conn = ofono_dbus_get_connection(); | ||
278 | 213 | DBusMessage *signal = dbus_message_new_signal(ntd->path, | ||
279 | 214 | OFONO_NETWORK_TIME_INTERFACE, | ||
280 | 215 | "NetworkTimeChanged"); | ||
281 | 216 | fill_time_notification(signal, ntd); | ||
282 | 217 | g_dbus_send_message(conn, signal); | ||
283 | 218 | } | ||
284 | 219 | |||
285 | 220 | static void nettime_info_received(struct ofono_nettime_context *context, | ||
286 | 221 | struct ofono_network_time *info) | ||
287 | 222 | { | ||
288 | 223 | struct ofono_netreg *netreg; | ||
289 | 224 | struct tm t; | ||
290 | 225 | |||
291 | 226 | if (info == NULL) | ||
292 | 227 | return; | ||
293 | 228 | |||
294 | 229 | netreg = __ofono_atom_get_data(__ofono_modem_find_atom( | ||
295 | 230 | context->modem, OFONO_ATOM_TYPE_NETREG)); | ||
296 | 231 | ntd->path = ofono_modem_get_path(context->modem); | ||
297 | 232 | ntd->mcc = ofono_netreg_get_mcc(netreg); | ||
298 | 233 | ntd->mnc = ofono_netreg_get_mnc(netreg); | ||
299 | 234 | ntd->received = get_monotonic_time(); | ||
300 | 235 | ntd->time_pending = TRUE; | ||
301 | 236 | ntd->dst = info->dst; | ||
302 | 237 | ntd->time_zone = info->utcoff; | ||
303 | 238 | |||
304 | 239 | ntd->time_available = encode_time_format(info, &t); | ||
305 | 240 | if (ntd->time_available == TRUE) | ||
306 | 241 | ntd->nw_time_utc = timegm(&t); | ||
307 | 242 | |||
308 | 243 | send_signal(ntd); | ||
309 | 244 | DBG("modem: %p (%s)", context->modem, ofono_modem_get_path(context->modem)); | ||
310 | 245 | DBG("time: %04d-%02d-%02d %02d:%02d:%02d%c%02d:%02d (DST=%d)", | ||
311 | 246 | info->year, info->mon, info->mday, info->hour, | ||
312 | 247 | info->min, info->sec, info->utcoff > 0 ? '+' : '-', | ||
313 | 248 | abs(info->utcoff) / 3600, (abs(info->utcoff) % 3600) / 60, | ||
314 | 249 | info->dst); | ||
315 | 250 | DBG("UTC timestamp: %li, Received (monotonic time): %li", | ||
316 | 251 | ntd->nw_time_utc, ntd->received); | ||
317 | 252 | DBG("MCC: %s, MNC: %s", ntd->mcc, ntd->mnc); | ||
318 | 253 | } | ||
319 | 254 | |||
320 | 255 | static struct ofono_nettime_driver driver = { | ||
321 | 256 | .name = "Network Time", | ||
322 | 257 | .probe = nettime_probe, | ||
323 | 258 | .remove = nettime_remove, | ||
324 | 259 | .info_received = nettime_info_received, | ||
325 | 260 | }; | ||
326 | 261 | |||
327 | 262 | static int nettime_init(void) | ||
328 | 263 | { | ||
329 | 264 | return ofono_nettime_driver_register(&driver); | ||
330 | 265 | } | ||
331 | 266 | |||
332 | 267 | static void nettime_exit(void) | ||
333 | 268 | { | ||
334 | 269 | ofono_nettime_driver_unregister(&driver); | ||
335 | 270 | } | ||
336 | 271 | |||
337 | 272 | OFONO_PLUGIN_DEFINE(nettime, "Network Time Plugin", | ||
338 | 273 | VERSION, OFONO_PLUGIN_PRIORITY_DEFAULT, | ||
339 | 274 | nettime_init, nettime_exit) | ||
340 | 0 | 275 | ||
341 | === added file 'test/get-network-time' | |||
342 | --- test/get-network-time 1970-01-01 00:00:00 +0000 | |||
343 | +++ test/get-network-time 2013-06-26 17:26:23 +0000 | |||
344 | @@ -0,0 +1,69 @@ | |||
345 | 1 | #!/usr/bin/python | ||
346 | 2 | |||
347 | 3 | import dbus | ||
348 | 4 | import sys | ||
349 | 5 | _dbus2py = { | ||
350 | 6 | dbus.String : unicode, | ||
351 | 7 | dbus.UInt32 : int, | ||
352 | 8 | dbus.Int32 : int, | ||
353 | 9 | dbus.Int16 : int, | ||
354 | 10 | dbus.UInt16 : int, | ||
355 | 11 | dbus.UInt64 : int, | ||
356 | 12 | dbus.Int64 : int, | ||
357 | 13 | dbus.Byte : int, | ||
358 | 14 | dbus.Boolean : bool, | ||
359 | 15 | dbus.ByteArray : str, | ||
360 | 16 | dbus.ObjectPath : str | ||
361 | 17 | } | ||
362 | 18 | |||
363 | 19 | def dbus2py(d): | ||
364 | 20 | t = type(d) | ||
365 | 21 | if t in _dbus2py: | ||
366 | 22 | return _dbus2py[t](d) | ||
367 | 23 | if t is dbus.Dictionary: | ||
368 | 24 | return dict([(dbus2py(k), dbus2py(v)) for k, v in d.items()]) | ||
369 | 25 | if t is dbus.Array and d.signature == "y": | ||
370 | 26 | return "".join([chr(b) for b in d]) | ||
371 | 27 | if t is dbus.Array or t is list: | ||
372 | 28 | return [dbus2py(v) for v in d] | ||
373 | 29 | if t is dbus.Struct or t is tuple: | ||
374 | 30 | return tuple([dbus2py(v) for v in d]) | ||
375 | 31 | return d | ||
376 | 32 | |||
377 | 33 | def pretty(d): | ||
378 | 34 | d = dbus2py(d) | ||
379 | 35 | t = type(d) | ||
380 | 36 | |||
381 | 37 | if t in (dict, tuple, list) and len(d) > 0: | ||
382 | 38 | if t is dict: | ||
383 | 39 | d = ", ".join(["%s = %s" % (k, pretty(v)) | ||
384 | 40 | for k, v in d.items()]) | ||
385 | 41 | return "{ %s }" % d | ||
386 | 42 | |||
387 | 43 | d = " ".join([pretty(e) for e in d]) | ||
388 | 44 | |||
389 | 45 | if t is tuple: | ||
390 | 46 | return "( %s )" % d | ||
391 | 47 | |||
392 | 48 | if t is str: | ||
393 | 49 | return "%s" % d | ||
394 | 50 | |||
395 | 51 | return str(d) | ||
396 | 52 | |||
397 | 53 | bus = dbus.SystemBus() | ||
398 | 54 | |||
399 | 55 | manager = dbus.Interface(bus.get_object("org.ofono", "/"), | ||
400 | 56 | "org.ofono.Manager") | ||
401 | 57 | |||
402 | 58 | modems = manager.GetModems() | ||
403 | 59 | |||
404 | 60 | for path, properties in modems: | ||
405 | 61 | if "org.ofono.NetworkTime" in properties["Interfaces"]: | ||
406 | 62 | break | ||
407 | 63 | |||
408 | 64 | net_time = dbus.Interface(bus.get_object('org.ofono', path), | ||
409 | 65 | 'org.ofono.NetworkTime') | ||
410 | 66 | |||
411 | 67 | time = net_time.GetNetworkTime() | ||
412 | 68 | |||
413 | 69 | print pretty(time) | ||
414 | 0 | 70 | ||
415 | === modified file 'test/monitor-ofono' | |||
416 | --- test/monitor-ofono 2013-01-28 16:25:32 +0000 | |||
417 | +++ test/monitor-ofono 2013-06-26 17:26:23 +0000 | |||
418 | @@ -74,6 +74,10 @@ | |||
419 | 74 | print "{%s} [%s] %s %s (%s)" % (iface, path, member, | 74 | print "{%s} [%s] %s %s (%s)" % (iface, path, member, |
420 | 75 | msg, pretty(args)) | 75 | msg, pretty(args)) |
421 | 76 | 76 | ||
422 | 77 | def network_time_changed(time, member, path, interface): | ||
423 | 78 | iface = interface[interface.rfind(".") + 1:] | ||
424 | 79 | print "{%s} [%s] %s %s" % (iface, path, member, pretty(time)) | ||
425 | 80 | |||
426 | 77 | def ussd(msg, member, path, interface): | 81 | def ussd(msg, member, path, interface): |
427 | 78 | iface = interface[interface.rfind(".") + 1:] | 82 | iface = interface[interface.rfind(".") + 1:] |
428 | 79 | print "{%s} [%s] %s %s" % (iface, path, member, msg) | 83 | print "{%s} [%s] %s %s" % (iface, path, member, msg) |
429 | @@ -150,5 +154,13 @@ | |||
430 | 150 | path_keyword="path", | 154 | path_keyword="path", |
431 | 151 | interface_keyword="interface") | 155 | interface_keyword="interface") |
432 | 152 | 156 | ||
433 | 157 | for member in ["NetworkTimeChanged"]: | ||
434 | 158 | bus.add_signal_receiver(network_time_changed, | ||
435 | 159 | bus_name="org.ofono", | ||
436 | 160 | signal_name = member, | ||
437 | 161 | member_keyword="member", | ||
438 | 162 | path_keyword="path", | ||
439 | 163 | interface_keyword="interface") | ||
440 | 164 | |||
441 | 153 | mainloop = gobject.MainLoop() | 165 | mainloop = gobject.MainLoop() |
442 | 154 | mainloop.run() | 166 | mainloop.run() |
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...