- LinkedList<AltosSerialMonitor> callbacks;
-
- public void run() {
- try {
- for (;;) {
- String s = reader.get_telem();
- synchronized(callbacks) {
- Iterator<AltosSerialMonitor> i = callbacks.iterator();
- while (i.hasNext()) {
- i.next().data(s);
- }
- }
- }
- } catch (InterruptedException e) {
- }
- }
-
- boolean need_monitor() {
- return reader.opened() && !callbacks.isEmpty();
- }
-
- void maybe_stop_monitor() {
- if (!need_monitor() && monitor_thread != null) {
- monitor_thread.interrupt();
- try {
- monitor_thread.join();
- } catch (InterruptedException e) {
- } finally {
- monitor_thread = null;
- }
- }
- }
-
- void maybe_start_monitor() {
- if (need_monitor() && monitor_thread == null) {
- monitor_thread = new Thread(this);
- monitor_thread.start();
- }
- }