Contents of /trunk/kdebase/patches/kdebase-3.5.5-dbus090-2.patch
Parent Directory | Revision Log
Revision 144 -
(show annotations)
(download)
Tue May 8 20:06:05 2007 UTC (17 years, 4 months ago) by niro
File size: 38153 byte(s)
Tue May 8 20:06:05 2007 UTC (17 years, 4 months ago) by niro
File size: 38153 byte(s)
-import
1 | --- kdebase-3.5.5/kioslave/media/configure.in.in.dbus 2006-10-01 19:31:54.000000000 +0200 |
2 | +++ kdebase-3.5.5/kioslave/media/configure.in.in 2006-10-10 19:55:19.000000000 +0200 |
3 | @@ -97,70 +97,6 @@ |
4 | |
5 | AC_SUBST(DBUS_INCS) |
6 | AC_SUBST(DBUS_LIBS) |
7 | - |
8 | -########### Check for DBus-Qt3 bindings |
9 | - |
10 | - AC_MSG_CHECKING(for DBus-Qt3 bindings) |
11 | - |
12 | - dbusqt_inc=NOTFOUND |
13 | - dbusqt_lib=NOTFOUND |
14 | - dbusqt=NOTFOUND |
15 | - |
16 | - search_incs="$kde_includes $kde_extra_includes /usr/include /usr/include/dbus-1.0 /usr/local/include /usr/local/include/dbus-1.0" |
17 | - AC_FIND_FILE(dbus/connection.h, $search_incs, dbusqt_incdir) |
18 | - |
19 | - if test -r $dbusqt_incdir/dbus/connection.h ; then |
20 | - have_qt_patch=0 |
21 | - grep dbus_connection_setup_with_qt_main $dbusqt_incdir/dbus/connection.h \ |
22 | - > /dev/null 2>&1 && have_qt_patch=1 |
23 | - if test $have_qt_patch = 1 ; then |
24 | - DBUSQT_INCS="-I$dbusqt_incdir" |
25 | - dbusqt_inc=FOUND |
26 | - fi |
27 | - fi |
28 | - |
29 | - search_libs="$kde_libraries $kde_extra_libs /usr/lib$kdelibsuff /usr/local/lib$kdelibsuff" |
30 | - AC_FIND_FILE(libdbus-qt-1.so, $search_libs, dbusqt_libdir) |
31 | - |
32 | - if test -r $dbusqt_libdir/libdbus-qt-1.so ; then |
33 | - DBUSQT_LIBS="-L$dbusqt_libdir -ldbus-qt-1" |
34 | - dbusqt_lib=FOUND |
35 | - fi |
36 | - |
37 | - if test $dbusqt_inc != FOUND || test $dbusqt_lib != FOUND ; then |
38 | - |
39 | - search_incs="`pkg-config --cflags dbus-1 |sed 's/-I//g'`" |
40 | - AC_FIND_FILE(dbus/connection.h, $search_incs, dbusqt_incdir) |
41 | - if test -r $dbusqt_incdir/dbus/connection.h ; then |
42 | - have_qt_patch=0 |
43 | - grep dbus_connection_setup_with_qt_main $dbusqt_incdir/dbus/connection.h \ |
44 | - > /dev/null 2>&1 && have_qt_patch=1 |
45 | - if test $have_qt_patch = 1 ; then |
46 | - DBUSQT_INCS="-I$dbusqt_incdir" |
47 | - dbusqt_inc=FOUND |
48 | - fi |
49 | - fi |
50 | - |
51 | - search_libs="`pkg-config --libs dbus-1 --libs-only-L | sed 's/-L//g'`" |
52 | - AC_FIND_FILE(libdbus-qt-1.so, $search_libs, dbusqt_libdir) |
53 | - |
54 | - if test -r $dbusqt_libdir/libdbus-qt-1.so ; then |
55 | - DBUSQT_LIBS="-L$dbusqt_libdir -ldbus-qt-1" |
56 | - dbusqt_lib=FOUND |
57 | - fi |
58 | - |
59 | - fi |
60 | - |
61 | - |
62 | - if test $dbusqt_inc = FOUND && test $dbusqt_lib = FOUND ; then |
63 | - AC_MSG_RESULT(headers $dbusqt_incdir libraries $dbusqt_libdir) |
64 | - dbusqt=FOUND |
65 | - else |
66 | - AC_MSG_RESULT(searched but not found) |
67 | - fi |
68 | - |
69 | - AC_SUBST(DBUSQT_INCS) |
70 | - AC_SUBST(DBUSQT_LIBS) |
71 | fi |
72 | |
73 | ########### Check if media HAL backend sould be compiled |
74 | @@ -168,7 +104,7 @@ |
75 | AC_MSG_CHECKING(if the HAL backend for media:/ should be compiled) |
76 | |
77 | HALBACKEND=no |
78 | -if test "x$hal" = "xFOUND" && test "x$dbus" = "xFOUND" && test "x$dbusqt" = "xFOUND" ; then |
79 | +if test "x$hal" = "xFOUND" && test "x$dbus" = "xFOUND" ; then |
80 | AC_DEFINE_UNQUOTED([COMPILE_HALBACKEND],1, [media HAL backend compilation]) |
81 | HALBACKEND=yes |
82 | AC_SUBST(HALBACKEND) |
83 | --- kdebase-3.5.5/kioslave/media/mediamanager/halbackend.h.dbus 2006-07-22 10:15:45.000000000 +0200 |
84 | +++ kdebase-3.5.5/kioslave/media/mediamanager/halbackend.h 2006-10-10 17:41:42.000000000 +0200 |
85 | @@ -40,7 +40,7 @@ |
86 | /* We acknowledge the the dbus API is unstable */ |
87 | #define DBUS_API_SUBJECT_TO_CHANGE |
88 | /* DBus-Qt bindings */ |
89 | -#include <dbus/connection.h> |
90 | +#include <connection.h> |
91 | /* HAL libraries */ |
92 | #include <libhal.h> |
93 | #include <libhal-storage.h> |
94 | --- /dev/null 2006-10-09 18:32:23.425560750 +0200 |
95 | +++ kdebase-3.5.5/kioslave/media/mediamanager/connection.cpp 2006-10-10 17:41:42.000000000 +0200 |
96 | @@ -0,0 +1,168 @@ |
97 | +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
98 | +/* connection.cpp: Qt wrapper for DBusConnection |
99 | + * |
100 | + * Copyright (C) 2003 Zack Rusin <zack@kde.org> |
101 | + * |
102 | + * Licensed under the Academic Free License version 2.0 |
103 | + * |
104 | + * This program is free software; you can redistribute it and/or modify |
105 | + * it under the terms of the GNU General Public License as published by |
106 | + * the Free Software Foundation; either version 2 of the License, or |
107 | + * (at your option) any later version. |
108 | + * |
109 | + * This program is distributed in the hope that it will be useful, |
110 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
111 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
112 | + * GNU General Public License for more details. |
113 | + * |
114 | + * You should have received a copy of the GNU General Public License |
115 | + * along with this program; if not, write to the Free Software |
116 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
117 | + * |
118 | + */ |
119 | +#include "connection.h" |
120 | + |
121 | +using namespace DBusQt; |
122 | + |
123 | +#include "integrator.h" |
124 | +using Internal::Integrator; |
125 | + |
126 | +struct Connection::Private |
127 | +{ |
128 | + Private( Connection *qq ); |
129 | + void setConnection( DBusConnection *c ); |
130 | + DBusConnection *connection; |
131 | + int connectionSlot; |
132 | + DBusError error; |
133 | + Integrator *integrator; |
134 | + int timeout; |
135 | + Connection *q; |
136 | +}; |
137 | + |
138 | +Connection::Private::Private( Connection *qq ) |
139 | + : connection( 0 ), connectionSlot( 0 ), integrator( 0 ), |
140 | + timeout( -1 ), q( qq ) |
141 | +{ |
142 | + dbus_error_init( &error ); |
143 | +} |
144 | + |
145 | +void Connection::Private::setConnection( DBusConnection *c ) |
146 | +{ |
147 | + if (!c) { |
148 | + qDebug( "error: %s, %s", error.name, error.message ); |
149 | + dbus_error_free( &error ); |
150 | + return; |
151 | + } |
152 | + connection = c; |
153 | + integrator = new Integrator( c, q ); |
154 | + connect( integrator, SIGNAL(readReady()), q, SLOT(dispatchRead()) ); |
155 | +} |
156 | + |
157 | +Connection::Connection( QObject *parent ) |
158 | + : QObject( parent ) |
159 | +{ |
160 | + d = new Private( this ); |
161 | +} |
162 | + |
163 | +Connection::Connection( const QString& host, QObject *parent ) |
164 | + : QObject( parent ) |
165 | +{ |
166 | + d = new Private( this ); |
167 | + |
168 | + if ( !host.isEmpty() ) |
169 | + init( host ); |
170 | +} |
171 | + |
172 | +Connection::Connection( DBusBusType type, QObject* parent ) |
173 | + : QObject( parent ) |
174 | +{ |
175 | + d = new Private( this ); |
176 | + d->setConnection( dbus_bus_get(type, &d->error) ); |
177 | +} |
178 | + |
179 | +void Connection::init( const QString& host ) |
180 | +{ |
181 | + d->setConnection( dbus_connection_open( host.ascii(), &d->error) ); |
182 | + //dbus_connection_allocate_data_slot( &d->connectionSlot ); |
183 | + //dbus_connection_set_data( d->connection, d->connectionSlot, 0, 0 ); |
184 | +} |
185 | + |
186 | +bool Connection::isConnected() const |
187 | +{ |
188 | + return dbus_connection_get_is_connected( d->connection ); |
189 | +} |
190 | + |
191 | +bool Connection::isAuthenticated() const |
192 | +{ |
193 | + return dbus_connection_get_is_authenticated( d->connection ); |
194 | +} |
195 | + |
196 | +void Connection::open( const QString& host ) |
197 | +{ |
198 | + if ( host.isEmpty() ) return; |
199 | + |
200 | + init( host ); |
201 | +} |
202 | + |
203 | +void Connection::close() |
204 | +{ |
205 | + dbus_connection_close( d->connection ); |
206 | +} |
207 | + |
208 | +void Connection::flush() |
209 | +{ |
210 | + dbus_connection_flush( d->connection ); |
211 | +} |
212 | + |
213 | +void Connection::dispatchRead() |
214 | +{ |
215 | + while ( dbus_connection_dispatch( d->connection ) == DBUS_DISPATCH_DATA_REMAINS ) |
216 | + ; |
217 | +} |
218 | + |
219 | +DBusConnection* Connection::connection() const |
220 | +{ |
221 | + return d->connection; |
222 | +} |
223 | + |
224 | +Connection::Connection( DBusConnection *connection, QObject *parent ) |
225 | + : QObject( parent ) |
226 | +{ |
227 | + d = new Private(this); |
228 | + d->setConnection(connection); |
229 | +} |
230 | + |
231 | +void Connection::send( const Message &m ) |
232 | +{ |
233 | + dbus_connection_send(d->connection, m.message(), 0); |
234 | +} |
235 | + |
236 | +void Connection::sendWithReply( const Message& ) |
237 | +{ |
238 | +} |
239 | + |
240 | +Message Connection::sendWithReplyAndBlock( const Message &m ) |
241 | +{ |
242 | + DBusMessage *reply; |
243 | + reply = dbus_connection_send_with_reply_and_block( d->connection, m.message(), d->timeout, &d->error ); |
244 | + if (dbus_error_is_set(&d->error)) { |
245 | + qDebug("error: %s, %s", d->error.name, d->error.message); |
246 | + dbus_error_free(&d->error); |
247 | + } |
248 | + return Message( reply ); |
249 | +} |
250 | + |
251 | +void* Connection::virtual_hook( int, void* ) |
252 | +{ |
253 | +} |
254 | + |
255 | +void Connection::dbus_connection_setup_with_qt_main (DBusConnection *connection) |
256 | +{ |
257 | + d->setConnection( connection ); |
258 | +} |
259 | + |
260 | + |
261 | + |
262 | +///////////////////////////////////////////////////////// |
263 | + |
264 | +#include "connection.moc" |
265 | --- /dev/null 2006-10-09 18:32:23.425560750 +0200 |
266 | +++ kdebase-3.5.5/kioslave/media/mediamanager/connection.h 2006-10-10 17:41:42.000000000 +0200 |
267 | @@ -0,0 +1,86 @@ |
268 | +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
269 | +/* connection.h: Qt wrapper for DBusConnection |
270 | + * |
271 | + * Copyright (C) 2003 Zack Rusin <zack@kde.org> |
272 | + * |
273 | + * Licensed under the Academic Free License version 2.1 |
274 | + * |
275 | + * This program is free software; you can redistribute it and/or modify |
276 | + * it under the terms of the GNU General Public License as published by |
277 | + * the Free Software Foundation; either version 2 of the License, or |
278 | + * (at your option) any later version. |
279 | + * |
280 | + * This program is distributed in the hope that it will be useful, |
281 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
282 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
283 | + * GNU General Public License for more details. |
284 | + * |
285 | + * You should have received a copy of the GNU General Public License |
286 | + * along with this program; if not, write to the Free Software |
287 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
288 | + * |
289 | + */ |
290 | +#ifndef DBUS_QT_CONNECTION_H |
291 | +#define DBUS_QT_CONNECTION_H |
292 | + |
293 | +/* We acknowledge the the dbus API is unstable */ |
294 | +#define DBUS_API_SUBJECT_TO_CHANGE |
295 | + |
296 | +#include "message.h" |
297 | + |
298 | +#include <qobject.h> |
299 | +#include <qstring.h> |
300 | + |
301 | +#include "dbus/dbus.h" |
302 | + |
303 | +namespace DBusQt { |
304 | + namespace Internal { |
305 | + class Integrator; |
306 | + } |
307 | + |
308 | + class Connection : public QObject |
309 | + { |
310 | + Q_OBJECT |
311 | + public: |
312 | + Connection( QObject *parent =0 ); |
313 | + Connection( const QString& host, |
314 | + QObject *parent = 0 ); |
315 | + Connection( DBusBusType type, QObject* parent = 0 ); |
316 | + |
317 | + bool isConnected() const; |
318 | + bool isAuthenticated() const; |
319 | + |
320 | + Message borrowMessage(); |
321 | + Message popMessage(); |
322 | + void stealBorrowMessage( const Message& ); |
323 | + void dbus_connection_setup_with_qt_main (DBusConnection *connection); |
324 | + |
325 | + public slots: |
326 | + void open( const QString& ); |
327 | + void close(); |
328 | + void flush(); |
329 | + void send( const Message& ); |
330 | + void sendWithReply( const Message& ); |
331 | + Message sendWithReplyAndBlock( const Message& ); |
332 | + |
333 | + protected slots: |
334 | + void dispatchRead(); |
335 | + |
336 | + protected: |
337 | + void init( const QString& host ); |
338 | + virtual void *virtual_hook( int id, void *data ); |
339 | + |
340 | + private: |
341 | + friend class Internal::Integrator; |
342 | + DBusConnection *connection() const; |
343 | + Connection( DBusConnection *connection, QObject *parent ); |
344 | + |
345 | + private: |
346 | + struct Private; |
347 | + Private *d; |
348 | + }; |
349 | + |
350 | +} |
351 | + |
352 | + |
353 | +#endif |
354 | --- /dev/null 2006-10-09 18:32:23.425560750 +0200 |
355 | +++ kdebase-3.5.5/kioslave/media/mediamanager/message.h 2006-10-10 17:41:42.000000000 +0200 |
356 | @@ -0,0 +1,132 @@ |
357 | +/* -*- mode: C++; c-file-style: "gnu" -*- */ |
358 | +/* message.h: Qt wrapper for DBusMessage |
359 | + * |
360 | + * Copyright (C) 2003 Zack Rusin <zack@kde.org> |
361 | + * |
362 | + * Licensed under the Academic Free License version 2.1 |
363 | + * |
364 | + * This program is free software; you can redistribute it and/or modify |
365 | + * it under the terms of the GNU General Public License as published by |
366 | + * the Free Software Foundation; either version 2 of the License, or |
367 | + * (at your option) any later version. |
368 | + * |
369 | + * This program is distributed in the hope that it will be useful, |
370 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
371 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
372 | + * GNU General Public License for more details. |
373 | + * |
374 | + * You should have received a copy of the GNU General Public License |
375 | + * along with this program; if not, write to the Free Software |
376 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
377 | + * |
378 | + */ |
379 | +#ifndef DBUS_QT_MESSAGE_H |
380 | +#define DBUS_QT_MESSAGE_H |
381 | + |
382 | +/* We acknowledge the the dbus API is unstable */ |
383 | +#define DBUS_API_SUBJECT_TO_CHANGE |
384 | + |
385 | +#include <qvariant.h> |
386 | +#include <qstring.h> |
387 | +#include <qstringlist.h> |
388 | + |
389 | +#include "dbus/dbus.h" |
390 | + |
391 | +namespace DBusQt { |
392 | + |
393 | + class Message |
394 | + { |
395 | + public: |
396 | + class iterator { |
397 | + public: |
398 | + iterator(); |
399 | + iterator( const iterator& ); |
400 | + iterator( DBusMessage* msg ); |
401 | + ~iterator(); |
402 | + |
403 | + iterator& operator=( const iterator& ); |
404 | + const QVariant& operator*() const; |
405 | + QVariant& operator*(); |
406 | + iterator& operator++(); |
407 | + iterator operator++(int); |
408 | + bool operator==( const iterator& it ); |
409 | + bool operator!=( const iterator& it ); |
410 | + |
411 | + QVariant var() const; |
412 | + protected: |
413 | + QVariant marshallBaseType( DBusMessageIter* i ); |
414 | + void fillVar(); |
415 | + struct IteratorData; |
416 | + IteratorData *d; |
417 | + }; |
418 | + |
419 | + Message( int messageType ); |
420 | + Message( DBusMessage * );//hide this one from the public implementation |
421 | + Message( const QString& service, const QString& path, |
422 | + const QString& interface, const QString& method ); |
423 | + Message( const Message& replayingTo ); |
424 | + Message( const QString& path, const QString& interface, |
425 | + const QString& name ); |
426 | + Message( const Message& replayingTo, const QString& errorName, |
427 | + const QString& errorMessage ); |
428 | + |
429 | + Message operator=( const Message& other ); |
430 | + |
431 | + virtual ~Message(); |
432 | + |
433 | + int type() const; |
434 | + |
435 | + void setPath( const QString& ); |
436 | + QString path() const; |
437 | + |
438 | + void setInterface( const QString& ); |
439 | + QString interface() const; |
440 | + |
441 | + void setMember( const QString& ); |
442 | + QString member() const; |
443 | + |
444 | + QString errorName() const; |
445 | + |
446 | + QString destination() const; |
447 | + |
448 | + bool setSender( const QString& sender ); |
449 | + QString sender() const; |
450 | + |
451 | + QString signature() const; |
452 | + |
453 | + iterator begin() const; |
454 | + iterator end() const; |
455 | + |
456 | + QVariant at( int i ); |
457 | + |
458 | + |
459 | + public: |
460 | + Message& operator<<( bool ); |
461 | + Message& operator<<( Q_INT8 ); |
462 | + Message& operator<<( Q_INT32 ); |
463 | + Message& operator<<( Q_UINT32 ); |
464 | + Message& operator<<( Q_INT64 ); |
465 | + Message& operator<<( Q_UINT64 ); |
466 | + Message& operator<<( double ); |
467 | + Message& operator<<( const QString& ); |
468 | + Message& operator<<( const QVariant& ); |
469 | + //Message& operator<<(); |
470 | + //Message& operator<<(); |
471 | + //Message& operator<<(); |
472 | + //Message& operator<<(); |
473 | + //Message& operator<<(); |
474 | + //Message& operator<<(); |
475 | + //Message& operator<<(); |
476 | + |
477 | + protected: |
478 | + friend class Connection; |
479 | + DBusMessage* message() const; |
480 | + |
481 | + private: |
482 | + struct Private; |
483 | + Private *d; |
484 | + }; |
485 | + |
486 | +} |
487 | + |
488 | +#endif |
489 | --- /dev/null 2006-10-09 18:32:23.425560750 +0200 |
490 | +++ kdebase-3.5.5/kioslave/media/mediamanager/integrator.h 2006-10-10 17:41:42.000000000 +0200 |
491 | @@ -0,0 +1,95 @@ |
492 | +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
493 | +/* integrator.h: integrates D-BUS into Qt event loop |
494 | + * |
495 | + * Copyright (C) 2003 Zack Rusin <zack@kde.org> |
496 | + * |
497 | + * Licensed under the Academic Free License version 2.1 |
498 | + * |
499 | + * This program is free software; you can redistribute it and/or modify |
500 | + * it under the terms of the GNU General Public License as published by |
501 | + * the Free Software Foundation; either version 2 of the License, or |
502 | + * (at your option) any later version. |
503 | + * |
504 | + * This program is distributed in the hope that it will be useful, |
505 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
506 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
507 | + * GNU General Public License for more details. |
508 | + * |
509 | + * You should have received a copy of the GNU General Public License |
510 | + * along with this program; if not, write to the Free Software |
511 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
512 | + * |
513 | + */ |
514 | +#ifndef DBUS_QT_INTEGRATOR_H |
515 | +#define DBUS_QT_INTEGRATOR_H |
516 | + |
517 | +/* We acknowledge the the dbus API is unstable */ |
518 | +#define DBUS_API_SUBJECT_TO_CHANGE |
519 | + |
520 | +#include <qobject.h> |
521 | + |
522 | +#include <qintdict.h> |
523 | +#include <qptrdict.h> |
524 | + |
525 | +#include "dbus/dbus.h" |
526 | + |
527 | +class QTimer; |
528 | + |
529 | +namespace DBusQt |
530 | +{ |
531 | + class Connection; |
532 | + |
533 | + namespace Internal |
534 | + { |
535 | + struct Watch; |
536 | + |
537 | + class Timeout : public QObject |
538 | + { |
539 | + Q_OBJECT |
540 | + public: |
541 | + Timeout( QObject *parent, DBusTimeout *t ); |
542 | + public: |
543 | + void start(); |
544 | + signals: |
545 | + void timeout( DBusTimeout* ); |
546 | + protected slots: |
547 | + void slotTimeout(); |
548 | + private: |
549 | + QTimer *m_timer; |
550 | + DBusTimeout *m_timeout; |
551 | + }; |
552 | + |
553 | + class Integrator : public QObject |
554 | + { |
555 | + Q_OBJECT |
556 | + public: |
557 | + Integrator( DBusConnection *connection, QObject *parent ); |
558 | + Integrator( DBusServer *server, QObject *parent ); |
559 | + |
560 | + signals: |
561 | + void readReady(); |
562 | + void newConnection( Connection* ); |
563 | + |
564 | + protected slots: |
565 | + void slotRead( int ); |
566 | + void slotWrite( int ); |
567 | + void slotTimeout( DBusTimeout *timeout ); |
568 | + |
569 | + public: |
570 | + void addWatch( DBusWatch* ); |
571 | + void removeWatch( DBusWatch* ); |
572 | + |
573 | + void addTimeout( DBusTimeout* ); |
574 | + void removeTimeout( DBusTimeout* ); |
575 | + |
576 | + void handleConnection( DBusConnection* ); |
577 | + private: |
578 | + QIntDict<Watch> m_watches; |
579 | + QPtrDict<Timeout> m_timeouts; |
580 | + DBusConnection *m_connection; |
581 | + DBusServer *m_server; |
582 | + }; |
583 | + } |
584 | +} |
585 | + |
586 | +#endif |
587 | --- kdebase-3.5.5/kioslave/media/mediamanager/Makefile.am.dbus 2005-09-10 10:25:36.000000000 +0200 |
588 | +++ kdebase-3.5.5/kioslave/media/mediamanager/Makefile.am 2006-10-10 17:41:42.000000000 +0200 |
589 | @@ -1,17 +1,22 @@ |
590 | kde_module_LTLIBRARIES = kded_mediamanager.la |
591 | |
592 | if include_media_halbackend |
593 | -HALBACKEND_INCS = $(HAL_INCS) $(DBUS_INCS) $(DBUSQT_INCS) |
594 | +HALBACKEND_INCS = $(HAL_INCS) $(DBUS_INCS) |
595 | endif |
596 | |
597 | METASOURCES = AUTO |
598 | INCLUDES = -I$(srcdir)/../libmediacommon -I../libmediacommon $(HALBACKEND_INCS) $(all_includes) |
599 | |
600 | +DBUSQT3BINDING_LIB = libdbusqt3.la |
601 | +libdbusqt3_la_SOURCES = connection.cpp integrator.cpp message.cpp |
602 | +libdbusqt3_la_LDFLAGS = -avoid-version $(all_libraries) -no-undefined |
603 | +libdbusqt3_la_LIBADD = $(HAL_LIBS) $(DBUS_LIBS) |
604 | + |
605 | if include_media_halbackend |
606 | HALBACKEND_LIB = libhalbackend.la |
607 | libhalbackend_la_SOURCES = halbackend.cpp |
608 | libhalbackend_la_LDFLAGS = -avoid-version $(all_libraries) -no-undefined |
609 | -libhalbackend_la_LIBADD = $(HAL_LIBS) $(DBUS_LIBS) $(DBUSQT_LIBS) |
610 | +libhalbackend_la_LIBADD = $(HAL_LIBS) $(DBUS_LIBS) $(DBUSQT3BINDING_LIB) |
611 | endif |
612 | |
613 | if include_media_linuxcdpolling |
614 | @@ -20,7 +25,7 @@ |
615 | liblinuxcdpolling_la_LDFLAGS = -avoid-version $(all_libraries) -no-undefined |
616 | endif |
617 | |
618 | -noinst_LTLIBRARIES = $(LINUXCDPOLLING_LIB) $(HALBACKEND_LIB) |
619 | +noinst_LTLIBRARIES = $(LINUXCDPOLLING_LIB) $(HALBACKEND_LIB) $(DBUSQT3BINDING_LIB) |
620 | |
621 | kded_mediamanager_la_SOURCES = mediamanager.cpp mediamanager.skel medialist.cpp backendbase.cpp fstabbackend.cpp removablebackend.cpp mediadirnotify.cpp mediadirnotify.skel |
622 | kded_mediamanager_la_LDFLAGS = $(all_libraries) -module -avoid-version |
623 | --- /dev/null 2006-10-09 18:32:23.425560750 +0200 |
624 | +++ kdebase-3.5.5/kioslave/media/mediamanager/message.cpp 2006-10-10 17:41:42.000000000 +0200 |
625 | @@ -0,0 +1,551 @@ |
626 | +/* -*- mode: C++; c-file-style: "gnu" -*- */ |
627 | +/* message.cpp: Qt wrapper for DBusMessage |
628 | + * |
629 | + * Copyright (C) 2003 Zack Rusin <zack@kde.org> |
630 | + * |
631 | + * Licensed under the Academic Free License version 2.0 |
632 | + * |
633 | + * This program is free software; you can redistribute it and/or modify |
634 | + * it under the terms of the GNU General Public License as published by |
635 | + * the Free Software Foundation; either version 2 of the License, or |
636 | + * (at your option) any later version. |
637 | + * |
638 | + * This program is distributed in the hope that it will be useful, |
639 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
640 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
641 | + * GNU General Public License for more details. |
642 | + * |
643 | + * You should have received a copy of the GNU General Public License |
644 | + * along with this program; if not, write to the Free Software |
645 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
646 | + * |
647 | + */ |
648 | +#include "message.h" |
649 | + |
650 | +#include <qmap.h> |
651 | + |
652 | +#include <cstdlib> |
653 | + |
654 | +namespace DBusQt { |
655 | + |
656 | +struct Message::iterator::IteratorData { |
657 | + DBusMessageIter *iter; |
658 | + QVariant var; |
659 | + bool end; |
660 | + DBusMessage *mesg; |
661 | +}; |
662 | + |
663 | +/** |
664 | + * Iterator. |
665 | + */ |
666 | +Message::iterator::iterator() |
667 | +{ |
668 | + d = new IteratorData; |
669 | + d->iter = 0; d->end = true; |
670 | +} |
671 | + |
672 | +/** |
673 | + * Constructs iterator for the message. |
674 | + * @param msg message whose fields we want to iterate |
675 | + */ |
676 | +Message::iterator::iterator( DBusMessage* msg ) |
677 | +{ |
678 | + d = new IteratorData; |
679 | + d->mesg = msg; |
680 | + d->iter = static_cast<DBusMessageIter *>( malloc( sizeof(DBusMessageIter) ) ); |
681 | + dbus_message_iter_init( d->mesg, d->iter ); |
682 | + if ( !d->iter ) { |
683 | + qDebug("No iterator??"); |
684 | + } |
685 | + fillVar(); |
686 | + d->end = false; |
687 | +} |
688 | + |
689 | +/** |
690 | + * Copy constructor for the iterator. |
691 | + * @param itr iterator |
692 | + */ |
693 | +Message::iterator::iterator( const iterator& itr ) |
694 | +{ |
695 | + d = new IteratorData; |
696 | + d->iter = itr.d->iter; |
697 | + d->var = itr.d->var; |
698 | + d->end = itr.d->end; |
699 | +} |
700 | + |
701 | +/** |
702 | + * Destructor. |
703 | + */ |
704 | +Message::iterator::~iterator() |
705 | +{ |
706 | + free( d->iter ); |
707 | + delete d; d=0; |
708 | +} |
709 | + |
710 | +/** |
711 | + * Creates an iterator equal to the @p itr iterator |
712 | + * @param itr other iterator |
713 | + * @return |
714 | + */ |
715 | +Message::iterator& |
716 | +Message::iterator::operator=( const iterator& itr ) |
717 | +{ |
718 | + IteratorData *tmp = new IteratorData; |
719 | + tmp->iter = itr.d->iter; |
720 | + tmp->var = itr.d->var; |
721 | + tmp->end = itr.d->end; |
722 | + delete d; d=tmp; |
723 | + return *this; |
724 | +} |
725 | + |
726 | +/** |
727 | + * Returns the constant QVariant held by the iterator. |
728 | + * @return the constant reference to QVariant held by this iterator |
729 | + */ |
730 | +const QVariant& |
731 | +Message::iterator::operator*() const |
732 | +{ |
733 | + return d->var; |
734 | +} |
735 | + |
736 | +/** |
737 | + * Returns the QVariant held by the iterator. |
738 | + * @return reference to QVariant held by this iterator |
739 | + */ |
740 | +QVariant& |
741 | +Message::iterator::operator*() |
742 | +{ |
743 | + return d->var; |
744 | +} |
745 | + |
746 | +/** |
747 | + * Moves to the next field and return a reference to itself after |
748 | + * incrementing. |
749 | + * @return reference to self after incrementing |
750 | + */ |
751 | +Message::iterator& |
752 | +Message::iterator::operator++() |
753 | +{ |
754 | + if ( d->end ) |
755 | + return *this; |
756 | + |
757 | + if ( dbus_message_iter_next( d->iter ) ) { |
758 | + fillVar(); |
759 | + } else { |
760 | + d->end = true; |
761 | + d->var = QVariant(); |
762 | + } |
763 | + return *this; |
764 | +} |
765 | + |
766 | +/** |
767 | + * Moves to the next field and returns self before incrementing. |
768 | + * @return self before incrementing |
769 | + */ |
770 | +Message::iterator |
771 | +Message::iterator::operator++(int) |
772 | +{ |
773 | + iterator itr( *this ); |
774 | + operator++(); |
775 | + return itr; |
776 | +} |
777 | + |
778 | +/** |
779 | + * Compares this iterator to @p it iterator. |
780 | + * @param it the iterator to which we're comparing this one to |
781 | + * @return true if they're equal, false otherwise |
782 | + */ |
783 | +bool |
784 | +Message::iterator::operator==( const iterator& it ) |
785 | +{ |
786 | + if ( d->end == it.d->end ) { |
787 | + if ( d->end == true ) { |
788 | + return true; |
789 | + } else { |
790 | + return d->var == it.d->var; |
791 | + } |
792 | + } else |
793 | + return false; |
794 | +} |
795 | + |
796 | +/** |
797 | + * Compares two iterators. |
798 | + * @param it The other iterator. |
799 | + * @return true if two iterators are not equal, false |
800 | + * otherwise |
801 | + */ |
802 | +bool |
803 | +Message::iterator::operator!=( const iterator& it ) |
804 | +{ |
805 | + return !operator==( it ); |
806 | +} |
807 | + |
808 | +QVariant Message::iterator::marshallBaseType( DBusMessageIter* i ) |
809 | +{ |
810 | + QVariant ret; |
811 | + switch (dbus_message_iter_get_arg_type(i)) { |
812 | + case DBUS_TYPE_INT32: |
813 | + { |
814 | + dbus_int32_t v; |
815 | + dbus_message_iter_get_basic (i, &v); |
816 | + ret = QVariant( v ); |
817 | + } |
818 | + break; |
819 | + case DBUS_TYPE_UINT32: |
820 | + { |
821 | + dbus_uint32_t v; |
822 | + dbus_message_iter_get_basic (i, &v); |
823 | + ret = QVariant( v ); |
824 | + } |
825 | + break; |
826 | + case DBUS_TYPE_DOUBLE: |
827 | + { |
828 | + double v; |
829 | + dbus_message_iter_get_basic (i, &v); |
830 | + ret = QVariant( v ); |
831 | + } |
832 | + break; |
833 | + case DBUS_TYPE_STRING: |
834 | + { |
835 | + const char *v; |
836 | + dbus_message_iter_get_basic (i, &v); |
837 | + ret = QVariant( v ); |
838 | + } |
839 | + break; |
840 | + default: |
841 | + ret = QVariant(); |
842 | + break; |
843 | + } |
844 | + return ret; |
845 | +} |
846 | + |
847 | +/** |
848 | + * Fills QVariant based on what current DBusMessageIter helds. |
849 | + */ |
850 | +void |
851 | +Message::iterator::fillVar() |
852 | +{ |
853 | + switch ( dbus_message_iter_get_arg_type( d->iter ) ) { |
854 | + case DBUS_TYPE_INT32: |
855 | + case DBUS_TYPE_UINT32: |
856 | + case DBUS_TYPE_DOUBLE: |
857 | + case DBUS_TYPE_STRING: |
858 | + d->var = marshallBaseType( d->iter ); |
859 | + break; |
860 | + case DBUS_TYPE_ARRAY: { |
861 | + switch ( dbus_message_iter_get_element_type( d->iter ) ) { |
862 | + case DBUS_TYPE_STRING: { |
863 | + QStringList tempList; |
864 | + DBusMessageIter sub; |
865 | + dbus_message_iter_recurse (d->iter, &sub); |
866 | + while (dbus_message_iter_get_arg_type (&sub) != DBUS_TYPE_INVALID) |
867 | + { |
868 | + const char *v; |
869 | + dbus_message_iter_get_basic (&sub, &v); |
870 | + tempList.append( QString( v ) ); |
871 | + dbus_message_iter_next (&sub); |
872 | + } |
873 | + d->var = QVariant( tempList ); |
874 | + break; |
875 | + } |
876 | + default: |
877 | + qDebug( "Array of type not implemented" ); |
878 | + d->var = QVariant(); |
879 | + break; |
880 | + } |
881 | + break; |
882 | + } |
883 | +#if 0 |
884 | + /* DICT is gone for now, but expected to be reintroduced, or else |
885 | + * reintroduced as a flag on the introspection data that can |
886 | + * apply to array of struct of two fields |
887 | + */ |
888 | + case DBUS_TYPE_DICT: { |
889 | + qDebug( "Got a hash!" ); |
890 | + QMap<QString, QVariant> tempMap; |
891 | + DBusMessageIter dictIter; |
892 | + dbus_message_iter_init_dict_iterator( d->iter, &dictIter ); |
893 | + do { |
894 | + char *key = dbus_message_iter_get_dict_key( &dictIter ); |
895 | + tempMap[key] = marshallBaseType( &dictIter ); |
896 | + dbus_free( key ); |
897 | + dbus_message_iter_next( &dictIter ); |
898 | + } while( dbus_message_iter_has_next( &dictIter ) ); |
899 | + d->var = QVariant( tempMap ); |
900 | + break; |
901 | + qDebug( "Hash/Dict type not implemented" ); |
902 | + d->var = QVariant(); |
903 | + break; |
904 | + } |
905 | +#endif |
906 | + default: |
907 | + qDebug( "not implemented" ); |
908 | + d->var = QVariant(); |
909 | + break; |
910 | + } |
911 | +} |
912 | + |
913 | +/** |
914 | + * Returns a QVariant help by this iterator. |
915 | + * @return QVariant held by this iterator |
916 | + */ |
917 | +QVariant |
918 | +Message::iterator::var() const |
919 | +{ |
920 | + return d->var; |
921 | +} |
922 | + |
923 | +struct Message::Private { |
924 | + DBusMessage *msg; |
925 | +}; |
926 | + |
927 | +Message::Message( DBusMessage *m ) |
928 | +{ |
929 | + d = new Private; |
930 | + d->msg = m; |
931 | +} |
932 | + |
933 | +/** |
934 | + * |
935 | + */ |
936 | +Message::Message( int messageType ) |
937 | +{ |
938 | + d = new Private; |
939 | + d->msg = dbus_message_new( messageType ); |
940 | +} |
941 | + |
942 | +/** |
943 | + * Constructs a new Message with the given service and name. |
944 | + * @param service service service that the message should be sent to |
945 | + * @param name name of the message |
946 | + */ |
947 | +Message::Message( const QString& service, const QString& path, |
948 | + const QString& interface, const QString& method ) |
949 | +{ |
950 | + d = new Private; |
951 | + d->msg = dbus_message_new_method_call( service.latin1(), path.latin1(), |
952 | + interface.latin1(), method.latin1() ); |
953 | +} |
954 | + |
955 | +/** |
956 | + * Constructs a message that is a reply to some other |
957 | + * message. |
958 | + * @param name the name of the message |
959 | + * @param replayingTo original_message the message which the created |
960 | + * message is a reply to. |
961 | + */ |
962 | +Message::Message( const Message& replayingTo ) |
963 | +{ |
964 | + d = new Private; |
965 | + d->msg = dbus_message_new_method_return( replayingTo.d->msg ); |
966 | +} |
967 | + |
968 | +Message:: Message( const QString& path, const QString& interface, |
969 | + const QString& name ) |
970 | +{ |
971 | + d = new Private; |
972 | + d->msg = dbus_message_new_signal( path.ascii(), interface.ascii(), |
973 | + name.ascii() ); |
974 | +} |
975 | + |
976 | +Message::Message( const Message& replayingTo, const QString& errorName, |
977 | + const QString& errorMessage ) |
978 | +{ |
979 | + d = new Private; |
980 | + d->msg = dbus_message_new_error( replayingTo.d->msg, errorName.utf8(), |
981 | + errorMessage.utf8() ); |
982 | +} |
983 | + |
984 | +Message Message::operator=( const Message& other ) |
985 | +{ |
986 | + //FIXME: ref the other.d->msg instead of copying it? |
987 | +} |
988 | +/** |
989 | + * Destructs message. |
990 | + */ |
991 | +Message::~Message() |
992 | +{ |
993 | + if ( d->msg ) { |
994 | + dbus_message_unref( d->msg ); |
995 | + } |
996 | + delete d; d=0; |
997 | +} |
998 | + |
999 | +int Message::type() const |
1000 | +{ |
1001 | + return dbus_message_get_type( d->msg ); |
1002 | +} |
1003 | + |
1004 | +void Message::setPath( const QString& path ) |
1005 | +{ |
1006 | + dbus_message_set_path( d->msg, path.ascii() ); |
1007 | +} |
1008 | + |
1009 | +QString Message::path() const |
1010 | +{ |
1011 | + return dbus_message_get_path( d->msg ); |
1012 | +} |
1013 | + |
1014 | +void Message::setInterface( const QString& iface ) |
1015 | +{ |
1016 | + dbus_message_set_interface( d->msg, iface.ascii() ); |
1017 | +} |
1018 | + |
1019 | +QString Message::interface() const |
1020 | +{ |
1021 | + return dbus_message_get_interface( d->msg ); |
1022 | +} |
1023 | + |
1024 | +void Message::setMember( const QString& member ) |
1025 | +{ |
1026 | + dbus_message_set_member( d->msg, member.ascii() ); |
1027 | +} |
1028 | + |
1029 | +QString Message::member() const |
1030 | +{ |
1031 | + return dbus_message_get_member( d->msg ); |
1032 | +} |
1033 | + |
1034 | +QString Message::errorName() const |
1035 | +{ |
1036 | + return dbus_message_get_error_name( d->msg ); |
1037 | +} |
1038 | + |
1039 | +QString Message::destination() const |
1040 | +{ |
1041 | + return dbus_message_get_destination( d->msg ); |
1042 | +} |
1043 | + |
1044 | +/** |
1045 | + * Sets the message sender. |
1046 | + * @param sender the sender |
1047 | + * @return false if unsuccessful |
1048 | + */ |
1049 | +bool |
1050 | +Message::setSender( const QString& sender ) |
1051 | +{ |
1052 | + return dbus_message_set_sender( d->msg, sender.latin1() ); |
1053 | +} |
1054 | + |
1055 | +/** |
1056 | + * Returns sender of this message. |
1057 | + * @return sender |
1058 | + */ |
1059 | +QString |
1060 | +Message::sender() const |
1061 | +{ |
1062 | + return dbus_message_get_sender( d->msg ); |
1063 | +} |
1064 | + |
1065 | +QString Message::signature() const |
1066 | +{ |
1067 | + return dbus_message_get_signature( d->msg ); |
1068 | +} |
1069 | + |
1070 | + |
1071 | +/** |
1072 | + * Returns the starting iterator for the fields of this |
1073 | + * message. |
1074 | + * @return starting iterator |
1075 | + */ |
1076 | +Message::iterator |
1077 | +Message::begin() const |
1078 | +{ |
1079 | + return iterator( d->msg ); |
1080 | +} |
1081 | + |
1082 | +/** |
1083 | + * Returns the ending iterator for the fields of this |
1084 | + * message. |
1085 | + * @return ending iterator |
1086 | + */ |
1087 | +Message::iterator |
1088 | +Message::end() const |
1089 | +{ |
1090 | + return iterator(); |
1091 | +} |
1092 | + |
1093 | +/** |
1094 | + * Returns the field at position @p i |
1095 | + * @param i position of the wanted field |
1096 | + * @return QVariant at position @p i or an empty QVariant |
1097 | + */ |
1098 | +QVariant |
1099 | +Message::at( int i ) |
1100 | +{ |
1101 | + iterator itr( d->msg ); |
1102 | + |
1103 | + while ( i-- ) { |
1104 | + if ( itr == end() ) |
1105 | + return QVariant();//nothing there |
1106 | + ++itr; |
1107 | + } |
1108 | + return *itr; |
1109 | +} |
1110 | + |
1111 | +/** |
1112 | + * The underlying DBusMessage of this class. |
1113 | + * @return DBusMessage pointer. |
1114 | + */ |
1115 | +DBusMessage* |
1116 | +Message::message() const |
1117 | +{ |
1118 | + return d->msg; |
1119 | +} |
1120 | + |
1121 | +Message& Message::operator<<( bool b ) |
1122 | +{ |
1123 | + const dbus_bool_t right_size_bool = b; |
1124 | + dbus_message_append_args( d->msg, DBUS_TYPE_BOOLEAN, &right_size_bool, |
1125 | + DBUS_TYPE_INVALID ); |
1126 | +} |
1127 | + |
1128 | +Message& Message::operator<<( Q_INT8 byte ) |
1129 | +{ |
1130 | + dbus_message_append_args( d->msg, DBUS_TYPE_BYTE, &byte, |
1131 | + DBUS_TYPE_INVALID ); |
1132 | +} |
1133 | + |
1134 | +Message& Message::operator<<( Q_INT32 num ) |
1135 | +{ |
1136 | + dbus_message_append_args( d->msg, DBUS_TYPE_INT32, &num, |
1137 | + DBUS_TYPE_INVALID ); |
1138 | +} |
1139 | + |
1140 | +Message& Message::operator<<( Q_UINT32 num ) |
1141 | +{ |
1142 | + dbus_message_append_args( d->msg, DBUS_TYPE_UINT32, &num, |
1143 | + DBUS_TYPE_INVALID ); |
1144 | +} |
1145 | + |
1146 | +Message& Message::operator<<( Q_INT64 num ) |
1147 | +{ |
1148 | + dbus_message_append_args( d->msg, DBUS_TYPE_INT64, &num, |
1149 | + DBUS_TYPE_INVALID ); |
1150 | +} |
1151 | + |
1152 | +Message& Message::operator<<( Q_UINT64 num ) |
1153 | +{ |
1154 | + dbus_message_append_args( d->msg, DBUS_TYPE_UINT64, &num, |
1155 | + DBUS_TYPE_INVALID ); |
1156 | +} |
1157 | + |
1158 | +Message& Message::operator<<( double num ) |
1159 | +{ |
1160 | + dbus_message_append_args( d->msg, DBUS_TYPE_DOUBLE, &num, |
1161 | + DBUS_TYPE_INVALID ); |
1162 | +} |
1163 | + |
1164 | +Message& Message::operator<<( const QString& str ) |
1165 | +{ |
1166 | + const char *u = str.utf8(); |
1167 | + dbus_message_append_args( d->msg, DBUS_TYPE_STRING, &u, |
1168 | + DBUS_TYPE_INVALID ); |
1169 | +} |
1170 | + |
1171 | +Message& Message::operator<<( const QVariant& custom ) |
1172 | +{ |
1173 | + //FIXME: imeplement |
1174 | +} |
1175 | + |
1176 | +} |
1177 | --- /dev/null 2006-10-09 18:32:23.425560750 +0200 |
1178 | +++ kdebase-3.5.5/kioslave/media/mediamanager/integrator.cpp 2006-10-10 17:41:42.000000000 +0200 |
1179 | @@ -0,0 +1,244 @@ |
1180 | +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
1181 | +/* integrator.h: integrates D-BUS into Qt event loop |
1182 | + * |
1183 | + * Copyright (C) 2003 Zack Rusin <zack@kde.org> |
1184 | + * |
1185 | + * Licensed under the Academic Free License version 2.0 |
1186 | + * |
1187 | + * This program is free software; you can redistribute it and/or modify |
1188 | + * it under the terms of the GNU General Public License as published by |
1189 | + * the Free Software Foundation; either version 2 of the License, or |
1190 | + * (at your option) any later version. |
1191 | + * |
1192 | + * This program is distributed in the hope that it will be useful, |
1193 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1194 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1195 | + * GNU General Public License for more details. |
1196 | + * |
1197 | + * You should have received a copy of the GNU General Public License |
1198 | + * along with this program; if not, write to the Free Software |
1199 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
1200 | + * |
1201 | + */ |
1202 | +#include "integrator.h" |
1203 | +#include "connection.h" |
1204 | + |
1205 | +#include <qtimer.h> |
1206 | +#include <qsocketnotifier.h> |
1207 | +#include <qintdict.h> |
1208 | +#include <qptrlist.h> |
1209 | + |
1210 | +namespace DBusQt |
1211 | +{ |
1212 | +namespace Internal { |
1213 | + |
1214 | +struct Watch { |
1215 | + Watch(): readSocket( 0 ), writeSocket( 0 ) { } |
1216 | + |
1217 | + DBusWatch *watch; |
1218 | + QSocketNotifier *readSocket; |
1219 | + QSocketNotifier *writeSocket; |
1220 | +}; |
1221 | + |
1222 | +////////////////////////////////////////////////////////////// |
1223 | +dbus_bool_t dbusAddWatch( DBusWatch *watch, void *data ) |
1224 | +{ |
1225 | + Integrator *con = static_cast<Integrator*>( data ); |
1226 | + con->addWatch( watch ); |
1227 | + return true; |
1228 | +} |
1229 | +void dbusRemoveWatch( DBusWatch *watch, void *data ) |
1230 | +{ |
1231 | + Integrator *con = static_cast<Integrator*>( data ); |
1232 | + con->removeWatch( watch ); |
1233 | +} |
1234 | + |
1235 | +void dbusToggleWatch( DBusWatch *watch, void *data ) |
1236 | +{ |
1237 | + Integrator *itg = static_cast<Integrator*>( data ); |
1238 | + if ( dbus_watch_get_enabled( watch ) ) |
1239 | + itg->addWatch( watch ); |
1240 | + else |
1241 | + itg->removeWatch( watch ); |
1242 | +} |
1243 | + |
1244 | +dbus_bool_t dbusAddTimeout( DBusTimeout *timeout, void *data ) |
1245 | +{ |
1246 | + if ( !dbus_timeout_get_enabled(timeout) ) |
1247 | + return true; |
1248 | + |
1249 | + Integrator *itg = static_cast<Integrator*>( data ); |
1250 | + itg->addTimeout( timeout ); |
1251 | + return true; |
1252 | +} |
1253 | + |
1254 | +void dbusRemoveTimeout( DBusTimeout *timeout, void *data ) |
1255 | +{ |
1256 | + Integrator *itg = static_cast<Integrator*>( data ); |
1257 | + itg->removeTimeout( timeout ); |
1258 | +} |
1259 | + |
1260 | +void dbusToggleTimeout( DBusTimeout *timeout, void *data ) |
1261 | +{ |
1262 | + Integrator *itg = static_cast<Integrator*>( data ); |
1263 | + |
1264 | + if ( dbus_timeout_get_enabled( timeout ) ) |
1265 | + itg->addTimeout( timeout ); |
1266 | + else |
1267 | + itg->removeTimeout( timeout ); |
1268 | +} |
1269 | + |
1270 | +void dbusWakeupMain( void* ) |
1271 | +{ |
1272 | +} |
1273 | + |
1274 | +void dbusNewConnection( DBusServer *server, |
1275 | + DBusConnection *new_connection, |
1276 | + void *data ) |
1277 | +{ |
1278 | + Integrator *itg = static_cast<Integrator*>( data ); |
1279 | + itg->handleConnection( new_connection ); |
1280 | +} |
1281 | +///////////////////////////////////////////////////////////// |
1282 | + |
1283 | +Timeout::Timeout( QObject *parent, DBusTimeout *t ) |
1284 | + : QObject( parent ), m_timeout( t ) |
1285 | +{ |
1286 | + m_timer = new QTimer( this ); |
1287 | + connect( m_timer, SIGNAL(timeout()), |
1288 | + SLOT(slotTimeout()) ); |
1289 | +} |
1290 | + |
1291 | +void Timeout::slotTimeout() |
1292 | +{ |
1293 | + emit timeout( m_timeout ); |
1294 | +} |
1295 | + |
1296 | +void Timeout::start() |
1297 | +{ |
1298 | + m_timer->start( dbus_timeout_get_interval( m_timeout ) ); |
1299 | +} |
1300 | + |
1301 | +Integrator::Integrator( DBusConnection *conn, QObject *parent ) |
1302 | + : QObject( parent ), m_connection( conn ) |
1303 | +{ |
1304 | + m_timeouts.setAutoDelete( true ); |
1305 | + |
1306 | + dbus_connection_set_watch_functions( m_connection, |
1307 | + dbusAddWatch, |
1308 | + dbusRemoveWatch, |
1309 | + dbusToggleWatch, |
1310 | + this, 0 ); |
1311 | + dbus_connection_set_timeout_functions( m_connection, |
1312 | + dbusAddTimeout, |
1313 | + dbusRemoveTimeout, |
1314 | + dbusToggleTimeout, |
1315 | + this, 0 ); |
1316 | + dbus_connection_set_wakeup_main_function( m_connection, |
1317 | + dbusWakeupMain, |
1318 | + this, 0 ); |
1319 | +} |
1320 | + |
1321 | +Integrator::Integrator( DBusServer *server, QObject *parent ) |
1322 | + : QObject( parent ), m_server( server ) |
1323 | +{ |
1324 | + m_connection = reinterpret_cast<DBusConnection*>( m_server ); |
1325 | + m_timeouts.setAutoDelete( true ); |
1326 | + |
1327 | + dbus_server_set_watch_functions( m_server, |
1328 | + dbusAddWatch, |
1329 | + dbusRemoveWatch, |
1330 | + dbusToggleWatch, |
1331 | + this, 0 ); |
1332 | + dbus_server_set_timeout_functions( m_server, |
1333 | + dbusAddTimeout, |
1334 | + dbusRemoveTimeout, |
1335 | + dbusToggleTimeout, |
1336 | + this, 0 ); |
1337 | + dbus_server_set_new_connection_function( m_server, |
1338 | + dbusNewConnection, |
1339 | + this, 0 ); |
1340 | +} |
1341 | + |
1342 | +void Integrator::slotRead( int fd ) |
1343 | +{ |
1344 | + QIntDictIterator<Watch> it( m_watches ); |
1345 | + for ( ; it.current(); ++it ) |
1346 | + dbus_watch_handle ( it.current()->watch, DBUS_WATCH_READABLE ); |
1347 | + |
1348 | + emit readReady(); |
1349 | +} |
1350 | + |
1351 | +void Integrator::slotWrite( int fd ) |
1352 | +{ |
1353 | + QIntDictIterator<Watch> it( m_watches ); |
1354 | + for ( ; it.current(); ++it ) |
1355 | + dbus_watch_handle ( it.current()->watch, DBUS_WATCH_WRITABLE ); |
1356 | +} |
1357 | + |
1358 | +void Integrator::slotTimeout( DBusTimeout *timeout ) |
1359 | +{ |
1360 | + dbus_timeout_handle( timeout ); |
1361 | +} |
1362 | + |
1363 | +void Integrator::addWatch( DBusWatch *watch ) |
1364 | +{ |
1365 | + if ( !dbus_watch_get_enabled( watch ) ) |
1366 | + return; |
1367 | + |
1368 | + Watch *qtwatch = new Watch; |
1369 | + qtwatch->watch = watch; |
1370 | + |
1371 | + int flags = dbus_watch_get_flags( watch ); |
1372 | + int fd = dbus_watch_get_fd( watch ); |
1373 | + |
1374 | + if ( flags & DBUS_WATCH_READABLE ) { |
1375 | + qtwatch->readSocket = new QSocketNotifier( fd, QSocketNotifier::Read, this ); |
1376 | + QObject::connect( qtwatch->readSocket, SIGNAL(activated(int)), SLOT(slotRead(int)) ); |
1377 | + } |
1378 | + |
1379 | + if (flags & DBUS_WATCH_WRITABLE) { |
1380 | + qtwatch->writeSocket = new QSocketNotifier( fd, QSocketNotifier::Write, this ); |
1381 | + QObject::connect( qtwatch->writeSocket, SIGNAL(activated(int)), SLOT(slotWrite(int)) ); |
1382 | + } |
1383 | + |
1384 | + m_watches.insert( fd, qtwatch ); |
1385 | +} |
1386 | + |
1387 | +void Integrator::removeWatch( DBusWatch *watch ) |
1388 | +{ |
1389 | + int key = dbus_watch_get_fd( watch ); |
1390 | + |
1391 | + Watch *qtwatch = m_watches.take( key ); |
1392 | + |
1393 | + if ( qtwatch ) { |
1394 | + delete qtwatch->readSocket; qtwatch->readSocket = 0; |
1395 | + delete qtwatch->writeSocket; qtwatch->writeSocket = 0; |
1396 | + delete qtwatch; |
1397 | + } |
1398 | +} |
1399 | + |
1400 | +void Integrator::addTimeout( DBusTimeout *timeout ) |
1401 | +{ |
1402 | + Timeout *mt = new Timeout( this, timeout ); |
1403 | + m_timeouts.insert( timeout, mt ); |
1404 | + connect( mt, SIGNAL(timeout(DBusTimeout*)), |
1405 | + SLOT(slotTimeout(DBusTimeout*)) ); |
1406 | + mt->start(); |
1407 | +} |
1408 | + |
1409 | +void Integrator::removeTimeout( DBusTimeout *timeout ) |
1410 | +{ |
1411 | + m_timeouts.remove( timeout ); |
1412 | +} |
1413 | + |
1414 | +void Integrator::handleConnection( DBusConnection *c ) |
1415 | +{ |
1416 | + Connection *con = new Connection( c, this ); |
1417 | + emit newConnection( con ); |
1418 | +} |
1419 | + |
1420 | +}//end namespace Internal |
1421 | +}//end namespace DBusQt |
1422 | + |
1423 | +#include "integrator.moc" |