]> git.meshlink.io Git - catta/commitdiff
rethink r1269 once again: instead of updating the entry group state in
authorLennart Poettering <lennart@poettering.net>
Thu, 24 Aug 2006 21:37:18 +0000 (21:37 +0000)
committerLennart Poettering <lennart@poettering.net>
Thu, 24 Aug 2006 21:37:18 +0000 (21:37 +0000)
EntryGroup::Commit() immediately (which would cause the state change callback
function to be called from the current stack frame which might be roblem for
some programs), do it asynchronously again, like in pre-r1269. However, modify
GetState() to always return the real state by asking the server if we have
doubt that our locally cached state is out-of-date.

git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1271 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-client/entrygroup.c
avahi-client/internal.h

index ea9b6767cf531d95630bf4f80db999d898054219..e2fc3b9298e146e431f9f080f399b4f0fb7cf438 100644 (file)
 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);
@@ -82,9 +83,7 @@ static int retrieve_state(AvahiEntryGroup *group) {
     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)) {
@@ -106,6 +105,7 @@ AvahiEntryGroup* avahi_entry_group_new (AvahiClient *client, AvahiEntryGroupCall
     DBusMessage *message = NULL, *reply = NULL;
     DBusError error;
     char *path;
+    int state;
 
     assert(client);
 
@@ -124,7 +124,7 @@ AvahiEntryGroup* avahi_entry_group_new (AvahiClient *client, AvahiEntryGroupCall
     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);
     
@@ -157,8 +157,12 @@ AvahiEntryGroup* avahi_entry_group_new (AvahiClient *client, AvahiEntryGroupCall
         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);
@@ -258,8 +262,8 @@ int avahi_entry_group_commit(AvahiEntryGroup *group) {
     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) {
@@ -271,15 +275,18 @@ 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) {
index 7a79dd7337628c34bdc73f2c5ceca21cfffb7ec8..e49dd15cb41d3e5e6bbb7ca6c214c5acabaaef69 100644 (file)
@@ -56,6 +56,7 @@ struct AvahiClient {
 struct AvahiEntryGroup {
     char *path;
     AvahiEntryGroupState state;
+    int state_valid;
     AvahiClient *client;
     AvahiEntryGroupCallback callback;
     void *userdata;