Diffstat (limited to 'libopie2/opiecore/linux/opcmciasystem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiecore/linux/opcmciasystem.cpp | 92 |
1 files changed, 77 insertions, 15 deletions
diff --git a/libopie2/opiecore/linux/opcmciasystem.cpp b/libopie2/opiecore/linux/opcmciasystem.cpp index 34e4477..c4b5316 100644 --- a/libopie2/opiecore/linux/opcmciasystem.cpp +++ b/libopie2/opiecore/linux/opcmciasystem.cpp | |||
@@ -20,124 +20,186 @@ | |||
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" |
31 | using namespace Opie::Core; | 31 | using 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 <sys/ioctl.h> | 45 | #include <sys/ioctl.h> |
45 | #include <sys/types.h> | 46 | #include <sys/types.h> |
46 | #include <sys/stat.h> | 47 | #include <sys/stat.h> |
47 | 48 | ||
48 | /*====================================================================================== | 49 | /*====================================================================================== |
49 | * OPcmciaSystem | 50 | * OPcmciaSystem |
50 | *======================================================================================*/ | 51 | *======================================================================================*/ |
51 | 52 | ||
52 | OPcmciaSystem* OPcmciaSystem::_instance = 0; | 53 | OPcmciaSystem* OPcmciaSystem::_instance = 0; |
53 | 54 | ||
54 | OPcmciaSystem::OPcmciaSystem() | 55 | OPcmciaSystem::OPcmciaSystem() |
55 | { | 56 | { |
56 | qDebug( "OPcmciaSystem::OPcmciaSystem()" ); | 57 | qDebug( "OPcmciaSystem::OPcmciaSystem()" ); |
57 | synchronize(); | 58 | synchronize(); |
58 | } | 59 | } |
59 | 60 | ||
60 | void OPcmciaSystem::synchronize() | 61 | void OPcmciaSystem::synchronize() |
61 | { | 62 | { |
62 | qDebug( "OPcmciaSystem::synchronize()" ); | 63 | qDebug( "OPcmciaSystem::synchronize()" ); |
63 | _interfaces.clear(); | 64 | _interfaces.clear(); |
64 | 65 | ||
65 | //FIXME: Use cardmgr subsystem ioctls | 66 | //FIXME: Use cardmgr subsystem ioctls |
66 | 67 | ||
67 | QString fileName; | 68 | QString fileName; |
68 | if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; } | 69 | if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; } |
69 | else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; } | 70 | else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; } |
70 | else { fileName = "/var/lib/pcmcia/stab"; } | 71 | else { fileName = "/var/lib/pcmcia/stab"; } |
71 | QFile cardinfofile( fileName ); | 72 | QFile cardinfofile( fileName ); |
72 | if ( !cardinfofile.exists() || !cardinfofile.open( IO_ReadOnly ) ) | 73 | if ( !cardinfofile.exists() || !cardinfofile.open( IO_ReadOnly ) ) |
73 | { | 74 | { |
74 | qWarning( "pcmcia info file not found or unaccessible" ); | 75 | qWarning( "pcmcia info file not found or unaccessible" ); |
75 | return; | 76 | return; |
76 | } | 77 | } |
77 | QTextStream cardinfo( &cardinfofile ); | 78 | QTextStream cardinfo( &cardinfofile ); |
78 | while ( !cardinfo.atEnd() ) | 79 | while ( !cardinfo.atEnd() ) |
79 | { | 80 | { |
80 | QString line = cardinfo.readLine(); | 81 | QString strSocket; |
81 | // qDebug( "line = '%s'", (const char*) line ); | 82 | int numSocket; |
82 | if ( line.startsWith( "Socket" ) && ! line.contains( "empty" ) ) | 83 | char colon; |
84 | QString cardName; | ||
85 | cardinfo >> strSocket >> numSocket >> colon; | ||
86 | cardName = cardinfo.readLine().stripWhiteSpace(); | ||
87 | qDebug( "strSocket = '%s', numSocket = '%d', colon = '%c', cardName = '%s'", (const char*) strSocket, numSocket, colon, ( const char*) cardName ); | ||
88 | if ( strSocket == "Socket" && colon == ':' ) | ||
83 | { | 89 | { |
84 | int mid = line.find( ':' ); | 90 | _interfaces.append( new OPcmciaSocket( numSocket, this, (const char*) cardName ) ); |
85 | QString name = line.right( line.length() - mid - 1 ); | ||
86 | QString id = line.right( line.length() - mid + 1 ); | ||
87 | if ( mid ) _interfaces.insert( name.stripWhiteSpace(), new OPcmciaCard( this, (const char*) id.stripWhiteSpace() ) ); | ||
88 | } | 91 | } |
89 | else | 92 | else |
90 | { | 93 | { |
91 | continue; | 94 | continue; |
92 | } | 95 | } |
93 | } | 96 | } |
94 | } | 97 | } |
95 | 98 | ||
96 | 99 | ||
97 | int OPcmciaSystem::count() const | 100 | int OPcmciaSystem::count() const |
98 | { | 101 | { |
99 | return _interfaces.count(); | 102 | return _interfaces.count(); |
100 | } | 103 | } |
101 | 104 | ||
102 | 105 | ||
103 | OPcmciaCard* OPcmciaSystem::card( const QString& iface ) const | 106 | int OPcmciaSystem::cardCount() const |
104 | { | 107 | { |
105 | return _interfaces[iface]; | 108 | int nonEmpty = 0; |
109 | OPcmciaSystem::CardIterator it = iterator(); | ||
110 | while ( it.current() ) | ||
111 | { | ||
112 | if ( !it.current()->isEmpty() ) nonEmpty++; | ||
113 | ++it; | ||
114 | } | ||
115 | return nonEmpty; | ||
116 | } | ||
117 | |||
118 | |||
119 | OPcmciaSocket* OPcmciaSystem::socket( unsigned int number ) | ||
120 | { | ||
121 | return _interfaces.at( number ); | ||
106 | } | 122 | } |
107 | 123 | ||
108 | 124 | ||
109 | OPcmciaSystem* OPcmciaSystem::instance() | 125 | OPcmciaSystem* OPcmciaSystem::instance() |
110 | { | 126 | { |
111 | if ( !_instance ) _instance = new OPcmciaSystem(); | 127 | if ( !_instance ) _instance = new OPcmciaSystem(); |
112 | return _instance; | 128 | return _instance; |
113 | } | 129 | } |
114 | 130 | ||
115 | 131 | ||
116 | OPcmciaSystem::CardIterator OPcmciaSystem::iterator() const | 132 | OPcmciaSystem::CardIterator OPcmciaSystem::iterator() const |
117 | { | 133 | { |
118 | return OPcmciaSystem::CardIterator( _interfaces ); | 134 | return OPcmciaSystem::CardIterator( _interfaces ); |
119 | } | 135 | } |
120 | 136 | ||
121 | 137 | ||
122 | /*====================================================================================== | 138 | /*====================================================================================== |
123 | * OPcmciaCard | 139 | * OPcmciaSocket |
124 | *======================================================================================*/ | 140 | *======================================================================================*/ |
125 | 141 | ||
126 | OPcmciaCard::OPcmciaCard( QObject* parent, const char* name ) | 142 | OPcmciaSocket::OPcmciaSocket( int socket, QObject* parent, const char* name ) |
127 | :QObject( parent, name ) | 143 | :QObject( parent, name ), _socket( socket ) |
128 | { | 144 | { |
129 | odebug << "OPcmciaCard::OPcmciaCard()" << oendl; | 145 | odebug << "OPcmciaSocket::OPcmciaSocket()" << oendl; |
130 | init(); | 146 | init(); |
131 | } | 147 | } |
132 | 148 | ||
133 | 149 | ||
134 | OPcmciaCard::~OPcmciaCard() | 150 | OPcmciaSocket::~OPcmciaSocket() |
151 | { | ||
152 | } | ||
153 | |||
154 | |||
155 | /* internal */ void OPcmciaSocket::init() | ||
156 | { | ||
157 | } | ||
158 | |||
159 | /* internal */ bool OPcmciaSocket::command( const QString& cmd ) | ||
160 | { | ||
161 | QString cmdline = QString().sprintf( "cardctl %s %d &", (const char*) cmd, _socket ); | ||
162 | ::system( (const char*) cmdline ); | ||
163 | } | ||
164 | |||
165 | int OPcmciaSocket::number() const | ||
166 | { | ||
167 | return _socket; | ||
168 | } | ||
169 | |||
170 | |||
171 | QString OPcmciaSocket::identity() const | ||
135 | { | 172 | { |
173 | return ( strcmp( name(), "empty" ) == 0 ) ? "<Empty Socket>" : name(); | ||
136 | } | 174 | } |
137 | 175 | ||
138 | 176 | ||
139 | void OPcmciaCard::init() | 177 | bool OPcmciaSocket::isEmpty() const |
140 | { | 178 | { |
179 | return ( strcmp( name(), "empty" ) == 0 ); | ||
141 | } | 180 | } |
142 | 181 | ||
143 | 182 | ||
183 | bool OPcmciaSocket::isSuspended() const | ||
184 | { | ||
185 | } | ||
186 | |||
187 | bool OPcmciaSocket::eject() | ||
188 | { | ||
189 | return command( "eject" ); | ||
190 | } | ||
191 | |||
192 | bool OPcmciaSocket::insert() | ||
193 | { | ||
194 | return command( "insert" ); | ||
195 | } | ||
196 | |||
197 | bool OPcmciaSocket::suspend() | ||
198 | { | ||
199 | return command( "suspend" ); | ||
200 | } | ||
201 | |||
202 | bool OPcmciaSocket::resume() | ||
203 | { | ||
204 | return command( "resume "); | ||
205 | } | ||