mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-05 07:15:39 +02:00
[294351] Fix leaking service tracker
This commit is contained in:
parent
ff4609c895
commit
7e5c056111
1 changed files with 131 additions and 127 deletions
|
@ -1,127 +1,131 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
* This component and the accompanying materials are made available
|
* This component and the accompanying materials are made available
|
||||||
* under the terms of the License "Eclipse Public License v1.0"
|
* under the terms of the License "Eclipse Public License v1.0"
|
||||||
* which accompanies this distribution, and is available
|
* which accompanies this distribution, and is available
|
||||||
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
||||||
*
|
*
|
||||||
* Initial Contributors:
|
* Initial Contributors:
|
||||||
* Nokia Corporation - initial contribution.
|
* Nokia Corporation - initial contribution.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.eclipse.cdt.dsf.debug.ui;
|
package org.eclipse.cdt.dsf.debug.ui;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.ui.editors.AbstractDebugTextHover;
|
import org.eclipse.cdt.debug.ui.editors.AbstractDebugTextHover;
|
||||||
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
|
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
|
||||||
import org.eclipse.cdt.dsf.concurrent.Query;
|
import org.eclipse.cdt.dsf.concurrent.Query;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IExpressions;
|
import org.eclipse.cdt.dsf.debug.service.IExpressions;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IFormattedValues;
|
import org.eclipse.cdt.dsf.debug.service.IFormattedValues;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext;
|
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMContext;
|
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMContext;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMData;
|
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMData;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IStack.IFrameDMContext;
|
import org.eclipse.cdt.dsf.debug.service.IStack.IFrameDMContext;
|
||||||
import org.eclipse.cdt.dsf.internal.ui.DsfUIPlugin;
|
import org.eclipse.cdt.dsf.internal.ui.DsfUIPlugin;
|
||||||
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
|
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
|
||||||
import org.eclipse.cdt.dsf.service.DsfSession;
|
import org.eclipse.cdt.dsf.service.DsfSession;
|
||||||
import org.eclipse.core.runtime.IAdaptable;
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
import org.eclipse.debug.core.model.IDebugModelProvider;
|
import org.eclipse.debug.core.model.IDebugModelProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of AbstractDebugTextHover using DSF services
|
* An implementation of AbstractDebugTextHover using DSF services.
|
||||||
*
|
*
|
||||||
* @since 2.1
|
* @since 2.1
|
||||||
*/
|
*/
|
||||||
abstract public class AbstractDsfDebugTextHover extends AbstractDebugTextHover {
|
abstract public class AbstractDsfDebugTextHover extends AbstractDebugTextHover {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the debug model ID of that this debug text hover is to be used for.
|
* Returns the debug model ID of that this debug text hover is to be used for.
|
||||||
*/
|
*/
|
||||||
abstract protected String getModelId();
|
abstract protected String getModelId();
|
||||||
|
|
||||||
private static class GetExpressionValueQuery extends Query<FormattedValueDMData> {
|
private static class GetExpressionValueQuery extends Query<FormattedValueDMData> {
|
||||||
private final IFrameDMContext frame;
|
private final IFrameDMContext frame;
|
||||||
private final String expression;
|
private final String expression;
|
||||||
private DsfServicesTracker dsfServicesTracker;
|
private DsfServicesTracker dsfServicesTracker;
|
||||||
|
|
||||||
public GetExpressionValueQuery(IFrameDMContext frame, String expression, DsfServicesTracker dsfServicesTracker) {
|
public GetExpressionValueQuery(IFrameDMContext frame, String expression, DsfServicesTracker dsfServicesTracker) {
|
||||||
this.frame = frame;
|
this.frame = frame;
|
||||||
this.expression = expression;
|
this.expression = expression;
|
||||||
this.dsfServicesTracker = dsfServicesTracker;
|
this.dsfServicesTracker = dsfServicesTracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute(final DataRequestMonitor<FormattedValueDMData> rm) {
|
protected void execute(final DataRequestMonitor<FormattedValueDMData> rm) {
|
||||||
DsfSession session = DsfSession.getSession(frame.getSessionId());
|
DsfSession session = DsfSession.getSession(frame.getSessionId());
|
||||||
IExpressions expressions = dsfServicesTracker.getService(IExpressions.class);
|
IExpressions expressions = dsfServicesTracker.getService(IExpressions.class);
|
||||||
IExpressionDMContext expressionDMC = expressions.createExpression(frame, expression);
|
IExpressionDMContext expressionDMC = expressions.createExpression(frame, expression);
|
||||||
FormattedValueDMContext formattedValueContext = expressions.getFormattedValueContext(expressionDMC, IFormattedValues.NATURAL_FORMAT);
|
FormattedValueDMContext formattedValueContext = expressions.getFormattedValueContext(expressionDMC, IFormattedValues.NATURAL_FORMAT);
|
||||||
expressions.getFormattedExpressionValue(formattedValueContext,
|
expressions.getFormattedExpressionValue(formattedValueContext,
|
||||||
new DataRequestMonitor<FormattedValueDMData>(session.getExecutor(), rm) {
|
new DataRequestMonitor<FormattedValueDMData>(session.getExecutor(), rm) {
|
||||||
@Override
|
@Override
|
||||||
protected void handleSuccess() {
|
protected void handleSuccess() {
|
||||||
rm.setData(getData());
|
rm.setData(getData());
|
||||||
rm.done();
|
rm.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleFailure() {
|
protected void handleFailure() {
|
||||||
rm.done();
|
rm.done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IFrameDMContext getFrame() {
|
protected IFrameDMContext getFrame() {
|
||||||
IAdaptable adaptable = getSelectionAdaptable();
|
IAdaptable adaptable = getSelectionAdaptable();
|
||||||
if (adaptable != null) {
|
if (adaptable != null) {
|
||||||
return (IFrameDMContext) adaptable.getAdapter(IFrameDMContext.class);
|
return (IFrameDMContext) adaptable.getAdapter(IFrameDMContext.class);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean canEvaluate() {
|
protected boolean canEvaluate() {
|
||||||
if (getFrame() == null) {
|
if (getFrame() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
IAdaptable adaptable = getSelectionAdaptable();
|
IAdaptable adaptable = getSelectionAdaptable();
|
||||||
if (adaptable != null) {
|
if (adaptable != null) {
|
||||||
IDebugModelProvider modelProvider = (IDebugModelProvider)adaptable.getAdapter(IDebugModelProvider.class);
|
IDebugModelProvider modelProvider = (IDebugModelProvider)adaptable.getAdapter(IDebugModelProvider.class);
|
||||||
if (modelProvider != null) {
|
if (modelProvider != null) {
|
||||||
String[] models = modelProvider.getModelIdentifiers();
|
String[] models = modelProvider.getModelIdentifiers();
|
||||||
String myModel = getModelId();
|
String myModel = getModelId();
|
||||||
for (int i = 0; i < models.length; i++) {
|
for (int i = 0; i < models.length; i++) {
|
||||||
if (models[i].equals(myModel)) {
|
if (models[i].equals(myModel)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String evaluateExpression(String expression) {
|
protected String evaluateExpression(String expression) {
|
||||||
IFrameDMContext frame = getFrame();
|
IFrameDMContext frame = getFrame();
|
||||||
String sessionId = frame.getSessionId();
|
String sessionId = frame.getSessionId();
|
||||||
DsfServicesTracker dsfServicesTracker = new DsfServicesTracker(DsfUIPlugin.getBundleContext(), sessionId);
|
DsfServicesTracker dsfServicesTracker = new DsfServicesTracker(DsfUIPlugin.getBundleContext(), sessionId);
|
||||||
GetExpressionValueQuery query = new GetExpressionValueQuery(frame, expression, dsfServicesTracker);
|
try {
|
||||||
DsfSession session = DsfSession.getSession(sessionId);
|
GetExpressionValueQuery query = new GetExpressionValueQuery(frame, expression, dsfServicesTracker);
|
||||||
session.getExecutor().execute(query);
|
DsfSession session = DsfSession.getSession(sessionId);
|
||||||
try {
|
session.getExecutor().execute(query);
|
||||||
FormattedValueDMData data = query.get();
|
try {
|
||||||
if (data != null)
|
FormattedValueDMData data = query.get();
|
||||||
return data.getFormattedValue();
|
if (data != null)
|
||||||
} catch (Exception e) {
|
return data.getFormattedValue();
|
||||||
}
|
} catch (Exception e) {
|
||||||
return null;
|
}
|
||||||
}
|
} finally {
|
||||||
|
dsfServicesTracker.dispose();
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue