1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
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);
}
}
}
|