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 e4c35da50ec0dceb61c455ca2ed79ccf6eea6442..c54460b6f79fe61e5c13f374bde33cfbaed59529 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 51cda8f56f393ff96d3e7e25404fe4c7df0c7fd5..73615020f41c352f167716c69c1acfdddfe46da5 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);