using System; using System.IO; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; // from IIOPChannel.dll using Ch.Elca.Iiop; using Ch.Elca.Iiop.Services; using omg.org.CosNaming; // from ExecutorI.dll using manut.Executor; namespace manut.Executor { public class CorbaHandler { // remote object private manut.Executor.ExecCmd servant; private IiopChannel chan2; private CorbaInit init2; private MainWindow window; private string host; private int port; public CorbaHandler() { host = "192.168.0.253"; port = 2809; connect(); } public CorbaHandler(string _host, int _port, MainWindow _window) { host = _host; port = _port; window = _window; } public void serve(){ try { // Host Servant chan2 = new IiopChannel(0); ChannelServices.RegisterChannel(chan2); init2 = CorbaInit.GetInit(); NamingContext nameService2 = init2.GetNameService(host, port); NameComponent[] moduleName2 = new NameComponent[] {new NameComponent("manut.Controller", "")}; NamingContext nameSpace2 = (NamingContext)nameService2.bind_new_context(moduleName2); NameComponent[] interfaceName2 = new NameComponent[] {new NameComponent("Disp", "")}; manut.Controller.Disp interfaceImpl = new manut.Controller.Disp(window); Console.WriteLine("4"); nameSpace2.bind(interfaceName2, interfaceImpl); Console.WriteLine("DisplayServer ready"); } catch (Exception e) { Console.WriteLine(e); } } public void connect() { try{ // Connect to Executer // Access the COS naming service (NameService)... NamingContext nameService = init2.GetNameService(host, port); // Access the IDL-defined module // (which maps to a .Net namespace)... NameComponent[] moduleName = new NameComponent[] {new NameComponent("Executor", "")}; NamingContext nameSpace = (NamingContext)nameService.resolve(moduleName); Console.Write("Executor ok, "); // Access the IDL-defined interface // (which maps to a .NET interface class) NameComponent[] interfaceName = new NameComponent[] {new NameComponent("ExecCmd", "")}; this.servant = (manut.Executor.ExecCmd)nameSpace.resolve(interfaceName); Console.Write("ExecCmd ok\n\nTesting... "); this.servant.changeMode(2); Console.Write("ok\n\n"); } catch (Exception e) { Console.WriteLine(e); } } public bool setPorts(short one, short two, short three) { return this.servant.setPorts(one, two, three); } public bool setMode(short mode) { try { return this.servant.changeMode(mode); } catch(Exception e) { Console.WriteLine("setMode Exception: "+e); return false; } } public void display(string txt) { window.display(txt); } } }