-rw-r--r-- | x11/ipc/client/ocopclient.cpp | 9 | ||||
-rw-r--r-- | x11/ipc/client/ocopclient.h | 7 | ||||
-rw-r--r-- | x11/ipc/server/ocopserver.cpp | 27 |
3 files changed, 35 insertions, 8 deletions
diff --git a/x11/ipc/client/ocopclient.cpp b/x11/ipc/client/ocopclient.cpp index c1def73..6085481 100644 --- a/x11/ipc/client/ocopclient.cpp +++ b/x11/ipc/client/ocopclient.cpp | |||
@@ -1,40 +1,49 @@ | |||
1 | #include <errno.h> | 1 | #include <errno.h> |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <stdio.h> | 3 | #include <stdio.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <sys/socket.h> | 5 | #include <sys/socket.h> |
6 | #include <sys/types.h> | 6 | #include <sys/types.h> |
7 | #include <sys/un.h> | 7 | #include <sys/un.h> |
8 | 8 | ||
9 | 9 | ||
10 | #include <qfile.h> | 10 | #include <qfile.h> |
11 | #include <qtimer.h> | 11 | #include <qtimer.h> |
12 | 12 | ||
13 | #include "../common/ocoppacket.h" | 13 | #include "../common/ocoppacket.h" |
14 | 14 | ||
15 | #include "ocopclient.h" | 15 | #include "ocopclient.h" |
16 | 16 | ||
17 | OCOPClient* OCOPClient::m_self = 0; | ||
18 | |||
19 | OCOPClient* OCOPClient::self() { | ||
20 | if (!m_self ) { | ||
21 | m_self = new OCOPClient(); | ||
22 | } | ||
23 | return m_self; | ||
24 | } | ||
25 | |||
17 | OCOPClient::OCOPClient( const QString& path, QObject* obj ) | 26 | OCOPClient::OCOPClient( const QString& path, QObject* obj ) |
18 | : QObject( obj ) | 27 | : QObject( obj ) |
19 | { | 28 | { |
20 | m_tries = 0; | 29 | m_tries = 0; |
21 | init(QFile::encodeName(path) ); | 30 | init(QFile::encodeName(path) ); |
22 | } | 31 | } |
23 | OCOPClient::~OCOPClient() { | 32 | OCOPClient::~OCOPClient() { |
24 | delete m_notify; | 33 | delete m_notify; |
25 | close( m_socket ); | 34 | close( m_socket ); |
26 | } | 35 | } |
27 | void OCOPClient::init() { | 36 | void OCOPClient::init() { |
28 | // failed start ther server NOW!!! | 37 | // failed start ther server NOW!!! |
29 | startUP(); | 38 | startUP(); |
30 | QCString str; | 39 | QCString str; |
31 | init(str ); | 40 | init(str ); |
32 | } | 41 | } |
33 | void OCOPClient::init( const QCString& ) { | 42 | void OCOPClient::init( const QCString& ) { |
34 | m_tries++; | 43 | m_tries++; |
35 | struct sockaddr_un unix_adr; | 44 | struct sockaddr_un unix_adr; |
36 | if ( (m_socket = socket(PF_UNIX, SOCK_STREAM, 0) ) < 0 ) { | 45 | if ( (m_socket = socket(PF_UNIX, SOCK_STREAM, 0) ) < 0 ) { |
37 | qWarning("could not socket"); | 46 | qWarning("could not socket"); |
38 | if ( m_tries < 8 ) | 47 | if ( m_tries < 8 ) |
39 | QTimer::singleShot(400, this,SLOT(init() ) ); | 48 | QTimer::singleShot(400, this,SLOT(init() ) ); |
40 | return; | 49 | return; |
diff --git a/x11/ipc/client/ocopclient.h b/x11/ipc/client/ocopclient.h index 53018a5..ee2015a 100644 --- a/x11/ipc/client/ocopclient.h +++ b/x11/ipc/client/ocopclient.h | |||
@@ -1,61 +1,66 @@ | |||
1 | #ifndef OPIE_OCOP_CLIENT_H | 1 | #ifndef OPIE_OCOP_CLIENT_H |
2 | #define OPIE_OCOP_CLIENT_H | 2 | #define OPIE_OCOP_CLIENT_H |
3 | 3 | ||
4 | 4 | ||
5 | #include <qobject.h> | 5 | #include <qobject.h> |
6 | #include <qcstring.h> | 6 | #include <qcstring.h> |
7 | #include <qmap.h> | 7 | #include <qmap.h> |
8 | #include <qsignal.h> | 8 | #include <qsignal.h> |
9 | #include <qstring.h> | 9 | #include <qstring.h> |
10 | #include <qsocketnotifier.h> | 10 | #include <qsocketnotifier.h> |
11 | 11 | ||
12 | 12 | ||
13 | /** | 13 | /** |
14 | * This is the OCOP client | 14 | * This is the OCOP client |
15 | * It currently only supports | 15 | * It currently only supports |
16 | * asking if a Channel is registered, | 16 | * asking if a Channel is registered, |
17 | * calling and receiving calls | 17 | * calling and receiving calls |
18 | */ | 18 | */ |
19 | class OCOPPacket; | 19 | class OCOPPacket; |
20 | class OCOPClient : public QObject{ | 20 | class OCOPClient : public QObject{ |
21 | Q_OBJECT | 21 | Q_OBJECT |
22 | public: | 22 | public: |
23 | 23 | /* | |
24 | * this is the static | ||
25 | * OCopClient | ||
26 | */ | ||
27 | static OCOPClient* self(); | ||
24 | /** | 28 | /** |
25 | * Occasionally I decide to start a Server from here | 29 | * Occasionally I decide to start a Server from here |
26 | */ | 30 | */ |
27 | OCOPClient(const QString& pathToServer = QString::null, QObject* obj = 0l); | 31 | OCOPClient(const QString& pathToServer = QString::null, QObject* obj = 0l); |
28 | ~OCOPClient(); | 32 | ~OCOPClient(); |
29 | 33 | ||
30 | bool isRegistered( const QCString& )const; | 34 | bool isRegistered( const QCString& )const; |
31 | void send( const QCString& chan, const QCString&, const QByteArray& msg ); | 35 | void send( const QCString& chan, const QCString&, const QByteArray& msg ); |
32 | 36 | ||
33 | /** | 37 | /** |
34 | * add a channel and does connect to a signal | 38 | * add a channel and does connect to a signal |
35 | * callback is the object | 39 | * callback is the object |
36 | * slot is the SLOT() | 40 | * slot is the SLOT() |
37 | */ | 41 | */ |
38 | void addChannel( const QCString& channel ); | 42 | void addChannel( const QCString& channel ); |
39 | void delChannel( const QCString& channel ); | 43 | void delChannel( const QCString& channel ); |
40 | 44 | ||
41 | /* make it singleton? */ | 45 | /* make it singleton? */ |
42 | //static OCOPClient* self(); | 46 | //static OCOPClient* self(); |
43 | /* no direct signals due the design */ | 47 | /* no direct signals due the design */ |
44 | signals: | 48 | signals: |
45 | void called(const QCString&, const QCString&, const QByteArray& ); | 49 | void called(const QCString&, const QCString&, const QByteArray& ); |
46 | private slots: | 50 | private slots: |
47 | void init(); | 51 | void init(); |
48 | void init(const QCString& pa); | 52 | void init(const QCString& pa); |
49 | void newData(); | 53 | void newData(); |
50 | private: | 54 | private: |
51 | void startUP(); | 55 | void startUP(); |
52 | OCOPPacket packet()const; | 56 | OCOPPacket packet()const; |
53 | void call( const OCOPPacket& ); | 57 | void call( const OCOPPacket& ); |
54 | 58 | ||
55 | QSocketNotifier* m_notify; | 59 | QSocketNotifier* m_notify; |
56 | int m_socket; | 60 | int m_socket; |
57 | int m_tries; | 61 | int m_tries; |
58 | 62 | ||
63 | static OCOPClient* m_self; | ||
59 | }; | 64 | }; |
60 | 65 | ||
61 | #endif | 66 | #endif |
diff --git a/x11/ipc/server/ocopserver.cpp b/x11/ipc/server/ocopserver.cpp index 421e49c..4940cb8 100644 --- a/x11/ipc/server/ocopserver.cpp +++ b/x11/ipc/server/ocopserver.cpp | |||
@@ -193,78 +193,91 @@ void OCopServer::newOnClient( int fd ) { | |||
193 | OCOPPacket packet( head.type, channel, func, data ); | 193 | OCOPPacket packet( head.type, channel, func, data ); |
194 | dispatch( packet, fd ); | 194 | dispatch( packet, fd ); |
195 | 195 | ||
196 | }else{ | 196 | }else{ |
197 | qWarning("magic does not match"); | 197 | qWarning("magic does not match"); |
198 | qWarning("magic %d", head.magic ); | 198 | qWarning("magic %d", head.magic ); |
199 | } | 199 | } |
200 | } | 200 | } |
201 | void OCopServer::registerClient( int fd ) { | 201 | void OCopServer::registerClient( int fd ) { |
202 | if (m_clients.contains(fd) ) | 202 | if (m_clients.contains(fd) ) |
203 | return; | 203 | return; |
204 | 204 | ||
205 | QSocketNotifier* notify = new QSocketNotifier(fd, QSocketNotifier::Read, this ); | 205 | QSocketNotifier* notify = new QSocketNotifier(fd, QSocketNotifier::Read, this ); |
206 | connect(notify, SIGNAL(activated(int) ), | 206 | connect(notify, SIGNAL(activated(int) ), |
207 | this, SLOT(newOnClient(int) ) ); | 207 | this, SLOT(newOnClient(int) ) ); |
208 | OCOPClient client; | 208 | OCOPClient client; |
209 | client.fd = fd; | 209 | client.fd = fd; |
210 | client.notify = notify; | 210 | client.notify = notify; |
211 | m_clients.insert( client.fd, client ); | 211 | m_clients.insert( client.fd, client ); |
212 | qWarning("clients are up to %d", m_clients.count() ); | 212 | qWarning("clients are up to %d", m_clients.count() ); |
213 | }; | 213 | }; |
214 | void OCopServer::deregisterClient(int fd ) { | 214 | void OCopServer::deregisterClient(int fd ) { |
215 | QMap<int, OCOPClient>::Iterator it = m_clients.find( fd ); | 215 | QMap<int, OCOPClient>::Iterator it = m_clients.find( fd ); |
216 | if (it != m_clients.end() ) { | 216 | if (it != m_clients.end() ) { |
217 | OCOPClient client = (*it); | 217 | OCOPClient client = it.data(); |
218 | delete client.notify; | 218 | delete client.notify; |
219 | m_clients.remove(fd ); | 219 | m_clients.remove(fd ); |
220 | close(fd ); | 220 | close(fd ); |
221 | /* | 221 | /* |
222 | * TIME_ME | 222 | * TIME_ME |
223 | * | 223 | * |
224 | * now delete from all channels | 224 | * now delete from all channels |
225 | * go through all channels | 225 | * go through all channels |
226 | * remove the fd from the list | 226 | * remove the fd from the list |
227 | * if count becomes 0 remove the channel | 227 | * if count becomes 0 remove the channel |
228 | * otherwise replace QArray<int> | 228 | * otherwise replace QArray<int> |
229 | */ | 229 | */ |
230 | QMap<QCString, QValueList<int> >::Iterator it; | 230 | QMap<QCString, QValueList<int> >::Iterator it2; |
231 | for ( it = m_channels.begin(); it != m_channels.end(); ++it ) { | 231 | repeatIt: |
232 | for ( it2 = m_channels.begin(); it2 != m_channels.end(); ++it2 ) { | ||
232 | /* | 233 | /* |
233 | * The channel contains this fd | 234 | * The channel contains this fd |
234 | */ | 235 | */ |
235 | if ( it.data().contains( fd ) ) { | 236 | qWarning("Channel %s", it2.key().data() ); |
236 | QValueList<int> array = it.data(); | 237 | if ( it2.data().contains( fd ) ) { |
238 | qWarning("contains"); | ||
239 | QValueList<int> array = it2.data(); | ||
237 | 240 | ||
238 | /* | 241 | /* |
239 | * remove channel or just replace | 242 | * remove channel or just replace |
240 | */ | 243 | */ |
241 | if ( array.count() == 1 ) { | 244 | if ( array.count() == 1 ) { |
245 | qWarning("Invalidate!"); | ||
242 | /* is the list now invalidatet? */ | 246 | /* is the list now invalidatet? */ |
243 | m_channels.remove( it ); | 247 | m_channels.remove( it2 ); |
248 | /* That is the first go to of my life | ||
249 | * but Iterator remove( Iterator ) | ||
250 | * does not exist | ||
251 | * it2 = --it2; | ||
252 | * does not work reliable too | ||
253 | * so the only way is to reiterate :( | ||
254 | */ | ||
255 | goto repeatIt; | ||
244 | }else{ | 256 | }else{ |
257 | qWarning("removing"); | ||
245 | array.remove( fd ); | 258 | array.remove( fd ); |
246 | it = m_channels.replace( it.key(), array ); | 259 | it2 = m_channels.replace( it2.key(), array ); |
247 | } | 260 | } |
248 | } | 261 | } |
249 | } // off all channels | 262 | } // off all channels |
250 | } | 263 | } |
251 | qWarning("clients are now at %d", m_clients.count() ); | 264 | qWarning("clients are now at %d", m_clients.count() ); |
252 | }; | 265 | }; |
253 | /** | 266 | /** |
254 | * this function will evaluate | 267 | * this function will evaluate |
255 | * the package and then do the appropriate thins | 268 | * the package and then do the appropriate thins |
256 | */ | 269 | */ |
257 | void OCopServer::dispatch( const OCOPPacket& packet, int sourceFD ) { | 270 | void OCopServer::dispatch( const OCOPPacket& packet, int sourceFD ) { |
258 | qWarning("packet.type() == %d", packet.type() ); | 271 | qWarning("packet.type() == %d", packet.type() ); |
259 | switch( packet.type() ) { | 272 | switch( packet.type() ) { |
260 | case OCOPPacket::Register: | 273 | case OCOPPacket::Register: |
261 | registerClient(sourceFD ); | 274 | registerClient(sourceFD ); |
262 | break; | 275 | break; |
263 | case OCOPPacket::Unregister: | 276 | case OCOPPacket::Unregister: |
264 | deregisterClient(sourceFD ); | 277 | deregisterClient(sourceFD ); |
265 | break; | 278 | break; |
266 | case OCOPPacket::Call: | 279 | case OCOPPacket::Call: |
267 | call( packet, sourceFD ); | 280 | call( packet, sourceFD ); |
268 | break; | 281 | break; |
269 | /* not implemented */ | 282 | /* not implemented */ |
270 | case OCOPPacket::Method: | 283 | case OCOPPacket::Method: |