/******************************************************************************* | |
* Copyright (c) 2011 Nokia and others. | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v1.0 | |
* which accompanies this distribution, and is available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
* | |
* Contributors: | |
* Nokia - Initial API and implementation | |
*******************************************************************************/ | |
package org.eclipse.cdt.debug.edc.tests.tcfagent; | |
import org.eclipse.cdt.debug.edc.tcf.extension.AgentUtils; | |
import org.eclipse.cdt.debug.edc.tcf.extension.services.ILogging; | |
import org.eclipse.tm.tcf.protocol.IChannel; | |
import org.eclipse.tm.tcf.protocol.IService; | |
import org.eclipse.tm.tcf.protocol.IToken; | |
import org.eclipse.tm.tcf.protocol.JSON; | |
/** | |
* See {@link IUnitTestDriver} | |
*/ | |
public class UnitTestDriverService implements IService { | |
private final IChannel channel; | |
private class CommandServer implements IChannel.ICommandServer { | |
public void command(IToken token, String name, byte[] data) { | |
try { | |
command(token, name, JSON.parseSequence(data)); | |
} catch (Throwable x) { | |
channel.terminate(x); | |
} | |
} | |
private void command(IToken token, String name, Object[] args) throws Exception { | |
if (name.equals(IUnitTestDriver.COMMAND_LOGGING_WRITE)|| | |
name.equals(IUnitTestDriver.COMMAND_LOGGING_WRITELN) || | |
name.equals(IUnitTestDriver.COMMAND_LOGGING_DIALOG)) | |
{ | |
if (!AgentUtils.checkNumArgs(token, channel, args.length, 1)) | |
return; | |
String s = (String) args[0]; | |
// Now ask loggingService to send a event. | |
LoggingService loggingSvc = (LoggingService)channel.getLocalService(ILogging.NAME); | |
if (loggingSvc == null) | |
channel.sendResult(token, AgentUtils.jsonErr("LoggingService not supported by the agent.")); | |
else { | |
channel.sendResult(token, JSON.toJSONSequence(new Object[] { null })); | |
if (name.equals(IUnitTestDriver.COMMAND_LOGGING_WRITE)) | |
loggingSvc.write(s); | |
else if (name.equals(IUnitTestDriver.COMMAND_LOGGING_WRITELN)) | |
loggingSvc.writeln(s); | |
else if (name.equals(IUnitTestDriver.COMMAND_LOGGING_DIALOG)) | |
loggingSvc.dialog(0, s, s); | |
} | |
} | |
else { | |
channel.rejectCommand(token); | |
} | |
} | |
} | |
public UnitTestDriverService(IChannel channel) { | |
this.channel = channel; | |
channel.addCommandServer(this, new CommandServer()); | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see org.eclipse.tm.tcf.protocol.IService#getName() | |
*/ | |
public String getName() { | |
return IUnitTestDriver.NAME; | |
} | |
} |