Skip to content

Commit

Permalink
Merged with latest 0.9.5 branch changes, including the fix to cancel …
Browse files Browse the repository at this point in the history
…an ongoing RLE-capture properly.
  • Loading branch information
jawi committed Dec 7, 2011
2 parents 7569d9b + 6d8326f commit 774a1de
Show file tree
Hide file tree
Showing 15 changed files with 380 additions and 162 deletions.
15 changes: 10 additions & 5 deletions api/src/main/java/nl/lxtreme/ols/api/DataAcquisitionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ public interface DataAcquisitionService
/**
* Signals that the current acquisition should be cancelled.
*
* @param aDevice
* the device from which data should be acquired, cannot be
* <code>null</code>;
* @throws IOException
* in case of I/O problems during the acquisition of data;
* @throws IllegalStateException
* in case no acquisition is in progress.
*/
public void cancelAcquisition() throws IllegalStateException;
public void cancelAcquisition( Device aDevice ) throws IOException, IllegalStateException;

/**
* Returns whether or not this device controller is acquiring data.
Expand All @@ -53,13 +58,13 @@ public interface DataAcquisitionService
/**
* Acquires data from the given device.
*
* @param aDeviceController
* the device controller from which data should be acquired, cannot
* be <code>null</code>;
* @param aDevice
* the device from which data should be acquired, cannot be
* <code>null</code>;
* @throws IOException
* in case of I/O problems during the acquisition of data;
* @throws IllegalArgumentException
* in case the given device was <code>null</code>.
*/
void acquireData( Device aDeviceController ) throws IOException;
void acquireData( Device aDevice ) throws IOException;
}
28 changes: 5 additions & 23 deletions api/src/main/java/nl/lxtreme/ols/api/devices/AcquisitionTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,17 @@
package nl.lxtreme.ols.api.devices;


import java.io.*;
import nl.lxtreme.ols.api.acquisition.*;
import nl.lxtreme.ols.api.task.*;


/**
* Denotes a device that we can talk to by calling {@link #call()} on it. The
* implementation of that method should do all necessary tasks to acquire data
* from the device and return that data in the form of an
* Denotes an acquisition task that we can talk to by calling {@link #call()} on
* it. The implementation of that method should do all necessary tasks to
* acquire data from the device and return that data in the form of an
* {@link AcquisitionResult} object.
*/
public interface AcquisitionTask extends Task<AcquisitionResult>, Closeable
public interface AcquisitionTask extends Task<AcquisitionResult>
{
// METHODS

/**
* Closes the device.
*
* @throws IOException
* in case of I/O problems closing the device.
*/
void close() throws IOException;

/**
* Opens the device for acquisition.
*
* @throws IOException
* in case of I/O problems closing the device.
*/
void open() throws IOException;

// No additional methods
}
36 changes: 36 additions & 0 deletions api/src/main/java/nl/lxtreme/ols/api/devices/CancelTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* OpenBench LogicSniffer / SUMP project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
*
* Copyright (C) 2006-2010 Michael Poppitz, www.sump.org
* Copyright (C) 2010 J.W. Janssen, www.lxtreme.nl
*/
package nl.lxtreme.ols.api.devices;


import nl.lxtreme.ols.api.task.*;


/**
* Denotes a task that talk to by calling {@link #call()} on it. The
* implementation of that method should cause the device to stop acquiring data,
* if possible. If the device already finished its acquisition task, this task
* should not lead to unpredictable results.
*/
public interface CancelTask extends Task<Void>
{
// No additional methods
}
15 changes: 14 additions & 1 deletion api/src/main/java/nl/lxtreme/ols/api/devices/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* Interface for implementing device controllers. Each supported device must
* implement at least this interface.
*/
public interface Device
public interface Device extends Closeable
{
// METHODS

Expand All @@ -40,12 +40,25 @@ public interface Device
* @param aProgressListener
* the acquisition progress listener the acquisition task can use to
* report its progress, cannot be <code>null</code>.
* @return a new acquisition task, never <code>null</code>.
* @throws IOException
* in case of I/O problems during the creation of the acquisition
* task.
*/
public AcquisitionTask createAcquisitionTask( AcquisitionProgressListener aProgressListener ) throws IOException;

/**
* Creates a new {@link CancelTask} for canceling the current acquisition from
* the device, if the device needs something special to do this.
*
* @return a new cancel task, if <code>null</code> the running acquisition is
* simply cancelled.
* @throws IOException
* in case of I/O problems during the creating of the cancellation
* task.
*/
public CancelTask createCancelTask() throws IOException;

/**
* Returns a descriptive name of this device controller.
*
Expand Down
28 changes: 25 additions & 3 deletions client/src/main/java/nl/lxtreme/ols/client/ClientController.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,34 @@ public void addTool( final Tool<?> aTool )
public void cancelCapture()
{
final DataAcquisitionService acquisitionService = getDataAcquisitionService();
if ( acquisitionService != null )
final Device device = getDevice();
if ( ( device == null ) || ( acquisitionService == null ) )
{
acquisitionService.cancelAcquisition();
return;
}

updateActionsOnEDT();
try
{
acquisitionService.cancelAcquisition( device );
}
catch ( final IllegalStateException exception )
{
setStatusOnEDT( "No acquisition in progress!" );
}
catch ( final IOException exception )
{
setStatusOnEDT( "I/O problem: " + exception.getMessage() );

// Make sure to handle IO-interrupted exceptions properly!
if ( !HostUtils.handleInterruptedException( exception ) )
{
exception.printStackTrace();
}
}
finally
{
updateActionsOnEDT();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.awt.*;
import java.io.*;

import nl.lxtreme.ols.api.acquisition.*;
import nl.lxtreme.ols.api.devices.*;

Expand All @@ -48,11 +49,31 @@ public class GenericDevice implements Device
* {@inheritDoc}
*/
@Override
public AcquisitionTask createAcquisitionTask( final AcquisitionProgressListener aProgressListener ) throws IOException
public void close() throws IOException
{
// No-op...
}

/**
* {@inheritDoc}
*/
@Override
public AcquisitionTask createAcquisitionTask( final AcquisitionProgressListener aProgressListener )
throws IOException
{
return new GenericDeviceAcquisitionTask( this.deviceConfig, aProgressListener );
}

/**
* {@inheritDoc}
*/
@Override
public CancelTask createCancelTask() throws IOException
{
// Nothing special is needed...
return null;
}

/**
* @see nl.lxtreme.ols.api.devices.Device#getName()
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public AcquisitionResult call() throws IOException
final int[] values = new int[count];
final long[] timestamps = new long[count];

this.inputStream = new FileInputStream( this.deviceConfig.getDevicePath() );

try
{
int idx = 0;
Expand All @@ -109,24 +111,10 @@ public AcquisitionResult call() throws IOException
// Rethrow the caught exception...
throw exception;
}
}

/**
* {@inheritDoc}
*/
@Override
public void close() throws IOException
{
HostUtils.closeResource( this.inputStream );
}

/**
* {@inheritDoc}
*/
@Override
public void open() throws IOException
{
this.inputStream = new FileInputStream( this.deviceConfig.getDevicePath() );
finally
{
HostUtils.closeResource( this.inputStream );
}
}

/**
Expand Down
Loading

0 comments on commit 774a1de

Please sign in to comment.