conduit r1334 - in trunk/conduit-sharp: . src test



Author: thomasvm
Date: Wed Feb 20 07:21:41 2008
New Revision: 1334
URL: http://svn.gnome.org/viewvc/conduit?rev=1334&view=rev

Log:
2008-02-20  Thomas Van Machelen <thomas vanmachelen gmail com>

	* src/Delegates: move delegates into separate file

	* src/Application.cs:
	* src/Conduit.cs:
	* src/Exporter.cs:
	* src/SyncSet.cs: add missing pieces of the dbus api, more objects,
	more methods

	* test/test-conduit.cs: add test for conduit, demonstrating events
	handling

	* configure.ac: depend on gtk-sharp, and ndesk-dbus-glib as well
	for demonstrating its usage in test-conduit


Added:
   trunk/conduit-sharp/src/Delegates.cs
   trunk/conduit-sharp/src/Exporter.cs
   trunk/conduit-sharp/test/test-conduit.cs
Modified:
   trunk/conduit-sharp/ChangeLog
   trunk/conduit-sharp/configure.ac
   trunk/conduit-sharp/src/Application.cs
   trunk/conduit-sharp/src/Conduit.cs
   trunk/conduit-sharp/src/Makefile.am
   trunk/conduit-sharp/src/SyncSet.cs
   trunk/conduit-sharp/src/src.mdp
   trunk/conduit-sharp/test/Makefile.am
   trunk/conduit-sharp/test/test-application.cs
   trunk/conduit-sharp/test/test.mdp

Modified: trunk/conduit-sharp/configure.ac
==============================================================================
--- trunk/conduit-sharp/configure.ac	(original)
+++ trunk/conduit-sharp/configure.ac	Wed Feb 20 07:21:41 2008
@@ -50,12 +50,15 @@
 	AM_CONDITIONAL(BUILD_DOCS, false)
 fi
 
-PKG_CHECK_MODULES(GLIBSHARP, glib-sharp-2.0 > 2.10.0)
-AC_SUBST(GLIBSHARP_LIBS)
+PKG_CHECK_MODULES(GTKSHARP, gtk-sharp-2.0 > 2.10.0)
+AC_SUBST(GTKSHARP_LIBS)
 
 PKG_CHECK_MODULES(NDESKDBUS, ndesk-dbus-1.0 >= 0.4.0)
 AC_SUBST(NDESKDBUS_LIBS)
 
+PKG_CHECK_MODULES(NDESKDBUSGLIB, ndesk-dbus-glib-1.0 >= 0.3.0)
+AC_SUBST(NDESKDBUSGLIB_LIBS)
+
 AC_OUTPUT([
 	Makefile
 	conduit-sharp.pc

Modified: trunk/conduit-sharp/src/Application.cs
==============================================================================
--- trunk/conduit-sharp/src/Application.cs	(original)
+++ trunk/conduit-sharp/src/Application.cs	Wed Feb 20 07:21:41 2008
@@ -1,12 +1,13 @@
 using System;
 using NDesk.DBus;
+
 namespace Conduit {
  	[Interface("org.conduit.Application")]
-	internal interface IApplication {
+	internal interface IApplication  {
 
 	 	ObjectPath BuildConduit (ObjectPath source, ObjectPath sink);
 
-	 	ObjectPath BuildConduit (string key);
+	 	ObjectPath BuildExporter (string key);
 
 		string[] GetAllDataProviders (); 
 
@@ -15,31 +16,59 @@
 		ObjectPath NewSyncSet ();
 
 		void Quit ();
+
+		event KeyCallBack DataproviderAvailable;
+
+		event KeyCallBack DataproviderUnavailable;
 	}
 
 	public class Application {
-		private IApplication dbus_application = null;
+		public event KeyCallBack DataProviderAvailable;
+		public event KeyCallBack DataProviderUnavailable;
+
+		private IApplication application_proxy = null;
 
 		public Application() {
 			if (!Bus.Session.NameHasOwner(Util.APPLICATION_BUSNAME))
 				throw new Exception("Conduit is not available.");
-			
-	        dbus_application = Util.GetObject<IApplication> (new ObjectPath ("/"));
+		
+			// get proxy	
+			application_proxy = Util.GetObject<IApplication> (new ObjectPath ("/"));
+
+			// connect to events to raise our own
+			application_proxy.DataproviderAvailable += HandleDataProviderAvailable;
+			application_proxy.DataproviderUnavailable += HandleDataProviderUnavailable;
 		}
 
 		public Conduit BuildConduit (DataProvider source, DataProvider sink) {
-			ObjectPath path = dbus_application.BuildConduit (source.Path, sink.Path); 
+			ObjectPath path = application_proxy.BuildConduit (source.Path, sink.Path); 
 			return new Conduit (path);
 		}
 
+		public Exporter BuildExporter (string key) {
+		 	ObjectPath path = application_proxy.BuildExporter (key);
+			return new Exporter (path);
+		}
+
 		public string[] GetAllDataProviders () {
-			return dbus_application.GetAllDataProviders (); 
+			return application_proxy.GetAllDataProviders (); 
 		}
 
 		public DataProvider GetDataProvider (string key) {
-			ObjectPath path = dbus_application.GetDataProvider (key); 
+			ObjectPath path = application_proxy.GetDataProvider (key); 
 			return new DataProvider (path);
 		}
+		
+		// Proxy event handlers
+
+		private void HandleDataProviderAvailable (string key) {
+			if (DataProviderAvailable != null)
+			 	DataProviderAvailable (key); 
+		}
 
+		private void HandleDataProviderUnavailable (string key) {
+			if (DataProviderUnavailable != null)
+			 	DataProviderUnavailable (key); 
+		}
 	}
 }

Modified: trunk/conduit-sharp/src/Conduit.cs
==============================================================================
--- trunk/conduit-sharp/src/Conduit.cs	(original)
+++ trunk/conduit-sharp/src/Conduit.cs	Wed Feb 20 07:21:41 2008
@@ -4,6 +4,7 @@
 namespace Conduit {
 	[Interface("org.conduit.Conduit")]
 	internal interface IConduit {
+		// Methods
 		void AddDataProvider (ObjectPath dp, bool trySource);
 		
 		void DeleteDataProvider (ObjectPath dp);
@@ -17,46 +18,92 @@
 		void Refresh();
 		
 		void Sync();
+		
+		// Events
+		event EmptyCallBack SyncStarted;
+		
+		event EmptyCallBack SyncConflict;
+		
+		event SyncProgressCallBack SyncProgress;
+		
+		event SyncCompletedCallBack SyncCompleted;
+
 	}
 
 	public class Conduit {
-		private IConduit dbus_conduit;
+		private IConduit conduit_proxy;
 		private ObjectPath path;
+		
+		public event EmptyCallBack SyncStarted;
+		
+		public event EmptyCallBack SyncConflict;
+		
+		public event SyncProgressCallBack SyncProgress;
+		
+		public event SyncCompletedCallBack SyncCompleted;
 
 		public ObjectPath Path {
 			get { return path; } 
 		}
 
-	 	public Conduit (ObjectPath path) {
-	 		dbus_conduit = Util.GetObject<IConduit> (path);
+	 	internal Conduit (ObjectPath path) {
+	 		conduit_proxy = Util.GetObject<IConduit> (path);
 		 	this.path = path;
+			
+			// hookup events
+			conduit_proxy.SyncStarted += HandleSyncStarted;
+			conduit_proxy.SyncCompleted += HandleSyncCompleted;		
+			conduit_proxy.SyncProgress += HandleSyncProgress;
+			conduit_proxy.SyncConflict += HandleSyncConflict;
 		}
 		
 		public void AddDataProvider (DataProvider dp, bool trySource) {
-			dbus_conduit.AddDataProvider(dp.Path, trySource);		
+			conduit_proxy.AddDataProvider(dp.Path, trySource);		
 		}
 		
 		public void DeleteDataProvider (DataProvider dp) {
-			dbus_conduit.DeleteDataProvider(dp.Path);
+			conduit_proxy.DeleteDataProvider(dp.Path);
 		}
 		
 		public void DisableTwoWaySync () {
-			dbus_conduit.DisableTwoWaySync();
+			conduit_proxy.DisableTwoWaySync();
 		}
 		
 		public void EnableTwoWaySync () {
-			dbus_conduit.EnableTwoWaySync();	
+			conduit_proxy.EnableTwoWaySync();	
 		}
 		
 		public bool IsTwoWay () {
-			return dbus_conduit.IsTwoWay();
+			return conduit_proxy.IsTwoWay();
 		}
 		public void Refresh() {
-			dbus_conduit.Refresh();
+			conduit_proxy.Refresh();
 		}
 		
 		public void Sync() {
-			dbus_conduit.Sync();
+			conduit_proxy.Sync();
 		}
+		
+		// Proxy event handlers
+		
+		private void HandleSyncStarted() {
+			if (SyncStarted != null)
+				SyncStarted ();
+		}
+		
+		private void HandleSyncConflict () {
+			if (SyncConflict != null)
+				SyncConflict ();
+		}
+		
+		private void HandleSyncCompleted (bool aborted, bool error, bool conflict) {
+			if (SyncCompleted != null)
+				SyncCompleted (aborted, error, conflict);
+		}
+		
+		private void HandleSyncProgress (double progress) {
+			if (SyncProgress != null)
+				SyncProgress (progress);
+		}		
 	} 
 }

Added: trunk/conduit-sharp/src/Delegates.cs
==============================================================================
--- (empty file)
+++ trunk/conduit-sharp/src/Delegates.cs	Wed Feb 20 07:21:41 2008
@@ -0,0 +1,12 @@
+using System;
+
+namespace Conduit
+{
+	// General
+	public delegate void KeyCallBack (string key);
+	public delegate void EmptyCallBack ();
+	
+	// Conduit
+	public delegate void SyncCompletedCallBack (bool aborted, bool error, bool conflict);
+	public delegate void SyncProgressCallBack (double progress);
+}

Added: trunk/conduit-sharp/src/Exporter.cs
==============================================================================
--- (empty file)
+++ trunk/conduit-sharp/src/Exporter.cs	Wed Feb 20 07:21:41 2008
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+
+using NDesk.DBus;
+
+namespace Conduit {
+ 	[Interface("org.conduit.Exporter")]
+	internal interface IExporter {
+		bool AddData (string uri);
+		
+		void SinkConfigure();
+		
+		string SinkGetConfigurationXml ();
+
+		void SinkSetConfigurationXml (string xml);
+
+		IDictionary<string, string> SinkGetInformation ();
+	} 
+
+	public class Exporter {
+	 	private IExporter exporter_proxy;
+		private ObjectPath path;
+
+		internal Exporter (ObjectPath path) {
+			this.exporter_proxy = Util.GetObject<IExporter> (path);
+			this.path = path;
+		}
+
+		public bool AddData (string uri) {
+			return exporter_proxy.AddData (uri);
+		}
+
+		public void Configure () {
+			exporter_proxy.SinkConfigure (); 
+		}
+
+		public string GetConfigurationXml () {
+			return exporter_proxy.SinkGetConfigurationXml (); 
+		}
+
+		public void SinkSetConfigurationXml (string xml) {
+			exporter_proxy.SinkSetConfigurationXml (xml); 
+		}
+
+		public IDictionary<string, string> GetInformation () {
+			return exporter_proxy.SinkGetInformation (); 
+		}
+	}
+}

Modified: trunk/conduit-sharp/src/Makefile.am
==============================================================================
--- trunk/conduit-sharp/src/Makefile.am	(original)
+++ trunk/conduit-sharp/src/Makefile.am	Wed Feb 20 07:21:41 2008
@@ -4,6 +4,8 @@
 	Application.cs		\
 	Conduit.cs		\
 	DataProvider.cs		\
+	Delegates.cs		\
+	Exporter.cs		\
 	SyncSet.cs		\
 	Util.cs
 

Modified: trunk/conduit-sharp/src/SyncSet.cs
==============================================================================
--- trunk/conduit-sharp/src/SyncSet.cs	(original)
+++ trunk/conduit-sharp/src/SyncSet.cs	Wed Feb 20 07:21:41 2008
@@ -12,16 +12,22 @@
 		void RestoreFromXml (string path);
 
 		void SaveToXml (string path);
+
+		event KeyCallBack ConduitAdded;
+		event KeyCallBack ConduitRemoved;
 	}
 
 	public class SyncSet {
 
+		private ISyncSet syncset_proxy;
 		private ObjectPath path;
-		private ISyncSet dbus_syncset;
 
 		private static SyncSet gui;
 		private static SyncSet dbus;
 
+		public event KeyCallBack ConduitAdded;
+		public event KeyCallBack ConduitRemoved;
+
 		public static SyncSet Gui {
 			get {
 				if (gui == null) {
@@ -45,24 +51,38 @@
 		}
 
 	 	private SyncSet (ObjectPath path) {
-			dbus_syncset = Util.GetObject<ISyncSet> (path);
+			syncset_proxy = Util.GetObject<ISyncSet> (path);
 			this.path = path;
+
+			// hookup events
+			syncset_proxy.ConduitAdded += HandleConduitAdded;
+			syncset_proxy.ConduitRemoved += HandleConduitRemoved;
 		}
 
 		public void AddConduit (Conduit conduit) {
-			dbus_syncset.AddConduit (conduit.Path); 
+			syncset_proxy.AddConduit (conduit.Path); 
 		}
 
 		public void DeleteConduit (Conduit conduit) {
-			dbus_syncset.DeleteConduit (conduit.Path); 
+			syncset_proxy.DeleteConduit (conduit.Path); 
 		}
 
 		public void SaveToXml (string path) {
-			dbus_syncset.SaveToXml (path);
+			syncset_proxy.SaveToXml (path);
 		}
 
 		public void RestoreFromXml (string path) {
-			dbus_syncset.RestoreFromXml (path); 
+			syncset_proxy.RestoreFromXml (path); 
+		}
+
+		private void HandleConduitAdded (string key) {
+			if (ConduitAdded != null)
+			 	ConduitAdded (key); 
+		}
+
+		private void HandleConduitRemoved (string key) {
+			if (ConduitRemoved != null)
+			 	ConduitRemoved (key); 
 		}
 	}
 }

Modified: trunk/conduit-sharp/src/src.mdp
==============================================================================
--- trunk/conduit-sharp/src/src.mdp	(original)
+++ trunk/conduit-sharp/src/src.mdp	Wed Feb 20 07:21:41 2008
@@ -20,6 +20,8 @@
     <File name="./SyncSet.cs" subtype="Code" buildaction="Compile" />
     <File name="./Util.cs" subtype="Code" buildaction="Compile" />
     <File name="./conduit-sharp.snk" subtype="Code" buildaction="Nothing" />
+    <File name="./Delegates.cs" subtype="Code" buildaction="Compile" />
+    <File name="./Exporter.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="NDesk.DBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f6716e4f9b2ed099" />

Modified: trunk/conduit-sharp/test/Makefile.am
==============================================================================
--- trunk/conduit-sharp/test/Makefile.am	(original)
+++ trunk/conduit-sharp/test/Makefile.am	Wed Feb 20 07:21:41 2008
@@ -1,4 +1,4 @@
-SAMPLES=test-application.cs 
+SAMPLES=test-application.cs test-conduit.cs
 MCSFLAGS= -debug -nologo -r:conduit-sharp.dll
 
 EXTRA_DIST=$(SAMPLES)
@@ -7,7 +7,7 @@
 noinst_SCRIPTS=$(SAMPLES:.cs=.exe)
 
 %.exe: %.cs conduit-sharp.dll
-	$(MCS) $(MCSFLAGS) `pkg-config --libs glib-sharp-2.0` -out:$@ $<
+	$(MCS) $(MCSFLAGS) $(GTKSHARP_LIBS) $(NDESKDBUSGLIB_LIBS) -out:$@ $<
 
 conduit-sharp.dll: $(top_builddir)/src/conduit-sharp.dll
 	cp $(top_builddir)/src/conduit-sharp.dll* .

Modified: trunk/conduit-sharp/test/test-application.cs
==============================================================================
--- trunk/conduit-sharp/test/test-application.cs	(original)
+++ trunk/conduit-sharp/test/test-application.cs	Wed Feb 20 07:21:41 2008
@@ -12,6 +12,5 @@
 			Console.WriteLine("{0} {1}", keyPair.Key, keyPair.Value);
 		
 		Console.WriteLine("Configured: {0}", dp.IsConfigured(true, true));
-		
 	}
 }

Added: trunk/conduit-sharp/test/test-conduit.cs
==============================================================================
--- (empty file)
+++ trunk/conduit-sharp/test/test-conduit.cs	Wed Feb 20 07:21:41 2008
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using Conduit;
+
+using NDesk.DBus;
+
+public class Program {
+	public static void Main () {
+		BusG.Init ();
+		Gtk.Application.Init ();
+		
+		Conduit.Application app = new Conduit.Application ();
+
+		DataProvider source = app.GetDataProvider ("TestFolderTwoWay");
+		DataProvider sink   = app.GetDataProvider ("TestFolderTwoWay");
+
+		Conduit.Conduit conduit = app.BuildConduit (source, sink);
+		SyncSet.Gui.AddConduit (conduit);
+
+		conduit.SyncStarted += HandleSyncStarted;
+		conduit.SyncProgress += HandleSyncProgress;
+		conduit.SyncCompleted += HandleSyncCompleted;
+
+		Console.WriteLine ("Now Synchronise the Conduit...");
+
+		// mainloop, for events processing
+		Gtk.Application.Run ();
+	}
+
+	private static void HandleSyncStarted () {
+		Console.WriteLine ("Sync Started");
+	}
+	private static void HandleSyncProgress (double progress) {
+		Console.WriteLine ("Sync Progress");
+	}
+	private static void HandleSyncCompleted (bool aborted, bool error, bool conflict) {
+		Console.WriteLine ("Sync Completed");
+		Gtk.Application.Quit ();
+	}
+}
+

Modified: trunk/conduit-sharp/test/test.mdp
==============================================================================
--- trunk/conduit-sharp/test/test.mdp	(original)
+++ trunk/conduit-sharp/test/test.mdp	Wed Feb 20 07:21:41 2008
@@ -18,5 +18,7 @@
   </Contents>
   <References>
     <ProjectReference type="Project" localcopy="True" refto="src" />
+    <ProjectReference type="Gac" localcopy="True" refto="NDesk.DBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f6716e4f9b2ed099" />
+    <ProjectReference type="Gac" localcopy="True" refto="NDesk.DBus.GLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f6716e4f9b2ed099" />
   </References>
 </Project>
\ No newline at end of file



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