00001 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- 00002 /* server.h: Qt wrapper for DBusServer 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 "server.h" 00024 #include "connection.h" 00025 00026 #include "integrator.h" 00027 using DBusQt::Internal::Integrator; 00028 00029 namespace DBusQt 00030 { 00031 00032 struct Server::Private { 00033 Private() : integrator( 0 ), server( 0 ) 00034 {} 00035 00036 Integrator *integrator; 00037 DBusServer *server; 00038 DBusError error; 00039 }; 00040 00041 Server::Server( const QString& addr, QObject *parent ) 00042 : QObject( parent ) 00043 { 00044 d = new Private; 00045 00046 if ( !addr.isEmpty() ) { 00047 init( addr ); 00048 } 00049 } 00050 00051 Server::~Server() 00052 { 00053 delete d; 00054 } 00055 00056 bool Server::isConnected() const 00057 { 00058 return dbus_server_get_is_connected( d->server ); 00059 } 00060 00061 void Server::disconnect() 00062 { 00063 dbus_server_disconnect( d->server ); 00064 } 00065 00066 QString Server::address() const 00067 { 00068 //FIXME: leak? 00069 return dbus_server_get_address( d->server ); 00070 } 00071 00072 void Server::listen( const QString& addr ) 00073 { 00074 if ( !d->server ) { 00075 init( addr ); 00076 } 00077 } 00078 00079 void Server::init( const QString& addr ) 00080 { 00081 d->server = dbus_server_listen( addr.ascii(), &d->error ); 00082 d->integrator = new Integrator( d->server, this ); 00083 connect( d->integrator, SIGNAL(newConnection(Connection*)), 00084 SIGNAL(newConnection(Connection*)) ); 00085 } 00086 00087 } 00088 00089 00090 #include "server.moc"