/*
    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.                                   *
    *                                                                       *
    *************************************************************************
*/

#ifndef DEVICE_WRAP_H_
#define DEVICE_WRAP_H_

#include "abstractdevice.h"

#include <qmap.h>

#include "sysfs_global.h"
#include "attribute.h"

class KProcess;

/**
 * This class represents a network interface device
 */
class Device : public AbstractDevice
{
Q_OBJECT
protected:
	Device( const QString& name, const QString& path, 
		const QString& mPath = QString(), bool read = true );
public:
	/**
	 * @param device name of the network device
	 * @return a Device object on success 0 otherwise.
	 */
	static Device*
	build( const QString& device, bool read = true );

	virtual ~Device();

	/**
	 * Reads the attributes of the device. Subsequent calls to this method
	 * is redundant since it will not read attributes again.
	 * @see reRead()
	 */
	void
	read();

	bool
	isAvailable() const;

	bool
	isEthernet() const;

	/**
	 * @return true if the device is a wireless interface
	 */
	bool
	isWireless() const;

	const QString&
	mac() const;

	const QString&
	netmask() const;

	const QString&
	gateway() const;

	bool
	isLinkUp() const;

	const QString&
	name() const;

	void
	setSignalScanFreq( int );

	void
	setLinkScanFreq( int );

	int
	linkScanFreq() const;

	void
	setApScanFreq( int );

	int
	apScanFreq() const;

	Speed
	speed() const;

	Duplex
	duplex() const;

	const QString&
	ip4() const;

	const QString&
	ip6() const;

	bool
	isUp() const;

	class Private;
public slots:
	void checkLink();
	void checkSignal();
	void checkAccessPoints();
	void checkUpDown();
protected slots:
	void ethtoolStdout( const QString& );
	void ethtoolStderr( const QString& );
	void ethtoolExited( KProcess* );
	void iwconfigStdout( const QString& );
	void iwconfigStderr( const QString& );
	void iwconfigExited( KProcess* );
	void ifconfigStdout( const QString& );
	void ifconfigStderr( const QString& );
	void ifconfigExited( KProcess* );
signals:
	void ethtoolError( Device*, const QString& );
	void iwconfigError( Device*, const QString& );
	void ifconfigError( Device*, const QString& );
private:
	Private *d;
};

#endif
