summaryrefslogtreecommitdiff
path: root/CSharp/Ivy
diff options
context:
space:
mode:
authorfcolin2007-02-01 09:55:02 +0000
committerfcolin2007-02-01 09:55:02 +0000
commitcfdcf876085efaebe90001dcf86b8db46102ebf1 (patch)
treedd32499a9cff89ea5bab0fec278b2a6124f9bc1b /CSharp/Ivy
parent7327a481cc6956a0cbcb26d394ae32c4494f8500 (diff)
downloadivy-csharp-cfdcf876085efaebe90001dcf86b8db46102ebf1.zip
ivy-csharp-cfdcf876085efaebe90001dcf86b8db46102ebf1.tar.gz
ivy-csharp-cfdcf876085efaebe90001dcf86b8db46102ebf1.tar.bz2
ivy-csharp-cfdcf876085efaebe90001dcf86b8db46102ebf1.tar.xz
Utilisateur : Fcolin Date : 12/01/06 Heure : 12:53 Archivé dans $/CSharp/Ivy/Ivy Commentaire: (vss 33)
Diffstat (limited to 'CSharp/Ivy')
-rw-r--r--CSharp/Ivy/IvyPPC/Ivy.cs167
1 files changed, 94 insertions, 73 deletions
diff --git a/CSharp/Ivy/IvyPPC/Ivy.cs b/CSharp/Ivy/IvyPPC/Ivy.cs
index 7f4ae81..d99942b 100644
--- a/CSharp/Ivy/IvyPPC/Ivy.cs
+++ b/CSharp/Ivy/IvyPPC/Ivy.cs
@@ -131,6 +131,14 @@ namespace IvyBus
}
}
+ public int ProtocolVersion
+ {
+ get
+ {
+ return protocolVersion;
+ }
+
+ }
///<summary>SentMessageClasses the first word token of sent messages
///<remarks> optimise the parsing process when sending messages </remarks>
///</summary>
@@ -166,8 +174,8 @@ namespace IvyBus
/// the domain for the UDP rendez vous
internal static readonly string DEFAULT_DOMAIN = "127.255.255.255:" + DEFAULT_PORT;
internal const string libVersion = "2.0.0";
-
- private bool debug;
+ internal int protocolVersion = 3;
+ private bool debug = false;
private static ushort serial = 0; /* an unique ID for each regexp */
private MyTcpListener app;
private List<IvyWatcher> watchers;
@@ -225,7 +233,10 @@ namespace IvyBus
bindings = new Dictionary<int,ApplicationBinding>();
appName = name;
ready_message = message;
+#if (!PocketPC )
debug = Properties.Settings.Default.IvyDebug;
+ protocolVersion = Properties.Settings.Default.IvyProtocolVersion;
+#endif
}
public Ivy(string name, string message, Control sync) :this( name, message )
{
@@ -252,8 +263,9 @@ namespace IvyBus
domainbus = getDomain(domainbus);
try
{
- IPAddress localaddr = Dns.Resolve(Dns.GetHostName()).AddressList[0];
- app = new MyTcpListener(IPAddress.Any,0);
+ //IPAddress localaddr = Dns.Resolve(Dns.GetHostName()).AddressList[0];
+ IPAddress localaddr = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0];
+ app = new MyTcpListener(IPAddress.Any, 0);
app.Start();
applicationPort = (ushort)((IPEndPoint) app.LocalEndpoint).Port;
applicationHost = localaddr;
@@ -266,7 +278,7 @@ namespace IvyBus
{
throw new IvyException("can't open TCP service socket " + e);
}
- traceDebug("lib: " + libVersion + " protocol: " + Properties.Settings.Default.IvyProtocolVersion + " TCP service open on port " + applicationPort);
+ traceDebug("lib: " + libVersion + " protocol: " + ProtocolVersion + " TCP service open on port " + applicationPort);
watchers = new List<IvyWatcher>();
Domain[] d = parseDomains(domainbus);
@@ -278,13 +290,20 @@ namespace IvyBus
}
serverThread = new Thread(new ThreadStart(this.Run));
serverThread.Name = "Ivy Tcp Server Thread";
- serverThread.Start();
+ stopped = false;
+ serverThread.Start();
+
+#if (PocketPC )
+ traceDebug(" Ivy Threading start in progress...");
+ Thread.Sleep(100);
+#else
// Wait for readyness
- while ( serverThread.ThreadState != ThreadState.Running || !app.IsActive())
+ while ( serverThread.ThreadState != ThreadState.Running || !app.IsActive())
{
traceDebug( " Ivy Threading start in progress..." );
Thread.Sleep( 100 );
}
+#endif
// sends the broadcasts and listen to incoming connexions
for (int i = 0; i < watchers.Count; i++)
{
@@ -373,7 +392,7 @@ namespace IvyBus
}
catch (IOException e)
{
- traceDebug("IOexception Stop ");
+ traceDebug("IOexception Stop "+e.Message);
}
traceDebug("the bus should have stopped so far");
}
@@ -527,7 +546,7 @@ namespace IvyBus
{
unBindMsg(bind.key);
}
- catch (IvyException ie)
+ catch (IvyException)
{
return false;
}
@@ -588,85 +607,71 @@ namespace IvyBus
v[i].stream.TokenPing(message);
return v.Count;
}
-// internal object FireEvents(Delegate eventDelegate, params object[] args)
-// {
-// if (eventDelegate != null)
-// {
-// if (syncControl != null
-//#if (!PocketPC )
-// && syncControl.Created
-//#endif
-// )
-// return syncControl.Invoke(eventDelegate, args);
-// else return eventDelegate(args);
-// }
-// return null;
-// }
- internal void FireCallback(IvyClient client, int key, string[] arg)
+ internal bool IsSynchronous()
{
- ApplicationBinding bind = bindings[key];
- if (bind.callback == null)
- {
- throw new IvyException("(callCallback) Not regexp matching id " + key);
- }
- if (syncControl != null && syncControl.Created)
- syncControl.Invoke(bind.callback, new object[] { client, arg });
- else bind.callback(client, arg);
+ if (syncControl != null
+#if (!PocketPC )
+ && syncControl.Created
+#endif
+ )
+ return true;
+ else return false;
}
internal void FireDirectMessage(IvyClient app, int id, string arg)
{
- if ( directMessageReceived != null )
- {
- if (syncControl != null && syncControl.Created)
- syncControl.Invoke( directMessageReceived, new object[]{app,id,arg});
- else directMessageReceived( app, id, arg);
- }
+ if ( directMessageReceived != null )
+ {
+ if (IsSynchronous())
+ syncControl.Invoke( directMessageReceived, new object[]{app,id,arg});
+ else directMessageReceived( app, id, arg);
+ }
}
internal void FireClientConnected (IvyClient app)
{
- if ( clientConnected != null )
- {
- if (syncControl != null && syncControl.Created)
- syncControl.Invoke( clientConnected, new object[]{app});
- else clientConnected( app);
- }
+ if ( clientConnected != null )
+ {
+ if (IsSynchronous())
+ syncControl.Invoke( clientConnected, new object[]{app});
+ else clientConnected( app);
+ }
+
}
internal void FireClientDisconnected (IvyClient app)
{
- if ( clientDisconnected != null )
- {
- if ( syncControl != null && syncControl.Created )
- syncControl.Invoke( clientDisconnected, new object[]{app});
- else clientDisconnected( app);
- }
- }
+ if ( clientDisconnected != null )
+ {
+ if (IsSynchronous())
+ syncControl.Invoke( clientDisconnected, new object[]{app});
+ else clientDisconnected( app);
+ }
+ }
internal void FireClientAddBinding (IvyClient app, string regexp)
{
- if ( addBinding != null )
- {
- if (syncControl != null && syncControl.Created)
- syncControl.Invoke( addBinding, new object[]{app,regexp});
- else addBinding( app,regexp);
- }
+ if ( addBinding != null )
+ {
+ if (IsSynchronous())
+ syncControl.Invoke( addBinding, new object[]{app,regexp});
+ else addBinding( app,regexp);
+ }
}
internal void FireClientRemoveBinding (IvyClient app, string regexp)
{
- if ( removeBinding != null )
- {
- if (syncControl != null && syncControl.Created)
- syncControl.Invoke( removeBinding, new object[]{app,regexp});
- else removeBinding( app,regexp);
- }
+ if ( removeBinding != null )
+ {
+ if (IsSynchronous())
+ syncControl.Invoke( removeBinding, new object[]{app,regexp});
+ else removeBinding( app,regexp);
+ }
}
internal bool FireDie (IvyClient app, int id, string arg )
{
- if ( dieReceived != null )
- {
- if (syncControl != null && syncControl.Created)
- syncControl.Invoke( dieReceived, new object[]{app,id,arg});
- else return dieReceived( app, id, arg);
- }
- return false;
+ if ( dieReceived != null )
+ {
+ if (IsSynchronous())
+ return (bool )syncControl.Invoke( dieReceived, new object[]{app,id,arg});
+ else return dieReceived( app, id, arg);
+ }
+ return false;
}
@@ -714,18 +719,34 @@ namespace IvyBus
}
traceDebug(ClientNames);
}
+
+ internal void FireCallback(IvyClient client, int key, string[] arg)
+ {
+ ApplicationBinding bind = bindings[key];
+ if (bind.callback == null)
+ {
+ throw new IvyException("(callCallback) Not regexp matching id " + key);
+ }
+ if ( syncControl != null )
+ syncControl.Invoke(bind.callback, new object[] { client, arg });
+ else bind.callback(client, arg);
+ }
public static string getDomain(string domainbus)
{
- if (domainbus == null)
+ //TODO pocket PC BUS default ?????
+#if (!PocketPC)
+ if (domainbus == null)
{
domainbus = Environment.GetEnvironmentVariable("IVYBUS");
}
+
if (domainbus == null)
{
domainbus = Properties.Settings.Default.IvyBus;
}
+#endif
if (domainbus == null)
domainbus = DEFAULT_DOMAIN;
return domainbus;
@@ -800,7 +821,7 @@ namespace IvyBus
}
catch (SocketException e)
{
- traceDebug("my server socket has been closed");
+ traceDebug("my server socket has been closed " + e.Message);
running = false;
}
}
@@ -811,7 +832,7 @@ namespace IvyBus
private void traceDebug(string s)
{
if (debug)
- Console.WriteLine("-->ivy<-- " + s);
+ Console.Error.WriteLine("-->ivy<-- " + s);
}
internal class Domain