diff --git a/SparkleLib/SparkleListenerBase.cs b/SparkleLib/SparkleListenerBase.cs index 33cbd92d..af575537 100755 --- a/SparkleLib/SparkleListenerBase.cs +++ b/SparkleLib/SparkleListenerBase.cs @@ -64,7 +64,7 @@ namespace SparkleLib { SparkleHelpers.DebugInfo ("ListenerFactory", "Refered to existing listener for " + announce_uri); - listener.AlsoListenTo (folder_identifier); + listener.AlsoListenToBase (folder_identifier); return (SparkleListenerBase) listener; } } @@ -103,10 +103,10 @@ namespace SparkleLib { public abstract void Connect (); - public abstract void Announce (SparkleAnnouncement announcent); - public abstract void AlsoListenTo (string folder_identifier); public abstract bool IsConnected { get; } public abstract bool IsConnecting { get; } + protected abstract void Announce (SparkleAnnouncement announcent); + protected abstract void AlsoListenTo (string folder_identifier); protected List channels = new List (); @@ -171,6 +171,18 @@ namespace SparkleLib { } + public void AlsoListenToBase (string channel) + { + if (!this.channels.Contains (channel) && IsConnected) { + SparkleHelpers.DebugInfo ("Listener", + "Subscribing to channel " + channel); + + this.channels.Add (channel); + AlsoListenTo (channel); + } + } + + public void Reconnect () { SparkleHelpers.DebugInfo ("Listener", "Trying to reconnect to " + Server); diff --git a/SparkleLib/SparkleListenerTcp.cs b/SparkleLib/SparkleListenerTcp.cs index 547f686d..1849802c 100755 --- a/SparkleLib/SparkleListenerTcp.cs +++ b/SparkleLib/SparkleListenerTcp.cs @@ -145,40 +145,9 @@ namespace SparkleLib { } - public override void AlsoListenTo (string folder_identifier) + protected override void AlsoListenTo (string folder_identifier) { - string channel = folder_identifier; - - if (!base.channels.Contains (channel)) { - base.channels.Add (channel); - - if (IsConnected) { - SparkleHelpers.DebugInfo ("ListenerTcp", "Subscribing to channel " + channel); - - string to_send = "subscribe " + folder_identifier + "\n"; - - try { - lock (this.socket_lock) { - this.socket.Send (Encoding.UTF8.GetBytes (to_send)); - } - - } catch (SocketException e) { - SparkleHelpers.DebugInfo ("ListenerTcp", "Could not connect to " + Server + ": " + e.Message); - this.is_connected = false; - this.is_connecting = false; - - - OnDisconnected (); - } - } - } - } - - - public override void Announce (SparkleAnnouncement announcement) - { - string to_send = "announce " + announcement.FolderIdentifier - + " " + announcement.Message + "\n"; + string to_send = "subscribe " + folder_identifier + "\n"; try { lock (this.socket_lock) { @@ -186,10 +155,34 @@ namespace SparkleLib { } } catch (SocketException e) { - SparkleHelpers.DebugInfo ("ListenerTcp", "Could not connect to " + Server + ": " + e.Message); + SparkleHelpers.DebugInfo ("ListenerTcp", + "Could not connect to " + Server + ": " + e.Message); - this.is_connected = false; - OnDisconnected (); + this.is_connected = false; + this.is_connecting = false; + + OnDisconnected (); + } + } + + + protected override void Announce (SparkleAnnouncement announcement) + { + string to_send = "announce " + announcement.FolderIdentifier + + " " + announcement.Message + "\n"; + + try { + lock (this.socket_lock) + this.socket.Send (Encoding.UTF8.GetBytes (to_send)); + + } catch (SocketException e) { + SparkleHelpers.DebugInfo ("ListenerTcp", + "Could not connect to " + Server + ": " + e.Message); + + this.is_connected = false; + this.is_connecting = false; + + OnDisconnected (); } }