Skip to content

Commit 9980299

Browse files
committed
Propagate code and reason from disconnect from server on client
1 parent 44def2e commit 9980299

File tree

17 files changed

+50
-29
lines changed

17 files changed

+50
-29
lines changed

OCPP-J/src/main/java/eu/chargetime/ocpp/WebSocketReceiver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
MIT License
66
77
Copyright (C) 2016-2018 Thomas Volden <[email protected]>
8-
8+
Copyright (C) 2022 Emil Melar <[email protected]>
99
Permission is hereby granted, free of charge, to any person obtaining a copy
1010
of this software and associated documentation files (the "Software"), to deal
1111
in the Software without restriction, including without limitation the rights
@@ -37,7 +37,7 @@ public WebSocketReceiver(WebSocketReceiverEvents handler) {
3737
@Override
3838
public void disconnect() {
3939
receiverEvents.close();
40-
handler.disconnected();
40+
handler.disconnected(0, "disconnect() method called");
4141
}
4242

4343
void relay(String message) {

OCPP-J/src/main/java/eu/chargetime/ocpp/WebSocketTransmitter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
MIT License
77
88
Copyright (C) 2016-2018 Thomas Volden
9+
Copyright (C) 2022 Emil Melar <[email protected]>
910
1011
Permission is hereby granted, free of charge, to any person obtaining a copy
1112
of this software and associated documentation files (the "Software"), to deal
@@ -105,7 +106,7 @@ public void onClose(int code, String reason, boolean remote) {
105106
logger.debug(
106107
"On connection close (code: {}, reason: {}, remote: {})", code, reason, remote);
107108

108-
events.disconnected();
109+
events.disconnected(code, reason);
109110
}
110111

111112
@Override

ocpp-common/src/main/java/eu/chargetime/ocpp/Client.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
MIT License
77
88
Copyright (C) 2016-2018 Thomas Volden
9+
Copyright (C) 2022 Emil Melar <[email protected]>
910
1011
Permission is hereby granted, free of charge, to any person obtaining a copy
1112
of this software and associated documentation files (the "Software"), to deal
@@ -113,8 +114,8 @@ public void handleError(
113114
}
114115

115116
@Override
116-
public void handleConnectionClosed() {
117-
if (events != null) events.connectionClosed();
117+
public void handleConnectionClosed(int code, String reason) {
118+
if (events != null) events.connectionClosed(code, reason);
118119
}
119120

120121
@Override

ocpp-common/src/main/java/eu/chargetime/ocpp/ClientEvents.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
MIT License
88
9-
Copyright (C) 2017 Emil Christopher Solli Melar
9+
Copyright (C) 2022 Emil Melar <[email protected]>
1010
1111
Permission is hereby granted, free of charge, to any person obtaining a copy
1212
of this software and associated documentation files (the "Software"), to deal
@@ -30,5 +30,5 @@ of this software and associated documentation files (the "Software"), to deal
3030
public interface ClientEvents {
3131
void connectionOpened();
3232

33-
void connectionClosed();
33+
void connectionClosed(int code, String reason);
3434
}

ocpp-common/src/main/java/eu/chargetime/ocpp/Communicator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
MIT License
77
88
Copyright (C) 2016-2018 Thomas Volden
9+
Copyright (C) 2022 Emil Melar <[email protected]>
910
1011
Permission is hereby granted, free of charge, to any person obtaining a copy
1112
of this software and associated documentation files (the "Software"), to deal
@@ -292,8 +293,8 @@ public void receivedMessage(Object input) {
292293
}
293294

294295
@Override
295-
public void disconnected() {
296-
events.onDisconnected();
296+
public void disconnected(int code, String reason) {
297+
events.onDisconnected(code, reason);
297298
}
298299
}
299300

ocpp-common/src/main/java/eu/chargetime/ocpp/CommunicatorEvents.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
MIT License
88
99
Copyright (C) 2016-2018 Thomas Volden
10+
Copyright (C) 2022 Emil Melar <[email protected]>
1011
1112
Permission is hereby granted, free of charge, to any person obtaining a copy
1213
of this software and associated documentation files (the "Software"), to deal
@@ -66,8 +67,10 @@ public interface CommunicatorEvents {
6667
*/
6768
void onError(String id, String errorCode, String errorDescription, Object payload);
6869

69-
/** The connection was disconnected. */
70-
void onDisconnected();
70+
/** The connection was disconnected.
71+
* @param code
72+
* @param reason*/
73+
void onDisconnected(int code, String reason);
7174

7275
/** A connection was established. */
7376
void onConnected();

ocpp-common/src/main/java/eu/chargetime/ocpp/RadioEvents.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
MIT License
88
99
Copyright (C) 2016-2018 Thomas Volden
10+
Copyright (C) 2022 Emil Melar <[email protected]>
1011
1112
Permission is hereby granted, free of charge, to any person obtaining a copy
1213
of this software and associated documentation files (the "Software"), to deal
@@ -39,6 +40,8 @@ public interface RadioEvents {
3940
*/
4041
void receivedMessage(Object message);
4142

42-
/** Disconnected from node. */
43-
void disconnected();
43+
/** Disconnected from node.
44+
* @param code
45+
* @param reason*/
46+
void disconnected(int code, String reason);
4447
}

ocpp-common/src/main/java/eu/chargetime/ocpp/Server.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
MIT License
66
77
Copyright (C) 2016-2018 Thomas Volden <[email protected]>
8+
Copyright (C) 2022 Emil Melar <[email protected]>
89
910
Permission is hereby granted, free of charge, to any person obtaining a copy
1011
of this software and associated documentation files (the "Software"), to deal
@@ -143,7 +144,7 @@ public void handleError(
143144
}
144145

145146
@Override
146-
public void handleConnectionClosed() {
147+
public void handleConnectionClosed(int code, String reason) {
147148
Optional<UUID> sessionIdOptional = getSessionID(session);
148149
if (sessionIdOptional.isPresent()) {
149150
serverEvents.lostSession(sessionIdOptional.get());

ocpp-common/src/main/java/eu/chargetime/ocpp/Session.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
MIT License
77
88
Copyright (C) 2016-2018 Thomas Volden
9+
Copyright (C) 2022 Emil Melar <[email protected]>
910
1011
Permission is hereby granted, free of charge, to any person obtaining a copy
1112
of this software and associated documentation files (the "Software"), to deal
@@ -221,8 +222,8 @@ public void onError(String id, String errorCode, String errorDescription, Object
221222
}
222223

223224
@Override
224-
public void onDisconnected() {
225-
events.handleConnectionClosed();
225+
public void onDisconnected(int code, String reason) {
226+
events.handleConnectionClosed(code, reason);
226227
}
227228

228229
@Override

ocpp-common/src/main/java/eu/chargetime/ocpp/SessionEvents.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
MIT License
1111
1212
Copyright (C) 2016-2018 Thomas Volden
13+
Copyright (C) 2022 Emil Melar <[email protected]>
1314
1415
Permission is hereby granted, free of charge, to any person obtaining a copy
1516
of this software and associated documentation files (the "Software"), to deal
@@ -59,8 +60,10 @@ public interface SessionEvents {
5960
*/
6061
void handleError(String uniqueId, String errorCode, String errorDescription, Object payload);
6162

62-
/** Handle a closed connection. */
63-
void handleConnectionClosed();
63+
/** Handle a closed connection.
64+
* @param code
65+
* @param reason*/
66+
void handleConnectionClosed(int code, String reason);
6467

6568
/** Handle a opened connection. */
6669
void handleConnectionOpened();

0 commit comments

Comments
 (0)