Changeset 1724

Show
Ignore:
Timestamp:
11/22/09 12:55:51 (14 years ago)
Author:
arnonym
Message:

Introduce a Control::Boolean for simple switches. To be used in the SaffirePro?24 first, but maybe others will follow? Using this instead of Control::Enum saves code.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/libcontrol/BasicElements.h

    r1158 r1724  
    154154    virtual std::string getAttributeName(int attridx) = 0; 
    155155}; 
     156/*! 
     157@brief Base class for basic boolean control elements 
     158*/ 
     159class Boolean 
     160: public Element 
     161{ 
     162public: 
     163    Boolean(Element *p) : Element(p) {}; 
     164    Boolean(Element *p, std::string n) : Element(p, n) {}; 
     165    virtual ~Boolean() {}; 
     166 
     167    virtual bool select(bool) = 0; 
     168    virtual bool selected() = 0; 
     169    virtual std::string getBooleanLabel(bool n) { 
     170        if (n) return "True"; 
     171        return "False"; 
     172    } 
     173}; 
    156174 
    157175}; // namespace Control 
  • trunk/libffado/support/dbus/control-interface.xml

    r1655 r1724  
    303303  </interface> 
    304304 
     305  <interface name="org.ffado.Control.Element.Boolean"> 
     306      <method name="select"> 
     307          <arg type="b" name="value" direction="in"/> 
     308          <arg type="b" name="success" direction="out"/> 
     309      </method> 
     310      <method name="selected"> 
     311          <arg type="b" name="value" direction="out"/> 
     312      </method> 
     313      <method name="getBooleanLabel"> 
     314          <arg type="b" name="value" direction="in"/> 
     315          <arg type="s" name="label" direction="out"/> 
     316      </method> 
     317  </interface> 
    305318</node> 
  • trunk/libffado/support/dbus/controlserver.cpp

    r1655 r1724  
    410410        } 
    411411         
     412        if (dynamic_cast<Control::Boolean *>(&e) != NULL) { 
     413            debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Boolean\n"); 
     414             
     415            return new Boolean(conn(), std::string(path()+"/"+e.getName()), 
     416                parent, *dynamic_cast<Control::Boolean *>(&e)); 
     417        } 
     418         
    412419        if (dynamic_cast<ConfigRom *>(&e) != NULL) { 
    413420            debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a ConfigRom\n"); 
     
    10091016} 
    10101017 
     1018// --- Boolean 
     1019 
     1020Boolean::Boolean( DBus::Connection& connection, std::string p, Element* parent, Control::Boolean &slave) 
     1021: Element(connection, p, parent, slave) 
     1022, m_Slave(slave) 
     1023{ 
     1024    debugOutput( DEBUG_LEVEL_VERBOSE, "Created Boolean on '%s'\n", 
     1025                 path().c_str() ); 
     1026} 
     1027 
     1028DBus::Bool 
     1029Boolean::select( const DBus::Bool& value ) 
     1030{ 
     1031    debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "select(%d)\n", value ); 
     1032    return  m_Slave.select(value); 
     1033} 
     1034 
     1035DBus::Bool 
     1036Boolean::selected() 
     1037{ 
     1038    bool retval = m_Slave.selected(); 
     1039    debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "selected() => %d\n", retval ); 
     1040    return retval; 
     1041} 
     1042 
     1043DBus::String 
     1044Boolean::getBooleanLabel( const DBus::Bool& value ) 
     1045{ 
     1046    std::string retval = m_Slave.getBooleanLabel(value); 
     1047    debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "getBooleanLabel(%d) => %s\n", value, retval.c_str() ); 
     1048    return retval; 
     1049} 
     1050 
    10111051 
    10121052} // end of namespace Control 
  • trunk/libffado/support/dbus/controlserver.h

    r1655 r1724  
    367367}; 
    368368 
     369class Boolean 
     370: public org::ffado::Control::Element::Boolean 
     371, public Element 
     372{ 
     373public: 
     374    Boolean( DBus::Connection& connection, 
     375          std::string p, Element *, 
     376          Control::Boolean &slave ); 
     377     
     378    DBus::Bool select( const DBus::Bool& value ); 
     379    DBus::Bool selected(); 
     380    DBus::String getBooleanLabel( const DBus::Bool& value ); 
     381 
     382private: 
     383    Control::Boolean &m_Slave; 
     384}; 
    369385} 
    370386