コード例 #1
0
ファイル: Module.py プロジェクト: BackupTheBerlios/pplt-svn
    def __init__(self, parameters = None):
        """ This is the constructor. The parameter "parameters" specifies the
            parameter for the sprcific module. These can be used to setup the
            module correctly. This class contains a CConnectionDatabase 
            instance as the _d_conenctions attribute. Please use it to manage
            your conenctions! Else if you don't want to use it or if you can't
            please override the is_busy() method also! This method returns 
            True if there are connections to the specific module. """
        CObject.__init__(self)
        
        if None == parameters:
            parameters = {}

        self._d_module_lock = threading.Lock()
        self._d_module_parameters = parameters
        self._d_connections = CConnectionDatabase()

        self._d_logger = logging.getLogger("PPLT.core")
コード例 #2
0
ファイル: Module.py プロジェクト: BackupTheBerlios/pplt-svn
class CModule (CObject):
    """ This is the baseclass for all module classes. This class imeplements
        the basic needs for a module. Ie Locking. This locking is used to 
        ensure that only child accesses a module simultaneously. The methods
        reserve() and release() where never be called directly by the child
        insteat they call the reserve and release methods of the connection
        instance. Note: A module have to implement the connect() and 
        disconnect() methods."""

    _d_module_lock = None
    _d_module_parameters = None
    _d_connections = None


    def __init__(self, parameters = None):
        """ This is the constructor. The parameter "parameters" specifies the
            parameter for the sprcific module. These can be used to setup the
            module correctly. This class contains a CConnectionDatabase 
            instance as the _d_conenctions attribute. Please use it to manage
            your conenctions! Else if you don't want to use it or if you can't
            please override the is_busy() method also! This method returns 
            True if there are connections to the specific module. 
            
            @param parameters: This optional parameter will contain all the 
                parameters needed to setup a module.
            @type parameters: dict  """
        CObject.__init__(self)
        
        if None == parameters:
            parameters = {}

        self._d_module_lock = threading.Lock()
        self._d_module_parameters = parameters
        self._d_connections = CConnectionDatabase()

        self._d_logger = logging.getLogger("PPLT.core")


    
    def __del__(self):
        if self.is_busy():
            self._d_logger.warning("Destruction of module %s but is_busy() == True"%_fmtid(self.identifier()))
        CObject.__del__(self)



    def reserve(self):
        """ This method will be used by the connection objects to reserve 
            (lock) this module. Normaly this method doesn't need to be 
            overridden, a module doesn't need to know if it is reserved or 
            not.""" 
        self._d_module_lock.acquire()



    def release(self):
        """ This method releases the module. This method will be called by the
            connection object retuned from the connect() method of the module
            implementation. """
        self._d_module_lock.release()



    def connect(self, address, child=None):
        """ This method have to be overridden by the module implementation. 
            This method tooks the address and the optional child module and
            should return a connection instance of the proper type. 
            For example a CStreamConnection instance if the module handles
            streams. 
            
            @param address: This parameters specifies the address the 
                connection will established with. This parameter can be used 
                to determ the type of the connection and what the child 
                expects.
            @type address: string
            @param child: This optional parameter specifies the child (source)
                of the connetion. This instance will be called to handle 
                events. Therefore it have to implement the IDisposable
                interface.
            @type child: Any derived from IDisposable """
        raise NotImplemented("The method connect() have to be implemented!");



    def disconnect(self, con_id):
        """ This method have to be overridden to implement the diconnect 
            method. The parameter conid specifies the identifier of the 
            connection instance. This one can be obtained by calling the
            indentifier() method of the connection instance (all connections
            have one).
            
            @param con_id: This parameters specifies the identifier of the 
                connection to be closed. 
            @type con_id: string """
        raise NotImplemented("The method disconnect() have to be implemented!");



    def is_busy(self):
        """ This method returns True if there are connections left to the module.
            This method uses the module internal ConnectionDatabase insatance
            to determ if there are connection left. If a module implementation
            doesn't use this db to strore and manage the connection this method
            have to be overridden! """
        return 0 != self._d_connections.count();