Seperating integration with D-BUS from Connection to the internal Integrator
[platform/upstream/dbus.git] / qt / connection.cpp
1 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 /* connection.cpp: Qt wrapper for DBusConnection
3  *
4  * Copyright (C) 2003  Zack Rusin <zack@kde.org>
5  *
6  * Licensed under the Academic Free License version 1.2
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 "connection.h"
24
25 using namespace DBusQt;
26
27 #include "integrator.h"
28 using Internal::Integrator;
29
30 struct Connection::Private
31 {
32   DBusConnection *connection;
33   int connectionSlot;
34   DBusError error;
35   Integrator *integrator;
36 };
37
38 Connection::Connection( const QString& host )
39 {
40   d = new Private;
41   d->integrator = new Integrator( this );
42   connect( d->integrator, SIGNAL(readReady()),
43            SLOT(dispatchRead()) );
44
45   initDbus();
46
47   if ( !host.isEmpty() )
48     init( host );
49 }
50
51 void Connection::initDbus()
52 {
53 }
54
55 void Connection::init( const QString& host )
56 {
57   dbus_error_init( &d->error );
58   d->connection = dbus_connection_open( host.ascii(), &d->error );
59   //dbus_connection_allocate_data_slot( &d->connectionSlot );
60   //dbus_connection_set_data( d->connection, d->connectionSlot, 0, 0 );
61   initDbus();
62 }
63
64 bool Connection::isConnected() const
65 {
66 }
67
68 bool Connection::isAuthenticated() const
69 {
70 }
71
72 void Connection::open( const QString& host )
73 {
74   if ( host.isEmpty() ) return;
75
76   init( host );
77 }
78
79 void Connection::close()
80 {
81   dbus_connection_disconnect( d->connection );
82 }
83
84 void Connection::flush()
85 {
86   dbus_connection_flush( d->connection );
87 }
88
89 void Connection::dispatchRead()
90 {
91   while ( dbus_connection_dispatch( d->connection ) == DBUS_DISPATCH_DATA_REMAINS )
92     ;
93 }
94
95 DBusConnection* Connection::connection() const
96 {
97   return d->connection;
98 }
99
100 /////////////////////////////////////////////////////////
101
102 #include "connection.moc"