Commit c1e4efeb authored by legoc's avatar legoc
Browse files

Added user in different SessionManager requests and notification of token state

parent d0b33f70
...@@ -47,17 +47,17 @@ public class TokenManager { ...@@ -47,17 +47,17 @@ public class TokenManager {
public void requireToken() { public void requireToken() {
// for the moment => immediately accepted // for the moment => immediately accepted
TokenEvent event = new TokenEvent(0, "?"); TokenEvent event = new TokenEvent(0, "?", "?");
event.setState(TokenServerState.OWNED); event.setState(TokenServerState.OWNED);
} }
public void freeToken() { public void freeToken() {
SessionManager.getInstance(SERVER_ID).releaseToken(); SessionManager.getInstance(SERVER_ID).releaseToken("USER");
} }
public void askForToken(String clientType) { public void askForToken(String clientType) {
SessionManager.getInstance(SERVER_ID).requestToken(clientType); SessionManager.getInstance(SERVER_ID).requestToken(clientType, "USER");
} }
} }
\ No newline at end of file
...@@ -31,10 +31,12 @@ public class TokenEvent { ...@@ -31,10 +31,12 @@ public class TokenEvent {
private TokenServerState state = TokenServerState.FREE; private TokenServerState state = TokenServerState.FREE;
private int ownerClientID; private int ownerClientID;
private String ownerEndpoint; private String ownerEndpoint;
private String user;
public TokenEvent(int ownerClientID, String ownerEndpoint) { public TokenEvent(int ownerClientID, String ownerEndpoint, String user) {
this.ownerClientID = ownerClientID; this.ownerClientID = ownerClientID;
this.ownerEndpoint = ownerEndpoint; this.ownerEndpoint = ownerEndpoint;
this.user = user;
} }
public void setRemoteControlState(RemoteControlServerState remoteControlState) { public void setRemoteControlState(RemoteControlServerState remoteControlState) {
...@@ -61,4 +63,8 @@ public class TokenEvent { ...@@ -61,4 +63,8 @@ public class TokenEvent {
return ownerEndpoint; return ownerEndpoint;
} }
public String getUser() {
return user;
}
} }
\ No newline at end of file
...@@ -294,7 +294,7 @@ public class DataChangeSubscriber { ...@@ -294,7 +294,7 @@ public class DataChangeSubscriber {
state = ClientTokenState.OWNED; state = ClientTokenState.OWNED;
} }
DataNotificationClient.getInstance().tokenStateChanged(remoteControlState, state, message.getOwnerClientID(), message.getOwnerEndpoint()); DataNotificationClient.getInstance().tokenStateChanged(remoteControlState, state, message.getOwnerClientID(), message.getOwnerEndpoint(), message.getUser());
} }
private void notifyChatMessage(ChatMessage message) { private void notifyChatMessage(ChatMessage message) {
......
...@@ -180,9 +180,9 @@ public class DataNotificationClient { ...@@ -180,9 +180,9 @@ public class DataNotificationClient {
} }
} }
public void tokenStateChanged(ClientRemoteControlState remoteControlState, ClientTokenState state, int ownerClientID, String ownerEndpoint) { public void tokenStateChanged(ClientRemoteControlState remoteControlState, ClientTokenState state, int ownerClientID, String ownerEndpoint, String user) {
synchronized (pendingChanges) { synchronized (pendingChanges) {
TokenChangedNotificationData change = new TokenChangedNotificationData(remoteControlState, state, ownerClientID, ownerEndpoint); TokenChangedNotificationData change = new TokenChangedNotificationData(remoteControlState, state, ownerClientID, ownerEndpoint, user);
updatePendingChanges(change); updatePendingChanges(change);
} }
} }
...@@ -506,13 +506,13 @@ public class DataNotificationClient { ...@@ -506,13 +506,13 @@ public class DataNotificationClient {
} }
} }
public void notifyTokenStateChanged(ClientRemoteControlState clientRemoteControlState, ClientTokenState state, int ownerClientID, String ownerEndpoint) { public void notifyTokenStateChanged(ClientRemoteControlState clientRemoteControlState, ClientTokenState state, int ownerClientID, String ownerEndpoint, String user) {
synchronized (tokenChangeListeners) { synchronized (tokenChangeListeners) {
Iterator<TokenEventListener> it = tokenChangeListeners.iterator(); Iterator<TokenEventListener> it = tokenChangeListeners.iterator();
while (it.hasNext()) { while (it.hasNext()) {
TokenEventListener listener = it.next(); TokenEventListener listener = it.next();
TokenEvent event = new TokenEvent(ownerClientID, ownerEndpoint); TokenEvent event = new TokenEvent(ownerClientID, ownerEndpoint, user);
if (clientRemoteControlState == ClientRemoteControlState.DISABLED) { if (clientRemoteControlState == ClientRemoteControlState.DISABLED) {
event.setRemoteControlState(TokenEvent.RemoteControlServerState.DISABLED); event.setRemoteControlState(TokenEvent.RemoteControlServerState.DISABLED);
...@@ -599,7 +599,7 @@ public class DataNotificationClient { ...@@ -599,7 +599,7 @@ public class DataNotificationClient {
} else if (data instanceof TokenChangedNotificationData) { } else if (data instanceof TokenChangedNotificationData) {
TokenChangedNotificationData tokenChangedData = (TokenChangedNotificationData)data; TokenChangedNotificationData tokenChangedData = (TokenChangedNotificationData)data;
notifyTokenStateChanged(tokenChangedData.getRemoteControlState(), tokenChangedData.getState(), tokenChangedData.getOwnerClientID(), tokenChangedData.getOwnerEndpoint()); notifyTokenStateChanged(tokenChangedData.getRemoteControlState(), tokenChangedData.getState(), tokenChangedData.getOwnerClientID(), tokenChangedData.getOwnerEndpoint(), tokenChangedData.getUser());
} else if (data instanceof ChatNotificationData) { } else if (data instanceof ChatNotificationData) {
ChatNotificationData chatData = (ChatNotificationData)data; ChatNotificationData chatData = (ChatNotificationData)data;
......
...@@ -27,12 +27,14 @@ public class TokenChangedNotificationData implements INotificationData { ...@@ -27,12 +27,14 @@ public class TokenChangedNotificationData implements INotificationData {
private ClientTokenState state; private ClientTokenState state;
private int ownerClientID; private int ownerClientID;
private String ownerEndpoint; private String ownerEndpoint;
private String user;
public TokenChangedNotificationData(ClientRemoteControlState remoteControlState, ClientTokenState state, int ownerClientID, String ownerEndpoint) { public TokenChangedNotificationData(ClientRemoteControlState remoteControlState, ClientTokenState state, int ownerClientID, String ownerEndpoint, String user) {
this.remoteControlState = remoteControlState; this.remoteControlState = remoteControlState;
this.state = state; this.state = state;
this.ownerClientID = ownerClientID; this.ownerClientID = ownerClientID;
this.ownerEndpoint = ownerEndpoint; this.ownerEndpoint = ownerEndpoint;
this.user = user;
} }
public ClientRemoteControlState getRemoteControlState() { public ClientRemoteControlState getRemoteControlState() {
...@@ -50,6 +52,10 @@ public class TokenChangedNotificationData implements INotificationData { ...@@ -50,6 +52,10 @@ public class TokenChangedNotificationData implements INotificationData {
public String getOwnerEndpoint() { public String getOwnerEndpoint() {
return ownerEndpoint; return ownerEndpoint;
} }
public String getUser() {
return user;
}
public boolean equals(Object obj) { public boolean equals(Object obj) {
if(this == obj) { if(this == obj) {
...@@ -63,6 +69,7 @@ public class TokenChangedNotificationData implements INotificationData { ...@@ -63,6 +69,7 @@ public class TokenChangedNotificationData implements INotificationData {
if (otherOne.getOwnerEndpoint().equals(ownerEndpoint) if (otherOne.getOwnerEndpoint().equals(ownerEndpoint)
&& otherOne.getOwnerClientID() == ownerClientID && otherOne.getOwnerClientID() == ownerClientID
&& otherOne.getUser() == user
&& otherOne.getState() == state && otherOne.getState() == state
&& otherOne.getRemoteControlState() == remoteControlState) { && otherOne.getRemoteControlState() == remoteControlState) {
return true; return true;
...@@ -71,7 +78,7 @@ public class TokenChangedNotificationData implements INotificationData { ...@@ -71,7 +78,7 @@ public class TokenChangedNotificationData implements INotificationData {
} }
public int hashCode() { public int hashCode() {
String id = "token " + ownerClientID + "." + state + "." + remoteControlState; String id = "token " + ownerClientID + "." + user + "." + state + "." + remoteControlState;
return id.hashCode(); return id.hashCode();
} }
} }
\ No newline at end of file
...@@ -165,7 +165,7 @@ public class SessionManager { ...@@ -165,7 +165,7 @@ public class SessionManager {
} }
} }
public void enableRemoteControl(String clientType) { public void enableRemoteControl(String clientType, String user) {
// Create the message type. // Create the message type.
SessionRequests.Message type = SessionRequests.Message.newBuilder() SessionRequests.Message type = SessionRequests.Message.newBuilder()
...@@ -176,6 +176,7 @@ public class SessionManager { ...@@ -176,6 +176,7 @@ public class SessionManager {
SessionRequests.RemoteControlRequest request = SessionRequests.RemoteControlRequest.newBuilder() SessionRequests.RemoteControlRequest request = SessionRequests.RemoteControlRequest.newBuilder()
.setClientType(clientType) .setClientType(clientType)
.setClientID(clientId) .setClientID(clientId)
.setUser(user)
.build(); .build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray()); sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
...@@ -188,7 +189,7 @@ public class SessionManager { ...@@ -188,7 +189,7 @@ public class SessionManager {
} }
} }
public void disableRemoteControl(String clientType) { public void disableRemoteControl(String clientType, String user) {
// Create the message type. // Create the message type.
SessionRequests.Message type = SessionRequests.Message.newBuilder() SessionRequests.Message type = SessionRequests.Message.newBuilder()
...@@ -199,6 +200,7 @@ public class SessionManager { ...@@ -199,6 +200,7 @@ public class SessionManager {
SessionRequests.RemoteControlRequest request = SessionRequests.RemoteControlRequest.newBuilder() SessionRequests.RemoteControlRequest request = SessionRequests.RemoteControlRequest.newBuilder()
.setClientType(clientType) .setClientType(clientType)
.setClientID(clientId) .setClientID(clientId)
.setUser(user)
.build(); .build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray()); sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
...@@ -212,7 +214,7 @@ public class SessionManager { ...@@ -212,7 +214,7 @@ public class SessionManager {
} }
public void requestToken(String clientType) { public void requestToken(String clientType, String user) {
// Create the message type. // Create the message type.
SessionRequests.Message type = SessionRequests.Message.newBuilder() SessionRequests.Message type = SessionRequests.Message.newBuilder()
...@@ -223,6 +225,7 @@ public class SessionManager { ...@@ -223,6 +225,7 @@ public class SessionManager {
SessionRequests.GetTokenRequest request = SessionRequests.GetTokenRequest.newBuilder() SessionRequests.GetTokenRequest request = SessionRequests.GetTokenRequest.newBuilder()
.setClientType(clientType) .setClientType(clientType)
.setClientID(clientId) .setClientID(clientId)
.setUser(user)
.build(); .build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray()); sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
...@@ -235,7 +238,7 @@ public class SessionManager { ...@@ -235,7 +238,7 @@ public class SessionManager {
} }
} }
public void releaseToken() { public void releaseToken(String user) {
// Create the message type. // Create the message type.
SessionRequests.Message type = SessionRequests.Message.newBuilder() SessionRequests.Message type = SessionRequests.Message.newBuilder()
...@@ -245,6 +248,7 @@ public class SessionManager { ...@@ -245,6 +248,7 @@ public class SessionManager {
// Create the request. // Create the request.
SessionRequests.ReleaseTokenRequest request = SessionRequests.ReleaseTokenRequest.newBuilder() SessionRequests.ReleaseTokenRequest request = SessionRequests.ReleaseTokenRequest.newBuilder()
.setClientID(clientId) .setClientID(clientId)
.setUser(user)
.build(); .build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray()); sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment