bring Qt3 library back. Some apps that are not in the KDE trunk are using it.
[platform/upstream/dbus.git] / qt3 / server.cpp
1 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 /* server.h: Qt wrapper for DBusServer
3  *
4  * Copyright (C) 2003  Zack Rusin <zack@kde.org>
5  *
6  * Licensed under the Academic Free License version 2.0
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23 #include "server.h"
24 #include "connection.h"
25
26 #include "integrator.h"
27 using DBusQt::Internal::Integrator;
28
29 namespace DBusQt
30 {
31
32 struct Server::Private {
33   Private() : integrator( 0 ), server( 0 )
34     {}
35
36   Integrator *integrator;
37   DBusServer *server;
38   DBusError error;
39 };
40
41 Server::Server( const QString& addr, QObject *parent )
42   : QObject( parent )
43 {
44   d = new Private;
45
46   if ( !addr.isEmpty() ) {
47     init( addr );
48   }
49 }
50
51 Server::~Server()
52 {
53   delete d;
54 }
55
56 bool Server::isConnected() const
57 {
58   return dbus_server_get_is_connected( d->server );
59 }
60
61 void Server::disconnect()
62 {
63   dbus_server_disconnect( d->server );
64 }
65
66 QString Server::address() const
67 {
68   //FIXME: leak?
69   return dbus_server_get_address( d->server );
70 }
71
72 void Server::listen( const QString& addr )
73 {
74   if ( !d->server ) {
75     init( addr );
76   }
77 }
78
79 void Server::init( const QString& addr )
80 {
81   d->server = dbus_server_listen( addr.ascii(),  &d->error );
82   d->integrator = new Integrator( d->server, this );
83   connect( d->integrator, SIGNAL(newConnection(Connection*)),
84            SIGNAL(newConnection(Connection*)) );
85 }
86
87 }
88
89
90 #include "server.moc"