|
1 | 1 | package edu.wpi.grip.core; |
2 | 2 |
|
3 | | -import com.google.common.collect.ImmutableSet; |
4 | | -import com.google.common.eventbus.EventBus; |
5 | 3 | import edu.wpi.grip.core.sockets.InputSocket; |
6 | 4 | import edu.wpi.grip.core.sockets.OutputSocket; |
7 | | -import edu.wpi.grip.core.sockets.SocketsProvider; |
8 | 5 |
|
9 | | -import java.io.InputStream; |
10 | | -import java.util.Optional; |
| 6 | +import java.util.List; |
11 | 7 |
|
12 | 8 | /** |
13 | | - * The common interface used by <code>Step</code>s in a pipeline to call various operations. There is usually only one |
14 | | - * instance of any class that implements <code>Operation</code>, which is called whenever that operation is used. |
| 9 | + * The common interface used by <code>Step</code>s in a pipeline to call various operations. Each instance of an |
| 10 | + * operation in the pipeline is handled by a unique instance of that {@code Operation} class. |
15 | 11 | */ |
16 | 12 | public interface Operation { |
17 | 13 |
|
18 | | - enum Category { |
19 | | - IMAGE_PROCESSING, |
20 | | - FEATURE_DETECTION, |
21 | | - NETWORK, |
22 | | - LOGICAL, |
23 | | - OPENCV, |
24 | | - MISCELLANEOUS, |
25 | | - } |
26 | | - |
27 | | - /** |
28 | | - * @return The unique user-facing name of the operation, such as "Gaussian Blur" |
29 | | - */ |
30 | | - String getName(); |
31 | | - |
32 | | - /** |
33 | | - * @return Any old unique user-facing names of the operation. This is used to preserve compatibility with |
34 | | - * old versions of GRIP if the operation name changes. |
35 | | - */ |
36 | | - default ImmutableSet<String> getAliases() { |
37 | | - return ImmutableSet.of(); |
38 | | - } |
39 | | - |
40 | | - |
41 | | - /** |
42 | | - * @return A description of the operation. |
43 | | - */ |
44 | | - String getDescription(); |
45 | | - |
46 | | - /** |
47 | | - * @return What category the operation falls under. This is used to organize them in the GUI |
48 | | - */ |
49 | | - default Category getCategory() { |
50 | | - return Category.MISCELLANEOUS; |
51 | | - } |
52 | | - |
53 | 14 | /** |
54 | | - * @return An {@link InputStream} of a 128x128 image to show the user as a representation of the operation. |
55 | | - */ |
56 | | - default Optional<InputStream> getIcon() { |
57 | | - return Optional.empty(); |
58 | | - } |
59 | | - |
60 | | - default SocketsProvider createSockets(EventBus eventBus) { |
61 | | - return new SocketsProvider(createInputSockets(eventBus), createOutputSockets(eventBus)); |
62 | | - } |
63 | | - /** |
64 | | - * @param eventBus The Guava {@link EventBus} used by the application. |
65 | | - * @return An array of sockets for the inputs that the operation expects. |
66 | | - */ |
67 | | - InputSocket<?>[] createInputSockets(EventBus eventBus); |
68 | | - |
69 | | - /** |
70 | | - * @param eventBus The Guava {@link EventBus} used by the application. |
71 | | - * @return An array of sockets for the outputs that the operation produces. |
| 15 | + * @return A list of sockets for the inputs that the operation expects. |
| 16 | + * |
| 17 | + * @implNote The returned list should be immutable (i.e. read-only) |
72 | 18 | */ |
73 | | - OutputSocket<?>[] createOutputSockets(EventBus eventBus); |
| 19 | + List<InputSocket> getInputSockets(); |
74 | 20 |
|
75 | 21 | /** |
76 | | - * Override this to provide persistent per-step data |
| 22 | + * @return A list of sockets for the outputs that the operation produces. |
| 23 | + * |
| 24 | + * @implNote The returned list should be immutable (i.e. read-only) |
77 | 25 | */ |
78 | | - default Optional<?> createData() { |
79 | | - return Optional.empty(); |
80 | | - } |
| 26 | + List<OutputSocket> getOutputSockets(); |
81 | 27 |
|
82 | 28 | /** |
83 | | - * Perform the operation on the specified inputs, storing the results in the specified outputs. |
84 | | - * |
85 | | - * @param inputs An array obtained from {@link #createInputSockets(EventBus)}. The caller can set the value of |
86 | | - * each socket to an actual parameter for the operation. |
87 | | - * @param outputs An array obtained from {@link #createOutputSockets(EventBus)}. The outputs of the operation will |
88 | | - * be stored in these sockets. |
89 | | - * @param data Optional data to be passed to the operation |
| 29 | + * Performs this {@code Operation}. |
90 | 30 | */ |
91 | | - default void perform(InputSocket<?>[] inputs, OutputSocket<?>[] outputs, Optional<?> data) { |
92 | | - perform(inputs, outputs); |
93 | | - } |
94 | | - |
95 | | - default void perform(InputSocket<?>[] inputs, OutputSocket<?>[] outputs) { |
96 | | - throw new UnsupportedOperationException("Perform was not overridden"); |
97 | | - } |
| 31 | + void perform(); |
98 | 32 |
|
99 | 33 | /** |
100 | 34 | * Allows the step to clean itself up when removed from the pipeline. |
101 | 35 | * This should only be called by {@link Step#setRemoved()} to ensure correct synchronization. |
102 | | - * |
103 | | - * @param inputs An array obtained from {@link #createInputSockets(EventBus)}. The caller can set the value of |
104 | | - * each socket to an actual parameter for the operation. |
105 | | - * @param outputs An array obtained from {@link #createOutputSockets(EventBus)}. The outputs of the operation will |
106 | | - * be stored in these sockets. |
107 | | - * @param data Optional data to be passed to the operation |
108 | 36 | */ |
109 | | - default void cleanUp(InputSocket<?>[] inputs, OutputSocket<?>[] outputs, Optional<?> data) { |
| 37 | + default void cleanUp() { |
110 | 38 | /* no-op */ |
111 | 39 | } |
112 | 40 | } |
0 commit comments