void avahi_entry_group_set_state(AvahiEntryGroup *group, AvahiEntryGroupState state) {
assert(group);
- if (group->state == state)
+ if (group->state_valid && group->state == state)
return;
group->state = state;
+ group->state_valid = 1;
if (group->callback)
group->callback(group, state, group->userdata);
dbus_message_unref(message);
dbus_message_unref(reply);
- avahi_entry_group_set_state(group, (AvahiEntryGroupState) state);
-
- return AVAHI_OK;
+ return state;
fail:
if (dbus_error_is_set(&error)) {
DBusMessage *message = NULL, *reply = NULL;
DBusError error;
char *path;
+ int state;
assert(client);
group->client = client;
group->callback = callback;
group->userdata = userdata;
- group->state = AVAHI_ENTRY_GROUP_UNCOMMITED;
+ group->state_valid = 0;
group->path = NULL;
AVAHI_LLIST_PREPEND(AvahiEntryGroup, groups, client->groups, group);
goto fail;
}
- if (retrieve_state(group) < 0)
+ if ((state = retrieve_state(group)) < 0) {
+ avahi_client_set_errno(client, state);
goto fail;
+ }
+
+ avahi_entry_group_set_state(group, (AvahiEntryGroupState) state);
dbus_message_unref(message);
dbus_message_unref(reply);
if ((ret = entry_group_simple_method_call(group, "Commit")) < 0)
return ret;
- avahi_entry_group_set_state(group, AVAHI_ENTRY_GROUP_REGISTERING);
- return 0;
+ group->state_valid = 0;
+ return ret;
}
int avahi_entry_group_reset(AvahiEntryGroup *group) {
if ((ret = entry_group_simple_method_call(group, "Reset")) < 0)
return ret;
-
- avahi_entry_group_set_state(group, AVAHI_ENTRY_GROUP_UNCOMMITED);
- return 0;
+
+ group->state_valid = 0;
+ return ret;
}
int avahi_entry_group_get_state (AvahiEntryGroup *group) {
assert (group);
- return group->state;
+ if (group->state_valid)
+ return group->state;
+
+ return retrieve_state(group);
}
AvahiClient* avahi_entry_group_get_client (AvahiEntryGroup *group) {