]> rtime.felk.cvut.cz Git - orte.git/blob - orte/Robot_Demo/src/org/ocera/orte/demo/HokuyoScanSubscribe.java
ROBOT_DEMO: fix sync. problems in publisher for "motion_speed"
[orte.git] / orte / Robot_Demo / src / org / ocera / orte / demo / HokuyoScanSubscribe.java
1 package org.ocera.orte.demo;
2
3 import org.ocera.orte.DomainApp;
4 import org.ocera.orte.Subscription;
5 import org.ocera.orte.SubscriptionCallback;
6 import org.ocera.orte.types.MessageData;
7 import org.ocera.orte.types.NtpTime;
8 import org.ocera.orte.types.RecvInfo;
9 import org.ocera.orte.types.SubsProp;
10
11 public class HokuyoScanSubscribe extends SubscriptionCallback{
12
13     public final static int IMMEDIATE    = 0x02;
14     public final static int BEST_EFFORTS = 0x01;
15     
16         private Subscription sub;
17         private HokuyoView view;
18         private HokuyoScanType hokuyomsg;
19         private DomainApp domainApp;
20         private SubsProp subProps;
21         private boolean isCancelled = true;
22         
23         public HokuyoScanSubscribe(DomainApp domainApp, HokuyoView view) {
24                 this.view = view;
25                 this.domainApp = domainApp;
26                 
27             NtpTime deadline      = new NtpTime(10);
28             NtpTime minSeparation = new NtpTime(0);
29             
30             hokuyomsg = new HokuyoScanType(domainApp, "hokuyo_scan");
31                 
32             subProps = new SubsProp(hokuyomsg.getTopic(),
33                                                         "hokuyo_scan",                                  
34                                                         minSeparation,  
35                                                         deadline,
36                                                         IMMEDIATE,
37                                                         BEST_EFFORTS,
38                                                         0);
39         }
40         
41         public void start() {
42             isCancelled = false;
43                 sub = domainApp.createSubscription(subProps, hokuyomsg, this);
44         }
45         
46         public void cancel() {
47                 sub.destroy();
48                 isCancelled = true;
49         }
50         
51         public boolean isCancelled() {
52                 return isCancelled;
53         }
54         
55     public void callback(RecvInfo info, MessageData msg) {
56         view.setData(((HokuyoScanType)msg).hokuyo);
57         }
58 }