/*
    knetd, KDE Network Daemon

    Copyright (c) 2005 by Engin AYDOGAN		<engin @ bzzzt.biz>

    *************************************************************************
    *                                                                       *
    * This program is free software; you can redistribute it and/or modify  *
    * it under the terms of the GNU General Public License as published by  *
    * the Free Software Foundation; either version 2 of the License, or     *
    * (at your option) any later version.                                   *
    *                                                                       *
    *************************************************************************
*/

#include <kdebug.h>

#include "attribute.h"

Attribute::Attribute( sysfs_attribute* a )
 : m_name( a->name ), m_path( a->path ), m_value( a->value ), m_method( a->method )
{
// 	kdWarning() << k_funcinfo << "Attribute[ " << m_name << " ]" << endl;
}

Attribute::Attribute()
{
}

bool
Attribute::isWritable() const
{
	return m_method & SYSFS_METHOD_STORE;
}

bool
Attribute::isReadable() const
{
	return m_method & SYSFS_METHOD_SHOW;
}

Attribute&
Attribute::operator=( const QString& val )
{
	sysfs_attribute* a = sysfs_open_attribute( m_path.ascii() );
	sysfs_write_attribute( a, val.ascii(), val.length() );
	sysfs_close_attribute( a );
	return *this;
}

bool
Attribute::operator==( const QString& val ) const
{
	return ( value() == val );
}

QString
Attribute::name() const
{
	return m_name;
}

QString
Attribute::value() const
{
	return m_value;
}

void
Attribute::reRead()
{
	sysfs_attribute* a = sysfs_open_attribute( m_path.ascii() );
	sysfs_read_attribute( a );
	m_value = a->value;
	sysfs_close_attribute( a );
}
