static dbus_bool_t __ni_objectmodel_bridge_set_ports(ni_dbus_object_t *object, const ni_dbus_property_t *property, const ni_dbus_variant_t *argument, DBusError *error) { ni_dbus_variant_t *port_dict; ni_bridge_t *bridge; unsigned int i; if (!(bridge = __ni_objectmodel_bridge_write_handle(object, error))) return FALSE; if (!ni_dbus_variant_is_dict_array(argument)) return FALSE; port_dict = argument->variant_array_value; for (i = 0; i < argument->array.len; ++i, ++port_dict) { ni_bridge_port_t *port; port = ni_bridge_port_new(NULL, NULL, 0); if (!__ni_objectmodel_bridge_port_from_dict(port, port_dict, error, TRUE)) { ni_bridge_port_free(port); return FALSE; } if (ni_bridge_add_port(bridge, port) < 0) { ni_bridge_port_free(port); /* duplicate port */ } } return TRUE; }
static void ni_bridge_port_array_destroy(ni_bridge_port_array_t *array) { while (array->count > 0) ni_bridge_port_free(array->data[--array->count]); free(array->data); ni_bridge_port_array_init(array); }
static int ni_bridge_port_array_remove_index(ni_bridge_port_array_t *array, unsigned int pos) { unsigned int i; if (pos >= array->count) return -1; ni_bridge_port_free(array->data[pos]); /* make it less cumbersome... */ array->data[pos] = NULL; for (i = pos + 1; i < array->count; ++i) { array->data[i - 1] = array->data[i]; array->data[i] = NULL; } array->count--; return 0; }