diff --git a/src/libprs500/device.py b/src/libprs500/device.py index fe06b9a1c1..aead319c3d 100644 --- a/src/libprs500/device.py +++ b/src/libprs500/device.py @@ -12,13 +12,15 @@ ## 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. - """ Define the minimum interface that a device backend must satisfy to be used in the GUI. A device backend must subclass the L{Device} class. See prs500.py for a backend that implement the Device interface for the SONY PRS500 Reader. """ +import threading +from functools import wraps + class Device(object): """ Defines the interface that should be implemented by backends that @@ -111,5 +113,21 @@ class Device(object): @param booklists: A tuple containing the result of calls to (L{books}(oncard=False), L{books}(oncard=True)). """ - raise NotImplementedError() + raise NotImplementedError() + +def _safe(func): + @wraps(func) + def run_in_thread(*args, **kwargs): + dm = args[0] + dm + +class DeviceManager(object): + + def __init__(self, device): + if not isinstance(device, Device): + raise TypeError, '%s must implement the Device interface' % (str(device),) + self.dev = device + self.lock = threading.RLock() + + diff --git a/src/libprs500/prs500.py b/src/libprs500/prs500.py index f5e6ec678b..5ac690cb7f 100755 --- a/src/libprs500/prs500.py +++ b/src/libprs500/prs500.py @@ -46,9 +46,7 @@ Contains the logic for communication with the device (a SONY PRS-500). The public interface of class L{PRS500} defines the methods for performing various tasks. """ -import sys -import os -import time +import sys, os from tempfile import TemporaryFile from array import array from functools import wraps