Add support for marking devices as secondary
authorMarcel Holtmann <marcel@holtmann.org>
Fri, 1 May 2009 16:03:13 +0000 (09:03 -0700)
committerMarcel Holtmann <marcel@holtmann.org>
Fri, 1 May 2009 16:03:13 +0000 (09:03 -0700)
include/device.h
src/device.c
src/network.c

index 17a2a0c..8311607 100644 (file)
@@ -89,6 +89,9 @@ extern void connman_device_set_policy(struct connman_device *device,
 extern void connman_device_set_mode(struct connman_device *device,
                                                enum connman_device_mode mode);
 extern enum connman_device_mode connman_device_get_mode(struct connman_device *device);
+extern void connman_device_set_secondary(struct connman_device *device,
+                                               connman_bool_t secondary);
+extern connman_bool_t connman_device_get_secondary(struct connman_device *device);
 
 extern int connman_device_set_powered(struct connman_device *device,
                                                connman_bool_t powered);
index df7e7fb..f33d601 100644 (file)
@@ -35,6 +35,7 @@ struct connman_device {
        enum connman_device_type type;
        enum connman_device_mode mode;
        enum connman_device_policy policy;
+       connman_bool_t secondary;
        connman_bool_t powered;
        connman_bool_t carrier;
        connman_bool_t scanning;
@@ -793,7 +794,8 @@ static int setup_device(struct connman_device *device)
        case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
                break;
        case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
-               __connman_profile_add_device(device);
+               if (device->secondary == FALSE)
+                       __connman_profile_add_device(device);
                break;
        }
 
@@ -837,7 +839,8 @@ static void remove_device(struct connman_device *device)
        case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
                break;
        case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
-               __connman_profile_remove_device(device);
+               if (device->secondary == FALSE)
+                       __connman_profile_remove_device(device);
                break;
        }
 
@@ -984,10 +987,11 @@ struct connman_device *connman_device_create(const char *node,
 
        device->element.ipv4.method = CONNMAN_IPV4_METHOD_DHCP;
 
-       device->type   = type;
-       device->name   = g_strdup(type2description(device->type));
-       device->mode   = CONNMAN_DEVICE_MODE_UNKNOWN;
-       device->policy = CONNMAN_DEVICE_POLICY_AUTO;
+       device->type      = type;
+       device->name      = g_strdup(type2description(device->type));
+       device->mode      = CONNMAN_DEVICE_MODE_UNKNOWN;
+       device->policy    = CONNMAN_DEVICE_POLICY_AUTO;
+       device->secondary = FALSE;
 
        switch (type) {
        case CONNMAN_DEVICE_TYPE_UNKNOWN:
@@ -1205,6 +1209,30 @@ enum connman_device_mode connman_device_get_mode(struct connman_device *device)
 }
 
 /**
+ * connman_device_set_secondary:
+ * @device: device structure
+ * @secondary: secondary value
+ *
+ * Change secondary value of device
+ */
+void connman_device_set_secondary(struct connman_device *device,
+                                                connman_bool_t secondary)
+{
+       device->secondary = secondary;
+}
+
+/**
+ * connman_device_get_secondary:
+ * @device: device structure
+ *
+ * Get secondary value of device
+ */
+connman_bool_t connman_device_get_secondary(struct connman_device *device)
+{
+       return device->secondary;
+}
+
+/**
  * connman_device_set_powered:
  * @device: device structure
  * @powered: powered state
index 6c37eac..f2b9da2 100644 (file)
@@ -33,6 +33,7 @@ struct connman_network {
        struct connman_element element;
        enum connman_network_type type;
        enum connman_network_protocol protocol;
+       connman_bool_t secondary;
        connman_bool_t available;
        connman_bool_t connected;
        connman_bool_t remember;
@@ -486,7 +487,8 @@ struct connman_network *connman_network_create(const char *identifier,
 
        connman_element_set_uint8(&network->element, "Strength", strength);
 
-       network->type = type;
+       network->type       = type;
+       network->secondary  = FALSE;
        network->identifier = g_strdup(identifier);
 
        return network;
@@ -1108,6 +1110,8 @@ static int network_probe(struct connman_element *element)
                return err;
        }
 
+       network->secondary = connman_device_get_secondary(network->device);
+
        switch (network->type) {
        case CONNMAN_NETWORK_TYPE_UNKNOWN:
        case CONNMAN_NETWORK_TYPE_VENDOR:
@@ -1117,7 +1121,8 @@ static int network_probe(struct connman_element *element)
                break;
        case CONNMAN_NETWORK_TYPE_WIFI:
        case CONNMAN_NETWORK_TYPE_WIMAX:
-               __connman_profile_add_network(network);
+               if (network->secondary == FALSE)
+                       __connman_profile_add_network(network);
                break;
        }
 
@@ -1145,7 +1150,8 @@ static void network_remove(struct connman_element *element)
                break;
        case CONNMAN_NETWORK_TYPE_WIFI:
        case CONNMAN_NETWORK_TYPE_WIMAX:
-               __connman_profile_remove_network(network);
+               if (network->secondary == FALSE)
+                       __connman_profile_remove_network(network);
                break;
        }