The code.ill.fr has been recreated and upgraded with the latest version this weekend, If you encounter any problem please inform the Helpdesk.

Commit 0d83ad6e authored by yannick legoc's avatar yannick legoc
Browse files

reimplemented getControllerNameWithRole + removed useless functions

parent a8e9d3d8
......@@ -80,5 +80,7 @@ public abstract class ControllerManager {
public abstract void updateDynamicProperties(Controller controller);
public abstract void reloadControllers();
public abstract String getControllerNameWithRole(Controller controller, String role);
}
......@@ -266,6 +266,12 @@ public class CorbaControllerManager extends ControllerManager implements ServerC
// reset controller information
reset();
}
@Override
public String getControllerNameWithRole(Controller controller, String role) {
CorbaController corbaController = (CorbaController)controller;
return servantManager.getControllerNameWithRole(corbaController.getId(), role);
}
}
\ No newline at end of file
......@@ -65,68 +65,7 @@ public class CorbaServant implements Controller {
this.servantDescriptor = descriptor;
this.servantId = servantId;
}
public void init() {
// initialise properties
initProperties();
// initialise commands
initCommands();
}
private void initProperties() {
try {
ListIterator iterator = servant.getProperties(databaseId);
// iterate over the list and create a new non-corba ServantDescriptor for each item
while (iterator.hasNext()) {
ListItem item = iterator.next();
PropertyDescriptor corbaDescriptor = PropertyDescriptorHelper.narrow(item);
// copy sequence values into vector
List<Integer> ids = new ArrayList<Integer>();
int[] idArray = corbaDescriptor.getIDArray();
int propertyId = idArray[0];
for (int i = 1; i < idArray.length; i++) {
ids.add(new Integer(idArray[i]));
}
if (corbaDescriptor.isDynamic()) {
PropertyDatabase.getInstance().addDynamicPropertyDescriptor(servantDescriptor.getId(), new DynamicPropertyDescriptor(propertyId, ids, corbaDescriptor.getName(), corbaDescriptor.getType()));
} else {
PropertyDatabase.getInstance().addStandardPropertyDescriptor(servantDescriptor.getId(), new StandardPropertyDescriptor(propertyId, corbaDescriptor.getName(), corbaDescriptor.getType()));
}
}
// release the corba object
iterator.releaseIterator();
} catch (IteratorFailureException e) {
e.printStackTrace();
}
}
private void initCommands() {
try {
ListIterator iterator = servant.getCommands(databaseId);
// iterate over the list and create a new non-corba ServantDescriptor for each item
while (iterator.hasNext()) {
ListItem item = iterator.next();
CommandDescriptor commandDescriptor = CommandDescriptorHelper.narrow(item);
CommandDatabase.getInstance().addCommandDescriptor(servantDescriptor.getId(), new ClientCommandDescriptor(commandDescriptor.getID(), commandDescriptor.getName()));
}
// release the corba object
iterator.releaseIterator();
} catch (IteratorFailureException e) {
e.printStackTrace();
}
}
public String getName() {
return servantDescriptor.getName();
}
......@@ -159,25 +98,7 @@ public class CorbaServant implements Controller {
}
public String getControllerNameWithRole(String role) {
try {
ListIterator iterator = servant.getChildServants(databaseId);
// iterate over the list and create a new non-corba ServantDescriptor for each item
while (iterator.hasNext()) {
ListItem item = iterator.next();
ChildServantDescriptor childDescriptor = ChildServantDescriptorHelper.narrow(item);
String nName = childDescriptor.getNName();
if (nName.equals(role)) {
return childDescriptor.getNameArray()[0];
}
}
} catch (IteratorFailureException e) {
e.printStackTrace();
}
return "?";
return ControllerManager.getInstance().getControllerNameWithRole(this, role);
}
public Set getCommandNames() {
......
......@@ -58,8 +58,13 @@ public class CorbaServantManager {
private ServantManager servantManager;
private static class ChildServants {
String name;
List<String> childNames = new LinkedList<String>();
}
private Map<Integer, CorbaServant> servants = new HashMap<Integer, CorbaServant>();
private Map<Integer, List<String>> childServantNames = new HashMap<Integer, List<String>>();
private Map<Integer, List<ChildServants>> childServantNames = new HashMap<Integer, List<ChildServants>>();
private final static String PARAMETERIZABLE_SCAN_1D = "parameterizable_scan_1d";
......@@ -82,22 +87,11 @@ public class CorbaServantManager {
CorbaController controller = (CorbaController)servants.get(descriptor.getId());
if (controller != null) {
return controller;
} else {
System.err.println("cannot find a controller for servant with id " + descriptor.getId());
}
try {
if (descriptor.getType().equals(PARAMETERIZABLE_SCAN_1D)) {
controller = new CorbaIcsParameterizableScan1D(DATABASE_ID, descriptor.getId(), servantManager.getController(descriptor.getId()), descriptor);
} else {
controller = new CorbaController(DATABASE_ID, descriptor.getId(), servantManager.getController(descriptor.getId()), descriptor);
}
controller.init();
servants.put(descriptor.getId(), controller);
return controller;
} catch (NoSuchServantException e) {
return null;
}
return null;
}
private CorbaController createCorbaController(ClientServantDescriptor descriptor) {
......@@ -133,29 +127,11 @@ public class CorbaServantManager {
CorbaDriver driver = (CorbaDriver)servants.get(descriptor.getId());
if (driver != null) {
return driver;
} else {
System.err.println("cannot find a driver for servant with id " + descriptor.getId());
}
try {
Driver corbaDriver = servantManager.getDriver(descriptor.getId());
driver = new CorbaDriver(DATABASE_ID, descriptor.getId(), corbaDriver, descriptor);
DriverMode corbaMode = corbaDriver.getMode(DATABASE_ID);
if (corbaMode == DriverMode.REAL) {
driver.setMode(Mode.REAL);
} else if (corbaMode == DriverMode.SIMULATED) {
driver.setMode(Mode.SIMULATED);
} else if (corbaMode == DriverMode.PERFECT) {
driver.setMode(Mode.PERFECT);
}
driver.init();
servants.put(descriptor.getId(), driver);
return driver;
} catch (NoSuchServantException e) {
return null;
}
return null;
}
private CorbaDriver createCorbaDriver(ClientServantDescriptor descriptor, int channel, Mode mode) {
......@@ -168,33 +144,18 @@ public class CorbaServantManager {
return driver;
}
public List getControllers() {
List controllers = new ArrayList();
try {
ListIterator iterator = servantManager.getControllersIterator(DATABASE_ID);
// iterate over the list and create a new non-corba ServantDescriptor for each item
while (iterator.hasNext()) {
ListItem item = iterator.next();
ServantDescriptor corbaDescriptor = ServantDescriptorHelper.narrow(item);
controllers.add(new ClientServantDescriptor(corbaDescriptor.getID(), corbaDescriptor.getName(), corbaDescriptor.getClientType(), corbaDescriptor.getFamily(), corbaDescriptor.isCommand(), corbaDescriptor.isVisible(), corbaDescriptor.isEnabled(), corbaDescriptor.isFavourite(), corbaDescriptor.isRoot()));
}
// release the corba object
iterator.releaseIterator();
} catch (IteratorFailureException e) {
e.printStackTrace();
}
return controllers;
}
public List<String> getChildServants(int id) {
return childServantNames.get(id);
// return the full list by aggregating the child names
List<String> fullList = new LinkedList<String>();
List<ChildServants> childServantsList = childServantNames.get(id);
for (ChildServants c : childServantsList) {
fullList.addAll(c.childNames);
}
return fullList;
}
public void pauseSpies(boolean isPaused) {
......@@ -296,7 +257,7 @@ public class CorbaServantManager {
}
// add the list of child names
LinkedList<String> childNames = new LinkedList<String>();
LinkedList<ChildServants> childNames = new LinkedList<ChildServants>();
// first level of child is not necessary to get the information
// ex: for drivers, pbChild1 = "children"
......@@ -306,12 +267,17 @@ public class CorbaServantManager {
while (cd.hasNext()) {
ServantDataConfiguration.ChildDescriptor pbChild1 = cd.next();
ChildServants childServants = new ChildServants();
childServants.name = pbChild1.getName();
Iterator<ServantDataConfiguration.ChildDescriptor.Child> ccd = pbChild1.getChildArrayList().iterator();
while (ccd.hasNext()) {
ServantDataConfiguration.ChildDescriptor.Child pbChild2 = ccd.next();
childNames.add(pbChild2.getName());
childServants.childNames.add(pbChild2.getName());
}
childNames.add(childServants);
}
childServantNames.put(descriptor.getId(), childNames);
......@@ -486,4 +452,17 @@ public class CorbaServantManager {
}
public String getControllerNameWithRole(int servantID, String role) {
List<ChildServants> childServants = childServantNames.get(servantID);
for (ChildServants s : childServants) {
if (s.name.equals(role)) {
return s.childNames.get(0);
}
}
return "?";
}
}
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