/** This method is called, when a task is finished for this inode * pid == 0 -> no operator or node have no holistic operator * pid == -1 -> can't start process */ void INode::taskFinished(int pid, int exit_state) { try { int flag = -1; #ifdef DEBUGMSG qDebug("# INode::taskFinished (%s)(%p) pid=%d ES=%d", (const char *) name(), this, pid, execState()); #endif switch (execState()) { case TD: if (exit_state!=0) { analysis()->setError(true); status(TD_ERROR); analysis()->ready(); qDebug("INode::184:clean up necessary?"); return; } flag = evalTopDown(pid); break; case BU: if (exit_state!=0) { analysis()->setError(true); status(BU_ERROR); analysis()->ready(); qDebug ( "INode::194:clean up necessary?"); return; } flag = evalBottomUp(pid); break; } #ifdef DEBUGMSG qDebug("# INode::taskFinished: finish ... (%s) pid=%d %p flag=%d\n", (const char *) name(), pid, this, flag); #endif switch (flag) { case 1: INode::analysis()->ready(); break; case 0: delete this; break; } } catch(FatalError err) { qDebug("INode::taskFinished(): Exception(%s) %s", name().latin1(), err.message().latin1()); // emit analysis_->message(err.message()); } }
/** initialize inode */ void INode::init() { labelImage_ = 0; sNode_ = 0; status(HI); //default; execState(TD); //default; aktivcount_ = childcount_ = ordercount_ = aktivorder_ = 0; truncation_ = FALSE; childList_ = NULL; }
TaskExecuter::State TaskExecuter::run(const string &taskName, State start) { if (!initialized) { init(taskName); } State s = start; currStep = 0; do { Transition t = execState(s); State s2 = nextState(s, t); LOG_INFO("state machine: transitioning from " << s << " to " << s2 << " via " << t); s = s2; } while (!isTerminalState(s)); return s; }
/** Execute the bottomUp operator */ void INode::execBottomUp() { #ifdef DEBUGMSG qDebug("#* INode::execBottomUp(%s)(%p): Start\n", (const char *) name(), this); #endif if (analysis()->error()) { status(BU_ABORTED); return; } execState(BU); CHECK_PTR(this->sNode()); if (sNode_) sNode_->execBottomUpOp(this); //start BU }
/** Copy constructor */ INode::INode(INode & node):TreeNode < INode, GNode > (node) { sNode_ = 0; sNode(node.sNode()); execState(node.execState()); status(node.status()); childList_ = node.childList_; childcount_ = node.childcount_; aktivcount_ = node.aktivcount_; ordercount_ = node.ordercount_; aktivorder_ = node.aktivorder_; truncation_ = node.truncation_; analysis_ = node.analysis_; output_ = node.output_; if (node.labelImage_) labelImage_ = node.labelImage_->shallowCopy(); else labelImage_ = 0; }
/** call the TopDown Operator of the SNode */ void INode::execTopDown() { #ifdef DEBUGMSG qDebug("#* INode::execTopDown(%s)(%p): Start\n", (const char *) name(),this); #endif if (analysis()->error()) { status(TD_ABORTED); return; } execState(TD); CHECK_PTR(this->sNode()); if (sNode_->holistic()) sNode_->execTopDownOp(this); //start TD else if (!sNode_->attributeBool("td_multiclass")) taskFinished(0,0); else { parent()->decrementCount(); // status(TRASH); parent()->childUnlink(this); //!remove this temporary INode delete this; } }
/** handle the results of the TopDown operator * pid == 0 -> no operator or node have no holistic operator * pid == -1 -> can't start process * never call for "root" node (this is not root node) * this can be "last" node */ int INode::evalTopDown(int pid) { #ifdef DEBUGMSG qDebug("#* INode::evalTopDown(%s)(%p): pid=%d Start\n", (const char *) name(), this, pid); #endif CHECK_PTR(sNode_); //Hier Absturz weil parent = 0 CHECK_PTR(parent()); INode* parent=INode::parent(); if (pid <= 0) { #ifdef DEBUGMSG qDebug ("# (ERROR -1/0) evalTopDown: can't start process \n try it structural\n"); #endif #warning Without Dummy TopDown nothing works if (!isLast() && !truncation()) childTopDown(); //do it structural else if (isLast()) { //is last node status(MI); execState(BU); parent->childUnlink(this); //!remove this temporary INode parent->decrementCount(); return 0; } else { //is trash status(TRASH); execState(BU); parent->childUnlink(this); //!remove this temporary INode parent->decrementCount(); return 0; } } if (sNode_->holistic()) { //pid > 0 QList < INode > iNodeList = sNode_->evalTopDown(this); #ifdef DEBUGMSG qDebug("##*** evalTopDown: %d(min) < %d(ist) < %d(max)",sNode()->minNumNode(),iNodeList.count(), sNode()->maxNumNode()); #endif if (!(sNode()->minNumNode() == 0 && sNode()->maxNumNode() == 0 )) //beide eintraege null -> alles erlaubt if (iNodeList.count() < sNode()->minNumNode() || iNodeList.count() > sNode()->maxNumNode() ) { #ifdef DEBUGMSG qDebug("***** iNodeList.count %d, sNode->minNumNode %d, sNode->maxNumNode %d \n",iNodeList.count(),sNode()->minNumNode(),sNode()->maxNumNode()); #endif status(MI); execState(BU); truncation(TRUE); //! unlink here parent->status(TRASH); parent->truncation(TRUE); parent->childUnlink(this); //!remove this temporary INode parent->decrementCount(); return 0; } #ifdef DEBUGMSG qDebug("# (INFO) sNode is holistic; count new nodes: %d\n", iNodeList.count()); #endif if (iNodeList.isEmpty()) { #ifdef DEBUGMSG qDebug("# (warning) operator return no result - missing Instance"); #endif status(MI); execState(BU); //! unlink here parent->childUnlink(this); //!remove this temporary INode parent->decrementCount(); return 0; } parent->incrementCount(iNodeList.count() - 1); INode *el; parent->childUnlink(this); //!remove this temporary INode for (el = iNodeList.first(); el != 0; el = iNodeList.next()) { #ifdef DEBUGMSG qDebug("# einhaengen: (%p) %s in %s", this,(const char *)el->name(), (const char *)parent->name()); #endif if (el->isLast()) el->status(CI); //el->execState(BU); ??????????? else el->status(PI); el->execState(TD); //}????????????? parent->childLink(el); //insert the new INodes analysis_->nodeChange(el); if (el->isLast()) parent->decrementCount(); else el->childTopDown(); //last node have no children } //delete this; //XXXX #ifdef DEBUGMSG qDebug("# einhaengen: (%p) fertig in %s",this,(const char *)parent->name()); #endif return 0; } else { qDebug ("# (ERROR 1) taskFinished no operator found \n try it structural\n"); if (isLast()) qDebug("# (ERROR 1) last node must be holistic!\n"); parent->childUnlink(this); //!remove this temporary INode return 0; } }
/** handle the results of the BottomUp operator * pid == 0 -> no operator or node have no holistic operator * pid == -1 -> can't start process * return -1 - error * return 0 - delete 'this' * return 1 - analyze is ready * return 2 - processing * remember: a node without SNode is a "Trash-Node" * this node must have children */ int INode::evalBottomUp(int pid) { #ifdef DEBUGMSG qDebug("#* INode::evalBottomUp(%s): pid=%d (%p)\n", (const char *) name(), pid, this); #endif if (pid <= 0) { #ifdef DEBUGMSG qDebug("# (ERROR) evalBottomUp(%p): BottomUp operator have no result \n", this); #endif //! hier noch das Icon im Browser auf rot setzen (Problem) status(TRASH); if (parent()) parent()->decrementCount(); return -1; } execState(BU); if (isRoot()) { //! Debug qDebug("INode::evalBottomUp: is Root"); #ifdef WIN32 QMessageBox::information(0,"INode","evalBottomUp: is Root",QMessageBox::Cancel); #endif } analysis_->nodeChange(this); QList < INode > &nodeList = sNode_->evalBottomUp(this); //new composition analysis_->nodeChange(this); #ifdef DEBUGMSG qDebug("# (INFO) nodeList count: %d\n", nodeList.count()); #endif if (isRoot()) { switch (nodeList.count()) { case 0: #ifdef DEBUGMSG qDebug("# (ERROR) No szene found(%p)\n", this); #endif #ifdef WIN32 QMessageBox::warning(0,"INode","evalBottomUp: No szene found"); #endif return 1; case 1:{ #ifdef DEBUGMSG qDebug("# Root node is unique (%p)\n", this); #endif //alle bis auf die zurückgegebenen aus this entfernen { //! eigentlich können die children direkt gelöscht werden! INode *trashNode = new INode(*this); #ifdef WIN32 if (trashNode == 0){ cout << "Out of Memory..11"; exit(1); } #endif trashNode->status(TRASH); { // normally this code should do nothing because the children are already moved INode *el; while (children().count()) { el = (children()).first(); trashNode->childLink(el); analysis_->nodeChange(el); } } #if 0 delete trashNode; #else analysis_->setTrashRoot(trashNode); #endif } { INode *el; INode *iNode = nodeList.first(); update(iNode->attribList()); labelImage(iNode->labelImage()); el = (iNode->children()).first(); while (el) { childLink(el); analysis_->nodeChange(el); el = (iNode->children()).first(); } delete iNode; } delete & nodeList; return 1; //=> analyze is ready } default: #ifdef DEBUGMSG qDebug("# (ERROR) Root node must be unique (%p)\n", this); #endif #ifdef WIN32 QMessageBox::warning(0,"INode","evalBottomUp: Root node must be unique"); #endif delete & nodeList; return -1; } } if (nodeList.isEmpty()) { #ifdef DEBUGMSG qDebug ("# (ERROR) evalBottomUp: QList<<INode> nodeList is empty - all trash\n"); #endif status(TRASH); parent()->decrementCount(); delete & nodeList; //return 0; // XXX TEST - fuer die Ergebnisdarstellung return 2; //=> } QListIterator < INode > it(nodeList); for (; it.current(); ++it) { INode *iNode = it.current(); analysis_->nodeChange(iNode); parent()->childLink(iNode); iNode->status(CI); INode *el; for (el = iNode->children().first(); el != 0; el = iNode->children().next()) { if (el->status() <= MI) iNode->status(MI); analysis_->nodeChange(el); //info to the rest of the world } } INode *p = parent(); //for later access if ((this->children()).isEmpty()) { #ifdef DEBUGMSG qDebug("# (INFO) evalBottomUp: empty list - no trash\n"); // #endif parent()->childUnlink(this); p->decrementCount(); delete & nodeList; return 0; // delete this; } else { //this->sNode(0); //make a TRASH Node; -> has no SNode this->status(TRASH); p->decrementCount(); delete & nodeList; //return 0; // XXX TEST - fuer die Ergebnisdarstellung return 2; } }