Пример #1
0
/*
 * get/set ethtool.priv-flags
 */
static dbus_bool_t
ni_objectmodel_ethtool_get_priv_flags(const ni_dbus_object_t *object,
		const ni_dbus_property_t *property,
		ni_dbus_variant_t *result,
		DBusError *error)
{
	const ni_ethtool_priv_flags_t *priv;
	const ni_ethtool_t *ethtool;
	ni_dbus_variant_t *dict;
	const char *name;
	unsigned int i;

	if (!(ethtool = ni_objectmodel_ethtool_read_handle(object, error)))
		return FALSE;
	if (!(priv = ethtool->priv_flags) || !priv->names.count || priv->names.count > 32)
		return FALSE;

	ni_dbus_dict_array_init(result);
	for (i = 0; i < priv->names.count; ++i) {
		name = priv->names.data[i];
		if (ni_string_empty(name))
			continue;

		if (!(dict = ni_dbus_dict_array_add(result)))
			continue;
		ni_dbus_dict_add_string(dict, "name", name);
		ni_dbus_dict_add_bool(dict, "enabled", !!(priv->bitmap & NI_BIT(i)));
	}
	return TRUE;
}
Пример #2
0
static dbus_bool_t
ni_objectmodel_ethtool_get_features(const ni_dbus_object_t *object,
		const ni_dbus_property_t *property,
		ni_dbus_variant_t *result,
		DBusError *error)
{
	const ni_ethtool_feature_t *feature;
	const ni_ethtool_t *ethtool;
	ni_dbus_variant_t *dict;
	unsigned int i;

	if (!(ethtool = ni_objectmodel_ethtool_read_handle(object, error)))
		return FALSE;

	if (!ethtool->features || !ethtool->features->count)
		return FALSE;

	ni_dbus_dict_array_init(result);
	for (i = 0; i < ethtool->features->count; ++i) {
		if (!(feature = ethtool->features->data[i]))
			continue;

		if (!(dict = ni_dbus_dict_array_add(result)))
			continue;

		ni_objectmodel_ethtool_feature_into_dict(dict, feature);
	}
	return TRUE;
}
Пример #3
0
static dbus_bool_t
__ni_objectmodel_ovs_bridge_get_ports(const ni_dbus_object_t *object, const ni_dbus_property_t *property,
					ni_dbus_variant_t *result, DBusError *error)
{
	ni_dbus_variant_t *dict;
	const ni_ovs_bridge_t *ovsbr;
	unsigned int i;

	ni_dbus_dict_array_init(result);

	if (!(ovsbr = __ni_objectmodel_ovs_bridge_read_handle(object, error)))
		return ni_dbus_error_property_not_present(error, object->path, property->name);

	for (i = 0; i < ovsbr->ports.count; ++i) {
		const ni_ovs_bridge_port_t *port = ovsbr->ports.data[i];

		if (!port || ni_string_empty(port->device.name))
			continue;

		if (!(dict = ni_dbus_dict_array_add(result)))
			return FALSE;

		ni_dbus_variant_init_dict(dict);
		if (!__ni_objectmodel_ovs_bridge_port_to_dict(port, dict, error))
			return FALSE;
	}
	return TRUE;
}
Пример #4
0
/*
 * Property ports
 */
static dbus_bool_t
__ni_objectmodel_bridge_get_ports(const ni_dbus_object_t *object, const ni_dbus_property_t *property,
				ni_dbus_variant_t *result, DBusError *error)
{
	const ni_bridge_t *bridge;
	unsigned int i;

	if (!(bridge = __ni_objectmodel_bridge_read_handle(object, error)))
		return FALSE;

	ni_dbus_dict_array_init(result);
	for (i = 0; i < bridge->ports.count; ++i) {
		const ni_bridge_port_t *port = bridge->ports.data[i];
		ni_dbus_variant_t *dict;

		/* Append a new element to the array */
		if (!(dict = ni_dbus_dict_array_add(result)))
			return FALSE;
		ni_dbus_variant_init_dict(dict);

		if (!__ni_objectmodel_bridge_port_to_dict(port, dict, object, 0))
			return FALSE;
	}
	return TRUE;
}
Пример #5
0
/*
 * Get/set the list of slaves
 */
static dbus_bool_t
__ni_objectmodel_bonding_get_slaves(const ni_dbus_object_t *object,
				const ni_dbus_property_t *property,
				ni_dbus_variant_t *result,
				DBusError *error)
{
	const ni_bonding_t *bond;
	unsigned int i;

	if (!(bond = __ni_objectmodel_bonding_read_handle(object, error)))
		return FALSE;

	ni_dbus_dict_array_init(result);
	for (i = 0; i < bond->slave_names.count; ++i) {
		const char *slave_name = bond->slave_names.data[i];
		ni_dbus_variant_t *slave;

		slave = ni_dbus_dict_array_add(result);

		ni_dbus_dict_add_string(slave, "device", slave_name);
		if (bond->primary_slave && ni_string_eq(bond->primary_slave, slave_name))
			ni_dbus_dict_add_bool(slave, "primary", TRUE);
		if (bond->active_slave && ni_string_eq(bond->active_slave, slave_name))
			ni_dbus_dict_add_bool(slave, "active", TRUE);
	}

	return TRUE;
}
Пример #6
0
/*
  <define name="properties" class="dict">
    <last-seq type="uint32" />
    <events class="array" element-type="event_t" />
  </define>
 */
static dbus_bool_t
__ni_testbus_eventlog_get_events(const ni_dbus_object_t *object, const ni_dbus_property_t *property,
			ni_dbus_variant_t *result, DBusError *error)
{
	ni_eventlog_t *log;
	unsigned int i;

	if (!(log = __ni_objectmodel_get_eventlog(object, FALSE, error)))
		return FALSE;

	ni_dbus_dict_array_init(result);
	for (i = log->consumed; i < log->events.count; ++i) {
		ni_event_t *ev = &log->events.data[i];

		ni_testbus_event_serialize(ev, ni_dbus_dict_array_add(result));
	}
	return TRUE;
}
Пример #7
0
/*
 * Property ports (array)
 */
static dbus_bool_t
__ni_objectmodel_team_get_ports(const ni_dbus_object_t *object, const ni_dbus_property_t *property,
				ni_dbus_variant_t *result, DBusError *error)
{
	ni_dbus_variant_t *dict;
	const ni_team_t *team;
	unsigned int i;

	if (!(team = __ni_objectmodel_team_read_handle(object, error)))
		return FALSE;

	ni_dbus_dict_array_init(result);
	for (i = 0; i < team->ports.count; ++i) {
		const ni_team_port_t *port = team->ports.data[i];

		if (!(dict = ni_dbus_dict_array_add(result)))
			return FALSE;

		ni_dbus_variant_init_dict(dict);
		if (!__ni_objectmodel_team_port_to_dict(port, dict, error))
			return FALSE;
	}
	return TRUE;
}