From 7ed95260da40a765007cdf57520b7da53a70d008 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 09:54:22 +0000 Subject: Utilisateur : Fcolin Date : 20/11/03 Heure : 12:46 Archivé dans $/EScribe/Ivy Commentaire: (vss 13) --- CSharp/Ivy/IvyPPC/Ivy.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'CSharp/Ivy') diff --git a/CSharp/Ivy/IvyPPC/Ivy.cs b/CSharp/Ivy/IvyPPC/Ivy.cs index b4a2ef4..18f94e7 100644 --- a/CSharp/Ivy/IvyPPC/Ivy.cs +++ b/CSharp/Ivy/IvyPPC/Ivy.cs @@ -24,7 +24,7 @@ namespace IvyBus public delegate void ClientDisconnectedHandler (IvyClient app); public delegate bool DieHandler (IvyClient app, int id ); - public delegate void MessageHandler (IvyClient app, string[] args ); + public delegate void MessageHandler (object data , IvyClient app, string[] args ); /* Event */ @@ -106,6 +106,7 @@ namespace IvyBus private ArrayList watchers; private volatile Thread serverThread; // to ensure quick communication of the end private Hashtable callbacks; + private Hashtable clients_data; private Hashtable clients; private String[] messages_classes = null; private bool stopped = false; @@ -139,8 +140,9 @@ namespace IvyBus /// public Ivy(String name, String message) { - callbacks = new Hashtable(); + callbacks = Hashtable.Synchronized( new Hashtable() ); clients = Hashtable.Synchronized( new Hashtable() ); + clients_data = Hashtable.Synchronized( new Hashtable() ); regexp_out = Hashtable.Synchronized( new Hashtable()); appName = name; ready_message = message; @@ -345,10 +347,16 @@ namespace IvyBus /// public int bindMsg(String regexp, MessageHandler callback) { + return bindMsg( regexp, callback, null); + } + public int bindMsg(String regexp, MessageHandler callback, object data) + { // creates a new binding (regexp,callback) Int32 key = serial++; + // TODO Make a unique Object grouping lock (regexp_out.SyncRoot) regexp_out.Add( key, regexp); - lock (callback) callbacks.Add( key, callback); + lock (callbacks.SyncRoot) callbacks.Add( key, callback); + lock (clients_data.SyncRoot) clients_data.Add( key, data); // notifies the other clients this new regexp lock ( clients.SyncRoot ) { @@ -494,13 +502,14 @@ namespace IvyBus internal void callCallback(IvyClient client, Int32 key, String[] tab) { MessageHandler callback = (MessageHandler) callbacks[key]; + object data = clients_data[key]; if (callback == null) { throw new IvyException("(callCallback) Not regexp matching id " + key); } if ( syncControl != null ) - syncControl.Invoke( callback, new object[]{client,tab}); - else callback(client, tab); + syncControl.Invoke( callback, new object[]{data, client,tab}); + else callback(data, client, tab); } private static String[] myTokenize(String s, String separator) -- cgit v1.1