beagle r4830 - trunk/beagle/Util



Author: dbera
Date: Mon Jul 14 15:04:38 2008
New Revision: 4830
URL: http://svn.gnome.org/viewvc/beagle?rev=4830&view=rev

Log:
Ahh... I made the mistake of catching a runtime exception; unfortunately that code got shipped and now cannot be taken back. Cushion the mistake by printing an error message and adding a FIXME in the code. Also, do galago_init() only once instead of init() and uninit() every time the functions are called.


Modified:
   trunk/beagle/Util/Galago.cs

Modified: trunk/beagle/Util/Galago.cs
==============================================================================
--- trunk/beagle/Util/Galago.cs	(original)
+++ trunk/beagle/Util/Galago.cs	Mon Jul 14 15:04:38 2008
@@ -29,11 +29,8 @@
 
 namespace Beagle.Util {
 
-	public class GalagoTools {
+	public static class GalagoTools {
 
-		private GalagoTools () {} // This class is static
-		private static Galago.Service service;
-	
 		public enum Status {
 			Available = 0,
 			Offline = 1,
@@ -42,17 +39,27 @@
 			NoStatus = -1,
 		};
 
-		public static Status GetPresence (string service_id, string username)
+		private static bool init;
+
+		static GalagoTools ()
 		{
+			// Init only once. I see no reason to init and uninit during every function invocation.
 			try {
-				if (! Galago.Global.Init ("beagle-galago-presence"))
-					return Status.NoStatus;
+				init = Galago.Global.Init ("beagle-galago-presence");
 			} catch (DllNotFoundException) {
-				// Catch Debian Galago packaging bug
-				return Status.NoStatus;
+				// FIXME: Catch Debian Galago packaging bug.
+				// Catching runtime exceptions is not right. Do here but monitor the distro bug.
+				init = false;
+				Console.Error.WriteLine ("Galago init failed. No buddy information will be provided.");
 			}
+		}
 
-			service = Galago.Global.GetService (service_id, Galago.Origin.Remote, true);
+		public static Status GetPresence (string service_id, string username)
+		{
+			if (! init)
+				return Status.NoStatus;
+
+			Galago.Service service = Galago.Global.GetService (service_id, Galago.Origin.Remote, true);
 			if (service == null)
 				return Status.NoStatus;
 
@@ -86,16 +93,16 @@
 						break;
 				}
 			}
-			Galago.Global.Uninit();
 
 			return user_status;
 		}
+
 		public static string GetIdleTime (string service_id, string username)
 		{
-			if (! Galago.Global.Init ("beagle-galago-presence"))
+			if (! init)
 				return null;
 
-			service = Galago.Global.GetService (service_id, Galago.Origin.Remote, true);
+			Galago.Service service = Galago.Global.GetService (service_id, Galago.Origin.Remote, true);
 			if (service == null)
 				return null;
 
@@ -111,7 +118,6 @@
 			
 			string str =  StringFu.DurationToPrettyString  ( DateTime.Now, presence.IdleStartTime);
 			
-			Galago.Global.Uninit();
 			return str;
 		}
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]