2 #include "e_dbus_private.h"
5 * This file contains wrappers around the standard interfaces that
6 * objects on the bus should implement.
9 static inline DBusPendingCall *
10 _dbus_peer_call(E_DBus_Connection *conn, const char *method_name, const char *destination, const char *path, E_DBus_Method_Return_Cb cb_return, const void *data)
15 msg = dbus_message_new_method_call
16 (destination, path, "org.freedesktop.DBus.Peer", method_name);
20 "ERROR: failed to create message for method call: %s() at "
22 method_name, destination, path);
26 ret = e_dbus_message_send(conn, msg, cb_return, -1, (void *)data);
27 dbus_message_unref(msg);
30 fprintf(stderr, "ERROR: could not %s() \"%s\" at \"%s\".\n",
31 method_name, destination, path);
39 * @param conn the dbus connection
40 * @param destination the bus name that the object is on
41 * @param path the object path
42 * @param cb_return a callback for a successful return
43 * @param data data to pass to the callbacks
45 EAPI DBusPendingCall *
46 e_dbus_peer_ping(E_DBus_Connection *conn, const char *destination, const char *path, E_DBus_Method_Return_Cb cb_return, const void *data)
48 return _dbus_peer_call(conn, "Ping", destination, path, cb_return, data);
52 * Get the UUID of the peer
54 * @param conn the dbus connection
55 * @param destination the bus name that the object is on
56 * @param path the object path
57 * @param cb_return a callback for a successful return
58 * @param data data to pass to the callbacks
60 EAPI DBusPendingCall *
61 e_dbus_peer_get_machine_id(E_DBus_Connection *conn, const char *destination, const char *path, E_DBus_Method_Return_Cb cb_return, const void *data)
63 return _dbus_peer_call(conn, "GetMachineId", destination, path, cb_return, data);
66 static inline DBusMessage *
67 _dbus_message_property_method_call(E_DBus_Connection *conn, const char *method_name, const char *destination, const char *path, const char *interface, const char *property)
73 fprintf(stderr, "ERROR: no connection for call of %s\n", method_name);
77 msg = dbus_message_new_method_call
78 (destination, path, "org.freedesktop.DBus.Properties", method_name);
82 "ERROR: failed to create message for method call: %s() at "
84 method_name, destination, path);
90 dbus_message_append_args(msg, DBUS_TYPE_STRING, &interface,
91 DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID);
95 dbus_message_append_args(msg, DBUS_TYPE_STRING, &interface, DBUS_TYPE_INVALID);
101 EAPI DBusPendingCall *
102 e_dbus_properties_get_all(E_DBus_Connection *conn, const char *destination, const char *path, const char *interface, E_DBus_Method_Return_Cb cb_return, const void *data)
105 DBusPendingCall *ret;
107 msg = _dbus_message_property_method_call
108 (conn, "GetAll", destination, path, interface, NULL);
111 ret = e_dbus_message_send(conn, msg, cb_return, -1, (void *)data);
112 dbus_message_unref(msg);
115 fprintf(stderr, "ERROR: failed to call GetAll() at \"%s\" at \"%s\"\n",
122 * Get the value of a property on an object
124 * @param conn the dbus connection
125 * @param destination the bus name that the object is on
126 * @param path the object path
127 * @param interface the interface name of the property
128 * @param property the name of the property
129 * @param cb_return a callback for a successful return
130 * @param data data to pass to the callbacks
132 EAPI DBusPendingCall *
133 e_dbus_properties_get(E_DBus_Connection *conn, const char *destination, const char *path, const char *interface, const char *property, E_DBus_Method_Return_Cb cb_return, const void *data)
136 DBusPendingCall *ret;
138 msg = _dbus_message_property_method_call
139 (conn, "Get", destination, path, interface, property);
142 ret = e_dbus_message_send(conn, msg, cb_return, -1, (void *)data);
143 dbus_message_unref(msg);
146 fprintf(stderr, "ERROR: failed to call Get() at \"%s\" at \"%s\"\n",
153 * Set the value of a property on an object
155 * @param conn the dbus connection
156 * @param destination the bus name that the object is on
157 * @param path the object path
158 * @param interface the interface name of the property
159 * @param property the name of the property
160 * @param value_type the type of the property's value
161 * @param value a pointer to the value
162 * @param cb_return a callback for a successful return
163 * @param data data to pass to the callbacks
165 EAPI DBusPendingCall *
166 e_dbus_properties_set(E_DBus_Connection *conn, const char *destination, const char *path, const char *interface, const char *property, int value_type, const void *value, E_DBus_Method_Return_Cb cb_return, const void *data)
169 DBusMessageIter iter, sub;
171 DBusPendingCall *ret;
173 if (!dbus_type_is_basic(value_type))
177 dbus_error_init(&err);
178 dbus_set_error(&err, "org.enlightenment.DBus.InvalidType", "Only basic types may be set using e_dbus_properties_set()");
179 cb_return((void *)data, NULL, &err);
185 msg = _dbus_message_property_method_call
186 (conn, "Set", destination, path, interface, property);
190 dbus_message_iter_init_append(msg, &iter);
191 dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, dbus_message_type_to_string(value_type), &sub);
192 dbus_message_iter_append_basic(&sub, value_type, &value);
193 dbus_message_iter_close_container(&iter, &sub);
195 ret = e_dbus_message_send(conn, msg, cb_return, -1, (void *)data);
196 dbus_message_unref(msg);
199 fprintf(stderr, "ERROR: failed to call Set() at \"%s\" at \"%s\"\n",