server.cpp
Go to the documentation of this file.
1/*
2 *
3 * D-Bus++ - C++ bindings for D-Bus
4 *
5 * Copyright (C) 2005-2007 Paolo Durante <shackan@gmail.com>
6 *
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library 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 GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <dbus-c++/debug.h>
29#include <dbus-c++/server.h>
30
31#include "internalerror.h"
32#include "server_p.h"
33#include "connection_p.h"
34#include "dispatcher_p.h"
35
36using namespace DBus;
37
39 : server(s)
40{
41}
42
46
47void Server::Private::on_new_conn_cb(DBusServer *server, DBusConnection *conn, void *data)
48{
49 Server *s = static_cast<Server *>(data);
50
51 Connection nc(new Connection::Private(conn, s->_pvt.get()));
52
53 s->_pvt->connections.push_back(nc);
54
55 s->on_new_connection(nc);
56
57 debug_log("incoming connection 0x%08x", conn);
58}
59
60Server::Server(const char *address)
61{
63 DBusServer *server = dbus_server_listen(address, e);
64
65 if (e) throw Error(e);
66
67 debug_log("server 0x%08x listening on %s", server, address);
68
69 _pvt = new Private(server);
70
71 dbus_server_set_new_connection_function(_pvt->server, Private::on_new_conn_cb, this, NULL);
72
74}
75/*
76Server::Server(const Server &s)
77: _pvt(s._pvt)
78{
79 dbus_server_ref(_pvt->server);
80}
81*/
83{
84 dbus_server_unref(_pvt->server);
85}
86
88{
89 debug_log("registering stubs for server %p", _pvt->server);
90
91 Dispatcher *prev = _pvt->dispatcher;
92
93 dbus_server_set_watch_functions(
94 _pvt->server,
98 dispatcher,
99 0
100 );
101
102 dbus_server_set_timeout_functions(
103 _pvt->server,
107 dispatcher,
108 0
109 );
110
111 _pvt->dispatcher = dispatcher;
112
113 return prev;
114}
115
116bool Server::operator == (const Server &s) const
117{
118 return _pvt->server == s._pvt->server;
119}
120
122{
123 return dbus_server_get_is_connected(_pvt->server);
124}
126{
127 dbus_server_disconnect(_pvt->server);
128}
129
RefPtrI< Private > _pvt
Definition server.h:70
Server(const char *address)
Definition server.cpp:60
bool operator==(const Server &) const
Definition server.cpp:116
virtual ~Server()
Definition server.cpp:82
bool listening() const
Definition server.cpp:121
Dispatcher * setup(Dispatcher *)
Definition server.cpp:87
virtual void on_new_connection(Connection &c)=0
void disconnect()
Definition server.cpp:125
DXXAPI Dispatcher * default_dispatcher
DXXAPI LogFunction debug_log
Definition debug.cpp:55
static void on_rem_watch(DBusWatch *watch, void *data)
static dbus_bool_t on_add_timeout(DBusTimeout *timeout, void *data)
static dbus_bool_t on_add_watch(DBusWatch *watch, void *data)
static void on_toggle_timeout(DBusTimeout *timeout, void *data)
static void on_toggle_watch(DBusWatch *watch, void *data)
static void on_rem_timeout(DBusTimeout *timeout, void *data)
Private(DBusServer *)
Definition server.cpp:38
static void on_new_conn_cb(DBusServer *server, DBusConnection *conn, void *data)
Definition server.cpp:47
DBusServer * server
Definition server_p.h:43