1 #ifndef RTDBUS_H 2 #define RTDBUS_H 3 /* 4 roxterm - VTE/GTK terminal emulator with tabs 5 Copyright (C) 2004-2015 Tony Houghton <h@realh.co.uk> 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21 22 23 /* D-BUS functions common to all parts of ROXTerm */ 24 25 #ifndef DEFNS_H 26 #include "defns.h" 27 #endif 28 29 #include <dbus/dbus-glib-lowlevel.h> 30 31 /* These are just stubs; they should have a specific suffix appended */ 32 #define RTDBUS_NAME "net.sf.roxterm" 33 #define RTDBUS_OBJECT_PATH "/net/sf/roxterm" 34 #define RTDBUS_INTERFACE RTDBUS_NAME 35 #define RTDBUS_ERROR RTDBUS_NAME 36 37 extern DBusConnection *rtdbus_connection; 38 extern DBusGConnection *rtdbus_g_connection; 39 40 extern gboolean rtdbus_ok; 41 42 /* Report a D-BUS error in a dialog, prepending message 's', 43 * then free the error data */ 44 void rtdbus_whinge(DBusError *pderror, const char *s); 45 46 /* As above but print it on the console with g_warning */ 47 void rtdbus_warn(DBusError *pderror, const char *s); 48 49 /* Unrefs message after sending */ 50 gboolean rtdbus_send_message(DBusMessage *message); 51 52 /* As above but waits for a reply and checks it for success */ 53 gboolean rtdbus_send_message_with_reply(DBusMessage *message); 54 55 /* Returns TRUE if another instance already has the name */ 56 gboolean rtdbus_start_service(const char *name, const char *object_path, 57 DBusObjectPathMessageFunction, gboolean replace); 58 59 /* Call before any other D-BUS functions. May be called more than once */ 60 gboolean rtdbus_init(void); 61 62 /* Adds a match rule and filter */ 63 gboolean rtdbus_add_rule_and_filter(const char *match_rule, 64 DBusHandleMessageFunction filter_fn, void *user_data); 65 66 /* Constructs a match rule for the given signal and adds a filter for it */ 67 gboolean rtdbus_add_signal_rule_and_filter( 68 const char *path, const char *interface, 69 DBusHandleMessageFunction); 70 71 /* Creates a signal message with the given arguments passed as pairs of 72 * DBUS_TYPE_*, &(*) terminated by DBUS_TYPE_INVALID */ 73 DBusMessage *rtdbus_signal_new(const char *object_path, const char *interface, 74 const char *signal_name, int first_arg_type, ...); 75 76 /* As above but creates a method call */ 77 DBusMessage *rtdbus_method_new(const char *bus_name, const char *object_path, 78 const char *interface, const char *method_name, 79 int first_arg_type, ...); 80 81 /* Appends args (see above) to message and returns the modified message. On 82 * failure (unlikely) the message is freed, an error is printed and NULL is 83 * returned */ 84 DBusMessage *rtdbus_append_args(DBusMessage *message, 85 int first_arg_type, ...); 86 87 /* See above */ 88 DBusMessage *rtdbus_append_args_valist(DBusMessage *message, 89 int first_arg_type, va_list ap); 90 91 /* Returns NULL-terminated array of strings ("strv") corresponding to a 92 * message's args. Non-string message args are counted as errors and skipped. 93 * Result may be freed with g_strfreev if it isn't NULL (no args). 94 * iter must be initialised before calling. 95 */ 96 char **rtdbus_get_message_args_as_strings(DBusMessageIter *iter); 97 98 /* Returns a "strv" from a single message arg, advancing iter */ 99 char **rtdbus_get_message_arg_string_array(DBusMessageIter *iter); 100 101 #endif /* RTDBUS_H */ 102 103 /* vi:set sw=4 ts=4 noet cindent cino= */ 104