Commit 72f55869 authored by yannick legoc's avatar yannick legoc
Browse files

Spy properties are added to PropertyDatabase at the initialisation of the client

parent 43696df6
......@@ -27,6 +27,7 @@ import java.util.Map.Entry;
import java.util.Set;
import fr.ill.ics.nscclient.servant.DynamicPropertyDescriptor;
import fr.ill.ics.nscclient.servant.SpyPropertyDescriptor;
import fr.ill.ics.nscclient.servant.StandardPropertyDescriptor;
public class PropertyDatabase {
......@@ -37,6 +38,8 @@ public class PropertyDatabase {
private Map<Integer, Set<Integer>> propertiesByServant; // KEY=Servant id VALUE=Set of StandardPropertyDescriptor ids
private Map<Integer, Set<DynamicPropertyDescriptor>> dynamicPropertiesByServant; // KEY=Servant id VALUE=Set of associated DynamicPropertyDescriptor
private Map<Integer, Set<SpyPropertyDescriptor>> spyPropertiesByServant; // KEY=Servant id VALUE=Set of associated SpyPropertyDescriptor
private static PropertyDatabase instance = null;
public static PropertyDatabase getInstance() {
......@@ -58,8 +61,9 @@ public class PropertyDatabase {
private void init() {
properties = new HashMap<Integer, StandardPropertyDescriptor>();
dynamicProperties = new HashMap<Integer, DynamicPropertyDescriptor>();
dynamicPropertiesByServant = new HashMap<Integer, Set<DynamicPropertyDescriptor>>();
propertiesByServant = new HashMap<Integer, Set<Integer>>();
dynamicPropertiesByServant = new HashMap<Integer, Set<DynamicPropertyDescriptor>>();
spyPropertiesByServant = new HashMap<Integer, Set<SpyPropertyDescriptor>>();
}
......@@ -71,7 +75,7 @@ public class PropertyDatabase {
public void addStandardPropertyDescriptor(int servantId, StandardPropertyDescriptor standardPropertyDescriptor) {
properties.put(standardPropertyDescriptor.getId(), standardPropertyDescriptor);
if (!propertiesByServant.containsKey(servantId)) {
Set set = new HashSet<Integer>();
Set<Integer> set = new HashSet<Integer>();
propertiesByServant.put(servantId, set);
}
propertiesByServant.get(servantId).add(standardPropertyDescriptor.getId());
......@@ -86,12 +90,27 @@ public class PropertyDatabase {
public void addDynamicPropertyDescriptor(int servantId, DynamicPropertyDescriptor dynamicPropertyDescriptor) {
dynamicProperties.put(dynamicPropertyDescriptor.getId(), dynamicPropertyDescriptor);
if (!dynamicPropertiesByServant.containsKey(servantId)) {
Set set = new HashSet<Integer>();
Set<DynamicPropertyDescriptor> set = new HashSet<DynamicPropertyDescriptor>();
dynamicPropertiesByServant.put(servantId, set);
}
dynamicPropertiesByServant.get(servantId).add(dynamicPropertyDescriptor);
}
public void addSpyPropertyDescriptor(int servantId, SpyPropertyDescriptor descriptor) {
if (!spyPropertiesByServant.containsKey(servantId)) {
Set<SpyPropertyDescriptor> set = new HashSet<SpyPropertyDescriptor>();
spyPropertiesByServant.put(servantId, set);
}
spyPropertiesByServant.get(servantId).add(descriptor);
if (descriptor.getSetpointID() != 0) {
System.out.println("spy property for servant " + servantId);
System.out.println(descriptor);
}
}
/**
*
* @param id
......
......@@ -20,7 +20,6 @@ package fr.ill.ics.nscclient.servant;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
......@@ -34,6 +33,7 @@ import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.ServantData;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.ServantDataUpdate;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.ServantDynamicProperties;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.ServantSpyProperties;
import fr.ill.ics.nomadserver.core.ServantManager;
import fr.ill.ics.nomadserver.core.ServantManagerPackage.NoSuchServantException;
import fr.ill.ics.nomadserver.core.ServantManagerPackage.ServantCreationException;
......@@ -232,7 +232,7 @@ public class CorbaServantManager {
ServantDatabase.getInstance().addController(descriptor);
servant = createCorbaController(descriptor);
}
// add the list of child names
LinkedList<ChildServants> childNames = new LinkedList<ChildServants>();
......@@ -292,6 +292,9 @@ public class CorbaServantManager {
CommandDatabase.getInstance().addCommandDescriptor(descriptor.getId(), new ClientCommandDescriptor(pbCommand.getID(), pbCommand.getName()));
}
// add the spy properties
addSpyProperties(servant.getId());
return servant;
}
......@@ -426,7 +429,6 @@ public class CorbaServantManager {
} catch (ServantCreationException e) {
return null;
}
}
public String getControllerNameWithRole(int servantID, String role) {
......@@ -441,5 +443,39 @@ public class CorbaServantManager {
return "?";
}
public void addSpyProperties(int servantID) {
try {
byte[] pbResult = servantManager.getServantSpyProperties(DATABASE_ID, servantID);
ServantSpyProperties servantSpyProperties = null;
try {
servantSpyProperties = ServantSpyProperties.parseFrom(new ByteArrayInputStream(pbResult));
} catch (IOException e) {
System.err.println("cannot parse servant spy properties data");
}
Iterator<ServantDataConfiguration.SpyPropertyDescriptor> p = servantSpyProperties.getPropertiesList().iterator();
while (p.hasNext()) {
ServantDataConfiguration.SpyPropertyDescriptor pbProperty = p.next();
SpyPropertyDescriptor descriptor = new SpyPropertyDescriptor(pbProperty.getActualID(),
pbProperty.getSetpointID(),
pbProperty.getOffsetID(),
pbProperty.getUnitID(),
pbProperty.getAlias());
PropertyDatabase.getInstance().addSpyPropertyDescriptor(servantID, descriptor);
}
} catch (NoSuchServantException e) {
}
}
}
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.nscclient.servant;
public class SpyPropertyDescriptor {
private int actualID;
private int setpointID;
private int offsetID;
private int unitID;
private String alias;
public SpyPropertyDescriptor(int actualID, int setpointID, int offsetID, int unitID, String alias) {
super();
this.actualID = actualID;
this.setpointID = setpointID;
this.offsetID = offsetID;
this.unitID = unitID;
this.alias = alias;
}
public int getActualID() {
return actualID;
}
public int getSetpointID() {
return setpointID;
}
public int getOffsetID() {
return offsetID;
}
public int getUnitID() {
return unitID;
}
public String getAlias() {
return alias;
}
@Override
public String toString() {
return "SpyPropertyDescriptor [actualID=" + actualID + ", setpointID="
+ setpointID + ", offsetID=" + offsetID + ", unitID=" + unitID
+ ", alias=" + alias + "]";
}
}
\ No newline at end of file
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