summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CSharp/Ivy/IvyPPC/Ivy.cs19
1 files changed, 14 insertions, 5 deletions
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
/// </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)