Commit 2125b96e authored by legoc's avatar legoc
Browse files

Added remote control methods

parent 98a3b5f5
4.0.0
-----
* Remote control management
3.4.0 05/02/2020
-----
* Token management
......
......@@ -24,8 +24,10 @@ package fr.ill.ics.bridge.events;
*/
public class TokenEvent {
public enum RemoteControlServerState {DISABLED, ENABLED};
public enum TokenServerState {FREE, OWNED};
private RemoteControlServerState remoteControlState = RemoteControlServerState.DISABLED;
private TokenServerState state = TokenServerState.FREE;
private int ownerClientID;
private String ownerEndpoint;
......@@ -35,6 +37,14 @@ public class TokenEvent {
this.ownerEndpoint = ownerEndpoint;
}
public void setRemoteControlState(RemoteControlServerState remoteControlState) {
this.remoteControlState = remoteControlState;
}
public RemoteControlServerState getRemoteControlState() {
return remoteControlState;
}
public void setState(TokenServerState state) {
this.state = state;
}
......
......@@ -43,6 +43,7 @@ public class DataAccessor {
public enum ClientCommandState {INACTIVE, ACTIVE, PAUSED, PAUSING, STOPPING, RESTARTING, PENDING, STARTING};
public enum ClientConfigurationState {ENABLED, DISABLED, TREE, PROPERTY};
public enum ClientConditionState {ACTIVE, INACTIVE, ON_ACTIVATION_DELAY};
public enum ClientRemoteControlState {DISABLED, ENABLED};
public enum ClientTokenState {FREE, OWNED};
private String serverId;
......
......@@ -35,12 +35,14 @@ import fr.ill.ics.nomadserver.notification.NotificationMessage.ConditionStateCha
import fr.ill.ics.nomadserver.notification.NotificationMessage.ConfigurationChanged;
import fr.ill.ics.nomadserver.notification.NotificationMessage.PropertyChanged;
import fr.ill.ics.nomadserver.notification.NotificationMessage.TokenState;
import fr.ill.ics.nomadserver.notification.NotificationMessage.TokenState.RemoteControlState;
import fr.ill.ics.nomadserver.notification.NotificationMessage.TokenState.State;
import fr.ill.ics.nomadserver.notification.NotificationMessage.UserVariableStateChanged;
import fr.ill.ics.nomadserver.notification.NotificationMessage.UserVariableValueChanged;
import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientCommandState;
import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientConditionState;
import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientConfigurationState;
import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientRemoteControlState;
import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientTokenState;
import fr.ill.ics.nscclient.serverconnection.ServerInstance;
import fr.ill.ics.nscclient.sessionmanagement.SessionManager;
......@@ -273,6 +275,16 @@ public class DataChangeSubscriber {
}
private void notifyTokenStateChanged(TokenState message) {
ClientRemoteControlState remoteControlState = ClientRemoteControlState.DISABLED;
if (message.getRemoteControlState() == RemoteControlState.DISABLED) {
remoteControlState = ClientRemoteControlState.DISABLED;
}
else if (message.getRemoteControlState() == RemoteControlState.ENABLED) {
remoteControlState = ClientRemoteControlState.ENABLED;
}
ClientTokenState state = ClientTokenState.FREE;
if (message.getState() == State.FREE) {
......@@ -282,7 +294,7 @@ public class DataChangeSubscriber {
state = ClientTokenState.OWNED;
}
DataNotificationClient.getInstance().tokenStateChanged(state, message.getOwnerClientID(), message.getOwnerEndpoint());
DataNotificationClient.getInstance().tokenStateChanged(remoteControlState, state, message.getOwnerClientID(), message.getOwnerEndpoint());
}
private void notifyChatMessage(ChatMessage message) {
......
......@@ -54,10 +54,12 @@ import fr.ill.ics.bridge.listeners.TokenEventListener;
import fr.ill.ics.core.property.Property;
import fr.ill.ics.core.property.PropertyManager;
import fr.ill.ics.nomadserver.common.Common.ConfigurationStateType;
import fr.ill.ics.nomadserver.notification.NotificationMessage.TokenState.RemoteControlState;
import fr.ill.ics.nscclient.dataprovider.CommandDatabase;
import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientCommandState;
import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientConditionState;
import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientConfigurationState;
import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientRemoteControlState;
import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientTokenState;
import fr.ill.ics.nscclient.dataprovider.ServantDatabase;
import fr.ill.ics.util.ConfigManager;
......@@ -179,9 +181,9 @@ public class DataNotificationClient {
}
}
public void tokenStateChanged(ClientTokenState state, int ownerClientID, String ownerEndpoint) {
public void tokenStateChanged(ClientRemoteControlState remoteControlState, ClientTokenState state, int ownerClientID, String ownerEndpoint) {
synchronized (pendingChanges) {
TokenChangedNotificationData change = new TokenChangedNotificationData(state, ownerClientID, ownerEndpoint);
TokenChangedNotificationData change = new TokenChangedNotificationData(remoteControlState, state, ownerClientID, ownerEndpoint);
updatePendingChanges(change);
}
}
......@@ -505,13 +507,20 @@ public class DataNotificationClient {
}
}
public void notifyTokenStateChanged(ClientTokenState state, int ownerClientID, String ownerEndpoint) {
public void notifyTokenStateChanged(ClientRemoteControlState clientRemoteControlState, ClientTokenState state, int ownerClientID, String ownerEndpoint) {
synchronized (tokenChangeListeners) {
Iterator<TokenEventListener> it = tokenChangeListeners.iterator();
while (it.hasNext()) {
TokenEventListener listener = it.next();
TokenEvent event = new TokenEvent(ownerClientID, ownerEndpoint);
if (clientRemoteControlState == ClientRemoteControlState.DISABLED) {
event.setRemoteControlState(TokenEvent.RemoteControlServerState.DISABLED);
} else {
event.setRemoteControlState(TokenEvent.RemoteControlServerState.ENABLED);
}
if (state == ClientTokenState.FREE) {
event.setState(TokenEvent.TokenServerState.FREE);
} else {
......@@ -591,7 +600,7 @@ public class DataNotificationClient {
} else if (data instanceof TokenChangedNotificationData) {
TokenChangedNotificationData tokenChangedData = (TokenChangedNotificationData)data;
notifyTokenStateChanged(tokenChangedData.getState(), tokenChangedData.getOwnerClientID(), tokenChangedData.getOwnerEndpoint());
notifyTokenStateChanged(tokenChangedData.getRemoteControlState(), tokenChangedData.getState(), tokenChangedData.getOwnerClientID(), tokenChangedData.getOwnerEndpoint());
} else if (data instanceof ChatNotificationData) {
ChatNotificationData chatData = (ChatNotificationData)data;
......
......@@ -18,20 +18,27 @@
package fr.ill.ics.nscclient.notification;
import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientRemoteControlState;
import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientTokenState;
public class TokenChangedNotificationData implements INotificationData {
private ClientRemoteControlState remoteControlState;
private ClientTokenState state;
private int ownerClientID;
private String ownerEndpoint;
public TokenChangedNotificationData(ClientTokenState state, int ownerClientID, String ownerEndpoint) {
public TokenChangedNotificationData(ClientRemoteControlState remoteControlState, ClientTokenState state, int ownerClientID, String ownerEndpoint) {
this.remoteControlState = remoteControlState;
this.state = state;
this.ownerClientID = ownerClientID;
this.ownerEndpoint = ownerEndpoint;
}
public ClientRemoteControlState getRemoteControlState() {
return remoteControlState;
}
public ClientTokenState getState() {
return state;
}
......@@ -56,14 +63,15 @@ public class TokenChangedNotificationData implements INotificationData {
if (otherOne.getOwnerEndpoint().equals(ownerEndpoint)
&& otherOne.getOwnerClientID() == ownerClientID
&& otherOne.getState() == state) {
&& otherOne.getState() == state
&& otherOne.getRemoteControlState() == remoteControlState) {
return true;
}
return false;
}
public int hashCode() {
String id = "token " + ownerClientID + "." + state;
String id = "token " + ownerClientID + "." + state + "." + remoteControlState;
return id.hashCode();
}
}
\ No newline at end of file
......@@ -123,6 +123,53 @@ public class SessionManager {
}
}
public void enableRemoteControl(String clientType) {
// Create the message type.
SessionRequests.Message type = SessionRequests.Message.newBuilder()
.setType(SessionRequests.Message.Type.EnableRemoteControl)
.build();
// Create the request.
SessionRequests.RemoteControlRequest request = SessionRequests.RemoteControlRequest.newBuilder()
.setClientType(clientType)
.setClientID(clientId)
.build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse.parseFrom(sessionRequester.receive());
}
catch (InvalidProtocolBufferException e) {
System.err.println("error in parsing response of requestToken");
}
}
public void disableRemoteControl(String clientType) {
// Create the message type.
SessionRequests.Message type = SessionRequests.Message.newBuilder()
.setType(SessionRequests.Message.Type.DisableRemoteControl)
.build();
// Create the request.
SessionRequests.RemoteControlRequest request = SessionRequests.RemoteControlRequest.newBuilder()
.setClientType(clientType)
.setClientID(clientId)
.build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse.parseFrom(sessionRequester.receive());
}
catch (InvalidProtocolBufferException e) {
System.err.println("error in parsing response of requestToken");
}
}
public void requestToken(String clientType) {
// Create the message type.
......
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