mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Added standard error codes and refactored existing implementation to use them (bug# 159043).
This commit is contained in:
parent
60ce7f8c10
commit
4cde8d219c
5 changed files with 42 additions and 65 deletions
|
@ -52,12 +52,12 @@ abstract public class Done extends DsfRunnable {
|
||||||
* @return Returns true if there was an error that was propagated and
|
* @return Returns true if there was an error that was propagated and
|
||||||
* the caller can stop processing result.
|
* the caller can stop processing result.
|
||||||
*/
|
*/
|
||||||
protected boolean propagateErrorToClient(DsfExecutor executor, Done clientDone, int code, String message) {
|
protected boolean propagateErrorToClient(DsfExecutor executor, Done clientDone, String message) {
|
||||||
if (clientDone.getStatus().getSeverity() == IStatus.CANCEL) {
|
if (clientDone.getStatus().getSeverity() == IStatus.CANCEL) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!getStatus().isOK()) {
|
if (!getStatus().isOK()) {
|
||||||
clientDone.setErrorStatus(DsfPlugin.PLUGIN_ID, code, message, getStatus());
|
clientDone.setErrorStatus(DsfPlugin.PLUGIN_ID, getStatus().getCode(), message, getStatus());
|
||||||
executor.execute(clientDone);
|
executor.execute(clientDone);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.dd.dsf.DsfPlugin;
|
import org.eclipse.dd.dsf.DsfPlugin;
|
||||||
|
import org.eclipse.dd.dsf.service.IDsfService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A convenience class that allows a client to retrieve data from services
|
* A convenience class that allows a client to retrieve data from services
|
||||||
|
@ -83,7 +84,7 @@ abstract public class DsfQuery<V> {
|
||||||
wait();
|
wait();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
fStatus = new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, -1,
|
fStatus = new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, IDsfService.INTERNAL_ERROR,
|
||||||
"Interrupted exception while waiting for result.", e);
|
"Interrupted exception while waiting for result.", e);
|
||||||
fValid = true;
|
fValid = true;
|
||||||
}
|
}
|
||||||
|
@ -153,7 +154,7 @@ abstract public class DsfQuery<V> {
|
||||||
|
|
||||||
public synchronized void doneException(Throwable t) {
|
public synchronized void doneException(Throwable t) {
|
||||||
if (fValid) return;
|
if (fValid) return;
|
||||||
doneError(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, -1,
|
doneError(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, IDsfService.INTERNAL_ERROR,
|
||||||
"Exception while computing result.", t));
|
"Exception while computing result.", t));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2006 Wind River Systems 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:
|
|
||||||
* Wind River Systems - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.dd.dsf.concurrent;
|
|
||||||
|
|
||||||
import org.eclipse.core.runtime.IStatus;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience extension to GetDataDone, which handles posting of the client's
|
|
||||||
* <code>Done</code> upon the completion of this <code>GetDataDone</code>.
|
|
||||||
* @param <V> Class type of data.
|
|
||||||
* @deprecated This class has been replaced with the
|
|
||||||
* {@link Done#propagateErrorToClient(DsfExecutor, Done, int, String)}
|
|
||||||
* method.
|
|
||||||
*/
|
|
||||||
public abstract class GetDataDoneWithClientDone<V> extends GetDataDone<V> {
|
|
||||||
private DsfExecutor fExecutor;
|
|
||||||
private Done fClientDone;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor requires the Done to be posted as well as the executor to
|
|
||||||
* post it with.
|
|
||||||
*/
|
|
||||||
public GetDataDoneWithClientDone(DsfExecutor executor, Done clientDone) {
|
|
||||||
fExecutor = executor;
|
|
||||||
fClientDone = clientDone;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The run method checks the client done for cancellation, and this done
|
|
||||||
* for errors. It calls doRun() for the sub-class execution, and posts
|
|
||||||
* the client done when finished.
|
|
||||||
*/
|
|
||||||
public final void run() {
|
|
||||||
if (fClientDone.getStatus().getSeverity() == IStatus.CANCEL) return;
|
|
||||||
if (!getStatus().isOK()) {
|
|
||||||
fClientDone.setStatus(getStatus());
|
|
||||||
} else {
|
|
||||||
doRun();
|
|
||||||
}
|
|
||||||
fExecutor.execute(fClientDone);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to perform the actual work. It should not post the client done
|
|
||||||
* because it will be posted by this class in run().
|
|
||||||
*/
|
|
||||||
protected abstract void doRun();
|
|
||||||
}
|
|
|
@ -261,9 +261,10 @@ public class DsfSession
|
||||||
* @param serviceProperties properties of the service requesting the event to be dispatched
|
* @param serviceProperties properties of the service requesting the event to be dispatched
|
||||||
*/
|
*/
|
||||||
public void dispatchEvent(final Object event, final Dictionary serviceProperties) {
|
public void dispatchEvent(final Object event, final Dictionary serviceProperties) {
|
||||||
getExecutor().submit(new DsfRunnable() { public void run() {
|
getExecutor().submit(new DsfRunnable() {
|
||||||
doDispatchEvent(event, serviceProperties);
|
public void run() { doDispatchEvent(event, serviceProperties);}
|
||||||
}});
|
public String toString() { return "Event: " + event + ", from service " + serviceProperties; }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -40,7 +40,38 @@ public interface IDsfService {
|
||||||
* Property name for the session-id of this service. This property should be set by
|
* Property name for the session-id of this service. This property should be set by
|
||||||
* all DSF services when they are registered with OSGI service framework.
|
* all DSF services when they are registered with OSGI service framework.
|
||||||
*/
|
*/
|
||||||
static String PROP_SESSION_ID = "org.eclipse.dd.dsf.service.IService.session_id";
|
final static String PROP_SESSION_ID = "org.eclipse.dd.dsf.service.IService.session_id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error code indicating that the service is in a state which does not allow the
|
||||||
|
* request to be processed. For example if the client requested target information
|
||||||
|
* after target was disconnected.
|
||||||
|
*/
|
||||||
|
final static int INVALID_STATE = 10001;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error code indicating that client supplied an invalid handle to the service.
|
||||||
|
* A handle could become invalid after an object it represents is removed from
|
||||||
|
* the system.
|
||||||
|
*/
|
||||||
|
final static int INVALID_HANDLE = 10002;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error code indicating that the client request is not supported/implemented.
|
||||||
|
*/
|
||||||
|
final static int NOT_SUPPORTED = 10003;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error code indicating that the request to a sub-service or an external process
|
||||||
|
* failed.
|
||||||
|
*/
|
||||||
|
final static int REQUEST_FAILED = 10004;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error code indicating an unexpected condition in the service, i.e. programming error.
|
||||||
|
*/
|
||||||
|
final static int INTERNAL_ERROR = 10005;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the executor that should be used to call methods of this service.
|
* Returns the executor that should be used to call methods of this service.
|
||||||
|
|
Loading…
Add table
Reference in a new issue