author | kergoth <kergoth> | 2003-08-09 17:14:54 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2003-08-09 17:14:54 (UTC) |
commit | a7e015198a8c5ad3b6e144a9032b059086253e00 (patch) (unidiff) | |
tree | b712b6f11310d88744fe393a92b3160b741a7efe /noncore/settings/networksettings/ppp/pppmodule.cpp | |
parent | beba0e73306815337bf04dee39502233595e9739 (diff) | |
download | opie-a7e015198a8c5ad3b6e144a9032b059086253e00.zip opie-a7e015198a8c5ad3b6e144a9032b059086253e00.tar.gz opie-a7e015198a8c5ad3b6e144a9032b059086253e00.tar.bz2 |
Merge from BRANCH_1_0
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,96 +1,154 @@ | |||
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 | ||
39 | /** | 97 | /** |
40 | * Change the current profile | 98 | * Change the current profile |
41 | */ | 99 | */ |
42 | void PPPModule::setProfile(const QString &newProfile){ | 100 | void PPPModule::setProfile(const QString &newProfile){ |
43 | profile = newProfile; | 101 | profile = newProfile; |
44 | } | 102 | } |
45 | 103 | ||
46 | /** | 104 | /** |
47 | * get the icon name for this device. | 105 | * get the icon name for this device. |
48 | * @param Interface* can be used in determining the icon. | 106 | * @param Interface* can be used in determining the icon. |
49 | * @return QString the icon name (minus .png, .gif etc) | 107 | * @return QString the icon name (minus .png, .gif etc) |
50 | */ | 108 | */ |
51 | QString PPPModule::getPixmapName(Interface* ){ | 109 | QString PPPModule::getPixmapName(Interface* ){ |
52 | return "ppp"; | 110 | return "ppp"; |
53 | } | 111 | } |
54 | 112 | ||
55 | /** | 113 | /** |
56 | * Check to see if the interface i is owned by this module. | 114 | * Check to see if the interface i is owned by this module. |
57 | * @param Interface* interface to check against | 115 | * @param Interface* interface to check against |
58 | * @return bool true if i is owned by this module, false otherwise. | 116 | * @return bool true if i is owned by this module, false otherwise. |
59 | */ | 117 | */ |
60 | bool PPPModule::isOwner(Interface *i){ | 118 | bool PPPModule::isOwner(Interface *i){ |
61 | return list.find( i ) != -1; | 119 | return list.find( i ) != -1; |
62 | } | 120 | } |
63 | 121 | ||
64 | /** | 122 | /** |
65 | * Create, and return the WLANConfigure Module | 123 | * Create, and return the WLANConfigure Module |
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. |
79 | */ | 137 | */ |
80 | QWidget *PPPModule::information(Interface *i){ | 138 | QWidget *PPPModule::information(Interface *i){ |
81 | // We don't have any advanced pppd information widget yet :-D | 139 | // We don't have any advanced pppd information widget yet :-D |
82 | // TODO ^ | 140 | // TODO ^ |
83 | 141 | ||
84 | return new InterfaceInformationPPP( 0, "InterfaceInformationPPP", i ); | 142 | return new InterfaceInformationPPP( 0, "InterfaceInformationPPP", i ); |
85 | } | 143 | } |
86 | 144 | ||
87 | /** | 145 | /** |
88 | * Get all active (up or down) interfaces | 146 | * Get all active (up or down) interfaces |
89 | * @return QList<Interface> A list of interfaces that exsist that havn't | 147 | * @return QList<Interface> A list of interfaces that exsist that havn't |
90 | * been called by isOwner() | 148 | * been called by isOwner() |
91 | */ | 149 | */ |
92 | QList<Interface> PPPModule::getInterfaces(){ | 150 | QList<Interface> PPPModule::getInterfaces(){ |
93 | // List all of the files in the peer directory | 151 | // List all of the files in the peer directory |
94 | qDebug("PPPModule::getInterfaces"); | 152 | qDebug("PPPModule::getInterfaces"); |
95 | return list; | 153 | return list; |
96 | } | 154 | } |
@@ -114,24 +172,79 @@ Interface *PPPModule::addNewInterface(const QString &newInterface){ | |||
114 | list.append( iface ); | 172 | list.append( iface ); |
115 | return iface; | 173 | return iface; |
116 | }else { | 174 | }else { |
117 | delete ifaceppp; | 175 | delete ifaceppp; |
118 | iface = NULL; | 176 | iface = NULL; |
119 | } | 177 | } |
120 | return iface; | 178 | return iface; |
121 | } | 179 | } |
122 | 180 | ||
123 | /** | 181 | /** |
124 | * Attempts to remove the interface, doesn't delete i | 182 | * Attempts to remove the interface, doesn't delete i |
125 | * @return bool true if successfull, false otherwise. | 183 | * @return bool true if successfull, false otherwise. |
126 | */ | 184 | */ |
127 | bool PPPModule::remove(Interface *i){ | 185 | bool PPPModule::remove(Interface *i){ |
128 | return list.remove(i); | 186 | return list.remove(i); |
129 | } | 187 | } |
130 | 188 | ||
131 | void PPPModule::possibleNewInterfaces(QMap<QString, QString> &newIfaces) | 189 | 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 | } | ||