cmil::ComboHandler Class Reference

#include <InputNode.h>

Inheritance diagram for cmil::ComboHandler:

Inheritance graph
[legend]
Collaboration diagram for cmil::ComboHandler:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ComboHandler (System *const sys)
virtual ~ComboHandler ()
bool add (const Ev::Sequence &seq)
virtual bool handle (const InputData &input)
bool isCombo (const Ev::Sequence &seq) const
virtual std::string getName () const

Private Member Functions

bool canHandle (const InputData &input) const
bool Merge (const Ev::Sequence &seq)
bool check_time (const InputNode *child) const

Private Attributes

const Systemm_system
InputNodem_root
 This is the first node in the tree structure managed by this handler.
InputNodem_controlling
 This is the tracked controlling node in the tree structure managed by this handler.

Detailed Description

I decided to compartimentalized handling of combos in order to have a less complicated namespace and provide some further flexibility with handling of InputData types with this specific kind of Sequencer.

Definition at line 151 of file InputNode.h.


Constructor & Destructor Documentation

cmil::ComboHandler::ComboHandler ( System *const   sys  )  [inline]

Definition at line 153 of file InputNode.h.

00153 : SystemClient(sys), m_root(NULL), m_controlling(NULL) {}

virtual cmil::ComboHandler::~ComboHandler (  )  [inline, virtual]

Definition at line 154 of file InputNode.h.

References m_root.

00154 { delete m_root; }


Member Function Documentation

bool cmil::ComboHandler::add ( const Ev::Sequence seq  ) 

Definition at line 355 of file InputNode.cpp.

References Logger::log_debug(), and Merge().

Referenced by cmil::NodeSequencer::imp_addCombo().

00355                                               {
00356       std::cout << std::endl;
00357       log_debug("add(seq) : defering sequence to merge function."); 
00358       return Merge(seq);
00359   }

Here is the call graph for this function:

Here is the caller graph for this function:

bool cmil::ComboHandler::canHandle ( const InputData input  )  const [private]

Definition at line 361 of file InputNode.cpp.

References m_root.

Referenced by handle().

00361                                                            {
00362     if(!m_root) {
00363       //log_debug(std::string("canHandle() ").append(input.getName()).append(" not handled due to no sequences stored."));
00364       return false;
00365     }
00366     return true;
00367   }

Here is the caller graph for this function:

bool cmil::ComboHandler::check_time ( const InputNode child  )  const [private]

Definition at line 369 of file InputNode.cpp.

References cmil::InputNode::getParent(), cmil::InputNode::getTime(), cmil::InputNode::getTimeMargin(), Logger::log_debug(), and Logger::log_error().

Referenced by handle().

00369                                                             { 
00370     unsigned long child_time   = child->getTime();
00371     unsigned long child_margin = child->getTimeMargin();
00372     unsigned long parent_time  = 0;
00373 
00375     if(!child->getParent()) {
00376       log_error("check_time() failing due to being called on a root node.");
00377       return false;
00378     }
00379 
00381     if(!(child->getParent())->getParent()) {
00382       log_debug("check_time returning true due to calling from m_root node");
00383       return true;
00384     }
00385 
00386     parent_time = child->getParent()->getTime();
00387 
00388     if((child_time - parent_time) <= child_margin) { 
00389       log_debug("check_time() returning true because of time verification.");
00390       return true;
00391     }
00392 
00393     log_debug("check_time() returning false due to time check failure.");
00394     return false;
00395   }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual std::string cmil::ComboHandler::getName (  )  const [inline, virtual]

Reimplemented from cmil::SystemClient.

Definition at line 161 of file InputNode.h.

00161 { return "ComboHandler"; }

bool cmil::ComboHandler::handle ( const InputData input  )  [virtual]

Definition at line 397 of file InputNode.cpp.

References canHandle(), check_time(), cmil::InputNode::getAction(), cmil::InputNode::getChild(), cmil::InputData::getID(), cmil::InputData::getName(), cmil::InputData::getState(), cmil::InputData::getTime(), Logger::log_debug(), m_controlling, m_root, cmil::InputData::run(), and cmil::InputNode::setTime().

Referenced by cmil::NodeSequencer::imp_handle().

00397                                                   {
00398     InputNode* child;
00399 
00400     if(!canHandle(input) || !input.getState()) 
00401       return false;
00402     
00404   
00405     if ( (child = m_controlling->getChild(input.getID())) != NULL) {
00406       child->setTime(input.getTime());
00407       if(check_time(child))
00408       {
00409         if(child->getAction()) {
00411            input.run(child->getAction());
00412            m_controlling = m_root;
00413         }
00414         else  {
00415           log_debug(string("handle(InputData) moving to next child in sequence: ").append(input.getName()));  
00417           child->setTime(input.getTime());  
00418           m_controlling = child; 
00419         }
00420 
00421         log_debug(string("handle(InputData) : ").append(input.getName()).append(" handled."));
00422         return true; 
00423       }
00424     }
00425 
00426     m_controlling = m_root;
00427     log_debug(string("handle(InputData) : ").append(input.getName()).append(" not handled."));
00428     return false; 
00429   }

Here is the call graph for this function:

Here is the caller graph for this function:

bool cmil::ComboHandler::isCombo ( const Ev::Sequence seq  )  const

Determine if the sequence has combo qualities Note that this will return true if passed a normal sequence. It is the equivelant with the exception of allowing duplicate events.

All sequences should have an action asigned.

Validate InputData matching the event.

Validate action position and compatibilty.

Not at the end yet.

Definition at line 241 of file InputNode.cpp.

References cmil::SystemClient::getData(), cmil::InputData::isActionCompatible(), Logger::log_debug(), and Logger::log_error().

Referenced by cmil::NodeSequencer::isCombo().

00241                                                         {
00242     InputData*   tmp_input;
00243     InputAction* tmp_action;
00244 
00246     if( !(  seq.back().getAction() )  ) { 
00247       log_error("isCombo() : event is not part of a valid sequence due to missing action"); 
00248       return false;
00249     }
00250 
00251     for(Ev::Sequence::const_iterator i = seq.begin() ; i!= seq.end(); i++) {
00252       log_debug(string("isCombo() : iteratoring to event named: ").append((*i).getName())); 
00253       
00255       if( ( tmp_input = getData((*i))) == NULL ) {
00256         log_error(string("isCombo() : sequence found invalid due no InputData found for event: ").append((*i).getName()));
00257         return false;
00258       }
00259       
00261       if((tmp_action = (*i).getAction()) != NULL) {
00263         if( i != --(seq.end()) ) {
00264           log_error(string("isCombo() : action found in wrong position of sequence. Ev: ").append((*i).getName())); 
00265           return false;
00266         }
00267         else if(!tmp_input->isActionCompatible(tmp_action)) {
00268           log_error("isCombo() : action found incompatible with event. "); 
00269           return false;
00270         }
00271 
00272         log_debug("isCombo() : returning true "); 
00273         return true;
00274       }
00275     }
00276 
00277     log_error("isCombo() : returning false ");
00278     return false;
00279   }

Here is the call graph for this function:

Here is the caller graph for this function:

bool cmil::ComboHandler::Merge ( const Ev::Sequence seq  )  [private]

Definition at line 431 of file InputNode.cpp.

References cmil::InputNode::createChild(), cmil::InputNode::createRoot(), cmil::SystemClient::getSize(), cmil::SystemClient::getSystem(), Logger::log_debug(), Logger::log_error(), m_controlling, m_root, cmil::InputNode::setAction(), and cmil::InputNode::setTimeMargin().

Referenced by add().

00431                                                 {
00432     std::ostringstream debug_ss;
00433     InputAction* tmp_action;
00434     InputNode* current;
00435 
00436     if(!m_root) {
00437       log_debug("Merge() creating root node");
00438       m_root = InputNode::createRoot(getSystem(), getSize());
00439       m_controlling = m_root;
00440     }
00441 
00442     current = m_root;
00443 
00444     for(Ev::Sequence::const_iterator i = seq.begin() ; i!=seq.end(); i++) {
00445       //log_debug(string("  Merge() iterating through event sequence, name: ").append((*i).getName()));
00446 
00447       if((current = current->createChild(true, *i)) == NULL) {
00448         log_error("  Merge() Unable to merge sequence due to InputNode creation error.");
00449         return false;
00450       }
00451 
00452       current->setTimeMargin( (*i).getTimeMargin() );
00453 
00455       if((tmp_action = (*i).getAction()) != NULL) {
00456         log_debug(string("  Merge() found action at event, assigning: ").append((*i).getName())); 
00457 
00458         current->setAction(tmp_action);
00459 
00460         return true;
00461       }
00462       else 
00463         log_debug(string("  Merge() did not find an action at event: ").append((*i).getName()));
00464     }
00465     
00467     log_error("Merge() Unable to merge sequence due to no action being found.");
00468     return false;
00469   }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

InputNode* cmil::ComboHandler::m_controlling [private]

This is the tracked controlling node in the tree structure managed by this handler.

Definition at line 175 of file InputNode.h.

Referenced by handle(), and Merge().

InputNode* cmil::ComboHandler::m_root [private]

This is the first node in the tree structure managed by this handler.

Definition at line 172 of file InputNode.h.

Referenced by canHandle(), handle(), Merge(), and ~ComboHandler().

const System* cmil::ComboHandler::m_system [private]

Reimplemented from cmil::SystemClient.

Definition at line 169 of file InputNode.h.


The documentation for this class was generated from the following files:
(c) 2006-2007 John P. Feltz
Generated on Wed Jul 25 16:08:03 2007 for Common Media Input Layer by doxygen 1.4.7

SourceForge.net Logo