blob: 8cd841b052121da1adf04fa2464d74b043599b76 [file] [log] [blame]
package org.eclipse.cdt.debug.edc.tests.tcfagent;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import org.eclipse.cdt.debug.edc.tcf.extension.services.AbstractTCFService;
import org.eclipse.cdt.debug.edc.tcf.extension.services.ISettings;
import org.eclipse.tm.tcf.protocol.IChannel;
import org.eclipse.tm.tcf.protocol.IChannel.ICommandServer;
import org.eclipse.tm.tcf.protocol.IService;
import org.eclipse.tm.tcf.protocol.IToken;
import org.eclipse.tm.tcf.protocol.JSON;
public class SettingsService extends AbstractTCFService {
private final HashMap<String, Object> settingsValues = new HashMap<String, Object>();
public static final String[] supportedSettings = {
"TestSetting_1",
"TestSetting_2",
};
public class CommandServer extends AbstractCommandServer {
public void getIds(IToken token, String name, Object[] args) throws IOException {
getChannel().sendResult(token, JSON.toJSONSequence(new Object[] { null,
supportedSettings }));
}
public void set(IToken token, String name, Object[] args) throws IOException {
@SuppressWarnings("unchecked")
Collection<Object>
ids = (Collection<Object>) args[1],
values = (Collection<Object>) args[2];
handleSetValues(token, (String) args[0], ids.toArray(new String[ids.size()]), values.toArray());
}
private void handleSetValues(IToken token, String context, String[] ids, Object[] values) throws IOException {
if (ids.length != values.length) {
throw new IOException("ids[] != values[] length");
}
for (int i = 0; i < ids.length; i++) {
settingsValues.put(ids[i], values[i]);
}
getChannel().sendResult(token, JSON.toJSONSequence(new Object[] { null }));
}
}
public SettingsService(IChannel channel) {
super(channel);
}
public String getName() {
return ISettings.NAME;
}
public Object getSettingValue(String id) {
return settingsValues.get(id);
}
@Override
protected ICommandServer getCommandServer() {
return new CommandServer();
}
}