1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-bus.c Convenience functions for communicating with the bus.
4 * Copyright (C) 2003 CodeFactory AB
5 * Copyright (C) 2003 Red Hat, Inc.
7 * Licensed under the Academic Free License version 1.2
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "dbus-protocol.h"
27 #include "dbus-internals.h"
30 * @defgroup DBusBus Message bus APIs
32 * @brief Functions for communicating with the message bus
38 * Registers a connection with the bus. This must be the first
39 * thing an application does when connecting to the message bus.
41 * @todo if we get an error reply, it has to be converted into
42 * DBusError and returned
44 * @param connection the connection
45 * @param error place to store errors
46 * @returns the client's unique service name, #NULL on error
49 dbus_bus_register_client (DBusConnection *connection,
52 DBusMessage *message, *reply;
55 message = dbus_message_new (DBUS_SERVICE_DBUS,
60 _DBUS_SET_OOM (error);
64 reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
66 dbus_message_unref (message);
70 _DBUS_ASSERT_ERROR_IS_SET (error);
74 if (!dbus_message_get_args (reply, error,
75 DBUS_TYPE_STRING, &name,
78 _DBUS_ASSERT_ERROR_IS_SET (error);
86 * Asks the bus to try to acquire a certain service.
88 * @todo these docs are not complete, need to document the
89 * return value and flags
91 * @todo if we get an error reply, it has to be converted into
92 * DBusError and returned
94 * @param connection the connection
95 * @param service_name the service name
97 * @param error location to store the error
98 * @returns a result code, -1 if error is set
101 dbus_bus_acquire_service (DBusConnection *connection,
102 const char *service_name,
106 DBusMessage *message, *reply;
109 message = dbus_message_new (DBUS_SERVICE_DBUS,
110 DBUS_MESSAGE_ACQUIRE_SERVICE);
114 _DBUS_SET_OOM (error);
118 if (!dbus_message_append_args (message,
119 DBUS_TYPE_STRING, service_name,
120 DBUS_TYPE_UINT32, flags,
123 dbus_message_unref (message);
124 _DBUS_SET_OOM (error);
128 reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
131 dbus_message_unref (message);
135 _DBUS_ASSERT_ERROR_IS_SET (error);
139 if (!dbus_message_get_args (reply, error,
140 DBUS_TYPE_UINT32, &service_result,
143 _DBUS_ASSERT_ERROR_IS_SET (error);
147 return service_result;
151 * Checks whether a certain service exists.
153 * @todo the SERVICE_EXISTS message should use BOOLEAN not UINT32
155 * @param connection the connection
156 * @param service_name the service name
157 * @param error location to store any errors
158 * @returns #TRUE if the service exists, #FALSE if not or on error
161 dbus_bus_service_exists (DBusConnection *connection,
162 const char *service_name,
165 DBusMessage *message, *reply;
168 message = dbus_message_new (DBUS_SERVICE_DBUS,
169 DBUS_MESSAGE_SERVICE_EXISTS);
172 _DBUS_SET_OOM (error);
176 if (!dbus_message_append_args (message,
177 DBUS_TYPE_STRING, service_name,
180 dbus_message_unref (message);
181 _DBUS_SET_OOM (error);
185 reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
186 dbus_message_unref (message);
190 _DBUS_ASSERT_ERROR_IS_SET (error);
194 if (!dbus_message_get_args (reply, error,
195 DBUS_TYPE_UINT32, &exists,
198 _DBUS_ASSERT_ERROR_IS_SET (error);
202 return (exists != FALSE);