X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-sharp%2FEntryGroup.cs;h=3f8a94cd98f3abfe44a2a06bbba2aa310754df23;hb=740bc001fb647255709b5385d5a8a19781722097;hp=85c9a1d51e5cad7388bd5b3b2ae8ca54a7854d4f;hpb=5af9f469d85a9281bc5484e9f5a8740751591dfe;p=catta diff --git a/avahi-sharp/EntryGroup.cs b/avahi-sharp/EntryGroup.cs index 85c9a1d..3f8a94c 100644 --- a/avahi-sharp/EntryGroup.cs +++ b/avahi-sharp/EntryGroup.cs @@ -26,11 +26,24 @@ using System.Runtime.InteropServices; namespace Avahi { + [Flags] + public enum PublishFlags { + None = 0, + Unique = 1, + NoProbe = 2, + NoAnnounce = 4, + AllowMultiple = 8, + NoReverse = 16, + NoCookie = 32, + Update = 64 + } + public enum EntryGroupState { Uncommited, Registering, Established, - Collision + Collision, + Failure } internal delegate void EntryGroupCallback (IntPtr group, EntryGroupState state, IntPtr userdata); @@ -46,10 +59,10 @@ namespace Avahi private static extern IntPtr avahi_entry_group_new (IntPtr client, EntryGroupCallback cb, IntPtr userdata); [DllImport ("avahi-client")] - private static extern void avahi_entry_group_commit (IntPtr group); + private static extern int avahi_entry_group_commit (IntPtr group); [DllImport ("avahi-client")] - private static extern void avahi_entry_group_reset (IntPtr group); + private static extern int avahi_entry_group_reset (IntPtr group); [DllImport ("avahi-client")] private static extern EntryGroupState avahi_entry_group_get_state (IntPtr group); @@ -58,9 +71,10 @@ namespace Avahi private static extern bool avahi_entry_group_is_empty (IntPtr group); [DllImport ("avahi-client")] - private static extern void avahi_entry_group_add_service_strlst (IntPtr group, int iface, Protocol proto, - IntPtr name, IntPtr type, IntPtr domain, - IntPtr host, UInt16 port, IntPtr strlst); + private static extern int avahi_entry_group_add_service_strlst (IntPtr group, int iface, Protocol proto, + PublishFlags flags, IntPtr name, IntPtr type, + IntPtr domain, IntPtr host, UInt16 port, + IntPtr strlst); [DllImport ("avahi-client")] private static extern void avahi_entry_group_free (IntPtr group); @@ -104,7 +118,8 @@ namespace Avahi lock (client) { handle = avahi_entry_group_new (client.Handle, cb, IntPtr.Zero); - client.CheckError (); + if (handle == IntPtr.Zero) + client.ThrowError (); } } @@ -126,26 +141,32 @@ namespace Avahi public void Commit () { lock (client) { - avahi_entry_group_commit (handle); - client.CheckError (); + if (avahi_entry_group_commit (handle) < 0) + client.ThrowError (); } } public void Reset () { lock (client) { - avahi_entry_group_reset (handle); - client.CheckError (); + if (avahi_entry_group_reset (handle) < 0) + client.ThrowError (); } } public void AddService (string name, string type, string domain, UInt16 port, params string[] txt) { - AddService (-1, Protocol.Unspecified, name, type, domain, null, port, txt); + AddService (PublishFlags.None, name, type, domain, port, txt); + } + + public void AddService (PublishFlags flags, string name, string type, string domain, + UInt16 port, params string[] txt) + { + AddService (-1, Protocol.Unspecified, flags, name, type, domain, null, port, txt); } - public void AddService (int iface, Protocol proto, string name, string type, string domain, + public void AddService (int iface, Protocol proto, PublishFlags flags, string name, string type, string domain, string host, UInt16 port, params string[] txt) { IntPtr list = avahi_string_list_new (IntPtr.Zero); @@ -164,13 +185,14 @@ namespace Avahi IntPtr hostPtr = Utility.StringToPtr (host); lock (client) { - avahi_entry_group_add_service_strlst (handle, iface, proto, namePtr, typePtr, domainPtr, - hostPtr, port, list); + int ret = avahi_entry_group_add_service_strlst (handle, iface, proto, flags, namePtr, typePtr, domainPtr, + hostPtr, port, list); + if (ret < 0) { + client.ThrowError (); + } } avahi_string_list_free (list); - - client.CheckError (); } public static string GetAlternativeServiceName (string name) {