01: /*=============================================================================
02: * Copyright Texas Instruments 2002. All Rights Reserved.
03: *
04: * This program is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package ti.chimera.registry;
20:
21: import oscript.data.Value;
22: import oscript.data.JavaBridge;
23:
24: /**
25: * Interface implemented by subscribers to the value of a node. When the
26: * node's value changes, it's new value will be published to all the node's
27: * subscribers.
28: *
29: * @author ;Rob Clark;a0873619;San Diego;;
30: * @version 0.1
31: */
32: public interface NodeSubscriber {
33: /**
34: * Called to publish the new node value to the subscriber.
35: *
36: * @param node the node doing the publishing
37: * @param value the node's new value
38: */
39: public void publish(Node node, Object value);
40:
41: /**
42: * An implementation of the <code>NodeSubscriber</code> for script
43: * functions.
44: */
45: public class ScriptFunctionNodeSubscriber implements NodeSubscriber {
46: private Value fxn;
47:
48: /**
49: * Class Constructor
50: *
51: * @param fxn the script function to call
52: */
53: public ScriptFunctionNodeSubscriber(Value fxn) {
54: this .fxn = fxn;
55: }
56:
57: /**
58: * delegate to the script function
59: */
60: public void publish(Node node, Object value) {
61: fxn.callAsFunction(new Value[] {
62: JavaBridge.convertToScriptObject(node),
63: JavaBridge.convertToScriptObject(value) });
64: }
65:
66: /**
67: * Overload equals() to be <code>true</code> if the wrapped fxns
68: * are equal, so add/remove from list, etc., works right.
69: */
70: public boolean equals(Object obj) {
71: return (obj instanceof ScriptFunctionNodeSubscriber)
72: && ((ScriptFunctionNodeSubscriber) obj).fxn
73: .equals(fxn);
74: }
75:
76: /**
77: * Overload hashCode() so add/remove from list, etc., works right.
78: */
79: public int hashCode() {
80: return fxn.hashCode();
81: }
82: }
83: }
84:
85: /*
86: * Local Variables:
87: * tab-width: 2
88: * indent-tabs-mode: nil
89: * mode: java
90: * c-indentation-style: java
91: * c-basic-offset: 2
92: * eval: (c-set-offset 'substatement-open '0)
93: * eval: (c-set-offset 'case-label '+)
94: * eval: (c-set-offset 'inclass '+)
95: * eval: (c-set-offset 'inline-open '0)
96: * End:
97: */
|