summaryrefslogtreecommitdiffstats
path: root/avahi-client
diff options
context:
space:
mode:
authorTrent Lloyd <lathiat@bur.st>2005-08-11 15:10:55 +0000
committerTrent Lloyd <lathiat@bur.st>2005-08-11 15:10:55 +0000
commit98b772ffc6e06ca0e19c2d31326c281a77646367 (patch)
treeae314039b708640e62fbe3435bb40beb873c4865 /avahi-client
parentfde1c3d1a0156f0e06a819cc0958ec077a88c8c6 (diff)
* Add ServiceTypeBrowser support to C API
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@290 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-client')
-rw-r--r--avahi-client/browser.c109
-rw-r--r--avahi-client/client-test.c17
-rw-r--r--avahi-client/client.c9
-rw-r--r--avahi-client/client.h18
-rw-r--r--avahi-client/internal.h15
5 files changed, 160 insertions, 8 deletions
diff --git a/avahi-client/browser.c b/avahi-client/browser.c
index 292162c..3e30110 100644
--- a/avahi-client/browser.c
+++ b/avahi-client/browser.c
@@ -40,6 +40,8 @@
#include "client.h"
#include "internal.h"
+/* AvahiDomainBrowser */
+
AvahiDomainBrowser* avahi_domain_browser_new (AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, char *domain, AvahiDomainBrowserType btype, AvahiDomainBrowserCallback callback, void *user_data)
{
AvahiDomainBrowser *tmp = NULL;
@@ -93,7 +95,7 @@ avahi_domain_browser_path (AvahiDomainBrowser *b)
}
DBusHandlerResult
-avahi_entry_group_event (AvahiClient *client, AvahiBrowserEvent event, DBusMessage *message)
+avahi_domain_browser_event (AvahiClient *client, AvahiBrowserEvent event, DBusMessage *message)
{
AvahiDomainBrowser *n, *db = NULL;
DBusError error;
@@ -105,7 +107,6 @@ avahi_entry_group_event (AvahiClient *client, AvahiBrowserEvent event, DBusMessa
path = dbus_message_get_path (message);
- printf ("bailing out 1\n");
if (path == NULL)
goto out;
@@ -118,14 +119,12 @@ avahi_entry_group_event (AvahiClient *client, AvahiBrowserEvent event, DBusMessa
}
}
- printf ("bailing out 2\n");
if (db == NULL)
goto out;
dbus_message_get_args (message, &error, DBUS_TYPE_INT32, &interface,
DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &domain, DBUS_TYPE_INVALID);
- printf ("bailing out 3\n");
if (dbus_error_is_set (&error))
goto out;
@@ -137,3 +136,105 @@ out:
dbus_error_free (&error);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
+
+/* AvahiServiceTypeBrowser */
+AvahiServiceTypeBrowser* avahi_service_type_browser_new (AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, char *domain, AvahiServiceTypeBrowserCallback callback, void *user_data)
+{
+ AvahiServiceTypeBrowser *tmp = NULL;
+ DBusMessage *message = NULL, *reply;
+ DBusError error;
+ char *path;
+
+ if (client == NULL)
+ return NULL;
+
+ dbus_error_init (&error);
+
+ message = dbus_message_new_method_call (AVAHI_DBUS_NAME,
+ AVAHI_DBUS_PATH_SERVER,
+ AVAHI_DBUS_INTERFACE_SERVER,
+ "ServiceTypeBrowserNew");
+
+ if (!dbus_message_append_args (message, DBUS_TYPE_INT32, &interface, DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &domain, DBUS_TYPE_INVALID))
+ goto dbus_error;
+
+ reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error);
+
+ if (dbus_error_is_set (&error) || reply == NULL)
+ goto dbus_error;
+
+ if (!dbus_message_get_args (reply, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID))
+ goto dbus_error;
+
+ if (dbus_error_is_set (&error) || path == NULL)
+ goto dbus_error;
+
+ tmp = malloc (sizeof (AvahiServiceTypeBrowser));
+ tmp->client = client;
+ tmp->callback = callback;
+ tmp->user_data = user_data;
+ tmp->path = strdup (path);
+
+ AVAHI_LLIST_PREPEND(AvahiServiceTypeBrowser, service_type_browsers, client->service_type_browsers, tmp);
+
+ return tmp;
+
+dbus_error:
+ dbus_error_free (&error);
+ avahi_client_set_errno (client, AVAHI_ERR_DBUS_ERROR);
+
+ return NULL;
+}
+
+char*
+avahi_service_type_browser_path (AvahiServiceTypeBrowser *b)
+{
+ return b->path;
+}
+
+DBusHandlerResult
+avahi_service_type_browser_event (AvahiClient *client, AvahiBrowserEvent event, DBusMessage *message)
+{
+ AvahiServiceTypeBrowser *n, *db = NULL;
+ DBusError error;
+ const char *path;
+ char *domain, *type;
+ int interface, protocol;
+
+ dbus_error_init (&error);
+
+ path = dbus_message_get_path (message);
+
+ if (path == NULL)
+ goto out;
+
+ for (n = client->service_type_browsers; n != NULL; n = n->service_type_browsers_next)
+ {
+ printf ("cmp: %s, %s\n", n->path, path);
+ if (strcmp (n->path, path) == 0) {
+ db = n;
+ break;
+ }
+ }
+
+ if (db == NULL)
+ goto out;
+
+ dbus_message_get_args (message, &error,
+ DBUS_TYPE_INT32, &interface,
+ DBUS_TYPE_INT32, &protocol,
+ DBUS_TYPE_STRING, &type,
+ DBUS_TYPE_STRING, &domain,
+ DBUS_TYPE_INVALID);
+
+ if (dbus_error_is_set (&error))
+ goto out;
+
+ db->callback (db, interface, protocol, event, type, domain, db->user_data);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+
+out:
+ dbus_error_free (&error);
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
diff --git a/avahi-client/client-test.c b/avahi-client/client-test.c
index f55d1e4..2a1690d 100644
--- a/avahi-client/client-test.c
+++ b/avahi-client/client-test.c
@@ -39,9 +39,14 @@ avahi_entry_group_callback (AvahiEntryGroup *g, AvahiEntryGroupState state, void
void
avahi_domain_browser_callback (AvahiDomainBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, char *domain, void *user_data)
{
- printf ("XXX: Callback on %s, event -> %d, domain -> %s, data -> %s\n", avahi_domain_browser_path (b), event, domain, (char*)user_data);
+ printf ("XXX: Callback on %s, interface (%d), protocol (%d), event (%d), domain (%s), data (%s)\n", avahi_domain_browser_path (b), interface, protocol, event, domain, (char*)user_data);
}
+void
+avahi_service_type_browser_callback (AvahiServiceTypeBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, char *type, char *domain, void *user_data)
+{
+ printf ("XXX: Callback on %s, interface (%d), protocol (%d), event (%d), type (%s), domain (%s), data (%s)\n", avahi_service_type_browser_path (b), interface, protocol, event, type, domain, (char*)user_data);
+}
int
main (int argc, char *argv[])
{
@@ -50,6 +55,7 @@ main (int argc, char *argv[])
AvahiEntryGroup *group;
AvahiStringList *txt;
AvahiDomainBrowser *domain;
+ AvahiServiceTypeBrowser *st;
char *ret;
loop = g_main_loop_new (NULL, FALSE);
@@ -93,7 +99,14 @@ main (int argc, char *argv[])
if (domain == NULL)
printf ("Failed to create domain browser object\n");
else
- printf ("Sucessfully created browser, path %s\n", avahi_domain_browser_path (domain));
+ printf ("Sucessfully created domain browser, path %s\n", avahi_domain_browser_path (domain));
+
+ st = avahi_service_type_browser_new (avahi, AVAHI_IF_UNSPEC, AF_UNSPEC, "", avahi_service_type_browser_callback, "omghai3u");
+ if (st == NULL)
+ printf ("Failed to create service type browser object\n");
+ else
+ printf ("Sucessfully created service type browser, path %s\n", avahi_service_type_browser_path (st));
+
g_main_loop_run (loop);
diff --git a/avahi-client/client.c b/avahi-client/client.c
index 485444c..46b7b37 100644
--- a/avahi-client/client.c
+++ b/avahi-client/client.c
@@ -176,9 +176,13 @@ filter_func (DBusConnection *bus, DBusMessage *message, void *data)
avahi_entry_group_state_change (group, state);
}
} else if (dbus_message_is_signal (message, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "ItemNew")) {
- return avahi_entry_group_event (client, AVAHI_BROWSER_NEW, message);
+ return avahi_domain_browser_event (client, AVAHI_BROWSER_NEW, message);
} else if (dbus_message_is_signal (message, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "ItemRemove")) {
- return avahi_entry_group_event (client, AVAHI_BROWSER_REMOVE, message);
+ return avahi_domain_browser_event (client, AVAHI_BROWSER_REMOVE, message);
+ } else if (dbus_message_is_signal (message, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "ItemNew")) {
+ return avahi_service_type_browser_event (client, AVAHI_BROWSER_NEW, message);
+ } else if (dbus_message_is_signal (message, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "ItemRemove")) {
+ return avahi_service_type_browser_event (client, AVAHI_BROWSER_REMOVE, message);
}
return DBUS_HANDLER_RESULT_HANDLED;
@@ -200,6 +204,7 @@ avahi_client_new (AvahiClientCallback callback, void *user_data)
AVAHI_LLIST_HEAD_INIT(AvahiEntryGroup, tmp->groups);
AVAHI_LLIST_HEAD_INIT(AvahiDomainBrowser, tmp->domain_browsers);
+ AVAHI_LLIST_HEAD_INIT(AvahiServieTypeBrowser, tmp->service_type_browsers);
dbus_error_init (&error);
diff --git a/avahi-client/client.h b/avahi-client/client.h
index 4e06762..a7ca4e7 100644
--- a/avahi-client/client.h
+++ b/avahi-client/client.h
@@ -39,6 +39,8 @@ typedef struct _AvahiEntryGroup AvahiEntryGroup;
typedef struct _AvahiDomainBrowser AvahiDomainBrowser;
+typedef struct _AvahiServiceTypeBrowser AvahiServiceTypeBrowser;
+
/** States of a client object, note that AvahiServerStates are also emitted */
typedef enum {
AVAHI_CLIENT_DISCONNECTED = 100, /**< Lost DBUS connection to the Avahi daemon */
@@ -54,6 +56,9 @@ typedef void (*AvahiEntryGroupCallback) (AvahiEntryGroup *g, AvahiEntryGroupStat
/** The function prototype for the callback of an AvahiDomainBrowser */
typedef void (*AvahiDomainBrowserCallback) (AvahiDomainBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, char *domain, void *user_data);
+/** The function prototype for the callback of an AvahiServiceTypeBrowser */
+typedef void (*AvahiServiceTypeBrowserCallback) (AvahiServiceTypeBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, char *type, char *domain, void *user_data);
+
/** Creates a new client instance */
AvahiClient* avahi_client_new (AvahiClientCallback callback, void *user_data);
@@ -117,6 +122,19 @@ AvahiDomainBrowser* avahi_domain_browser_new (AvahiClient *client,
AvahiDomainBrowserCallback callback,
void *user_data);
+/** Get the D-Bus path of an AvahiServiceTypeBrowser object, for debugging purposes only. */
+char* avahi_service_type_browser_path (AvahiServiceTypeBrowser *);
+
+/** Browse for service types on the local network */
+AvahiServiceTypeBrowser* avahi_service_type_browser_new (
+ AvahiClient *client,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ char *domain,
+ AvahiServiceTypeBrowserCallback callback,
+ void *user_data);
+
+
#ifndef DOXYGEN_SHOULD_SKIP_THIS
AVAHI_C_DECL_END
#endif
diff --git a/avahi-client/internal.h b/avahi-client/internal.h
index 72c01de..e1f4662 100644
--- a/avahi-client/internal.h
+++ b/avahi-client/internal.h
@@ -26,6 +26,8 @@
#include <config.h>
#endif
+#include <dbus/dbus.h>
+
struct _AvahiClient
{
DBusConnection *bus;
@@ -34,6 +36,7 @@ struct _AvahiClient
void *user_data;
AVAHI_LLIST_HEAD(AvahiEntryGroup, groups);
AVAHI_LLIST_HEAD(AvahiDomainBrowser, domain_browsers);
+ AVAHI_LLIST_HEAD(AvahiServiceTypeBrowser, service_type_browsers);
};
struct _AvahiEntryGroup {
@@ -52,8 +55,20 @@ struct _AvahiDomainBrowser {
AVAHI_LLIST_FIELDS(AvahiDomainBrowser, domain_browsers);
};
+struct _AvahiServiceTypeBrowser {
+ char *path;
+ AvahiClient *client;
+ AvahiServiceTypeBrowserCallback callback;
+ void *user_data;
+ AVAHI_LLIST_FIELDS(AvahiServiceTypeBrowser, service_type_browsers);
+};
+
int avahi_client_set_errno (AvahiClient *client, int errno);
void avahi_entry_group_state_change (AvahiEntryGroup *group, int state);
+DBusHandlerResult avahi_domain_browser_event (AvahiClient *client, AvahiBrowserEvent event, DBusMessage *message);
+
+DBusHandlerResult avahi_service_type_browser_event (AvahiClient *client, AvahiBrowserEvent event, DBusMessage *message);
+
#endif