+#include "client.h"
+#include "internal.h"
+
+int
+avahi_client_set_errno (AvahiClient *client, int errno)
+{
+ if (client == NULL) return errno;
+
+ client->errno = errno;
+
+ return errno;
+}
+
+static
+void avahi_client_state_change (AvahiClient *client, int state)
+{
+ if (client == NULL || client->callback == NULL)
+ return;
+
+ client->callback (client, state, client->user_data);
+}
+
+void
+avahi_client_state_request_callback (DBusPendingCall *call, void *data)
+{
+ AvahiClient *client = data;
+ DBusError error;
+ DBusMessage *reply;
+ int state, type;
+
+ dbus_error_init (&error);
+
+ reply = dbus_pending_call_steal_reply (call);
+
+ type = dbus_message_get_type (reply);
+
+ if (type == DBUS_MESSAGE_TYPE_METHOD_RETURN)
+ {
+ dbus_message_get_args (reply, &error, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID);
+
+ if (dbus_error_is_set (&error))
+ {
+ fprintf (stderr, "internal error parsing client state change for client\n");
+ return;
+ }
+
+ printf ("statechange (client) to %d\n", state);
+
+ avahi_client_state_change (client, state);
+ } else if (type == DBUS_MESSAGE_TYPE_ERROR) {
+ dbus_set_error_from_message (&error, reply);
+ fprintf (stderr, "Error from reply: %s\n", error.message);
+ }
+
+ dbus_pending_call_unref (call);
+}
+
+void
+avahi_client_schedule_state_request (AvahiClient *client)