/** * Performs the actual count retrieval and calculation. * * @param rm Request monitor to complete with data. */ private void doGetCount(final DataRequestMonitor<Integer> rm) { // Array to store counts retrieved asynchronously final int[] counts = new int[fDataGenerators.length]; // Counting request monitor is called once all data is retrieved. final CountingRequestMonitor crm = new CountingRequestMonitor(fExecutor, rm) { @Override protected void handleSuccess() { // Pick the highest count value. Arrays.sort(counts, 0, counts.length - 1); int maxCount = counts[counts.length - 1]; rm.setData(maxCount); rm.done(); }; }; // Each call to data generator fills in one value in array. for (int i = 0; i < fDataGenerators.length; i++) { final int finalI = i; fDataGenerators[i].getCount( new DataRequestMonitor<Integer>(ImmediateExecutor.getInstance(), crm) { @Override protected void handleSuccess() { counts[finalI] = getData(); crm.done(); } }); } crm.setDoneCount(fDataGenerators.length); }
/** Start executing the program. */ @Execute public void stepStartExecution(final RequestMonitor rm) { if (fBackend.getSessionType() != SessionType.CORE) { // Overwrite the program name to use the binary name that was specified. // This is important for multi-process // Bug 342351 fAttributes.put(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, fBinaryName); fProcService.start( getContainerContext(), fAttributes, new DataRequestMonitor<IContainerDMContext>(ImmediateExecutor.getInstance(), rm) { @Override protected void handleSuccess() { assert getData() instanceof IMIContainerDMContext; // Set the container that we created setContainerContext( DMContexts.getAncestorOfType(getData(), IMIContainerDMContext.class)); fDataRequestMonitor.setData(getContainerContext()); // Don't call fDataRequestMonitor.done(), the sequence will // automatically do that when it completes; rm.done(); } }); } else { fDataRequestMonitor.setData(getContainerContext()); rm.done(); } }
/** Specify the arguments to the program that will be run. */ @Execute public void stepSetArguments(RequestMonitor rm) { try { String args = fBackend.getProgramArguments(); if (args != null) { String[] argArray = args.replaceAll("\n", " ").split(" "); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ fCommandControl.queueCommand( fCommandFactory.createMIGDBSetArgs(getContainerContext(), argArray), new DataRequestMonitor<MIInfo>(ImmediateExecutor.getInstance(), rm)); } else { rm.done(); } } catch (CoreException e) { rm.setStatus( new Status( IStatus.ERROR, GdbPlugin.PLUGIN_ID, IDsfStatusConstants.REQUEST_FAILED, "Cannot get inferior arguments", e)); //$NON-NLS-1$ rm.done(); } }
/** * Performs the actual value retrieval and calculation. * * @param rm Request monitor to complete with data. */ private void doGetValue(int index, final DataRequestMonitor<Integer> rm) { // Array to store counts retrieved asynchronously final int[] values = new int[fDataGenerators.length]; // Counting request monitor is called once all data is retrieved. final CountingRequestMonitor crm = new CountingRequestMonitor(fExecutor, rm) { @Override protected void handleSuccess() { // Sum up values in array. int sum = 0; for (int value : values) { sum += value; } rm.setData(sum); rm.done(); }; }; // Each call to data generator fills in one value in array. for (int i = 0; i < fDataGenerators.length; i++) { final int finalI = i; fDataGenerators[i].getValue( index, new DataRequestMonitor<Integer>(ImmediateExecutor.getInstance(), crm) { @Override protected void handleSuccess() { values[finalI] = getData(); crm.done(); } }); } crm.setDoneCount(fDataGenerators.length); }
/** * This method initializes this service. * * @param requestMonitor The request monitor indicating the operation is finished */ @Override public void initialize(final RequestMonitor requestMonitor) { super.initialize( new RequestMonitor(ImmediateExecutor.getInstance(), requestMonitor) { @Override protected void handleSuccess() { doInitialize(requestMonitor); } }); }
/** * The entry point for the example. * * @param args Program arguments. */ public static void main(String[] args) { // Create the shell to hold the viewer. Display display = new Display(); Shell shell = new Shell(display, SWT.SHELL_TRIM); shell.setLayout(new GridLayout()); GridData data = new GridData(GridData.FILL_BOTH); shell.setLayoutData(data); Font font = new Font(display, "Courier", 10, SWT.NORMAL); // Create the table viewer. TableViewer tableViewer = new TableViewer(shell, SWT.BORDER); tableViewer.getControl().setLayoutData(data); // Create the data generator. // #ifdef exercises // TODO Exercise 5 - Use the DataGeneratorWithExecutor() instead. final IDataGenerator generator = new DataGeneratorWithThread(); // #else // # final IDataGenerator generator = new DataGeneratorWithExecutor(); // #endif // Create the content provider which will populate the viewer. SyncDataViewer contentProvider = new SyncDataViewer(tableViewer, generator); tableViewer.setContentProvider(contentProvider); tableViewer.setInput(new Object()); // Open the shell and service the display dispatch loop until user // closes the shell. shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } // The IDataGenerator.shutdown() method is asynchronous, this requires // using a query again in order to wait for its completion. Query<Object> shutdownQuery = new Query<Object>() { @Override protected void execute(DataRequestMonitor<Object> rm) { generator.shutdown(rm); } }; ImmediateExecutor.getInstance().execute(shutdownQuery); try { shutdownQuery.get(); } catch (Exception e) { } // Shut down the display. font.dispose(); display.dispose(); }
/** * If we are dealing with a remote debugging session, connect to the target. * * @since 4.0 */ @Execute public void stepRemoteConnection(RequestMonitor rm) { // If we are dealing with a non-attach remote session, it is now time to connect // to the remote side. Note that this is the 'target remote' case // and not the 'target extended-remote' case (remote attach session) // This step is actually global for GDB. However, we have to do it after // we have specified the executable, so we have to do it here. // It is safe to do it here because a 'target remote' does not support // multi-process so this step will not be executed more than once. if (fBackend.getSessionType() == SessionType.REMOTE && !fBackend.getIsAttachSession()) { boolean isTcpConnection = CDebugUtils.getAttribute( fAttributes, IGDBLaunchConfigurationConstants.ATTR_REMOTE_TCP, false); if (isTcpConnection) { String remoteTcpHost = CDebugUtils.getAttribute( fAttributes, IGDBLaunchConfigurationConstants.ATTR_HOST, INVALID); String remoteTcpPort = CDebugUtils.getAttribute( fAttributes, IGDBLaunchConfigurationConstants.ATTR_PORT, INVALID); fCommandControl.queueCommand( fCommandFactory.createMITargetSelect( fCommandControl.getContext(), remoteTcpHost, remoteTcpPort, false), new DataRequestMonitor<MIInfo>(ImmediateExecutor.getInstance(), rm)); } else { String serialDevice = CDebugUtils.getAttribute( fAttributes, IGDBLaunchConfigurationConstants.ATTR_DEV, INVALID); fCommandControl.queueCommand( fCommandFactory.createMITargetSelect(fCommandControl.getContext(), serialDevice, false), new DataRequestMonitor<MIInfo>(ImmediateExecutor.getInstance(), rm)); } } else { rm.done(); } }
@Override protected void doExecute(IRegisters service, final DataRequestMonitor<IRegisterDMData> rm) { service.getRegisterData( fDmc, new DataRequestMonitor<IRegisterDMData>(ImmediateExecutor.getInstance(), rm) { @Override protected void handleSuccess() { /* * All good set return value. */ rm.setData(getData()); rm.done(); } }); }
/** Specify the executable file to be debugged and read the symbol table. */ @Execute public void stepSetExecutable(RequestMonitor rm) { boolean noFileCommand = CDebugUtils.getAttribute( fAttributes, IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_USE_SOLIB_SYMBOLS_FOR_APP, IGDBLaunchConfigurationConstants.DEBUGGER_USE_SOLIB_SYMBOLS_FOR_APP_DEFAULT); if (!noFileCommand && fBinaryName != null && fBinaryName.length() > 0) { fCommandControl.queueCommand( fCommandFactory.createMIFileExecAndSymbols(getContainerContext(), fBinaryName), new DataRequestMonitor<MIInfo>(ImmediateExecutor.getInstance(), rm)); } else { rm.done(); } }
@Override protected void doExecute(IRegisters service, final DataRequestMonitor<Object> rm) { // Write the bit field using the mnemonic style. service.writeBitField( fDmc, fMnemonic, new DataRequestMonitor<IBitFieldDMData>(ImmediateExecutor.getInstance(), rm) { @Override protected void handleSuccess() { /* * All good set return value. */ rm.setData(new Object()); rm.done(); } }); }
@Override protected void doExecute(IRegisters service, final DataRequestMonitor<String> rm) { /* * Convert to the proper formatting DMC then go get the formatted * value. */ FormattedValueDMContext formDmc = service.getFormattedValueContext(fDmc, fFormatId); service.getFormattedExpressionValue( formDmc, new DataRequestMonitor<FormattedValueDMData>(ImmediateExecutor.getInstance(), rm) { @Override protected void handleSuccess() { /* * All good set return value. */ rm.setData(getData().getFormattedValue()); rm.done(); } }); }
public Object[] getElements(Object inputElement) { // Create the query object for reading data count. Query<Integer> countQuery = new Query<Integer>() { @Override protected void execute(DataRequestMonitor<Integer> rm) { fDataGenerator.getCount(rm); } }; // Submit the query to be executed. A query implements a runnable // interface and it has to be executed in order to do its work. ImmediateExecutor.getInstance().execute(countQuery); int count = 0; // Block until the query completes, which will happen when the request // monitor of the execute() method is marked done. try { count = countQuery.get(); } catch (Exception e) { // InterruptedException and ExecutionException can be thrown here. // ExecutionException containing a CoreException will be thrown // if an error status is set to the Query's request monitor. return new Object[0]; } final int finalCount = count; Query<List<Integer>> valueQuery = new Query<List<Integer>>() { @Override protected void execute(final DataRequestMonitor<List<Integer>> rm) { final Integer[] retVal = new Integer[finalCount]; final CountingRequestMonitor crm = new CountingRequestMonitor(ImmediateExecutor.getInstance(), rm) { @Override protected void handleSuccess() { rm.setData(Arrays.asList(retVal)); rm.done(); }; }; for (int i = 0; i < finalCount; i++) { final int finalI = i; fDataGenerator.getValue( i, new DataRequestMonitor<Integer>(ImmediateExecutor.getInstance(), crm) { @Override protected void handleSuccess() { retVal[finalI] = getData(); crm.done(); } }); } crm.setDoneCount(finalCount); } }; ImmediateExecutor.getInstance().execute(valueQuery); try { return valueQuery.get().toArray(new Integer[0]); } catch (Exception e) { } return new Object[0]; }
@Override protected void updatePropertiesInSessionThread(IPropertiesUpdate[] updates) { IPropertiesUpdate[] parentUpdates = new IPropertiesUpdate[updates.length]; for (int i = 0; i < updates.length; i++) { final IPropertiesUpdate update = updates[i]; final ViewerCountingRequestMonitor countringRm = new ViewerCountingRequestMonitor(ImmediateExecutor.getInstance(), updates[i]); int count = 0; // Create a delegating update which will let the super-class fill in the // standard container properties. parentUpdates[i] = new VMDelegatingPropertiesUpdate(updates[i], countringRm); count++; IMIExecutionDMContext execDmc = findDmcInPath( update.getViewerInput(), update.getElementPath(), IMIExecutionDMContext.class); if (execDmc != null) { update.setProperty(ILaunchVMConstants.PROP_ID, Integer.toString(execDmc.getThreadId())); // set pin properties IPinElementColorDescriptor colorDesc = PinCloneUtils.getPinElementColorDescriptor(GdbPinProvider.getPinnedHandles(), execDmc); updates[i].setProperty( IGdbLaunchVMConstants.PROP_PIN_COLOR, colorDesc != null ? colorDesc.getOverlayColor() : null); updates[i].setProperty( IGdbLaunchVMConstants.PROP_PINNED_CONTEXT, PinCloneUtils.isPinnedTo(GdbPinProvider.getPinnedHandles(), execDmc)); } if (update.getProperties().contains(PROP_NAME) || update.getProperties().contains(IGdbLaunchVMConstants.PROP_OS_ID) || update.getProperties().contains(IGdbLaunchVMConstants.PROP_CORES_ID)) { IProcesses processService = getServicesTracker().getService(IProcesses.class); final IThreadDMContext threadDmc = findDmcInPath(update.getViewerInput(), update.getElementPath(), IThreadDMContext.class); if (processService == null || threadDmc == null) { update.setStatus( new Status( IStatus.ERROR, GdbUIPlugin.PLUGIN_ID, "Service or handle invalid", null)); //$NON-NLS-1$ } else { processService.getExecutionData( threadDmc, new ViewerDataRequestMonitor<IThreadDMData>(getExecutor(), update) { @Override public void handleCompleted() { if (isSuccess()) { fillThreadDataProperties(update, getData()); } update.setStatus(getStatus()); countringRm.done(); } }); count++; } } countringRm.setDoneCount(count); } super.updatePropertiesInSessionThread(parentUpdates); }