Skip to content

Commit

Permalink
ServiceBrowser: add Services property which is synchronized with the …
Browse files Browse the repository at this point in the history
…user events
  • Loading branch information
tmds committed Nov 25, 2013
1 parent 0a6210e commit ab361ba
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Tmds/MDns/ServiceBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void StartBrowse(string serviceType)
public QueryParameters QueryParameters { get; private set; }
public SynchronizationContext SynchronizationContext { get; set; }
public bool IsBrowsing { get; private set; }
public IEnumerator<ServiceAnnouncement> Services { get { return _services.GetEnumerator(); } }

public event EventHandler<ServiceAnnouncementEventArgs> ServiceAdded;
public event EventHandler<ServiceAnnouncementEventArgs> ServiceRemoved;
Expand All @@ -78,6 +79,10 @@ internal void OnServiceAdded(ServiceInfo service)
_serviceAnnouncements.Add(Tuple.Create(service.NetworkInterface.Id, service.Name), announcement);
SynchronizationContextPost(o =>
{
lock (_services)
{
_services.Add(announcement);
}
if (ServiceAdded != null)
{
ServiceAdded(this, new ServiceAnnouncementEventArgs(announcement));
Expand All @@ -93,6 +98,10 @@ internal void OnServiceRemoved(ServiceInfo service)
SynchronizationContextPost(o =>
{
announcement.IsRemoved = true;
lock (_services)
{
_services.Remove(announcement);
}
if (ServiceRemoved != null)
{
ServiceRemoved(this, new ServiceAnnouncementEventArgs(announcement));
Expand Down Expand Up @@ -229,6 +238,7 @@ private void SynchronizationContextPost(SendOrPostCallback cb)
}
}

private readonly HashSet<ServiceAnnouncement> _services = new HashSet<ServiceAnnouncement>();
private readonly Dictionary<Tuple<string, Name>, ServiceAnnouncement> _serviceAnnouncements = new Dictionary<Tuple<string, Name>, ServiceAnnouncement>();
private readonly List<string> _serviceTypes = new List<string>();
private Dictionary<int, NetworkInterfaceHandler> _interfaceHandlers;
Expand Down

0 comments on commit ab361ba

Please sign in to comment.