author | benmeyer <benmeyer> | 2002-10-17 16:30:44 (UTC) |
---|---|---|
committer | benmeyer <benmeyer> | 2002-10-17 16:30:44 (UTC) |
commit | 18cc7321db186865629a5c4702074211e42b92fd (patch) (unidiff) | |
tree | beb15112009c1cc966115904a322b32d465e47e6 /noncore/settings/networksettings/interface.cpp | |
parent | 75f078ec92376db2c90a327bbc50d9bb5c1fb57a (diff) | |
download | opie-18cc7321db186865629a5c4702074211e42b92fd.zip opie-18cc7321db186865629a5c4702074211e42b92fd.tar.gz opie-18cc7321db186865629a5c4702074211e42b92fd.tar.bz2 |
interface is now a qobject
Diffstat (limited to 'noncore/settings/networksettings/interface.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/interface.cpp | 77 |
1 files changed, 61 insertions, 16 deletions
diff --git a/noncore/settings/networksettings/interface.cpp b/noncore/settings/networksettings/interface.cpp index 1f32093..1e01da4 100644 --- a/noncore/settings/networksettings/interface.cpp +++ b/noncore/settings/networksettings/interface.cpp | |||
@@ -8,57 +8,98 @@ | |||
8 | #define IFCONFIG "/sbin/ifconfig" | 8 | #define IFCONFIG "/sbin/ifconfig" |
9 | #define HDCP_INFO_DIR "/etc/dhcpc" | 9 | #define HDCP_INFO_DIR "/etc/dhcpc" |
10 | 10 | ||
11 | #include <stdio.h> | 11 | #include <stdio.h> |
12 | #include <stdlib.h> | 12 | #include <stdlib.h> |
13 | 13 | ||
14 | 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){ | 14 | 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){ |
15 | refresh(); | 15 | refresh(); |
16 | } | 16 | } |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * Set status | ||
20 | * @param newStatus - the new status | ||
21 | * emit updateInterface | ||
22 | */ | ||
23 | void Interface::setStatus(bool newStatus){ | ||
24 | if(status != newStatus){ | ||
25 | status = newStatus; | ||
26 | refresh(); | ||
27 | } | ||
28 | }; | ||
29 | |||
30 | /** | ||
31 | * Set if attached or not (802.11 card pulled out for example) | ||
32 | * @param isAttached - if attached | ||
33 | * emit updateInterface | ||
34 | */ | ||
35 | void Interface::setAttached(bool isAttached){ | ||
36 | attached = isAttached; | ||
37 | emit(updateInterface(this)); | ||
38 | }; | ||
39 | |||
40 | /** | ||
41 | * Set Hardware name | ||
42 | * @param name - the new name | ||
43 | * emit updateInterface | ||
44 | */ | ||
45 | void Interface::setHardwareName(QString name){ | ||
46 | hardareName = name; | ||
47 | emit(updateInterface(this)); | ||
48 | }; | ||
49 | |||
50 | /** | ||
51 | * Set Module owner | ||
52 | * @param owner - the new owner | ||
53 | * emit updateInterface | ||
54 | */ | ||
55 | void Interface::setModuleOwner(Module *owner){ | ||
56 | moduleOwner = owner; | ||
57 | emit(updateInterface(this)); | ||
58 | }; | ||
59 | |||
60 | |||
61 | /** | ||
19 | * Try to start the interface. | 62 | * Try to start the interface. |
20 | * @return bool true if successfull. | ||
21 | */ | 63 | */ |
22 | bool Interface::start(){ | 64 | void Interface::start(){ |
23 | // check to see if we are already running. | 65 | // check to see if we are already running. |
24 | if(status) | 66 | if(true == status) |
25 | return false; | 67 | return; |
26 | 68 | ||
27 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1()); | 69 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1()); |
70 | // See if it was successfull... | ||
28 | if(ret != 0) | 71 | if(ret != 0) |
29 | return false; | 72 | return; |
30 | 73 | ||
31 | status = true; | 74 | status = true; |
32 | refresh(); | 75 | refresh(); |
33 | return true; | ||
34 | } | 76 | } |
35 | 77 | ||
36 | /** | 78 | /** |
37 | * Try to stop the interface. | 79 | * Try to stop the interface. |
38 | * @return bool true if successfull. | ||
39 | */ | 80 | */ |
40 | bool Interface::stop(){ | 81 | void Interface::stop(){ |
41 | // check to see if we are already stopped. | 82 | // check to see if we are already stopped. |
42 | if(status == false) | 83 | if(false == status) |
43 | return false; | 84 | return; |
44 | 85 | ||
45 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1()); | 86 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1()); |
46 | if(ret != 0) | 87 | if(ret != 0) |
47 | return false; | 88 | return; |
48 | 89 | ||
49 | status = true; | 90 | status = true; |
50 | refresh(); | 91 | refresh(); |
51 | return true; | ||
52 | } | 92 | } |
93 | |||
53 | /** | 94 | /** |
54 | * Try to restart the interface. | 95 | * Try to restart the interface. |
55 | * @return bool true if successfull. | ||
56 | */ | 96 | */ |
57 | bool Interface::restart(){ | 97 | void Interface::restart(){ |
58 | return (stop() && start()); | 98 | stop(); |
99 | start(); | ||
59 | } | 100 | } |
60 | 101 | ||
61 | /** | 102 | /** |
62 | * Try to refresh the information about the interface. | 103 | * Try to refresh the information about the interface. |
63 | * First call ifconfig, then check the dhcp-info file | 104 | * First call ifconfig, then check the dhcp-info file |
64 | * @return bool true if successfull. | 105 | * @return bool true if successfull. |
@@ -71,12 +112,13 @@ bool Interface::refresh(){ | |||
71 | subnetMask = "0.0.0.0"; | 112 | subnetMask = "0.0.0.0"; |
72 | broadcast = ""; | 113 | broadcast = ""; |
73 | dhcp = false; | 114 | dhcp = false; |
74 | dhcpServerIp = ""; | 115 | dhcpServerIp = ""; |
75 | leaseObtained = ""; | 116 | leaseObtained = ""; |
76 | leaseExpires = ""; | 117 | leaseExpires = ""; |
118 | emit(updateInterface(this)); | ||
77 | return true; | 119 | return true; |
78 | } | 120 | } |
79 | 121 | ||
80 | QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName); | 122 | QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName); |
81 | int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(interfaceName).arg(fileName).latin1()); | 123 | int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(interfaceName).arg(fileName).latin1()); |
82 | if(ret != 0){ | 124 | if(ret != 0){ |
@@ -135,12 +177,13 @@ bool Interface::refresh(){ | |||
135 | dhcpDirectory = "/var/run"; | 177 | dhcpDirectory = "/var/run"; |
136 | 178 | ||
137 | // See if we have | 179 | // See if we have |
138 | QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName)); | 180 | QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName)); |
139 | // If there is no DHCP information then exit now with no errors. | 181 | // If there is no DHCP information then exit now with no errors. |
140 | if(!QFile::exists(dhcpFile)){ | 182 | if(!QFile::exists(dhcpFile)){ |
183 | emit(updateInterface(this)); | ||
141 | return true; | 184 | return true; |
142 | } | 185 | } |
143 | 186 | ||
144 | file.setName(dhcpFile); | 187 | file.setName(dhcpFile); |
145 | if (!file.open(IO_ReadOnly)){ | 188 | if (!file.open(IO_ReadOnly)){ |
146 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | 189 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); |
@@ -232,11 +275,13 @@ bool Interface::refresh(){ | |||
232 | 275 | ||
233 | // Calculate the start and renew times | 276 | // Calculate the start and renew times |
234 | datetime = datetime.addSecs(leaseTime); | 277 | datetime = datetime.addSecs(leaseTime); |
235 | leaseExpires = datetime.toString(); | 278 | leaseExpires = datetime.toString(); |
236 | 279 | ||
237 | dhcp = true; | 280 | dhcp = true; |
281 | |||
282 | emit(updateInterface(this)); | ||
238 | return true; | 283 | return true; |
239 | } | 284 | } |
240 | 285 | ||
241 | // interface.cpp | 286 | // interface.cpp |
242 | 287 | ||