Skip to content

Commit c49a7e0

Browse files
committed
Fix Templated Operations not running (#593)
Closes #592
1 parent 01a853d commit c49a7e0

12 files changed

+78
-55
lines changed

core/src/main/java/edu/wpi/grip/core/OperationMetaData.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package edu.wpi.grip.core;
22

3+
import com.google.common.base.MoreObjects;
4+
35
import javax.annotation.concurrent.Immutable;
46
import java.util.function.Supplier;
57

@@ -38,4 +40,12 @@ public OperationDescription getDescription() {
3840
public Supplier<Operation> getOperationSupplier() {
3941
return operationSupplier;
4042
}
43+
44+
@Override
45+
public String toString() {
46+
return MoreObjects.toStringHelper(OperationMetaData.class)
47+
.add("description", description)
48+
.add("operationSupplier", operationSupplier)
49+
.toString();
50+
}
4151
}

core/src/main/java/edu/wpi/grip/core/operations/CVOperations.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package edu.wpi.grip.core.operations;
22

33

4+
import com.google.common.annotations.VisibleForTesting;
45
import com.google.common.collect.ImmutableList;
56
import com.google.common.eventbus.EventBus;
67
import com.google.inject.Inject;
@@ -314,6 +315,14 @@ public class CVOperations {
314315
);
315316
}
316317

318+
/**
319+
* All of the operations that this list supplies
320+
*/
321+
@VisibleForTesting
322+
ImmutableList<OperationMetaData> operations() {
323+
return ImmutableList.<OperationMetaData>builder().addAll(coreOperations).addAll(imgprocOperation).build();
324+
}
325+
317326
public void addOperations() {
318327
coreOperations.stream()
319328
.map(OperationAddedEvent::new)

core/src/main/java/edu/wpi/grip/core/operations/Operations.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package edu.wpi.grip.core.operations;
22

3+
import com.google.common.annotations.VisibleForTesting;
34
import com.google.common.collect.ImmutableList;
45
import com.google.common.eventbus.EventBus;
56
import com.google.inject.Inject;
@@ -102,6 +103,11 @@ public class Operations {
102103
);
103104
}
104105

106+
@VisibleForTesting
107+
ImmutableList<OperationMetaData> operations() {
108+
return operations;
109+
}
110+
105111
public void addOperations() {
106112
operations.stream()
107113
.map(OperationAddedEvent::new)

core/src/main/java/edu/wpi/grip/core/operations/templated/FiveSourceOneDestinationOperation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public interface Performer<T1, T2, T3, T4, T5, R> {
3434
this.input4 = inputSocketFactory.create(t4SocketHint);
3535
this.input5 = inputSocketFactory.create(t5SocketHint);
3636
this.output = outputSocketFactory.create(rSocketHint);
37+
assert output.getValue().isPresent() : TemplateFactory.ASSERTION_MESSAGE;
3738
}
3839

3940
@Override

core/src/main/java/edu/wpi/grip/core/operations/templated/FourSourceOneDestinationOperation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public interface Performer<T1, T2, T3, T4, R> {
3232
this.input3 = inputSocketFactory.create(t3SocketHint);
3333
this.input4 = inputSocketFactory.create(t4SocketHint);
3434
this.output = outputSocketFactory.create(rSocketHint);
35+
assert output.getValue().isPresent() : TemplateFactory.ASSERTION_MESSAGE;
3536
}
3637

3738

core/src/main/java/edu/wpi/grip/core/operations/templated/OneSourceOneDestinationOperation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public interface Performer<T1, R> {
2626
SocketHint<R> rSocketHint) {
2727
this.input1 = inputSocketFactory.create(t1SocketHint);
2828
this.output = outputSocketFactory.create(rSocketHint);
29+
assert output.getValue().isPresent() : TemplateFactory.ASSERTION_MESSAGE;
2930
this.performer = performer;
3031
}
3132

core/src/main/java/edu/wpi/grip/core/operations/templated/SevenSourceOneDestinationOperation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public interface Performer<T1, T2, T3, T4, T5, T6, T7, R> {
4747
this.input6 = inputSocketFactory.create(t6SocketHint);
4848
this.input7 = inputSocketFactory.create(t7SocketHint);
4949
this.output = outputSocketFactory.create(rSocketHint);
50+
assert output.getValue().isPresent() : TemplateFactory.ASSERTION_MESSAGE;
5051
}
5152

5253
@Override

core/src/main/java/edu/wpi/grip/core/operations/templated/SixSourceOneDestinationOperation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public interface Performer<T1, T2, T3, T4, T5, T6, R> {
4444
this.input5 = inputSocketFactory.create(t5SocketHint);
4545
this.input6 = inputSocketFactory.create(t6SocketHint);
4646
this.output = outputSocketFactory.create(rSocketHint);
47+
assert output.getValue().isPresent() : TemplateFactory.ASSERTION_MESSAGE;
4748
}
4849

4950

core/src/main/java/edu/wpi/grip/core/operations/templated/TemplateFactory.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import edu.wpi.grip.core.sockets.InputSocket;
77
import edu.wpi.grip.core.sockets.OutputSocket;
88
import edu.wpi.grip.core.sockets.SocketHint;
9+
import edu.wpi.grip.core.sockets.SocketHints;
910
import org.bytedeco.javacpp.opencv_core.Mat;
1011

1112
import java.util.function.Supplier;
@@ -17,6 +18,10 @@
1718
@Singleton
1819
@SuppressWarnings("PMD.GenericsNaming")
1920
public final class TemplateFactory {
21+
/*
22+
* Intentionally package private
23+
*/
24+
static final String ASSERTION_MESSAGE = "Output must be present for this operation to complete correctly.";
2025
private final InputSocket.Factory isf;
2126
private final OutputSocket.Factory osf;
2227

@@ -105,7 +110,7 @@ public Supplier<Operation> createAllMatTwoSource(
105110
}
106111

107112
public Supplier<Operation> createAllMatTwoSource(TwoSourceOneDestinationOperation.Performer<Mat, Mat, Mat> performer) {
108-
return createAllMatTwoSource(srcSocketHint(Mat.class, 1), srcSocketHint(Mat.class, 2), dstSocketHint(Mat.class), performer);
113+
return createAllMatTwoSource(srcSocketHint(Mat.class, 1), srcSocketHint(Mat.class, 2), dstMatSocketHint(), performer);
109114
}
110115

111116
public Supplier<Operation> createAllMatOneSource(
@@ -116,15 +121,15 @@ public Supplier<Operation> createAllMatOneSource(
116121
}
117122

118123
public Supplier<Operation> createAllMatOneSource(OneSourceOneDestinationOperation.Performer<Mat, Mat> performer) {
119-
return createAllMatOneSource(srcSocketHint(Mat.class, 1), dstSocketHint(Mat.class), performer);
124+
return createAllMatOneSource(srcSocketHint(Mat.class, 1), dstMatSocketHint(), performer);
120125
}
121126

122127

123128
private <R> SocketHint<R> srcSocketHint(Class<R> srcType, int index) {
124129
return new SocketHint.Builder<>(srcType).identifier("src" + index).build();
125130
}
126131

127-
private <R> SocketHint<R> dstSocketHint(Class<R> returnType) {
128-
return new SocketHint.Builder<>(returnType).identifier("dst").build();
132+
private SocketHint<Mat> dstMatSocketHint() {
133+
return SocketHints.Outputs.createMatSocketHint("dst");
129134
}
130135
}

core/src/main/java/edu/wpi/grip/core/operations/templated/ThreeSourceOneDestinationOperation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public interface Performer<T1, T2, T3, R> {
3131
this.input2 = inputSocketFactory.create(t2SocketHint);
3232
this.input3 = inputSocketFactory.create(t3SocketHint);
3333
this.output = outputSocketFactory.create(rSocketHint);
34+
assert output.getValue().isPresent() : TemplateFactory.ASSERTION_MESSAGE;
3435
}
3536

3637
@Override

0 commit comments

Comments
 (0)