Skip to content

Commit aa3ea19

Browse files
authored
0.70.7
* Fix eventing and subscriptions for Nodes that are DIValues. * DSElementType fixes.
1 parent 2545d64 commit aa3ea19

File tree

7 files changed

+33
-30
lines changed

7 files changed

+33
-30
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ subprojects {
55
apply plugin: 'maven'
66

77
group 'org.iot-dsa'
8-
version '0.70.6'
8+
version '0.70.7'
99

1010
targetCompatibility = JavaVersion.VERSION_1_8
1111
sourceCompatibility = JavaVersion.VERSION_1_8

dslink-v2-api/src/main/java/org/iot/dsa/node/DSInfo.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,11 @@ DSInfo<T> setName(String arg) {
574574
DSInfo<T> setObject(T arg) {
575575
if (isDeclared()) {
576576
if (!getDefaultObject().getClass().isInstance(arg)) {
577+
if (isValue() && (arg instanceof DSIValue)) {
578+
DSIValue v = (DSIValue) arg;
579+
this.object = (T) getValue().valueOf(v.toElement());
580+
return this;
581+
}
577582
throw new IllegalArgumentException(arg + " not an instanceof the declared type " +
578583
getDefaultObject().getClass().getName());
579584
}

dslink-v2-api/src/main/java/org/iot/dsa/node/DSValueNode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.iot.dsa.node;
22

3+
import org.iot.dsa.node.event.DSEvent;
4+
35
/**
46
* A convenience implementation of a node that is also a value. The value of the node must be
57
* stored as a child. Subclasses only need to override is getValueChild()
@@ -34,7 +36,7 @@ public boolean isNull() {
3436
public void onChildChanged(DSInfo child) {
3537
DSInfo info = getValueChild();
3638
if (child == info) {
37-
fire(VALUE_CHANGED_EVENT, child, child.getValue());
39+
fire(VALUE_CHANGED_EVENT, null, child.getValue());
3840
DSNode parent = getParent();
3941
if (parent != null) {
4042
parent.fire(VALUE_CHANGED_EVENT, getInfo(), child.getValue());

dslink-v2-api/src/main/java/org/iot/dsa/node/event/DSEventFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public DSEventFilter(DSISubscriber subscriber) {
4343
* @param child Optional.
4444
*/
4545
public DSEventFilter(DSISubscriber subscriber, DSEvent event, DSInfo child) {
46-
this.subscriber = subscriber;
46+
this(subscriber);
4747
this.event = event;
4848
this.child = child;
4949
}

dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/protocol/responder/DSInboundSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public void run() {
4141
setPath(path.getPath());
4242
responder.onSet(this);
4343
} else {
44-
DSNode parent = path.getNode();
4544
DSInfo info = path.getTargetInfo();
4645
if ((info != null) && info.isReadOnly()) {
4746
throw new DSRequestException("Not writable: " + getPath());
@@ -58,6 +57,7 @@ public void run() {
5857
((DSNode) obj).onSet(value);
5958
} else {
6059
//since not a node, there must be a parent
60+
DSNode parent = info.getParent();
6161
DSIValue current = info.getValue();
6262
if (current == null) {
6363
if (info.isValue()) {

dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/protocol/responder/DSInboundSubscription.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import org.iot.dsa.node.DSIValue;
1313
import org.iot.dsa.node.DSInfo;
1414
import org.iot.dsa.node.DSNode;
15+
import org.iot.dsa.node.DSNull;
1516
import org.iot.dsa.node.DSStatus;
1617
import org.iot.dsa.node.event.DSEvent;
18+
import org.iot.dsa.node.event.DSEventFilter;
1719
import org.iot.dsa.node.event.DSISubscriber;
1820
import org.iot.dsa.node.event.DSISubscription;
1921
import org.iot.dsa.time.DSDateTime;
@@ -110,17 +112,20 @@ public void onClosed(DSISubscription subscription) {
110112

111113
@Override
112114
public void onEvent(DSEvent event, DSNode node, DSInfo child, DSIValue data) {
113-
DSIValue value;
114-
if (child != null) {
115-
value = child.getValue();
116-
} else {
117-
value = (DSIValue) node;
115+
if (data == null) {
116+
if ((child != null) && child.isValue()) {
117+
data = child.getValue();
118+
} else if (node instanceof DSIValue) {
119+
data = (DSIValue) node;
120+
} else {
121+
data = DSNull.NULL;
122+
}
118123
}
119124
DSStatus status = DSStatus.ok;
120-
if (value instanceof DSIStatus) {
121-
status = ((DSIStatus) value).getStatus();
125+
if (data instanceof DSIStatus) {
126+
status = ((DSIStatus) data).getStatus();
122127
}
123-
update(DSDateTime.now(), value, status);
128+
update(DSDateTime.now(), data, status);
124129
}
125130

126131
/**
@@ -219,11 +224,18 @@ protected void init() {
219224
DSIObject obj = path.getTarget();
220225
if (obj instanceof DSNode) {
221226
node = (DSNode) obj;
222-
this.subscription = node.subscribe(this, DSNode.VALUE_CHANGED_EVENT, null);
227+
this.subscription = node.subscribe(new DSISubscriber() {
228+
@Override
229+
public void onEvent(DSEvent event, DSNode node, DSInfo child, DSIValue data) {
230+
if (child == null) {
231+
DSInboundSubscription.this.onEvent(event, node, null, data);
232+
}
233+
}
234+
});
223235
onEvent(DSNode.VALUE_CHANGED_EVENT, node, null, null);
224236
} else {
225237
DSInfo info = path.getTargetInfo();
226-
node = path.getNode();
238+
node = info.getParent();
227239
child = info;
228240
this.subscription = node.subscribe(this, DSNode.VALUE_CHANGED_EVENT, info);
229241
onEvent(DSNode.VALUE_CHANGED_EVENT, node, info, null);

dslink-v2/src/test/java/org/iot/dsa/dslink/SerializationTest.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,6 @@ public class SerializationTest {
3636
// Methods
3737
// -------
3838

39-
@Test
40-
public void differentTypeThanDefault() throws Exception {
41-
DSNode node = new MyNode();
42-
node.put("tmp", DSElement.make(10));
43-
boolean success = false;
44-
try {
45-
node.put("string", DSLong.valueOf(6));
46-
} catch (Exception x) {
47-
success = true;
48-
}
49-
Assert.assertTrue(success);
50-
node = decode(encode(node));
51-
Assert.assertEquals(node.get("string"), DSString.EMPTY);
52-
Assert.assertEquals(node.get("tmp"), DSElement.make(10));
53-
}
54-
5539
/**
5640
* Testing an "Already parented" bug that cropped up.
5741
*/

0 commit comments

Comments
 (0)