1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-bus.h Convenience functions for communicating with the bus.
4 * Copyright (C) 2003 CodeFactory AB
6 * Licensed under the Academic Free License version 1.2
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "dbus-protocol.h"
28 * @defgroup DBusBus Convenience functinos for communicating with the bus.
30 * @brief Convenience functinos for communicating with the bus.
36 * Registers a connection with the bus. This is needed to send messages
39 * @param connection The connection
40 * @param result address where a result code can be returned.
41 * @returns the service name of which the client is known as.
44 dbus_bus_register_client (DBusConnection *connection,
45 DBusResultCode *result)
47 DBusMessage *message, *reply;
51 message = dbus_message_new (DBUS_SERVICE_DBUS,
56 dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
60 reply = dbus_connection_send_message_with_reply_and_block (connection, message, -1, result);
62 dbus_message_unref (message);
67 code = dbus_message_get_fields (reply,
68 DBUS_TYPE_STRING, &name,
70 if (code != DBUS_RESULT_SUCCESS)
72 dbus_set_result (result, code);
76 dbus_set_result (result, DBUS_RESULT_SUCCESS);
82 * Asks the bus to try to acquire a certain service.
84 * @param connection the connection
85 * @param service_name the service name
87 * @param result address where a result code can be returned.
88 * @returns a result code.
91 dbus_bus_acquire_service (DBusConnection *connection,
92 const char *service_name,
94 DBusResultCode *result)
96 DBusMessage *message, *reply;
100 message = dbus_message_new (DBUS_SERVICE_DBUS,
101 DBUS_MESSAGE_ACQUIRE_SERVICE);
105 dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
109 if (!dbus_message_append_fields (message,
110 DBUS_TYPE_STRING, service_name,
111 DBUS_TYPE_UINT32, flags,
114 dbus_message_unref (message);
115 dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
119 reply = dbus_connection_send_message_with_reply_and_block (connection, message, -1, result);
120 dbus_message_unref (message);
125 code = dbus_message_get_fields (reply,
126 DBUS_TYPE_UINT32, &service_result,
128 if (code != DBUS_RESULT_SUCCESS)
130 dbus_set_result (result, code);
134 dbus_set_result (result, DBUS_RESULT_SUCCESS);
136 return service_result;
140 * Checks whether a certain service exists.
142 * @param connection the connection
143 * @param service_name the service name
144 * @param result address where a result code can be returned.
145 * @returns #TRUE if the service exists, #FALSE otherwise.
148 dbus_bus_service_exists (DBusConnection *connection,
149 const char *service_name,
150 DBusResultCode *result)
152 DBusMessage *message, *reply;
156 message = dbus_message_new (DBUS_SERVICE_DBUS,
157 DBUS_MESSAGE_SERVICE_EXISTS);
160 dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
164 if (!dbus_message_append_fields (message,
165 DBUS_TYPE_STRING, service_name,
168 dbus_message_unref (message);
169 dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
173 reply = dbus_connection_send_message_with_reply_and_block (connection, message, -1, result);
174 dbus_message_unref (message);
179 code = dbus_message_get_fields (reply,
180 DBUS_TYPE_UINT32, &exists,
182 if (code != DBUS_RESULT_SUCCESS)
184 dbus_set_result (result, code);
188 dbus_set_result (result, DBUS_RESULT_SUCCESS);
190 return (exists != FALSE);