+/* $Id$ */
+
/***
This file is part of avahi.
private int iface;
private Protocol proto;
private string domain;
+ private ServiceTypeBrowserCallback cb;
private ArrayList addListeners = new ArrayList ();
private ArrayList removeListeners = new ArrayList ();
this.iface = iface;
this.proto = proto;
this.domain = domain;
+ cb = OnServiceTypeBrowserCallback;
}
~ServiceTypeBrowser ()
private void Start ()
{
- if (handle != IntPtr.Zero || (addListeners.Count == 0 && removeListeners.Count == 0))
+ if (client.Handle == IntPtr.Zero || handle != IntPtr.Zero ||
+ (addListeners.Count == 0 && removeListeners.Count == 0))
return;
- IntPtr domainPtr = Utility.StringToPtr (domain);
- handle = avahi_service_type_browser_new (client.Handle, iface, (int) proto, domainPtr,
- OnServiceTypeBrowserCallback, IntPtr.Zero);
- Utility.Free (domainPtr);
+ lock (client) {
+ IntPtr domainPtr = Utility.StringToPtr (domain);
+ handle = avahi_service_type_browser_new (client.Handle, iface, (int) proto, domainPtr,
+ cb, IntPtr.Zero);
+ Utility.Free (domainPtr);
+ }
}
private void Stop (bool force)
{
- if (handle != IntPtr.Zero && (force || (addListeners.Count == 0 && removeListeners.Count == 0))) {
- avahi_service_type_browser_free (handle);
- handle = IntPtr.Zero;
+ if (client.Handle != IntPtr.Zero && handle != IntPtr.Zero &&
+ (force || (addListeners.Count == 0 && removeListeners.Count == 0))) {
+
+ lock (client) {
+ avahi_service_type_browser_free (handle);
+ handle = IntPtr.Zero;
+ }
}
}