summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-05-21 20:23:05 (UTC)
committer mickeyl <mickeyl>2005-05-21 20:23:05 (UTC)
commitdb6b46788db3653812f07c3018abc5bfaaa821c3 (patch) (unidiff)
treee159683e96eed09bbc9a886c39c6fd7776fe5f42
parentafb929e7fd04ecdfec2799a5cf9cf298d1af77c6 (diff)
downloadopie-db6b46788db3653812f07c3018abc5bfaaa821c3.zip
opie-db6b46788db3653812f07c3018abc5bfaaa821c3.tar.gz
opie-db6b46788db3653812f07c3018abc5bfaaa821c3.tar.bz2
add more methods to OPcmciaSocket
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/linux/opcmciasystem.cpp15
-rw-r--r--libopie2/opiecore/linux/opcmciasystem.h9
2 files changed, 23 insertions, 1 deletions
diff --git a/libopie2/opiecore/linux/opcmciasystem.cpp b/libopie2/opiecore/linux/opcmciasystem.cpp
index c4b5316..c310b85 100644
--- a/libopie2/opiecore/linux/opcmciasystem.cpp
+++ b/libopie2/opiecore/linux/opcmciasystem.cpp
@@ -1,205 +1,218 @@
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 48
49/*====================================================================================== 49/*======================================================================================
50 * OPcmciaSystem 50 * OPcmciaSystem
51 *======================================================================================*/ 51 *======================================================================================*/
52 52
53OPcmciaSystem* OPcmciaSystem::_instance = 0; 53OPcmciaSystem* OPcmciaSystem::_instance = 0;
54 54
55OPcmciaSystem::OPcmciaSystem() 55OPcmciaSystem::OPcmciaSystem()
56{ 56{
57 qDebug( "OPcmciaSystem::OPcmciaSystem()" ); 57 qDebug( "OPcmciaSystem::OPcmciaSystem()" );
58 synchronize(); 58 synchronize();
59} 59}
60 60
61void OPcmciaSystem::synchronize() 61void OPcmciaSystem::synchronize()
62{ 62{
63 qDebug( "OPcmciaSystem::synchronize()" ); 63 qDebug( "OPcmciaSystem::synchronize()" );
64 _interfaces.clear(); 64 _interfaces.clear();
65 65
66 //FIXME: Use cardmgr subsystem ioctls 66 //FIXME: Use cardmgr subsystem ioctls
67 67
68 QString fileName; 68 QString fileName;
69 if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; } 69 if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; }
70 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"; }
71 else { fileName = "/var/lib/pcmcia/stab"; } 71 else { fileName = "/var/lib/pcmcia/stab"; }
72 QFile cardinfofile( fileName ); 72 QFile cardinfofile( fileName );
73 if ( !cardinfofile.exists() || !cardinfofile.open( IO_ReadOnly ) ) 73 if ( !cardinfofile.exists() || !cardinfofile.open( IO_ReadOnly ) )
74 { 74 {
75 qWarning( "pcmcia info file not found or unaccessible" ); 75 qWarning( "pcmcia info file not found or unaccessible" );
76 return; 76 return;
77 } 77 }
78 QTextStream cardinfo( &cardinfofile ); 78 QTextStream cardinfo( &cardinfofile );
79 while ( !cardinfo.atEnd() ) 79 while ( !cardinfo.atEnd() )
80 { 80 {
81 QString strSocket; 81 QString strSocket;
82 int numSocket; 82 int numSocket;
83 char colon; 83 char colon;
84 QString cardName; 84 QString cardName;
85 cardinfo >> strSocket >> numSocket >> colon; 85 cardinfo >> strSocket >> numSocket >> colon;
86 cardName = cardinfo.readLine().stripWhiteSpace(); 86 cardName = cardinfo.readLine().stripWhiteSpace();
87 qDebug( "strSocket = '%s', numSocket = '%d', colon = '%c', cardName = '%s'", (const char*) strSocket, numSocket, colon, ( const char*) cardName ); 87 qDebug( "strSocket = '%s', numSocket = '%d', colon = '%c', cardName = '%s'", (const char*) strSocket, numSocket, colon, ( const char*) cardName );
88 if ( strSocket == "Socket" && colon == ':' ) 88 if ( strSocket == "Socket" && colon == ':' )
89 { 89 {
90 _interfaces.append( new OPcmciaSocket( numSocket, this, (const char*) cardName ) ); 90 _interfaces.append( new OPcmciaSocket( numSocket, this, (const char*) cardName ) );
91 } 91 }
92 else 92 else
93 { 93 {
94 continue; 94 continue;
95 } 95 }
96 } 96 }
97} 97}
98 98
99 99
100int OPcmciaSystem::count() const 100int OPcmciaSystem::count() const
101{ 101{
102 return _interfaces.count(); 102 return _interfaces.count();
103} 103}
104 104
105 105
106int OPcmciaSystem::cardCount() const 106int OPcmciaSystem::cardCount() const
107{ 107{
108 int nonEmpty = 0; 108 int nonEmpty = 0;
109 OPcmciaSystem::CardIterator it = iterator(); 109 OPcmciaSystem::CardIterator it = iterator();
110 while ( it.current() ) 110 while ( it.current() )
111 { 111 {
112 if ( !it.current()->isEmpty() ) nonEmpty++; 112 if ( !it.current()->isEmpty() ) nonEmpty++;
113 ++it; 113 ++it;
114 } 114 }
115 return nonEmpty; 115 return nonEmpty;
116} 116}
117 117
118 118
119OPcmciaSocket* OPcmciaSystem::socket( unsigned int number ) 119OPcmciaSocket* OPcmciaSystem::socket( unsigned int number )
120{ 120{
121 return _interfaces.at( number ); 121 return _interfaces.at( number );
122} 122}
123 123
124 124
125OPcmciaSystem* OPcmciaSystem::instance() 125OPcmciaSystem* OPcmciaSystem::instance()
126{ 126{
127 if ( !_instance ) _instance = new OPcmciaSystem(); 127 if ( !_instance ) _instance = new OPcmciaSystem();
128 return _instance; 128 return _instance;
129} 129}
130 130
131 131
132OPcmciaSystem::CardIterator OPcmciaSystem::iterator() const 132OPcmciaSystem::CardIterator OPcmciaSystem::iterator() const
133{ 133{
134 return OPcmciaSystem::CardIterator( _interfaces ); 134 return OPcmciaSystem::CardIterator( _interfaces );
135} 135}
136 136
137 137
138/*====================================================================================== 138/*======================================================================================
139 * OPcmciaSocket 139 * OPcmciaSocket
140 *======================================================================================*/ 140 *======================================================================================*/
141 141
142OPcmciaSocket::OPcmciaSocket( int socket, QObject* parent, const char* name ) 142OPcmciaSocket::OPcmciaSocket( int socket, QObject* parent, const char* name )
143 :QObject( parent, name ), _socket( socket ) 143 :QObject( parent, name ), _socket( socket )
144{ 144{
145 odebug << "OPcmciaSocket::OPcmciaSocket()" << oendl; 145 odebug << "OPcmciaSocket::OPcmciaSocket()" << oendl;
146 init(); 146 init();
147} 147}
148 148
149 149
150OPcmciaSocket::~OPcmciaSocket() 150OPcmciaSocket::~OPcmciaSocket()
151{ 151{
152} 152}
153 153
154 154
155/* internal */ void OPcmciaSocket::init() 155/* internal */ void OPcmciaSocket::init()
156{ 156{
157} 157}
158 158
159/* internal */ bool OPcmciaSocket::command( const QString& cmd ) 159/* internal */ bool OPcmciaSocket::command( const QString& cmd )
160{ 160{
161 QString cmdline = QString().sprintf( "cardctl %s %d &", (const char*) cmd, _socket ); 161 QString cmdline = QString().sprintf( "cardctl %s %d &", (const char*) cmd, _socket );
162 ::system( (const char*) cmdline ); 162 ::system( (const char*) cmdline );
163} 163}
164 164
165int OPcmciaSocket::number() const 165int OPcmciaSocket::number() const
166{ 166{
167 return _socket; 167 return _socket;
168} 168}
169 169
170 170
171QString OPcmciaSocket::identity() const 171QString OPcmciaSocket::identity() const
172{ 172{
173 return ( strcmp( name(), "empty" ) == 0 ) ? "<Empty Socket>" : name(); 173 return ( strcmp( name(), "empty" ) == 0 ) ? "<Empty Socket>" : name();
174} 174}
175 175
176 176
177bool OPcmciaSocket::isUnsupported() const
178{
179 return ( strcmp( name(), "unsupported card" ) == 0 );
180}
181
182
177bool OPcmciaSocket::isEmpty() const 183bool OPcmciaSocket::isEmpty() const
178{ 184{
179 return ( strcmp( name(), "empty" ) == 0 ); 185 return ( strcmp( name(), "empty" ) == 0 );
180} 186}
181 187
182 188
183bool OPcmciaSocket::isSuspended() const 189bool OPcmciaSocket::isSuspended() const
184{ 190{
191 //FIXME
192 return false;
185} 193}
186 194
187bool OPcmciaSocket::eject() 195bool OPcmciaSocket::eject()
188{ 196{
189 return command( "eject" ); 197 return command( "eject" );
190} 198}
191 199
192bool OPcmciaSocket::insert() 200bool OPcmciaSocket::insert()
193{ 201{
194 return command( "insert" ); 202 return command( "insert" );
195} 203}
196 204
197bool OPcmciaSocket::suspend() 205bool OPcmciaSocket::suspend()
198{ 206{
199 return command( "suspend" ); 207 return command( "suspend" );
200} 208}
201 209
202bool OPcmciaSocket::resume() 210bool OPcmciaSocket::resume()
203{ 211{
204 return command( "resume "); 212 return command( "resume");
213}
214
215bool OPcmciaSocket::reset()
216{
217 return command( "reset");
205} 218}
diff --git a/libopie2/opiecore/linux/opcmciasystem.h b/libopie2/opiecore/linux/opcmciasystem.h
index 4b445aa..630a434 100644
--- a/libopie2/opiecore/linux/opcmciasystem.h
+++ b/libopie2/opiecore/linux/opcmciasystem.h
@@ -1,171 +1,180 @@
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#ifndef OPCMCIASYSTEM_H 30#ifndef OPCMCIASYSTEM_H
31#define OPCMCIASYSTEM_H 31#define OPCMCIASYSTEM_H
32 32
33#include <qobject.h> 33#include <qobject.h>
34#include <qlist.h> 34#include <qlist.h>
35 35
36namespace Opie { 36namespace Opie {
37namespace Core { 37namespace Core {
38 38
39class OPcmciaSocket; 39class OPcmciaSocket;
40 40
41/*====================================================================================== 41/*======================================================================================
42 * OPcmciaSystem 42 * OPcmciaSystem
43 *======================================================================================*/ 43 *======================================================================================*/
44 44
45/** 45/**
46 * @brief A container class for the linux pcmcia subsystem 46 * @brief A container class for the linux pcmcia subsystem
47 * 47 *
48 * This class provides access to all available pcmcia/cf cards on your device. 48 * This class provides access to all available pcmcia/cf cards on your device.
49 * 49 *
50 * @author Michael 'Mickey' Lauer <mickey@Vanille.de> 50 * @author Michael 'Mickey' Lauer <mickey@Vanille.de>
51 */ 51 */
52class OPcmciaSystem : public QObject 52class OPcmciaSystem : public QObject
53{ 53{
54 Q_OBJECT 54 Q_OBJECT
55 55
56 public: 56 public:
57 typedef QList<OPcmciaSocket> CardList; 57 typedef QList<OPcmciaSocket> CardList;
58 typedef QListIterator<OPcmciaSocket> CardIterator; 58 typedef QListIterator<OPcmciaSocket> CardIterator;
59 59
60 public: 60 public:
61 /** 61 /**
62 * @returns the number of available sockets 62 * @returns the number of available sockets
63 */ 63 */
64 int count() const; 64 int count() const;
65 /** 65 /**
66 * @returns the number of populated sockets 66 * @returns the number of populated sockets
67 */ 67 */
68 int cardCount() const; 68 int cardCount() const;
69 /** 69 /**
70 * @returns a pointer to the (one and only) @ref OSystem instance. 70 * @returns a pointer to the (one and only) @ref OSystem instance.
71 */ 71 */
72 static OPcmciaSystem* instance(); 72 static OPcmciaSystem* instance();
73 /** 73 /**
74 * @returns an iterator usable for iterating through all sound cards. 74 * @returns an iterator usable for iterating through all sound cards.
75 */ 75 */
76 CardIterator iterator() const; 76 CardIterator iterator() const;
77 /** 77 /**
78 * @returns a pointer to the @ref OPcmciaSocket object correspinding to socket number n, or 0, if not found 78 * @returns a pointer to the @ref OPcmciaSocket object correspinding to socket number n, or 0, if not found
79 * @see OPcmciaSocket 79 * @see OPcmciaSocket
80 */ 80 */
81 OPcmciaSocket* socket( unsigned int number ); 81 OPcmciaSocket* socket( unsigned int number );
82 /** 82 /**
83 * @internal Rebuild the internal database 83 * @internal Rebuild the internal database
84 * @note Sometimes it might be useful to call this from client code, 84 * @note Sometimes it might be useful to call this from client code,
85 * e.g. after issuing a cardctl insert 85 * e.g. after issuing a cardctl insert
86 */ 86 */
87 void synchronize(); 87 void synchronize();
88 88
89 protected: 89 protected:
90 OPcmciaSystem(); 90 OPcmciaSystem();
91 91
92 private: 92 private:
93 static OPcmciaSystem* _instance; 93 static OPcmciaSystem* _instance;
94 CardList _interfaces; 94 CardList _interfaces;
95 class Private; 95 class Private;
96 Private *d; 96 Private *d;
97}; 97};
98 98
99 99
100/*====================================================================================== 100/*======================================================================================
101 * OPcmciaSocket 101 * OPcmciaSocket
102 *======================================================================================*/ 102 *======================================================================================*/
103 103
104class OPcmciaSocket : public QObject 104class OPcmciaSocket : public QObject
105{ 105{
106 Q_OBJECT 106 Q_OBJECT
107 107
108 public: 108 public:
109 /** 109 /**
110 * Constructor. Normally you don't create @ref OPcmciaSocket objects yourself, 110 * Constructor. Normally you don't create @ref OPcmciaSocket objects yourself,
111 * but access them via @ref OPcmciaSystem::card(). 111 * but access them via @ref OPcmciaSystem::card().
112 */ 112 */
113 OPcmciaSocket( int socket, QObject* parent, const char* name ); 113 OPcmciaSocket( int socket, QObject* parent, const char* name );
114 /** 114 /**
115 * Destructor. 115 * Destructor.
116 */ 116 */
117 virtual ~OPcmciaSocket(); 117 virtual ~OPcmciaSocket();
118 /** 118 /**
119 * @returns the corresponding socket number 119 * @returns the corresponding socket number
120 */ 120 */
121 int number() const; 121 int number() const;
122 /** 122 /**
123 * @returns the identification string of the card in this socket, or "<Empty Socket>" 123 * @returns the identification string of the card in this socket, or "<Empty Socket>"
124 */ 124 */
125 QString identity() const; 125 QString identity() const;
126 /** 126 /**
127 * @returns true, if the card is unsupported by the cardmgr
128 */
129 bool isUnsupported() const;
130 /**
127 * @returns true, if the socket is empty 131 * @returns true, if the socket is empty
128 */ 132 */
129 bool isEmpty() const; 133 bool isEmpty() const;
130 /** 134 /**
131 * @returns true, if the socket is suspended 135 * @returns true, if the socket is suspended
132 */ 136 */
133 bool isSuspended() const; 137 bool isSuspended() const;
134 /** 138 /**
135 * Eject card. @returns true, if operation succeeded 139 * Eject card. @returns true, if operation succeeded
136 * @note: This operation needs root privileges 140 * @note: This operation needs root privileges
137 */ 141 */
138 bool eject(); 142 bool eject();
139 /** 143 /**
140 * Insert card. @returns true, if operation succeeded 144 * Insert card. @returns true, if operation succeeded
141 * @note: This operation needs root privileges 145 * @note: This operation needs root privileges
142 */ 146 */
143 bool insert(); 147 bool insert();
144 /** 148 /**
145 * Suspend card. @returns true, if operation succeeded 149 * Suspend card. @returns true, if operation succeeded
146 * @note: This operation needs root privileges 150 * @note: This operation needs root privileges
147 */ 151 */
148 bool suspend(); 152 bool suspend();
149 /** 153 /**
150 * Resume card. @returns true, if operation succeeded 154 * Resume card. @returns true, if operation succeeded
151 * @note: This operation needs root privileges 155 * @note: This operation needs root privileges
152 */ 156 */
153 bool resume(); 157 bool resume();
158 /**
159 * Reset card. @returns true, if operation succeeded
160 * @note: This operation needs root privileges
161 */
162 bool reset();
154 163
155 protected: 164 protected:
156 165
157 private: 166 private:
158 void init(); 167 void init();
159 bool command( const QString& cmd ); 168 bool command( const QString& cmd );
160 int _socket; 169 int _socket;
161 170
162 private: 171 private:
163 class Private; 172 class Private;
164 Private *d; 173 Private *d;
165}; 174};
166 175
167 176
168} 177}
169} 178}
170 179
171#endif // OPCMCIASYSTEM_H 180#endif // OPCMCIASYSTEM_H