8
8
package io .runtime .mcumgr ;
9
9
10
10
import org .jetbrains .annotations .NotNull ;
11
+ import org .jetbrains .annotations .Nullable ;
11
12
12
13
import io .runtime .mcumgr .exception .McuMgrException ;
13
14
import io .runtime .mcumgr .response .McuMgrResponse ;
20
21
*/
21
22
public interface McuMgrTransport {
22
23
24
+ /**
25
+ * Receives connection state changes independent of explicit calls to
26
+ * {@link #connect} or {@link #release}.
27
+ * <p>
28
+ * To add or remove an observer, use {@link #addObserver} and
29
+ * {@link #removeObserver} respectively.
30
+ */
23
31
interface ConnectionObserver {
24
32
/**
25
- * A method called when the connection to the device has been established.
33
+ * Called when the connection to the device has been established.
26
34
*/
27
35
void onConnected ();
28
36
29
37
/**
30
- * A method called when the connection to the device has been lost.
38
+ * Called when the connection to the device has been lost.
31
39
*/
32
40
void onDisconnected ();
33
41
}
34
42
43
+ /**
44
+ * Receives callbacks from an explicit call to {@link #connect}.
45
+ */
46
+ interface ConnectionCallback {
47
+ /**
48
+ * Called when connection attempt succeeds or is already open when {@link #connect} is
49
+ * called.
50
+ */
51
+ void onConnected ();
52
+
53
+ /**
54
+ * Called when the transporter has decided not to connect to the transporter at this time.
55
+ *
56
+ * This method is useful for transporters who do not wish to allow the caller of
57
+ * {@link #connect} to manage the connection or would rather wait to connect until
58
+ * necessary.
59
+ */
60
+ void onDeferred ();
61
+
62
+ /**
63
+ * Called when the connection attempt has failed.
64
+ *
65
+ * @param t The connection failure reason.
66
+ */
67
+ void onError (@ NotNull Throwable t );
68
+ }
69
+
35
70
/**
36
71
* Gets the scheme for this transport (see {@link McuMgrScheme}).
37
72
*
@@ -51,8 +86,7 @@ interface ConnectionObserver {
51
86
* @throws McuMgrException thrown on error. Set the cause of the error if caused by a different
52
87
* type of exception.
53
88
*/
54
- @ NotNull
55
- <T extends McuMgrResponse > T send (@ NotNull byte [] payload , @ NotNull Class <T > responseType )
89
+ @ NotNull <T extends McuMgrResponse > T send (@ NotNull byte [] payload , @ NotNull Class <T > responseType )
56
90
throws McuMgrException ;
57
91
58
92
/**
@@ -68,6 +102,14 @@ <T extends McuMgrResponse> T send(@NotNull byte[] payload, @NotNull Class<T> res
68
102
<T extends McuMgrResponse > void send (@ NotNull byte [] payload , @ NotNull Class <T > responseType ,
69
103
@ NotNull McuMgrCallback <T > callback );
70
104
105
+ /**
106
+ * Connect the transporter to the remote device. The callback must be called if supplied, even
107
+ * if the transport connection is already opened.
108
+ *
109
+ * @param callback An optional callback to receive the result of the connection attempt.
110
+ */
111
+ void connect (@ Nullable ConnectionCallback callback );
112
+
71
113
/**
72
114
* Releases the transport connection. When the connection is already closed this method does
73
115
* nothing.
0 commit comments