cdt/cdt_6_0_x/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/service/BreakpointsMediator.java
author l12wang
Wed, 11 Nov 2009 14:48:30 -0600
changeset 112 6b1088abccf8
parent 104 b23e845b9366
child 117 09f3d307f081
permissions -rw-r--r--
Reworked BreakpointsMediator. See Eclipse bug 292468.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     1
/*******************************************************************************
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     2
 * Copyright (c) 2007, 2008 Wind River and others.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     3
 * All rights reserved. This program and the accompanying materials
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     4
 * are made available under the terms of the Eclipse Public License v1.0
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     5
 * which accompanies this distribution, and is available at
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     6
 * http://www.eclipse.org/legal/epl-v10.html
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     7
 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     8
 * Contributors:
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     9
 *     Wind River - Initial API and implementation
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    10
 *     Ericsson   - Low-level breakpoints integration  
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    11
 *******************************************************************************/
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    12
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    13
package org.eclipse.cdt.dsf.debug.service;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    14
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    15
import java.util.ArrayList;
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    16
import java.util.Collections;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    17
import java.util.HashMap;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    18
import java.util.HashSet;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    19
import java.util.Hashtable;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    20
import java.util.LinkedList;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    21
import java.util.List;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    22
import java.util.Map;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    23
import java.util.Set;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    24
import java.util.concurrent.RejectedExecutionException;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    25
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    26
import org.eclipse.cdt.dsf.concurrent.CountingRequestMonitor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    27
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    28
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    29
import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    30
import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    31
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    32
import org.eclipse.cdt.dsf.concurrent.ThreadSafe;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    33
import org.eclipse.cdt.dsf.datamodel.IDMContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    34
import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointDMContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    35
import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    36
import org.eclipse.cdt.dsf.internal.DsfPlugin;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    37
import org.eclipse.cdt.dsf.service.AbstractDsfService;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    38
import org.eclipse.cdt.dsf.service.DsfSession;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    39
import org.eclipse.core.resources.IMarkerDelta;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    40
import org.eclipse.core.runtime.CoreException;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    41
import org.eclipse.core.runtime.IProgressMonitor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    42
import org.eclipse.core.runtime.IStatus;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    43
import org.eclipse.core.runtime.Status;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    44
import org.eclipse.core.runtime.jobs.Job;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    45
import org.eclipse.debug.core.DebugPlugin;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    46
import org.eclipse.debug.core.IBreakpointManager;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    47
import org.eclipse.debug.core.IBreakpointManagerListener;
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    48
import org.eclipse.debug.core.IBreakpointsListener;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    49
import org.eclipse.debug.core.model.IBreakpoint;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    50
import org.osgi.framework.BundleContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    51
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    52
/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    53
 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    54
 */
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    55
public class BreakpointsMediator extends AbstractDsfService implements IBreakpointManagerListener, IBreakpointsListener
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    56
{
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    57
	public enum BreakpointEventType {ADDED, REMOVED, MODIFIED}; 	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    58
	
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    59
    /**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    60
     * The attribute translator that this service will use to map the platform
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    61
     * breakpoint attributes to the corresponding target attributes, and vice
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    62
     * versa.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    63
     */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    64
    private IBreakpointAttributeTranslator fAttributeTranslator;
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    65
    
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    66
    /**
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    67
     * If the attribute translator implements the {@link IBreakpointAttributeTranslatorExtension},
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    68
     * this field will be valid, otherwise it is null.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    69
     */
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    70
    private IBreakpointAttributeTranslatorExtension fAttributeTranslator2;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    71
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    72
    /**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    73
     * DSF Debug service for creating breakpoints.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    74
     */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    75
    IBreakpoints fBreakpoints;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    76
    
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    77
    /**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    78
     * Platform breakpoint manager
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    79
     */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    80
    IBreakpointManager fBreakpointManager;
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    81
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    82
    /**
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    83
     * Object describing the information about a single target breakpoint  
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    84
     * corresponding to specific platform breakpoint and breakpoint target 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    85
     * context.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    86
     * 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    87
     * @since 2.1
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    88
     */
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    89
    public interface ITargetBreakpointInfo {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    90
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    91
    	/**
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    92
    	 * Returns the breakpoint attributes as returned by the attribute translator.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    93
    	 */
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    94
    	public Map<String, Object> getAttributes();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    95
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    96
    	/**
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    97
    	 * Returns the target breakpoint context.  May be <code>null</code> if the 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    98
    	 * breakpoint failed to install on target. 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
    99
    	 */
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   100
    	public IBreakpointDMContext getTargetBreakpoint();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   101
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   102
    	/**
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   103
    	 * Returns the status result of the last breakpoint operation (install/remove). 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   104
    	 */
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   105
    	public IStatus getStatus();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   106
    }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   107
    
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   108
    private static class TargetBP implements ITargetBreakpointInfo {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   109
    	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   110
    	private Map<String, Object> fAttributes;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   111
    	private Map<String, Object> fAttributesDelta; // not really useful ?
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   112
    	private IBreakpointDMContext fTargetBPContext;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   113
    	private IStatus fStatus;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   114
    	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   115
    	public TargetBP(Map<String, Object> attrs) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   116
    		fAttributes = attrs;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   117
    	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   118
    	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   119
    	public Map<String, Object> getAttributes() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   120
			return fAttributes;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   121
		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   122
    	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   123
    	public IBreakpointDMContext getTargetBreakpoint() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   124
			return fTargetBPContext;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   125
		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   126
    	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   127
    	public IStatus getStatus() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   128
			return fStatus;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   129
		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   130
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   131
		public void setTargetBreakpoint(IBreakpointDMContext fTargetBPContext) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   132
			this.fTargetBPContext = fTargetBPContext;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   133
		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   134
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   135
		public void setStatus(IStatus status) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   136
			this.fStatus = status;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   137
		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   138
    }
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   139
    
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   140
    ///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   141
    // Breakpoints tracking
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   142
    ///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   143
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   144
    /**
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   145
     * Holds the set of platform breakpoints with their breakpoint information 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   146
     * structures, per context (i.e. each platform breakpoint is
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   147
     * replicated for each execution context).
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   148
     * - Context entry added/removed on start/stopTrackingBreakpoints()
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   149
     * - Augmented on breakpointAdded()
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   150
     * - Modified on breakpointChanged()
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   151
     * - Diminished on breakpointRemoved()
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   152
     */
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   153
	private Map<IBreakpointsTargetDMContext, Map<IBreakpoint, List<TargetBP>>> fPlatformBPs = 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   154
		new HashMap<IBreakpointsTargetDMContext, Map<IBreakpoint, List<TargetBP>>>();
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   155
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   156
    /**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   157
     * Due to the very asynchronous nature of DSF, a new breakpoint request can
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   158
     * pop up at any time before an ongoing one is completed. The following set
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   159
     * is used to store requests until the ongoing operation completes.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   160
     */
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   161
	private Set<IBreakpoint> fRunningEvents    = new HashSet<IBreakpoint>();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   162
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   163
	private static class PendingEventInfo {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   164
		PendingEventInfo(BreakpointEventType eventType, IBreakpointsTargetDMContext bpsTargetDmc, RequestMonitor rm) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   165
			fEventType = eventType;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   166
			fBPsTargetDmc = bpsTargetDmc;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   167
			fRequestMonitor = rm;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   168
		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   169
		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   170
		RequestMonitor fRequestMonitor;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   171
		BreakpointEventType fEventType;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   172
		IBreakpointsTargetDMContext fBPsTargetDmc;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   173
	}
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   174
	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   175
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   176
	 * @see fPendingRequests
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   177
	 */
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   178
	private Map<IBreakpoint, LinkedList<PendingEventInfo>> fPendingEvents = 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   179
		Collections.synchronizedMap(new HashMap<IBreakpoint, LinkedList<PendingEventInfo>>());
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   180
	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   181
    ///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   182
    // AbstractDsfService    
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   183
    ///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   184
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   185
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   186
	 * The service constructor
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   187
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   188
	 * @param session
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   189
	 * @param debugModelId
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   190
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   191
	public BreakpointsMediator(DsfSession session, IBreakpointAttributeTranslator attributeTranslator) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   192
        super(session);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   193
        fAttributeTranslator = attributeTranslator;
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   194
        
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   195
        fAttributeTranslator2 = null;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   196
        if (attributeTranslator instanceof IBreakpointAttributeTranslatorExtension)
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   197
        	fAttributeTranslator2 = (IBreakpointAttributeTranslatorExtension)attributeTranslator;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   198
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   199
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   200
    @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   201
    public void initialize(final RequestMonitor rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   202
        // - Collect references for the services we interact with
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   203
        // - Register to interesting events
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   204
        // - Obtain the list of platform breakpoints   
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   205
        // - Register the service for interested parties
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   206
        super.initialize(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   207
            new RequestMonitor(getExecutor(), rm) { 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   208
                @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   209
                protected void handleSuccess() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   210
                    doInitialize(rm);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   211
                }});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   212
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   213
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   214
    /**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   215
     * Asynchronous service initialization 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   216
     * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   217
     * @param requestMonitor
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   218
     */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   219
    private void doInitialize(RequestMonitor rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   220
    	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   221
    	// Get the services references
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   222
        fBreakpoints  = getServicesTracker().getService(IBreakpoints.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   223
        fBreakpointManager = DebugPlugin.getDefault().getBreakpointManager();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   224
        fAttributeTranslator.initialize(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   225
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   226
        // Register to the useful events
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   227
        fBreakpointManager.addBreakpointListener(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   228
        fBreakpointManager.addBreakpointManagerListener( this );
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   229
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   230
        // Register this service
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   231
        register(new String[] { BreakpointsMediator.class.getName() },
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   232
				 new Hashtable<String, String>());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   233
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   234
        rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   235
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   236
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   237
    @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   238
    public void shutdown(final RequestMonitor rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   239
        // - Un-register the service
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   240
        // - Stop listening to events
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   241
        // - Remove the breakpoints installed by this service
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   242
        // 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   243
        //  Since we are shutting down, there is no overwhelming need
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   244
        //  to keep the maps coherent...
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   245
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   246
        // Stop accepting requests and events
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   247
    	unregister();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   248
        fBreakpointManager.removeBreakpointListener(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   249
        fBreakpointManager.removeBreakpointManagerListener( this );
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   250
        fAttributeTranslator.dispose();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   251
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   252
        // Cleanup the breakpoints that are still installed by the service.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   253
        // Use a counting monitor which will call mom to complete the shutdown
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   254
        // after the breakpoints are un-installed (successfully or not).
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   255
        CountingRequestMonitor countingRm = new CountingRequestMonitor(getExecutor(), rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   256
            @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   257
            protected void handleCompleted() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   258
                BreakpointsMediator.super.shutdown(rm);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   259
            }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   260
        };
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   261
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   262
        // We have to make a copy of the fPlatformBPs keys because uninstallBreakpoints()
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   263
        // modifies the map as it walks through it.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   264
        List<IBreakpointsTargetDMContext> platformBPKeysCopy = new ArrayList<IBreakpointsTargetDMContext>(fPlatformBPs.size());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   265
        platformBPKeysCopy.addAll(0, fPlatformBPs.keySet());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   266
        for (IBreakpointsTargetDMContext dmc : platformBPKeysCopy) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   267
            stopTrackingBreakpoints(dmc, countingRm);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   268
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   269
        countingRm.setDoneCount(platformBPKeysCopy.size());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   270
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   271
    
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   272
	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   273
    protected BundleContext getBundleContext() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   274
        return DsfPlugin.getBundleContext();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   275
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   276
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   277
    ///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   278
    // IBreakpointsManager
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   279
    ///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   280
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   281
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   282
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   283
     * Install and begin tracking breakpoints for given context.  The service 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   284
     * will keep installing new breakpoints that appear in the IDE for this 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   285
     * context until {@link #uninstallBreakpoints(IDMContext)} is called for that
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   286
     * context.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   287
     * @param dmc Context to start tracking breakpoints for.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   288
     * @param rm Completion callback.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   289
     */
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   290
    public void startTrackingBreakpoints(final IBreakpointsTargetDMContext dmc, final RequestMonitor rm) {
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   291
        // - Augment the maps with the new execution context
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   292
        // - Install the platform breakpoints on the selected target
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   293
            
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   294
        // Make sure a mapping for this execution context does not already exist
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   295
		Map<IBreakpoint, List<TargetBP>> platformBPs = fPlatformBPs.get(dmc);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   296
		if (platformBPs != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   297
            rm.setStatus(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, INTERNAL_ERROR, "Context already initialized", null)); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   298
            rm.done();            
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   299
            return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   300
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   301
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   302
        // Create entries in the breakpoint tables for the new context. These entries should only
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   303
        // be removed when this service stops tracking breakpoints for the given context.
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   304
        fPlatformBPs.put(dmc, new HashMap<IBreakpoint, List<TargetBP>>());
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   305
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   306
        // Install the platform breakpoints (stored in fPlatformBPs) on the target.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   307
		// We need to use a background thread for this operation because we are 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   308
		// accessing the resources system to retrieve the breakpoint attributes.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   309
		// Accessing the resources system potentially requires using global locks.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   310
		// Also we will be calling IBreakpointAttributeTranslator which is prohibited
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   311
		// from being called on the session executor thread.
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   312
		new Job("Install initial breakpoint list.") { //$NON-NLS-1$
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   313
            { setSystem(true); }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   314
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   315
			// Get the stored breakpoints from the platform BreakpointManager
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   316
			// and install them on the target
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   317
        	@Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   318
            protected IStatus run(IProgressMonitor monitor) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   319
        		doBreakpointsAdded(DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(), dmc, rm);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   320
                return Status.OK_STATUS;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   321
            }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   322
        }.schedule();    
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   323
    }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   324
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   325
    public void stopTrackingBreakpoints(final IBreakpointsTargetDMContext dmc, final RequestMonitor rm) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   326
        // - Remove the target breakpoints for the given execution context
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   327
        // - Update the maps
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   328
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   329
    	// Remove the breakpoints for given DMC from the internal maps.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   330
        Map<IBreakpoint, List<TargetBP>> platformBPs = fPlatformBPs.get(dmc);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   331
        if (platformBPs == null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   332
            rm.setStatus(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, INTERNAL_ERROR, "Breakpoints not installed for given context", null)); //$NON-NLS-1$
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   333
            rm.done();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   334
            return;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   335
        }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   336
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   337
		new Job("Uninstall target breakpoints list.") { //$NON-NLS-1$
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   338
            { setSystem(true); }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   339
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   340
			// Get the stored breakpoints from the platform BreakpointManager
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   341
			// and install them on the target
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   342
        	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   343
            protected IStatus run(IProgressMonitor monitor) {
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   344
        		doBreakpointsRemoved(DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(), dmc, rm);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   345
                return Status.OK_STATUS;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   346
            }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   347
        }.schedule();    
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   348
    }
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   349
    
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   350
    /**
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   351
     * Find target breakpoints installed in the given context that are resolved 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   352
     * from the given platform breakpoint.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   353
     *  
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   354
     * @param dmc - context
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   355
     * @param platformBp - platform breakpoint
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   356
     * @return array of target breakpoints. 
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   357
     */
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   358
    public ITargetBreakpointInfo[] getTargetBreakpoints(IBreakpointsTargetDMContext dmc, IBreakpoint platformBp) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   359
        Map<IBreakpoint, List<TargetBP>> platformBPs = fPlatformBPs.get(dmc);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   360
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   361
        if (platformBPs != null)
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   362
        {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   363
        	List<TargetBP> bpInfo = platformBPs.get(platformBp);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   364
            if (bpInfo != null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   365
            	return bpInfo.toArray(new ITargetBreakpointInfo[bpInfo.size()]);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   366
            }
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   367
        }
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   368
        return null;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   369
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   370
    
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   371
    /**
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   372
     * Find the platform breakpoint that's mapped to the given target breakpoint.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   373
     * 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   374
     * @param dmc - context of the target breakpoint, can be null.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   375
     * @param bp - target breakpoint
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   376
     * @return platform breakpoint. null if not found. 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   377
     */
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   378
    public IBreakpoint getPlatformBreakpoint(IBreakpointsTargetDMContext dmc, IBreakpointDMContext bp) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   379
    	for (IBreakpointsTargetDMContext bpContext : fPlatformBPs.keySet()) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   380
    		if (dmc != null && !dmc.equals(bpContext))
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   381
    			continue;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   382
    		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   383
	        Map<IBreakpoint, List<TargetBP>> platformBPs = fPlatformBPs.get(bpContext);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   384
	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   385
	        if (platformBPs != null && platformBPs.size() > 0)
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   386
	        {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   387
	            for(Map.Entry<IBreakpoint, List<TargetBP>> e: platformBPs.entrySet())
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   388
	            {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   389
	                // Stop at the first occurrence
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   390
	            	for (TargetBP tbp : e.getValue())
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   391
	            		if(tbp.getTargetBreakpoint().equals(bp))
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   392
	            			return e.getKey();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   393
	            }    
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   394
	        }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   395
    	}
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   396
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   397
    	return null;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   398
    }
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   399
    
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   400
    ///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   401
    // Back-end interface functions
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   402
    ///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   403
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   404
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   405
	 * Install a new platform breakpoint on the back-end. A platform breakpoint
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   406
	 * can resolve into multiple back-end breakpoints, e.g. when threads are taken
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   407
	 * into account.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   408
	 *  
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   409
	 * @param dmc
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   410
	 * @param breakpoint
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   411
	 * @param attrsList - list of attribute map, each mapping to a potential target BP.
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   412
	 * @param rm
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   413
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   414
	private void installBreakpoint(IBreakpointsTargetDMContext dmc, final IBreakpoint breakpoint,
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   415
			final List<Map<String, Object>> attrsList, final DataRequestMonitor<List<TargetBP>> rm)
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   416
	{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   417
    	// Retrieve the set of breakpoints for this context
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   418
        final Map<IBreakpoint, List<TargetBP>> platformBPs = fPlatformBPs.get(dmc);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   419
        assert platformBPs != null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   420
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   421
        // Ensure the breakpoint is not already installed
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   422
        assert !platformBPs.containsKey(breakpoint);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   423
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   424
        final ArrayList<TargetBP> targetBPsAttempted = new ArrayList<TargetBP>(attrsList.size());
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   425
        for (int i = 0; i < attrsList.size(); i++) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   426
        	targetBPsAttempted.add(new TargetBP(attrsList.get(i)));
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   427
        }
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   428
        
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   429
        final ArrayList<TargetBP> targetBPsInstalled = new ArrayList<TargetBP>(attrsList.size());
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   430
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   431
        // Update the breakpoint status when all back-end breakpoints have been installed
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   432
    	final CountingRequestMonitor installRM = new CountingRequestMonitor(getExecutor(), rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   433
			@Override
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   434
			protected void handleCompleted() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   435
				// Store successful targetBPs with the platform breakpoint
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   436
				if (targetBPsInstalled.size() > 0)
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   437
					platformBPs.put(breakpoint, targetBPsInstalled);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   438
				
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   439
				// Store all targetBPs, success or failure, in the rm.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   440
				rm.setData(targetBPsAttempted);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   441
		        rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   442
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   443
		};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   444
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   445
        // A back-end breakpoint needs to be installed for each specified attributes map.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   446
		installRM.setDoneCount(attrsList.size());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   447
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   448
		// Install the back-end breakpoint(s)
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   449
		for (int _i = 0; _i < attrsList.size(); _i++) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   450
			final int i = _i;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   451
            fBreakpoints.insertBreakpoint(
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   452
                dmc, attrsList.get(i), 
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   453
				new DataRequestMonitor<IBreakpointDMContext>(getExecutor(), installRM) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   454
				@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   455
                protected void handleCompleted() {
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   456
					TargetBP targetBP = targetBPsAttempted.get(i);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   457
                    if (isSuccess()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   458
						// Add the breakpoint back-end mapping
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   459
                    	targetBP.setTargetBreakpoint(getData());
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   460
                    	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   461
                    	targetBPsInstalled.add(targetBP);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   462
					} 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   463
                    targetBP.setStatus(getStatus());
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   464
                    
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   465
					installRM.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   466
                }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   467
            });
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   468
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   469
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   470
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   471
    /**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   472
     * Un-install an individual breakpoint on the back-end. For one platform
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   473
     * breakpoint, there could be multiple corresponding back-end breakpoints.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   474
     * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   475
     * @param dmc
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   476
     * @param breakpoint
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   477
     * @param drm
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   478
     */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   479
    private void uninstallBreakpoint(final IBreakpointsTargetDMContext dmc, final IBreakpoint breakpoint, 
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   480
        final DataRequestMonitor<List<TargetBP>> drm)
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   481
    {
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   482
		// Remove the back-end breakpoints
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   483
		final Map<IBreakpoint, List<TargetBP>> platformBPs = fPlatformBPs.get(dmc);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   484
        if (platformBPs == null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   485
            drm.setStatus(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid breakpoint", null)); //$NON-NLS-1$
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   486
            drm.done();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   487
            return;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   488
        }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   489
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   490
        final List<TargetBP> bpList = platformBPs.get(breakpoint);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   491
        assert bpList != null;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   492
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   493
        // Only try to remove those targetBPs that are successfully installed.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   494
        
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   495
  		// Remove completion monitor
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   496
    	final CountingRequestMonitor countingRm = new CountingRequestMonitor(getExecutor(), drm) {
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   497
			@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   498
			protected void handleCompleted() {
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   499
				platformBPs.remove(breakpoint);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   500
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   501
		        // Complete the request monitor.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   502
		        drm.setData(bpList);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   503
		        drm.done();
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   504
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   505
		};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   506
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   507
        int count = 0;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   508
        for (int i = 0; i < bpList.size(); i++) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   509
        	final TargetBP bp = bpList.get(i);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   510
        	if (bp.getTargetBreakpoint() != null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   511
        		fBreakpoints.removeBreakpoint(
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   512
        				bp.getTargetBreakpoint(), 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   513
        				new RequestMonitor(getExecutor(), countingRm) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   514
        					@Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   515
        					protected void handleCompleted() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   516
        				        bp.setStatus(getStatus());
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   517
        				        bp.fAttributesDelta = bp.fAttributes;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   518
        				        if (isSuccess()) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   519
            						bp.setTargetBreakpoint(null);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   520
        				        	bp.fAttributes = null;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   521
        				        } 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   522
        				        countingRm.done();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   523
        					}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   524
        				});
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   525
        		count++;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   526
        	} else {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   527
        		bp.setStatus(Status.OK_STATUS);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   528
        	}
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   529
        }
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   530
        countingRm.setDoneCount(count);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   531
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   532
	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   533
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   534
	 * Modify an individual breakpoint
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   535
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   536
	 * @param context
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   537
	 * @param breakpoint
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   538
	 * @param attributes
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   539
	 * @param drm
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   540
	 * @throws CoreException
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   541
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   542
	private void modifyBreakpoint(final IBreakpointsTargetDMContext context, final IBreakpoint breakpoint,
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   543
			final List<Map<String, Object>> newAttrsList, final DataRequestMonitor<List<TargetBP>> drm)
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   544
	{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   545
	    // This method uses several lists to track the changed breakpoints:
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   546
	    // commonAttrsList - attributes which have not changed 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   547
	    // oldAttrsList - attributes for the breakpoint before the change
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   548
	    // newAttrsList - attributes for the breakpoint after the change
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   549
	    // oldBpContexts - target-side breakpoints from before the change
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   550
	    // newBpContexts - target-side breakpoints after the change
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   551
	    // attrDeltasList - changes in the attributes for each attribute map in 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   552
	    //     oldAttrsList and newAttrsList
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   553
	    
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   554
    	// Get the maps
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   555
        final Map<IBreakpoint, List<TargetBP>> platformBPs = fPlatformBPs.get(context);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   556
        if (platformBPs == null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   557
            drm.setStatus(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid context", null)); //$NON-NLS-1$
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   558
            drm.done();
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   559
            return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   560
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   561
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   562
        final List<TargetBP> oldBpList = platformBPs.get(breakpoint);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   563
        
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   564
        final List<TargetBP> bpList = new ArrayList<TargetBP>(newAttrsList.size());
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   565
        
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   566
        if (oldBpList == null || oldBpList.size() == 0) { // not targetBP installed
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   567
            drm.setData(bpList);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   568
        	drm.done();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   569
        	return;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   570
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   571
        
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   572
        for (int i = 0; i < newAttrsList.size(); i++) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   573
        	bpList.add(new TargetBP(newAttrsList.get(i)));
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   574
        }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   575
        
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   576
        // Create a list of attribute changes.  The length of this list will
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   577
        // always be max(oldAttrList.size(), newAttrsList.size()), padded with
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   578
        // null's if oldAttrsList was longer.
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   579
        calcBPsAttrs(oldBpList, bpList);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   580
        
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   581
        // Create the request monitor that will be called when all
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   582
        // modifying/inserting/removing is complete.
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   583
        final CountingRequestMonitor countingRM = new CountingRequestMonitor(getExecutor(), drm) {
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   584
            @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   585
            protected void handleCompleted() {
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   586
                // Save the new list of target breakpoints 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   587
            	platformBPs.put(breakpoint, bpList);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   588
                drm.setData(bpList);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   589
                drm.done();
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   590
            }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   591
        };
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   592
        
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   593
        // Set the count, if could be zero if no breakpoints have actually changed.
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   594
        int coutingRmCount = 0;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   595
        
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   596
        // Process the changed breakpoints.
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   597
        for (int _i = 0; _i < bpList.size(); _i++) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   598
        	final int i = _i;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   599
        	final TargetBP bp = bpList.get(i);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   600
            if (bp.fAttributes == null) {
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   601
                // The list of new attribute maps was shorter than the old.
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   602
                // Remove the corresponding target-side bp.  
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   603
            	// Note the target BP context may be null if the target
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   604
            	// BP failed to insert in the first place.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   605
            	if (bp.getTargetBreakpoint() != null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   606
            		fBreakpoints.removeBreakpoint(
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   607
            				bp.getTargetBreakpoint(), 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   608
            				new RequestMonitor(getExecutor(), countingRM) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   609
            					@Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   610
            					protected void handleCompleted() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   611
            						bp.fStatus = getStatus();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   612
            						countingRM.done();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   613
            					}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   614
            				});
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   615
                    coutingRmCount++;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   616
            	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   617
            } else if ( bp.getTargetBreakpoint() == null) {
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   618
                // The list of new attribute maps was longer, just insert
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   619
                // the new breakpoint
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   620
                final Map<String, Object> attrs = newAttrsList.get(i);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   621
                fBreakpoints.insertBreakpoint(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   622
                    context, attrs, 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   623
                    new DataRequestMonitor<IBreakpointDMContext>(getExecutor(), countingRM) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   624
                        @Override
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   625
                        protected void handleCompleted() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   626
                        	if (isSuccess()) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   627
                        		bp.fTargetBPContext = getData();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   628
                        	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   629
                        	bp.fStatus = getStatus();
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   630
                            countingRM.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   631
                        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   632
                    });
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   633
                coutingRmCount++;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   634
            } else if (bp.fAttributesDelta.size() == 0) { 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   635
            	// Breakpoint attributes have not changed, only copy over the old status.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   636
            	bp.fStatus = oldBpList.get(i).fStatus;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   637
            } else if ( !fAttributeTranslator.canUpdateAttributes(bp.getTargetBreakpoint(), bp.fAttributesDelta) ) {
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   638
                // The attribute translator tells us that the debugger cannot modify the 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   639
                // breakpoint to change the given attributes.  Remove the breakpoint
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   640
                // and insert a new one.
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   641
                RequestMonitor removeRm = new RequestMonitor(getExecutor(), countingRM) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   642
                    @Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   643
                    protected void handleCompleted() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   644
                    	if (isSuccess()) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   645
                    		bp.fTargetBPContext = null;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   646
	                        fBreakpoints.insertBreakpoint(
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   647
	                            context, newAttrsList.get(i),
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   648
	                            new DataRequestMonitor<IBreakpointDMContext>(getExecutor(), countingRM) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   649
	                                @Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   650
	                                protected void handleCompleted() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   651
	                                    if (isSuccess()) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   652
	                                        bp.fTargetBPContext = getData();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   653
	                                    } 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   654
	                                    bp.fStatus = getStatus();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   655
	                                    countingRM.done();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   656
	                                }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   657
	                            });
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   658
                    	} else {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   659
                    		// Failed to remove old breakpoint, do not proceed to insert a new one
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   660
                    		// just save the error from target with the old context.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   661
                            bp.fStatus = getStatus();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   662
                            countingRM.done();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   663
                    	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   664
                    }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   665
                };
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   666
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   667
            	fBreakpoints.removeBreakpoint(bp.getTargetBreakpoint(), removeRm);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   668
                coutingRmCount++;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   669
            } else {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   670
                // The back end can modify the breakpoint.  Update the breakpoint with the 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   671
                // new attributes.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   672
                fBreakpoints.updateBreakpoint(
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   673
                    bp.getTargetBreakpoint(), bp.fAttributes, 
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   674
                    new RequestMonitor(getExecutor(), countingRM) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   675
                        @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   676
                        protected void handleCompleted() {
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   677
                            bp.fStatus = getStatus();
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   678
                            countingRM.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   679
                        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   680
                    });
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   681
                coutingRmCount++;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   682
            }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   683
        }
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   684
        countingRM.setDoneCount(coutingRmCount);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   685
	} 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   686
	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   687
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   688
	 * Determine the set of modified attributes
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   689
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   690
	 * @param oldAttributes
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   691
	 * @param newAttributes
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   692
	 * @return
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   693
	 */
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   694
	private void calcBPsAttrs(List<TargetBP> oldBpList, List<TargetBP> bpList) {
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   695
	    // Go through the bp attributes common to the old and the new lists and calculate
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   696
	    // their deltas.
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   697
		int i = 0;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   698
	    for (i = 0; i < oldBpList.size() && i < bpList.size(); i++) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   699
    		TargetBP newBp = bpList.get(i);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   700
    		TargetBP oldBp = oldBpList.get(i);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   701
    		newBp.fTargetBPContext = oldBp.getTargetBreakpoint();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   702
	        Map<String, Object> oldAttributes = oldBp.fAttributes; 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   703
	        Map<String, Object> newAttributes = newBp.fAttributes;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   704
    	    
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   705
	        if (oldAttributes == null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   706
	        	// Reached a point in the old BP list where breakpoints were 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   707
	        	// removed.  Break out of the loop.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   708
	        	break;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   709
	        }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   710
	        
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   711
    		bpList.get(i).fAttributesDelta = getAttributesDelta(oldAttributes, newAttributes);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   712
	    } 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   713
	    
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   714
	    // Add all the new attributes as deltas
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   715
	    for (; i < bpList.size(); i++) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   716
	    	TargetBP newBP = bpList.get(i); 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   717
	        newBP.fAttributesDelta =  newBP.fAttributes;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   718
	    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   719
	    
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   720
	    // For breakpoints that were removed create TargetBP entry with a 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   721
	    // null set of attributes
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   722
	    for (; i < oldBpList.size(); i++) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   723
	    	TargetBP oldBp = oldBpList.get(i);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   724
	    	if (oldBp.fAttributes == null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   725
	    		// Guard against old removed breakpoints
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   726
	    		break;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   727
	    	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   728
	    	TargetBP newBp = new TargetBP(null);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   729
	    	newBp.fTargetBPContext = oldBp.getTargetBreakpoint();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   730
	    	newBp.fAttributesDelta = oldBpList.get(i).fAttributes;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   731
	    	bpList.add(newBp);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   732
	    }	    
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   733
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   734
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   735
    ///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   736
    // IBreakpointManagerListener implementation
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   737
    ///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   738
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   739
	public void breakpointManagerEnablementChanged(boolean enabled) {
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   740
		Map<String, Object> platformAttrDelta = new HashMap<String, Object>(1);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   741
		platformAttrDelta.put(IBreakpoint.ENABLED, enabled);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   742
		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   743
		Map<IBreakpoint, Map<String, Object>> bp2DeltaMap = new HashMap<IBreakpoint, Map<String, Object>>(); 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   744
		for (IBreakpoint bp : fBreakpointManager.getBreakpoints()) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   745
			if (! fAttributeTranslator.supportsBreakpoint(bp))
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   746
				continue;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   747
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   748
			bp2DeltaMap.put(bp, platformAttrDelta);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   749
		}
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   750
		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   751
		doBreakpointsChanged(bp2DeltaMap);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   752
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   753
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   754
	@ThreadSafe
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   755
	public void breakpointsAdded(final IBreakpoint[] bps) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   756
		doBreakpointsAdded(bps, null, null);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   757
	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   758
	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   759
	@SuppressWarnings("unchecked")
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   760
	private void doBreakpointsAdded(final IBreakpoint[] bps, final IBreakpointsTargetDMContext bpsTargetDmc, final RequestMonitor rm) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   761
		final List<IBreakpoint> bpCandidates = new ArrayList<IBreakpoint>(bps.length);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   762
		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   763
		for (int i = 0; i < bps.length; i++) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   764
			IBreakpoint bp = bps[i];
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   765
			
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   766
			if (fAttributeTranslator.supportsBreakpoint(bp)) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   767
				try {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   768
					if (fAttributeTranslator2 != null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   769
						if (bp.getMarker() == null)
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   770
							continue;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   771
						
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   772
						// if the breakpoint is not enabled, ask translator2 if it can set (and manage)
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   773
						// disabled breakpoint itself. If not, just bail out.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   774
						//
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   775
						Map<String, Object> platformAttrs = bp.getMarker().getAttributes();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   776
						
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   777
						if (! (Boolean)platformAttrs.get(IBreakpoint.ENABLED) || ! fBreakpointManager.isEnabled()) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   778
							Map<String, Object> platformAttr = new HashMap<String, Object>(1);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   779
							platformAttr.put(IBreakpoint.ENABLED, Boolean.FALSE);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   780
							Map<String, Object> targetAttr = fAttributeTranslator2.convertAttributeDelta(platformAttr);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   781
							if (! fAttributeTranslator2.canUpdateAttributes(null, targetAttr)) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   782
								// bail out.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   783
								continue;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   784
							}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   785
						}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   786
					}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   787
					
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   788
					bpCandidates.add(bp);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   789
				} catch (CoreException e) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   790
					DsfPlugin.getDefault().getLog().log(e.getStatus());
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   791
				}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   792
			}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   793
		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   794
		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   795
		// Nothing to do
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   796
		if (bpCandidates.isEmpty()) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   797
			if (rm != null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   798
				rm.done();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   799
			}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   800
			return;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   801
		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   802
				
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   803
		try {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   804
            getExecutor().execute(new DsfRunnable() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   805
				public void run() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   806
					final Map<IBreakpoint, Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>> eventBPs =  
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   807
						new HashMap<IBreakpoint, Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>>(bpCandidates.size(), 1);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   808
					
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   809
	                CountingRequestMonitor processPendingCountingRm = new CountingRequestMonitor(getExecutor(), rm) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   810
		                    @Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   811
		                    protected void handleCompleted() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   812
		                    	processPendingRequests();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   813
		                    	fireUpdateBreakpointsStatus(eventBPs, BreakpointEventType.ADDED);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   814
		                        super.handleCompleted();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   815
		                    }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   816
		                };	            	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   817
	                int processPendingCountingRmCount = 0;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   818
	            	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   819
	            	for (final IBreakpoint breakpoint : bpCandidates) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   820
	            		final Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]> targetBPs = 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   821
	            			new HashMap<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>(fPlatformBPs.size(), 1);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   822
	            		eventBPs.put(breakpoint, targetBPs);	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   823
	            			
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   824
						if (fRunningEvents.contains(breakpoint)) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   825
							PendingEventInfo pendingEvent = new PendingEventInfo(BreakpointEventType.ADDED, bpsTargetDmc, processPendingCountingRm);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   826
							processPendingCountingRmCount++;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   827
							updatePendingRequest(breakpoint, pendingEvent);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   828
							continue;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   829
						}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   830
		                // Mark the breakpoint as being updated and go
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   831
		                fRunningEvents.add(breakpoint);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   832
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   833
	            		final CountingRequestMonitor bpTargetsCountingRm = new CountingRequestMonitor(getExecutor(), processPendingCountingRm) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   834
								@Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   835
								protected void handleCompleted() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   836
			                    	// Indicate that the running event has completed
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   837
			                    	fRunningEvents.remove(breakpoint);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   838
			                    	super.handleCompleted();
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   839
								}
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   840
							};
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   841
						int bpTargetsCountingRmCount = 0;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   842
						processPendingCountingRmCount++;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   843
	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   844
						
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   845
						// Install the breakpoint in all the execution contexts
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   846
						for (final IBreakpointsTargetDMContext dmc : fPlatformBPs.keySet()) {
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   847
							if (bpsTargetDmc != null && !bpsTargetDmc.equals(dmc)) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   848
								continue;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   849
							}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   850
							
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   851
			                // Now ask lower level to set the bp.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   852
							//
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   853
							if (fAttributeTranslator2 != null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   854
								fAttributeTranslator2.getTargetBreakpointAttributes(dmc, breakpoint, fBreakpointManager.isEnabled(),
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   855
										new DataRequestMonitor<List<Map<String,Object>>>(getExecutor(), bpTargetsCountingRm){
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   856
											@Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   857
											protected void handleSuccess() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   858
												installBreakpoint(
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   859
											    		dmc, breakpoint, getData(), 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   860
											    		new DataRequestMonitor<List<TargetBP>>(getExecutor(), bpTargetsCountingRm) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   861
											    			@Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   862
															protected void handleSuccess() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   863
											    				targetBPs.put(dmc, getData().toArray(new ITargetBreakpointInfo[getData().size()]));
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   864
											    				super.handleSuccess();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   865
											    			};
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   866
											    		});
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   867
											}});
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   868
							}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   869
							else {	// Old way
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   870
								List<Map<String, Object>> attrsArray;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   871
								try {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   872
									attrsArray = fAttributeTranslator.getBreakpointAttributes(breakpoint, fBreakpointManager.isEnabled());
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   873
								} catch (CoreException e) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   874
									attrsArray = new ArrayList<Map<String, Object>>();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   875
									DsfPlugin.getDefault().getLog().log(e.getStatus());
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   876
								}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   877
				        		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   878
								installBreakpoint(
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   879
						    		dmc, breakpoint, attrsArray, 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   880
						    		new DataRequestMonitor<List<TargetBP>>(getExecutor(), bpTargetsCountingRm) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   881
						    			@Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   882
										protected void handleSuccess() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   883
						    				targetBPs.put(dmc, getData().toArray(new ITargetBreakpointInfo[getData().size()]));
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   884
						    				super.handleSuccess();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   885
						    			};
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   886
						    		});
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   887
							}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   888
							
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   889
							bpTargetsCountingRmCount++;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   890
						}
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   891
						bpTargetsCountingRm.setDoneCount(bpTargetsCountingRmCount);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   892
	            	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   893
	            	processPendingCountingRm.setDoneCount(processPendingCountingRmCount);	            	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   894
				}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   895
			});
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   896
		} catch (RejectedExecutionException e) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   897
			IStatus status = new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, IDsfStatusConstants.INTERNAL_ERROR, "Request for monitor: '" + toString() + "' resulted in a rejected execution exception.", e);//$NON-NLS-1$ //$NON-NLS-2$
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   898
			if (rm != null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   899
				rm.setStatus(status);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   900
				rm.done();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   901
			} else {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   902
				DsfPlugin.getDefault().getLog().log(status); 
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   903
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   904
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   905
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   906
	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   907
    ///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   908
    // IBreakpointListener implementation
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   909
    ///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   910
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   911
	@SuppressWarnings("unchecked")
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   912
	public void breakpointsChanged(IBreakpoint[] bps, IMarkerDelta[] deltas) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   913
		Map<IBreakpoint, Map<String, Object>> bp2DeltaMap = new HashMap<IBreakpoint, Map<String, Object>>(); 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   914
		for (int i = 0; i < bps.length; i++) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   915
			IBreakpoint bp = bps[i];
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   916
			
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   917
			if (deltas[i] == null)
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   918
				continue;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   919
			
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   920
			if (bp.getMarker() == null)
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   921
				continue;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   922
			
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   923
			if (! fAttributeTranslator.supportsBreakpoint(bp))
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   924
				continue;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   925
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   926
			try {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   927
				Map<String, Object> oldAttrs = deltas[i].getAttributes();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   928
				Map<String, Object> newAttrs = bp.getMarker().getAttributes();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   929
				
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   930
				Map<String, Object> platformAttrDelta = getAttributesDelta(oldAttrs, newAttrs);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   931
				
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   932
				if (platformAttrDelta.size() == 0) // no change. possible when user cancels breakpoint properties dialog.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   933
					continue;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   934
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   935
				bp2DeltaMap.put(bp, platformAttrDelta);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   936
			} catch (CoreException e) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   937
				DsfPlugin.getDefault().getLog().log(e.getStatus());
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   938
			}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   939
		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   940
		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   941
		doBreakpointsChanged(bp2DeltaMap);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   942
	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   943
	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   944
	/**
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   945
	 * 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   946
	 * @param bp2DeltaMap - pairs of (breakpoint, attrDelta), where attrDelta contains changed 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   947
	 * and new attributes for the breakpoint.  
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   948
	 */
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   949
	private void doBreakpointsChanged(Map<IBreakpoint, Map<String, Object>> bp2DeltaMap) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   950
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   951
		final Map<IBreakpoint, List<Map<String, Object>>> bpsAttrs = 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   952
			new HashMap<IBreakpoint, List<Map<String, Object>>>(bp2DeltaMap.size() * 4/3);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   953
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   954
		for (IBreakpoint bp : bp2DeltaMap.keySet()) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   955
			try {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   956
				Map<String, Object> platformAttrDelta = bp2DeltaMap.get(bp);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   957
				
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   958
				if (fAttributeTranslator2 != null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   959
					Map<String, Object> targetAttrDelta = fAttributeTranslator2.convertAttributeDelta(platformAttrDelta);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   960
		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   961
					if (! fAttributeTranslator2.canUpdateAttributes(null, targetAttrDelta)) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   962
						// DSF client cannot handle at least one of the attribute change, just remove
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   963
						// old target BPs and install new ones.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   964
						final IBreakpoint[] platformBPs = new IBreakpoint[] {bp};
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   965
						
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   966
						if (platformAttrDelta.containsKey(IBreakpoint.ENABLED)) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   967
							if ((Boolean)platformAttrDelta.get(IBreakpoint.ENABLED))
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   968
								// platform BP changed from disabled to enabled
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   969
								doBreakpointsAdded(platformBPs, null, null);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   970
							else
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   971
								doBreakpointsRemoved(platformBPs, null, null);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   972
						}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   973
						else {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   974
							// other attribute change, remove old and install new.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   975
							doBreakpointsRemoved(platformBPs, null, new RequestMonitor(getExecutor(), null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   976
								@Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   977
								protected void handleSuccess() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   978
									doBreakpointsAdded(platformBPs, null, null);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   979
								}});
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   980
						}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   981
					}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   982
					else 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   983
						updateBreakpoint(bp, targetAttrDelta);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   984
				}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   985
				else { // old way
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   986
					
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   987
	                // Retrieve the breakpoint attributes
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   988
	        		List<Map<String, Object>> attrsArray = 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   989
	        		    fAttributeTranslator.getBreakpointAttributes(bp, fBreakpointManager.isEnabled());
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   990
	        		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   991
	        		bpsAttrs.put(bp, attrsArray);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   992
				}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   993
			} catch (CoreException e) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   994
				DsfPlugin.getDefault().getLog().log(e.getStatus());
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   995
			}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   996
		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   997
		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   998
		if (bpsAttrs.isEmpty()) return; // nothing to do
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
   999
		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1000
		try {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1001
			// Modify the breakpoint in all the target contexts
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1002
	        getExecutor().execute( new DsfRunnable() { 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1003
	            public void run() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1004
					final Map<IBreakpoint, Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>> eventBPs =  
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1005
						new HashMap<IBreakpoint, Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>>(bpsAttrs.size(), 1);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1006
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1007
					CountingRequestMonitor processPendingCountingRm = new CountingRequestMonitor(getExecutor(), null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1008
	                    @Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1009
	                    protected void handleCompleted() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1010
	                    	processPendingRequests();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1011
	                    	fireUpdateBreakpointsStatus(eventBPs, BreakpointEventType.MODIFIED);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1012
	                    }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1013
	                };	            	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1014
	                int processPendingCountingRmCount = 0;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1015
	            	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1016
	            	for (final IBreakpoint breakpoint : bpsAttrs.keySet()) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1017
	            		final Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]> targetBPs = 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1018
	            			new HashMap<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>(fPlatformBPs.size(), 1);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1019
	            		eventBPs.put(breakpoint, targetBPs);	
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1020
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1021
	            		// If the breakpoint is currently being updated, queue the request and exit
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1022
		            	if (fRunningEvents.contains(breakpoint)) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1023
		            		updatePendingRequest(breakpoint, new PendingEventInfo(BreakpointEventType.MODIFIED, null, null));
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1024
							continue;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1025
		            	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1026
		            	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1027
		                // Keep track of the updates
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1028
		                CountingRequestMonitor bpTargetsCountingRm = 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1029
		                	new CountingRequestMonitor(getExecutor(), processPendingCountingRm) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1030
			                    @Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1031
			                    protected void handleCompleted() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1032
			                    	// Indicate that the running event has completed
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1033
			                    	fRunningEvents.remove(breakpoint);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1034
			                    	super.handleCompleted();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1035
			                    }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1036
			                };
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1037
			            processPendingCountingRmCount++;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1038
		                bpTargetsCountingRm.setDoneCount(fPlatformBPs.size());
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1039
	
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1040
		                // Mark the breakpoint as being updated and go
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1041
		                fRunningEvents.add(breakpoint);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1042
		                
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1043
		                // Modify the breakpoint in all the execution contexts
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1044
		                for (final IBreakpointsTargetDMContext dmc : fPlatformBPs.keySet()) {
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1045
		                    modifyBreakpoint(
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1046
		                    		dmc, breakpoint, bpsAttrs.get(breakpoint), 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1047
		                    		new DataRequestMonitor<List<TargetBP>>(getExecutor(), bpTargetsCountingRm) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1048
						    			@Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1049
										protected void handleSuccess() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1050
						    				targetBPs.put(dmc, getData().toArray(new ITargetBreakpointInfo[getData().size()]));
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1051
						    				super.handleSuccess();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1052
						    			};
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1053
		                    		});
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1054
		                }
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1055
	            	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1056
	            	processPendingCountingRm.setDoneCount(processPendingCountingRmCount);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1057
	            }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1058
	        });
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1059
	    } catch (RejectedExecutionException e) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1060
			DsfPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, IDsfStatusConstants.INTERNAL_ERROR, "Request for monitor: '" + toString() + "' resulted in a rejected execution exception.", e)); //$NON-NLS-1$ //$NON-NLS-2$
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1061
	    }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1062
	}
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1063
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1064
	/**
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1065
	 * For the given platform BP, update all its target BPs with the given attribute change.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1066
	 * 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1067
	 * @param bp
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1068
	 * @param targetAttrDelta - target attribute change.  
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1069
	 */
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1070
	private void updateBreakpoint(final IBreakpoint bp, final Map<String, Object> targetAttrDelta) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1071
        getExecutor().execute(new DsfRunnable() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1072
        	public void run() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1073
				for (IBreakpointsTargetDMContext dmc : fPlatformBPs.keySet()) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1074
					List<TargetBP> targetBPs = fPlatformBPs.get(dmc).get(bp);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1075
					if (targetBPs != null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1076
						for (TargetBP tbp : targetBPs) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1077
							// this must be an installed bp.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1078
							assert (tbp.getTargetBreakpoint() != null);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1079
							
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1080
							fBreakpoints.updateBreakpoint(tbp.getTargetBreakpoint(), targetAttrDelta, new RequestMonitor(getExecutor(), null) {});
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1081
						}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1082
					}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1083
				}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1084
        	}});
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1085
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1086
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1087
	public void breakpointsRemoved(final IBreakpoint[] bps, IMarkerDelta delta[]) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1088
		doBreakpointsRemoved(bps, null, null);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1089
	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1090
	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1091
	public void doBreakpointsRemoved(final IBreakpoint[] bps, final IBreakpointsTargetDMContext bpsTargetDmc, final RequestMonitor rm) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1092
	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1093
		final List<IBreakpoint> bpCandidates = new ArrayList<IBreakpoint>();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1094
		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1095
		for (int i = 0; i < bps.length; i++) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1096
			IBreakpoint bp = bps[i];
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1097
			
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1098
			if (fAttributeTranslator.supportsBreakpoint(bp)) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1099
				if (bpsTargetDmc == null)
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1100
					bpCandidates.add(bp);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1101
				else if (fPlatformBPs.get(bpsTargetDmc).containsKey(bp))	// target BPs are installed in the context 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1102
					bpCandidates.add(bp);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1103
			}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1104
		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1105
		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1106
		if (bpCandidates.isEmpty()) { // nothing to do
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1107
			if (rm != null)
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1108
				rm.done();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1109
			return;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1110
		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1111
		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1112
		try {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1113
	        getExecutor().execute(new DsfRunnable() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1114
	        	public void run() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1115
					final Map<IBreakpoint, Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>> eventBPs =  
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1116
						new HashMap<IBreakpoint, Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>>(bpCandidates.size(), 1);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1117
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1118
					CountingRequestMonitor processPendingCountingRm = new CountingRequestMonitor(getExecutor(), rm) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1119
            			@Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1120
            			protected void handleCompleted() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1121
            				processPendingRequests();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1122
	                    	fireUpdateBreakpointsStatus(eventBPs, BreakpointEventType.REMOVED);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1123
            				super.handleCompleted();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1124
            			}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1125
            		};
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1126
            		int processPendingCountingRmCount = 0;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1127
            		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1128
					for (final IBreakpoint breakpoint : bpCandidates) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1129
	            		final Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]> targetBPs = 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1130
	            			new HashMap<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>(fPlatformBPs.size(), 1);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1131
	            		eventBPs.put(breakpoint, targetBPs);	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1132
				
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1133
		            	// If the breakpoint is currently being updated, queue the request and exit
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1134
		            	if (fRunningEvents.contains(breakpoint)) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1135
		            		PendingEventInfo pendingEvent = new PendingEventInfo(BreakpointEventType.REMOVED, bpsTargetDmc, processPendingCountingRm);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1136
            				processPendingCountingRmCount++;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1137
		            		updatePendingRequest(breakpoint, pendingEvent);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1138
							continue;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1139
		            	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1140
		            	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1141
	            		CountingRequestMonitor bpTargetDmcCRM = new CountingRequestMonitor(getExecutor(), processPendingCountingRm) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1142
							@Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1143
							protected void handleCompleted() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1144
		                    	// Indicate that the running event has completed
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1145
		                    	fRunningEvents.remove(breakpoint);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1146
		                    	super.handleCompleted();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1147
							}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1148
						};
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1149
						processPendingCountingRmCount++;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1150
						int bpTargetDmcCRMCount = 0;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1151
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1152
	            		// Remove the breakpoint in all the execution contexts
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1153
	            		for (final IBreakpointsTargetDMContext dmc : fPlatformBPs.keySet()) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1154
	            			if (bpsTargetDmc != null && !bpsTargetDmc.equals(dmc)) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1155
	            				continue;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1156
	            			}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1157
	            			
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1158
	            			if (fPlatformBPs.get(dmc).containsKey(breakpoint)) {		// there are targetBPs installed 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1159
	            				uninstallBreakpoint(
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1160
	            						dmc, breakpoint,
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1161
	            						new DataRequestMonitor<List<TargetBP>>(getExecutor(), bpTargetDmcCRM) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1162
							    			@Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1163
											protected void handleSuccess() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1164
							    				targetBPs.put(dmc, getData().toArray(new ITargetBreakpointInfo[getData().size()]));
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1165
							    				super.handleSuccess();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1166
							    			};
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1167
	            						});
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1168
	            				bpTargetDmcCRMCount++;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1169
	            			} else {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1170
	            				// Breakpoint not installed for given context, do nothing.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1171
	            			}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1172
	            		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1173
	            		bpTargetDmcCRM.setDoneCount(bpTargetDmcCRMCount);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1174
					}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1175
					
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1176
					processPendingCountingRm.setDoneCount(processPendingCountingRmCount);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1177
	        	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1178
	        });
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1179
        } catch (RejectedExecutionException e) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1180
			IStatus status = new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, IDsfStatusConstants.INTERNAL_ERROR, "Request for monitor: '" + toString() + "' resulted in a rejected execution exception.", e);//$NON-NLS-1$ //$NON-NLS-2$
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1181
			if (rm != null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1182
				rm.setStatus(status);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1183
				rm.done();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1184
			} else {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1185
				DsfPlugin.getDefault().getLog().log(status); 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1186
			}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1187
        }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1188
	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1189
	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1190
	private void updatePendingRequest(IBreakpoint breakpoint, PendingEventInfo pendingEvent) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1191
		LinkedList<PendingEventInfo> pendingEventsList = fPendingEvents.get(breakpoint);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1192
		if (pendingEventsList == null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1193
			pendingEventsList = new LinkedList<PendingEventInfo>();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1194
			fPendingEvents.put(breakpoint, pendingEventsList);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1195
		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1196
		if (pendingEventsList.size() > 0 &&
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1197
				pendingEventsList.getLast().fEventType == BreakpointEventType.MODIFIED) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1198
			pendingEventsList.removeLast();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1199
		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1200
		pendingEventsList.add(pendingEvent);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1201
	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1202
	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1203
	private void processPendingRequests() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1204
		if (fPendingEvents.isEmpty()) return;  // Nothing to do
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1205
		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1206
		final List<PendingEventInfo> modifyBPs = new ArrayList<PendingEventInfo>(1);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1207
		final Map<IBreakpointsTargetDMContext, List<PendingEventInfo>> addBPs =
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1208
			new HashMap<IBreakpointsTargetDMContext, List<PendingEventInfo>>(1);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1209
		final Map<IBreakpointsTargetDMContext, List<PendingEventInfo>> removeBPs =
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1210
			new HashMap<IBreakpointsTargetDMContext, List<PendingEventInfo>>(1);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1211
		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1212
		// Make a copy to avoid java.util.ConcurrentModificationException.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1213
		Set<IBreakpoint> bpsInPendingEvents = new HashSet<IBreakpoint>(fPendingEvents.keySet()); 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1214
//		for (IBreakpoint bp : fPendingEvents.keySet()) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1215
		for (IBreakpoint bp : bpsInPendingEvents) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1216
	    	// Process the next pending update for this breakpoint
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1217
	    	if (!fRunningEvents.contains(bp)) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1218
	    		LinkedList<PendingEventInfo> eventInfoList = fPendingEvents.get(bp);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1219
	    		PendingEventInfo eventInfo = eventInfoList.removeFirst();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1220
	    		if (eventInfoList.isEmpty()) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1221
	    			fPendingEvents.remove(bp);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1222
	    		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1223
	    		BreakpointEventType type = eventInfo.fEventType;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1224
	    		if (type.equals(BreakpointEventType.MODIFIED)) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1225
	    			modifyBPs.add(eventInfo);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1226
	    		} else if (type.equals(BreakpointEventType.ADDED)){
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1227
	    			List<PendingEventInfo> addList = addBPs.get(eventInfo.fBPsTargetDmc);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1228
	    			if (addList == null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1229
	    				addList = new ArrayList<PendingEventInfo>(1);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1230
	    				addBPs.put(eventInfo.fBPsTargetDmc, addList);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1231
	    			}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1232
	    			addList.add(eventInfo);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1233
	    		} else if (type.equals(BreakpointEventType.REMOVED)){
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1234
	    			List<PendingEventInfo> removeList = removeBPs.get(eventInfo.fBPsTargetDmc);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1235
	    			if (removeList == null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1236
	    				removeList = new ArrayList<PendingEventInfo>(1);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1237
	    				removeBPs.put(eventInfo.fBPsTargetDmc, removeList);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1238
	    			}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1239
	    			removeList.add(eventInfo);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1240
	    		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1241
	    	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1242
		}
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1243
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1244
		if (modifyBPs.size() != 0 || removeBPs.size() != 0) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1245
			new Job("Deferred breakpoint changed job") { //$NON-NLS-1$
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1246
	            { setSystem(true); }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1247
	            @Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1248
	            protected IStatus run(IProgressMonitor monitor) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1249
	            	if (modifyBPs.size() != 0) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1250
	            		breakpointsChanged(modifyBPs.toArray(new IBreakpoint[modifyBPs.size()]), null);	            		
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1251
	            	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1252
	            	if (addBPs.size() != 0) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1253
	            		for (Map.Entry<IBreakpointsTargetDMContext, List<PendingEventInfo>> addBPsEntry : addBPs.entrySet()) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1254
	            			IBreakpointsTargetDMContext bpsTargetDmc = addBPsEntry.getKey();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1255
	            			final List<PendingEventInfo> addBpList = addBPsEntry.getValue();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1256
	            			RequestMonitor rm = new RequestMonitor(ImmediateExecutor.getInstance(), null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1257
	            				@Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1258
								protected void handleCompleted() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1259
	            					for (PendingEventInfo eventInfo : addBpList) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1260
	            						if (eventInfo.fRequestMonitor != null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1261
	            							eventInfo.fRequestMonitor.done();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1262
	            						}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1263
	            					}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1264
	            				};
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1265
	            			};
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1266
		            		doBreakpointsAdded(addBpList.toArray(new IBreakpoint[addBpList.size()]), bpsTargetDmc, rm);	            			            			
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1267
	            		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1268
	            	} 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1269
	            	if (removeBPs.size() != 0) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1270
	            		for (Map.Entry<IBreakpointsTargetDMContext, List<PendingEventInfo>> removeBPsEntry : removeBPs.entrySet()) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1271
	            			IBreakpointsTargetDMContext bpsTargetDmc = removeBPsEntry.getKey();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1272
	            			final List<PendingEventInfo> removeBpList = removeBPsEntry.getValue();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1273
	            			RequestMonitor rm = new RequestMonitor(ImmediateExecutor.getInstance(), null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1274
	            				@Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1275
								protected void handleCompleted() {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1276
	            					for (PendingEventInfo eventInfo : removeBpList) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1277
	            						if (eventInfo.fRequestMonitor != null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1278
	            							eventInfo.fRequestMonitor.done();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1279
	            						}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1280
	            					}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1281
	            				};
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1282
	            			};
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1283
		            		doBreakpointsRemoved(removeBpList.toArray(new IBreakpoint[removeBpList.size()]), bpsTargetDmc, rm);	            			            			
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1284
	            		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1285
	            	} 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1286
	                return Status.OK_STATUS;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1287
	            };
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1288
			}.schedule();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1289
		}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1290
	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1291
	
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1292
	private void fireUpdateBreakpointsStatus(final Map<IBreakpoint, Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>> eventBPs, final BreakpointEventType eventType) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1293
        // Update breakpoint status
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1294
        new Job("Breakpoint status update") { //$NON-NLS-1$
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1295
            { setSystem(true); }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1296
            @Override
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1297
            protected IStatus run(IProgressMonitor monitor) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1298
            	for (IBreakpoint bp : eventBPs.keySet()) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1299
            		fAttributeTranslator.updateBreakpointStatus(bp);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1300
            	}
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1301
                
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1302
                if (fAttributeTranslator2 != null) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1303
                	fAttributeTranslator2.updateBreakpointsStatus(eventBPs, eventType);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1304
                }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1305
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1306
                return Status.OK_STATUS;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1307
            };
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1308
        }.schedule();
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1309
		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1310
	}
112
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1311
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1312
    /**
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1313
     * Determine the set of modified attributes.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1314
     * 
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1315
     * @param oldAttributes old map of attributes.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1316
     * @param newAttributes new map of attributes.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1317
     * @return new and changed attribute in the new map. May be empty indicating the two maps are equal.
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1318
     */
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1319
    private Map<String, Object> getAttributesDelta(Map<String, Object> oldAttributes, Map<String, Object> newAttributes) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1320
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1321
        Map<String, Object> delta = new HashMap<String,Object>();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1322
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1323
        Set<String> oldKeySet = oldAttributes.keySet();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1324
        Set<String> newKeySet = newAttributes.keySet();
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1325
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1326
        Set<String> commonKeys  = new HashSet<String>(newKeySet); commonKeys.retainAll(oldKeySet);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1327
        Set<String> addedKeys   = new HashSet<String>(newKeySet); addedKeys.removeAll(oldKeySet);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1328
        Set<String> removedKeys = new HashSet<String>(oldKeySet); removedKeys.removeAll(newKeySet);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1329
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1330
        // Add the modified attributes
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1331
        for (String key : commonKeys) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1332
            if (!(oldAttributes.get(key).equals(newAttributes.get(key))))
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1333
                delta.put(key, newAttributes.get(key));
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1334
        }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1335
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1336
        // Add the new attributes
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1337
        for (String key : addedKeys) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1338
            delta.put(key, newAttributes.get(key));
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1339
        }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1340
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1341
        // Remove the deleted attributes
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1342
        for (String key : removedKeys) {
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1343
            delta.put(key, null);
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1344
        }
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1345
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1346
        return delta;
6b1088abccf8 Reworked BreakpointsMediator. See Eclipse bug 292468.
l12wang
parents: 104
diff changeset
  1347
    }
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1348
}