Merge lp:~kvalo/indicator-network/libconnman-sort-services into lp:~indicator-applet-developers/indicator-network/indicator-network
- libconnman-sort-services
- Merge into indicator-network
Proposed by
Kalle Valo
on 2010-12-03
| Status: | Merged |
|---|---|
| Merged at revision: | 113 |
| Proposed branch: | lp:~kvalo/indicator-network/libconnman-sort-services |
| Merge into: | lp:~indicator-applet-developers/indicator-network/indicator-network |
| Diff against target: |
891 lines (+375/-80) 15 files modified
.bzrignore (+3/-3) configure.ac (+3/-2) src/Makefile.am (+1/-0) src/backend/manager.c (+18/-10) src/backend/service-manager.c (+27/-17) src/backend/service-manager.h (+4/-0) src/common/Makefile.am (+1/-16) src/libconnman/Makefile.am (+17/-0) src/libconnman/connman-manager.c (+217/-25) src/libconnman/connman-manager.h (+1/-0) src/libconnman/connman-service.c (+21/-1) tests/Makefile.am (+1/-0) tests/libconnman-tool.c (+52/-6) tests/mock-connman-manager.c (+5/-0) tests/mock-service-manager.c (+4/-0) |
| To merge this branch: | bzr merge lp:~kvalo/indicator-network/libconnman-sort-services |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Mikkel Kamstrup Erlandsen (community) | 2010-12-03 | Approve on 2010-12-03 | |
|
Review via email:
|
|||
Commit Message
Description of the Change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
| 1 | === modified file '.bzrignore' |
| 2 | --- .bzrignore 2010-11-17 14:07:04 +0000 |
| 3 | +++ .bzrignore 2010-12-03 09:51:48 +0000 |
| 4 | @@ -84,7 +84,7 @@ |
| 5 | src/common/ofono-manager-xml.h |
| 6 | src/common/ofono-modem-xml.h |
| 7 | src/common/ofono-simmanager-xml.h |
| 8 | -src/common/libconnman.la |
| 9 | -src/common/libconnman_la-connman-manager.lo |
| 10 | +src/libconnman/libconnman.la |
| 11 | +src/libconnman/libconnman_la-connman-manager.lo |
| 12 | tests/libconnman-tool |
| 13 | -src/common/libconnman_la-connman-service.lo |
| 14 | +src/libconnman/libconnman_la-connman-service.lo |
| 15 | |
| 16 | === modified file 'configure.ac' |
| 17 | --- configure.ac 2010-11-30 15:10:47 +0000 |
| 18 | +++ configure.ac 2010-12-03 09:51:48 +0000 |
| 19 | @@ -120,8 +120,8 @@ |
| 20 | AC_DEFINE_UNQUOTED($1, "$ac_define_path", $3)) |
| 21 | ]) |
| 22 | |
| 23 | -CONNMAN_CFLAGS="-I\$(top_srcdir)/src/common" |
| 24 | -CONNMAN_LIBS="\$(top_builddir)/src/common/libconnman.la" |
| 25 | +CONNMAN_CFLAGS="-I\$(top_srcdir)/src/libconnman" |
| 26 | +CONNMAN_LIBS="\$(top_builddir)/src/libconnman/libconnman.la" |
| 27 | |
| 28 | AC_SUBST(CONNMAN_CFLAGS) |
| 29 | AC_SUBST(CONNMAN_LIBS) |
| 30 | @@ -146,6 +146,7 @@ |
| 31 | src/Makefile |
| 32 | src/indicator/Makefile |
| 33 | src/common/Makefile |
| 34 | +src/libconnman/Makefile |
| 35 | src/backend/Makefile |
| 36 | src/agent/Makefile |
| 37 | data/Makefile |
| 38 | |
| 39 | === modified file 'src/Makefile.am' |
| 40 | --- src/Makefile.am 2010-09-23 07:43:40 +0000 |
| 41 | +++ src/Makefile.am 2010-12-03 09:51:48 +0000 |
| 42 | @@ -1,5 +1,6 @@ |
| 43 | SUBDIRS = \ |
| 44 | common \ |
| 45 | + libconnman \ |
| 46 | indicator \ |
| 47 | backend \ |
| 48 | agent |
| 49 | |
| 50 | === modified file 'src/backend/manager.c' |
| 51 | --- src/backend/manager.c 2010-11-25 15:12:47 +0000 |
| 52 | +++ src/backend/manager.c 2010-12-03 09:51:48 +0000 |
| 53 | @@ -95,7 +95,6 @@ |
| 54 | gint connecting_stage; |
| 55 | gint connecting_state; |
| 56 | gchar *connecting_icons[CONNECTING_ICON_STAGES][CONNECTING_ICON_STATES]; |
| 57 | - gchar *default_service_path; |
| 58 | gint signal_strength; |
| 59 | ManagerState manager_state; |
| 60 | NetworkMenu *network_menu; |
| 61 | @@ -342,23 +341,18 @@ |
| 62 | update_icon(self); |
| 63 | } |
| 64 | |
| 65 | -static void default_service_changed(ServiceManager *sm, gpointer user_data) |
| 66 | +static void default_service_changed(Manager *self) |
| 67 | { |
| 68 | - Manager *self = MANAGER(user_data); |
| 69 | ManagerPrivate *priv = GET_PRIVATE(self); |
| 70 | Service *service; |
| 71 | |
| 72 | g_return_if_fail(self != NULL); |
| 73 | g_return_if_fail(priv != NULL); |
| 74 | |
| 75 | - g_free(priv->default_service_path); |
| 76 | - priv->default_service_path = NULL; |
| 77 | - |
| 78 | service = service_manager_get_default_service(priv->service_manager); |
| 79 | if (service == NULL) |
| 80 | goto done; |
| 81 | |
| 82 | - priv->default_service_path = g_strdup(service_get_path(service)); |
| 83 | priv->signal_strength = service_get_strength(service); |
| 84 | |
| 85 | done: |
| 86 | @@ -376,6 +370,19 @@ |
| 87 | update_icon(self); |
| 88 | } |
| 89 | |
| 90 | +static void default_service_notify(ConnmanManager *connman, GParamSpec *pspec, |
| 91 | + gpointer user_data) |
| 92 | +{ |
| 93 | + Manager *self = MANAGER(user_data); |
| 94 | + ManagerPrivate *priv = GET_PRIVATE(self); |
| 95 | + ConnmanService *cs; |
| 96 | + |
| 97 | + cs = connman_manager_get_default_service(priv->connman); |
| 98 | + service_manager_update_default_service(priv->service_manager, cs); |
| 99 | + |
| 100 | + default_service_changed(self); |
| 101 | +} |
| 102 | + |
| 103 | static void update_services(Manager *self) |
| 104 | { |
| 105 | ManagerPrivate *priv = GET_PRIVATE(self); |
| 106 | @@ -466,6 +473,10 @@ |
| 107 | G_CALLBACK(connman_service_removed), |
| 108 | self); |
| 109 | |
| 110 | + g_signal_connect(priv->connman, "notify::default-service", |
| 111 | + G_CALLBACK(default_service_notify), |
| 112 | + self); |
| 113 | + |
| 114 | if (connman_manager_is_connected(priv->connman)) |
| 115 | connman_connected(self); |
| 116 | |
| 117 | @@ -590,9 +601,6 @@ |
| 118 | G_CALLBACK(state_changed), self); |
| 119 | g_signal_connect(G_OBJECT(priv->service_manager), "strength-updated", |
| 120 | G_CALLBACK(strength_updated), self); |
| 121 | - g_signal_connect(G_OBJECT(priv->service_manager), |
| 122 | - "default-service-changed", |
| 123 | - G_CALLBACK(default_service_changed), self); |
| 124 | |
| 125 | create_ui_proxy(self); |
| 126 | create_connman(self); |
| 127 | |
| 128 | === modified file 'src/backend/service-manager.c' |
| 129 | --- src/backend/service-manager.c 2010-11-23 11:29:29 +0000 |
| 130 | +++ src/backend/service-manager.c 2010-12-03 09:51:48 +0000 |
| 131 | @@ -217,14 +217,6 @@ |
| 132 | |
| 133 | g_signal_emit(self, signals[SERVICES_UPDATED], 0); |
| 134 | |
| 135 | - link = g_list_first(priv->services); |
| 136 | - if (link != NULL) |
| 137 | - priv->default_service = link->data; |
| 138 | - else |
| 139 | - priv->default_service = NULL; |
| 140 | - |
| 141 | - g_signal_emit(self, signals[DEFAULT_SERVICE_CHANGED], 0); |
| 142 | - |
| 143 | /* remove unavailable services, we don't want to show them anymore */ |
| 144 | service_manager_free_all(old_services); |
| 145 | old_services = NULL; |
| 146 | @@ -348,19 +340,37 @@ |
| 147 | Service *service_manager_get_default_service(ServiceManager *self) |
| 148 | { |
| 149 | ServiceManagerPrivate *priv = GET_PRIVATE(self); |
| 150 | - Service *service; |
| 151 | - GList *iter; |
| 152 | |
| 153 | g_return_val_if_fail(IS_SERVICE_MANAGER(self), NULL); |
| 154 | g_return_val_if_fail(priv != NULL, NULL); |
| 155 | |
| 156 | - iter = g_list_first(priv->services); |
| 157 | - if (iter == NULL) |
| 158 | - return NULL; |
| 159 | - |
| 160 | - service = iter->data; |
| 161 | - |
| 162 | - return service; |
| 163 | + return priv->default_service; |
| 164 | +} |
| 165 | + |
| 166 | +void service_manager_update_default_service(ServiceManager *self, |
| 167 | + ConnmanService *cs) |
| 168 | +{ |
| 169 | + ServiceManagerPrivate *priv = GET_PRIVATE(self); |
| 170 | + GList *l; |
| 171 | + |
| 172 | + g_return_if_fail(IS_SERVICE_MANAGER(self)); |
| 173 | + g_return_if_fail(priv != NULL); |
| 174 | + |
| 175 | + if (cs == NULL) { |
| 176 | + priv->default_service = NULL; |
| 177 | + goto out; |
| 178 | + } |
| 179 | + |
| 180 | + l = service_manager_find(priv->services, connman_service_get_path(cs)); |
| 181 | + if (l == NULL) { |
| 182 | + priv->default_service = NULL; |
| 183 | + goto out; |
| 184 | + } |
| 185 | + |
| 186 | + priv->default_service = l->data; |
| 187 | + |
| 188 | + out: |
| 189 | + g_signal_emit(self, signals[DEFAULT_SERVICE_CHANGED], 0); |
| 190 | } |
| 191 | |
| 192 | guint service_manager_get_strength(ServiceManager *self) |
| 193 | |
| 194 | === modified file 'src/backend/service-manager.h' |
| 195 | --- src/backend/service-manager.h 2010-11-23 11:29:29 +0000 |
| 196 | +++ src/backend/service-manager.h 2010-12-03 09:51:48 +0000 |
| 197 | @@ -23,6 +23,8 @@ |
| 198 | |
| 199 | #include <glib-object.h> |
| 200 | |
| 201 | +#include "connman-service.h" |
| 202 | + |
| 203 | G_BEGIN_DECLS |
| 204 | |
| 205 | #define TYPE_SERVICE_MANAGER service_manager_get_type() |
| 206 | @@ -69,6 +71,8 @@ |
| 207 | gboolean service_manager_is_connected(ServiceManager *self); |
| 208 | guint service_manager_get_connected(ServiceManager *self); |
| 209 | ConnmanServiceType service_manager_get_default_technology(ServiceManager *self); |
| 210 | +void service_manager_update_default_service(ServiceManager *self, |
| 211 | + ConnmanService *cs); |
| 212 | Service *service_manager_get_default_service(ServiceManager *self); |
| 213 | guint service_manager_get_strength(ServiceManager *self); |
| 214 | |
| 215 | |
| 216 | === modified file 'src/common/Makefile.am' |
| 217 | --- src/common/Makefile.am 2010-11-18 11:33:00 +0000 |
| 218 | +++ src/common/Makefile.am 2010-12-03 09:51:48 +0000 |
| 219 | @@ -1,4 +1,4 @@ |
| 220 | -noinst_LTLIBRARIES = libmarshal.la liblog.la libconnman.la |
| 221 | +noinst_LTLIBRARIES = libmarshal.la liblog.la |
| 222 | |
| 223 | libmarshal_la_SOURCES = \ |
| 224 | marshal-main.c |
| 225 | @@ -25,20 +25,6 @@ |
| 226 | liblog_la_CPPFLAGS = \ |
| 227 | $(GLIB_CFLAGS) |
| 228 | |
| 229 | -libconnman_la_SOURCES = \ |
| 230 | - connman-manager.c \ |
| 231 | - connman-manager.h \ |
| 232 | - connman-service.c \ |
| 233 | - connman-service.h |
| 234 | - |
| 235 | -libconnman_la_LIBADD = \ |
| 236 | - $(GLIB_LIBS) \ |
| 237 | - $(GIO_LIBS) |
| 238 | - |
| 239 | -libconnman_la_CPPFLAGS = \ |
| 240 | - $(GLIB_CFLAGS) \ |
| 241 | - $(GIO_CFLAGS) |
| 242 | - |
| 243 | DBUS_GLIB_INTERFACES = \ |
| 244 | connman-agent.xml \ |
| 245 | connman-manager.xml \ |
| 246 | @@ -100,6 +86,5 @@ |
| 247 | EXTRA_DIST = \ |
| 248 | marshal.list \ |
| 249 | dbus-shared-names.h \ |
| 250 | - connman.h \ |
| 251 | ofono.h \ |
| 252 | $(DBUS_GLIB_INTERFACES) |
| 253 | |
| 254 | === added directory 'src/libconnman' |
| 255 | === added file 'src/libconnman/Makefile.am' |
| 256 | --- src/libconnman/Makefile.am 1970-01-01 00:00:00 +0000 |
| 257 | +++ src/libconnman/Makefile.am 2010-12-03 09:51:48 +0000 |
| 258 | @@ -0,0 +1,17 @@ |
| 259 | +noinst_LTLIBRARIES = libconnman.la |
| 260 | + |
| 261 | +libconnman_la_SOURCES = \ |
| 262 | + connman.h \ |
| 263 | + connman-manager.c \ |
| 264 | + connman-manager.h \ |
| 265 | + connman-service.c \ |
| 266 | + connman-service.h |
| 267 | + |
| 268 | +libconnman_la_LIBADD = \ |
| 269 | + $(GLIB_LIBS) \ |
| 270 | + $(GIO_LIBS) |
| 271 | + |
| 272 | +libconnman_la_CPPFLAGS = \ |
| 273 | + $(GLIB_CFLAGS) \ |
| 274 | + $(GIO_CFLAGS) \ |
| 275 | + -I${top_builddir}/src/common |
| 276 | |
| 277 | === renamed file 'src/common/connman-manager.c' => 'src/libconnman/connman-manager.c' |
| 278 | --- src/common/connman-manager.c 2010-11-19 12:12:06 +0000 |
| 279 | +++ src/libconnman/connman-manager.c 2010-12-03 09:51:48 +0000 |
| 280 | @@ -51,6 +51,15 @@ |
| 281 | |
| 282 | /* used only by get_services() */ |
| 283 | ConnmanService **array; |
| 284 | + |
| 285 | + /* current default service, visible to clients */ |
| 286 | + ConnmanService *default_service; |
| 287 | + |
| 288 | + /* |
| 289 | + * the new default service but waiting for it to be ready, not visible to |
| 290 | + * clients |
| 291 | + */ |
| 292 | + ConnmanService *pending_default_service; |
| 293 | }; |
| 294 | |
| 295 | enum { |
| 296 | @@ -67,6 +76,7 @@ |
| 297 | PROP_0, |
| 298 | |
| 299 | PROP_CONNECTED, |
| 300 | + PROP_DEFAULT_SERVICE, |
| 301 | }; |
| 302 | |
| 303 | static void connect_service_cb(GObject *object, GAsyncResult *res, |
| 304 | @@ -223,6 +233,99 @@ |
| 305 | return priv->array; |
| 306 | } |
| 307 | |
| 308 | +ConnmanService *connman_manager_get_default_service(ConnmanManager *self) |
| 309 | +{ |
| 310 | + ConnmanManagerPrivate *priv = GET_PRIVATE(self); |
| 311 | + |
| 312 | + g_return_val_if_fail(CONNMAN_IS_MANAGER(self), NULL); |
| 313 | + g_return_val_if_fail(priv != NULL, NULL); |
| 314 | + |
| 315 | + return priv->default_service; |
| 316 | +} |
| 317 | + |
| 318 | +static void update_default_service(ConnmanManager *self) |
| 319 | +{ |
| 320 | + ConnmanManagerPrivate *priv = GET_PRIVATE(self); |
| 321 | + gboolean changed = FALSE; |
| 322 | + ConnmanService *pending; |
| 323 | + |
| 324 | + g_return_if_fail(priv != NULL); |
| 325 | + |
| 326 | + pending = priv->pending_default_service; |
| 327 | + |
| 328 | + if (pending == NULL) { |
| 329 | + if (priv->default_service == NULL) |
| 330 | + goto out; |
| 331 | + |
| 332 | + /* remove current default service because there aren't any services */ |
| 333 | + g_object_unref(priv->default_service); |
| 334 | + priv->default_service = NULL; |
| 335 | + changed = TRUE; |
| 336 | + goto check; |
| 337 | + } |
| 338 | + |
| 339 | + /* no need to do anything if the service is already the default */ |
| 340 | + if (priv->default_service == pending) |
| 341 | + goto check; |
| 342 | + |
| 343 | + if (!connman_service_is_ready(pending)) |
| 344 | + /* wait for the ready signal from the service */ |
| 345 | + goto check; |
| 346 | + |
| 347 | + switch(connman_service_get_state(pending)) { |
| 348 | + case CONNMAN_SERVICE_STATE_IDLE: |
| 349 | + case CONNMAN_SERVICE_STATE_FAILURE: |
| 350 | + case CONNMAN_SERVICE_STATE_ASSOCIATION: |
| 351 | + case CONNMAN_SERVICE_STATE_CONFIGURATION: |
| 352 | + case CONNMAN_SERVICE_STATE_DISCONNECT: |
| 353 | + /* pending isn't connected and we can't use it as default, yet */ |
| 354 | + goto check; |
| 355 | + case CONNMAN_SERVICE_STATE_READY: |
| 356 | + case CONNMAN_SERVICE_STATE_LOGIN: |
| 357 | + case CONNMAN_SERVICE_STATE_ONLINE: |
| 358 | + break; |
| 359 | + } |
| 360 | + |
| 361 | + /* pending service is now ready, let's switch to it */ |
| 362 | + if (priv->default_service != NULL) |
| 363 | + g_object_unref(priv->default_service); |
| 364 | + |
| 365 | + /* the ownership moves from pending_default_service to default_service */ |
| 366 | + priv->default_service = pending; |
| 367 | + priv->pending_default_service = NULL; |
| 368 | + changed = TRUE; |
| 369 | + |
| 370 | + check: |
| 371 | + if (priv->default_service == NULL) |
| 372 | + goto out; |
| 373 | + |
| 374 | + /* |
| 375 | + * Let's check the state of the default service and whether it needs to |
| 376 | + * be removed. |
| 377 | + */ |
| 378 | + switch(connman_service_get_state(priv->default_service)) { |
| 379 | + case CONNMAN_SERVICE_STATE_IDLE: |
| 380 | + case CONNMAN_SERVICE_STATE_FAILURE: |
| 381 | + case CONNMAN_SERVICE_STATE_ASSOCIATION: |
| 382 | + case CONNMAN_SERVICE_STATE_CONFIGURATION: |
| 383 | + case CONNMAN_SERVICE_STATE_DISCONNECT: |
| 384 | + /* remove the default service because it's not valid anymore */ |
| 385 | + g_object_unref(priv->default_service); |
| 386 | + priv->default_service = NULL; |
| 387 | + changed = TRUE; |
| 388 | + break; |
| 389 | + case CONNMAN_SERVICE_STATE_READY: |
| 390 | + case CONNMAN_SERVICE_STATE_LOGIN: |
| 391 | + case CONNMAN_SERVICE_STATE_ONLINE: |
| 392 | + break; |
| 393 | + } |
| 394 | + |
| 395 | + out: |
| 396 | + /* don't send any signals until connected to connmand */ |
| 397 | + if (priv->connected && changed) |
| 398 | + g_object_notify(G_OBJECT(self), "default-service"); |
| 399 | +} |
| 400 | + |
| 401 | static void iterate_service_ready(gpointer key, gpointer value, |
| 402 | gpointer user_data) |
| 403 | { |
| 404 | @@ -252,6 +355,10 @@ |
| 405 | if (!connman_service_is_ready(service)) |
| 406 | return; |
| 407 | |
| 408 | + if (priv->pending_default_service != NULL && |
| 409 | + priv->pending_default_service == service) |
| 410 | + update_default_service(self); |
| 411 | + |
| 412 | /* |
| 413 | * Send service added signals only after we are connected. The client |
| 414 | * needs to call get_services() when it has received the connected |
| 415 | @@ -269,13 +376,73 @@ |
| 416 | g_signal_emit(self, signals[SERVICE_ADDED_SIGNAL], 0, service); |
| 417 | } |
| 418 | |
| 419 | +static void service_state_notify(ConnmanService *service, GParamSpec *pspec, |
| 420 | + gpointer user_data) |
| 421 | +{ |
| 422 | + ConnmanManager *self = CONNMAN_MANAGER(user_data); |
| 423 | + ConnmanManagerPrivate *priv = GET_PRIVATE(self); |
| 424 | + |
| 425 | + if (priv->pending_default_service == service || |
| 426 | + priv->default_service == service) |
| 427 | + update_default_service(self); |
| 428 | +} |
| 429 | + |
| 430 | +static ConnmanService *create_service(ConnmanManager *self, |
| 431 | + const gchar *path) |
| 432 | +{ |
| 433 | + ConnmanManagerPrivate *priv = GET_PRIVATE(self); |
| 434 | + ConnmanService *service; |
| 435 | + |
| 436 | + service = connman_service_new(path); |
| 437 | + |
| 438 | + g_hash_table_insert(priv->services, g_strdup(path), service); |
| 439 | + |
| 440 | + /* FIXME: disconnect ready handler */ |
| 441 | + g_signal_connect(service, "notify::ready", G_CALLBACK(service_ready), |
| 442 | + self); |
| 443 | + g_signal_connect(service, "notify::state", |
| 444 | + G_CALLBACK(service_state_notify), self); |
| 445 | + |
| 446 | + return service; |
| 447 | +} |
| 448 | + |
| 449 | +static void remove_service(ConnmanManager *self, ConnmanService *service) |
| 450 | +{ |
| 451 | + ConnmanManagerPrivate *priv = GET_PRIVATE(self); |
| 452 | + const gchar *path = connman_service_get_path(service); |
| 453 | + |
| 454 | + /* |
| 455 | + * Send service removed signals only when connected, connected |
| 456 | + * property with false value implies that services are lost. |
| 457 | + */ |
| 458 | + if (priv->connected) |
| 459 | + g_signal_emit(self, signals[SERVICE_REMOVED_SIGNAL], 0, path); |
| 460 | + |
| 461 | + g_signal_handlers_disconnect_by_func(service, |
| 462 | + G_CALLBACK(service_state_notify), |
| 463 | + self); |
| 464 | + |
| 465 | + g_object_unref(service); |
| 466 | +} |
| 467 | + |
| 468 | +static GHashTable *create_services_list(ConnmanManager *self) |
| 469 | +{ |
| 470 | + return g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); |
| 471 | +} |
| 472 | + |
| 473 | static void notify_service_removal(gpointer key, gpointer value, |
| 474 | - gpointer user_data) |
| 475 | + gpointer user_data) |
| 476 | { |
| 477 | ConnmanManager *self = CONNMAN_MANAGER(user_data); |
| 478 | - gchar *path = key; |
| 479 | - |
| 480 | - g_signal_emit(self, signals[SERVICE_REMOVED_SIGNAL], 0, path); |
| 481 | + ConnmanService *service = CONNMAN_SERVICE(value); |
| 482 | + |
| 483 | + remove_service(self, service); |
| 484 | +} |
| 485 | + |
| 486 | +static void remove_services_list(ConnmanManager *self, GHashTable *list) |
| 487 | +{ |
| 488 | + g_hash_table_foreach(list, notify_service_removal, self); |
| 489 | + g_hash_table_destroy(list); |
| 490 | } |
| 491 | |
| 492 | static void update_services(ConnmanManager *self, GVariant *variant) |
| 493 | @@ -285,12 +452,13 @@ |
| 494 | ConnmanService *service; |
| 495 | gchar *path; |
| 496 | GVariantIter iter; |
| 497 | + gint count; |
| 498 | |
| 499 | old_services = priv->services; |
| 500 | - priv->services = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 501 | - g_free, g_object_unref); |
| 502 | + priv->services = create_services_list(self); |
| 503 | |
| 504 | g_variant_iter_init(&iter, variant); |
| 505 | + count = 0; |
| 506 | |
| 507 | while (g_variant_iter_next(&iter, "o", &path)) { |
| 508 | /* try find an existing service */ |
| 509 | @@ -299,27 +467,28 @@ |
| 510 | |
| 511 | if (service != NULL) { |
| 512 | /* there's already an object for this service */ |
| 513 | - g_object_ref(service); |
| 514 | g_hash_table_remove(old_services, path); |
| 515 | g_hash_table_insert(priv->services, path, service); |
| 516 | - continue; |
| 517 | + goto next; |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | - /* need to create a new object */ |
| 522 | - service = connman_service_new(path); |
| 523 | - g_hash_table_insert(priv->services, path, service); |
| 524 | - |
| 525 | - g_signal_connect(service, "notify::ready", G_CALLBACK(service_ready), |
| 526 | - self); |
| 527 | + service = create_service(self, path); |
| 528 | + g_free(path); |
| 529 | + |
| 530 | + next: |
| 531 | + if (count++ == 0) { |
| 532 | + if (priv->pending_default_service != NULL) |
| 533 | + g_object_unref(priv->pending_default_service); |
| 534 | + |
| 535 | + priv->pending_default_service = g_object_ref(service); |
| 536 | + update_default_service(self); |
| 537 | + } |
| 538 | } |
| 539 | |
| 540 | /* remove services which are not visible anymore */ |
| 541 | if (old_services != NULL) { |
| 542 | - if (priv->initialised) |
| 543 | - g_hash_table_foreach(old_services, notify_service_removal, self); |
| 544 | - |
| 545 | - g_hash_table_destroy(old_services); |
| 546 | + remove_services_list(self, old_services); |
| 547 | old_services = NULL; |
| 548 | } |
| 549 | } |
| 550 | @@ -464,19 +633,16 @@ |
| 551 | if (priv->initialised && !priv->connected) |
| 552 | return; |
| 553 | |
| 554 | + priv->connected = FALSE; |
| 555 | + |
| 556 | if (priv->services != NULL) { |
| 557 | - /* |
| 558 | - * Don't send services removed signals, connected property with false |
| 559 | - * value implies that services are lost. |
| 560 | - */ |
| 561 | - g_hash_table_destroy(priv->services); |
| 562 | + remove_services_list(self, priv->services); |
| 563 | priv->services = NULL; |
| 564 | } |
| 565 | |
| 566 | if (!priv->initialised) |
| 567 | priv->initialised = TRUE; |
| 568 | |
| 569 | - priv->connected = FALSE; |
| 570 | g_object_notify(G_OBJECT(self), "connected"); |
| 571 | } |
| 572 | |
| 573 | @@ -535,6 +701,9 @@ |
| 574 | case PROP_CONNECTED: |
| 575 | priv->connected = g_value_get_boolean(value); |
| 576 | break; |
| 577 | + case PROP_DEFAULT_SERVICE: |
| 578 | + priv->default_service = g_value_get_object(value); |
| 579 | + break; |
| 580 | default: |
| 581 | /* We don't have any other property... */ |
| 582 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); |
| 583 | @@ -552,6 +721,9 @@ |
| 584 | case PROP_CONNECTED: |
| 585 | g_value_set_boolean(value, priv->connected); |
| 586 | break; |
| 587 | + case PROP_DEFAULT_SERVICE: |
| 588 | + g_value_set_object(value, priv->default_service); |
| 589 | + break; |
| 590 | default: |
| 591 | /* We don't have any other property... */ |
| 592 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); |
| 593 | @@ -565,7 +737,7 @@ |
| 594 | ConnmanManagerPrivate *priv = GET_PRIVATE(self); |
| 595 | |
| 596 | if (priv->services != NULL) { |
| 597 | - g_hash_table_destroy(priv->services); |
| 598 | + remove_services_list(self, priv->services); |
| 599 | priv->services = NULL; |
| 600 | } |
| 601 | |
| 602 | @@ -579,6 +751,16 @@ |
| 603 | priv->watch_id = 0; |
| 604 | } |
| 605 | |
| 606 | + if (priv->default_service != NULL) { |
| 607 | + g_object_unref(priv->default_service); |
| 608 | + priv->default_service = NULL; |
| 609 | + } |
| 610 | + |
| 611 | + if (priv->pending_default_service != NULL) { |
| 612 | + g_object_unref(priv->pending_default_service); |
| 613 | + priv->pending_default_service = NULL; |
| 614 | + } |
| 615 | + |
| 616 | G_OBJECT_CLASS(connman_manager_parent_class)->dispose(object); |
| 617 | } |
| 618 | |
| 619 | @@ -627,6 +809,13 @@ |
| 620 | "Set connected state", FALSE, |
| 621 | G_PARAM_READABLE); |
| 622 | g_object_class_install_property(gobject_class, PROP_CONNECTED, pspec); |
| 623 | + |
| 624 | + pspec = g_param_spec_object("default-service", |
| 625 | + "ConnmanManager's default service", |
| 626 | + "Set default service", |
| 627 | + CONNMAN_TYPE_SERVICE, |
| 628 | + G_PARAM_READABLE); |
| 629 | + g_object_class_install_property(gobject_class, PROP_DEFAULT_SERVICE, pspec); |
| 630 | } |
| 631 | |
| 632 | static void connman_manager_init(ConnmanManager *self) |
| 633 | @@ -638,6 +827,9 @@ |
| 634 | priv->connected = FALSE; |
| 635 | priv->initialised = FALSE; |
| 636 | |
| 637 | + priv->default_service = NULL; |
| 638 | + priv->pending_default_service = NULL; |
| 639 | + |
| 640 | g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, |
| 641 | NULL, CONNMAN_SERVICE_NAME, CONNMAN_MANAGER_PATH, |
| 642 | CONNMAN_MANAGER_INTERFACE, NULL, |
| 643 | |
| 644 | === renamed file 'src/common/connman-manager.h' => 'src/libconnman/connman-manager.h' |
| 645 | --- src/common/connman-manager.h 2010-11-19 12:05:05 +0000 |
| 646 | +++ src/libconnman/connman-manager.h 2010-12-03 09:51:48 +0000 |
| 647 | @@ -69,6 +69,7 @@ |
| 648 | GError **error); |
| 649 | gboolean connman_manager_is_connected(ConnmanManager *self); |
| 650 | ConnmanService **connman_manager_get_services(ConnmanManager *self); |
| 651 | +ConnmanService *connman_manager_get_default_service(ConnmanManager *self); |
| 652 | ConnmanManager *connman_manager_new(void); |
| 653 | |
| 654 | #endif |
| 655 | |
| 656 | === renamed file 'src/common/connman-service.c' => 'src/libconnman/connman-service.c' |
| 657 | --- src/common/connman-service.c 2010-11-19 12:12:06 +0000 |
| 658 | +++ src/libconnman/connman-service.c 2010-12-03 09:51:48 +0000 |
| 659 | @@ -234,6 +234,9 @@ |
| 660 | { |
| 661 | ConnmanServicePrivate *priv = GET_PRIVATE(self); |
| 662 | |
| 663 | + g_return_val_if_fail(CONNMAN_IS_SERVICE(self), CONNMAN_SERVICE_STATE_FAILURE); |
| 664 | + g_return_val_if_fail(priv != NULL, CONNMAN_SERVICE_STATE_FAILURE); |
| 665 | + |
| 666 | return priv->state; |
| 667 | } |
| 668 | |
| 669 | @@ -241,6 +244,9 @@ |
| 670 | { |
| 671 | ConnmanServicePrivate *priv = GET_PRIVATE(self); |
| 672 | |
| 673 | + g_return_val_if_fail(CONNMAN_IS_SERVICE(self), NULL); |
| 674 | + g_return_val_if_fail(priv != NULL, NULL); |
| 675 | + |
| 676 | return priv->error; |
| 677 | } |
| 678 | |
| 679 | @@ -248,6 +254,9 @@ |
| 680 | { |
| 681 | ConnmanServicePrivate *priv = GET_PRIVATE(self); |
| 682 | |
| 683 | + g_return_val_if_fail(CONNMAN_IS_SERVICE(self), NULL); |
| 684 | + g_return_val_if_fail(priv != NULL, NULL); |
| 685 | + |
| 686 | return priv->name; |
| 687 | } |
| 688 | |
| 689 | @@ -255,6 +264,9 @@ |
| 690 | { |
| 691 | ConnmanServicePrivate *priv = GET_PRIVATE(self); |
| 692 | |
| 693 | + g_return_val_if_fail(CONNMAN_IS_SERVICE(self), CONNMAN_SERVICE_TYPE_ETHERNET); |
| 694 | + g_return_val_if_fail(priv != NULL, CONNMAN_SERVICE_TYPE_ETHERNET); |
| 695 | + |
| 696 | return priv->type; |
| 697 | } |
| 698 | |
| 699 | @@ -262,6 +274,9 @@ |
| 700 | { |
| 701 | ConnmanServicePrivate *priv = GET_PRIVATE(self); |
| 702 | |
| 703 | + g_return_val_if_fail(CONNMAN_IS_SERVICE(self), CONNMAN_SERVICE_SECURITY_NONE); |
| 704 | + g_return_val_if_fail(priv != NULL, CONNMAN_SERVICE_SECURITY_NONE); |
| 705 | + |
| 706 | return priv->security; |
| 707 | } |
| 708 | |
| 709 | @@ -269,6 +284,9 @@ |
| 710 | { |
| 711 | ConnmanServicePrivate *priv = GET_PRIVATE(self); |
| 712 | |
| 713 | + g_return_val_if_fail(CONNMAN_IS_SERVICE(self), 0); |
| 714 | + g_return_val_if_fail(priv != NULL, 0); |
| 715 | + |
| 716 | return priv->strength; |
| 717 | } |
| 718 | |
| 719 | @@ -276,6 +294,9 @@ |
| 720 | { |
| 721 | ConnmanServicePrivate *priv = GET_PRIVATE(self); |
| 722 | |
| 723 | + g_return_val_if_fail(CONNMAN_IS_SERVICE(self), FALSE); |
| 724 | + g_return_val_if_fail(priv != NULL, FALSE); |
| 725 | + |
| 726 | return priv->setup_required; |
| 727 | } |
| 728 | |
| 729 | @@ -624,7 +645,6 @@ |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | - |
| 734 | static void get_properties(ConnmanService *self) |
| 735 | { |
| 736 | ConnmanServicePrivate *priv = GET_PRIVATE(self); |
| 737 | |
| 738 | === renamed file 'src/common/connman-service.h' => 'src/libconnman/connman-service.h' |
| 739 | === renamed file 'src/common/connman.h' => 'src/libconnman/connman.h' |
| 740 | === modified file 'tests/Makefile.am' |
| 741 | --- tests/Makefile.am 2010-11-25 15:12:47 +0000 |
| 742 | +++ tests/Makefile.am 2010-12-03 09:51:48 +0000 |
| 743 | @@ -21,6 +21,7 @@ |
| 744 | $(DBUSGLIB_CFLAGS) \ |
| 745 | $(DBUSMENUGLIB_CFLAGS) \ |
| 746 | $(LIBNOTIFY_CFLAGS) \ |
| 747 | + $(CONNMAN_CFLAGS) \ |
| 748 | -DLIBEXECDIR=\"$(libexecdir)\" \ |
| 749 | -DBINDIR=\"$(bindir)\" \ |
| 750 | $(GCOV_FLAGS) |
| 751 | |
| 752 | === modified file 'tests/libconnman-tool.c' |
| 753 | --- tests/libconnman-tool.c 2010-11-19 12:05:05 +0000 |
| 754 | +++ tests/libconnman-tool.c 2010-12-03 09:51:48 +0000 |
| 755 | @@ -29,14 +29,20 @@ |
| 756 | static GMainLoop *loop; |
| 757 | static ConnmanManager *connman; |
| 758 | |
| 759 | +static const gchar *connect_path; |
| 760 | + |
| 761 | static enum { |
| 762 | TEST_LIST_SERVICES, |
| 763 | TEST_CONNECT_SERVICE, |
| 764 | + TEST_CONNECT, |
| 765 | } test; |
| 766 | |
| 767 | static void usage(const gchar *name) |
| 768 | { |
| 769 | - g_print("%s: list-services|connect-service\n", name); |
| 770 | + g_print("%s:\n", name); |
| 771 | + g_print("connect-service\n"); |
| 772 | + g_print("list-services\n"); |
| 773 | + g_print("connect <path>\n"); |
| 774 | } |
| 775 | |
| 776 | static void connect_hidden_ssid_cb(GObject *object, GAsyncResult *res, |
| 777 | @@ -166,14 +172,15 @@ |
| 778 | g_signal_connect(service, "notify::setup-required", |
| 779 | G_CALLBACK(setup_required_updated), NULL); |
| 780 | |
| 781 | - if (g_strcmp0(connman_service_get_name(service), "/ethernet_1") == 0) |
| 782 | + if (test == TEST_CONNECT && |
| 783 | + g_strcmp0(connman_service_get_name(service), connect_path) == 0) |
| 784 | connman_service_connect(service, connect_cb, NULL); |
| 785 | } |
| 786 | |
| 787 | static void connected_cb(ConnmanManager *proxy, GParamSpec *pspec, |
| 788 | gpointer user_data) |
| 789 | { |
| 790 | - ConnmanService **services; |
| 791 | + ConnmanService **services, *service; |
| 792 | gboolean connected; |
| 793 | guint count; |
| 794 | |
| 795 | @@ -212,6 +219,23 @@ |
| 796 | } |
| 797 | |
| 798 | g_print("%d services received\n", count); |
| 799 | + |
| 800 | + if (connman_manager_is_connected(connman)) { |
| 801 | + service = connman_manager_get_default_service(connman); |
| 802 | + g_print("connected, default service %s\n", |
| 803 | + service ? connman_service_get_path(service) : "none"); |
| 804 | + } else { |
| 805 | + g_print("not connected\n"); |
| 806 | + } |
| 807 | +} |
| 808 | + |
| 809 | +static void default_service_notify(ConnmanManager *proxy, GParamSpec *pspec, |
| 810 | + gpointer user_data) |
| 811 | +{ |
| 812 | + ConnmanService *service = connman_manager_get_default_service(connman); |
| 813 | + |
| 814 | + g_print("new default service %s\n", |
| 815 | + service ? connman_service_get_path(service) : "none"); |
| 816 | } |
| 817 | |
| 818 | static void service_added(ConnmanManager *proxy, ConnmanService *service, |
| 819 | @@ -234,7 +258,7 @@ |
| 820 | { |
| 821 | g_type_init(); |
| 822 | |
| 823 | - if (argc != 2) { |
| 824 | + if (argc < 2) { |
| 825 | usage(argv[0]); |
| 826 | return 1; |
| 827 | } |
| 828 | @@ -243,14 +267,36 @@ |
| 829 | |
| 830 | connman = connman_manager_new(); |
| 831 | |
| 832 | - if (g_strcmp0(argv[1], "list-services") == 0) |
| 833 | + if (g_strcmp0(argv[1], "list-services") == 0) { |
| 834 | test = TEST_LIST_SERVICES; |
| 835 | - else if (g_strcmp0(argv[1], "connect-service") == 0) |
| 836 | + if (argc != 2) { |
| 837 | + usage(argv[0]); |
| 838 | + return 1; |
| 839 | + } |
| 840 | + } |
| 841 | + else if (g_strcmp0(argv[1], "connect-service") == 0) { |
| 842 | test = TEST_CONNECT_SERVICE; |
| 843 | + if (argc != 2) { |
| 844 | + usage(argv[0]); |
| 845 | + return 1; |
| 846 | + } |
| 847 | + } |
| 848 | + else if (g_strcmp0(argv[1], "connect") == 0) { |
| 849 | + test = TEST_CONNECT; |
| 850 | + if (argc != 3) { |
| 851 | + usage(argv[0]); |
| 852 | + return 1; |
| 853 | + } |
| 854 | + connect_path = argv[2]; |
| 855 | + } |
| 856 | |
| 857 | g_signal_connect(connman, "notify::connected", G_CALLBACK(connected_cb), |
| 858 | NULL); |
| 859 | |
| 860 | + g_signal_connect(connman, "notify::default-service", |
| 861 | + G_CALLBACK(default_service_notify), |
| 862 | + NULL); |
| 863 | + |
| 864 | if (test == TEST_LIST_SERVICES) { |
| 865 | g_signal_connect(connman, "service-added", G_CALLBACK(service_added), |
| 866 | NULL); |
| 867 | |
| 868 | === modified file 'tests/mock-connman-manager.c' |
| 869 | --- tests/mock-connman-manager.c 2010-11-24 13:26:10 +0000 |
| 870 | +++ tests/mock-connman-manager.c 2010-12-03 09:51:48 +0000 |
| 871 | @@ -192,3 +192,8 @@ |
| 872 | priv->connected = connected; |
| 873 | g_object_notify(G_OBJECT(self), "connected"); |
| 874 | } |
| 875 | + |
| 876 | +ConnmanService *connman_manager_get_default_service(ConnmanManager *self) |
| 877 | +{ |
| 878 | + return NULL; |
| 879 | +} |
| 880 | |
| 881 | === modified file 'tests/mock-service-manager.c' |
| 882 | --- tests/mock-service-manager.c 2010-11-24 12:35:47 +0000 |
| 883 | +++ tests/mock-service-manager.c 2010-12-03 09:51:48 +0000 |
| 884 | @@ -161,3 +161,7 @@ |
| 885 | return 0; |
| 886 | } |
| 887 | |
| 888 | +void service_manager_update_default_service(ServiceManager *self, |
| 889 | + ConnmanService *cs) |
| 890 | +{ |
| 891 | +} |

Looks good to me, although I must confess I have been slightly less thorough than usually as I have quite a bit on my stack