summaryrefslogtreecommitdiff
path: root/gio/src/dbusserver.hg
blob: c7dc24f0869ebe42908e4c17f8a86d816847b1ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* Copyright (C) 2010 The giomm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <glibmm/object.h>
#include <giomm/dbusconnection.h>
#include <giomm/dbusauthobserver.h>
#include <giomm/initable.h>

_DEFS(giomm,gio)
_PINCLUDE(glibmm/private/object_p.h)

namespace Gio
{

namespace DBus
{

_GMMPROC_EXTRA_NAMESPACE(DBus)

//TODO: Add example from the C API in class docs.
/** This is a helper for listening to and accepting D-Bus connections.
 * Since Server derives from Initiable, its constructors can
 * throw an exception if construction fails.
 *
 * This can be used to create a new D-Bus server, allowing two
 * peers to use the D-Bus protocol for their own specialized communication.
 * A server instance provided in this way will not perform message routing or
 * implement the org.freedesktop.DBus interface.
 *
 * To just export an object on a well-known name on a message bus, such as the
 * session or system bus, you should instead use Gio::DBus::own_name().
 *
 * @newin{2,28}
 * @ingroup DBus
 */
class GIOMM_API Server : public Glib::Object, public Initable
{
  _CLASS_GOBJECT(Server, GDBusServer, G_DBUS_SERVER, Glib::Object, GObject, , , GIOMM_API)
  _IMPLEMENTS_INTERFACE(Initable)

public:
  _WRAP_ENUM(Flags, GDBusServerFlags, gtype_func g_dbus_server_flags_get_type, decl_prefix GIOMM_API)

protected:
  Server(const std::string& address,
    const std::string& guid,
    const Glib::RefPtr<AuthObserver>& observer,
    const Glib::RefPtr<Cancellable>& cancellable,
    Flags flags);

  Server(const std::string& address,
    const std::string& guid,
    const Glib::RefPtr<Cancellable>& cancellable,
    Flags flags);

  Server(const std::string& address,
    const std::string& guid,
    const Glib::RefPtr<AuthObserver>& observer,
    Flags flags);

  Server(const std::string& address,
    const std::string& guid,
    Flags flags);

public:

  _WRAP_METHOD_DOCS_ONLY(g_dbus_server_new_sync)
  /// @throw Glib::Error.
  static Glib::RefPtr<Server> create_sync(const std::string& address,
    const std::string& guid,
    const Glib::RefPtr<AuthObserver>& observer,
    const Glib::RefPtr<Cancellable>& cancellable,
    Flags flags = Gio::DBus::Server::Flags::NONE);

  _WRAP_METHOD_DOCS_ONLY(g_dbus_server_new_sync)
  /// @throw Glib::Error.
  static Glib::RefPtr<Server> create_sync(const std::string& address,
    const std::string& guid,
    const Glib::RefPtr<Cancellable>& cancellable,
    Flags flags = Gio::DBus::Server::Flags::NONE);

  /// Non-cancellable version of create_sync().
  static Glib::RefPtr<Server> create_sync(const std::string& address,
    const std::string& guid,
    const Glib::RefPtr<AuthObserver>& observer,
    Flags flags = Gio::DBus::Server::Flags::NONE);

  /// Non-cancellable version of create_sync().
  static Glib::RefPtr<Server> create_sync(const std::string& address,
    const std::string& guid,
    Flags flags = Gio::DBus::Server::Flags::NONE);

  _WRAP_METHOD(void start(), g_dbus_server_start)
  _WRAP_METHOD(void stop(), g_dbus_server_stop)
  _WRAP_METHOD(bool is_active() const, g_dbus_server_is_active)
  _WRAP_METHOD(std::string get_guid() const, g_dbus_server_get_guid)
  _WRAP_METHOD(Flags get_flags() const, g_dbus_server_get_flags)
  _WRAP_METHOD(std::string get_client_address() const, g_dbus_server_get_client_address)

  _WRAP_PROPERTY("active", bool)
  _WRAP_PROPERTY("address", std::string)
  _WRAP_PROPERTY("authentication-observer", Glib::RefPtr<AuthObserver>)
  _WRAP_PROPERTY("client-address", std::string)
  _WRAP_PROPERTY("flags", Flags)
  _WRAP_PROPERTY("guid", std::string)

#m4 _CONVERSION(`GDBusConnection*', `const Glib::RefPtr<Connection>&', `Glib::wrap($3, true)')
  _WRAP_SIGNAL(bool new_connection(const Glib::RefPtr<Connection>& connection), "new-connection", no_default_handler)
};

} //namespace DBus

} // namespace Gio