summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-06-17 13:47:42 (UTC)
committer mickeyl <mickeyl>2005-06-17 13:47:42 (UTC)
commitc36e39b5b1e450e64d4c38cb59e56048a2bec258 (patch) (unidiff)
tree0e796a165a2e4ce8e24b8b79f15bb58f4265a7bb
parent0e11eb29a20ff6bff533a07ff604ed858237f82b (diff)
downloadopie-c36e39b5b1e450e64d4c38cb59e56048a2bec258.zip
opie-c36e39b5b1e450e64d4c38cb59e56048a2bec258.tar.gz
opie-c36e39b5b1e450e64d4c38cb59e56048a2bec258.tar.bz2
- disable DEBUG in opcmciasystem
- fix suspend/resume logic
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/linux/opcmciasystem.cpp12
-rw-r--r--noncore/applets/pcmcia/pcmcia.cpp9
2 files changed, 11 insertions, 10 deletions
diff --git a/libopie2/opiecore/linux/opcmciasystem.cpp b/libopie2/opiecore/linux/opcmciasystem.cpp
index 2eece6b..054d261 100644
--- a/libopie2/opiecore/linux/opcmciasystem.cpp
+++ b/libopie2/opiecore/linux/opcmciasystem.cpp
@@ -1,391 +1,391 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> 3 =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l. 4 .=l.
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This program is free software; you can 6 _;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; version 2 of the License. 10 - .   .-<_>     .<> Foundation; version 2 of the License.
11     ._= =}       : 11     ._= =}       :
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This program is distributed in the hope that 13    .i_,=:_.      -<s. This program is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more 18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details. 19++=   -.     .`     .: details.
20 :     =  ...= . :.=- 20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU 21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with 22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB. 23    --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation, 24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, 25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27 27
28*/ 28*/
29 29
30#include "opcmciasystem.h" 30#include "opcmciasystem.h"
31using namespace Opie::Core; 31using namespace Opie::Core;
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/odebug.h> 34#include <opie2/odebug.h>
35 35
36/* QT */ 36/* QT */
37#include <qfile.h> 37#include <qfile.h>
38#include <qtextstream.h> 38#include <qtextstream.h>
39 39
40/* STD */ 40/* STD */
41#include <errno.h> 41#include <errno.h>
42#include <fcntl.h> 42#include <fcntl.h>
43#include <string.h> 43#include <string.h>
44#include <stdlib.h> 44#include <stdlib.h>
45#include <sys/ioctl.h> 45#include <sys/ioctl.h>
46#include <sys/types.h> 46#include <sys/types.h>
47#include <sys/stat.h> 47#include <sys/stat.h>
48#include <unistd.h> 48#include <unistd.h>
49 49
50#define PROC_DEVICES "/proc/devices" 50#define PROC_DEVICES "/proc/devices"
51 51
52#define OPCMCIA_DEBUG 1 52// #define OPCMCIA_DEBUG 1
53 53
54/*====================================================================================== 54/*======================================================================================
55 * OPcmciaSystem 55 * OPcmciaSystem
56 *======================================================================================*/ 56 *======================================================================================*/
57 57
58OPcmciaSystem* OPcmciaSystem::_instance = 0; 58OPcmciaSystem* OPcmciaSystem::_instance = 0;
59 59
60OPcmciaSystem::OPcmciaSystem() 60OPcmciaSystem::OPcmciaSystem()
61 :_major( 0 ) 61 :_major( 0 )
62{ 62{
63 qDebug( "OPcmciaSystem::OPcmciaSystem()" ); 63 qDebug( "OPcmciaSystem::OPcmciaSystem()" );
64 64
65 // get major node number out of /proc/devices 65 // get major node number out of /proc/devices
66 QFile procfile( PROC_DEVICES ); 66 QFile procfile( PROC_DEVICES );
67 if ( procfile.exists() && procfile.open( IO_ReadOnly ) ) 67 if ( procfile.exists() && procfile.open( IO_ReadOnly ) )
68 { 68 {
69 QTextStream devstream( &procfile ); 69 QTextStream devstream( &procfile );
70 devstream.readLine(); // skip header 70 devstream.readLine(); // skip header
71 while ( !devstream.atEnd() && !_major ) 71 while ( !devstream.atEnd() && !_major )
72 { 72 {
73 int nodenumber; 73 int nodenumber;
74 QString driver; 74 QString driver;
75 devstream >> nodenumber >> driver; 75 devstream >> nodenumber >> driver;
76 if ( driver == "pcmcia" ) 76 if ( driver == "pcmcia" )
77 { 77 {
78 qDebug( "OPcmciaSystem::OPcmciaSystem(): gotcha! pcmcia node number = %d", nodenumber ); 78 qDebug( "OPcmciaSystem::OPcmciaSystem(): gotcha! pcmcia node number = %d", nodenumber );
79 _major = nodenumber; 79 _major = nodenumber;
80 break; 80 break;
81 } 81 }
82 } 82 }
83 } 83 }
84 else 84 else
85 { 85 {
86 qWarning( "OPcmciaSystem::OPcmciaSystem() - can't open /proc/devices - continuing with limited functionality." ); 86 qWarning( "OPcmciaSystem::OPcmciaSystem() - can't open /proc/devices - continuing with limited functionality." );
87 } 87 }
88 88
89 synchronize(); 89 synchronize();
90} 90}
91 91
92void OPcmciaSystem::synchronize() 92void OPcmciaSystem::synchronize()
93{ 93{
94 qDebug( "OPcmciaSystem::synchronize()" ); 94 qDebug( "OPcmciaSystem::synchronize()" );
95 _interfaces.clear(); 95 _interfaces.clear();
96 96
97 //FIXME: Use cardmgr subsystem ioctls 97 //FIXME: Use cardmgr subsystem ioctls
98 98
99 QString fileName; 99 QString fileName;
100 if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; } 100 if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; }
101 else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; } 101 else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; }
102 else { fileName = "/var/lib/pcmcia/stab"; } 102 else { fileName = "/var/lib/pcmcia/stab"; }
103 QFile cardinfofile( fileName ); 103 QFile cardinfofile( fileName );
104 if ( !cardinfofile.exists() || !cardinfofile.open( IO_ReadOnly ) ) 104 if ( !cardinfofile.exists() || !cardinfofile.open( IO_ReadOnly ) )
105 { 105 {
106 qWarning( "pcmcia info file not found or unaccessible" ); 106 qWarning( "pcmcia info file not found or unaccessible" );
107 return; 107 return;
108 } 108 }
109 QTextStream cardinfo( &cardinfofile ); 109 QTextStream cardinfo( &cardinfofile );
110 while ( !cardinfo.atEnd() ) 110 while ( !cardinfo.atEnd() )
111 { 111 {
112 QString strSocket; 112 QString strSocket;
113 int numSocket; 113 int numSocket;
114 char colon; 114 char colon;
115 QString cardName; 115 QString cardName;
116 cardinfo >> strSocket >> numSocket >> colon; 116 cardinfo >> strSocket >> numSocket >> colon;
117 cardName = cardinfo.readLine().stripWhiteSpace(); 117 cardName = cardinfo.readLine().stripWhiteSpace();
118 qDebug( "strSocket = '%s', numSocket = '%d', colon = '%c', cardName = '%s'", (const char*) strSocket, numSocket, colon, ( const char*) cardName ); 118 qDebug( "strSocket = '%s', numSocket = '%d', colon = '%c', cardName = '%s'", (const char*) strSocket, numSocket, colon, ( const char*) cardName );
119 if ( strSocket == "Socket" && colon == ':' ) 119 if ( strSocket == "Socket" && colon == ':' )
120 { 120 {
121 _interfaces.append( new OPcmciaSocket( _major, numSocket, this, (const char*) cardName ) ); 121 _interfaces.append( new OPcmciaSocket( _major, numSocket, this, (const char*) cardName ) );
122 } 122 }
123 else 123 else
124 { 124 {
125 continue; 125 continue;
126 } 126 }
127 } 127 }
128} 128}
129 129
130 130
131int OPcmciaSystem::count() const 131int OPcmciaSystem::count() const
132{ 132{
133 return _interfaces.count(); 133 return _interfaces.count();
134} 134}
135 135
136 136
137int OPcmciaSystem::cardCount() const 137int OPcmciaSystem::cardCount() const
138{ 138{
139 int nonEmpty = 0; 139 int nonEmpty = 0;
140 OPcmciaSystem::CardIterator it = iterator(); 140 OPcmciaSystem::CardIterator it = iterator();
141 while ( it.current() ) 141 while ( it.current() )
142 { 142 {
143 if ( !it.current()->isEmpty() ) nonEmpty++; 143 if ( !it.current()->isEmpty() ) nonEmpty++;
144 ++it; 144 ++it;
145 } 145 }
146 return nonEmpty; 146 return nonEmpty;
147} 147}
148 148
149 149
150OPcmciaSocket* OPcmciaSystem::socket( unsigned int number ) 150OPcmciaSocket* OPcmciaSystem::socket( unsigned int number )
151{ 151{
152 return _interfaces.at( number ); 152 return _interfaces.at( number );
153} 153}
154 154
155 155
156OPcmciaSystem* OPcmciaSystem::instance() 156OPcmciaSystem* OPcmciaSystem::instance()
157{ 157{
158 if ( !_instance ) _instance = new OPcmciaSystem(); 158 if ( !_instance ) _instance = new OPcmciaSystem();
159 return _instance; 159 return _instance;
160} 160}
161 161
162 162
163OPcmciaSystem::CardIterator OPcmciaSystem::iterator() const 163OPcmciaSystem::CardIterator OPcmciaSystem::iterator() const
164{ 164{
165 return OPcmciaSystem::CardIterator( _interfaces ); 165 return OPcmciaSystem::CardIterator( _interfaces );
166} 166}
167 167
168 168
169/*====================================================================================== 169/*======================================================================================
170 * OPcmciaSocket 170 * OPcmciaSocket
171 *======================================================================================*/ 171 *======================================================================================*/
172 172
173OPcmciaSocket::OPcmciaSocket( int major, int socket, QObject* parent, const char* name ) 173OPcmciaSocket::OPcmciaSocket( int major, int socket, QObject* parent, const char* name )
174 :QObject( parent, name ), _major( major ), _socket( socket ) 174 :QObject( parent, name ), _major( major ), _socket( socket )
175{ 175{
176 qDebug( "OPcmciaSocket::OPcmciaSocket()" ); 176 qDebug( "OPcmciaSocket::OPcmciaSocket()" );
177 init(); 177 init();
178} 178}
179 179
180 180
181OPcmciaSocket::~OPcmciaSocket() 181OPcmciaSocket::~OPcmciaSocket()
182{ 182{
183 qDebug( "OPcmciaSocket::~OPcmciaSocket()" ); 183 qDebug( "OPcmciaSocket::~OPcmciaSocket()" );
184 cleanup(); 184 cleanup();
185} 185}
186 186
187 187
188/* internal */ void OPcmciaSocket::init() 188/* internal */ void OPcmciaSocket::init()
189{ 189{
190 // open control socket and gather file descriptor 190 // open control socket and gather file descriptor
191 if ( _major ) 191 if ( _major )
192 { 192 {
193 dev_t dev = makedev( _major, _socket ); 193 dev_t dev = makedev( _major, _socket );
194 194
195#ifdef OPCMCIA_DEBUG 195#ifdef OPCMCIA_DEBUG
196 QString filename = "/tmp/opcmciasystem-debug"; 196 QString filename = "/tmp/opcmciasystem-debug";
197 if ( QFile::exists( filename ) ) 197 if ( QFile::exists( filename ) )
198#else 198#else
199 QString filename = QString().sprintf( "/tmp/opcmciasystem-%d", ::getpid() ); 199 QString filename = QString().sprintf( "/tmp/opcmciasystem-%d", ::getpid() );
200 if ( ::mknod( (const char*) filename, ( S_IFCHR|S_IREAD|S_IWRITE ), dev ) == 0 ) 200 if ( ::mknod( (const char*) filename, ( S_IFCHR|S_IREAD|S_IWRITE ), dev ) == 0 )
201#endif 201#endif
202 { 202 {
203 _fd = ::open( (const char*) filename, O_RDONLY); 203 _fd = ::open( (const char*) filename, O_RDONLY);
204 if ( !_fd ) 204 if ( !_fd )
205 { 205 {
206 qWarning( "OPcmciaSocket::init() - can't open control socket (%s)", strerror( errno ) ); 206 qWarning( "OPcmciaSocket::init() - can't open control socket (%s)", strerror( errno ) );
207 } 207 }
208 else 208 else
209 { 209 {
210 ::unlink( (const char*) filename ); 210 ::unlink( (const char*) filename );
211 } 211 }
212 } 212 }
213 else 213 else
214 { 214 {
215 qWarning( "OPcmciaSocket::init() - can't create device node '%s' (%s)", (const char*) filename, strerror( errno ) ); 215 qWarning( "OPcmciaSocket::init() - can't create device node '%s' (%s)", (const char*) filename, strerror( errno ) );
216 } 216 }
217 } 217 }
218} 218}
219 219
220/* internal */ void OPcmciaSocket::cleanup() 220/* internal */ void OPcmciaSocket::cleanup()
221{ 221{
222 // close control socket 222 // close control socket
223} 223}
224 224
225/* internal */ bool OPcmciaSocket::getTuple( cisdata_t tuple ) const 225/* internal */ bool OPcmciaSocket::getTuple( cisdata_t tuple ) const
226{ 226{
227 _ioctlarg.tuple.DesiredTuple = tuple; 227 _ioctlarg.tuple.DesiredTuple = tuple;
228 _ioctlarg.tuple.Attributes = TUPLE_RETURN_COMMON; 228 _ioctlarg.tuple.Attributes = TUPLE_RETURN_COMMON;
229 _ioctlarg.tuple.TupleOffset = 0; 229 _ioctlarg.tuple.TupleOffset = 0;
230 230
231 int result; 231 int result;
232 result = ::ioctl(_fd, DS_GET_FIRST_TUPLE, &_ioctlarg); 232 result = ::ioctl(_fd, DS_GET_FIRST_TUPLE, &_ioctlarg);
233 if ( result != 0 ) 233 if ( result != 0 )
234 { 234 {
235 qWarning( "OPcmciaSocket::getTuple() - DS_GET_FIRST_TUPLE failed (%s)", strerror( errno ) ); 235 qWarning( "OPcmciaSocket::getTuple() - DS_GET_FIRST_TUPLE failed (%s)", strerror( errno ) );
236 return false; 236 return false;
237 } 237 }
238 238
239 result = ::ioctl(_fd, DS_GET_TUPLE_DATA, &_ioctlarg); 239 result = ::ioctl(_fd, DS_GET_TUPLE_DATA, &_ioctlarg);
240 if ( result != 0 ) 240 if ( result != 0 )
241 { 241 {
242 qWarning( "OPcmciaSocket::getTuple() - DS_GET_TUPLE_DATA failed (%s)", strerror( errno ) ); 242 qWarning( "OPcmciaSocket::getTuple() - DS_GET_TUPLE_DATA failed (%s)", strerror( errno ) );
243 return false; 243 return false;
244 } 244 }
245 245
246 result = ::ioctl( _fd, DS_PARSE_TUPLE, &_ioctlarg ); 246 result = ::ioctl( _fd, DS_PARSE_TUPLE, &_ioctlarg );
247 if ( result != 0 ) 247 if ( result != 0 )
248 { 248 {
249 qWarning( "OPcmciaSocket::getTuple() - DS_PARSE_TUPLE failed (%s)", strerror( errno ) ); 249 qWarning( "OPcmciaSocket::getTuple() - DS_PARSE_TUPLE failed (%s)", strerror( errno ) );
250 return false; 250 return false;
251 } 251 }
252 252
253 return true; 253 return true;
254} 254}
255 255
256 256
257int OPcmciaSocket::number() const 257int OPcmciaSocket::number() const
258{ 258{
259 return _socket; 259 return _socket;
260} 260}
261 261
262 262
263QString OPcmciaSocket::identity() const 263QString OPcmciaSocket::identity() const
264{ 264{
265 return ( strcmp( name(), "empty" ) == 0 ) ? "<Empty Socket>" : name(); 265 return ( strcmp( name(), "empty" ) == 0 ) ? "<Empty Socket>" : name();
266} 266}
267 267
268 268
269const OPcmciaSocket::OPcmciaSocketCardStatus OPcmciaSocket::status() const 269const OPcmciaSocket::OPcmciaSocketCardStatus OPcmciaSocket::status() const
270{ 270{
271 cs_status_t cs_status; 271 cs_status_t cs_status;
272 cs_status.Function = 0; 272 cs_status.Function = 0;
273 int result = ::ioctl( _fd, DS_GET_STATUS, &cs_status ); 273 int result = ::ioctl( _fd, DS_GET_STATUS, &cs_status );
274 if ( result != 0 ) 274 if ( result != 0 )
275 { 275 {
276 qWarning( "OPcmciaSocket::status() - DS_GET_STATUS failed (%s)", strerror( errno ) ); 276 qWarning( "OPcmciaSocket::status() - DS_GET_STATUS failed (%s)", strerror( errno ) );
277 return Unknown; 277 return Unknown;
278 } 278 }
279 else 279 else
280 { 280 {
281 qDebug( " card status = 0x%08x", cs_status.CardState ); 281 qDebug( " card status = 0x%08x", cs_status.CardState );
282 qDebug( " socket status = 0x%08x", cs_status.SocketState ); 282 qDebug( " socket status = 0x%08x", cs_status.SocketState );
283 return (OPcmciaSocket::OPcmciaSocketCardStatus) (cs_status.CardState + cs_status.SocketState); 283 return (OPcmciaSocket::OPcmciaSocketCardStatus) (cs_status.CardState + cs_status.SocketState);
284 } 284 }
285} 285}
286 286
287 287
288bool OPcmciaSocket::isUnsupported() const 288bool OPcmciaSocket::isUnsupported() const
289{ 289{
290 return ( strcmp( name(), "unsupported card" ) == 0 ); 290 return ( strcmp( name(), "unsupported card" ) == 0 );
291} 291}
292 292
293 293
294bool OPcmciaSocket::isEmpty() const 294bool OPcmciaSocket::isEmpty() const
295{ 295{
296 return ! status() && ( Occupied || OccupiedCardBus ); 296 return ! status() && ( Occupied || OccupiedCardBus );
297} 297}
298 298
299 299
300bool OPcmciaSocket::isSuspended() const 300bool OPcmciaSocket::isSuspended() const
301{ 301{
302 return status() && Suspended; 302 return status() && Suspended;
303} 303}
304 304
305 305
306bool OPcmciaSocket::eject() 306bool OPcmciaSocket::eject()
307{ 307{
308 return ::ioctl( _fd, DS_EJECT_CARD ); 308 return ::ioctl( _fd, DS_EJECT_CARD ) != -1;
309} 309}
310 310
311 311
312bool OPcmciaSocket::insert() 312bool OPcmciaSocket::insert()
313{ 313{
314 return ::ioctl( _fd, DS_INSERT_CARD ); 314 return ::ioctl( _fd, DS_INSERT_CARD ) != -1;
315} 315}
316 316
317 317
318bool OPcmciaSocket::suspend() 318bool OPcmciaSocket::suspend()
319{ 319{
320 return ::ioctl( _fd, DS_SUSPEND_CARD ); 320 return ::ioctl( _fd, DS_SUSPEND_CARD ) != -1;
321} 321}
322 322
323 323
324bool OPcmciaSocket::resume() 324bool OPcmciaSocket::resume()
325{ 325{
326 return ::ioctl( _fd, DS_RESUME_CARD ); 326 return ::ioctl( _fd, DS_RESUME_CARD ) != -1;
327} 327}
328 328
329 329
330bool OPcmciaSocket::reset() 330bool OPcmciaSocket::reset()
331{ 331{
332 return ::ioctl( _fd, DS_RESET_CARD ); 332 return ::ioctl( _fd, DS_RESET_CARD ) != -1;
333} 333}
334 334
335 335
336QStringList OPcmciaSocket::productIdentity() const 336QStringList OPcmciaSocket::productIdentity() const
337{ 337{
338 QStringList list; 338 QStringList list;
339 cistpl_vers_1_t *vers = &_ioctlarg.tuple_parse.parse.version_1; 339 cistpl_vers_1_t *vers = &_ioctlarg.tuple_parse.parse.version_1;
340 if ( getTuple( CISTPL_VERS_1 ) ) 340 if ( getTuple( CISTPL_VERS_1 ) )
341 { 341 {
342 for ( int i = 0; i < CISTPL_VERS_1_MAX_PROD_STRINGS; ++i ) 342 for ( int i = 0; i < CISTPL_VERS_1_MAX_PROD_STRINGS; ++i )
343 { 343 {
344 qDebug( " PRODID = '%s'", vers->str+vers->ofs[i] ); 344 qDebug( " PRODID = '%s'", vers->str+vers->ofs[i] );
345 list += vers->str+vers->ofs[i]; 345 list += vers->str+vers->ofs[i];
346 } 346 }
347 } 347 }
348 else 348 else
349 { 349 {
350 list += "<unknown>"; 350 list += "<unknown>";
351 } 351 }
352 return list; 352 return list;
353} 353}
354 354
355 355
356QString OPcmciaSocket::manufacturerIdentity() const 356QString OPcmciaSocket::manufacturerIdentity() const
357{ 357{
358 cistpl_manfid_t *manfid = &_ioctlarg.tuple_parse.parse.manfid; 358 cistpl_manfid_t *manfid = &_ioctlarg.tuple_parse.parse.manfid;
359 if ( getTuple( CISTPL_MANFID ) ) 359 if ( getTuple( CISTPL_MANFID ) )
360 { 360 {
361 return QString().sprintf( "0x%04x, 0x%04x", manfid->manf, manfid->card ); 361 return QString().sprintf( "0x%04x, 0x%04x", manfid->manf, manfid->card );
362 } 362 }
363 else 363 else
364 return "<unknown>"; 364 return "<unknown>";
365} 365}
366 366
367 367
368QString OPcmciaSocket::function() const 368QString OPcmciaSocket::function() const
369{ 369{
370 cistpl_funcid_t *funcid = &_ioctlarg.tuple_parse.parse.funcid; 370 cistpl_funcid_t *funcid = &_ioctlarg.tuple_parse.parse.funcid;
371 if ( getTuple( CISTPL_FUNCID ) ) 371 if ( getTuple( CISTPL_FUNCID ) )
372 { 372 {
373 switch ( funcid->func ) 373 switch ( funcid->func )
374 { 374 {
375 case 0: return "Multifunction"; break; 375 case 0: return "Multifunction"; break;
376 case 1: return "Memory"; break; 376 case 1: return "Memory"; break;
377 case 2: return "Serial"; break; 377 case 2: return "Serial"; break;
378 case 3: return "Parallel"; break; 378 case 3: return "Parallel"; break;
379 case 4: return "Fixed Disk"; break; 379 case 4: return "Fixed Disk"; break;
380 case 5: return "Video"; break; 380 case 5: return "Video"; break;
381 case 6: return "Network"; break; 381 case 6: return "Network"; break;
382 case 7: return "AIMS"; break; 382 case 7: return "AIMS"; break;
383 case 8: return "SCSI"; break; 383 case 8: return "SCSI"; break;
384 default: return "<unknown>"; break; 384 default: return "<unknown>"; break;
385 } 385 }
386 } 386 }
387 else 387 else
388 { 388 {
389 return "<unknown>"; 389 return "<unknown>";
390 } 390 }
391} 391}
diff --git a/noncore/applets/pcmcia/pcmcia.cpp b/noncore/applets/pcmcia/pcmcia.cpp
index aea699f..99c1bc9 100644
--- a/noncore/applets/pcmcia/pcmcia.cpp
+++ b/noncore/applets/pcmcia/pcmcia.cpp
@@ -1,297 +1,298 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> 3 =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l. 4 .=l.
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This program is free software; you can 6 _;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License, 10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version. 11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This program is distributed in the hope that 13    .i_,=:_.      -<s. This program is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more 18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details. 19++=   -.     .`     .: details.
20 :     =  ...= . :.=- 20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU 21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with 22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB. 23    --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation, 24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, 25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27 27
28*/ 28*/
29 29
30#include "pcmcia.h" 30#include "pcmcia.h"
31#include "configdialog.h" 31#include "configdialog.h"
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/odebug.h> 34#include <opie2/odebug.h>
35#include <opie2/odevice.h> 35#include <opie2/odevice.h>
36#include <opie2/oconfig.h> 36#include <opie2/oconfig.h>
37#include <opie2/oprocess.h> 37#include <opie2/oprocess.h>
38#include <opie2/opcmciasystem.h> 38#include <opie2/opcmciasystem.h>
39#include <opie2/oresource.h> 39#include <opie2/oresource.h>
40#include <opie2/otaskbarapplet.h> 40#include <opie2/otaskbarapplet.h>
41#include <qpe/applnk.h> 41#include <qpe/applnk.h>
42#include <qpe/resource.h> 42#include <qpe/resource.h>
43using namespace Opie::Core; 43using namespace Opie::Core;
44using namespace Opie::Ui; 44using namespace Opie::Ui;
45 45
46/* QT */ 46/* QT */
47#include <qcopchannel_qws.h> 47#include <qcopchannel_qws.h>
48#include <qpainter.h> 48#include <qpainter.h>
49#include <qfile.h> 49#include <qfile.h>
50#include <qtextstream.h> 50#include <qtextstream.h>
51#include <qmessagebox.h> 51#include <qmessagebox.h>
52#include <qsound.h> 52#include <qsound.h>
53#include <qtimer.h> 53#include <qtimer.h>
54 54
55/* STD */ 55/* STD */
56#include <stdio.h> 56#include <stdio.h>
57#include <unistd.h> 57#include <unistd.h>
58#include <stdlib.h> 58#include <stdlib.h>
59#include <string.h> 59#include <string.h>
60#include <errno.h>
60#include <fcntl.h> 61#include <fcntl.h>
61#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 62#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
62#include <sys/vfs.h> 63#include <sys/vfs.h>
63#include <mntent.h> 64#include <mntent.h>
64#endif 65#endif
65 66
66PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent ) 67PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent )
67{ 68{
68 QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); 69 QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this );
69 connect( pcmciaChannel, 70 connect( pcmciaChannel,
70 SIGNAL( received(const QCString&,const QByteArray&) ), this, 71 SIGNAL( received(const QCString&,const QByteArray&) ), this,
71 SLOT( cardMessage(const QCString&,const QByteArray&) ) ); 72 SLOT( cardMessage(const QCString&,const QByteArray&) ) );
72 73
73 setFocusPolicy( NoFocus ); 74 setFocusPolicy( NoFocus );
74 setFixedWidth ( AppLnk::smallIconSize() ); 75 setFixedWidth ( AppLnk::smallIconSize() );
75 setFixedHeight ( AppLnk::smallIconSize() ); 76 setFixedHeight ( AppLnk::smallIconSize() );
76 pm = Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon ); 77 pm = Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon );
77 configuring = false; 78 configuring = false;
78} 79}
79 80
80 81
81PcmciaManager::~PcmciaManager() 82PcmciaManager::~PcmciaManager()
82{ 83{
83} 84}
84 85
85 86
86void PcmciaManager::popUp( QString message, QString icon ) 87void PcmciaManager::popUp( QString message, QString icon )
87{ 88{
88 if ( !popupMenu ) { 89 if ( !popupMenu ) {
89 popupMenu = new QPopupMenu( this ); 90 popupMenu = new QPopupMenu( this );
90 } 91 }
91 92
92 popupMenu->clear(); 93 popupMenu->clear();
93 if ( icon.isEmpty() ) { 94 if ( icon.isEmpty() ) {
94 popupMenu->insertItem( message, 0 ); 95 popupMenu->insertItem( message, 0 );
95 } else { 96 } else {
96 popupMenu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ), 97 popupMenu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ),
97 message, 0 ); 98 message, 0 );
98 } 99 }
99 100
100 QPoint p = mapToGlobal( QPoint( 0, 0 ) ); 101 QPoint p = mapToGlobal( QPoint( 0, 0 ) );
101 QSize s = popupMenu->sizeHint(); 102 QSize s = popupMenu->sizeHint();
102 popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), 103 popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ),
103 p.y() - s.height() ), 0 ); 104 p.y() - s.height() ), 0 );
104 105
105 QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); 106 QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) );
106} 107}
107 108
108 109
109void PcmciaManager::popupTimeout() 110void PcmciaManager::popupTimeout()
110{ 111{
111 popupMenu->hide(); 112 popupMenu->hide();
112} 113}
113 114
114enum { EJECT, INSERT, SUSPEND, RESUME, RESET, CONFIGURE }; 115enum { EJECT, INSERT, SUSPEND, RESUME, RESET, CONFIGURE };
115 116
116void PcmciaManager::mousePressEvent( QMouseEvent* ) 117void PcmciaManager::mousePressEvent( QMouseEvent* )
117{ 118{
118 QPopupMenu* menu = new QPopupMenu( this ); 119 QPopupMenu* menu = new QPopupMenu( this );
119 QStringList cmd; 120 QStringList cmd;
120 bool execute = true; 121 bool execute = true;
121 122
122 OPcmciaSystem* sys = OPcmciaSystem::instance(); 123 OPcmciaSystem* sys = OPcmciaSystem::instance();
123 OPcmciaSystem::CardIterator it = sys->iterator(); 124 OPcmciaSystem::CardIterator it = sys->iterator();
124 if ( !sys->count() ) return; 125 if ( !sys->count() ) return;
125 126
126 int i = 0; 127 int i = 0;
127 while ( it.current() ) 128 while ( it.current() )
128 { 129 {
129 QPopupMenu* submenu = new QPopupMenu( menu ); 130 QPopupMenu* submenu = new QPopupMenu( menu );
130 submenu->insertItem( "&Eject", EJECT+i*100 ); 131 submenu->insertItem( "&Eject", EJECT+i*100 );
131 submenu->insertItem( "&Insert", INSERT+i*100 ); 132 submenu->insertItem( "&Insert", INSERT+i*100 );
132 submenu->insertItem( "&Suspend", SUSPEND+i*100 ); 133 submenu->insertItem( "&Suspend", SUSPEND+i*100 );
133 submenu->insertItem( "&Resume", RESUME+i*100 ); 134 submenu->insertItem( "&Resume", RESUME+i*100 );
134 submenu->insertItem( "Rese&t", RESET+i*100 ); 135 submenu->insertItem( "Rese&t", RESET+i*100 );
135 submenu->insertItem( "&Configure", CONFIGURE+i*100 ); 136 submenu->insertItem( "&Configure", CONFIGURE+i*100 );
136 137
137 submenu->setItemEnabled( EJECT+i*100, !it.current()->isEmpty() ); 138 submenu->setItemEnabled( EJECT+i*100, !it.current()->isEmpty() );
138 submenu->setItemEnabled( INSERT+i*100, it.current()->isEmpty() ); 139 submenu->setItemEnabled( INSERT+i*100, it.current()->isEmpty() );
139 submenu->setItemEnabled( SUSPEND+i*100, !it.current()->isEmpty() && !it.current()->isSuspended() ); 140 submenu->setItemEnabled( SUSPEND+i*100, !it.current()->isEmpty() && it.current()->isSuspended() );
140 submenu->setItemEnabled( RESUME+i*100, !it.current()->isEmpty() && it.current()->isSuspended() ); 141 submenu->setItemEnabled( RESUME+i*100, !it.current()->isEmpty() && !it.current()->isSuspended() );
141 submenu->setItemEnabled( CONFIGURE+i*100, !it.current()->isEmpty() && !configuring ); 142 submenu->setItemEnabled( CONFIGURE+i*100, !it.current()->isEmpty() && !configuring );
142 143
143 connect( submenu, SIGNAL(activated(int)), this, SLOT(userCardAction(int)) ); 144 connect( submenu, SIGNAL(activated(int)), this, SLOT(userCardAction(int)) );
144 menu->insertItem( tr( "%1: %2" ).arg( i++ ).arg( it.current()->identity() ), submenu, 1 ); 145 menu->insertItem( tr( "%1: %2" ).arg( i++ ).arg( it.current()->identity() ), submenu, 1 );
145 ++it; 146 ++it;
146 } 147 }
147 148
148 QPoint p = mapToGlobal( QPoint( 0, 0 ) ); 149 QPoint p = mapToGlobal( QPoint( 0, 0 ) );
149 QSize s = menu->sizeHint(); 150 QSize s = menu->sizeHint();
150 int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 ); 151 int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 );
151 qDebug( "pcmcia: menu result = %d", opt ); 152 qDebug( "pcmcia: menu result = %d", opt );
152 delete menu; 153 delete menu;
153} 154}
154 155
155 156
156void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) 157void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
157{ 158{
158 odebug << "PcmciaManager::cardMessage( '" << msg << "' )" << oendl; 159 odebug << "PcmciaManager::cardMessage( '" << msg << "' )" << oendl;
159 if ( msg != "stabChanged()" ) return; 160 if ( msg != "stabChanged()" ) return;
160 161
161 /* check if a previously unknown card has been inserted */ 162 /* check if a previously unknown card has been inserted */
162 OPcmciaSystem::instance()->synchronize(); 163 OPcmciaSystem::instance()->synchronize();
163 164
164 if ( !OPcmciaSystem::instance()->cardCount() ) return; 165 if ( !OPcmciaSystem::instance()->cardCount() ) return;
165 166
166 OConfig cfg( "PCMCIA" ); 167 OConfig cfg( "PCMCIA" );
167 cfg.setGroup( "Global" ); 168 cfg.setGroup( "Global" );
168 int nCards = cfg.readNumEntry( "nCards", 0 ); 169 int nCards = cfg.readNumEntry( "nCards", 0 );
169 170
170 OPcmciaSystem* sys = OPcmciaSystem::instance(); 171 OPcmciaSystem* sys = OPcmciaSystem::instance();
171 OPcmciaSystem::CardIterator it = sys->iterator(); 172 OPcmciaSystem::CardIterator it = sys->iterator();
172 173
173 bool newCard = true; 174 bool newCard = true;
174 OPcmciaSocket* theCard = 0; 175 OPcmciaSocket* theCard = 0;
175 176
176 while ( it.current() && newCard ) 177 while ( it.current() && newCard )
177 { 178 {
178 if ( it.current()->isEmpty() ) 179 if ( it.current()->isEmpty() )
179 { 180 {
180 odebug << "skipping empty card in socket " << it.current()->number() << oendl; 181 odebug << "skipping empty card in socket " << it.current()->number() << oendl;
181 ++it; 182 ++it;
182 continue; 183 continue;
183 } 184 }
184 else 185 else
185 { 186 {
186 theCard = it.current(); 187 theCard = it.current();
187 QString cardName = theCard->productIdentity().join( " " ); 188 QString cardName = theCard->productIdentity().join( " " );
188 for ( int i = 0; i < nCards; ++i ) 189 for ( int i = 0; i < nCards; ++i )
189 { 190 {
190 QString cardSection = QString( "Card_%1" ).arg( i ); 191 QString cardSection = QString( "Card_%1" ).arg( i );
191 cfg.setGroup( cardSection ); 192 cfg.setGroup( cardSection );
192 QString name = cfg.readEntry( "name" ); 193 QString name = cfg.readEntry( "name" );
193 odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl; 194 odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
194 if ( cardName == name ) 195 if ( cardName == name )
195 { 196 {
196 newCard = false; 197 newCard = false;
197 break; 198 break;
198 } 199 }
199 } 200 }
200 if ( !newCard ) ++it; else break; 201 if ( !newCard ) ++it; else break;
201 } 202 }
202 } 203 }
203 if ( newCard ) 204 if ( newCard )
204 { 205 {
205 odebug << "pcmcia: new card detected" << oendl; 206 odebug << "pcmcia: new card detected" << oendl;
206 cfg.setGroup( QString( "Card_%1" ).arg( nCards ) ); 207 cfg.setGroup( QString( "Card_%1" ).arg( nCards ) );
207 cfg.writeEntry( "name", theCard->productIdentity().join( " " ) ); 208 cfg.writeEntry( "name", theCard->productIdentity().join( " " ) );
208 cfg.writeEntry( "insert", "suspend" ); 209 cfg.writeEntry( "insert", "suspend" );
209 cfg.setGroup( "Global" ); 210 cfg.setGroup( "Global" );
210 cfg.writeEntry( "nCards", nCards+1 ); 211 cfg.writeEntry( "nCards", nCards+1 );
211 cfg.write(); 212 cfg.write();
212 213
213 int result = QMessageBox::information( qApp->desktop(), 214 int result = QMessageBox::information( qApp->desktop(),
214 tr( "PCMCIA/CF Subsystem" ), 215 tr( "PCMCIA/CF Subsystem" ),
215 tr( "You have inserted a new card:\n%1\nDo you want to configure?" ).arg( theCard->productIdentity().join( " " ) ), 216 tr( "You have inserted a new card:\n%1\nDo you want to configure?" ).arg( theCard->productIdentity().join( " " ) ),
216 tr( "Yes" ), tr( "No" ), 0, 0, 1 ); 217 tr( "Yes" ), tr( "No" ), 0, 0, 1 );
217 odebug << "result = " << result << oendl; 218 odebug << "result = " << result << oendl;
218 if ( result == 0 ) 219 if ( result == 0 )
219 { 220 {
220 configure( theCard ); 221 configure( theCard );
221 } 222 }
222 else 223 else
223 { 224 {
224 odebug << "pcmcia: user doesn't want to configure " << theCard->productIdentity().join( " " ) << " now." << oendl; 225 odebug << "pcmcia: user doesn't want to configure " << theCard->productIdentity().join( " " ) << " now." << oendl;
225 } 226 }
226 } 227 }
227 else 228 else
228 { 229 {
229 odebug << "pcmcia: card has been previously inserted" << oendl; 230 odebug << "pcmcia: card has been previously inserted" << oendl;
230 } 231 }
231 repaint( true ); 232 repaint( true );
232} 233}
233 234
234 235
235void PcmciaManager::paintEvent( QPaintEvent * ) 236void PcmciaManager::paintEvent( QPaintEvent * )
236{ 237{
237 QPainter p( this ); 238 QPainter p( this );
238 odebug << "sockets = " << OPcmciaSystem::instance()->count() << ", cards = " << OPcmciaSystem::instance()->cardCount() << oendl; 239 odebug << "sockets = " << OPcmciaSystem::instance()->count() << ", cards = " << OPcmciaSystem::instance()->cardCount() << oendl;
239 240
240 if ( OPcmciaSystem::instance()->cardCount() ) 241 if ( OPcmciaSystem::instance()->cardCount() )
241 { 242 {
242 p.drawPixmap( 0, 0, pm ); 243 p.drawPixmap( 0, 0, pm );
243 show(); 244 show();
244 } 245 }
245 else 246 else
246 { 247 {
247 hide(); 248 hide();
248 } 249 }
249} 250}
250 251
251int PcmciaManager::position() 252int PcmciaManager::position()
252{ 253{
253 return 7; 254 return 7;
254} 255}
255 256
256void PcmciaManager::execCommand( const QStringList &strList ) 257void PcmciaManager::execCommand( const QStringList &strList )
257{ 258{
258} 259}
259 260
260void PcmciaManager::userCardAction( int action ) 261void PcmciaManager::userCardAction( int action )
261{ 262{
262 odebug << "user action requested. action = " << action << oendl; 263 odebug << "user action on socket " << action / 100 << " requested. action = " << action << oendl;
263 264
264 int socket = action / 100; 265 int socket = action / 100;
265 int what = action % 100; 266 int what = action % 100;
266 bool success = false; 267 bool success = false;
267 268
268 switch ( what ) 269 switch ( what )
269 { 270 {
270 case CONFIGURE: configure( OPcmciaSystem::instance()->socket( socket ) ); success = true; break; 271 case CONFIGURE: configure( OPcmciaSystem::instance()->socket( socket ) ); success = true; break;
271 case EJECT: success = OPcmciaSystem::instance()->socket( socket )->eject(); break; 272 case EJECT: success = OPcmciaSystem::instance()->socket( socket )->eject(); break;
272 case INSERT: success = OPcmciaSystem::instance()->socket( socket )->insert(); break; 273 case INSERT: success = OPcmciaSystem::instance()->socket( socket )->insert(); break;
273 case SUSPEND: success = OPcmciaSystem::instance()->socket( socket )->suspend(); break; 274 case SUSPEND: success = OPcmciaSystem::instance()->socket( socket )->suspend(); break;
274 case RESUME: success = OPcmciaSystem::instance()->socket( socket )->resume(); break; 275 case RESUME: success = OPcmciaSystem::instance()->socket( socket )->resume(); break;
275 case RESET: success = OPcmciaSystem::instance()->socket( socket )->reset(); break; 276 case RESET: success = OPcmciaSystem::instance()->socket( socket )->reset(); break;
276 default: odebug << "not yet implemented" << oendl; 277 default: odebug << "not yet implemented" << oendl;
277 } 278 }
278 279
279 if ( !success ) 280 if ( !success )
280 { 281 {
281 owarn << "couldn't perform user action" << oendl; 282 owarn << "couldn't perform user action (" << strerror( errno ) << ")" << oendl;
282 } 283 }
283 284
284} 285}
285 286
286void PcmciaManager::configure( OPcmciaSocket* card ) 287void PcmciaManager::configure( OPcmciaSocket* card )
287{ 288{
288 configuring = true; 289 configuring = true;
289 ConfigDialog dialog( card, qApp->desktop() ); 290 ConfigDialog dialog( card, qApp->desktop() );
290 int configresult = QPEApplication::execDialog( &dialog, false ); 291 int configresult = QPEApplication::execDialog( &dialog, false );
291 configuring = false; 292 configuring = false;
292 odebug << "pcmcia: configresult = " << configresult << oendl; 293 odebug << "pcmcia: configresult = " << configresult << oendl;
293} 294}
294 295
295 296
296EXPORT_OPIE_APPLET_v1( PcmciaManager ) 297EXPORT_OPIE_APPLET_v1( PcmciaManager )
297 298