From 301fa1a42180ca207244dec66e7fca065fdb06b9 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 11 Feb 2012 20:23:38 +0100 Subject: [PATCH] listener: rename some methods --- SparkleLib/SparkleListenerBase.cs | 15 +++++++-------- SparkleLib/SparkleListenerFactory.cs | 2 +- SparkleLib/SparkleListenerTcp.cs | 18 +++++++----------- SparkleLib/SparkleRepoBase.cs | 4 ++-- 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/SparkleLib/SparkleListenerBase.cs b/SparkleLib/SparkleListenerBase.cs index 89e1406b..5e92143a 100755 --- a/SparkleLib/SparkleListenerBase.cs +++ b/SparkleLib/SparkleListenerBase.cs @@ -40,8 +40,8 @@ namespace SparkleLib { public abstract void Connect (); public abstract bool IsConnected { get; } public abstract bool IsConnecting { get; } - protected abstract void Announce (SparkleAnnouncement announcent); - protected abstract void AlsoListenTo (string folder_identifier); + protected abstract void AnnounceInternal (SparkleAnnouncement announcent); + protected abstract void AlsoListenToInternal (string folder_identifier); protected List channels = new List (); @@ -78,7 +78,7 @@ namespace SparkleLib { } - public void AnnounceBase (SparkleAnnouncement announcement) + public void Announce (SparkleAnnouncement announcement) { if (!IsRecentAnnouncement (announcement)) { if (IsConnected) { @@ -86,7 +86,7 @@ namespace SparkleLib { "Announcing message " + announcement.Message + " to " + announcement.FolderIdentifier + " on " + Server); - Announce (announcement); + AnnounceInternal (announcement); AddRecentAnnouncement (announcement); } else { @@ -105,15 +105,14 @@ namespace SparkleLib { } - // TODO: rename override method instead? - public void AlsoListenToBase (string channel) + public void AlsoListenTo (string channel) { if (!this.channels.Contains (channel) && IsConnected) { SparkleHelpers.DebugInfo ("Listener", "Subscribing to channel " + channel); this.channels.Add (channel); - AlsoListenTo (channel); + AlsoListenToInternal (channel); } } @@ -138,7 +137,7 @@ namespace SparkleLib { foreach (KeyValuePair item in this.queue_up) { SparkleAnnouncement announcement = item.Value; - AnnounceBase (announcement); + Announce (announcement); } this.queue_down.Clear (); diff --git a/SparkleLib/SparkleListenerFactory.cs b/SparkleLib/SparkleListenerFactory.cs index 6da29c35..f6fabbcf 100644 --- a/SparkleLib/SparkleListenerFactory.cs +++ b/SparkleLib/SparkleListenerFactory.cs @@ -64,7 +64,7 @@ namespace SparkleLib { // We already seem to have a listener for this server, // refer to the existing one instead - listener.AlsoListenToBase (folder_identifier); + listener.AlsoListenTo (folder_identifier); return (SparkleListenerBase) listener; } } diff --git a/SparkleLib/SparkleListenerTcp.cs b/SparkleLib/SparkleListenerTcp.cs index 34e38702..1bb38a1d 100755 --- a/SparkleLib/SparkleListenerTcp.cs +++ b/SparkleLib/SparkleListenerTcp.cs @@ -83,15 +83,8 @@ namespace SparkleLib { OnConnected (); // Subscribe to channels of interest to us - foreach (string channel in base.channels) { - SparkleHelpers.DebugInfo ("ListenerTcp", - "Subscribing to channel " + channel + " on " + Server); - - byte [] subscribe_bytes = - Encoding.UTF8.GetBytes ("subscribe " + channel + "\n"); - - this.socket.Send (subscribe_bytes); - } + foreach (string channel in base.channels) + AlsoListenToInternal (channel); } } catch (SocketException e) { @@ -204,8 +197,11 @@ namespace SparkleLib { } - protected override void AlsoListenTo (string folder_identifier) + protected override void AlsoListenToInternal (string folder_identifier) { + SparkleHelpers.DebugInfo ("ListenerTcp", + "Subscribing to channel " + folder_identifier + " on " + Server); + string to_send = "subscribe " + folder_identifier + "\n"; try { @@ -223,7 +219,7 @@ namespace SparkleLib { } - protected override void Announce (SparkleAnnouncement announcement) + protected override void AnnounceInternal (SparkleAnnouncement announcement) { string to_send = "announce " + announcement.FolderIdentifier + " " + announcement.Message + "\n"; diff --git a/SparkleLib/SparkleRepoBase.cs b/SparkleLib/SparkleRepoBase.cs index d493c1de..8d797c75 100755 --- a/SparkleLib/SparkleRepoBase.cs +++ b/SparkleLib/SparkleRepoBase.cs @@ -352,7 +352,7 @@ namespace SparkleLib { if (SyncStatusChanged != null) SyncStatusChanged (SyncStatus.Idle); - this.listener.AnnounceBase (new SparkleAnnouncement (Identifier, CurrentRevision)); + this.listener.Announce (new SparkleAnnouncement (Identifier, CurrentRevision)); } else { SparkleHelpers.DebugInfo ("SyncUp", "[" + Name + "] Error"); @@ -367,7 +367,7 @@ namespace SparkleLib { if (SyncStatusChanged != null) SyncStatusChanged (SyncStatus.Idle); - this.listener.AnnounceBase (new SparkleAnnouncement (Identifier, CurrentRevision)); + this.listener.Announce (new SparkleAnnouncement (Identifier, CurrentRevision)); } else { this.server_online = false;