pcisim.lib.datafield
index
../../src/pcisim/lib/datafield.py

A module which implements a generic container for a bitfield.

 
Classes
       
__builtin__.object
DataField
pcisim.lib.MyException(exceptions.Exception)
DataFieldOverflow

 
class DataField(__builtin__.object)
    A bitfield container with name, bits, value and description.
 
@ATTRIBS
    (str) name : symbolic name for the field
    (int) bits : number of bits of the field
    (int) value : internal value of the field
    (str) hint : field description or None
 
In order to handle field value, the following interfaces are available:
    - self.value : retrieve the current field value
    - self.set : set field value making size checks and notify
        changed value to callbacks.
    - self.value = x : set field value directly (*not recommended*)
 
It is possible to add callbacks to be executed on value change. This
remarks provider-subscriber programming pattern.
 
Field values can be limited using *slots*. Slots can be classified in
category groups and, optionally, a *filter* field can be used to query
current category.
See 'add_slot*' and 'set_filter' methods for more details.
 
@NOTES
    - A readonly field cannot be modified
    - Value is actually changed only if different from current one
 
  Methods defined here:
__init__(self, bits, name='', value=0, hint=None, ro=False)
__str__(self)
Shows field name, bits and hex value.
add_callback(self, callback)
Add a function listener for field value change.
 
@PARAMS
    callback : callback to call on change.
add_slot(self, slotlb, slotval, cat=0)
Adds a slot to the field slots.
 
@PARAMS
    (str) slotlb : label associated the slot
    (int) slotval : value associated to the slot
    cat : optional slot category
 
@NOTES
    Default category code is 0x0
add_slots(self, slots_l, cat=0)
Adds multiple slots at once, using same category.
 
@PARAMS
    (list)(list[2]) : slots list of slot_label, slot_value
    cat : optional slots category
 
@NOTES
    Default category code is 0x0
can_hold(self, value)
Performs checks on value to ensure it fits field bit size.
 
@PARAMS
    (uint) value to check
 
@RETURN
    | FITS OK : True
    | DON'T FIT : False
clean_slots(self)
Removes all slots and filter from the field
get_bin(self)
Get binary representation as a string.
get_hex(self)
Get hexadecimal representation as a string.
get_slot_name(self, slotval)
Find a slot in current category by value.
 
@PARAMS
    (int) slotval : slot value to search
 
@RETURN
    | SUCCESS : (str) slot name
    | FAILURE : (None)
get_slots(self)
Get the field slots. If a filter is being set, use it to extract
only the slots having the filtered category.
 
@RETURN
    (list)(list[2]) : slots list of slot_label, slot_value
has_category(self, cat)
Query field slots and look for specified category.
 
@PARAMS
    cat : slots category group name.
 
@RETURN
    | HAS CATEGORY : True
    | HAS NOT CATEGORY : False
has_highlight(self)
Get field selection state.
 
@RETURN
    | HAS HIGHLIGHT : True
    | HAS NOT HIGHLIGHT : False
has_slots(self)
Query about field slots.
 
@RETURN
    | HAS SLOTS : True
    | HAS NOT SLOTS : False
highlight(self, highlight=True)
Sets field selection state.
 
@PARAMS
    (bool) highlight : higlight state, True if active.
 
@NOTES
    This function sends callbacks notification.
is_readonly(self)
Returns readonly boolean state
notify(self, exclude=[])
This function is called to notify to the callbacks that field
value id changed.
 
@PARAMS
    | (list) exclude : optional list of callbacks to exclude
    | (func) exclude : single callback to exclude
rand(self)
Fills field with a random value, in respect to field bit size and
optional slots.
rem_callback(self, callback)
Removes the function from internal callbacks or does nothing.
 
@PARAMS
    callback : function to remove
 
@NOTES
    It is safe to call this function for an unsubscribed callback.
set(self, value, notify=True)
Set field value after performing size checks.
 
@PARAMS
    (int | long) value : value to set
    notify : if True, send value changes notifications to callbacks
 
@NOTES
    This function sends callbacks notification.
 
@RAISES
    DataFieldOverflow on field value overflow.
set_filter(self, field)
Adds a filter field for category filtering.
 
@PARAMS
    (DataField) field : field used as a filter
set_readonly(self, readonly)
Set readonly status.
 
@PARAMS
    (bool) readonly : if True, field modifications are locked
set_slot(self, sloti)
Sets the active slot for the current category.
 
@PARAMS
    (int) sloti : index in slot category of the setting slot.
 
@NOTES
    Internal value is changed and changes are notified.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class DataFieldOverflow(pcisim.lib.MyException)
    Occurrs when a value does not fit bit size.
 
@ATTRIBS
    (DataField) field : field where overflow occurred.
    (int) value : value which caused the overflow.
 
 
Method resolution order:
DataFieldOverflow
pcisim.lib.MyException
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, field, value)
@PARAMS
    (DataField) field : field where overflow occurred.
    (int) value : value which caused the overflow.
__str__(self)

Data descriptors inherited from pcisim.lib.MyException:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
Data
        __all__ = ['DataField', 'DataFieldOverflow']