Module ThreadProxy :: Class AudioThreadProxy
[hide private]
[frames] | no frames]

Class AudioThreadProxy

source code

                object --+        
                         |        
        threading._Verbose --+    
                             |    
              threading.Thread --+
                                 |
AccessEngine.AEOutput.AEOutput --+
                                 |
                                AudioThreadProxy

Buffers calls to methods on a Devices.Audio device in a secondary thread and executes them some time later when that thread runs.

Instance Methods [hide private]
 
__init__(self, device)
Initializes the parent class and stores the device reference.
source code
 
init(self)
Called after the instance is created to start the device running.
source code
list of string
getCapabilities(self)
Gets the capabilities of the proxied device.
source code
 
loadStyles(self)
Called after the init method by the AccessEngine.AEDeviceManager to ensure that the device is functioning before time is spent unserializing its style data.
source code
 
saveStyles(self)
Persists styles to disk.
source code
 
setStyle(self, key, style)
Stores the style object under the given key.
source code
AEState
getStyle(self, key)
Gets the style object stored under the given key.
source code
list of AEOutput.Style
createDistinctStyles(self, num_groups, num_layers)
Creates up to the given number of styles for this device.
source code
AEOutput.Style
getDefaultStyle(self)
Creates up to the given number of styles for this device.
source code
 
close(self)
Stops the running thread.
source code
AudioThreadProxy
getProxy(self)
Returns this object as the proxy for itself because a thread proxying for another thread proxying for a device is not supported.
source code
string
getName(self)
Gives the user displayable (localized) name for this output device.
source code
object
send(self, name, value, style=None)
Buffers methods to call for known commands in the context of the thread.
source code
boolean
isActive(self)
Indicates whether the device is active (giving output) or not.
source code
3-tuple of lists of string, AEPor, AEOutput.Style
parseString(self, text, style, por, sem)
Parses the string using the implementation provided by the proxied device.
source code
 
_put(self, mtd, *args)
Buffers any non-stop command in the queue and returns immediately.
source code
 
run(self)
Runs the thread until alive is not longer True.
source code

Inherited from threading.Thread: __repr__, isAlive, isDaemon, join, setDaemon, setName, start

Inherited from threading.Thread (private): _set_daemon

Inherited from threading._Verbose (private): _note

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

Instance Variables [hide private]
boolean alive
Is the thread running or not?
Queue.Queue data_buffer
Buffer of commands to be sent to the output device
Devices.Audio device
Device on which to invoke send* methods
threading.Event init_event
Event used to block non-threaded calls to the device until the device has been initialized in the context of the running thread.
boolean just_stopped
Flag indicating that the last written command was a stop.
threading.Sempahore lock
Semaphore used to ensure no commands are buffered while the buffer is being reset after sending a stop
boolean want_stop
Flag indicating a stop is requested
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, device)
(Constructor)

source code 
Initializes the parent class and stores the device reference. Creates a queue that will buffer commands to the speech device. Creates flags used for indicating whether a stop is requested or has been requested recently. Creates a semaphore used to ensure that no commands can be added to the buffer while it is being reset by a stop command.
Parameters:
  • device (Devices.Audio) - The device reference to use for writing commands
Overrides: threading.Thread.__init__

init(self)

source code 
Called after the instance is created to start the device running. The device's init method is called in the context of the running thread's run method before the thread enters its loop.

getCapabilities(self)

source code 
Gets the capabilities of the proxied device. This method is called in the context of the caller, not the running thread.
Returns: list of string
List of capability names

loadStyles(self)

source code 

Called after the init method by the AccessEngine.AEDeviceManager to ensure that the device is functioning before time is spent unserializing its style data.

Calls the init method on the default style object and provides it with a reference to this initialized device. Then tries to load the persisted setting values from disk. If that fails, the AccessEngine.AEDeviceManager will try to call createDistinctStyles instead.

This method is called in the context of the caller, not the running thread. It blocks until the init_event is set indicating the device has been initialized in the second thread.
Raises:
  • KeyError - When styles have not previously been persisted for this device
  • OSError - When the profile file cannot be opened or read

saveStyles(self)

source code 
Persists styles to disk. Called after the close method by the AccessEngine.AEDeviceManager to ensure the device is properly shutdown before serializing its data. This method is called in the context of the caller, not the running thread.
Raises:
  • KeyError - When styles have not previously been persisted for this device
  • OSError - When the profile file cannot be opened or read

setStyle(self, key, style)

source code 
Stores the style object under the given key. The style object should be one previously generated by this device (e.g. using createDistinctStyles) but it is not an enforced requirement. Always makes the style clean before storing it. This method is called in the context of the caller, not the running thread.
Parameters:
  • key (immutable) - Any immutable object
  • style (AEState) - AEOutput subclass of AEState

getStyle(self, key)

source code 
Gets the style object stored under the given key. If the key is unknown, returns an empty flyweight backed by the default style and stores the new style. This method is called in the context of the caller, not the running thread.
Parameters:
  • key (immutable) - Any immutable object
Returns: AEState
AEOutput subclass of AEState

createDistinctStyles(self, num_groups, num_layers)

source code 
Creates up to the given number of styles for this device. This method is called in the context of the caller, not the running thread. It blocks until the init_event is set indicating the device has been initialized in the second thread.
Parameters:
  • num_groups (integer) - Number of sematic groups the requestor would like to represent using distinct styles
  • num_layers (integer) - Number of content origins (e.g. output originating from a background task versus the focus) the requestor would like to represent using distinct styles
Returns: list of AEOutput.Style
New styles

getDefaultStyle(self)

source code 
Creates up to the given number of styles for this device. This method is called in the context of the caller, not the running thread. It blocks until the init_event is set indicating the device has been initialized in the second thread.
Returns: AEOutput.Style
Default style

close(self)

source code 
Stops the running thread. Puts a null callable in the queue to wake the thread if it is sleeping.

getProxy(self)

source code 
Returns this object as the proxy for itself because a thread proxying for another thread proxying for a device is not supported.
Returns: AudioThreadProxy
self

getName(self)

source code 
Gives the user displayable (localized) name for this output device. Relevant version and device status should be included. This method is called in the context of the caller, not the running thread.
Returns: string
The localized name for the device
Overrides: threading.Thread.getName

send(self, name, value, style=None)

source code 
Buffers methods to call for known commands in the context of the thread.
Parameters:
  • name (object) - Descriptor of the data value sent
  • value (object) - Content value
  • style (AEOutput.Style) - Style with which this value should be output
Returns: object
Return value specific to the given command
Raises:
  • NotImplementedError - When not overridden in a subclass

isActive(self)

source code 
Indicates whether the device is active (giving output) or not.
Returns: boolean
True when content is buffered or the device is outputing
Raises:
  • NotImplementedError - When not overriden in a subclass

parseString(self, text, style, por, sem)

source code 
Parses the string using the implementation provided by the proxied device. This method is called in the context of the caller, not the running thread.
Parameters:
  • text (string) - Text to be parsed
  • style (AEOutput.Style) - Style object defining how the text should be parsed
  • por (AEPor) - Point of regard for the first character in the text, or None if the text is not associated with a POR
  • sem (integer) - Semantic tag for the text
Returns: 3-tuple of lists of string, AEPor, AEOutput.Style
Parsed words

_put(self, mtd, *args)

source code 
Buffers any non-stop command in the queue and returns immediately. Sets the want_stop flag for a stop command if neither want_stop nor just_stopped is set. Blocks on entry if the thread is busy clearing out the buffer in response to a previous stop command. Leaves the lock set if a new stop command is buffered. It will be unset when the command is processed.
Parameters:
  • mtd (callable) - Device method to call at a later time
  • args (list) - Additional positional arguments to be passed to the device when the method is invoked

run(self)

source code 
Runs the thread until alive is not longer True. Sleeps until methods and arguments to be applied are put in the data_buffer. Wakes up and invokes all buffered methods and arguments. Initializes the device before entering the loop and closes it after leaving the loop.
Overrides: threading.Thread.run

Instance Variable Details [hide private]

just_stopped

Flag indicating that the last written command was a stop. Used to avoid unnecessary stops
Type:
boolean