From 4f5cb588bd29d89337a9286d4efdc88536931b32 Mon Sep 17 00:00:00 2001 From: fcolin Date: Wed, 30 Nov 2011 08:59:39 +0000 Subject: ajout IvyTransduct Tool to change message syntaxe based on an xml file --- IvyTransduct/IvyTransduct.cs | 105 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 IvyTransduct/IvyTransduct.cs (limited to 'IvyTransduct/IvyTransduct.cs') diff --git a/IvyTransduct/IvyTransduct.cs b/IvyTransduct/IvyTransduct.cs new file mode 100644 index 0000000..b8fc366 --- /dev/null +++ b/IvyTransduct/IvyTransduct.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Text; +using IvyBus; +using Gnu; +using System.Xml; + +namespace IvyTransduct +{ + class IvyTransduct + { + public const String helpmsg = + "usage: IvyProbe [options] filename\n" + + "\t-b BUS\tspecifies the Ivy bus domain\n" + + "\t-n ivyname (default IvyTransduct)\n" + + "\t-d\tdebug\n" + + "\t-h\thelp\n\n" + + "\t-f filename ( message to transduct)"; + static Ivy bus; + static bool debug = false; + + static void resentCB(object sender, IvyMessageEventArgs args) + { + IvyApplicationBinding binding = sender as IvyApplicationBinding; + foreach (string msg in (List)binding.CallbackArguments[0]) + { + try + { + string msg_out = string.Format(msg, args.GetArguments()); + if (debug) + Console.WriteLine("resent msg: {0} => {1}", args, msg_out); + bus.SendMsg(msg_out); + } + catch (Exception ex) + { + Console.WriteLine("Error sending msg {0} : {1}", msg, ex.Message); + } + } + + } + static void Main(string[] args) + { + string domain = Ivy.GetDomain(null); + + string name = "IvyTransduct"; + + GetOpt opt = new GetOpt(args, "n:b:dh"); + Arg a; + while ((a = opt.NextArg()) != null) + { + switch (a.Flag) + { + case 'd': + debug = true; + break; + + case 'b': + domain = a.Parameter; + break; + + case 'n': + name = a.Parameter; + break; + + case 'h': + default: + System.Console.Out.WriteLine(helpmsg); + System.Environment.Exit(0); + break; + + } + } + bus = new Ivy(name, name + " ready"); + + foreach (string filename in opt.Extras) + { + if (debug) + Console.WriteLine("Read File {0}", filename); + try + { + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.Load(filename); + foreach (XmlElement msg in xmlDoc.SelectNodes("/transduct/message")) + { + string msg_in = msg.SelectSingleNode("input").Attributes["bind"].Value; + if (debug) Console.WriteLine("message: " + msg_in); + List outputs = new List(); + foreach ( XmlElement item in msg.SelectNodes( "output/item" ) ) + { + string msg_out = item.Attributes["msg"].Value; + if (debug) Console.WriteLine("\t out: " + msg_out); + outputs.Add(msg_out); + } + bus.BindMsg(msg_in, resentCB, outputs); + } + } + catch (Exception ex) + { + Console.WriteLine("Error reading file {0} : {1}", filename, ex.Message); + } + } + bus.Start(domain); + } + } +} -- cgit v1.1