summaryrefslogtreecommitdiff
path: root/gio/src/dbusinterfacevtable.hg
blob: caf181a7d99a138fd58792e8a711ebcab7907715 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-

/* 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, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <giomm/dbusmethodinvocation.h>
#include <gio/gio.h>

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

namespace Gio
{

namespace DBus
{

/**This represents a virtual table for
 * handling properties and method calls for a D-Bus interface.
 *
 * If you want to handle getting/setting D-Bus properties asynchronously,
 * simply register an object with the org.freedesktop.DBus.Properties D-Bus
 * interface using Gio::DBus::Connection::register_object().
 *
 * The only correct use of this class is to declare a global instance of it
 * (or an instance local to the main function) and pass pointers to the
 * instance to the methods that require such a parameter.  The instance can be
 * used for multiple registrations and the memory it uses will be freed at the
 * end of execution.  Any other use (like creating an instance local to a
 * function and using that) may cause memory leaks or errors (if the instance
 * is destroyed too early).
 *
 * @newin{2,28}
 * @ingroup DBus
 */
class InterfaceVTable
{
  _CLASS_GENERIC(InterfaceVTable, GDBusInterfaceVTable)

public:
  /** The type for a slot which handles a method call for a D-Bus interface.
   * for example,
   * @code
   * void on_interface_method_call(const Glib::RefPtr<Gio::DBus::Connection>&
   * connection, const Glib::ustring& sender, const Glib::ustring&
   * object_path, const Glib::ustring& interface_name, const Glib::ustring&
   * method_name, const Glib::VariantContainerBase& parameters, const
   * Glib::RefPtr<Gio::DBus::MethodInvocation>& invocation);
   * @endcode
   */
  using SlotInterfaceMethodCall = sigc::slot<
    void,
    const Glib::RefPtr<Connection>&,
    const Glib::ustring&,
    const Glib::ustring&,
    const Glib::ustring&,
    const Glib::ustring&,
    const Glib::VariantContainerBase&,
    const Glib::RefPtr<MethodInvocation>&
    >;

  /** The type for a slot which handles getting a property for a D-Bus
   * interface.
   * for example,
   * @code
   * void on_interface_get_property(Glib::VariantBase& property, const
   * Glib::RefPtr<Gio::DBus::Connection>& connection, const Glib::ustring&
   * sender, const Glib::ustring& object_path, const Glib::ustring&
   * interface_name, const Glib::ustring& property_name);
   * @endcode
   * @throw Glib::Error.
   */
  using SlotInterfaceGetProperty = sigc::slot<
    void,
    Glib::VariantBase&,
    const Glib::RefPtr<Connection>&,
    const Glib::ustring&,
    const Glib::ustring&,
    const Glib::ustring&,
    const Glib::ustring&
    >;

  /** The type for a slot which handles setting a property for a D-Bus
   * interface.
   * for example,
   * @code
   * bool on_interface_set_property(const Glib::RefPtr<Gio::DBus::Connection>&
   * connection, const Glib::ustring& sender, const Glib::ustring&
   * object_path, const Glib::ustring& interface_name, const Glib::ustring&
   * property_name, const Glib::VariantBase& value);
   * @endcode
   * @throw Glib::Error.
   */
  using SlotInterfaceSetProperty = sigc::slot<
    bool,
    const Glib::RefPtr<Connection>&,
    const Glib::ustring&,
    const Glib::ustring&,
    const Glib::ustring&,
    const Glib::ustring&,
    const Glib::VariantBase&
    >;

  /** Constructs a new InterfaceVTable using the specified slots.
   * @param slot_method_call The slot for handling incoming method calls.
   * @param slot_get_property The slot for getting a property.
   * @param slot_set_property The slot for setting a property.
   */
  explicit InterfaceVTable(
   const SlotInterfaceMethodCall& slot_method_call,
   const SlotInterfaceGetProperty& slot_get_property = SlotInterfaceGetProperty(),
   const SlotInterfaceSetProperty& slot_set_property = SlotInterfaceSetProperty()
  );

  InterfaceVTable(const InterfaceVTable& other) = delete;
  InterfaceVTable& operator=(const InterfaceVTable& other) = delete;

  InterfaceVTable(InterfaceVTable&& other) noexcept;
  InterfaceVTable& operator=(InterfaceVTable&& other) noexcept;

  /// Destructor.
  virtual ~InterfaceVTable();

  /// Provides access to the underlying C object.
  GDBusInterfaceVTable* gobj()
    { return reinterpret_cast<GDBusInterfaceVTable*>(&gobject_); }

  /// Provides access to the underlying C object.
  const GDBusInterfaceVTable* gobj() const
    { return reinterpret_cast<const GDBusInterfaceVTable*>(&gobject_); }

#ifndef DOXYGEN_SHOULD_SKIP_THIS
  // These are so the C callbacks and the
  // Gio::DBus::Connection::register_object() method can have access to the
  // copies of the slots used for creation when registering.
  SlotInterfaceMethodCall*      get_slot_method_call() const;
  SlotInterfaceGetProperty*     get_slot_get_property() const;
  SlotInterfaceSetProperty*     get_slot_set_property() const;
#endif

protected:
  // The underlying C instance.
  GDBusInterfaceVTable          gobject_;

  // Pointers to copies of the slots used to create an instance.
  SlotInterfaceMethodCall*      slot_method_call_;
  SlotInterfaceGetProperty*     slot_get_property_;
  SlotInterfaceSetProperty*     slot_set_property_;
};


} //namespace DBus

} // namespace Gio