author | mickeyl <mickeyl> | 2005-05-21 15:42:44 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-05-21 15:42:44 (UTC) |
commit | c5cb180e37514584fd0015d7713fe07c041f3815 (patch) (unidiff) | |
tree | f7fa392e38ca7dd213a6078996695350e772741e | |
parent | 81a650dc44d3be986cbf8f60e7c7b21ef76d1b94 (diff) | |
download | opie-c5cb180e37514584fd0015d7713fe07c041f3815.zip opie-c5cb180e37514584fd0015d7713fe07c041f3815.tar.gz opie-c5cb180e37514584fd0015d7713fe07c041f3815.tar.bz2 |
change OPcmciaCard to OPcmciaSocket, it now resembles a socket rather than a card
-rw-r--r-- | libopie2/opiecore/linux/opcmciasystem.cpp | 92 | ||||
-rw-r--r-- | libopie2/opiecore/linux/opcmciasystem.h | 74 |
2 files changed, 135 insertions, 31 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 | |||
@@ -38,12 +38,13 @@ using namespace Opie::Core; | |||
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 |
@@ -74,20 +75,22 @@ void OPcmciaSystem::synchronize() | |||
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 | } |
@@ -97,15 +100,28 @@ void OPcmciaSystem::synchronize() | |||
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(); |
@@ -117,27 +133,73 @@ 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 | } | ||
diff --git a/libopie2/opiecore/linux/opcmciasystem.h b/libopie2/opiecore/linux/opcmciasystem.h index 694bf16..4b445aa 100644 --- a/libopie2/opiecore/linux/opcmciasystem.h +++ b/libopie2/opiecore/linux/opcmciasystem.h | |||
@@ -28,19 +28,18 @@ | |||
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 <qdict.h> | 34 | #include <qlist.h> |
35 | #include <qmap.h> | ||
36 | 35 | ||
37 | namespace Opie { | 36 | namespace Opie { |
38 | namespace Core { | 37 | namespace Core { |
39 | 38 | ||
40 | class OPcmciaCard; | 39 | class OPcmciaSocket; |
41 | 40 | ||
42 | /*====================================================================================== | 41 | /*====================================================================================== |
43 | * OPcmciaSystem | 42 | * OPcmciaSystem |
44 | *======================================================================================*/ | 43 | *======================================================================================*/ |
45 | 44 | ||
46 | /** | 45 | /** |
@@ -52,74 +51,117 @@ class OPcmciaCard; | |||
52 | */ | 51 | */ |
53 | class OPcmciaSystem : public QObject | 52 | class OPcmciaSystem : public QObject |
54 | { | 53 | { |
55 | Q_OBJECT | 54 | Q_OBJECT |
56 | 55 | ||
57 | public: | 56 | public: |
58 | typedef QDict<OPcmciaCard> CardMap; | 57 | typedef QList<OPcmciaSocket> CardList; |
59 | typedef QDictIterator<OPcmciaCard> CardIterator; | 58 | typedef QListIterator<OPcmciaSocket> CardIterator; |
60 | 59 | ||
61 | public: | 60 | public: |
62 | /** | 61 | /** |
63 | * @returns the number of available interfaces | 62 | * @returns the number of available sockets |
64 | */ | 63 | */ |
65 | int count() const; | 64 | int count() const; |
66 | /** | 65 | /** |
66 | * @returns the number of populated sockets | ||
67 | */ | ||
68 | int cardCount() const; | ||
69 | /** | ||
67 | * @returns a pointer to the (one and only) @ref OSystem instance. | 70 | * @returns a pointer to the (one and only) @ref OSystem instance. |
68 | */ | 71 | */ |
69 | static OPcmciaSystem* instance(); | 72 | static OPcmciaSystem* instance(); |
70 | /** | 73 | /** |
71 | * @returns an iterator usable for iterating through all sound cards. | 74 | * @returns an iterator usable for iterating through all sound cards. |
72 | */ | 75 | */ |
73 | CardIterator iterator() const; | 76 | CardIterator iterator() const; |
74 | /** | 77 | /** |
75 | * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found | 78 | * @returns a pointer to the @ref OPcmciaSocket object correspinding to socket number n, or 0, if not found |
76 | * @see OAudioInterface | 79 | * @see OPcmciaSocket |
77 | */ | 80 | */ |
78 | OPcmciaCard* card( const QString& interface ) const; | 81 | OPcmciaSocket* socket( unsigned int number ); |
79 | /** | 82 | /** |
80 | * @internal Rebuild the internal interface database | 83 | * @internal Rebuild the internal database |
81 | * @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, |
82 | * e.g. after issuing a cardctl insert | 85 | * e.g. after issuing a cardctl insert |
83 | */ | 86 | */ |
84 | void synchronize(); | 87 | void synchronize(); |
85 | 88 | ||
86 | protected: | 89 | protected: |
87 | OPcmciaSystem(); | 90 | OPcmciaSystem(); |
88 | 91 | ||
89 | private: | 92 | private: |
90 | static OPcmciaSystem* _instance; | 93 | static OPcmciaSystem* _instance; |
91 | CardMap _interfaces; | 94 | CardList _interfaces; |
92 | class Private; | 95 | class Private; |
93 | Private *d; | 96 | Private *d; |
94 | }; | 97 | }; |
95 | 98 | ||
96 | 99 | ||
97 | /*====================================================================================== | 100 | /*====================================================================================== |
98 | * OPcmciaCard | 101 | * OPcmciaSocket |
99 | *======================================================================================*/ | 102 | *======================================================================================*/ |
100 | 103 | ||
101 | class OPcmciaCard : public QObject | 104 | class OPcmciaSocket : public QObject |
102 | { | 105 | { |
103 | Q_OBJECT | 106 | Q_OBJECT |
104 | 107 | ||
105 | public: | 108 | public: |
106 | /** | 109 | /** |
107 | * Constructor. Normally you don't create @ref OPcmciaCard objects yourself, | 110 | * Constructor. Normally you don't create @ref OPcmciaSocket objects yourself, |
108 | * but access them via @ref OPcmciaSystem::card(). | 111 | * but access them via @ref OPcmciaSystem::card(). |
109 | */ | 112 | */ |
110 | OPcmciaCard( QObject* parent, const char* name ); | 113 | OPcmciaSocket( int socket, QObject* parent, const char* name ); |
111 | /** | 114 | /** |
112 | * Destructor. | 115 | * Destructor. |
113 | */ | 116 | */ |
114 | virtual ~OPcmciaCard(); | 117 | virtual ~OPcmciaSocket(); |
118 | /** | ||
119 | * @returns the corresponding socket number | ||
120 | */ | ||
121 | int number() const; | ||
122 | /** | ||
123 | * @returns the identification string of the card in this socket, or "<Empty Socket>" | ||
124 | */ | ||
125 | QString identity() const; | ||
126 | /** | ||
127 | * @returns true, if the socket is empty | ||
128 | */ | ||
129 | bool isEmpty() const; | ||
130 | /** | ||
131 | * @returns true, if the socket is suspended | ||
132 | */ | ||
133 | bool isSuspended() const; | ||
134 | /** | ||
135 | * Eject card. @returns true, if operation succeeded | ||
136 | * @note: This operation needs root privileges | ||
137 | */ | ||
138 | bool eject(); | ||
139 | /** | ||
140 | * Insert card. @returns true, if operation succeeded | ||
141 | * @note: This operation needs root privileges | ||
142 | */ | ||
143 | bool insert(); | ||
144 | /** | ||
145 | * Suspend card. @returns true, if operation succeeded | ||
146 | * @note: This operation needs root privileges | ||
147 | */ | ||
148 | bool suspend(); | ||
149 | /** | ||
150 | * Resume card. @returns true, if operation succeeded | ||
151 | * @note: This operation needs root privileges | ||
152 | */ | ||
153 | bool resume(); | ||
115 | 154 | ||
116 | protected: | 155 | protected: |
117 | 156 | ||
118 | private: | 157 | private: |
119 | void init(); | 158 | void init(); |
159 | bool command( const QString& cmd ); | ||
160 | int _socket; | ||
161 | |||
120 | private: | 162 | private: |
121 | class Private; | 163 | class Private; |
122 | Private *d; | 164 | Private *d; |
123 | }; | 165 | }; |
124 | 166 | ||
125 | 167 | ||