1
|
package RTMExamples.SimpleSdoService;
|
2
|
|
3
|
import java.util.UUID;
|
4
|
|
5
|
import jp.go.aist.rtm.RTC.CorbaNaming;
|
6
|
import jp.go.aist.rtm.RTC.port.CorbaConsumer;
|
7
|
import jp.go.aist.rtm.RTC.util.CORBA_SeqUtil;
|
8
|
import jp.go.aist.rtm.RTC.util.NVUtil;
|
9
|
import jp.go.aist.rtm.RTC.util.ORBUtil;
|
10
|
|
11
|
import org.omg.CORBA.ORB;
|
12
|
import org.omg.CosNaming.NamingContextPackage.CannotProceed;
|
13
|
import org.omg.CosNaming.NamingContextPackage.InvalidName;
|
14
|
import org.omg.CosNaming.NamingContextPackage.NotFound;
|
15
|
import org.omg.PortableServer.POA;
|
16
|
import org.omg.PortableServer.POAHelper;
|
17
|
import org.omg.PortableServer.POAManager;
|
18
|
|
19
|
import OpenRTM.ComponentObserverHelper;
|
20
|
import OpenRTM.DataFlowComponent;
|
21
|
import _SDOPackage.NVListHolder;
|
22
|
import _SDOPackage.NameValue;
|
23
|
import _SDOPackage.Configuration;
|
24
|
import _SDOPackage.SDOService;
|
25
|
import _SDOPackage.SDOServiceHelper;
|
26
|
import _SDOPackage.ServiceProfile;
|
27
|
|
28
|
public class ToolComp {
|
29
|
|
30
|
public static void main(String[] args) {
|
31
|
|
32
|
ORB orb = ORBUtil.getOrb(args);
|
33
|
CorbaNaming naming = null;
|
34
|
try {
|
35
|
naming = new CorbaNaming(orb, "localhost:2809");
|
36
|
} catch (Exception e) {
|
37
|
e.printStackTrace();
|
38
|
}
|
39
|
if( naming == null ){
|
40
|
System.out.println("CorbaNaming is null.");
|
41
|
return;
|
42
|
}
|
43
|
|
44
|
CorbaConsumer<DataFlowComponent> conout =
|
45
|
new CorbaConsumer<DataFlowComponent>(DataFlowComponent.class);
|
46
|
|
47
|
if(conout == null){
|
48
|
System.out.println("Failed to create CorbaConsumer.");
|
49
|
return;
|
50
|
}
|
51
|
|
52
|
try {
|
53
|
conout.setObject(naming.resolve("SdoServiceConsumer0.rtc"));
|
54
|
} catch (NotFound e) {
|
55
|
e.printStackTrace();
|
56
|
} catch (CannotProceed e) {
|
57
|
e.printStackTrace();
|
58
|
} catch (InvalidName e) {
|
59
|
e.printStackTrace();
|
60
|
}
|
61
|
|
62
|
try {
|
63
|
org.omg.CORBA.Object obj = orb.resolve_initial_references("RootPOA");
|
64
|
POA poa = POAHelper.narrow(obj);
|
65
|
POAManager pman = poa.the_POAManager();
|
66
|
pman.activate();
|
67
|
Configuration conf = conout._ptr().get_configuration();
|
68
|
|
69
|
UUID uuid = UUID.randomUUID();
|
70
|
|
71
|
TestObserver to = new TestObserver();
|
72
|
|
73
|
NVListHolder nvholder = new NVListHolder();
|
74
|
nvholder.value = new NameValue[0];
|
75
|
CORBA_SeqUtil.push_back(nvholder,
|
76
|
NVUtil.newNVString("observed_status","ALL"));
|
77
|
CORBA_SeqUtil.push_back(nvholder,
|
78
|
NVUtil.newNVString("heartbeat.enable", "YES"));
|
79
|
CORBA_SeqUtil.push_back(nvholder,
|
80
|
NVUtil.newNVString("heartbeat.interval", "5"));
|
81
|
byte[] id = poa.activate_object(to);
|
82
|
org.omg.CORBA.Object ref = poa.id_to_reference(id);
|
83
|
SDOService sdo = SDOServiceHelper.narrow(ref);
|
84
|
ServiceProfile prof = new ServiceProfile(uuid.toString(),
|
85
|
ComponentObserverHelper.id(),
|
86
|
nvholder.value,
|
87
|
sdo);
|
88
|
|
89
|
conf.add_service_profile(prof);
|
90
|
|
91
|
|
92
|
System.out.println("..");
|
93
|
try {
|
94
|
Thread.sleep(100000);
|
95
|
}catch (InterruptedException e) {
|
96
|
e.printStackTrace();
|
97
|
}
|
98
|
|
99
|
|
100
|
conf.remove_service_profile(uuid.toString());
|
101
|
} catch(Exception e){
|
102
|
e.printStackTrace();
|
103
|
}
|
104
|
orb.destroy();
|
105
|
}
|
106
|
|
107
|
private static void usage() {
|
108
|
System.out.println("");
|
109
|
System.out.println( "usage: Tool RTCName " );
|
110
|
System.out.println("");
|
111
|
System.out.println("");
|
112
|
}
|
113
|
|
114
|
}
|