Windows: workaround for eject() not being called on the device thread

This commit is contained in:
Kovid Goyal 2012-09-01 15:06:53 +05:30
parent 9a110fb0d5
commit d278180bde
2 changed files with 20 additions and 7 deletions

View File

@ -314,6 +314,9 @@ class DevicePlugin(Plugin):
''' '''
Un-mount / eject the device from the OS. This does not check if there Un-mount / eject the device from the OS. This does not check if there
are pending GUI jobs that need to communicate with the device. are pending GUI jobs that need to communicate with the device.
NOTE: That this method may not be called on the same thread as the rest
of the device methods.
''' '''
raise NotImplementedError() raise NotImplementedError()

View File

@ -51,6 +51,7 @@ class MTP_DEVICE(MTPDeviceBase):
self._main_id = self._carda_id = self._cardb_id = None self._main_id = self._carda_id = self._cardb_id = None
self.start_thread = None self.start_thread = None
self._filesystem_cache = None self._filesystem_cache = None
self.eject_dev_on_next_scan = False
def startup(self): def startup(self):
self.start_thread = threading.current_thread() self.start_thread = threading.current_thread()
@ -75,6 +76,10 @@ class MTP_DEVICE(MTPDeviceBase):
@same_thread @same_thread
def detect_managed_devices(self, devices_on_system, force_refresh=False): def detect_managed_devices(self, devices_on_system, force_refresh=False):
if self.wpd is None: return None if self.wpd is None: return None
if self.eject_dev_on_next_scan:
self.eject_dev_on_next_scan = False
if self.currently_connected_pnp_id is not None:
self.do_eject()
devices_on_system = frozenset(devices_on_system) devices_on_system = frozenset(devices_on_system)
if (force_refresh or if (force_refresh or
@ -213,19 +218,24 @@ class MTP_DEVICE(MTPDeviceBase):
return self._filesystem_cache return self._filesystem_cache
@same_thread @same_thread
def post_yank_cleanup(self): def do_eject(self):
self.currently_connected_pnp_id = self.current_friendly_name = None
self._main_id = self._carda_id = self._cardb_id = None
self.dev = self._filesystem_cache = None
@same_thread
def eject(self):
if self.currently_connected_pnp_id is None: return if self.currently_connected_pnp_id is None: return
self.ejected_devices.add(self.currently_connected_pnp_id) self.ejected_devices.add(self.currently_connected_pnp_id)
self.currently_connected_pnp_id = self.current_friendly_name = None self.currently_connected_pnp_id = self.current_friendly_name = None
self._main_id = self._carda_id = self._cardb_id = None self._main_id = self._carda_id = self._cardb_id = None
self.dev = self._filesystem_cache = None self.dev = self._filesystem_cache = None
@same_thread
def post_yank_cleanup(self):
self.currently_connected_pnp_id = self.current_friendly_name = None
self._main_id = self._carda_id = self._cardb_id = None
self.dev = self._filesystem_cache = None
def eject(self):
if self.currently_connected_pnp_id is None: return
self.eject_dev_on_next_scan = True
@same_thread @same_thread
def open(self, connected_device, library_uuid): def open(self, connected_device, library_uuid):
self.dev = self._filesystem_cache = None self.dev = self._filesystem_cache = None