-/* $Id$ */
-
/***
This file is part of avahi.
#include <avahi-common/dbus.h>
#include <avahi-common/malloc.h>
#include <avahi-common/dbus-watch-glue.h>
+#include <avahi-common/i18n.h>
#include "client.h"
#include "internal.h"
return avahi_client_set_errno(client, avahi_error_dbus_to_number(error->name));
}
-static void client_set_state (AvahiClient *client, AvahiServerState state) {
+static void client_set_state(AvahiClient *client, AvahiClientState state) {
assert(client);
if (client->state == state)
if (strcmp(name, AVAHI_DBUS_NAME) == 0) {
- if (avahi_client_is_connected(client)) {
+ if (old[0] &&
+ avahi_client_is_connected(client)) {
- /* Regardless if the server lost or acquired its name or
+ /* Regardless if the server lost its name or
* if the name was transfered: our services are no longer
* available, so we disconnect ourselves */
avahi_client_set_errno(client, AVAHI_ERR_DISCONNECTED);
dbus_error_is_set (&error))
goto fail;
- client_set_state(client, (AvahiServerState) state);
+ client_set_state(client, (AvahiClientState) state);
dbus_message_unref(message);
dbus_message_unref(reply);
AvahiClient *avahi_client_new(const AvahiPoll *poll_api, AvahiClientFlags flags, AvahiClientCallback callback, void *userdata, int *ret_error) {
AvahiClient *client = NULL;
DBusError error;
+ DBusMessage *message = NULL, *reply = NULL;
avahi_init_i18n();
goto fail;
}
- if (!dbus_connection_add_filter (client->bus, filter_func, client, NULL)) {
+ if (!dbus_connection_add_filter(client->bus, filter_func, client, NULL)) {
if (ret_error)
*ret_error = AVAHI_ERR_NO_MEMORY;
goto fail;
if (dbus_error_is_set(&error))
goto fail;
- dbus_bus_add_match (
+ dbus_bus_add_match(
client->bus,
"type='signal', "
"interface='" DBUS_INTERFACE_LOCAL "'",
if (dbus_error_is_set(&error))
goto fail;
+ if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, "org.freedesktop.DBus.Peer", "Ping")))
+ goto fail;
- if (!(dbus_bus_name_has_owner(client->bus, AVAHI_DBUS_NAME, &error)) ||
- dbus_error_is_set(&error)) {
+ reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error);
+ if (!reply || dbus_error_is_set (&error)) {
/* We free the error so its not set, that way the fail target
* will return the NO_DAEMON error rather than a DBUS error */
dbus_error_free(&error);
goto fail;
}
+ dbus_message_unref(message);
+
+ if (reply)
+ dbus_message_unref(reply);
+
return client;
fail:
+ if (message)
+ dbus_message_unref(message);
+ if (reply)
+ dbus_message_unref(reply);
+
if (client)
avahi_client_free(client);