# DBus-C++

## Desktop Communication Bus System

libdbus-c-- Documentation 0.9.0

- Files
- Data Structures
- Globals
- Main Page

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
36 using namespace DBus;
37
38 Server::Private::Private(DBusServer *s)
39 : server(s)
40{
41}
42
43 Server::Private::~Private()
44{
45}
46
47 void 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
60 Server::Server(const char *address)
61{
62 InternalError e;
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
73 setup(default_dispatcher);
74}
75/*
76 Server::Server(const Server &s)
77: _pvt(s._pvt)
78{
79 dbus_server_ref(_pvt->server);
80}
81*/
82 Server::~Server()
83{
84 dbus_server_unref(_pvt->server);
85}
86
87 Dispatcher *Server::setup(Dispatcher *dispatcher)
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,
95 Dispatcher::Private::on_add_watch,
96 Dispatcher::Private::on_rem_watch,
97 Dispatcher::Private::on_toggle_watch,
98 dispatcher,
99 0
100 );
101
102 dbus_server_set_timeout_functions(
103 _pvt->server,
104 Dispatcher::Private::on_add_timeout,
105 Dispatcher::Private::on_rem_timeout,
106 Dispatcher::Private::on_toggle_timeout,
107 dispatcher,
108 0
109 );
110
111 _pvt->dispatcher = dispatcher;
112
113 return prev;
114}
115
116 bool Server::operator == (const Server &s) const
117{
118 return _pvt->server == s._pvt->server;
119}
120
121 bool Server::listening() const
122{
123 return dbus_server_get_is_connected(_pvt->server);
124}
125 void Server::disconnect()
126{
127 dbus_server_disconnect(_pvt->server);
128}
129
DBus::Connection
Definition connection.h:49
DBus::Dispatcher
Definition dispatcher.h:152
DBus::Error
Definition error.h:40
DBus::Server::_pvt
RefPtrI< Private > _pvt
Definition server.h:70
DBus::Server::Server
Server(const char *address)
Definition server.cpp:60
DBus::Server::operator==
bool operator==(const Server &) const
Definition server.cpp:116
DBus::Server::~Server
virtual ~Server()
Definition server.cpp:82
DBus::Server::listening
bool listening() const
Definition server.cpp:121
DBus::Server::setup
Dispatcher * setup(Dispatcher *)
Definition server.cpp:87
DBus::Server::on_new_connection
virtual void on_new_connection(Connection &c)=0
DBus::Server::disconnect
void disconnect()
Definition server.cpp:125
connection_p.h
debug.h
dispatcher_p.h
internalerror.h
DBus
Definition connection_p.h:42
DBus::default_dispatcher
DXXAPI Dispatcher * default_dispatcher
Definition dispatcher.cpp:36
DBus::debug_log
DXXAPI LogFunction debug_log
Definition debug.cpp:55
server.h
server_p.h
DBus::Connection::Private
Definition connection_p.h:45
DBus::Dispatcher::Private::on_rem_watch
static void on_rem_watch(DBusWatch *watch, void *data)
Definition dispatcher.cpp:115
DBus::Dispatcher::Private::on_add_timeout
static dbus_bool_t on_add_timeout(DBusTimeout *timeout, void *data)
Definition dispatcher.cpp:131
DBus::Dispatcher::Private::on_add_watch
static dbus_bool_t on_add_watch(DBusWatch *watch, void *data)
Definition dispatcher.cpp:104
DBus::Dispatcher::Private::on_toggle_timeout
static void on_toggle_timeout(DBusTimeout *timeout, void *data)
Definition dispatcher.cpp:151
DBus::Dispatcher::Private::on_toggle_watch
static void on_toggle_watch(DBusWatch *watch, void *data)
Definition dispatcher.cpp:124
DBus::Dispatcher::Private::on_rem_timeout
static void on_rem_timeout(DBusTimeout *timeout, void *data)
Definition dispatcher.cpp:142
DBus::InternalError
Definition internalerror.h:40
DBus::Server::Private
Definition server_p.h:42
DBus::Server::Private::Private
Private(DBusServer *)
Definition server.cpp:38
DBus::Server::Private::on_new_conn_cb
static void on_new_conn_cb(DBusServer *server, DBusConnection *conn, void *data)
Definition server.cpp:47
DBus::Server::Private::~Private
~Private()
Definition server.cpp:43
DBus::Server::Private::server
DBusServer * server
Definition server_p.h:43