public Unsubscribe ( string regex, LCMSubscriber sub ) : void | ||
regex | string | regular expression determining the channels to unsubscribe |
sub | LCMSubscriber | unsubscribing object |
return | void |
public void Unsubscribe(string regex, LCMSubscriber sub)
{
if (this.closed)
{
throw new SystemException();
}
lock (this)
{
foreach (Provider p in providers)
{
p.Unsubscribe(regex);
}
}
// TODO: need providers to unsubscribe?
// TODO: providers don't seem to use anything beyond first channel
lock (subscriptions)
{
// Find and remove subscriber from list
foreach (SubscriptionRecord sr in subscriptions.ToArray())
{
if ((sub == null || sr.lcsub == sub) && (regex == null || sr.regex.Equals(regex)))
{
subscriptions.Remove(sr);
}
}
// Find and remove subscriber from map
List<SubscriptionRecord> srecs;
foreach (string channel in subscriptionsMap.Keys)
{
if (subscriptionsMap.TryGetValue(channel, out srecs))
{
foreach (SubscriptionRecord sr in srecs.ToArray())
{
if ((sub == null || sr.lcsub == sub) && (regex == null || sr.regex.Equals(regex)))
{
srecs.Remove(sr);
}
}
}
}
}
}