Changeset 269 in pacpusframework for trunk/include
- Timestamp:
- Mar 13, 2014, 10:41:25 AM (11 years ago)
- Location:
- trunk/include/Pacpus/kernel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/Pacpus/kernel/InputOutputInterface.h
r258 r269 18 18 typedef T data_type; 19 19 typedef C component_type; 20 typedef void (C::*process_data_function_type)(const T &); 21 22 InputInterface(QString name, C * component, process_data_function_type processMethod) 23 : InputInterfaceBase(name, component, component) 24 , method(processMethod) 25 { 20 typedef void (C::*process_data_function_type_with_event)(T&, PacpusEvent); 21 typedef void (C::*process_data_function_type)(T&); 22 typedef void (C::*process_const_data_function_type_with_event)(T const&, PacpusEvent); 23 typedef void (C::*process_const_data_function_type)(T const&); 24 25 InputInterface(QString name, C* component, process_data_function_type_with_event processingMethod) 26 : InputInterfaceBase(name, component, component) 27 { 28 mProcessingMethod.fe = processingMethod; 29 } 30 31 InputInterface(QString name, C* component, process_data_function_type processingMethod) 32 : InputInterfaceBase(name, component, component) 33 { 34 mProcessingMethod.f = processingMethod; 35 } 36 37 InputInterface(QString name, C* component, process_const_data_function_type_with_event processingMethod) 38 : InputInterfaceBase(name, component, component) 39 { 40 mProcessingMethod.cfe = processingMethod; 41 } 42 43 InputInterface(QString name, C* component, process_const_data_function_type processingMethod) 44 : InputInterfaceBase(name, component, component) 45 { 46 mProcessingMethod.cf = processingMethod; 26 47 } 27 48 … … 35 56 } 36 57 37 const std::type_info& getDataType() const58 std::type_info const& getDataType() const 38 59 { 39 60 return typeid(T); … … 47 68 48 69 // FIXME: what's the purpose of this function? 49 void customEvent(QEvent * event) 50 { 70 void customEvent(QEvent* event) 71 { 72 static road_timerange_t const kMaximumBoundedTimeRange = 500; 73 74 if (!event) { 75 LOG_WARN("null event"); 76 return; 77 } 78 51 79 // check that component has been started 52 80 if ((NULL == getComponent()) || (!getComponent()->isActive())) { … … 57 85 LOG_TRACE("Receiver: " << getSignature()); 58 86 59 //PacpusTypedEvent<T> 60 PacpusEvent * pacpusEvent = dynamic_cast<PacpusEvent*>(event);87 //PacpusTypedEvent<T>* typedEvent = dynamic_cast<PacpusTypedEvent<T> *>(event); 88 PacpusEvent* pacpusEvent = dynamic_cast<PacpusEvent*>(event); 61 89 if (!pacpusEvent) { 62 90 LOG_WARN("dynamic_cast failed: not a PacpusEvent"); 63 91 return; 64 92 } 65 PacpusTypedEvent<T> * typedEvent = dynamic_cast<PacpusTypedEvent<T>*>(pacpusEvent);93 PacpusTypedEvent<T>* typedEvent = dynamic_cast<PacpusTypedEvent<T>*>(pacpusEvent); 66 94 if (!typedEvent) { 67 95 LOG_WARN("dynamic_cast failed: incompatible event types"); … … 71 99 switch (event->type()) { 72 100 case TYPED_EVENT: 73 if (TimeBounded == readingMode() && typedEvent->timerange() < 500) {74 LOG_WARN("Incorrect TimeRange ( 0), switch to NeverSkip");101 if (TimeBounded == readingMode() && typedEvent->timerange() < kMaximumBoundedTimeRange) { 102 LOG_WARN("Incorrect TimeRange (< " << kMaximumBoundedTimeRange << "), switching to NeverSkip mode"); 75 103 readingMode() = NeverSkip; 76 104 } … … 83 111 } 84 112 85 (dynamic_cast<C*>(component())->*method)(typedEvent->data());113 mProcessingMethod.invoke(component(), typedEvent->data(), *typedEvent); 86 114 break; 87 115 88 116 case GetLast: 89 (dynamic_cast<C*>(component())->*method)(typedEvent->data()); 117 mProcessingMethod.invoke(component(), typedEvent->data(), *typedEvent); 118 90 119 // delete all remaining events 91 120 QCoreApplication::removePostedEvents(this, TYPED_EVENT); … … 93 122 94 123 case NeverSkip: 95 (dynamic_cast<C*>(component())->*method)(typedEvent->data());124 mProcessingMethod.invoke(component(), typedEvent->data(), *typedEvent); 96 125 break; 97 126 … … 111 140 } 112 141 113 // TODO for Pulling mode (not yet implemented!!!)114 T 142 // TODO: pull mode (NOT YET IMPLEMENTED!!!) 143 T& getData() 115 144 { 116 145 T data; 117 // TODO askoutput data;146 // TODO: ask the output data; 118 147 return data; 119 148 } 120 149 121 150 protected: 122 process_data_function_type method; 151 struct ProcessingMethod 152 { 153 ProcessingMethod() 154 { 155 fe = NULL; 156 f = NULL; 157 cfe = NULL; 158 cf = NULL; 159 } 160 161 void invoke(ComponentBase* component, T& data, PacpusEvent event) 162 { 163 C* comp = dynamic_cast<C*>(component); 164 if (NULL == comp) { 165 LOG_WARN("NULL component"); 166 return; 167 } 168 if (fe) { 169 (comp->*fe)(data, event); 170 } else if (f) { 171 (comp->*f)(data); 172 } else if (cfe) { 173 (comp->*cfe)(data, event); 174 } else if (cf) { 175 (comp->*cf)(data); 176 } else { 177 LOG_WARN("no method to invoke"); 178 } 179 } 180 181 process_data_function_type_with_event fe; 182 process_data_function_type f; 183 process_const_data_function_type_with_event cfe; 184 process_const_data_function_type cf; 185 }; 186 187 ProcessingMethod mProcessingMethod; 123 188 }; 124 189 … … 131 196 typedef C component_type; 132 197 133 OutputInterface(QString name, C 198 OutputInterface(QString name, C* component) 134 199 : OutputInterfaceBase(name, component, component) 135 200 {} … … 139 204 140 205 /// Send data through a typed output 141 void send( const T& data, road_time_t t = road_time(), road_timerange_t tr = 0);206 void send(T const& data, road_time_t t = road_time(), road_timerange_t tr = 0); 142 207 143 208 std::size_t getDataSize() const … … 146 211 } 147 212 148 const std::type_info& getDataType() const213 std::type_info const& getDataType() const 149 214 { 150 215 return typeid(T); … … 153 218 154 219 template <typename T, class C> 155 void OutputInterface<T, C>::send( const T& data, road_time_t t, road_timerange_t tr)156 { 157 // FIXME Data Shared220 void OutputInterface<T, C>::send(T const& data, road_time_t t, road_timerange_t tr) 221 { 222 // FIXME: use shared data 158 223 //QSharedPointer<T> sharedPointer = new T(data); 159 224 160 225 for (QList<ConnectionBase>::iterator it = connections().begin(), itend = connections().end(); it != itend; ++it) { 161 // Qt documentati no:226 // Qt documentation: 162 227 // The event must be allocated on the heap since the post event queue will take ownership of the event and delete it once it has been posted. 163 228 // It is not safe to access the event after it has been posted. 164 QEvent * newEvent = new PacpusTypedEvent<T>(TYPED_EVENT, data, t, tr);229 QEvent* pacpusEvent = new PacpusTypedEvent<T>(TYPED_EVENT, data, t, tr); 165 230 QCoreApplication::postEvent( 166 231 it->getInterface(), 167 newEvent,232 pacpusEvent, 168 233 it->getPriority() 169 234 ); … … 173 238 174 239 template <typename T1, typename T2, class C> 175 bool checkedSend(OutputInterface<T1, C> * sender, const T2& data, road_time_t t = road_time(), road_timerange_t tr = 0);240 bool checkedSend(OutputInterface<T1, C>* sender, T2 const& data, road_time_t t = road_time(), road_timerange_t tr = 0); 176 241 177 242 template <typename T1, typename T2, class C> 178 bool checkedSend(OutputInterface<T1, C> * sender, const T2& data, road_time_t t, road_timerange_t tr)243 bool checkedSend(OutputInterface<T1, C>* sender, T2 const& data, road_time_t t, road_timerange_t tr) 179 244 { 180 245 if (sender && sender->hasConnection()) { -
trunk/include/Pacpus/kernel/PacpusEvent.h
r206 r269 49 49 } 50 50 51 road_time_t 51 road_time_t& time() 52 52 { 53 53 return m_time; 54 54 } 55 55 56 const road_time_t& time() const56 road_time_t const& time() const 57 57 { 58 58 return m_time; 59 59 } 60 60 61 road_timerange_t 61 road_timerange_t& timerange() 62 62 { 63 63 return m_timerange; 64 64 } 65 65 66 const road_timerange_t& timerange() const66 road_timerange_t const& timerange() const 67 67 { 68 68 return m_timerange; 69 69 } 70 70 71 protected: 71 72 road_time_t m_time; … … 121 122 /// when T is convertible to S 122 123 template <typename S> 123 PacpusTypedEvent( const PacpusTypedEvent<S>& other)124 PacpusTypedEvent(PacpusTypedEvent<S> const& other) 124 125 : PacpusEvent(static_cast<PacpusEventType>(other.type()), other.time(), other.timerange()) 125 126 , TypedData<T>(other.data()) … … 146 147 { 147 148 public: 148 GenericData(c onst char* data, size_t size)149 GenericData(char const* data, size_t size) 149 150 : m_data(NULL) 150 151 , m_dataSize(size)
Note:
See TracChangeset
for help on using the changeset viewer.