Changeset 110 in pacpusframework
- Timestamp:
- Jun 13, 2013, 1:43:39 PM (12 years ago)
- Location:
- branches/2.0-beta1
- Files:
-
- 1 deleted
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0-beta1/include/Pacpus/kernel/ComponentBase.h
r89 r110 29 29 #include <QString> 30 30 #include <QMap> 31 32 class QWidget; 31 33 32 34 namespace pacpus { … … 134 136 QMap<QString, OutputInterfaceBase *> output; 135 137 138 QWidget * ui; 139 136 140 private: 137 141 /// called by the ComponentManager to start the component -
branches/2.0-beta1/include/Pacpus/kernel/PacpusEvent.h
r98 r110 9 9 namespace pacpus { 10 10 11 // registerEventType // TODO 12 11 13 class GenericData { 12 14 public: 13 15 GenericData(char* data, size_t size) { 14 _data= (char*)malloc(size);15 memcpy( _data,data,size);16 data_ = (char*)malloc(size); 17 memcpy(data_,data,size); 16 18 _size = size;} 17 19 18 ~GenericData() {free( _data);}20 ~GenericData() {free(data_);} 19 21 20 char * data() { return _data;}22 char * data() { return data_;} 21 23 size_t size() {return _size;} 22 24 23 25 private: 24 char* _data;26 char* data_; 25 27 size_t _size; 26 28 }; … … 52 54 { 53 55 public: 54 PacpusTypedEvent(PacpusEventType type, T data = T(), road_time_t t = road_time(), road_timerange_t tr = 0 ):PacpusEvent(type, t, tr), _data(data) {}56 PacpusTypedEvent(PacpusEventType type, T data = T(), road_time_t t = road_time(), road_timerange_t tr = 0 ):PacpusEvent(type, t, tr),data_(data) {} 55 57 ~PacpusTypedEvent() {} 56 58 57 QDataStream& streamOut(QDataStream& out) {return out << (quint64)t_ << tr_ /*<< _data*/;} // FIXME Stream Data errors58 QDataStream& streamIn(QDataStream& in) {return in >> (quint64&)t_ >> tr_ /*>> _data*/;}59 QDataStream& streamOut(QDataStream& out) {return out << (quint64)t_ << tr_ /*<<data_*/;} // FIXME Stream Data errors 60 QDataStream& streamIn(QDataStream& in) {return in >> (quint64&)t_ >> tr_ /*>> data_*/;} 59 61 60 62 public: // TODO make protected 61 T _data;63 T data_; 62 64 }; 63 64 inline QDataStream& operator << (QDataStream& out, PacpusEvent& ev) {return ev.streamOut(out);}65 inline QDataStream& operator >> (QDataStream& in, PacpusEvent& ev) {return ev.streamIn(in);}66 65 67 66 class PACPUSLIB_API PacpusGenericEvent : public PacpusEvent … … 69 68 public: 70 69 PacpusGenericEvent(PacpusEventType type, char* data, size_t size):PacpusEvent(type) { 71 _data= (char*)malloc(size);72 memcpy( _data,data,size);70 data_ = (char*)malloc(size); 71 memcpy(data_,data,size); 73 72 _size = size; 74 73 75 74 } 76 virtual ~PacpusGenericEvent() {free( _data);}77 char* _data;75 virtual ~PacpusGenericEvent() {free(data_);} 76 char* data_; 78 77 size_t _size; 79 78 }; … … 82 81 } // namespace pacpus 83 82 83 inline QDataStream& operator << (QDataStream& out, pacpus::PacpusEvent& ev) {/*return ev.streamOut(out);*/ return out;} 84 inline QDataStream& operator >> (QDataStream& in, pacpus::PacpusEvent& ev) {/*return ev.streamIn(in);*/ return in;} 85 84 86 #endif // PACPUS_EVENT_H -
branches/2.0-beta1/include/Pacpus/kernel/inputOutputBase.h
r102 r110 60 60 //TODO get event Type anf call callback function 61 61 62 PacpusEvent * event = dynamic_cast<PacpusEvent *>(e); 62 63 QByteArray buf; 63 64 QDataStream out(&buf,QIODevice::WriteOnly); 64 out << e;65 event->streamOut(out); 65 66 // Callback QByteArray 66 67 } 67 68 68 69 void setReadingMode(ReadingMode mode) { readingMode_ = mode;} 69 virtual PacpusEvent getEventTemplate() {returnPacpusEvent(GENERIC_EVENT);} // TODO check ??70 virtual PacpusEvent* getEventTemplate() {return new PacpusEvent(GENERIC_EVENT);} // TODO check ?? 70 71 protected: 71 72 ReadingMode readingMode_; 73 private: 74 // metode(QByteArray) 75 76 //QQueue jobQueue_; 72 77 }; 73 78 … … 89 94 90 95 void send(/*const*/ QByteArray & data) { 96 // TODO check at least one Typed connection 91 97 92 // TODo getEvent 93 //PacpusEvent& event = _connection.at(0).getInterface()-> 94 QDataStream in(&data,QIODevice::ReadOnly); 95 //in >> event; 96 97 //for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it) 98 // QApplication::postEvent(it->getInterface(),&event,it->getPriority()); 98 for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it){ 99 QDataStream in(&data,QIODevice::ReadOnly); 100 PacpusEvent* event = dynamic_cast<InputInterfaceBase*>(_connection.at(0).getInterface())->getEventTemplate(); 101 event->streamIn(in); 102 QApplication::postEvent(it->getInterface(),event,it->getPriority()); 103 } 99 104 100 105 … … 103 108 }; 104 109 105 static bool connectInterface(OutputInterfaceBase* out, InputInterfaceBase * in, int priority )110 static bool connectInterface(OutputInterfaceBase* out, InputInterfaceBase * in, int priority, InputInterfaceBase::ReadingMode mode = InputInterfaceBase::GetLast) 106 111 { 107 112 if(out->getDataType() == in->getDataType() || out->getDataType() == QString(typeid(QByteArray).name()) || in->getDataType() == QString(typeid(QByteArray).name())) { … … 110 115 out->addConnection(ConnectionBase(in,priority)); // TODO make connect function 111 116 in->addConnection(ConnectionBase(out,priority)); 117 in->setReadingMode(mode); 112 118 //LOG_INFO("connection : Output " << out->getSignature() << " => Input " << in->getSignature()); 113 in->setReadingMode(InputInterfaceBase::NeverSkip);114 119 return true; 115 120 } else { -
branches/2.0-beta1/include/Pacpus/kernel/inputOutputInterface.h
r102 r110 4 4 #include <Pacpus/kernel/Log.h> 5 5 #include <Pacpus/kernel/inputOutputBase.h> 6 #include <QApplication> 7 #include <typeinfo> 6 8 7 #include <typeinfo>8 9 #include <QDebug> 9 #include <Q Application>10 #include <QThread> 10 11 11 12 #include <QByteArray> … … 13 14 #define ADD_INPUT(name,ComponentType, DataType, functionName) input.insert(name,new InputInterface<DataType,ComponentType> (name,this,&ComponentType::functionName)) 14 15 #define ADD_OUTPUT(name,ComponentType, DataType) output.insert(name,new OutputInterface<DataType,ComponentType> (name,this)) 16 15 17 #define GET_OUTPUT(name,ComponentType, DataType) dynamic_cast<OutputInterface<DataType,ComponentType> *> (output.value(name)) 18 #define GET_INPUT(name,ComponentType, DataType) dynamic_cast<InputInterface<DataType,ComponentType> *> (input.value(name)) 16 19 17 20 namespace pacpus { … … 26 29 QString getDataType() {return QString(typeid(T).name());} 27 30 28 protected: 29 int boundingTime_; 31 protected: 30 32 31 33 public: 32 34 33 PacpusEvent getEventTemplate() {returnPacpusTypedEvent<T>(TYPED_EVENT); }35 PacpusEvent* getEventTemplate() {return new PacpusTypedEvent<T>(TYPED_EVENT); } 34 36 35 37 void customEvent(QEvent* event) { … … 37 39 switch (event->type()) { 38 40 39 // from Component to Component (T->T) 40 case TYPED_EVENT: { 41 PacpusTypedEvent<T> * typedEvent = dynamic_cast<PacpusTypedEvent<T> *> (event); 42 //qDebug() << "E1 "; 43 //qDebug() << "recived 2 thread " << QThread::currentThread(); 44 if(typedEvent->tr_ == 0 && readingMode_ == TimeBounded) { 45 //LOG_WARN("Incorrect TimeRange (0), switch to NeverSkip"); 46 readingMode_ = NeverSkip;} 41 // from Component to Component (T->T) 42 case TYPED_EVENT: { 43 PacpusTypedEvent<T> * typedEvent = dynamic_cast<PacpusTypedEvent<T> *> (event); 47 44 48 switch (readingMode_){ 49 case TimeBounded: 50 qDebug() << "Input " << this->getSignature() << " Time bournded "<< road_time()- typedEvent->t_ << " " << typedEvent->tr_; 51 if(road_time() - typedEvent->t_> typedEvent->tr_) 52 { qDebug() << "Data skip " << this->getSignature(); 53 break;} 54 (dynamic_cast<C*>(_component)->*method)(typedEvent->_data); 55 break; 56 case GetLast: 57 qDebug() << "Input " << this->getSignature() << "GetLast "<< road_time() - typedEvent->t_ << " " << typedEvent->tr_; 58 (dynamic_cast<C*>(_component)->*method)(typedEvent->_data); 59 QCoreApplication::removePostedEvents(this,TYPED_EVENT); // delete all remining events 60 break; 61 case NeverSkip: 62 qDebug() << "Input " << this->getSignature() << "NeverSkip "<< road_time() - typedEvent->t_ << " " << typedEvent->tr_; 63 default: 64 (dynamic_cast<C*>(_component)->*method)(typedEvent->_data); 65 } 45 qDebug() << "Revever " << getSignature() << " thread " << QThread::currentThread() << " Data & " << & typedEvent->data_; 46 47 if(typedEvent->tr_ < 500 && readingMode_ == TimeBounded) { 48 //LOG_WARN("Incorrect TimeRange (0), switch to NeverSkip"); 49 qDebug() << "Incorrect TimeRange (0), switch to NeverSkip"; 50 readingMode_ = NeverSkip;} 51 52 switch (readingMode_){ 53 case TimeBounded: 54 qDebug() << "Input " << this->getSignature().leftJustified(20) << QString("Time bournded").leftJustified(15) << road_time()- typedEvent->t_ << "\t" << typedEvent->tr_; 55 56 if(road_time() - typedEvent->t_> typedEvent->tr_) 57 {qDebug() << "Data skip " << this->getSignature(); break;} 58 59 (dynamic_cast<C*>(_component)->*method)(typedEvent->data_); 66 60 break; 61 62 case GetLast: 63 qDebug() << "Input " << this->getSignature().leftJustified(20) << QString("GetLast").leftJustified(15) << road_time() - typedEvent->t_ << "\t" << typedEvent->tr_; 64 65 (dynamic_cast<C*>(_component)->*method)(typedEvent->data_); 66 QCoreApplication::removePostedEvents(this,TYPED_EVENT); // delete all remining events 67 break; 68 69 case NeverSkip: 70 qDebug() << "Input " << this->getSignature().leftJustified(20) << QString("NeverSkip").leftJustified(15) << road_time() - typedEvent->t_ << "\t" << typedEvent->tr_; 71 72 default: 73 (dynamic_cast<C*>(_component)->*method)(typedEvent->data_); 67 74 } 75 break; 76 } 68 77 69 70 /* case GENERIC_EVENT2: {78 // from Connection interface to Component (G->T) 79 /* case GENERIC_EVENT2: { 71 80 PacpusTypedEvent<QByteArray> * genericEvent = dynamic_cast<PacpusTypedEvent<QByteArray> *> (event); 72 81 T data; 73 QByteArray& buf = (QByteArray&) genericEvent-> _data;82 QByteArray& buf = (QByteArray&) genericEvent->data_; 74 83 QDataStream in(&buf,QIODevice::ReadOnly); 75 84 … … 81 90 case GENERIC_EVENT3: { 82 91 PacpusTypedEvent<T> * typedEvent = dynamic_cast<PacpusTypedEvent<T> *> (event); 83 (dynamic_cast<C*>(_component)->*method)(typedEvent-> _data); // copy 3 X92 (dynamic_cast<C*>(_component)->*method)(typedEvent->data_); // copy 3 X 84 93 85 94 break; 86 95 }*/ 87 96 88 97 default: 89 98 90 99 qDebug() << "Unknown event ID " << event->type(); 91 100 break; 92 101 } 102 event->accept(); 103 } 93 104 105 T& getData() { 106 T data; 107 // TODO ask output data; 94 108 109 //LOG4CXX_INFO(getLogger(), "Hello, World"); 110 111 return data; 95 112 } 96 113 97 114 protected: 98 115 void (C::*method)(const T&); 116 117 /* log4cxx::LoggerPtr& getLogger() { 118 static log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger( LOG4CXX_LOCATION.getClassName())); 119 return logger; 120 }*/ 99 121 100 122 }; … … 109 131 // Used by Components to send data througth typed output 110 132 void send(const T & data, road_time_t t = road_time(), road_timerange_t tr = 0) { 133 134 //QSharedPointer<T> sharedPointer = new T(data); 135 136 for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it){ 137 QApplication::postEvent(it->getInterface(),new PacpusTypedEvent<T>(TYPED_EVENT,data,t,tr),it->getPriority()); // Event is delete by the event loop handler 138 qDebug() << "sender " << it->getInterface()->getSignature() << " thread " << QThread::currentThread() << " Data & " << &data << " "; 139 // TODO DAta SHAred 140 } 141 } 142 143 /* void send(const T & data, road_time_t t = road_time(), road_timerange_t tr = 0) { 111 144 for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it){ 112 145 113 //if(it->getInterface()->getDataType() != QString(typeid(QByteArray).name()))146 if(it->getInterface()->getDataType() != QString(typeid(QByteArray).name())) 114 147 QApplication::postEvent(it->getInterface(),new PacpusTypedEvent<T>(TYPED_EVENT,data,t,tr),it->getPriority()); 115 /*else {148 else { 116 149 QByteArray buf; 117 150 QDataStream out(&buf,QIODevice::ReadWrite); 118 151 PacpusTypedEvent<QByteArray> * ev =new PacpusTypedEvent<QByteArray>(GENERIC_EVENT3,buf); 119 152 QApplication::postEvent(it->getInterface(),ev,it->getPriority()); // Copy 2 (ctor) 120 } */153 } 121 154 } 122 155 } 123 156 124 157 // Used by Connection Interfaces only to pose generic event 125 /*void sendGenericData(char * data, size_t size) {158 void sendGenericData(char * data, size_t size) { 126 159 QByteArray buf(data,size); // copy 5 127 160 for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it) -
branches/2.0-beta1/src/DBITEPlayer/CMakeLists.txt
r89 r110 32 32 ${CMAKE_BINARY_DIR}/DBITEPlayer 33 33 ${QT_INCLUDE_DIR} 34 ) 35 36 # ======================================== 37 # Link directories 38 # ======================================== 39 link_directories( 40 ${PROJECT_BINARY_DIR}/../PacpusLib 41 ${PROJECT_BINARY_DIR}/../FileLib 34 42 ) 35 43 … … 73 81 ${QT_LIBRARIES} 74 82 dbiteplayerlib 75 FileLib76 PacpusLib77 PacpusTools83 # FileLib 84 # PacpusLib 85 # PacpusTools 78 86 ) 79 87 # Windows -
branches/2.0-beta1/src/DBITEPlayerLib/CMakeLists.txt
r98 r110 33 33 ${CMAKE_BINARY_DIR}/DBITEPlayer 34 34 ${QT_INCLUDE_DIR} 35 ) 36 37 # ======================================== 38 # Link directories 39 # ======================================== 40 link_directories( 41 ${PROJECT_BINARY_DIR}/../PacpusLib 42 ${PROJECT_BINARY_DIR}/../FileLib 35 43 ) 36 44 … … 92 100 target_link_libraries( 93 101 ${PROJECT_NAME} 94 FileLib 95 PacpusTools 96 #optimized FileLib debug FileLib_d 97 #optimized PacpusTools debug PacpusTools_d 102 ${PACPUS_DEPENDENCIES_LIB} 103 #FileLib 104 #PacpusTools 105 optimized FileLib debug FileLib_d 106 optimized PacpusLib debug PacpusLib_d 98 107 ${QT_LIBRARIES} 99 108 ) -
branches/2.0-beta1/src/FileLib/CMakeLists.txt
r98 r110 52 52 target_link_libraries( 53 53 ${PROJECT_NAME} 54 #optimized PacpusLib debug PacpusLib_d 55 PacpusLib 54 ${PACPUS_DEPENDENCIES_LIB} 55 optimized PacpusLib debug PacpusLib_d 56 #PacpusLib 56 57 ) 57 58 endif() -
branches/2.0-beta1/src/PacpusLib/CMakeLists.txt
r99 r110 40 40 # ======================================== 41 41 link_directories( 42 ${PROJECT_BINARY_DIR}/../RoadTime 42 ${PROJECT_BINARY_DIR}/../RoadTime 43 ${PROJECT_BINARY_DIR}/../FileLib 43 44 ) 44 45 … … 73 74 ./XmlComponentConfig.cpp 74 75 ./XmlConfigFile.cpp 75 ./inputOutput Interface.cpp76 ./inputOutputBase.cpp 76 77 ) 77 78 … … 96 97 97 98 if(UNIX) 98 set(LIBS FileLib)#optimized FileLib debug FileLib_d) 99 #set(LIBS FileLib) 100 set(LIBS optimized FileLib debug FileLib_d) 99 101 else() 100 set(LIBS 102 set(LIBS 101 103 #optimized ROAD_TIME debug ROAD_TIME_d # TODO why debug not found ? 102 103 104 ROAD_TIME 105 ) 104 106 endif() 105 107 -
branches/2.0-beta1/src/PacpusLib/ComponentBase.cpp
r89 r110 20 20 , mgr(NULL) 21 21 , componentState_(NOT_MONITORED) 22 , ui(NULL) 22 23 { 23 24 LOG_TRACE("constructor"); -
branches/2.0-beta1/src/PacpusLib/ComponentManager.cpp
r96 r110 7 7 #include <Pacpus/kernel/ComponentManager.h> 8 8 #include <Pacpus/kernel/ComponentBase.h> 9 #include <Pacpus/kernel/ConnectionBase.h> 9 10 #include <Pacpus/kernel/Log.h> 10 #include <Pacpus/kernel/ConnectionBase.h>11 11 #include <QObject> 12 12 … … 227 227 QString componentType = cfg.getComponentType(); 228 228 QString componentName = cfg.getComponentName(); 229 //LOG_DEBUG("try to create component '" << componentName << "'"); 229 LOG_DEBUG("try to create component '" << componentName << "'"); 230 230 231 // create the component and automatically add it to the component manager list 231 232 if (!createComponent(componentType, componentName)) { … … 239 240 // Second, try to configure the components without regarding the dependencies 240 241 for (int i = 0; i < componentsNodeList.size(); ++i) { 241 //LOG_DEBUG("try to configure component '" << (*it) << "'");242 242 cfg.localCopy(componentsNodeList.item(i).toElement()); 243 243 QString componentName = cfg.getComponentName(); 244 LOG_DEBUG("try to configure component '" << componentName << "'"); 244 245 245 246 // copy locally the config parameters of the component … … 250 251 component->param.localCopy(cfg.qDomElement()); 251 252 component->configuration_ = component->configureComponent(cfg); 252 253 253 } 254 254 } // for … … 264 264 } else { 265 265 if (component->configuration_ == ComponentBase::CONFIGURATION_DELAYED) { 266 //LOG_DEBUG("try to configure component '" << (*it)<< "'");266 LOG_DEBUG("try to configure component '" << componentName << "'"); 267 267 268 268 // copy locally the config parameters of the component … … 274 274 --componentsToConfigureCount; 275 275 } else { 276 /*LOG_ERROR("cannot configure component '" << (*it)<< "'"276 LOG_ERROR("cannot configure component '" << componentName << "'" 277 277 << ". Dependencies with other components are too complex" 278 278 << ". It was not configured, please review your configuration and/or your component" 279 ); */279 ); 280 280 component->configuration_ = ComponentBase::CONFIGURED_FAILED; 281 281 } -
branches/2.0-beta1/src/PacpusLib/XmlComponentConfig.cpp
r100 r110 20 20 static const string kPropertyConnectionOutput = "output"; 21 21 static const string kPropertyConnectionPriority = "priority"; 22 static const string kPropertyConnectionInputC = "inputC";23 static const string kPropertyConnectionInputP = "inputP";24 static const string kPropertyConnectionOutputC = "outputC";25 static const string kPropertyConnectionOutputP = "outputP";22 //static const string kPropertyConnectionInputC = "inputC"; 23 //static const string kPropertyConnectionInputP = "inputP"; 24 //static const string kPropertyConnectionOutputC = "outputC"; 25 //static const string kPropertyConnectionOutputP = "outputP"; 26 26 27 27 XmlComponentConfig::XmlComponentConfig(const QString& name) -
branches/2.0-beta1/src/PacpusLib/XmlConfigFile.cpp
r100 r110 75 75 _mutex.lock(); 76 76 // TODO change .tagName => .attribute(kPropertyComponentName.c_str()) 77 if (_document.documentElement().namedItem(componentSection).namedItem(component. tagName()).isNull()) {78 LOG_WARN("component " << component. tagName()<< " exists already in the document");77 if (_document.documentElement().namedItem(componentSection).namedItem(component.attribute(nameAttribute)/*.tagName()*/).isNull()) { 78 LOG_WARN("component " << component.attribute(nameAttribute)/*tagName()*/ << " exists already in the document"); 79 79 } else { 80 80 QDomNode node = _document.documentElement().namedItem(componentSection).appendChild(component); … … 92 92 QDomNode node = _document.documentElement().namedItem(componentSection).removeChild(component); 93 93 if (node.isNull()) { 94 LOG_WARN("component " << component. tagName()<< " doesn't exist in the document.");94 LOG_WARN("component " << component.attribute(nameAttribute)/*tagName()*/ << " doesn't exist in the document."); 95 95 } else { 96 96 LOG_INFO("component " << node.nodeName() << " has been removed from the section " -
branches/2.0-beta1/src/PacpusSensor/CMakeLists.txt
r89 r110 32 32 ${PROJECT_BINARY_DIR} 33 33 ${QT_INCLUDE_DIR} 34 ) 35 # ======================================== 36 # Link directories 37 # ======================================== 38 link_directories( 39 ${PROJECT_BINARY_DIR}/../PacpusLib 40 ${PROJECT_BINARY_DIR}/../FileLib 34 41 ) 35 42 … … 72 79 target_link_libraries( 73 80 ${PROJECT_NAME} 74 dbiteplayerlib 75 FileLib 76 PacpusLib 77 PacpusTools 81 ${PACPUS_DEPENDENCIES_LIB} 82 # dbiteplayerlib 83 # FileLib 84 # PacpusLib 85 # PacpusTools 86 optimized FileLib debug FileLib_d 87 optimized PacpusLib debug PacpusLib_d 78 88 ${QT_LIBRARIES} 79 89 ) -
branches/2.0-beta1/src/PacpusTools/CMakeLists.txt
r89 r110 31 31 include_directories( 32 32 ${QT_INCLUDE_DIR} 33 ) 34 # ======================================== 35 # Link directories 36 # ======================================== 37 link_directories( 38 ${PROJECT_BINARY_DIR}/../PacpusLib 33 39 ) 34 40 … … 94 100 # ======================================== 95 101 pacpus_add_library( 96 ${PROJECT_NAME} 102 ${PROJECT_NAME} SHARED 97 103 ${PROJECT_SRCS} 98 104 ${PROJECT_MOC_SRCS} 105 ) 106 107 # ======================================== 108 # Libraries 109 # ======================================== 110 target_link_libraries( 111 ${PROJECT_NAME} 112 ${QT_LIBRARIES} 113 ${PACPUS_DEPENDENCIES_LIB} 114 optimized PacpusLib debug PacpusLib_d 99 115 ) 100 116
Note:
See TracChangeset
for help on using the changeset viewer.