1/* Copyright (C) 2010 The giomm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
15 */
16
17_CONFIGINCLUDE(giommconfig.h)
18
19#include <glibmm/object.h>
20#include <glibmm/variant.h>
21#include <glibmm/utility.h>
22
23#ifdef G_OS_UNIX
24# include <giomm/unixfdlist.h>
25#endif
26
27_DEFS(giomm,gio)
28_PINCLUDE(glibmm/private/object_p.h)
29
30namespace Gio
31{
32
33namespace DBus
34{
35
36_WRAP_ENUM(MessageType, GDBusMessageType, s#^DBUS_##, NO_GTYPE)
37_WRAP_ENUM(MessageFlags, GDBusMessageFlags, s#^DBUS_##, NO_GTYPE)
38_WRAP_ENUM(MessageHeaderField, GDBusMessageHeaderField, s#^DBUS_##, NO_GTYPE)
39_WRAP_ENUM(CapabilityFlags, GDBusCapabilityFlags, s#^DBUS_##, gtype_func g_dbus_capability_flags_get_type)
40
41_GMMPROC_EXTRA_NAMESPACE(DBus)
42
43/** A type for representing D-Bus messages that can be sent or received on a
44 * Connection.
45 *
46 * @newin{2,28}
47 * @ingroup DBus
48 */
49class GIOMM_API Message : public Glib::Object
50{
51  _CLASS_GOBJECT(Message, GDBusMessage, G_DBUS_MESSAGE, Glib::Object, GObject, , , GIOMM_API)
52
53protected:
54  _CTOR_DEFAULT
55  _IGNORE(g_dbus_message_new)
56
57public:
58  _WRAP_METHOD_DOCS_ONLY(g_dbus_message_new)
59  _WRAP_CREATE()
60
61  // Note that we can't use _WRAP_CTOR() and _WRAP_CREATE() because the C functions do more than just call g_object_new():
62  // See http://bugzilla.gnome.org/show_bug.cgi?id=624977
63
64  // See here about whether the parameters should be ustring or std::string:
65  // http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names
66  // They are generally UTF-8 that can only contain the ASCII subset,
67  // so ustring still seems preferrable to std::string, which generally implies an unknown encoding for us.
68
69  // The parameter name 'interface' can cause compilation errors with MinGW.
70  // See https://bugzilla.gnome.org/show_bug.cgi?id=735137
71  // The parameter name in glib is 'interface_'.
72  _WRAP_METHOD(static Glib::RefPtr<Message> create_signal(const Glib::ustring& path, const Glib::ustring& iface, const Glib::ustring& signal), g_dbus_message_new_signal)
73  _WRAP_METHOD(static Glib::RefPtr<Message> create_method_call(const Glib::ustring& name, const Glib::ustring& path, const Glib::ustring& iface, const Glib::ustring& method), g_dbus_message_new_method_call)
74  _WRAP_METHOD(static Glib::RefPtr<Message> create_method_reply(const Glib::RefPtr<Message>& method_call_message), g_dbus_message_new_method_reply)
75  _WRAP_METHOD(static Glib::RefPtr<Message> create_method_error_literal(const Glib::RefPtr<const Message>& method_call_message, const Glib::ustring& error_name, const Glib::ustring& error_message), g_dbus_message_new_method_error_literal)
76
77  // Ignore variable argument functions.
78  _IGNORE(g_dbus_message_new_method_error, g_dbus_message_new_method_error_valist)
79
80  _WRAP_METHOD(static Glib::RefPtr<Message> create_from_blob(const guchar* blob,  gsize blob_len, CapabilityFlags capabilities = CAPABILITY_FLAGS_NONE), g_dbus_message_new_from_blob, errthrow)
81
82
83  _WRAP_METHOD(Glib::ustring print(guint indent), g_dbus_message_print)
84
85  _WRAP_METHOD(bool get_locked() const, g_dbus_message_get_locked)
86  _WRAP_METHOD(void lock() ,g_dbus_message_lock)
87  _WRAP_METHOD(Glib::RefPtr<Message> copy() const, g_dbus_message_copy, errthrow)
88
89  _WRAP_METHOD(MessageType get_message_type() const, g_dbus_message_get_message_type)
90  _WRAP_METHOD(void set_message_type(MessageType type), g_dbus_message_set_message_type)
91
92  //gmmproc can't handle the character literals, and this won't be expanded in future,
93  //so we just wrap it by hand.
94  enum ByteOrder
95  {
96    BYTE_ORDER_BIG_ENDIAN    = 'B',
97    BYTE_ORDER_LITTLE_ENDIAN = 'l'
98  };
99
100  #m4 _CONVERSION(`ByteOrder',`GDBusMessageByteOrder',`(GDBusMessageByteOrder)($3)')
101  #m4 _CONVERSION(`GDBusMessageByteOrder',`ByteOrder',`(ByteOrder)($3)')
102
103  _WRAP_METHOD(ByteOrder get_byte_order() const, g_dbus_message_get_byte_order)
104  _WRAP_METHOD(void set_byte_order(ByteOrder byte_order), g_dbus_message_set_byte_order)
105
106  _WRAP_METHOD(guint32 get_serial() const, g_dbus_message_get_serial)
107  _WRAP_METHOD(void set_serial(guint32 serial), g_dbus_message_set_serial)
108
109  _WRAP_METHOD(MessageFlags get_flags() const, g_dbus_message_get_flags)
110  _WRAP_METHOD(void set_flags(MessageFlags flags), g_dbus_message_set_flags)
111
112  /** Gets the body of a message.  The body is returned in @a value.
113   * @param value Location in which to store the header.
114   */
115  void get_body(Glib::VariantBase& value) const;
116  _IGNORE(g_dbus_message_get_body)
117
118  _WRAP_METHOD(void set_body(const Glib::VariantBase& body), g_dbus_message_set_body)
119
120  _WRAP_METHOD(Glib::RefPtr<UnixFDList> get_unix_fd_list(), g_dbus_message_get_unix_fd_list, refreturn, ifdef G_OS_UNIX)
121  _WRAP_METHOD(Glib::RefPtr<const UnixFDList> get_unix_fd_list() const, g_dbus_message_get_unix_fd_list, refreturn, constversion, ifdef G_OS_UNIX)
122  _WRAP_METHOD(void set_unix_fd_list(const Glib::RefPtr<UnixFDList>& fd_list), g_dbus_message_set_unix_fd_list, ifdef G_OS_UNIX)
123
124#ifdef G_OS_UNIX
125  /** Clears the existing UNIX file descriptor list.
126   */
127  void unset_unix_fd_list();
128#endif //G_OS_UNIX
129
130  _WRAP_METHOD(guint32 get_num_unix_fds() const, g_dbus_message_get_num_unix_fds)
131  _WRAP_METHOD(void set_num_unix_fds(guint32 value), g_dbus_message_set_num_unix_fds)
132
133  /** Gets a header field on the message.  The header is returned in @a value.
134   * @param value Location in which to store the header.
135   * @param header_field The header field type.
136   */
137  void get_header(Glib::VariantBase& value, MessageHeaderField header_field) const;
138  _IGNORE(g_dbus_message_get_header)
139
140  _WRAP_METHOD(void set_header(MessageHeaderField header_field, const Glib::VariantBase& value), g_dbus_message_set_header)
141
142  #m4 _CONVERSION(`guchar*',`Glib::ArrayHandle<guchar>',`Glib::ArrayHandle<guchar>($3)')
143  _WRAP_METHOD(Glib::ArrayHandle<guchar> get_header_fields() const, g_dbus_message_get_header_fields)
144
145  _WRAP_METHOD(Glib::ustring get_destination() const, g_dbus_message_get_destination)
146  _WRAP_METHOD(void set_destination(const Glib::ustring& value), g_dbus_message_set_destination)
147
148  _WRAP_METHOD(Glib::ustring get_error_name() const, g_dbus_message_get_error_name)
149  _WRAP_METHOD(void set_error_name(const Glib::ustring& value), g_dbus_message_set_error_name)
150
151  _WRAP_METHOD(Glib::ustring get_interface() const, g_dbus_message_get_interface)
152  _WRAP_METHOD(void set_interface(const Glib::ustring& value), g_dbus_message_set_interface)
153
154  _WRAP_METHOD(Glib::ustring get_member() const, g_dbus_message_get_member)
155  _WRAP_METHOD(void set_member(const Glib::ustring& value), g_dbus_message_set_member)
156
157  _WRAP_METHOD(Glib::ustring get_path() const, g_dbus_message_get_path)
158  _WRAP_METHOD(void set_path(const Glib::ustring& value), g_dbus_message_set_path)
159
160  _WRAP_METHOD(guint32 get_reply_serial() const, g_dbus_message_get_reply_serial)
161  _WRAP_METHOD(void set_reply_serial(guint32 value), g_dbus_message_set_reply_serial)
162
163  _WRAP_METHOD(Glib::ustring get_sender() const, g_dbus_message_get_sender)
164  _WRAP_METHOD(void set_sender(const Glib::ustring& value), g_dbus_message_set_sender)
165
166  _WRAP_METHOD(Glib::ustring get_signature() const, g_dbus_message_get_signature)
167  _WRAP_METHOD(void set_signature(const Glib::ustring& value), g_dbus_message_set_signature)
168
169  _WRAP_METHOD(Glib::ustring get_arg0() const, g_dbus_message_get_arg0)
170
171  _WRAP_METHOD(static gssize bytes_needed(const guchar* blob, gsize blob_len), g_dbus_message_bytes_needed, errthrow)
172
173  _WRAP_METHOD(guchar* to_blob(gsize& out_size, CapabilityFlags capabilities = CAPABILITY_FLAGS_NONE), g_dbus_message_to_blob, errthrow)
174
175  _WRAP_METHOD(void to_exception(), g_dbus_message_to_gerror, errthrow)
176
177  _WRAP_PROPERTY("locked", bool)
178};
179
180} //namespace DBus
181
182} // namespace Gio
183