Пример #1
0
    def run(self):
        """Activate the manager.
        
        This method starts the player adapter, runs a main loop (GLib) and
        blocks until SIGINT or SIGTERM arrives or until stop() gets called. If
        this happens the player adapter gets stopped and this method returns.
        
        If `player_dbus_name` or `poll_fn` has been passed to __init__(), then
        the player adapter does not get started until the player is running
        (according to checks based on the DBus name or poll function). Also the
        adapter gets stopped automatically if the player is not running
        anymore. However, the manager keeps running, i.e. the player adapter
        may get started and stopped multiple times while this method is
        running.
        
        """
        if self.__observer is None:  # start pa directly
            ready = _start_pa(self.__pa)
        else:  # observer will start pa
            ready = True

        if ready and not self.__stopped:  # not stopped since creation
            log.info("start main loop")
            try:
                self.__ml.run()
            except Exception, e:
                log.exception("** BUG ** %s", e)
            else:
                log.info("main loop stopped")
Пример #2
0
 def run(self):
     """Activate the manager.
     
     This method starts the player adapter, runs a main loop (GLib) and
     blocks until SIGINT or SIGTERM arrives or until stop() gets called. If
     this happens the player adapter gets stopped and this method returns.
     
     If `player_dbus_name` or `poll_fn` has been passed to __init__(), then
     the player adapter does not get started until the player is running
     (according to checks based on the DBus name or poll function). Also the
     adapter gets stopped automatically if the player is not running
     anymore. However, the manager keeps running, i.e. the player adapter
     may get started and stopped multiple times while this method is
     running.
     
     """
     if self.__observer is None: # start pa directly
         ready = _start_pa(self.__pa)
     else: # observer will start pa
         ready = True
         
     if ready and not self.__stopped: # not stopped since creation 
         log.info("start main loop")
         try:
             self.__ml.run()
         except Exception, e:
             log.exception("** BUG ** %s", e)
         else:
             log.info("main loop stopped")
Пример #3
0
 def run(self):
     """Activate the manager.
     
     This method starts the player adapter, runs a main loop (GLib) and
     blocks until SIGINT or SIGTERM arrives or until stop() gets called. If
     this happens the player adapter gets stopped and this method returns.
     
     @note: If the keyword 'player_dbus_name' has been set in __init__(),
         then the player adapter does not get started until an application
         owns the bus name given by 'player_dbus_name'. It automatically
         gets started whenever the DBus name has an owner (which means the
         adapter's player is running) and it gets stopped when it has no
         owner. Obvisously here the player adapter may get started and
         stopped repeatedly while this method is running.
     
     """
     if self.__observer is None: # start pa directly
         ready = _start_pa(self.__pa)
     else: # observer will start pa
         ready = True
         
     if ready and not self.__stopped: # not stopped since creation 
         
         log.info("start main loop")
         try:
             self.__ml.run()
         except Exception, e:
             log.exception("** BUG ** %s", e)
         log.info("main loop stopped")
Пример #4
0
def _stop_pa(pa):
    """Stop the given player adapter with error handling."""
    
    log.info("stop player adapter")
    try:
        pa.stop()
    except Exception, e:
        log.exception("** BUG ** %s", e)
Пример #5
0
def _stop_pa(pa):
    """Stop the given player adapter with error handling."""

    log.info("stop player adapter")
    try:
        pa.stop()
    except Exception, e:
        log.exception("** BUG ** %s", e)
Пример #6
0
def _start_pa(pa):
    """Start the given player adapter with error handling."""
    
    log.info("start player adapter")
    try:
        pa.start()
    except StandardError as e:
        log.error("failed to start player adapter (%s)" % e)
        return False
    except Exception as e:
        log.exception("** BUG ** %s", e)
        return False
    else:
        log.info("player adapter started")
        return True
Пример #7
0
# =============================================================================
# start stop functions
# =============================================================================

def _start_pa(pa):
    """Start the given player adapter with error handling."""
    
    log.info("start player adapter")
    try:
        pa.start()
    except StandardError, e:
        log.error("failed to start player adapter (%s)" % e)
        return False
    except Exception, e:
        log.exception("** BUG ** %s", e)
        return False
    else:
        log.info("player adapter started")
        return True

def _stop_pa(pa):
    """Stop the given player adapter with error handling."""
    
    log.info("stop player adapter")
    try:
        pa.stop()
    except Exception, e:
        log.exception("** BUG ** %s", e)
    else:
        log.info("player adapter stopped")
Пример #8
0
# =============================================================================
# start stop functions
# =============================================================================


def _start_pa(pa):
    """Start the given player adapter with error handling."""

    log.info("start player adapter")
    try:
        pa.start()
    except StandardError, e:
        log.error("failed to start player adapter (%s)" % e)
        return False
    except Exception, e:
        log.exception("** BUG ** %s", e)
        return False
    else:
        log.info("player adapter started")
        return True


def _stop_pa(pa):
    """Stop the given player adapter with error handling."""

    log.info("stop player adapter")
    try:
        pa.stop()
    except Exception, e:
        log.exception("** BUG ** %s", e)
    else:
Пример #9
0
def pack(serializable):

    fmt = serializable.get_fmt()
    
    data = serializable.get_data()
    
    if len(fmt) != len(data):
        log.error("** BUG ** format string and data differ in length")
        return None
        
    #log.debug("data to pack: %s" % str(data))

    bin = Bin()
    
    try:

        for i in range(0,len(fmt)):
            
            type = fmt[i]
            bin.write_byte(type)
            
            if type == TYPE_Y:
                
                bin.write_byte(data[i])
                
            elif type == TYPE_B:
                
                bin.write_boolean(data[i])
        
            elif type == TYPE_N:
                
                bin.write_short(data[i])
                
            elif type == TYPE_I:
                
                bin.write_int(data[i])
                
            elif type == TYPE_L:
                
                bin.write_long(data[i])
                
            elif type == TYPE_S:
                
                bin.write_string(data[i])
                
            elif type == TYPE_AB:
                
                bin.write_array_boolean(data[i])
                
            elif type == TYPE_AY:
                
                bin.write_array_byte(data[i])
                
            elif type == TYPE_AN:
                
                bin.write_array_short(data[i])

            elif type == TYPE_AI:
                
                bin.write_array_int(data[i])

            elif type == TYPE_AL:
                
                bin.write_array_long(data[i])

            elif type == TYPE_AS:
                
                bin.write_array_string(data[i])

            else:
                log.error("** BUG ** unknown type (%d) in format string" % type)
                return None
        
    except struct.error as e:
        
        log.exception("** BUG ** %s" % e)
        
        return None
    
    return bin.get_buff()
Пример #10
0
def pack(serializable):

    fmt = serializable.get_fmt()

    data = serializable.get_data()

    if len(fmt) != len(data):
        log.error("** BUG ** format string and data differ in length")
        return None

    #log.debug("data to pack: %s" % str(data))

    bin = Bin()

    try:

        for i in range(0, len(fmt)):

            type = fmt[i]

            bin.write_byte(type)

            if type == TYPE_Y:

                bin.write_byte(data[i])

            elif type == TYPE_B:

                bin.write_boolean(data[i])

            elif type == TYPE_N:

                bin.write_short(data[i])

            elif type == TYPE_I:

                bin.write_int(data[i])

            elif type == TYPE_L:

                bin.write_long(data[i])

            elif type == TYPE_S:

                bin.write_string(data[i])

            elif type == TYPE_AB:

                bin.write_array_boolean(data[i])

            elif type == TYPE_AY:

                bin.write_array_byte(data[i])

            elif type == TYPE_AN:

                bin.write_array_short(data[i])

            elif type == TYPE_AI:

                bin.write_array_int(data[i])

            elif type == TYPE_AL:

                bin.write_array_long(data[i])

            elif type == TYPE_AS:

                bin.write_array_string(data[i])

            else:
                log.error("** BUG ** unknown type (%d) in format string" %
                          type)
                return None

    except struct.error, e:

        log.exception("** BUG ** %s" % e)

        return None