1
0
Fork 0
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:
Pawel Piech 2006-10-06 20:35:08 +00:00
parent 60ce7f8c10
commit 4cde8d219c
5 changed files with 42 additions and 65 deletions

View file

@ -48,16 +48,16 @@ abstract public class Done extends DsfRunnable {
/**
* Convenience method which checks for error in done, and propagates it
* to caller's client done.
* to caller's client done.
* @return Returns true if there was an error that was propagated and
* 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) {
return true;
}
if (!getStatus().isOK()) {
clientDone.setErrorStatus(DsfPlugin.PLUGIN_ID, code, message, getStatus());
clientDone.setErrorStatus(DsfPlugin.PLUGIN_ID, getStatus().getCode(), message, getStatus());
executor.execute(clientDone);
return true;
}

View file

@ -16,6 +16,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
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
@ -83,7 +84,7 @@ abstract public class DsfQuery<V> {
wait();
}
} 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);
fValid = true;
}
@ -153,7 +154,7 @@ abstract public class DsfQuery<V> {
public synchronized void doneException(Throwable t) {
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));
}
}

View file

@ -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();
}

View file

@ -261,9 +261,10 @@ public class DsfSession
* @param serviceProperties properties of the service requesting the event to be dispatched
*/
public void dispatchEvent(final Object event, final Dictionary serviceProperties) {
getExecutor().submit(new DsfRunnable() { public void run() {
doDispatchEvent(event, serviceProperties);
}});
getExecutor().submit(new DsfRunnable() {
public void run() { doDispatchEvent(event, serviceProperties);}
public String toString() { return "Event: " + event + ", from service " + serviceProperties; }
});
}
/**

View file

@ -40,7 +40,38 @@ public interface IDsfService {
* 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.
*/
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.