From a7e015198a8c5ad3b6e144a9032b059086253e00 Mon Sep 17 00:00:00 2001 From: kergoth Date: Sat, 09 Aug 2003 17:14:54 +0000 Subject: Merge from BRANCH_1_0 --- (limited to 'noncore/settings/networksettings/ppp/pppmodule.cpp') 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,35 +1,93 @@ +#include +#include + +#include + +#include "modem.h" #include "pppconfig.h" #include "pppmodule.h" #include "pppdata.h" #include "interfaceinformationppp.h" #include "interfaceppp.h" +// don't polute global namespace +namespace { + /* + * If network settings is qutting and we've ppp + * devices open we need to save the pid_t the PPData + * and the interface number + */ + struct Connection { + pid_t pid; + QString device; + QString name; + }; + class InterfaceKeeper { + public: + InterfaceKeeper(); + ~InterfaceKeeper(); + + void addInterface( pid_t, const QString& pppDev, const QString& name ); + QMap interfaces()const; // will check if still available + private: + bool isAvailable( pid_t )const; + QMap m_interfaces; + }; +} + /** * Constructor, find all of the possible interfaces + * We also need to restore the state.. it could be that + * an interface was up while closing the application + * we need to be able to shut it down... */ PPPModule::PPPModule() : Module() { + InterfaceKeeper inFace; + QMap running = inFace.interfaces(); + QStringList handledInterfaceNames; + QMap ifaces = PPPData::getConfiguredInterfaces(); QMap::Iterator it; InterfacePPP *iface; qDebug("getting interfaces"); for( it = ifaces.begin(); it != ifaces.end(); ++it ){ - qDebug("ifaces %s", it.key().latin1()); + qDebug("ifaces %s %s", it.key().latin1(), it.data().latin1() ); iface = new InterfacePPP( 0, it.key() ); iface->setHardwareName( it.data() ); list.append( (Interface*)iface ); + + // check if (*it) is one of the running ifaces + if ( running.contains( it.data() ) ) { + qDebug("iface is running %s", it.key().latin1() ); + handledInterfaceNames << running[it.data()].device; + iface->setStatus( true ); + iface->setPPPDpid( running[it.data()].pid ); + iface->modem()->setPPPDevice( running[it.data()].device ); + iface->refresh(); + } } + + setHandledInterfaceNames( handledInterfaceNames ); } /** * Delete any interfaces that we own. */ PPPModule::~PPPModule(){ + qDebug("PPPModule::~PPPModule() " ); QMap ifaces; + InterfaceKeeper keeper; Interface *i; for ( i=list.first(); i != 0; i=list.next() ){ + /* if online save the state */ + if ( i->getStatus() ) { + qDebug("Iface %s is still up", i->getHardwareName().latin1() ); + InterfacePPP* ppp = static_cast(i); + keeper.addInterface( ppp->pppPID(), ppp->pppDev(), ppp->getHardwareName() ); + } ifaces.insert( i->getInterfaceName(), i->getHardwareName() ); delete i; } @@ -69,7 +127,7 @@ QWidget *PPPModule::configure(Interface *i){ qDebug("return ModemWidget"); PPPConfigWidget *pppconfig = new PPPConfigWidget( (InterfacePPP*)i, 0, "PPPConfig", false, - Qt::WDestructiveClose ); + Qt::WDestructiveClose | Qt::WStyle_ContextHelp); return pppconfig; } @@ -135,3 +193,58 @@ void PPPModule::possibleNewInterfaces(QMap &newIfaces) } + +namespace { + InterfaceKeeper::InterfaceKeeper( ) { + } + InterfaceKeeper::~InterfaceKeeper() { + Config cfg("ppp_plugin_keeper"); + QStringList lst = cfg.groupList(); + for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { + Connection con; + cfg.setGroup( (*it) ); + cfg.clearGroup(); + } + + for (QMap::Iterator it = m_interfaces.begin(); it != m_interfaces.end(); ++it ) { + Connection con = it.data(); + cfg.setGroup( con.name ); + cfg.writeEntry( "pid", con.pid ); + cfg.writeEntry( "device", con.device ); + } + } + void InterfaceKeeper::addInterface(pid_t pid, const QString& dev, const QString& name ) { + Connection con; + con.pid = pid; + con.device = dev; + con.name = name; + m_interfaces.insert( name, con ); + } + QMap InterfaceKeeper::interfaces()const { + Config cfg("ppp_plugin_keeper"); + QMap ifaces; + QStringList lst = cfg.groupList(); + for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { + Connection con; + cfg.setGroup( (*it) ); + con.name = (*it); + con.pid = cfg.readNumEntry("pid"); + con.device = cfg.readEntry("device"); + qDebug(" %s %s %d", con.name.latin1(), con.device.latin1(), con.pid ); + + if ( con.pid != -1 && isAvailable( con.pid ) ) + ifaces.insert( con.name, con ); + } + return ifaces; + } + bool InterfaceKeeper::isAvailable( pid_t p)const { + if (::kill(p, 0 ) == 0 || errno != ESRCH ) { + qDebug("isAvailable %d", p); + return true; + } + + qDebug("notAvailable %d", p); + return false; + } + +} -- cgit v0.9.0.2