X-Git-Url: https://rtime.felk.cvut.cz/gitweb/orte.git/blobdiff_plain/80380d52dd567ca0425c68ec7fbdeb3cdff1056a..ab4df9d834af0d7e663796dace242fb9bf303570:/orte/contrib/shape_android/src/org/ocera/orte/shape_android/SubscriberElement.java diff --git a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/SubscriberElement.java b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/SubscriberElement.java index a16326a..4d65efc 100644 --- a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/SubscriberElement.java +++ b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/SubscriberElement.java @@ -34,6 +34,8 @@ import org.ocera.orte.types.RecvInfo; import org.ocera.orte.types.SubsProp; import org.ocera.orte.types.ORTEConstant; +import java.util.concurrent.locks.ReentrantLock; + /** * Subscribing objects are made by this class. * @@ -56,6 +58,8 @@ public class SubscriberElement extends SubscriptionCallback private boolean receiving; private boolean enabled; + public final ReentrantLock lock = new ReentrantLock(); + /** * Set default variables of subscriber's object. * @@ -99,20 +103,31 @@ public class SubscriberElement extends SubscriptionCallback { switch (info.getRecvStatus()) { case ORTEConstant.NEW_DATA: - this.receiving = true; - //Log.d("SubscriberElement", "new data: " + (int) ((Box) msg).strength + "(was "+ this.box.strength +"); " + ((Box) msg).rectangle.top_left_x + ", " + ((Box) msg).rectangle.top_left_y + ", " +((Box) msg).rectangle.bottom_right_x + ", " + ((Box) msg).rectangle.bottom_right_y); - - this.shape.getBounds().left = this.box.rectangle.top_left_x; - this.shape.getBounds().top = this.box.rectangle.top_left_y; - this.shape.getBounds().right = this.box.rectangle.bottom_right_x; - this.shape.getBounds().bottom = this.box.rectangle.bottom_right_y; - - this.setShape(); + + lock.lock(); + try { + this.receiving = true; + //Log.d("SubscriberElement", "new data: " + (int) ((Box) msg).strength + "(was "+ this.box.strength +"); " + ((Box) msg).rectangle.top_left_x + ", " + ((Box) msg).rectangle.top_left_y + ", " +((Box) msg).rectangle.bottom_right_x + ", " + ((Box) msg).rectangle.bottom_right_y); + + this.shape.setBounds(this.box.rectangle.top_left_x, + this.box.rectangle.top_left_y, + this.box.rectangle.bottom_right_x, + this.box.rectangle.bottom_right_y); + + this.setShape(); + } finally { + lock.unlock(); + } this.parentView.postInvalidate(); break; case ORTEConstant.DEADLINE: - this.receiving = false; + lock.lock(); + try { + this.receiving = false; + } finally { + lock.unlock(); + } this.parentView.postInvalidate(); break; } @@ -243,4 +258,15 @@ public class SubscriberElement extends SubscriptionCallback this.setShape(); } + /** + * When subscriber is removed, destroy subscription. + * + * @since 1.0 + */ + public void killMe() { + if (this.subscription != null) { + this.subscription.destroy(); + this.subscription = null; + } + } }