summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZack Rusin <zack@kde.org>2003-11-25 15:30:03 +0000
committerZack Rusin <zack@kde.org>2003-11-25 15:30:03 +0000
commit6d9f72b9e651d90fcbd191b43b5e91ba7bd63789 (patch)
tree0cf6c6c4c660cd3d61d5d3e642a66d981011f44e
parent27f6dca9ce4680dbbe8dc20a862f5ad63b709609 (diff)
Adding DBusServer wrapper. Switching some thingies, looking pretty and
being cool... Anyway, we're done at a very basic level. I have to go back to something else now, but i'll try to commit an example sometime soon.
-rw-r--r--ChangeLog10
-rw-r--r--qt/Makefile.am5
-rw-r--r--qt/connection.cpp16
-rw-r--r--qt/connection.h1
-rw-r--r--qt/integrator.cpp44
-rw-r--r--qt/integrator.h9
-rw-r--r--qt/server.cpp85
-rw-r--r--qt/server.h57
8 files changed, 215 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 9947af20..4ce96840 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2003-11-25 Zack Rusin <zack@kde.org>
+
+ * qt/integrator.h, qt/integrator.cpp: Adding handling of DBusServer,
+
+ * qt/server.h, qt/server.cpp, qt/Makefile.am: Adding DBusServer
+ wrappers,
+
+ * qt/connection.h, qt/connection.cpp: Adjusting to changes in
+ the Integrator and to better fit with the server,
+
2003-11-24 Zack Rusin <zack@kde.org>
* qt/connection.h, qt/connection.cpp: removing initDbus method since
diff --git a/qt/Makefile.am b/qt/Makefile.am
index 168920bf..80d0a9b4 100644
--- a/qt/Makefile.am
+++ b/qt/Makefile.am
@@ -5,11 +5,12 @@ dbusincludedir=$(includedir)/dbus-1.0/dbus
lib_LTLIBRARIES=libdbus-qt-1.la
dbusinclude_HEADERS= \
- dbus-qt.h message.h connection.h
+ dbus-qt.h message.h connection.h \
+ server.h
libdbus_qt_1_la_SOURCES = \
dbus-qthread.cpp message.cpp connection.cpp \
- integrator.cpp
+ integrator.cpp server.cpp
libdbus_qt_1_la_LIBADD= $(DBUS_QT_LIBS) $(top_builddir)/dbus/libdbus-1.la
libdbus_qt_1_la_LDFLAGS= -version-info 1:0
diff --git a/qt/connection.cpp b/qt/connection.cpp
index 830987d6..72b67ac9 100644
--- a/qt/connection.cpp
+++ b/qt/connection.cpp
@@ -38,9 +38,6 @@ struct Connection::Private
Connection::Connection( const QString& host )
{
d = new Private;
- d->integrator = new Integrator( this );
- connect( d->integrator, SIGNAL(readReady()),
- SLOT(dispatchRead()) );
if ( !host.isEmpty() )
init( host );
@@ -50,6 +47,9 @@ void Connection::init( const QString& host )
{
dbus_error_init( &d->error );
d->connection = dbus_connection_open( host.ascii(), &d->error );
+ d->integrator = new Integrator( d->connection, this );
+ connect( d->integrator, SIGNAL(readReady()),
+ SLOT(dispatchRead()) );
//dbus_connection_allocate_data_slot( &d->connectionSlot );
//dbus_connection_set_data( d->connection, d->connectionSlot, 0, 0 );
}
@@ -90,6 +90,16 @@ DBusConnection* Connection::connection() const
return d->connection;
}
+Connection::Connection( DBusConnection *connection, QObject *parent )
+ : QObject( parent )
+{
+ d = new Private;
+ d->connection = connection;
+ d->integrator = new Integrator( d->connection, this );
+ connect( d->integrator, SIGNAL(readReady()),
+ SLOT(dispatchRead()) );
+}
+
/////////////////////////////////////////////////////////
#include "connection.moc"
diff --git a/qt/connection.h b/qt/connection.h
index c864cd7c..d1bdd015 100644
--- a/qt/connection.h
+++ b/qt/connection.h
@@ -65,6 +65,7 @@ namespace DBusQt {
private:
friend class Internal::Integrator;
DBusConnection* connection() const;
+ Connection( DBusConnection *connection, QObject *parent );
private:
struct Private;
Private *d;
diff --git a/qt/integrator.cpp b/qt/integrator.cpp
index ca793a0a..4d42a76f 100644
--- a/qt/integrator.cpp
+++ b/qt/integrator.cpp
@@ -92,6 +92,13 @@ void dbusWakeupMain( void* )
{
}
+void dbusNewConnection( DBusServer *server,
+ DBusConnection *new_connection,
+ void *data )
+{
+ Integrator *itg = static_cast<Integrator*>( data );
+ itg->handleConnection( new_connection );
+}
/////////////////////////////////////////////////////////////
Timeout::Timeout( QObject *parent, DBusTimeout *t )
@@ -112,26 +119,47 @@ void Timeout::start()
m_timer->start( dbus_timeout_get_interval( m_timeout ) );
}
-Integrator::Integrator( Connection *parent )
- : QObject( parent ), m_parent( parent )
+Integrator::Integrator( DBusConnection *conn, QObject *parent )
+ : QObject( parent ), m_connection( conn )
{
m_timeouts.setAutoDelete( true );
- dbus_connection_set_watch_functions( m_parent->connection(),
+ dbus_connection_set_watch_functions( m_connection,
dbusAddWatch,
dbusRemoveWatch,
dbusToggleWatch,
this, 0 );
- dbus_connection_set_timeout_functions( m_parent->connection(),
+ dbus_connection_set_timeout_functions( m_connection,
dbusAddTimeout,
dbusRemoveTimeout,
dbusToggleTimeout,
this, 0 );
- dbus_connection_set_wakeup_main_function( m_parent->connection(),
+ dbus_connection_set_wakeup_main_function( m_connection,
dbusWakeupMain,
this, 0 );
}
+Integrator::Integrator( DBusServer *server, QObject *parent )
+ : QObject( parent ), m_server( server )
+{
+ m_connection = reinterpret_cast<DBusConnection*>( m_server );
+ m_timeouts.setAutoDelete( true );
+
+ dbus_server_set_watch_functions( m_server,
+ dbusAddWatch,
+ dbusRemoveWatch,
+ dbusToggleWatch,
+ this, 0 );
+ dbus_server_set_timeout_functions( m_server,
+ dbusAddTimeout,
+ dbusRemoveTimeout,
+ dbusToggleTimeout,
+ this, 0 );
+ dbus_server_set_new_connection_function( m_server,
+ dbusNewConnection,
+ this, 0 );
+}
+
void Integrator::slotRead( int fd )
{
Q_UNUSED( fd );
@@ -199,6 +227,12 @@ void Integrator::removeTimeout( DBusTimeout *timeout )
m_timeouts.remove( timeout );
}
+void Integrator::handleConnection( DBusConnection *c )
+{
+ Connection *con = new Connection( c, this );
+ emit newConnection( con );
+}
+
}//end namespace Internal
}//end namespace DBusQt
diff --git a/qt/integrator.h b/qt/integrator.h
index 71336e95..ef17d3d8 100644
--- a/qt/integrator.h
+++ b/qt/integrator.h
@@ -60,10 +60,12 @@ namespace DBusQt
{
Q_OBJECT
public:
- Integrator( Connection* parent );
+ Integrator( DBusConnection *connection, QObject *parent );
+ Integrator( DBusServer *server, QObject *parent );
signals:
void readReady();
+ void newConnection( Connection* );
protected slots:
void slotRead( int );
@@ -76,10 +78,13 @@ namespace DBusQt
void addTimeout( DBusTimeout* );
void removeTimeout( DBusTimeout* );
+
+ void handleConnection( DBusConnection* );
private:
QIntDict<Watch> m_watches;
QPtrDict<Timeout> m_timeouts;
- Connection* m_parent;
+ DBusConnection *m_connection;
+ DBusServer *m_server;
};
}
}
diff --git a/qt/server.cpp b/qt/server.cpp
new file mode 100644
index 00000000..6db6e1f1
--- /dev/null
+++ b/qt/server.cpp
@@ -0,0 +1,85 @@
+// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
+/* server.h: Qt wrapper for DBusServer
+ *
+ * Copyright (C) 2003 Zack Rusin <zack@kde.org>
+ *
+ * Licensed under the Academic Free License version 1.2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#include "server.h"
+#include "connection.h"
+
+#include "integrator.h"
+using DBusQt::Internal::Integrator;
+
+namespace DBusQt
+{
+
+struct Server::Private {
+ Private() : integrator( 0 ), server( 0 )
+ {}
+
+ Integrator *integrator;
+ DBusServer *server;
+ DBusError error;
+};
+
+Server::Server( const QString& addr, QObject *parent )
+ : QObject( parent )
+{
+ d = new Private;
+
+ if ( !addr.isEmpty() ) {
+ init( addr );
+ }
+}
+
+Server::~Server()
+{
+ delete d;
+}
+
+bool Server::isConnected() const
+{
+ return dbus_server_get_is_connected( d->server );
+}
+
+QString Server::address() const
+{
+ //FIXME: leak?
+ return dbus_server_get_address( d->server );
+}
+
+void Server::listen( const QString& addr )
+{
+ if ( !d->server ) {
+ init( addr );
+ }
+}
+
+void Server::init( const QString& addr )
+{
+ d->server = dbus_server_listen( addr.ascii(), &d->error );
+ d->integrator = new Integrator( d->server, this );
+ connect( d->integrator, SIGNAL(newConnection(Connection*)),
+ SIGNAL(newConnection(Connection*)) );
+}
+
+}
+
+
+#include "server.moc"
diff --git a/qt/server.h b/qt/server.h
new file mode 100644
index 00000000..5806d662
--- /dev/null
+++ b/qt/server.h
@@ -0,0 +1,57 @@
+// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
+/* server.h: Qt wrapper for DBusServer
+ *
+ * Copyright (C) 2003 Zack Rusin <zack@kde.org>
+ *
+ * Licensed under the Academic Free License version 1.2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef DBUS_QT_SERVER_H
+#define DBUS_QT_SERVER_H
+
+#include <qobject.h>
+
+#include "dbus/dbus.h"
+
+namespace DBusQt
+{
+ class Connection;
+ class Server : public QObject
+ {
+ Q_OBJECT
+ public:
+ Server( const QString& addr = QString::null, QObject *parent=0 );
+ ~Server();
+
+ bool isConnected() const;
+ QString address() const;
+
+ public slots:
+ void listen( const QString& addr );
+ void disconnect();
+ signals:
+ void newConnection( Connection* );
+
+ private:
+ void init( const QString& addr );
+ private:
+ struct Private;
+ Private *d;
+ };
+}
+
+#endif