Changeset 206 in pacpusframework for trunk/include/Pacpus
- Timestamp:
- Oct 30, 2013, 12:26:34 PM (11 years ago)
- Location:
- trunk/include/Pacpus/kernel
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/Pacpus/kernel/ComponentBase.h
r202 r206 84 84 /// Ctor of ComponentBase. 85 85 /// @param name Name of your component. 86 ComponentBase(const QString & name);86 ComponentBase(const QString & name); 87 87 88 88 /// Dtor of ComponentBase. … … 100 100 /// @return Name of the component. 101 101 QString getName() const; 102 103 /// @returns @b true if the component has been started and is active (working) 104 bool isActive() const; 102 105 103 106 protected: … … 170 173 } 171 174 172 bool isActive() const;173 175 void setActive(bool isActive); 174 176 bool isRecording() const; -
trunk/include/Pacpus/kernel/InputOutputBase.h
r200 r206 32 32 virtual std::size_t getDataSize() const = 0; 33 33 virtual const std::type_info & getDataType() const = 0; 34 35 //virtual PacpusEvent * getEventTemplate() = 0; 34 36 35 37 void addConnection(ConnectionBase connection); … … 99 101 QStringList getInputConnectedList(); 100 102 101 void send(/*const*/ QByteArray & data);103 //void send(/*const*/ QByteArray & data); 102 104 }; 103 105 -
trunk/include/Pacpus/kernel/InputOutputInterface.h
r202 r206 23 23 : InputInterfaceBase(name, component, component) 24 24 , method(processMethod) 25 {} 25 { 26 } 26 27 27 28 ~InputInterface() 28 {} 29 { 30 } 29 31 30 32 std::size_t getDataSize() const … … 39 41 40 42 // FIXME: what's the purpose of this function? 41 PacpusEvent * getEventTemplate()42 {43 return new PacpusTypedEvent<T>(TYPED_EVENT);44 }43 //PacpusEvent * getEventTemplate() 44 //{ 45 // return new PacpusTypedEvent<T>(TYPED_EVENT); 46 //} 45 47 46 48 // FIXME: what's the purpose of this function? 47 49 void customEvent(QEvent * event) 48 50 { 49 // TODO check component state started 50 //if (_component) get state 51 // check that component has been started 52 if ((NULL == getComponent()) || (!getComponent()->isActive())) { 53 LOG_DEBUG("component is not active"); 54 return; 55 } 56 57 LOG_DEBUG("Receiver: " << getSignature()); 58 59 //PacpusTypedEvent<T> * typedEvent = dynamic_cast<PacpusTypedEvent<T> *>(event); 60 PacpusEvent * pacpusEvent = dynamic_cast<PacpusEvent *>(event); 61 if (!pacpusEvent) { 62 LOG_WARN("dynamic_cast failed: not a PacpusEvent"); 63 return; 64 } 65 PacpusTypedEvent<T> * typedEvent = dynamic_cast<PacpusTypedEvent<T> *>(pacpusEvent); 66 if (!typedEvent) { 67 LOG_WARN("dynamic_cast failed: incompatible event types"); 68 return; 69 } 70 51 71 switch (event->type()) { 52 72 case TYPED_EVENT: 53 { 54 PacpusTypedEvent<T> * typedEvent = dynamic_cast<PacpusTypedEvent<T> *> (event); 55 56 LOG_DEBUG("Receiver: " << getSignature()); 57 58 if (typedEvent->timerange() < 500 && readingMode() == TimeBounded) { 73 if (TimeBounded == readingMode() && typedEvent->timerange() < 500) { 59 74 LOG_WARN("Incorrect TimeRange (0), switch to NeverSkip"); 60 75 readingMode() = NeverSkip; … … 63 78 switch (readingMode()) { 64 79 case TimeBounded: 65 66 80 if (road_time() - typedEvent->time() > typedEvent->timerange()) { 67 LOG_ DEBUG("Data skipped, receiver: " << this->getSignature());81 LOG_TRACE("Data skipped, receiver: " << this->getSignature()); 68 82 break; 69 83 } … … 73 87 74 88 case GetLast: 75 76 89 (dynamic_cast<C*>(component())->*method)(typedEvent->data()); 77 90 // delete all remaining events … … 85 98 default: 86 99 LOG_WARN("Unknown reading mode " << readingMode()); 100 break; 87 101 } 88 102 break; 89 }90 103 91 104 // Add here new event type if needed … … 95 108 break; 96 109 } 97 event->accept();110 event->accept(); 98 111 } 99 112 100 113 // TODO for Pulling mode (not yet implemented !!!) 101 T & getData() { 114 T & getData() 115 { 102 116 T data; 103 117 // TODO ask output data; 104 105 118 return data; 106 119 } … … 125 138 {} 126 139 127 // Used by Components to send data througthtyped output140 /// Send data through a typed output 128 141 void send(const T & data, road_time_t t = road_time(), road_timerange_t tr = 0); 129 142 … … 150 163 // It is not safe to access the event after it has been posted. 151 164 QEvent * newEvent = new PacpusTypedEvent<T>(TYPED_EVENT, data, t, tr); 152 QCoreApplication::postEvent(it->getInterface(), newEvent, it->getPriority()); 165 QCoreApplication::postEvent( 166 it->getInterface(), 167 newEvent, 168 it->getPriority() 169 ); 153 170 LOG_DEBUG("Sender: " << it->getInterface()->getSignature()); 154 171 LOG_DEBUG("Data &: " << &data); -
trunk/include/Pacpus/kernel/PacpusEvent.h
r196 r206 38 38 39 39 // TODO: should we make it virtual pure ??? 40 virtual QDataStream & streamOut(QDataStream& out)40 virtual QDataStream & streamOut(QDataStream & out) 41 41 { 42 42 return out; … … 77 77 { 78 78 public: 79 TypedData(const T & data)80 : m_data(data)79 TypedData(const T & data) 80 : m_data(data) 81 81 { 82 82 } … … 96 96 } 97 97 98 s ize_t size() const98 std::size_t size() const 99 99 { 100 100 return sizeof(T); … … 112 112 public: 113 113 // FIXME: why we need `data = T()` ??? 114 PacpusTypedEvent(PacpusEventType type, const T & data = T(), road_time_t t = road_time(), road_timerange_t tr = 0)114 PacpusTypedEvent(PacpusEventType type, const T & data/* = T()*/, road_time_t t = road_time(), road_timerange_t tr = 0) 115 115 : PacpusEvent(type, t, tr) 116 116 , TypedData<T>(data) 117 {} 117 { 118 } 119 120 /// Conversion constructor from another PacpusTypedEvent, 121 /// when T is convertible to S 122 template <typename S> 123 PacpusTypedEvent(const PacpusTypedEvent<S> & other) 124 : PacpusEvent(static_cast<PacpusEventType>(other.type()), other.time(), other.timerange()) 125 , TypedData<T>(other.data()) 126 { 127 } 118 128 119 129 ~PacpusTypedEvent() 120 {} 121 122 QDataStream& streamOut(QDataStream& out) 130 { 131 } 132 133 QDataStream & streamOut(QDataStream & out) 123 134 { 124 135 // FIXME Stream Data errors … … 126 137 } 127 138 128 QDataStream & streamIn(QDataStream& in)139 QDataStream & streamIn(QDataStream & in) 129 140 { 130 141 return in >> (quint64&) time() >> timerange() /*>> m_data*/; … … 135 146 { 136 147 public: 137 GenericData(const char * data, size_t size)148 GenericData(const char * data, size_t size) 138 149 : m_data(NULL) 139 150 , m_dataSize(size) … … 164 175 } 165 176 166 s ize_t size() const177 std::size_t size() const 167 178 { 168 179 return m_dataSize; … … 170 181 171 182 private: 172 char * m_data;173 s ize_t m_dataSize;183 char * m_data; 184 std::size_t m_dataSize; 174 185 }; 175 186 … … 179 190 { 180 191 public: 181 PacpusGenericEvent(PacpusEventType type, const char * data, size_t size)192 PacpusGenericEvent(PacpusEventType type, const char * data, size_t size) 182 193 : PacpusEvent(type) 183 194 , GenericData(data, size) … … 192 203 } // namespace pacpus 193 204 194 PACPUSLIB_API inline QDataStream & operator<< (QDataStream& out, pacpus::PacpusEvent& ev)205 PACPUSLIB_API inline QDataStream & operator<<(QDataStream & out, pacpus::PacpusEvent & ev) 195 206 { 196 207 /*return ev.streamOut(out);*/ … … 198 209 } 199 210 200 PACPUSLIB_API inline QDataStream & operator>> (QDataStream& in, pacpus::PacpusEvent& ev)211 PACPUSLIB_API inline QDataStream & operator>>(QDataStream & in, pacpus::PacpusEvent & ev) 201 212 { 202 213 /*return ev.streamIn(in);*/
Note:
See TracChangeset
for help on using the changeset viewer.