index.html
Main Page
|
modules.html
Modules
|
namespaces.html
Namespace List
|
hierarchy.html
Class Hierarchy
|
annotated.html
Data Structures
|
dirs.html
Directories
|
files.html
File List
|
namespacemembers.html
Namespace Members
|
functions.html
Data Fields
|
pages.html
Related Pages
dir_000003.html
qt
integrator.cpp
00001
// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002
/* integrator.h: integrates D-BUS into Qt event loop
00003
*
00004
* Copyright (C) 2003  Zack Rusin <zack@kde.org>
00005
*
00006
* Licensed under the Academic Free License version 2.0
00007
*
00008
* This program is free software; you can redistribute it and/or modify
00009
* it under the terms of the GNU General Public License as published by
00010
* the Free Software Foundation; either version 2 of the License, or
00011
* (at your option) any later version.
00012
*
00013
* This program is distributed in the hope that it will be useful,
00014
* but WITHOUT ANY WARRANTY; without even the implied warranty of
00015
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016
* GNU General Public License for more details.
00017
*
00018
* You should have received a copy of the GNU General Public License
00019
* along with this program; if not, write to the Free Software
00020
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021
*
00022
*/
00023
#include "integrator.h"
00024
#include "connection.h"
00025
00026
#include <qtimer.h>
00027
#include <qsocketnotifier.h>
00028
#include <qintdict.h>
00029
#include <qptrlist.h>
00030
00031
namespace
DBusQt
00032 {
00033
namespace
Internal {
00034
structDBusQt_1_1Internal_1_1Watch.html
00035
struct
structDBusQt_1_1Internal_1_1Watch.html
Watch
{
structDBusQt_1_1Internal_1_1Watch.html#a0
00036
structDBusQt_1_1Internal_1_1Watch.html#a0
Watch
():
structDBusQt_1_1Internal_1_1Watch.html#o1
readSocket
( 0 ),
structDBusQt_1_1Internal_1_1Watch.html#o2
writeSocket
( 0 ) { }
00037
structDBusQt_1_1Internal_1_1Watch.html#o0
00038
structDBusWatch.html
DBusWatch
*
structDBusQt_1_1Internal_1_1Watch.html#o0
watch
;
structDBusQt_1_1Internal_1_1Watch.html#o1
00039
QSocketNotifier *
structDBusQt_1_1Internal_1_1Watch.html#o1
readSocket
;
structDBusQt_1_1Internal_1_1Watch.html#o2
00040
QSocketNotifier *
structDBusQt_1_1Internal_1_1Watch.html#o2
writeSocket
;
00041 };
00042
namespaceDBusQt_1_1Internal.html#a0
00044
group__DBusTypes.html#ga2
dbus_bool_t
namespaceDBusQt_1_1Internal.html#a0
dbusAddWatch
(
structDBusWatch.html
DBusWatch
*watch,
void
*data )
00045 {
00046
classDBusQt_1_1Internal_1_1Integrator.html
Integrator
*con = static_cast<Integrator*>( data );
00047   con->
classDBusQt_1_1Internal_1_1Integrator.html#a2
addWatch
( watch );
00048
return
true
;
00049 }
namespaceDBusQt_1_1Internal.html#a1
00050
void
namespaceDBusQt_1_1Internal.html#a1
dbusRemoveWatch
(
structDBusWatch.html
DBusWatch
*watch,
void
*data )
00051 {
00052
classDBusQt_1_1Internal_1_1Integrator.html
Integrator
*con = static_cast<Integrator*>( data );
00053   con->
classDBusQt_1_1Internal_1_1Integrator.html#a3
removeWatch
( watch );
00054 }
00055
namespaceDBusQt_1_1Internal.html#a2
00056
void
namespaceDBusQt_1_1Internal.html#a2
dbusToggleWatch
(
structDBusWatch.html
DBusWatch
*watch,
void
*data )
00057 {
00058
classDBusQt_1_1Internal_1_1Integrator.html
Integrator
*itg = static_cast<Integrator*>( data );
00059
if
(
group__DBusWatch.html#ga4
dbus_watch_get_enabled
( watch ) )
00060     itg->
classDBusQt_1_1Internal_1_1Integrator.html#a2
addWatch
( watch );
00061
else
00062     itg->
classDBusQt_1_1Internal_1_1Integrator.html#a3
removeWatch
( watch );
00063 }
00064
namespaceDBusQt_1_1Internal.html#a3
00065
group__DBusTypes.html#ga2
dbus_bool_t
namespaceDBusQt_1_1Internal.html#a3
dbusAddTimeout
(
structDBusTimeout.html
DBusTimeout
*timeout,
void
*data )
00066 {
00067
if
( !
group__DBusTimeout.html#ga4
dbus_timeout_get_enabled
(timeout) )
00068
return
true
;
00069
00070
classDBusQt_1_1Internal_1_1Integrator.html
Integrator
*itg = static_cast<Integrator*>( data );
00071   itg->
classDBusQt_1_1Internal_1_1Integrator.html#a4
addTimeout
( timeout );
00072
return
true
;
00073 }
00074
namespaceDBusQt_1_1Internal.html#a4
00075
void
namespaceDBusQt_1_1Internal.html#a4
dbusRemoveTimeout
(
structDBusTimeout.html
DBusTimeout
*timeout,
void
*data )
00076 {
00077
classDBusQt_1_1Internal_1_1Integrator.html
Integrator
*itg = static_cast<Integrator*>( data );
00078   itg->
classDBusQt_1_1Internal_1_1Integrator.html#a5
removeTimeout
( timeout );
00079 }
00080
namespaceDBusQt_1_1Internal.html#a5
00081
void
namespaceDBusQt_1_1Internal.html#a5
dbusToggleTimeout
(
structDBusTimeout.html
DBusTimeout
*timeout,
void
*data )
00082 {
00083
classDBusQt_1_1Internal_1_1Integrator.html
Integrator
*itg = static_cast<Integrator*>( data );
00084
00085
if
(
group__DBusTimeout.html#ga4
dbus_timeout_get_enabled
( timeout ) )
00086     itg->
classDBusQt_1_1Internal_1_1Integrator.html#a4
addTimeout
( timeout );
00087
else
00088     itg->
classDBusQt_1_1Internal_1_1Integrator.html#a5
removeTimeout
( timeout );
00089 }
00090
namespaceDBusQt_1_1Internal.html#a6
00091
void
namespaceDBusQt_1_1Internal.html#a6
dbusWakeupMain
(
void
* )
00092 {
00093 }
00094
namespaceDBusQt_1_1Internal.html#a7
00095
void
namespaceDBusQt_1_1Internal.html#a7
dbusNewConnection
(
structDBusServer.html
DBusServer
*server,
00096
structDBusConnection.html
DBusConnection
*new_connection,
00097
void
*data )
00098 {
00099
classDBusQt_1_1Internal_1_1Integrator.html
Integrator
*itg = static_cast<Integrator*>( data );
00100   itg->
classDBusQt_1_1Internal_1_1Integrator.html#a6
handleConnection
( new_connection );
00101 }
00103
classDBusQt_1_1Internal_1_1Timeout.html#a0
00104
classDBusQt_1_1Internal_1_1Timeout.html#a0
Timeout::Timeout
( QObject *parent,
structDBusTimeout.html
DBusTimeout
*t )
00105   : QObject( parent ),  m_timeout( t )
00106 {
00107   m_timer =
new
QTimer(
this
);
00108   connect( m_timer,  SIGNAL(timeout()),
00109            SLOT(
classDBusQt_1_1Internal_1_1Timeout.html#j0
slotTimeout
()) );
00110 }
00111
classDBusQt_1_1Internal_1_1Timeout.html#j0
00112
void
classDBusQt_1_1Internal_1_1Timeout.html#j0
Timeout::slotTimeout
()
00113 {
00114   emit timeout( m_timeout );
00115 }
00116
classDBusQt_1_1Internal_1_1Timeout.html#a1
00117
void
classDBusQt_1_1Internal_1_1Timeout.html#a1
Timeout::start
()
00118 {
00119   m_timer->start(
group__DBusTimeout.html#ga0
dbus_timeout_get_interval
( m_timeout ) );
00120 }
00121
classDBusQt_1_1Internal_1_1Integrator.html#a0
00122
classDBusQt_1_1Internal_1_1Integrator.html#a0
Integrator::Integrator
(
structDBusConnection.html
DBusConnection
*conn, QObject *parent )
00123   : QObject( parent ), m_connection( conn )
00124 {
00125   m_timeouts.setAutoDelete(
true
);
00126
00127
group__DBusConnection.html#ga41
dbus_connection_set_watch_functions
( m_connection,
00128
namespaceDBusQt_1_1Internal.html#a0
dbusAddWatch
,
00129
namespaceDBusQt_1_1Internal.html#a1
dbusRemoveWatch
,
00130
namespaceDBusQt_1_1Internal.html#a2
dbusToggleWatch
,
00131
this
, 0 );
00132
group__DBusConnection.html#ga42
dbus_connection_set_timeout_functions
( m_connection,
00133
namespaceDBusQt_1_1Internal.html#a3
dbusAddTimeout
,
00134
namespaceDBusQt_1_1Internal.html#a4
dbusRemoveTimeout
,
00135
namespaceDBusQt_1_1Internal.html#a5
dbusToggleTimeout
,
00136
this
, 0 );
00137
group__DBusConnection.html#ga43
dbus_connection_set_wakeup_main_function
( m_connection,
00138
namespaceDBusQt_1_1Internal.html#a6
dbusWakeupMain
,
00139
this
, 0 );
00140 }
00141
classDBusQt_1_1Internal_1_1Integrator.html#a1
00142
classDBusQt_1_1Internal_1_1Integrator.html#a0
Integrator::Integrator
(
structDBusServer.html
DBusServer
*server, QObject *parent )
00143   : QObject( parent ), m_server( server )
00144 {
00145   m_connection = reinterpret_cast<DBusConnection*>( m_server );
00146   m_timeouts.setAutoDelete(
true
);
00147
00148
group__DBusServer.html#ga10
dbus_server_set_watch_functions
( m_server,
00149
namespaceDBusQt_1_1Internal.html#a0
dbusAddWatch
,
00150
namespaceDBusQt_1_1Internal.html#a1
dbusRemoveWatch
,
00151
namespaceDBusQt_1_1Internal.html#a2
dbusToggleWatch
,
00152
this
, 0 );
00153
group__DBusServer.html#ga11
dbus_server_set_timeout_functions
( m_server,
00154
namespaceDBusQt_1_1Internal.html#a3
dbusAddTimeout
,
00155
namespaceDBusQt_1_1Internal.html#a4
dbusRemoveTimeout
,
00156
namespaceDBusQt_1_1Internal.html#a5
dbusToggleTimeout
,
00157
this
, 0 );
00158
group__DBusServer.html#ga9
dbus_server_set_new_connection_function
( m_server,
00159
namespaceDBusQt_1_1Internal.html#a7
dbusNewConnection
,
00160
this
,  0 );
00161 }
00162
classDBusQt_1_1Internal_1_1Integrator.html#j0
00163
void
classDBusQt_1_1Internal_1_1Integrator.html#j0
Integrator::slotRead
(
int
fd )
00164 {
00165   QIntDictIterator<Watch>       it( m_watches );
00166
for
( ; it.current(); ++it )
00167
group__DBusWatch.html#ga5
dbus_watch_handle
( it.current()->watch, DBUS_WATCH_READABLE );
00168
00169   emit readReady();
00170 }
00171
classDBusQt_1_1Internal_1_1Integrator.html#j1
00172
void
classDBusQt_1_1Internal_1_1Integrator.html#j1
Integrator::slotWrite
(
int
fd )
00173 {
00174   QIntDictIterator<Watch>       it( m_watches );
00175
for
( ; it.current(); ++it )
00176
group__DBusWatch.html#ga5
dbus_watch_handle
( it.current()->watch, DBUS_WATCH_WRITABLE );
00177 }
00178
classDBusQt_1_1Internal_1_1Integrator.html#j2
00179
void
classDBusQt_1_1Internal_1_1Integrator.html#j2
Integrator::slotTimeout
(
structDBusTimeout.html
DBusTimeout
*timeout )
00180 {
00181
group__DBusTimeout.html#ga3
dbus_timeout_handle
( timeout );
00182 }
00183
classDBusQt_1_1Internal_1_1Integrator.html#a2
00184
void
classDBusQt_1_1Internal_1_1Integrator.html#a2
Integrator::addWatch
(
structDBusWatch.html
DBusWatch
*watch )
00185 {
00186
if
( !
group__DBusWatch.html#ga4
dbus_watch_get_enabled
( watch ) )
00187
return
;
00188
00189
structDBusQt_1_1Internal_1_1Watch.html
Watch
*qtwatch =
new
structDBusQt_1_1Internal_1_1Watch.html
Watch
;
00190   qtwatch->
structDBusQt_1_1Internal_1_1Watch.html#o0
watch
= watch;
00191
00192
int
flags =
group__DBusWatch.html#ga1
dbus_watch_get_flags
( watch );
00193
int
fd =
group__DBusWatch.html#ga0
dbus_watch_get_fd
( watch );
00194
00195
if
( flags & DBUS_WATCH_READABLE ) {
00196     qtwatch->
structDBusQt_1_1Internal_1_1Watch.html#o1
readSocket
=
new
QSocketNotifier( fd, QSocketNotifier::Read,
this
);
00197     QObject::connect( qtwatch->
structDBusQt_1_1Internal_1_1Watch.html#o1
readSocket
, SIGNAL(activated(
int
)), SLOT(
classDBusQt_1_1Internal_1_1Integrator.html#j0
slotRead
(
int
)) );
00198   }
00199
00200
if
(flags & DBUS_WATCH_WRITABLE) {
00201     qtwatch->
structDBusQt_1_1Internal_1_1Watch.html#o2
writeSocket
=
new
QSocketNotifier( fd, QSocketNotifier::Write,
this
);
00202     QObject::connect( qtwatch->
structDBusQt_1_1Internal_1_1Watch.html#o2
writeSocket
, SIGNAL(activated(
int
)), SLOT(
classDBusQt_1_1Internal_1_1Integrator.html#j1
slotWrite
(
int
)) );
00203   }
00204
00205   m_watches.insert( fd, qtwatch );
00206 }
00207
classDBusQt_1_1Internal_1_1Integrator.html#a3
00208
void
classDBusQt_1_1Internal_1_1Integrator.html#a3
Integrator::removeWatch
(
structDBusWatch.html
DBusWatch
*watch )
00209 {
00210
int
key =
group__DBusWatch.html#ga0
dbus_watch_get_fd
( watch );
00211
00212
structDBusQt_1_1Internal_1_1Watch.html
Watch
*qtwatch = m_watches.take( key );
00213
00214
if
( qtwatch ) {
00215
delete
qtwatch->
structDBusQt_1_1Internal_1_1Watch.html#o1
readSocket
;  qtwatch->
structDBusQt_1_1Internal_1_1Watch.html#o1
readSocket
= 0;
00216
delete
qtwatch->
structDBusQt_1_1Internal_1_1Watch.html#o2
writeSocket
; qtwatch->
structDBusQt_1_1Internal_1_1Watch.html#o2
writeSocket
= 0;
00217
delete
qtwatch;
00218   }
00219 }
00220
classDBusQt_1_1Internal_1_1Integrator.html#a4
00221
void
classDBusQt_1_1Internal_1_1Integrator.html#a4
Integrator::addTimeout
(
structDBusTimeout.html
DBusTimeout
*timeout )
00222 {
00223
classDBusQt_1_1Internal_1_1Timeout.html
Timeout
*mt =
new
classDBusQt_1_1Internal_1_1Timeout.html
Timeout
(
this
, timeout );
00224   m_timeouts.insert( timeout, mt );
00225   connect( mt, SIGNAL(timeout(
structDBusTimeout.html
DBusTimeout
*)),
00226            SLOT(
classDBusQt_1_1Internal_1_1Integrator.html#j2
slotTimeout
(
structDBusTimeout.html
DBusTimeout
*)) );
00227   mt->
classDBusQt_1_1Internal_1_1Timeout.html#a1
start
();
00228 }
00229
classDBusQt_1_1Internal_1_1Integrator.html#a5
00230
void
classDBusQt_1_1Internal_1_1Integrator.html#a5
Integrator::removeTimeout
(
structDBusTimeout.html
DBusTimeout
*timeout )
00231 {
00232   m_timeouts.remove( timeout );
00233 }
00234
classDBusQt_1_1Internal_1_1Integrator.html#a6
00235
void
classDBusQt_1_1Internal_1_1Integrator.html#a6
Integrator::handleConnection
(
structDBusConnection.html
DBusConnection
*c )
00236 {
00237
classDBusQt_1_1Connection.html
Connection
*con =
new
classDBusQt_1_1Connection.html
Connection
( c,
this
);
00238   emit newConnection( con );
00239 }
00240
00241 }
//end namespace Internal
00242 }
//end namespace DBusQt
00243
00244
#include "integrator.moc"
Generated on Tue Sep 13 01:28:08 2005 for D-BUS by
http://www.doxygen.org/index.html
doxygen
1.4.4
