summaryrefslogtreecommitdiffstats
path: root/dbus
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@codefactory.se>2003-02-01 21:26:32 +0000
committerAnders Carlsson <andersca@codefactory.se>2003-02-01 21:26:32 +0000
commitdbc4c0ca13fcc1cdf2be6c35a4559bc456243acb (patch)
tree3305148cd8a347b25dd4ec1577cb02b616a033dd /dbus
parentffeb3f0ee1bd083c4470a34988bd92f438b81e1e (diff)
2003-02-01 Anders Carlsson <andersca@codefactory.se>
* bus/driver.c: (create_unique_client_name), (bus_driver_handle_hello): Don't take a name, just use a numeric id to identify each client. * dbus/Makefile.am: * dbus/dbus-bus.c: (dbus_bus_register_client), (dbus_bus_acquire_service), (dbus_bus_service_exists): * dbus/dbus-bus.h: Add new convenience functions for communicating with the bus. * dbus/dbus-message.h: * dbus/dbus-protocol.h: Fix a typo.
Diffstat (limited to 'dbus')
-rw-r--r--dbus/Makefile.am4
-rw-r--r--dbus/dbus-bus.c192
-rw-r--r--dbus/dbus-bus.h43
-rw-r--r--dbus/dbus-protocol.h2
4 files changed, 239 insertions, 2 deletions
diff --git a/dbus/Makefile.am b/dbus/Makefile.am
index 4ffe7e2c..c28b5383 100644
--- a/dbus/Makefile.am
+++ b/dbus/Makefile.am
@@ -8,6 +8,7 @@ lib_LTLIBRARIES=libdbus-1.la
dbusinclude_HEADERS= \
dbus.h \
dbus-address.h \
+ dbus-bus.h \
dbus-connection.h \
dbus-errors.h \
dbus-macros.h \
@@ -23,6 +24,7 @@ libdbus_1_la_SOURCES= \
dbus-address.c \
dbus-auth.c \
dbus-auth.h \
+ dbus-bus.c \
dbus-connection.c \
dbus-connection-internal.h \
dbus-errors.c \
@@ -111,4 +113,4 @@ dbus_test_LDADD= $(DBUS_CLIENT_LIBS) libdbus-convenience.la libdbus-1.la
dbus_break_loader_SOURCES= \
dbus-break-loader.c
-dbus_break_loader_LDADD= $(DBUS_CLIENT_LIBS) libdbus-convenience.la libdbus-1.la \ No newline at end of file
+dbus_break_loader_LDADD= $(DBUS_CLIENT_LIBS) libdbus-convenience.la libdbus-1.la
diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c
new file mode 100644
index 00000000..6372c873
--- /dev/null
+++ b/dbus/dbus-bus.c
@@ -0,0 +1,192 @@
+/* -*- mode: C; c-file-style: "gnu" -*- */
+/* dbus-bus.h Convenience functions for communicating with the bus.
+ *
+ * Copyright (C) 2003 CodeFactory AB
+ *
+ * Licensed under the Academic Free License version 1.2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "dbus-bus.h"
+#include "dbus-protocol.h"
+
+/**
+ * @defgroup DBusBus Convenience functinos for communicating with the bus.
+ * @ingroup DBus
+ * @brief Convenience functinos for communicating with the bus.
+ *
+ * @{
+ */
+
+/**
+ * Registers a connection with the bus. This is needed to send messages
+ * to other clients.
+ *
+ * @param connection The connection
+ * @param result address where a result code can be returned.
+ * @returns the service name of which the client is known as.
+ */
+char *
+dbus_bus_register_client (DBusConnection *connection,
+ DBusResultCode *result)
+{
+ DBusMessage *message, *reply;
+ DBusResultCode code;
+ char *name;
+
+ message = dbus_message_new (DBUS_SERVICE_DBUS,
+ DBUS_MESSAGE_HELLO);
+
+ if (!message)
+ {
+ dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ return NULL;
+ }
+
+ reply = dbus_connection_send_message_with_reply_and_block (connection, message, -1, result);
+
+ dbus_message_unref (message);
+
+ if (!reply)
+ return NULL;
+
+ code = dbus_message_get_fields (reply,
+ DBUS_TYPE_STRING, &name,
+ 0);
+ if (code != DBUS_RESULT_SUCCESS)
+ {
+ dbus_set_result (result, code);
+ return NULL;
+ }
+
+ dbus_set_result (result, DBUS_RESULT_SUCCESS);
+
+ return name;
+}
+
+/**
+ * Asks the bus to try to acquire a certain service.
+ *
+ * @param connection the connection
+ * @param service_name the service name
+ * @param flags flags
+ * @param result address where a result code can be returned.
+ * @returns a result code.
+ */
+int
+dbus_bus_acquire_service (DBusConnection *connection,
+ const char *service_name,
+ unsigned int flags,
+ DBusResultCode *result)
+{
+ DBusMessage *message, *reply;
+ int service_result;
+ DBusResultCode code;
+
+ message = dbus_message_new (DBUS_SERVICE_DBUS,
+ DBUS_MESSAGE_ACQUIRE_SERVICE);
+
+ if (!message)
+ {
+ dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ return -1;
+ }
+
+ if (!dbus_message_append_fields (message,
+ DBUS_TYPE_STRING, service_name,
+ DBUS_TYPE_UINT32, flags,
+ 0))
+ {
+ dbus_message_unref (message);
+ dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ return -1;
+ }
+
+ reply = dbus_connection_send_message_with_reply_and_block (connection, message, -1, result);
+ dbus_message_unref (message);
+
+ if (!reply)
+ return -1;
+
+ code = dbus_message_get_fields (reply,
+ DBUS_TYPE_UINT32, &service_result,
+ 0);
+ if (code != DBUS_RESULT_SUCCESS)
+ {
+ dbus_set_result (result, code);
+ return -1;
+ }
+
+ dbus_set_result (result, DBUS_RESULT_SUCCESS);
+
+ return service_result;
+}
+
+/**
+ * Checks whether a certain service exists.
+ *
+ * @param connection the connection
+ * @param service_name the service name
+ * @param result address where a result code can be returned.
+ * @returns #TRUE if the service exists, #FALSE otherwise.
+ */
+dbus_bool_t
+dbus_bus_service_exists (DBusConnection *connection,
+ const char *service_name,
+ DBusResultCode *result)
+{
+ DBusMessage *message, *reply;
+ unsigned int exists;
+ DBusResultCode code;
+
+ message = dbus_message_new (DBUS_SERVICE_DBUS,
+ DBUS_MESSAGE_SERVICE_EXISTS);
+ if (!message)
+ {
+ dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ return FALSE;
+ }
+
+ if (!dbus_message_append_fields (message,
+ DBUS_TYPE_STRING, service_name,
+ 0))
+ {
+ dbus_message_unref (message);
+ dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ return FALSE;
+ }
+
+ reply = dbus_connection_send_message_with_reply_and_block (connection, message, -1, result);
+ dbus_message_unref (message);
+
+ if (!reply)
+ return FALSE;
+
+ code = dbus_message_get_fields (reply,
+ DBUS_TYPE_UINT32, &exists,
+ 0);
+ if (code != DBUS_RESULT_SUCCESS)
+ {
+ dbus_set_result (result, code);
+ return FALSE;
+ }
+
+ dbus_set_result (result, DBUS_RESULT_SUCCESS);
+ return (result != FALSE);
+}
+
+/** @} */
diff --git a/dbus/dbus-bus.h b/dbus/dbus-bus.h
new file mode 100644
index 00000000..0bd8dec8
--- /dev/null
+++ b/dbus/dbus-bus.h
@@ -0,0 +1,43 @@
+/* -*- mode: C; c-file-style: "gnu" -*- */
+/* dbus-bus.h Convenience functions for communicating with the bus.
+ *
+ * Copyright (C) 2003 CodeFactory AB
+ *
+ * Licensed under the Academic Free License version 1.2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
+#error "Only <dbus/dbus.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef DBUS_BUS_H
+#define DBUS_BUS_H
+
+#include <dbus/dbus-connection.h>
+
+char * dbus_bus_register_client (DBusConnection *connection,
+ DBusResultCode *result);
+int dbus_bus_acquire_service (DBusConnection *connection,
+ const char *service_name,
+ unsigned int flags,
+ DBusResultCode *result);
+dbus_bool_t dbus_bus_service_exists (DBusConnection *connection,
+ const char *service_name,
+ DBusResultCode *result);
+
+
+#endif /* DBUS_BUS_H */
diff --git a/dbus/dbus-protocol.h b/dbus/dbus-protocol.h
index f1d66ac4..be96b265 100644
--- a/dbus/dbus-protocol.h
+++ b/dbus/dbus-protocol.h
@@ -79,7 +79,7 @@ extern "C" {
#define DBUS_MESSAGE_SERVICE_EXISTS "org.freedesktop.DBus.ServiceExists"
#define DBUS_MESSAGE_HELLO "org.freedesktop.DBus.Hello"
#define DBUS_MESSAGE_LIST_SERVICES "org.freedesktop.DBus.ListServices"
-#define DBUS_MESSAGE_ACQUIRE_SERVICE "org.freedesktop.DBus.OwnService"
+#define DBUS_MESSAGE_ACQUIRE_SERVICE "org.freedesktop.DBus.AcquireService"
#define DBUS_MESSAGE_SERVICE_ACQUIRED "org.freedesktop.DBus.ServiceAcquired"
#define DBUS_MESSAGE_SERVICE_CREATED "org.freedesktop.DBus.ServiceCreated"
#define DBUS_MESSAGE_SERVICE_DELETED "org.freedesktop.DBus.ServiceDeleted"