Changeset 575

Show
Ignore:
Timestamp:
08/27/07 14:26:33 (14 years ago)
Author:
ppalmers
Message:

- Fixed bug in dbus c++ bindings
- First attempt at a decoupled control interface. [WIP]


The src/libcontrol/* elements are the ones that should be
subclassed to implement control elements on the FFADODevice
side.

The tests/controlserver.* files contain some code that
interfaces the DBus calls to these libcontrol elements. The
DBus classes allow for introspection and path discovery,
such that we don't have to care about that anymore.

In the end it should be fairly easy to write another 'backend'
to replace the current DBus one, e.g. to implement OSC support
or MIDI support. (Should we ever want that)

Note that there is no connection between ffado and dbus yet,
this code is merely to experiment with the Control/DBus infra-
structure. Once that is sort-of working, connecting ffado to
this infrastructure is a matter of subclassing the Control::*
classes, creating them on discovery and putting them into one
Container::* that is passed on to the DBus handlers.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/external/dbus/src/introspection.cpp

    r562 r575  
    115115        ObjectAdaptorPList::const_iterator oci; 
    116116 
     117        debug_log("nb children: %d", children.size()); 
    117118        for(oci = children.begin(); oci != children.end(); ++oci)  
    118119        { 
     120          
    119121                std::string name = (*oci)->path().substr(path.length()+1); 
    120                 name.substr(name.find('/')); 
    121  
     122                 
     123                std::string::size_type loc = name.find('/'); 
     124                if( loc != std::string::npos ) { 
     125                        name.substr(loc); 
     126                } 
     127                 
    122128                xml << "<node name=\"" << name << "\"/>"; 
    123129        } 
  • trunk/libffado/src/debugmodule/debugmodule.h

    r555 r575  
    2727 
    2828#include "../fbtypes.h" 
    29  
     29#include <assert.h> 
    3030 
    3131#include <vector> 
  • trunk/libffado/src/SConscript

    r573 r575  
    6868        libutil/TimeSource.cpp \ 
    6969        libutil/TimestampedBuffer.cpp \ 
     70        libcontrol/Element.cpp \ 
     71        libcontrol/BasicElements.cpp \ 
    7072' ) 
    7173 
  • trunk/libffado/tests/controlclient.cpp

    r574 r575  
    2525#include "controlclient.h" 
    2626 
    27 namespace Control { 
     27namespace DBusControl { 
    2828 
    29 IMPL_DEBUG_MODULE( ControlClient, ControlClient, DEBUG_LEVEL_VERBOSE ); 
     29// --- 
    3030 
    31 ControlClient::ControlClient( DBus::Connection& connection, const char* path, const char* name ) 
     31IMPL_DEBUG_MODULE( ContignousClient, ContignousClient, DEBUG_LEVEL_VERBOSE ); 
     32 
     33ContignousClient::ContignousClient( DBus::Connection& connection, const char* path, const char* name ) 
    3234: DBus::ObjectProxy(connection, path, name) 
    3335{ 
    34     debugOutput( DEBUG_LEVEL_VERBOSE, "Created ControlClient '%s' on '%s'\n", 
     36    debugOutput( DEBUG_LEVEL_VERBOSE, "Created ContignousClient '%s' on '%s'\n", 
    3537                 name, path ); 
    3638} 
  • trunk/libffado/tests/controlclient.h

    r574 r575  
    3232#include "controlclient-glue.h" 
    3333 
    34 static const char* SERVER_NAME = "org.ffado.Control.Test"; 
    35 static const char* SERVER_PATH = "/org/ffado/Control/Test"; 
     34static const char* SERVER_NAME = "org.ffado.Control"; 
     35static const char* SERVER_PATH = "/org/ffado/Control/Test/Fader"; 
    3636 
    37 namespace Control { 
     37namespace DBusControl { 
    3838 
    39 class ControlClient 
    40 : public org::ffado::Control::Test, 
     39// simple fader element 
     40class ContignousClient 
     41: public org::ffado::Control::Element::Fader, 
    4142  public DBus::IntrospectableProxy, 
    4243  public DBus::ObjectProxy 
     
    4445public: 
    4546 
    46     ControlClient( DBus::Connection& connection, const char* path, const char* name ); 
     47    ContignousClient( DBus::Connection& connection, const char* path, const char* name ); 
    4748 
    4849private: 
  • trunk/libffado/tests/controlserver.cpp

    r574 r575  
    2424 
    2525#include "controlserver.h" 
     26#include "libcontrol/Element.h" 
     27#include "libcontrol/BasicElements.h" 
    2628 
    27 namespace Control { 
     29namespace DBusControl { 
    2830 
    29 IMPL_DEBUG_MODULE( ControlServer, ControlServer, DEBUG_LEVEL_VERBOSE ); 
     31IMPL_DEBUG_MODULE( Element, Element, DEBUG_LEVEL_VERBOSE ); 
    3032 
    31 ControlServer::ControlServer( DBus::Connection& connection ) 
    32 : DBus::ObjectAdaptor(connection, SERVER_PATH) 
     33// --- Element 
     34Element::Element( DBus::Connection& connection, std::string p, Control::Element &slave) 
     35: DBus::ObjectAdaptor(connection, p) 
     36, m_Slave(slave) 
    3337{ 
    34     debugOutput( DEBUG_LEVEL_VERBOSE, "Created ControlServer on '%s'\n", 
    35                  SERVER_PATH ); 
     38    debugOutput( DEBUG_LEVEL_VERBOSE, "Created Element on '%s'\n", 
     39                 path().c_str() ); 
    3640} 
    3741 
    38 DBus::Int32 ControlServer::Echo( const DBus::Int32& value ) 
     42DBus::UInt64 
     43Element::getId( ) 
    3944{ 
    40     debugOutput( DEBUG_LEVEL_VERBOSE, "Echo(%d)\n", value ); 
    41     return value; 
     45    return m_Slave.getId(); 
    4246} 
    4347 
    44 std::map< DBus::String, DBus::String > ControlServer::Info() 
     48DBus::String 
     49Element::getName( ) 
    4550{ 
    46     debugOutput( DEBUG_LEVEL_VERBOSE, "Info()\n" ); 
    47      
    48     std::map< DBus::String, DBus::String > info; 
    49  
    50     info["testset1"] = "set1"; 
    51     info["testset2"] = "set2"; 
    52  
    53     return info; 
     51    return DBus::String(m_Slave.getName()); 
    5452} 
    5553 
     54// --- Container 
     55Container::Container( DBus::Connection& connection, std::string p, Control::Container &slave) 
     56: Element(connection, p, slave) 
     57, m_Slave(slave) 
     58{ 
     59    debugOutput( DEBUG_LEVEL_VERBOSE, "Created Container on '%s'\n", 
     60                 path().c_str() ); 
     61 
     62    // add children for the slave container 
     63    for ( Control::ConstElementVectorIterator it = slave.getElements().begin(); 
     64      it != slave.getElements().end(); 
     65      ++it ) 
     66    { 
     67        Element *e=createHandler(*(*it)); 
     68        if (e) { 
     69            m_Children.push_back(e); 
     70        } else { 
     71            debugWarning("Failed to create handler for Control::Element %s\n", 
     72                (*it)->getName().c_str()); 
     73        } 
     74    } 
     75} 
     76 
     77Container::~Container() { 
     78    for ( ElementVectorIterator it = m_Children.begin(); 
     79      it != m_Children.end(); 
     80      ++it ) 
     81    { 
     82        delete (*it); 
     83    } 
     84} 
     85 
     86/** 
     87 * \brief create a correct DBusControl counterpart for a given Control::Element 
     88 */ 
     89Element * 
     90Container::createHandler(Control::Element& e) { 
     91    debugOutput( DEBUG_LEVEL_VERBOSE, "Creating handler for '%s'\n", 
     92                 e.getName().c_str() ); 
     93                  
     94    if (dynamic_cast<Control::Container *>(&e) != NULL) { 
     95        debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Container\n"); 
     96         
     97        return new Container(conn(), std::string(path()+"/"+e.getName()),  
     98            *dynamic_cast<Control::Container *>(&e)); 
     99    } 
     100    if (dynamic_cast<Control::Contignous *>(&e) != NULL) { 
     101        debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Contignous\n"); 
     102         
     103        return new Contignous(conn(), std::string(path()+"/"+e.getName()), 
     104            *dynamic_cast<Control::Contignous *>(&e)); 
     105    } 
     106    debugOutput( DEBUG_LEVEL_VERBOSE, "Source is a Control::Element\n"); 
     107    return new Element(conn(), std::string(path()+"/"+e.getName()), e); 
     108} 
     109 
     110// --- Contignous 
     111 
     112Contignous::Contignous( DBus::Connection& connection, std::string p, Control::Contignous &slave) 
     113: Element(connection, p, slave) 
     114, m_Slave(slave) 
     115{ 
     116    debugOutput( DEBUG_LEVEL_VERBOSE, "Created Contignous on '%s'\n", 
     117                 path().c_str() ); 
     118} 
     119 
     120DBus::Double 
     121Contignous::setValue( const DBus::Double& value ) 
     122{ 
     123    m_Slave.setValue(value); 
     124    debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%lf) => %lf\n", value, m_Slave.getValue() ); 
     125     
     126    return m_Slave.getValue(); 
     127} 
     128 
     129DBus::Double 
     130Contignous::getValue(  ) 
     131{ 
     132    debugOutput( DEBUG_LEVEL_VERBOSE, "getValue() => %lf\n", m_Slave.getValue() ); 
     133    return m_Slave.getValue(); 
     134} 
    56135 
    57136} // end of namespace Control 
  • trunk/libffado/tests/controlserver.h

    r574 r575  
    3232#include "controlserver-glue.h" 
    3333 
    34 static const char* SERVER_NAME = "org.ffado.Control.Test"; 
    35 static const char* SERVER_PATH = "/org/ffado/Control/Test"; 
     34#include "libcontrol/BasicElements.h" 
    3635 
    37 namespace Control { 
     36namespace DBusControl { 
    3837 
    39 class Element { 
    40 public: 
    41     Element() {}; 
    42 }; 
    43  
    44 class ControlServer 
    45 : public org::ffado::Control::Test, 
    46   public DBus::IntrospectableAdaptor, 
    47   public DBus::ObjectAdaptor 
     38class Element 
     39: public org::ffado::Control::Element::Element 
     40, public DBus::IntrospectableAdaptor 
     41, public DBus::ObjectAdaptor 
    4842{ 
    4943public: 
    5044 
    51     ControlServer( DBus::Connection& connection ); 
    52      
    53     DBus::Int32 Echo( const DBus::Int32 & value ); 
    54     std::map< DBus::String, DBus::String > Info(); 
     45    Element( DBus::Connection& connection, 
     46             std::string p, 
     47             Control::Element &slave ); 
     48 
     49    DBus::UInt64 getId( ); 
     50    DBus::String getName( ); 
    5551 
    5652private: 
     53    Control::Element &m_Slave; 
     54 
     55protected: 
    5756    DECLARE_DEBUG_MODULE; 
     57}; 
     58typedef std::vector<Element *> ElementVector; 
     59typedef std::vector<Element *>::iterator ElementVectorIterator; 
     60typedef std::vector<Element *>::const_iterator ConstElementVectorIterator; 
     61 
     62class Container 
     63: public org::ffado::Control::Element::Container 
     64, public Element 
     65{ 
     66public: 
     67    Container( DBus::Connection& connection, 
     68                  std::string p, 
     69                  Control::Container &slave ); 
     70    virtual ~Container(); 
     71     
     72    Element *createHandler(Control::Element& e); 
     73private: 
     74    Control::Container &m_Slave; 
     75    ElementVector m_Children; 
     76}; 
     77 
     78class Contignous 
     79: public org::ffado::Control::Element::Fader 
     80, public Element 
     81{ 
     82public: 
     83    Contignous( DBus::Connection& connection, 
     84                  std::string p, 
     85                  Control::Contignous &slave ); 
     86     
     87    DBus::Double setValue( const DBus::Double & value ); 
     88    DBus::Double getValue( ); 
     89 
     90private: 
     91    Control::Contignous &m_Slave; 
    5892}; 
    5993 
  • trunk/libffado/tests/SConscript

    r574 r575  
    1515# 
    1616#for app in ["test-ffado", "test-extplugcmd", "test-fw410", "test-volume", "test-mixer", "test-cycletimer", "test-timestampedbuffer", "test-ieee1394service", "test-streamdump"]: 
     17 
    1718for app in ["test-ffado", "test-fw410", "test-cycletimer", "test-timestampedbuffer", "test-ieee1394service", "test-streamdump"]: 
    1819    env.Program( target=app, source = app+".cpp" ) 
  • trunk/libffado/tests/test-dbus-server.cpp

    r574 r575  
    9999} 
    100100 
     101static const char* SERVER_NAME = "org.ffado.Control"; 
     102 
    101103void start_server() { 
    102104 
     
    106108    DBus::Connection conn = DBus::Connection::SessionBus(); 
    107109    conn.request_name(SERVER_NAME); 
     110     
     111    Control::Contignous c0("test0"); 
     112    c0.setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
     113    DBusControl::Contignous fader(conn, "/org/ffado/Control/Test/Fader", c0); 
    108114 
    109     Control::ControlServer server(conn); 
     115    Control::Container cont("container1"); 
     116    cont.setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
     117     
     118    Control::Container cont1("container2"); 
     119    cont1.setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
     120     
     121    cont.addElement(&cont1); 
     122 
     123    Control::Contignous c1("test1"); 
     124    c1.setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
     125    cont.addElement(&c1); 
     126     
     127    Control::Contignous c2("test2"); 
     128    c2.setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
     129    cont.addElement(&c2); 
     130     
     131    Control::Contignous c3("test3"); 
     132    c3.setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
     133    cont.addElement(&c3); 
     134 
     135    Control::Contignous c4("test4"); 
     136    c4.setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
     137    cont1.addElement(&c4); 
     138 
     139    Control::Contignous c5("test5"); 
     140    c5.setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
     141    cont1.addElement(&c5); 
     142 
     143    // Note: create handlers AFTER all children are added 
     144 
     145    // we do dynamic allocation such that we are sure 
     146    // the container is deleted before the children become invalid 
     147    DBusControl::Container *container 
     148        = new DBusControl::Container(conn, "/org/ffado/Control/Test/Container", cont); 
    110149 
    111150    dispatcher.enter(); 
    112151 
     152    delete container; 
     153     
    113154} 
    114155 
  • trunk/libffado/tests/test-dbus.cpp

    r574 r575  
    107107    DBus::Connection conn = DBus::Connection::SessionBus(); 
    108108 
    109     Control::ControlClient client(conn, SERVER_PATH, SERVER_NAME); 
     109    DBusControl::ContignousClient client(conn, SERVER_PATH, SERVER_NAME); 
    110110 
    111111    int i=0; 
     
    113113    { 
    114114        try { 
    115             client.Echo(i++); 
     115            client.setValue(i++); 
    116116        } catch(...) { 
    117             cout << "error on Echo()\n"; 
     117            cout << "error on setValue()\n"; 
    118118        }; 
    119119//         try {