summaryrefslogtreecommitdiff
path: root/noncore/net/networksetup/interface.cpp
Side-by-side diff
Diffstat (limited to 'noncore/net/networksetup/interface.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/interface.cpp77
1 files changed, 61 insertions, 16 deletions
diff --git a/noncore/net/networksetup/interface.cpp b/noncore/net/networksetup/interface.cpp
index 1f32093..1e01da4 100644
--- a/noncore/net/networksetup/interface.cpp
+++ b/noncore/net/networksetup/interface.cpp
@@ -2,87 +2,129 @@
#include <qdatetime.h>
#include <qfile.h>
#include <qdir.h>
#include <qfileinfo.h>
#include <qtextstream.h>
#define IFCONFIG "/sbin/ifconfig"
#define HDCP_INFO_DIR "/etc/dhcpc"
#include <stdio.h>
#include <stdlib.h>
-Interface::Interface(QString name, bool newSatus): status(newSatus), attached(false), interfaceName(name), hardareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){
+Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), status(newSatus), attached(false), hardareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){
refresh();
}
/**
+ * Set status
+ * @param newStatus - the new status
+ * emit updateInterface
+ */
+void Interface::setStatus(bool newStatus){
+ if(status != newStatus){
+ status = newStatus;
+ refresh();
+ }
+};
+
+/**
+ * Set if attached or not (802.11 card pulled out for example)
+ * @param isAttached - if attached
+ * emit updateInterface
+ */
+void Interface::setAttached(bool isAttached){
+ attached = isAttached;
+ emit(updateInterface(this));
+};
+
+/**
+ * Set Hardware name
+ * @param name - the new name
+ * emit updateInterface
+ */
+void Interface::setHardwareName(QString name){
+ hardareName = name;
+ emit(updateInterface(this));
+};
+
+/**
+ * Set Module owner
+ * @param owner - the new owner
+ * emit updateInterface
+ */
+void Interface::setModuleOwner(Module *owner){
+ moduleOwner = owner;
+ emit(updateInterface(this));
+};
+
+
+/**
* Try to start the interface.
- * @return bool true if successfull.
*/
-bool Interface::start(){
+void Interface::start(){
// check to see if we are already running.
- if(status)
- return false;
+ if(true == status)
+ return;
int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1());
+ // See if it was successfull...
if(ret != 0)
- return false;
+ return;
status = true;
refresh();
- return true;
}
/**
* Try to stop the interface.
- * @return bool true if successfull.
*/
-bool Interface::stop(){
+void Interface::stop(){
// check to see if we are already stopped.
- if(status == false)
- return false;
+ if(false == status)
+ return;
int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1());
if(ret != 0)
- return false;
+ return;
status = true;
refresh();
- return true;
}
+
/**
* Try to restart the interface.
- * @return bool true if successfull.
*/
-bool Interface::restart(){
- return (stop() && start());
+void Interface::restart(){
+ stop();
+ start();
}
/**
* Try to refresh the information about the interface.
* First call ifconfig, then check the dhcp-info file
* @return bool true if successfull.
*/
bool Interface::refresh(){
// See if we are up.
if(status == false){
macAddress = "";
ip = "0.0.0.0";
subnetMask = "0.0.0.0";
broadcast = "";
dhcp = false;
dhcpServerIp = "";
leaseObtained = "";
leaseExpires = "";
+ emit(updateInterface(this));
return true;
}
QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName);
int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(interfaceName).arg(fileName).latin1());
if(ret != 0){
qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1());
return false;
}
QFile file(fileName);
if (!file.open(IO_ReadOnly)){
@@ -129,24 +171,25 @@ bool Interface::refresh(){
leaseExpires = "";
dhcp = false;
QString dhcpDirectory(HDCP_INFO_DIR);
QDir d(dhcpDirectory);
if(!d.exists(dhcpDirectory))
dhcpDirectory = "/var/run";
// See if we have
QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName));
// If there is no DHCP information then exit now with no errors.
if(!QFile::exists(dhcpFile)){
+ emit(updateInterface(this));
return true;
}
file.setName(dhcpFile);
if (!file.open(IO_ReadOnly)){
qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
return false;
}
// leaseTime and renewalTime and used if pid and deamon exe can be accessed.
int leaseTime = 0;
int renewalTime = 0;
@@ -226,17 +269,19 @@ bool Interface::refresh(){
datetime = datetime.addSecs(time);
//qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1());
// Calculate the start and renew times
leaseObtained = datetime.toString();
// Calculate the start and renew times
datetime = datetime.addSecs(leaseTime);
leaseExpires = datetime.toString();
dhcp = true;
+
+ emit(updateInterface(this));
return true;
}
// interface.cpp