]> rtime.felk.cvut.cz Git - orte.git/blob - orte/Robot_Demo/src/org/ocera/orte/demo/MagnetCmdPublish.java
Check whether windows dll is produced
[orte.git] / orte / Robot_Demo / src / org / ocera / orte / demo / MagnetCmdPublish.java
1 package org.ocera.orte.demo;
2
3 import java.util.concurrent.locks.ReentrantReadWriteLock;
4 import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
5 import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
6
7 import org.ocera.orte.DomainApp;
8 import org.ocera.orte.Publication;
9 import org.ocera.orte.types.NtpTime;
10 import org.ocera.orte.types.PublProp;
11
12 public class MagnetCmdPublish {
13         
14         private boolean isCancelled = true;
15         private MagnetCmdType magnetmsg;
16         private Publication pub;
17         private PublProp publProp;
18         private DomainApp appDomain;
19         
20         private final ReentrantReadWriteLock controlRrwl = new ReentrantReadWriteLock(true);
21         private final ReadLock rcLock = controlRrwl.readLock();
22         private final WriteLock wcLock = controlRrwl.writeLock();
23         
24         public MagnetCmdPublish(DomainApp appDomain) {
25                 this.appDomain = appDomain;
26                 
27             NtpTime persistence = new NtpTime(3);
28             int strength = 100;
29             
30             magnetmsg = new MagnetCmdType(appDomain,"magnet_cmd");
31             
32             publProp = new PublProp(magnetmsg.getTopic(),
33                                                                          "magnet_cmd",                                  
34                                                                          persistence,
35                                                                          strength);
36         }
37         
38         public void start() {
39                 wcLock.lock();
40                 try {
41                         isCancelled = false;
42                     pub = appDomain.createPublication(publProp, magnetmsg);
43                 }
44                 finally {
45                         wcLock.unlock();
46                 }
47         }
48         
49         public void cancel() {
50                 wcLock.lock();
51                 try {
52                         isCancelled = true;
53                         pub.destroy();
54                 } finally {
55                         wcLock.unlock();
56                 }
57         }
58         
59         public boolean isCancelled() {
60                 rcLock.lock();
61                 try {
62                         return isCancelled;
63                 } finally {
64                         rcLock.unlock();
65                 }
66         }
67         
68         public void send(int magnet) {
69                 magnetmsg.magnet = magnet;
70                 pub.send(magnetmsg);
71         }
72 }