Changeset 206 in pacpusframework for trunk/src/PacpusLib/ComponentManager.cpp


Ignore:
Timestamp:
Oct 30, 2013, 12:26:34 PM (11 years ago)
Author:
Marek Kurdej
Message:

Major: cleaned connection interfaces.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/PacpusLib/ComponentManager.cpp

    r204 r206  
    2222using namespace pacpus;
    2323
     24//template <typename _Elem, typename _Traits, typename _ListElem>
     25//std::basic_ostream<_Elem, _Traits> & operator<<(std::basic_ostream<_Elem, _Traits> & os, const QList<_ListElem> & list)
     26//{
     27//    typedef QList<_ListElem> ListType;
     28//    for (ListType::const_iterator it = list.cbegin(), itend = list.cend(); it != itend; ++it) {
     29//        os << *it << "\n";
     30//    }
     31//    return os;
     32//}
     33
    2434template <typename _Elem, typename _Traits, typename _ListElem>
    2535std::basic_ostream<_Elem, _Traits> & operator<<(std::basic_ostream<_Elem, _Traits> & os, const QList<_ListElem> & list)
     
    3646////////////////////////////////////////////////////////////////////////////////
    3747
     48/// Connects OutputInterfaceBase @b out to InputInterfaceBase @b in using given priority and reading mode.
     49/// @returns @b true if connection has been added successfully, @b false otherwise.
    3850bool connectInterface(OutputInterfaceBase * out, InputInterfaceBase * in, int priority, InputInterfaceBase::ReadingMode mode = InputInterfaceBase::GetLast);
    3951
     
    4254bool connectInterface(OutputInterfaceBase * out, InputInterfaceBase * in, int priority, InputInterfaceBase::ReadingMode mode)
    4355{
    44     if ((out->getDataType() == in->getDataType())
    45             || (out->getDataType() == typeid(QByteArray))
    46             || (in->getDataType() == typeid(QByteArray))) {
    47         // Add connection
    48         out->addConnection(ConnectionBase(in, priority));  // TODO make connect function
    49         in->addConnection(ConnectionBase(out, priority));
    50         in->setReadingMode(mode);
    51         //LOG_INFO("connection : Output " << out->getSignature() << " => Input " << in->getSignature());
    52         return true;
    53     } else {
    54         //LOG_WARN("connecting " << out->getSignature() << ":" << out->getDataType() << " to " << in->getSignature() << ":" << in->getDataType() << " failled : DataType incompatible " <<  QString(typeid(QByteArray).name()));
    55         return false;
    56     }
     56    // check connections
     57    if (!out || !in) {
     58        LOG_WARN("null connection");
     59        return false;
     60    }
     61
     62    // check if connection type are compatible
     63    // FIXME: it should permit an OutputType to be a type conversible to InputType
     64    if (out->getDataType() != in->getDataType()) {
     65        LOG_WARN("connection types do not match: "
     66            << out->getSignature() << "." << out->getDataType().name()
     67            << " -> "
     68            << in->getSignature() << "." << in->getDataType().name()
     69        );
     70        return false;
     71    }
     72    //if ((out->getDataType() == in->getDataType())
     73    //        || (out->getDataType() == typeid(QByteArray))
     74    //        || (in->getDataType() == typeid(QByteArray))) {
     75   
     76    // add connection
     77    out->addConnection(ConnectionBase(in, priority));  // TODO make connect function
     78    in->addConnection(ConnectionBase(out, priority));
     79    in->setReadingMode(mode);
     80    //LOG_INFO("connection : Output " << out->getSignature() << " => Input " << in->getSignature());
     81    return true;
    5782}
    5883
     
    145170    LOG_TRACE("registerComponent(name="<< name << ")");
    146171
    147     if (componentMap_.contains(name))
    148     {
     172    if (componentMap_.contains(name)) {
    149173        LOG_WARN("cannot register component '" << name << "'. A component with the same name exists already");
    150174        return false;
     
    235259}
    236260
    237 bool ComponentManager::createConnection(const QString& outputSignature, const QString& inputSignature, const QString& type, int priority = 0)
     261bool ComponentManager::createConnection(const QString & outputSignature, const QString & inputSignature, const QString & type, int priority = 0)
    238262{
    239263    // FIXME: use 2 signatures (output component + output connection) instead of 1 separated by a (".") dot
     
    247271        return false;
    248272    }
    249     // NOTE Create communicationInterface if needed ??
     273    // FIXME: Create communicationInterface if needed ??
    250274    return connectInterface(
    251275        getComponent(output[0])->getOutput(output[1]),
Note: See TracChangeset for help on using the changeset viewer.