Diffstat (limited to 'noncore/settings/networksettings/ppp/pppmodule.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/pppmodule.cpp | 117 |
1 files changed, 115 insertions, 2 deletions
diff --git a/noncore/settings/networksettings/ppp/pppmodule.cpp b/noncore/settings/networksettings/ppp/pppmodule.cpp index d4c137b..af05eb7 100644 --- a/noncore/settings/networksettings/ppp/pppmodule.cpp +++ b/noncore/settings/networksettings/ppp/pppmodule.cpp | |||
@@ -1,38 +1,96 @@ | |||
1 | #include <errno.h> | ||
2 | #include <signal.h> | ||
1 | 3 | ||
4 | |||
5 | #include <qpe/config.h> | ||
6 | |||
7 | #include "modem.h" | ||
2 | #include "pppconfig.h" | 8 | #include "pppconfig.h" |
3 | #include "pppmodule.h" | 9 | #include "pppmodule.h" |
4 | #include "pppdata.h" | 10 | #include "pppdata.h" |
5 | #include "interfaceinformationppp.h" | 11 | #include "interfaceinformationppp.h" |
6 | #include "interfaceppp.h" | 12 | #include "interfaceppp.h" |
7 | 13 | ||
14 | // don't polute global namespace | ||
15 | namespace { | ||
16 | /* | ||
17 | * If network settings is qutting and we've ppp | ||
18 | * devices open we need to save the pid_t the PPData | ||
19 | * and the interface number | ||
20 | */ | ||
21 | struct Connection { | ||
22 | pid_t pid; | ||
23 | QString device; | ||
24 | QString name; | ||
25 | }; | ||
26 | class InterfaceKeeper { | ||
27 | public: | ||
28 | InterfaceKeeper(); | ||
29 | ~InterfaceKeeper(); | ||
30 | |||
31 | void addInterface( pid_t, const QString& pppDev, const QString& name ); | ||
32 | QMap<QString, Connection> interfaces()const; // will check if still available | ||
33 | private: | ||
34 | bool isAvailable( pid_t )const; | ||
35 | QMap<QString, Connection> m_interfaces; | ||
36 | }; | ||
37 | } | ||
38 | |||
8 | 39 | ||
9 | /** | 40 | /** |
10 | * Constructor, find all of the possible interfaces | 41 | * Constructor, find all of the possible interfaces |
42 | * We also need to restore the state.. it could be that | ||
43 | * an interface was up while closing the application | ||
44 | * we need to be able to shut it down... | ||
11 | */ | 45 | */ |
12 | PPPModule::PPPModule() : Module() | 46 | PPPModule::PPPModule() : Module() |
13 | { | 47 | { |
48 | InterfaceKeeper inFace; | ||
49 | QMap<QString,Connection> running = inFace.interfaces(); | ||
50 | QStringList handledInterfaceNames; | ||
51 | |||
14 | QMap<QString,QString> ifaces = PPPData::getConfiguredInterfaces(); | 52 | QMap<QString,QString> ifaces = PPPData::getConfiguredInterfaces(); |
15 | QMap<QString,QString>::Iterator it; | 53 | QMap<QString,QString>::Iterator it; |
16 | InterfacePPP *iface; | 54 | InterfacePPP *iface; |
17 | qDebug("getting interfaces"); | 55 | qDebug("getting interfaces"); |
18 | for( it = ifaces.begin(); it != ifaces.end(); ++it ){ | 56 | for( it = ifaces.begin(); it != ifaces.end(); ++it ){ |
19 | qDebug("ifaces %s", it.key().latin1()); | 57 | qDebug("ifaces %s %s", it.key().latin1(), it.data().latin1() ); |
20 | iface = new InterfacePPP( 0, it.key() ); | 58 | iface = new InterfacePPP( 0, it.key() ); |
21 | iface->setHardwareName( it.data() ); | 59 | iface->setHardwareName( it.data() ); |
22 | list.append( (Interface*)iface ); | 60 | list.append( (Interface*)iface ); |
61 | |||
62 | // check if (*it) is one of the running ifaces | ||
63 | if ( running.contains( it.data() ) ) { | ||
64 | qDebug("iface is running %s", it.key().latin1() ); | ||
65 | handledInterfaceNames << running[it.data()].device; | ||
66 | iface->setStatus( true ); | ||
67 | iface->setPPPDpid( running[it.data()].pid ); | ||
68 | iface->modem()->setPPPDevice( running[it.data()].device ); | ||
69 | iface->refresh(); | ||
70 | } | ||
23 | } | 71 | } |
72 | |||
73 | setHandledInterfaceNames( handledInterfaceNames ); | ||
24 | } | 74 | } |
25 | 75 | ||
26 | /** | 76 | /** |
27 | * Delete any interfaces that we own. | 77 | * Delete any interfaces that we own. |
28 | */ | 78 | */ |
29 | PPPModule::~PPPModule(){ | 79 | PPPModule::~PPPModule(){ |
80 | qDebug("PPPModule::~PPPModule() " ); | ||
30 | QMap<QString,QString> ifaces; | 81 | QMap<QString,QString> ifaces; |
82 | InterfaceKeeper keeper; | ||
31 | Interface *i; | 83 | Interface *i; |
32 | for ( i=list.first(); i != 0; i=list.next() ){ | 84 | for ( i=list.first(); i != 0; i=list.next() ){ |
85 | /* if online save the state */ | ||
86 | if ( i->getStatus() ) { | ||
87 | qDebug("Iface %s is still up", i->getHardwareName().latin1() ); | ||
88 | InterfacePPP* ppp = static_cast<InterfacePPP*>(i); | ||
89 | keeper.addInterface( ppp->pppPID(), ppp->pppDev(), ppp->getHardwareName() ); | ||
90 | } | ||
33 | ifaces.insert( i->getInterfaceName(), i->getHardwareName() ); | 91 | ifaces.insert( i->getInterfaceName(), i->getHardwareName() ); |
34 | delete i; | 92 | delete i; |
35 | } | 93 | } |
36 | PPPData::setConfiguredInterfaces( ifaces ); | 94 | PPPData::setConfiguredInterfaces( ifaces ); |
37 | } | 95 | } |
38 | 96 | ||
@@ -66,13 +124,13 @@ bool PPPModule::isOwner(Interface *i){ | |||
66 | * @return QWidget* pointer to this modules configure. | 124 | * @return QWidget* pointer to this modules configure. |
67 | */ | 125 | */ |
68 | QWidget *PPPModule::configure(Interface *i){ | 126 | QWidget *PPPModule::configure(Interface *i){ |
69 | qDebug("return ModemWidget"); | 127 | qDebug("return ModemWidget"); |
70 | PPPConfigWidget *pppconfig = new PPPConfigWidget( (InterfacePPP*)i, | 128 | PPPConfigWidget *pppconfig = new PPPConfigWidget( (InterfacePPP*)i, |
71 | 0, "PPPConfig", false, | 129 | 0, "PPPConfig", false, |
72 | Qt::WDestructiveClose ); | 130 | Qt::WDestructiveClose | Qt::WStyle_ContextHelp); |
73 | return pppconfig; | 131 | return pppconfig; |
74 | } | 132 | } |
75 | 133 | ||
76 | /** | 134 | /** |
77 | * Create, and return the Information Module | 135 | * Create, and return the Information Module |
78 | * @return QWidget* pointer to this modules info. | 136 | * @return QWidget* pointer to this modules info. |
@@ -132,6 +190,61 @@ void PPPModule::possibleNewInterfaces(QMap<QString, QString> &newIfaces) | |||
132 | { | 190 | { |
133 | newIfaces.insert(QObject::tr("PPP") , | 191 | newIfaces.insert(QObject::tr("PPP") , |
134 | QObject::tr("generic ppp device")); | 192 | QObject::tr("generic ppp device")); |
135 | } | 193 | } |
136 | 194 | ||
137 | 195 | ||
196 | |||
197 | namespace { | ||
198 | InterfaceKeeper::InterfaceKeeper( ) { | ||
199 | } | ||
200 | InterfaceKeeper::~InterfaceKeeper() { | ||
201 | Config cfg("ppp_plugin_keeper"); | ||
202 | QStringList lst = cfg.groupList(); | ||
203 | for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { | ||
204 | Connection con; | ||
205 | cfg.setGroup( (*it) ); | ||
206 | cfg.clearGroup(); | ||
207 | } | ||
208 | |||
209 | for (QMap<QString, Connection>::Iterator it = m_interfaces.begin(); it != m_interfaces.end(); ++it ) { | ||
210 | Connection con = it.data(); | ||
211 | cfg.setGroup( con.name ); | ||
212 | cfg.writeEntry( "pid", con.pid ); | ||
213 | cfg.writeEntry( "device", con.device ); | ||
214 | } | ||
215 | } | ||
216 | void InterfaceKeeper::addInterface(pid_t pid, const QString& dev, const QString& name ) { | ||
217 | Connection con; | ||
218 | con.pid = pid; | ||
219 | con.device = dev; | ||
220 | con.name = name; | ||
221 | m_interfaces.insert( name, con ); | ||
222 | } | ||
223 | QMap<QString, Connection> InterfaceKeeper::interfaces()const { | ||
224 | Config cfg("ppp_plugin_keeper"); | ||
225 | QMap<QString, Connection> ifaces; | ||
226 | QStringList lst = cfg.groupList(); | ||
227 | for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { | ||
228 | Connection con; | ||
229 | cfg.setGroup( (*it) ); | ||
230 | con.name = (*it); | ||
231 | con.pid = cfg.readNumEntry("pid"); | ||
232 | con.device = cfg.readEntry("device"); | ||
233 | qDebug(" %s %s %d", con.name.latin1(), con.device.latin1(), con.pid ); | ||
234 | |||
235 | if ( con.pid != -1 && isAvailable( con.pid ) ) | ||
236 | ifaces.insert( con.name, con ); | ||
237 | } | ||
238 | return ifaces; | ||
239 | } | ||
240 | bool InterfaceKeeper::isAvailable( pid_t p)const { | ||
241 | if (::kill(p, 0 ) == 0 || errno != ESRCH ) { | ||
242 | qDebug("isAvailable %d", p); | ||
243 | return true; | ||
244 | } | ||
245 | |||
246 | qDebug("notAvailable %d", p); | ||
247 | return false; | ||
248 | } | ||
249 | |||
250 | } | ||