diff options
author | fcolin | 2007-02-01 09:42:22 +0000 |
---|---|---|
committer | fcolin | 2007-02-01 09:42:22 +0000 |
commit | 16cde27261c3241b5f6227c134ef999f206f5f44 (patch) | |
tree | f7f50b747e8f6b0fbff07d2ab0a7a7595de8414e | |
parent | 5f7db294ca4772b0559b0759c8427eba1f6408e2 (diff) | |
download | ivy-csharp-16cde27261c3241b5f6227c134ef999f206f5f44.zip ivy-csharp-16cde27261c3241b5f6227c134ef999f206f5f44.tar.gz ivy-csharp-16cde27261c3241b5f6227c134ef999f206f5f44.tar.bz2 ivy-csharp-16cde27261c3241b5f6227c134ef999f206f5f44.tar.xz |
Utilisateur : Fcolin Date : 20/11/03 Heure : 12:46 Archivé dans $/EScribe/Ivy Commentaire: (vss 13)
-rw-r--r-- | CSharp/Ivy/Ivy/Ivy.cs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/CSharp/Ivy/Ivy/Ivy.cs b/CSharp/Ivy/Ivy/Ivy.cs index b4a2ef4..18f94e7 100644 --- a/CSharp/Ivy/Ivy/Ivy.cs +++ b/CSharp/Ivy/Ivy/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 /// </param>
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 /// </returns>
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)
|