service: Add __connman_service_ipconfig_indicate_state()
authorDaniel Wagner <wagi@monom.org>
Thu, 7 Jul 2011 16:47:25 +0000 (19:47 +0300)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 7 Jul 2011 17:07:23 +0000 (19:07 +0200)
src/connman.h
src/service.c

index e4c35da..c54460b 100644 (file)
@@ -497,6 +497,10 @@ void __connman_service_set_string(struct connman_service *service,
                                        const char *key, const char *value);
 int __connman_service_set_ipconfig_ready(struct connman_service *service,
                                        enum connman_ipconfig_type type);
+int __connman_service_ipconfig_indicate_state(struct connman_service *service,
+                                       enum connman_service_state state,
+                                       enum connman_ipconfig_type type);
+
 int __connman_service_indicate_state(struct connman_service *service,
                                        enum connman_service_state new_state,
                                        enum connman_ipconfig_type type);
index 51cda8f..7361502 100644 (file)
@@ -3727,6 +3727,50 @@ int __connman_service_indicate_default(struct connman_service *service)
        return 0;
 }
 
+int __connman_service_ipconfig_indicate_state(struct connman_service *service,
+                                       enum connman_service_state state,
+                                       enum connman_ipconfig_type type)
+{
+       enum connman_service_state current_state;
+       int err = 0;
+
+       DBG("service %p (%s) state %d (%s) type %d (%s)",
+               service, service ? service->identifier : NULL,
+               state, state2string(state),
+               type, __connman_ipconfig_type2string(type));
+
+       if (service == NULL)
+               return -EINVAL;
+
+       current_state = combine_state(service->state_ipv4, service->state_ipv6);
+
+       switch (current_state) {
+       case CONNMAN_SERVICE_STATE_UNKNOWN:
+       case CONNMAN_SERVICE_STATE_IDLE:
+               break;
+       case CONNMAN_SERVICE_STATE_READY:
+       case CONNMAN_SERVICE_STATE_ONLINE:
+               if (state == CONNMAN_SERVICE_STATE_READY ||
+                               state == CONNMAN_SERVICE_STATE_ONLINE)
+                       return -EALREADY;
+               break;
+       case CONNMAN_SERVICE_STATE_FAILURE:
+       case CONNMAN_SERVICE_STATE_DISCONNECT:
+       case CONNMAN_SERVICE_STATE_ASSOCIATION:
+       case CONNMAN_SERVICE_STATE_CONFIGURATION:
+               break;
+       }
+
+       if (current_state == state)
+               return -EALREADY;
+
+       err = __connman_service_indicate_state(service, state, type);
+       if (err < 0)
+               return err;
+
+       return 0;
+}
+
 int __connman_service_request_login(struct connman_service *service)
 {
        DBG("service %p", service);