#include <InputNode.h>
Inheritance diagram for cmil::NormalHandler:
Public Types | |
typedef std::map< Ev::Sequence, NodeSequence * > | AddedSequences |
Public Member Functions | |
NormalHandler (System *const sys) | |
virtual | ~NormalHandler () |
virtual std::string | getName () const |
bool | add (const Ev::Sequence &seq) |
bool | remove (const Ev::Sequence &seq) |
virtual bool | handle (const InputData &input) |
virtual bool | handle (const ModData &input) |
bool | isNormal (const Ev::Sequence &seq) const |
Private Member Functions | |
bool | canHandle (const InputData &input) const |
bool | Merge (const Ev::Sequence &seq) |
bool | unMerge (const Ev::Sequence &seq) |
This removes a sequence starting at it's last node. | |
InputNode * | HandleActivity (const ModData &input) |
InputNode * | recurChildController (InputNode *const node) |
InputNode * | recurParentController (InputNode *const node) |
void | RemoveControl (InputNode *node) |
Remove control of this node or any nodes that depend on it. | |
Private Attributes | |
std::deque< InputNode * >::iterator | m_i |
std::deque< InputNode * > | m_controlnodes |
InputNode * | m_root |
This is the first node in the tree structure managed by this handler. | |
InputNode::NodeIndex | m_active |
This tracks the active nodes throughout the tree to allow for fast access. | |
AddedSequences | m_added_seq |
Classes | |
class | NodeSequence |
Definition at line 181 of file InputNode.h.
typedef std::map<Ev::Sequence, NodeSequence* > cmil::NormalHandler::AddedSequences |
Definition at line 194 of file InputNode.h.
cmil::NormalHandler::NormalHandler | ( | System *const | sys | ) | [inline] |
Node data and structures based off them are built on use, rather than building them while the registry contains a non-complete index.
Definition at line 200 of file InputNode.h.
00200 : SystemClient(sys), m_root(NULL) {}
virtual cmil::NormalHandler::~NormalHandler | ( | ) | [inline, virtual] |
Definition at line 201 of file InputNode.h.
References m_added_seq, and m_root.
00201 { 00202 delete m_root; 00203 00204 for(AddedSequences::iterator i = m_added_seq.begin(); i != m_added_seq.end() ; i++) 00205 delete (i->second); 00206 }
bool cmil::NormalHandler::add | ( | const Ev::Sequence & | seq | ) |
Definition at line 331 of file InputNode.cpp.
References Logger::log_debug(), Logger::log_error(), m_added_seq, and Merge().
Referenced by cmil::NodeSequencer::imp_addNormal().
00331 { 00332 std::cout << std::endl; 00333 00334 if( m_added_seq.find(seq) != m_added_seq.end()) { 00335 log_error(" add() found matching pre-existing sequence, not adding."); 00336 return false; 00337 } 00338 00339 log_debug("add(seq) : defering sequence to merge function."); 00340 return Merge(seq); 00341 }
Here is the call graph for this function:
Here is the caller graph for this function:
bool cmil::NormalHandler::canHandle | ( | const InputData & | input | ) | const [private] |
Definition at line 471 of file InputNode.cpp.
References cmil::InputData::getID(), cmil::InputData::getName(), Logger::log_debug(), Logger::log_error(), m_active, and m_root.
Referenced by handle().
00471 { 00472 if(!m_root) { 00473 log_debug(std::string("canHandle() ").append(input.getName()).append(" not handled due to no sequences stored.")); 00474 return false; 00475 } 00476 if(m_active.size()) { 00477 if(m_active.size() <= input.getID()) { 00478 log_error(std::string("canHandle() ").append(input.getName()).append(" not handled due to input not being availabile in present index.")); 00479 return false; 00480 } 00481 } 00482 else { 00483 log_debug(std::string("canHandle() ").append(input.getName()).append(" not handled due to no seqeuences stored.")); 00484 return false; 00485 } 00486 00487 //log_debug(std::string("canHandle() ").append(input.getName()).append(" returning true")); 00488 return true; 00489 }
Here is the call graph for this function:
Here is the caller graph for this function:
virtual std::string cmil::NormalHandler::getName | ( | ) | const [inline, virtual] |
bool cmil::NormalHandler::handle | ( | const ModData & | input | ) | [virtual] |
Definition at line 190 of file InputNode.cpp.
References canHandle(), cmil::InputData::getID(), cmil::InputData::getName(), cmil::InputData::getState(), HandleActivity(), Logger::log_debug(), m_active, RemoveControl(), and cmil::tInputData< ActionType >::run().
00190 { 00191 if(!canHandle(input)) 00192 return false; 00193 00194 log_debug(string("Handle(ModData) : ").append(input.getName())); 00195 00196 if(m_active[input.getID()]) { 00197 log_debug(string("Handle(ModData) : found in active active index: ").append(input.getName())); 00198 00200 if(!input.getState()) { 00201 (((m_active[input.getID()])->getParent())->setActiveChild(NULL)); 00202 00205 RemoveControl(m_active[input.getID()]); 00206 } 00207 00209 if((m_active[input.getID()])->getAction()) 00210 input.run((m_active[input.getID()])->getAction()); 00211 00213 m_active[input.getID()] = NULL; 00214 00215 log_debug(string("Handle(ModData) : ").append(input.getName()).append(" handled, inactivity set.")); 00216 return true; 00217 } 00218 else { 00221 if(input.getState()) { 00222 00223 if((m_active[input.getID()] = HandleActivity(input)) != NULL) { 00224 log_debug(string("Handle(ModData) : ").append(input.getName()).append(" handled, activity set")); 00225 return true; 00226 } 00227 else 00228 log_debug(string("Handle(ModData) : ").append(input.getName()).append(" not handled, no activity set")); 00229 00230 log_debug(string("Handle(ModData) : ").append(input.getName()).append(" not handled due to no sequence found, ")); 00231 return false; 00232 } 00233 return false; 00234 } 00235 }
Here is the call graph for this function:
bool cmil::NormalHandler::handle | ( | const InputData & | input | ) | [virtual] |
Definition at line 152 of file InputNode.cpp.
References canHandle(), cmil::InputNode::getAction(), cmil::InputData::getID(), cmil::InputNode::getIndex(), cmil::InputData::getName(), Logger::log_debug(), m_controlnodes, m_i, m_root, and cmil::InputData::run().
Referenced by cmil::NodeSequencer::imp_handle().
00152 { 00153 InputNode* child; 00154 std::ostringstream debug_ss; 00155 00156 if(!canHandle(input)) 00157 return false; 00158 00160 for(m_i = m_controlnodes.begin() ; m_i != m_controlnodes.end() ; m_i++) { 00161 //log_debug( "handle() iterating through control nodes.."); 00162 //check for the child by input index value 00163 00164 if((child = (*(*m_i)->getIndex())[input.getID()]) != NULL) { 00165 if(child->getAction()) 00166 input.run(child->getAction()); 00167 00168 debug_ss <<" handle( " << input.getName() << ") handled. "; 00169 log_debug(debug_ss.str()); 00170 debug_ss.str(""); 00171 00172 return true; 00173 } 00174 } 00175 00177 if(m_root) 00178 if((child = (*m_root->getIndex())[input.getID()]) != NULL) { 00179 input.run(child->getAction()); 00180 log_debug(string("handle(InputData) : ").append(input.getName()).append(" handled.")); 00181 return true; 00182 } 00183 00184 log_debug(string("handle(InputData) : ").append(input.getName()).append(" not handled.")); 00185 return false; 00186 }
Here is the call graph for this function:
Here is the caller graph for this function:
This checks non-root controlling node index'es to see if one of their children matches if so, replace the parent, if checking the root index, add as a new controlling node.
Check the registered controlling node index'es, last added to first.
Check for the child by input index value.
Set the parent's activechild to the one found.
Check if the child has dependants
Add this child as a controlling node since it's a child of the root the push_front call essentially sets the priority of which sequence handles the same input
Definition at line 570 of file InputNode.cpp.
References cmil::InputNode::getAction(), cmil::InputData::getID(), cmil::InputNode::getIndex(), cmil::InputData::getName(), Logger::log_debug(), m_controlnodes, m_i, m_root, recurChildController(), and cmil::tInputData< ActionType >::run().
Referenced by handle().
00570 { 00571 InputNode* child; 00572 00573 // log_debug(string("HandleActivity() : ").append(input.getName())); 00574 00576 for(m_i = m_controlnodes.begin() ; m_i != m_controlnodes.end() ; m_i++) { 00578 if((child = (*(*m_i)->getIndex())[input.getID()]) != NULL) { 00579 if(child->getAction()) 00580 input.run(child->getAction()); 00581 00583 (*m_i)->setActiveChild(child); 00584 (*m_i) = recurChildController(child); 00585 00586 log_debug(string("HandleActivity(ModData) ").append(input.getName()).append( "successfully handled.")); 00587 return child; 00588 } 00589 } 00590 00591 log_debug(" HandleActivity() checking root since no control nodes found."); 00592 00593 if(m_root) 00594 if((child = (*m_root->getIndex())[input.getID()]) != NULL) { 00595 if(child->getAction()) { 00596 log_debug("HandleActivity() running found action."); 00597 input.run(child->getAction()); 00598 } 00599 00601 if(child->getIndex() != NULL) 00604 m_controlnodes.push_front(child); 00605 00606 return child; 00607 } 00608 00609 log_debug(string("HandleActivity(ModeData) ").append(input.getName()).append(" not handled.")); 00610 return NULL; 00611 }
Here is the call graph for this function:
Here is the caller graph for this function:
bool cmil::NormalHandler::isNormal | ( | const Ev::Sequence & | seq | ) | const |
Definition at line 281 of file InputNode.cpp.
References cmil::SystemClient::getData(), cmil::Ev::getEventCount(), cmil::InputData::isActionCompatible(), Logger::log_debug(), and Logger::log_error().
Referenced by cmil::NodeSequencer::isNormal().
00281 { 00282 InputData* tmp_input; 00283 InputAction* tmp_action; 00284 00286 if( !( seq.back().getAction() ) ) { 00287 log_error("isNormal() : event is not part of a valid sequence due to missing action"); 00288 return false; 00289 } 00290 00291 for(Ev::Sequence::const_iterator i = seq.begin() ; i!= seq.end(); i++) { 00292 log_debug(string("isNormal() : iteratoring to event named: ").append((*i).getName())); 00294 if(Ev::getEventCount(seq, *(i)) > 1) { 00295 log_debug("isNormal() : returning false"); 00296 return false; 00297 } 00298 00300 if( ( tmp_input = getData(*i)) == NULL ) { 00301 log_error(string("isNormal() : sequence found invalid due no InputData found for event: ").append((*i).getName())); 00302 return false; 00303 } 00304 else if( i != --(seq.end()) ) { 00305 if(dynamic_cast<ModData*>(tmp_input) == NULL) { 00306 log_error("isNormal() : sequence found invalid due to a non-ModData type having dependant events."); 00307 return false; 00308 } 00309 } 00310 00312 if((tmp_action = (*i).getAction()) != NULL) { 00314 if( i != --(seq.end()) ) { 00315 log_error(string("isNormal() : action found in wrong position of sequence. Ev: ").append((*i).getName())); 00316 return false; 00317 } 00318 else if(!tmp_input->isActionCompatible(tmp_action)) { 00319 log_error("isNormal() : action found incompatible with event. "); 00320 return false; 00321 } 00322 00323 log_debug("isNormal() : returning true "); 00324 return true; 00325 } 00326 } 00327 00328 return false; 00329 }
Here is the call graph for this function:
Here is the caller graph for this function:
bool cmil::NormalHandler::Merge | ( | const Ev::Sequence & | seq | ) | [private] |
Definition at line 491 of file InputNode.cpp.
References cmil::InputNode::createChild(), cmil::InputNode::createRoot(), cmil::SystemClient::getSize(), cmil::SystemClient::getSystem(), Logger::log_debug(), Logger::log_error(), m_active, m_added_seq, m_root, and cmil::InputNode::setAction().
Referenced by add().
00491 { 00492 std::ostringstream debug_ss; 00493 InputAction* tmp_action; 00494 InputNode* current; 00495 00496 if(!m_root) { 00497 log_debug("Merge() creating root node"); 00498 m_root = InputNode::createRoot(getSystem(), getSize()); 00499 } 00500 00501 if(!m_active.size()) { 00502 log_debug("Merge() setting m_active" ); 00503 m_active = InputNode::NodeIndex(SystemClient::getSize()); 00504 } 00505 00506 current = m_root; 00507 00508 for(Ev::Sequence::const_iterator i = seq.begin() ; i!=seq.end(); i++) { 00509 //log_debug(string(" Merge() iterating through event sequence, name: ").append((*i).getName())); 00510 00512 if((current = current->createChild(false, (*i))) == NULL) 00513 return false; 00514 00516 if((tmp_action = (*i).getAction()) != NULL) { 00517 log_debug(string(" Merge() found action at event: ").append((*i).getName())); 00518 00519 current->setAction(tmp_action); 00520 00522 m_added_seq[seq] = new NodeSequence(current); 00523 return true; 00524 } 00525 else 00526 log_debug(string(" Merge() did not find an action at event: ").append((*i).getName())); 00527 } 00528 00530 log_error("Merge() Unable to merge sequence due to no action being found."); 00531 return false; 00532 }
Here is the call graph for this function:
Here is the caller graph for this function:
This function created a need for an getActiveChild(), because i don't want to have to iterate over the vector members just to get what should be a single node.
This node is qualified to be a controller if it has an m_index, but check the activechild to see if it meets the same quality first.
This node doesn't meet the m_index quality => it can't be a controller => return the parent which is the last valid controller.
Definition at line 617 of file InputNode.cpp.
References cmil::InputNode::getActiveChild(), cmil::InputNode::getIndex(), and cmil::InputNode::getParent().
Referenced by HandleActivity(), and RemoveControl().
00617 { 00620 if((node->getIndex() != NULL) ) { 00621 if(node->getActiveChild() != NULL) 00622 return recurChildController(node->getActiveChild()); 00623 else 00624 return node; 00625 } 00626 00629 return node->getParent(); 00630 }
Here is the call graph for this function:
Here is the caller graph for this function:
This finds the last valid parent controlling node (active /w index and accessible through parent). This should return NULL if closest found is root.
this is the root node, return NULL
It's active, return it.
Tt isn't, go to the next parent.
Definition at line 634 of file InputNode.cpp.
References cmil::InputNode::getID(), cmil::InputNode::getParent(), and m_active.
Referenced by RemoveControl().
00634 { 00635 if(!node->getParent()) 00637 return NULL; 00638 00639 if(m_active[node->getID()]) 00641 return node; 00642 00644 return recurParentController(node->getParent()); 00645 }
Here is the call graph for this function:
Here is the caller graph for this function:
bool cmil::NormalHandler::remove | ( | const Ev::Sequence & | seq | ) |
Definition at line 343 of file InputNode.cpp.
References Logger::log_debug(), Logger::log_error(), m_added_seq, and unMerge().
Referenced by cmil::NodeSequencer::imp_removeNormal().
00343 { 00344 std::cout << std::endl; 00345 00346 if( m_added_seq.find(seq) == m_added_seq.end()) { 00347 log_error(" remove(seq) no existing sequence found, not removing."); 00348 return false; 00349 } 00350 00351 log_debug("remove(seq) : defering sequence to unmerge function."); 00352 return unMerge(seq); 00353 }
Here is the call graph for this function:
Here is the caller graph for this function:
void cmil::NormalHandler::RemoveControl | ( | InputNode * | node | ) | [private] |
Remove control of this node or any nodes that depend on it.
Get the last in sequence child node with controller properties.
Get the iterator to the controller in the list.
Set the controlling node to the closest valid parent.
This is the root node, delete the node sequence.
Give the parent the same priority as the replaced controlling node.
Definition at line 648 of file InputNode.cpp.
References cmil::InputNode::getID(), cmil::InputNode::getParent(), m_controlnodes, m_i, recurChildController(), and recurParentController().
Referenced by handle().
00648 { 00650 InputNode* controller = recurChildController(node); 00651 00653 for(m_i = m_controlnodes.begin() ; m_i != m_controlnodes.end() ; m_i++) 00654 if((*m_i)->getID() == controller->getID()) { 00655 00657 00658 InputNode* new_controller = recurParentController(node->getParent()); 00659 00660 if (new_controller== NULL) 00662 m_controlnodes.erase(m_i); 00663 else { 00665 (*m_i) = new_controller; 00666 } 00667 break; 00668 } 00669 }
Here is the call graph for this function:
Here is the caller graph for this function:
bool cmil::NormalHandler::unMerge | ( | const Ev::Sequence & | seq | ) | [private] |
This removes a sequence starting at it's last node.
Definition at line 535 of file InputNode.cpp.
References cmil::InputNode::deleteChild(), cmil::InputNode::getChildren(), cmil::InputNode::getID(), cmil::InputNode::getParent(), Logger::log_debug(), Logger::log_error(), m_added_seq, and m_root.
Referenced by remove().
00535 { 00536 InputNode* parent; 00537 InputNode* current; 00538 00539 if(!m_root) { 00540 log_debug("unMerge() found no root node, returning false"); 00541 return false; 00542 } 00543 00544 if(m_added_seq[seq]) { 00545 current = m_added_seq[seq]->getLastNode(); 00546 m_added_seq.erase(seq); 00547 } 00548 else { 00549 log_error("unMerge() didn't find the sequence on what should be second check."); 00550 return false; 00551 } 00552 00553 for(Ev::Sequence::const_iterator i = seq.end() ; i!=seq.begin(); --i) { 00554 if( (current->getChildren()) || (!current->getParent()) ) 00555 continue; 00556 00557 parent = current->getParent(); 00558 parent->deleteChild(current->getID()); 00559 00560 current = parent; 00561 } 00562 00563 log_debug("unMerge() finishing removal"); 00564 return true; 00565 }
Here is the call graph for this function:
Here is the caller graph for this function:
This tracks the active nodes throughout the tree to allow for fast access.
Definition at line 243 of file InputNode.h.
Referenced by canHandle(), handle(), Merge(), and recurParentController().
Definition at line 245 of file InputNode.h.
Referenced by add(), Merge(), remove(), unMerge(), and ~NormalHandler().
std::deque<InputNode* > cmil::NormalHandler::m_controlnodes [private] |
This tracks which inputs which have control of a sequence. IE: given Ctrl-Q as a sequence, and Ctrl(pressed)->A(released), the node for Ctrl be stored here while Ctrl is pressed. A deque was used to express the order of precindence between control nodes with the same dependant event.
Definition at line 237 of file InputNode.h.
Referenced by handle(), HandleActivity(), and RemoveControl().
std::deque<InputNode* >::iterator cmil::NormalHandler::m_i [private] |
This is an iterator which needs to be at the class scope in order to be useful to certain functions.
Definition at line 230 of file InputNode.h.
Referenced by handle(), HandleActivity(), and RemoveControl().
InputNode* cmil::NormalHandler::m_root [private] |
This is the first node in the tree structure managed by this handler.
Definition at line 240 of file InputNode.h.
Referenced by canHandle(), handle(), HandleActivity(), Merge(), unMerge(), and ~NormalHandler().