Changeset 182 in pacpusframework


Ignore:
Timestamp:
Oct 23, 2013, 9:09:51 AM (11 years ago)
Author:
Marek Kurdej
Message:

Fixed: dependencies in InputOutputBase, ConnectionBase.

Location:
trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/Pacpus/kernel/ComponentBase.h

    r181 r182  
    2424
    2525#include <Pacpus/kernel/ComponentManager.h>
     26#include <Pacpus/kernel/InputOutputBase.h>
    2627#include <Pacpus/kernel/pacpus.h>
    2728#include <Pacpus/kernel/XmlComponentConfig.h>
    28 #include <Pacpus/kernel/InputOutputBase.h>
    2929
    3030#include <QString>
  • trunk/include/Pacpus/kernel/ConnectionBase.h

    r153 r182  
    1111{
    1212public:
    13     ConnectionBase(AbstractInterface * interface, int priority)
    14         : m_interface(interface)
    15         , m_priority(priority)
    16     {}
     13    ConnectionBase(AbstractInterface * anInterface, int priority);
     14    virtual ~ConnectionBase();
    1715
    18     ~ConnectionBase()
    19     {}
    20 
    21     AbstractInterface *  getInterface() const
    22     {
    23         return m_interface;
    24     }
    25 
    26     int getPriority() const
    27     {
    28         return m_priority;
    29     }
    30 
    31     bool operator==(ConnectionBase const &c)
    32     {
    33         return getInterface() == c.getInterface()
    34             && getPriority() == c.getPriority()
    35             ;
    36     }
     16    AbstractInterface *  getInterface() const;
     17    int getPriority() const;
     18    bool operator==(ConnectionBase const & c);
    3719
    3820private:
  • trunk/include/Pacpus/kernel/InputOutputBase.h

    r159 r182  
    22#define IN_OUT_BASE_H
    33
     4#include <Pacpus/kernel/ConnectionBase.h>
    45#include <Pacpus/kernel/Log.h>
    56#include <Pacpus/kernel/pacpus.h>
    6 #include <Pacpus/kernel/ConnectionBase.h>
    77#include <Pacpus/kernel/PacpusEvent.h>
    88
     
    2323
    2424protected:
    25     AbstractInterface(QString name, ComponentBase * component, QObject * parent = 0)
    26         : m_name(name)
    27         , m_component(component)
    28         , QObject(parent)
    29     {
    30         LOG_DEBUG("constructing abstract connection '" << getName() << "'");
    31     }
    32 
    33     ~AbstractInterface()
    34     {}
     25    AbstractInterface(QString name, ComponentBase * component, QObject * parent = 0);
     26    virtual ~AbstractInterface();
    3527
    3628public:
    37     QString getSignature();
    38     QString getName()
    39     {
    40         return m_name;
    41     }
    42    
     29    QString getSignature() const;
     30    QString getName() const;
    4331    virtual QString getDataType() = 0;
    4432   
    45     ComponentBase * getComponent()
    46     {
    47         return m_component;
    48     }
    49 
    50     void addConnection(ConnectionBase connection)
    51     {
    52         m_connections.append(connection);
    53     }
    54 
    55     bool removeConnection(ConnectionBase connection)
    56     {
    57         return m_connections.removeOne(connection);
    58     }
    59 
    60     bool hasConnection()
    61     {
    62         return m_connections.size() > 0;
    63     }
     33    void addConnection(ConnectionBase connection);
     34    bool removeConnection(ConnectionBase connection);
     35    bool hasConnection();
    6436   
    6537protected:
    66     QList<ConnectionBase> & connections()
    67     {
    68         return m_connections;
    69     }
     38    QList<ConnectionBase> & connections();
     39    const QList<ConnectionBase> & getConnections() const;
    7040
    71     const QList<ConnectionBase> & connections() const
    72     {
    73         return m_connections;
    74     }
    75 
    76     QString name()
    77     {
    78         return m_name;
    79     }
    80 
    81     ComponentBase * component()
    82     {
    83         return m_component;
    84     }
    85 
    86     const ComponentBase * component() const
    87     {
    88         return m_component;
    89     }
     41    ComponentBase * component();
     42    const ComponentBase * getComponent() const;
    9043   
    9144private:
     
    10154
    10255protected:
    103     InputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0)
    104         : AbstractInterface(name, component, parent)
    105     {}
     56    // TODO: add ctor with function pointer
     57    InputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0);
    10658
    10759public:
    108     //InputInterfaceBase(QString name, ComponentBase * component,int a, QObject * parent = 0):AbstractInterface(name,component,parent) {} // TODO add ctor with function pointer
    109 
    11060    enum ReadingMode {
    11161        NeverSkip,
     
    11464    };
    11565
    116     virtual ~InputInterfaceBase()
    117     {}
     66    virtual ~InputInterfaceBase();
    11867
    119     // TODO for serealization prupose (not yet implemented !!!)
    120     virtual void customEvent(QEvent* e)
    121     {
    122         //if(event->type())
    123         //TODO get event Type anf call callback function
     68    virtual void customEvent(QEvent* e);
    12469
    125         PacpusEvent * event = dynamic_cast<PacpusEvent *>(e);
    126         QByteArray buf;
    127         QDataStream out(&buf, QIODevice::WriteOnly);
    128         event->streamOut(out);
    129         // Callback QByteArray
    130     }
     70    ReadingMode & readingMode();
     71    const ReadingMode & readingMode() const;
     72    void setReadingMode(ReadingMode mode);
    13173
    132     ReadingMode & readingMode()
    133     {
    134         return m_readingMode;
    135     }
    136 
    137     const ReadingMode & readingMode() const
    138     {
    139         return m_readingMode;
    140     }
    141 
    142     void setReadingMode(ReadingMode mode)
    143     {
    144         m_readingMode = mode;
    145     }
    146 
    147     virtual PacpusEvent* getEventTemplate()
    148     {
    149         // TODO: check
    150         return new PacpusEvent(GENERIC_EVENT);
    151     }
     74    virtual PacpusEvent * getEventTemplate();
    15275   
    15376private:
     
    17194    {}
    17295
    173     QStringList getInputConnectedList()
    174     {
    175         QStringList list;
    176         for(QList<ConnectionBase>::iterator it = connections().begin(); it != connections().end(); ++it) {
    177             list.append(it->getInterface()->getName());
    178         }
    179         return list;
    180     }
     96    QStringList getInputConnectedList();
    18197
    182     // TODO for serealization prupose (not yet implemented !!!)
    183     void send(/*const*/ QByteArray & data)
    184     {
    185         // TODO check at least one Typed connection
    186 
    187         for(QList<ConnectionBase>::iterator it = connections().begin(); it!=connections().end(); ++it){
    188                 QDataStream in(&data,QIODevice::ReadOnly);
    189                 PacpusEvent* event = dynamic_cast<InputInterfaceBase*>(connections().at(0).getInterface())->getEventTemplate();
    190                 event->streamIn(in);
    191                 QApplication::postEvent(it->getInterface(),event,it->getPriority());
    192         }
    193     }
    194 
     98    // TODO for serialization prupose (not yet implemented !!!)
     99    void send(/*const*/ QByteArray & data);
    195100};
    196101
    197 static bool connectInterface(OutputInterfaceBase* out, InputInterfaceBase * in, int priority, InputInterfaceBase::ReadingMode mode = InputInterfaceBase::GetLast)
     102namespace {
     103
     104bool connectInterface(OutputInterfaceBase * out, InputInterfaceBase * in, int priority, InputInterfaceBase::ReadingMode mode = InputInterfaceBase::GetLast);
     105
     106bool connectInterface(OutputInterfaceBase * out, InputInterfaceBase * in, int priority, InputInterfaceBase::ReadingMode mode)
    198107{
    199     if(out->getDataType() == in->getDataType() || out->getDataType() == QString(typeid(QByteArray).name()) || in->getDataType() == QString(typeid(QByteArray).name())) {
     108    if (out->getDataType() == in->getDataType() || out->getDataType() == QString(typeid(QByteArray).name()) || in->getDataType() == QString(typeid(QByteArray).name())) {
    200109        // Add connection
    201         out->addConnection(ConnectionBase(in,priority));  // TODO make connect function
    202         in->addConnection(ConnectionBase(out,priority));
     110        out->addConnection(ConnectionBase(in, priority));  // TODO make connect function
     111        in->addConnection(ConnectionBase(out, priority));
    203112        in->setReadingMode(mode);
    204113        //LOG_INFO("connection : Output " << out->getSignature() << " => Input " << in->getSignature());
     
    210119}
    211120
     121} // namespace
     122
    212123} // namespace pacpus
    213124
  • trunk/include/Pacpus/kernel/InputOutputInterface.h

    r159 r182  
    4242    {
    4343        // TODO check component state started
    44         //if(_component) get state
     44        //if (_component) get state
    4545        switch (event->type()) {
    4646        case TYPED_EVENT:
  • trunk/src/PacpusLib/CMakeLists.txt

    r156 r182  
    7171
    7272set(PROJECT_SRCS
    73     ./ComponentBase.cpp
    74     ./ComponentFactoryBase.cpp
    75     ./ComponentManager.cpp
    76     ./Log.cpp
    77     ./PacpusApplication.cpp
    78     ./PacpusException.cpp
    79     ./XmlComponentConfig.cpp
    80     ./XmlConfigFile.cpp
    81     ./InputOutputBase.cpp
    82  #   ./PacpusStruct.cpp
     73    ComponentBase.cpp
     74    ComponentFactoryBase.cpp
     75    ComponentManager.cpp
     76    ConnectionBase.cpp
     77    InputOutputBase.cpp
     78    Log.cpp
     79    PacpusApplication.cpp
     80    PacpusException.cpp
     81 #   PacpusStruct.cpp
     82    XmlComponentConfig.cpp
     83    XmlConfigFile.cpp
    8384)
    8485
  • trunk/src/PacpusLib/ComponentBase.cpp

    r181 r182  
    66
    77#include <Pacpus/kernel/ComponentBase.h>
     8
    89#include <Pacpus/kernel/ComponentManager.h>
    910#include <Pacpus/kernel/Log.h>
     
    2021using namespace std;
    2122
    22 std::vector<std::string> convertAttributesToArgumentVector(const QDomNamedNodeMap & attributes);
    23 void logVariablesMap(boost::program_options::variables_map vm);
     23vector<string> convertAttributesToArgumentVector(const QDomNamedNodeMap & attributes);
     24void logVariablesMap(po::variables_map vm);
    2425
    2526DECLARE_STATIC_LOGGER("pacpus.core.ComponentBase");
    2627
    27 ComponentBase::ComponentBase(const QString& componentName)
    28   : m_componentName(componentName)
    29   , m_isActive(false)
    30   , mIsRecording(true)
    31   , m_manager(NULL)
    32   , m_ui(NULL)
    33   , m_componentState(NOT_MONITORED)
    34   , mOptionsDescription("Component parameters")
     28ComponentBase::ComponentBase(const QString & componentName)
     29    : m_componentName(componentName)
     30    , m_isActive(false)
     31    , mIsRecording(true)
     32    , m_manager(NULL)
     33    , m_ui(NULL)
     34    , m_componentState(NOT_MONITORED)
     35    , mOptionsDescription("Component parameters")
    3536{
    3637    LOG_TRACE("constructor");
     
    172173{
    173174/*    QList<QString> keys = output.keys();
    174     for(int i=0; i<keys.size();++i)
     175    for (int i=0; i<keys.size();++i)
    175176        LOG_INFO("Key : " << keys[i])*/;
    176177
  • trunk/src/PacpusLib/ComponentManager.cpp

    r176 r182  
    1010#include <Pacpus/kernel/ComponentBase.h>
    1111#include <Pacpus/kernel/ConnectionBase.h>
     12#include <Pacpus/kernel/InputOutputBase.h>
    1213#include <Pacpus/kernel/Log.h>
     14#include <QDomNodeList>
    1315#include <QObject>
    14 #include <QDomNodeList>
    15 
     16
     17using namespace pacpus;
    1618using namespace pacpus;
    1719
     
    186188    QStringList input  = inputSignature.split(".");
    187189
    188     if(getComponent(output[0])==NULL) {
     190    if (getComponent(output[0])==NULL) {
    189191        LOG_WARN("cannot make connection : component " << output[0] << " not found");
    190192        return false;}
    191     if(getComponent(output[0])->getOutput(output[1]) == NULL) {
     193    if (getComponent(output[0])->getOutput(output[1]) == NULL) {
    192194        LOG_WARN("cannot make connection : component " << output[0] << " doesn't have output " << output[1]);
    193195        return false;}
    194     if(getComponent(input[0])==NULL) {
     196    if (getComponent(input[0])==NULL) {
    195197        LOG_WARN("cannot make connection : component " << input[0] << " not found");
    196198        return false;}
    197     if(getComponent(input[0])->getInput(input[1]) == NULL) {
     199    if (getComponent(input[0])->getInput(input[1]) == NULL) {
    198200        LOG_WARN("cannot make connection : component " << input[0] << " doesn't have intput " << input[1]);
    199201        return false;}
    200202
    201203    // NOTE Create communicationInterface if needed ??
    202 
    203     return connectInterface(getComponent(output[0])->getOutput(output[1]), getComponent(input[0])->getInput(input[1]), priority);
     204    return connectInterface(
     205        getComponent(output[0])->getOutput(output[1]),
     206        getComponent(input[0])->getInput(input[1]),
     207        priority
     208    );
    204209
    205210}
  • trunk/src/PacpusLib/InputOutputBase.cpp

    r148 r182  
     1#include <Pacpus/kernel/InputOutputBase.h>
     2
    13#include <Pacpus/kernel/ComponentBase.h>
     4#include <Pacpus/kernel/ConnectionBase.h>
     5#define CONNECT_INTERFACE_EXPORTS
    26#include <Pacpus/kernel/InputOutputInterface.h>
     7#undef CONNECT_INTERFACE_EXPORTS
    38#include <Pacpus/kernel/Log.h>
    49
     
    712DECLARE_STATIC_LOGGER("pacpus.core.InputOutputInterface");
    813
    9 QString AbstractInterface::getSignature()
     14////////////////////////////////////////////////////////////////////////////////
     15
     16AbstractInterface::AbstractInterface(QString name, ComponentBase * component, QObject * parent)
     17    : m_name(name)
     18    , m_component(component)
     19    , QObject(parent)
    1020{
    11     return component()->getName() + '.' + name();
     21    LOG_DEBUG("constructing abstract connection '" << getName() << "'");
    1222}
     23
     24AbstractInterface::~AbstractInterface()
     25{}
     26
     27QString AbstractInterface::getSignature() const
     28{
     29    return getComponent()->getName() + '.' + getName();
     30}
     31
     32QString AbstractInterface::getName() const
     33{
     34    return m_name;
     35}
     36
     37QList<ConnectionBase> & AbstractInterface::connections()
     38{
     39    return m_connections;
     40}
     41
     42const QList<ConnectionBase> & AbstractInterface::getConnections() const
     43{
     44    return m_connections;
     45}
     46
     47ComponentBase * AbstractInterface::component()
     48{
     49    return m_component;
     50}
     51
     52const ComponentBase * AbstractInterface::getComponent() const
     53{
     54    return m_component;
     55}
     56
     57void AbstractInterface::addConnection(ConnectionBase connection)
     58{
     59    m_connections.append(connection);
     60}
     61
     62bool AbstractInterface::removeConnection(ConnectionBase connection)
     63{
     64    return m_connections.removeOne(connection);
     65}
     66
     67bool AbstractInterface::hasConnection()
     68{
     69    return m_connections.size() > 0;
     70}
     71
     72////////////////////////////////////////////////////////////////////////////////
     73
     74InputInterfaceBase::InputInterfaceBase(QString name, ComponentBase * component, QObject * parent)
     75    : AbstractInterface(name, component, parent)
     76{}
     77
     78InputInterfaceBase::~InputInterfaceBase()
     79{}
     80
     81// TODO for serialization prupose (not yet implemented !!!)
     82void InputInterfaceBase::customEvent(QEvent* e)
     83{
     84    //if (event->type())
     85    //TODO get event Type anf call callback function
     86
     87    PacpusEvent * event = dynamic_cast<PacpusEvent *>(e);
     88    QByteArray buf;
     89    QDataStream out(&buf, QIODevice::WriteOnly);
     90    event->streamOut(out);
     91    // Callback QByteArray
     92}
     93
     94InputInterfaceBase::ReadingMode & InputInterfaceBase::readingMode()
     95{
     96    return m_readingMode;
     97}
     98
     99const InputInterfaceBase::ReadingMode & InputInterfaceBase::readingMode() const
     100{
     101    return m_readingMode;
     102}
     103
     104void InputInterfaceBase::setReadingMode(ReadingMode mode)
     105{
     106    m_readingMode = mode;
     107}
     108
     109PacpusEvent * InputInterfaceBase::getEventTemplate()
     110{
     111    // TODO: check
     112    return new PacpusEvent(GENERIC_EVENT);
     113}
     114
     115////////////////////////////////////////////////////////////////////////////////
     116
     117QStringList OutputInterfaceBase::getInputConnectedList()
     118{
     119    QStringList list;
     120    for (QList<ConnectionBase>::iterator it = connections().begin(); it != connections().end(); ++it) {
     121        list.append(it->getInterface()->getName());
     122    }
     123    return list;
     124}
     125
     126// TODO for serialization prupose (not yet implemented !!!)
     127void OutputInterfaceBase::send(/*const*/ QByteArray & data)
     128{
     129    // TODO check at least one Typed connection
     130
     131    for (QList<ConnectionBase>::iterator it = connections().begin(); it!=connections().end(); ++it) {
     132            QDataStream in(&data,QIODevice::ReadOnly);
     133            PacpusEvent * event = dynamic_cast<InputInterfaceBase*>(connections().at(0).getInterface())->getEventTemplate();
     134            event->streamIn(in);
     135            QApplication::postEvent(it->getInterface(),event,it->getPriority());
     136    }
     137}
Note: See TracChangeset for help on using the changeset viewer.