* Add a free function for AvahiEntryGroup in C api
authorTrent Lloyd <lathiat@bur.st>
Sun, 14 Aug 2005 12:06:09 +0000 (12:06 +0000)
committerTrent Lloyd <lathiat@bur.st>
Sun, 14 Aug 2005 12:06:09 +0000 (12:06 +0000)
 * Modify the browser free functions to return/set errors.

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

avahi-client/browser.c
avahi-client/client.h
avahi-client/entrygroup.c
avahi-common/dbus.h
avahi-common/error.c
avahi-common/error.h
avahi-daemon/dbus-protocol.c

index 6e0ed5d..ab7a921 100644 (file)
@@ -88,25 +88,29 @@ dbus_error:
     return NULL;
 }
 
-void
+int
 avahi_domain_browser_free (AvahiDomainBrowser *b)
 {
+    AvahiClient *client = b->client;
     DBusMessage *message = NULL;
 
     if (b == NULL || b->path == NULL)
-        return;
+        return avahi_client_set_errno (client, AVAHI_ERR_INVALID_OBJECT);
 
     message = dbus_message_new_method_call (AVAHI_DBUS_NAME,
             b->path,
             AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "Free");
 
-    dbus_connection_send (b->client->bus, message, NULL);
+    if (message == NULL)
+        return avahi_client_set_errno (client, AVAHI_ERR_DBUS_ERROR);
+
+    dbus_connection_send (client->bus, message, NULL);
 
-    AVAHI_LLIST_REMOVE(AvahiDomainBrowser, domain_browsers, b->client->domain_browsers, b);
+    AVAHI_LLIST_REMOVE(AvahiDomainBrowser, domain_browsers, client->domain_browsers, b);
 
     free (b);
 
-    return;
+    return avahi_client_set_errno (client, AVAHI_OK);
 }
 
 char*
@@ -207,25 +211,29 @@ dbus_error:
     return NULL;
 }
 
-void
+int
 avahi_service_type_browser_free (AvahiServiceTypeBrowser *b)
 {
+    AvahiClient *client = b->client;
     DBusMessage *message = NULL;
 
     if (b == NULL || b->path == NULL)
-        return;
+        return avahi_client_set_errno (client, AVAHI_ERR_INVALID_OBJECT);
 
     message = dbus_message_new_method_call (AVAHI_DBUS_NAME,
             b->path,
             AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "Free");
 
+    if (message == NULL)
+        return avahi_client_set_errno (client, AVAHI_ERR_DBUS_ERROR);
+
     dbus_connection_send (b->client->bus, message, NULL);
 
     AVAHI_LLIST_REMOVE(AvahiServiceTypeBrowser, service_type_browsers, b->client->service_type_browsers, b);
 
     free (b);
 
-    return;
+    return avahi_client_set_errno (client, AVAHI_OK);
 }
 
 char*
@@ -334,27 +342,29 @@ dbus_error:
     return NULL;
 }
     
-void
+int
 avahi_service_browser_free (AvahiServiceBrowser *b)
 {
+    AvahiClient *client = b->client;
     DBusMessage *message = NULL;
-
+    
     if (b == NULL || b->path == NULL)
-        return;
-
-    printf ("Freeing %s\n", b->path);
+        return avahi_client_set_errno (client, AVAHI_ERR_INVALID_OBJECT);
 
     message = dbus_message_new_method_call (AVAHI_DBUS_NAME,
             b->path,
             AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, "Free");
 
+    if (message == NULL)
+        return avahi_client_set_errno (client, AVAHI_ERR_DBUS_ERROR);
+
     dbus_connection_send (b->client->bus, message, NULL);
 
     AVAHI_LLIST_REMOVE(AvahiServiceBrowser, service_browsers, b->client->service_browsers, b);
 
     free (b);
 
-    return;
+    return avahi_client_set_errno (client, AVAHI_OK);
 }
 
 char*
index 824f1e9..16e9998 100644 (file)
@@ -84,6 +84,9 @@ char* avahi_client_get_host_name_fqdn (AvahiClient*);
 /** Create a new AvahiEntryGroup object */
 AvahiEntryGroup* avahi_entry_group_new (AvahiClient*, AvahiEntryGroupCallback callback, void *user_data);
 
+/** Clean up and free an AvahiEntryGroup object */
+int avahi_entry_group_free (AvahiEntryGroup *);
+
 /** Commit an AvahiEntryGroup */
 int avahi_entry_group_commit (AvahiEntryGroup*);
 
@@ -130,7 +133,7 @@ AvahiDomainBrowser* avahi_domain_browser_new (AvahiClient *client,
 char* avahi_domain_browser_path (AvahiDomainBrowser *);
 
 /** Cleans up and frees an AvahiDomainBrowser object */
-void avahi_domain_browser_free (AvahiDomainBrowser *);
+int avahi_domain_browser_free (AvahiDomainBrowser *);
 
 /** Browse for service types on the local network */
 AvahiServiceTypeBrowser* avahi_service_type_browser_new (
@@ -145,7 +148,7 @@ AvahiServiceTypeBrowser* avahi_service_type_browser_new (
 char* avahi_service_type_browser_path (AvahiServiceTypeBrowser *);
 
 /** Cleans up and frees an AvahiServiceTypeBrowser object */
-void avahi_service_type_browser_free (AvahiServiceTypeBrowser *);
+int avahi_service_type_browser_free (AvahiServiceTypeBrowser *);
 
 /** Browse for services of a type on the local network */
 AvahiServiceBrowser* avahi_service_browser_new (
@@ -161,7 +164,7 @@ AvahiServiceBrowser* avahi_service_browser_new (
 char* avahi_service_browser_path (AvahiServiceBrowser *);
 
 /* Cleans up and frees an AvahiServiceBrowser object */
-void avahi_service_browser_free (AvahiServiceBrowser *);
+int avahi_service_browser_free (AvahiServiceBrowser *);
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 AVAHI_C_DECL_END
index ea56ee2..8120e49 100644 (file)
@@ -114,6 +114,28 @@ fail:
 }
 
 int
+avahi_entry_group_free (AvahiEntryGroup *group)
+{
+    AvahiClient *client = group->client;
+    DBusMessage *message;
+
+    if (group == NULL || group->path == NULL)
+        return avahi_client_set_errno (client, AVAHI_ERR_INVALID_OBJECT);
+
+    message = dbus_message_new_method_call (AVAHI_DBUS_NAME,
+            group->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "Free");
+
+    if (message == NULL)
+        return avahi_client_set_errno (client, AVAHI_ERR_DBUS_ERROR);
+
+    dbus_connection_send (client->bus, message, NULL);
+
+    free (group);
+
+    return avahi_client_set_errno (client, AVAHI_OK);
+}
+
+int
 avahi_entry_group_commit (AvahiEntryGroup *group)
 {
     DBusMessage *message;
index fc8dc02..e3aef6c 100644 (file)
@@ -60,6 +60,7 @@ AVAHI_C_DECL_BEGIN
 #define AVAHI_DBUS_ERR_DBUS_ERROR "org.freedesktop.Avahi.DBusError"
 #define AVAHI_DBUS_ERR_NOT_CONNECTED "org.freedesktop.Avahi.NotConnectedError"
 #define AVAHI_DBUS_ERR_NO_MEMORY "org.freedesktop.Avahi.NoMemoryError"
+#define AVAHI_DBUS_ERR_INVALID_OBJECT "org.freedesktop.Avahi.InvalidObject"
 
 AVAHI_C_DECL_END
 
index b845793..0635161 100644 (file)
@@ -49,6 +49,7 @@ const char *avahi_strerror(int error) {
         "An unexpected DBUS error occured",
         "Could not get a connection to the daemon",
         "Memory exhausted"
+        "The object passed in was not valid"
     };
 
     if (-error < 0 || -error >= -AVAHI_ERR_MAX)
index c949466..2cdda5f 100644 (file)
@@ -55,15 +55,18 @@ enum {
     AVAHI_ERR_DBUS_ERROR = -22,            /**< An unexpected DBUS error occured */
     AVAHI_ERR_NOT_CONNECTED = -23,         /**< Could not get a connection to the daemon */
     AVAHI_ERR_NO_MEMORY = -24,             /**< Memory exhausted */
+    AVAHI_ERR_INVALID_OBJECT = -25,        /**< The object passed to this function was invalid */
 
     /****
      ****    IF YOU ADD A NEW ERROR CODE HERE, PLEASE DON'T FORGET TO ADD
-     ****    IT TO THE STRING ARRAY IN avahi_strerror() AND TO THE ARRAY
-     ****    IN respond_error() IN dbus-protocol.c AND FINALLY TO
-     ****    dbus.h!
+     ****    IT TO THE STRING ARRAY IN avahi_strerror() IN error.c AND
+     ****    TO THE ARRAY IN respond_error() IN dbus-protocol.c
+     ****    AND FINALLY TO dbus.h!
+     ****
+     ****    Also remember to update the MAX value below.
      ****/
     
-    AVAHI_ERR_MAX = -25
+    AVAHI_ERR_MAX = -26
 };
 
 /** Return a human readable error string for the specified error code */
index c30873e..9b83da9 100644 (file)
@@ -349,7 +349,8 @@ static DBusHandlerResult respond_error(DBusConnection *c, DBusMessage *m, gint e
         AVAHI_DBUS_ERR_INVALID_OPERATION,
         AVAHI_DBUS_ERR_DBUS_ERROR,
         AVAHI_DBUS_ERR_NOT_CONNECTED,
-        AVAHI_DBUS_ERR_NO_MEMORY
+        AVAHI_DBUS_ERR_NO_MEMORY,
+        AVAHI_DBUS_ERR_INVALID_OBJECT
     };
 
     g_assert(-error > -AVAHI_OK);