mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-01-02 12:10:14 +01:00
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* bus/connection.c: (bus_connection_foreach): * bus/connection.h: Add new bus_connection_foreach function. * bus/driver.c: (send_one_message), (bus_driver_broadcast_message): Add function that broadcasts a message to all clients. (bus_driver_send_service_created), (bus_driver_handle_hello), (bus_driver_send_welcome_message), (bus_driver_handle_list_services), (bus_driver_message_handler): Implement functions that take care of listing services, and notifying clients when new services are created. * bus/services.c: (bus_services_list): * bus/services.h: Add new function that returns an array of strings with the currently registered services. * glib/dbus-glib.h: * glib/dbus-gmain.c: Update copyright year.
This commit is contained in:
parent
dc6a61a15b
commit
a16e83f45d
8 changed files with 174 additions and 13 deletions
24
ChangeLog
24
ChangeLog
|
|
@ -1,3 +1,27 @@
|
|||
2003-01-25 Anders Carlsson <andersca@codefactory.se>
|
||||
|
||||
* bus/connection.c: (bus_connection_foreach):
|
||||
* bus/connection.h:
|
||||
Add new bus_connection_foreach function.
|
||||
|
||||
* bus/driver.c: (send_one_message), (bus_driver_broadcast_message):
|
||||
Add function that broadcasts a message to all clients.
|
||||
|
||||
(bus_driver_send_service_created), (bus_driver_handle_hello),
|
||||
(bus_driver_send_welcome_message),
|
||||
(bus_driver_handle_list_services), (bus_driver_message_handler):
|
||||
Implement functions that take care of listing services, and notifying
|
||||
clients when new services are created.
|
||||
|
||||
* bus/services.c: (bus_services_list):
|
||||
* bus/services.h:
|
||||
Add new function that returns an array of strings with the currently
|
||||
registered services.
|
||||
|
||||
* glib/dbus-glib.h:
|
||||
* glib/dbus-gmain.c:
|
||||
Update copyright year.
|
||||
|
||||
2003-01-25 Anders Carlsson <andersca@codefactory.se>
|
||||
|
||||
* dbus/dbus-connection.c: (dbus_connection_send_message):
|
||||
|
|
|
|||
|
|
@ -224,3 +224,10 @@ bus_connection_get_name (DBusConnection *connection)
|
|||
|
||||
return d->name;
|
||||
}
|
||||
|
||||
void
|
||||
bus_connection_foreach (BusConnectionForeachFunction function,
|
||||
void *data)
|
||||
{
|
||||
_dbus_list_foreach (&connections, function, data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@
|
|||
#include <dbus/dbus.h>
|
||||
#include "services.h"
|
||||
|
||||
typedef void (* BusConnectionForeachFunction) (DBusConnection *connection,
|
||||
void *data);
|
||||
|
||||
dbus_bool_t bus_connection_init (void);
|
||||
|
||||
dbus_bool_t bus_connection_setup (DBusConnection *connection);
|
||||
|
|
@ -38,9 +41,11 @@ void bus_connection_remove_owned_service (DBusConnection *connection,
|
|||
BusService *service);
|
||||
|
||||
/* called by driver.c */
|
||||
dbus_bool_t bus_connection_set_name (DBusConnection *connection,
|
||||
const DBusString *name);
|
||||
const char *bus_connection_get_name (DBusConnection *connection);
|
||||
dbus_bool_t bus_connection_set_name (DBusConnection *connection,
|
||||
const DBusString *name);
|
||||
const char *bus_connection_get_name (DBusConnection *connection);
|
||||
void bus_connection_foreach (BusConnectionForeachFunction function,
|
||||
void *data);
|
||||
|
||||
|
||||
#endif /* BUS_CONNECTION_H */
|
||||
|
|
|
|||
100
bus/driver.c
100
bus/driver.c
|
|
@ -24,6 +24,7 @@
|
|||
#include "connection.h"
|
||||
#include "driver.h"
|
||||
#include "services.h"
|
||||
#include <dbus/dbus-message-internal.h>
|
||||
#include <dbus/dbus-internals.h>
|
||||
#include <dbus/dbus-string.h>
|
||||
#include <string.h>
|
||||
|
|
@ -31,10 +32,52 @@
|
|||
#define BUS_DRIVER_SERVICE_NAME "org.freedesktop.DBus"
|
||||
#define BUS_DRIVER_HELLO_NAME "org.freedesktop.DBus.Hello"
|
||||
#define BUS_DRIVER_WELCOME_NAME "org.freedesktop.DBus.Welcome"
|
||||
#define BUS_DRIVER_LIST_SERVICES_NAME "org.freedesktop.DBus.ListServices"
|
||||
#define BUS_DRIVER_SERVICES_NAME "org.freedesktop.DBus.Services"
|
||||
|
||||
#define BUS_DRIVER_SERVICE_CREATED_NAME "org.freedesktop.DBus.ServiceCreated"
|
||||
#define BUS_DRIVER_SERVICE_DELETED_NAME "org.freedesktop.DBus.ServiceDeleted"
|
||||
|
||||
static dbus_bool_t bus_driver_send_welcome_message (DBusConnection *connection,
|
||||
DBusMessage *hello_message);
|
||||
|
||||
static void
|
||||
send_one_message (DBusConnection *connection, void *data)
|
||||
{
|
||||
dbus_connection_send_message (connection, data, NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
bus_driver_broadcast_message (DBusMessage *message)
|
||||
{
|
||||
bus_connection_foreach (send_one_message, message);
|
||||
}
|
||||
|
||||
static dbus_bool_t
|
||||
bus_driver_send_service_created (DBusConnection *connection, const char *name)
|
||||
{
|
||||
DBusMessage *message;
|
||||
|
||||
message = dbus_message_new (NULL, BUS_DRIVER_SERVICE_CREATED_NAME);
|
||||
|
||||
if (!message)
|
||||
return FALSE;
|
||||
|
||||
if (!dbus_message_append_fields (message,
|
||||
DBUS_TYPE_STRING, name,
|
||||
0))
|
||||
{
|
||||
dbus_message_unref (message);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
dbus_message_set_sender (message, BUS_DRIVER_SERVICE_NAME);
|
||||
bus_driver_broadcast_message (message);
|
||||
dbus_message_unref (message);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static dbus_bool_t
|
||||
create_unique_client_name (const char *name,
|
||||
DBusString *str)
|
||||
|
|
@ -98,8 +141,8 @@ create_unique_client_name (const char *name,
|
|||
}
|
||||
|
||||
static dbus_bool_t
|
||||
bus_driver_handle_hello_message (DBusConnection *connection,
|
||||
DBusMessage *message)
|
||||
bus_driver_handle_hello (DBusConnection *connection,
|
||||
DBusMessage *message)
|
||||
{
|
||||
DBusResultCode result;
|
||||
char *name;
|
||||
|
|
@ -139,13 +182,19 @@ bus_driver_handle_hello_message (DBusConnection *connection,
|
|||
bus_connection_set_name (connection, &unique_name);
|
||||
|
||||
/* We need to assign the sender to the message here */
|
||||
_dbus_message_set_sender (message,
|
||||
bus_connection_get_name (connection));
|
||||
dbus_message_set_sender (message,
|
||||
bus_connection_get_name (connection));
|
||||
|
||||
_dbus_string_free (&unique_name);
|
||||
|
||||
retval = bus_driver_send_welcome_message (connection, message);
|
||||
|
||||
if (!retval)
|
||||
return FALSE;
|
||||
|
||||
/* Broadcast a ServiceCreated message */
|
||||
retval = bus_driver_send_service_created (connection, bus_connection_get_name (connection));
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -167,7 +216,7 @@ bus_driver_send_welcome_message (DBusConnection *connection,
|
|||
return FALSE;
|
||||
|
||||
/* FIXME: Return value */
|
||||
_dbus_message_set_sender (welcome, BUS_DRIVER_SERVICE_NAME);
|
||||
dbus_message_set_sender (welcome, BUS_DRIVER_SERVICE_NAME);
|
||||
|
||||
if (!dbus_message_append_fields (welcome,
|
||||
DBUS_TYPE_STRING, name,
|
||||
|
|
@ -183,6 +232,39 @@ bus_driver_send_welcome_message (DBusConnection *connection,
|
|||
return retval;
|
||||
}
|
||||
|
||||
static void
|
||||
bus_driver_handle_list_services (DBusConnection *connection,
|
||||
DBusMessage *message)
|
||||
{
|
||||
DBusMessage *reply;
|
||||
int len, i;
|
||||
char **services;
|
||||
|
||||
reply = dbus_message_new_reply (BUS_DRIVER_SERVICES_NAME, message);
|
||||
|
||||
if (reply == NULL)
|
||||
return;
|
||||
|
||||
services = bus_services_list (&len);
|
||||
|
||||
if (!services)
|
||||
return;
|
||||
|
||||
if (!dbus_message_append_fields (reply,
|
||||
DBUS_TYPE_STRING_ARRAY, services, len,
|
||||
0))
|
||||
goto error;
|
||||
|
||||
if (!dbus_connection_send_message (connection, reply, NULL, NULL))
|
||||
goto error;
|
||||
|
||||
error:
|
||||
dbus_message_unref (reply);
|
||||
for (i = 0; i < len; i++)
|
||||
dbus_free (services[i]);
|
||||
dbus_free (services);
|
||||
}
|
||||
|
||||
/* This is where all the magic occurs */
|
||||
static DBusHandlerResult
|
||||
bus_driver_message_handler (DBusMessageHandler *handler,
|
||||
|
|
@ -195,13 +277,15 @@ bus_driver_message_handler (DBusMessageHandler *handler,
|
|||
service = dbus_message_get_service (message);
|
||||
name = dbus_message_get_name (message);
|
||||
|
||||
_dbus_message_set_sender (message,
|
||||
bus_connection_get_name (connection));
|
||||
dbus_message_set_sender (message,
|
||||
bus_connection_get_name (connection));
|
||||
|
||||
if (strcmp (service, BUS_DRIVER_SERVICE_NAME) == 0)
|
||||
{
|
||||
if (strcmp (name, BUS_DRIVER_HELLO_NAME) == 0)
|
||||
bus_driver_handle_hello_message (connection, message);
|
||||
bus_driver_handle_hello (connection, message);
|
||||
else if (strcmp (name, BUS_DRIVER_LIST_SERVICES_NAME) == 0)
|
||||
bus_driver_handle_list_services (connection, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -163,3 +163,42 @@ bus_service_foreach (BusServiceForeachFunction function,
|
|||
(* function) (service, data);
|
||||
}
|
||||
}
|
||||
|
||||
char **
|
||||
bus_services_list (int *array_len)
|
||||
{
|
||||
int i, j, len;
|
||||
char **retval;
|
||||
DBusHashIter iter;
|
||||
|
||||
len = _dbus_hash_table_get_n_entries (service_hash);
|
||||
retval = dbus_new (char *, len);
|
||||
|
||||
if (retval == NULL)
|
||||
return NULL;
|
||||
|
||||
_dbus_hash_iter_init (service_hash, &iter);
|
||||
i = 0;
|
||||
while (_dbus_hash_iter_next (&iter))
|
||||
{
|
||||
BusService *service = _dbus_hash_iter_get_value (&iter);
|
||||
|
||||
retval[i] = _dbus_strdup (service->name);
|
||||
if (retval[i] == NULL)
|
||||
goto error;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if (array_len)
|
||||
*array_len = len;
|
||||
|
||||
return retval;
|
||||
|
||||
error:
|
||||
for (j = 0; j < i; j++)
|
||||
dbus_free (retval[i]);
|
||||
dbus_free (retval);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,4 +50,6 @@ const char* bus_service_get_name (BusService *servic
|
|||
void bus_service_foreach (BusServiceForeachFunction function,
|
||||
void *data);
|
||||
|
||||
char **bus_services_list (int *array_len);
|
||||
|
||||
#endif /* BUS_SERVICES_H */
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/* -*- mode: C; c-file-style: "gnu" -*- */
|
||||
/* dbus-glib.h GLib integration
|
||||
*
|
||||
* Copyright (C) 2002 CodeFactory AB
|
||||
* Copyright (C) 2002, 2003 CodeFactory AB
|
||||
*
|
||||
* Licensed under the Academic Free License version 1.2
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/* -*- mode: C; c-file-style: "gnu" -*- */
|
||||
/* dbus-gmain.c GLib main loop integration
|
||||
*
|
||||
* Copyright (C) 2002 CodeFactory AB
|
||||
* Copyright (C) 2002, 2003 CodeFactory AB
|
||||
*
|
||||
* Licensed under the Academic Free License version 1.2
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue