Example #1
0
void FissionReactor::process(const EventPtr& e)
{
	if (e->getType() == m_input_event_type.term_ref) {
		// used for generating new events
		EventFactory event_factory;
		EventPtr new_ptr;
		bool read_result;

		// iterate through each value defined for the input event term
		Event::ValuesRange range = e->equal_range(m_input_event_term.term_ref);
		for (Event::ConstIterator it = range.first; it != range.second; ++it) {

			// create an input stream based upon the term value
			const Event::BlobType& ss = boost::get<const Event::BlobType&>(it->value);
			boost::iostreams::stream<boost::iostreams::array_source> input_stream(ss.get(), ss.size());

			// read Event(s) from the input stream
			while ( isRunning() && !input_stream.eof() ) {

				// only allow one thread to use the codec at a time
				boost::mutex::scoped_lock codec_lock(m_codec_mutex);
				event_factory.create(new_ptr, m_codec_ptr->getEventType());
				read_result = m_codec_ptr->read(input_stream, *new_ptr);
				codec_lock.unlock();
				if (! read_result)
					break;

				// copy terms from original event ?
				if (m_copy_all_terms) {
					// copy all terms from original event
					*new_ptr += *e;
				} else if (! m_copy_terms.empty() ) {
					// copy some terms from original event
					for (TermVector::const_iterator term_it = m_copy_terms.begin();
						term_it != m_copy_terms.end(); ++term_it)
					{
						new_ptr->copyValues(*e, term_it->term_ref);
					}
				}

				// deliver the event
				deliverEvent(new_ptr);
			}
		}
	}
}