]> git.meshlink.io Git - catta/blobdiff - avahi-client/entrygroup.c
l10n: Updated Italian (it) translation to 100%
[catta] / avahi-client / entrygroup.c
index e94001b796f85022754ddb5e4b080d2cc474db89..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);
 }
 
 static int retrieve_state(AvahiEntryGroup *group) {
-    DBusMessage *message, *reply;
+    DBusMessage *message = NULL, *reply = NULL;
     DBusError error;
     int r = AVAHI_OK;
     int32_t state;
@@ -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,12 +105,13 @@ AvahiEntryGroup* avahi_entry_group_new (AvahiClient *client, AvahiEntryGroupCall
     DBusMessage *message = NULL, *reply = NULL;
     DBusError error;
     char *path;
+    int state;
 
     assert(client);
 
     dbus_error_init (&error);
 
-    if (client->state == AVAHI_CLIENT_DISCONNECTED) {
+    if (!avahi_client_is_connected(client)) {
         avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
         goto fail;
     }
@@ -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);
@@ -237,7 +241,7 @@ int avahi_entry_group_free(AvahiEntryGroup *group) {
         
     assert(group);
     
-    if (group->path && client->state != AVAHI_CLIENT_DISCONNECTED)
+    if (group->path && avahi_client_is_connected(client))
         r = entry_group_simple_method_call(group, "Free");
     
     AVAHI_LLIST_REMOVE(AvahiEntryGroup, groups, client->groups, group);
@@ -249,27 +253,40 @@ int avahi_entry_group_free(AvahiEntryGroup *group) {
 }
 
 int avahi_entry_group_commit(AvahiEntryGroup *group) {
+    int ret;
     assert(group);
     
-    if (!group->path || group->client->state == AVAHI_CLIENT_DISCONNECTED)
+    if (!group->path || !avahi_client_is_connected(group->client))
         return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);
 
-    return entry_group_simple_method_call(group, "Commit");
+    if ((ret = entry_group_simple_method_call(group, "Commit")) < 0)
+        return ret;
+
+    group->state_valid = 0;
+    return ret;
 }
 
 int avahi_entry_group_reset(AvahiEntryGroup *group) {
+    int ret;
     assert(group);
     
-    if (!group->path || group->client->state == AVAHI_CLIENT_DISCONNECTED)
+    if (!group->path || !avahi_client_is_connected(group->client))
         return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);
 
-    return entry_group_simple_method_call(group, "Reset");
+    if ((ret = entry_group_simple_method_call(group, "Reset")) < 0)
+        return ret;
+    
+    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) {
@@ -279,7 +296,7 @@ AvahiClient* avahi_entry_group_get_client (AvahiEntryGroup *group) {
 }
 
 int avahi_entry_group_is_empty (AvahiEntryGroup *group) {
-    DBusMessage *message, *reply;
+    DBusMessage *message = NULL, *reply = NULL;
     DBusError error;
     int r = AVAHI_OK;
     int b;
@@ -288,7 +305,7 @@ int avahi_entry_group_is_empty (AvahiEntryGroup *group) {
     assert(group);
     client = group->client;
 
-    if (!group->path || group->client->state == AVAHI_CLIENT_DISCONNECTED)
+    if (!group->path || !avahi_client_is_connected(group->client))
         return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);
 
     dbus_error_init(&error);
@@ -409,7 +426,7 @@ int avahi_entry_group_add_service_strlst(
 
     client = group->client;
 
-    if (!group->path || group->client->state == AVAHI_CLIENT_DISCONNECTED)
+    if (!group->path || !avahi_client_is_connected(group->client))
         return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);
 
     if (!domain)
@@ -528,7 +545,7 @@ int avahi_entry_group_add_service_subtype(
 
     client = group->client;
 
-    if (!group->path || group->client->state == AVAHI_CLIENT_DISCONNECTED)
+    if (!group->path || !avahi_client_is_connected(group->client))
         return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);
 
     if (!domain)
@@ -638,7 +655,7 @@ int avahi_entry_group_update_service_txt_strlst(
 
     client = group->client;
 
-    if (!group->path || group->client->state == AVAHI_CLIENT_DISCONNECTED)
+    if (!group->path || !avahi_client_is_connected(group->client))
         return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);
 
     if (!domain)
@@ -700,8 +717,6 @@ fail:
         dbus_message_unref(reply);
 
     return r;
-    
-    
 }
 
 /** Add a host/address pair */
@@ -726,7 +741,7 @@ int avahi_entry_group_add_address(
 
     client = group->client;
 
-    if (!group->path || group->client->state == AVAHI_CLIENT_DISCONNECTED)
+    if (!group->path || !avahi_client_is_connected(group->client))
         return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);
 
     dbus_error_init(&error);
@@ -815,7 +830,7 @@ int avahi_entry_group_add_record(
 
     client = group->client;
 
-    if (!group->path || group->client->state == AVAHI_CLIENT_DISCONNECTED)
+    if (!group->path || !avahi_client_is_connected(group->client))
         return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);
 
     dbus_error_init(&error);