| 72 | } |
| 73 | |
| 74 | bool Engine::load(const DataFlow& df) { |
| 75 | // release old dataflow |
| 76 | if (m_graph) |
| 77 | delete m_graph; |
| 78 | m_graph = new Graph<ProcessingStep>; |
| 79 | |
| 80 | // load component libraries |
| 81 | for (set<string>::const_iterator libIt=df.getComponentLibraries().begin(); |
| 82 | libIt!=df.getComponentLibraries().end(); libIt++) |
| 83 | { |
| 84 | if (ComponentFactory::instance()->loadLibrary(*libIt)!=0) |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | #ifdef WITH_TIMERS |
| 89 | static Timer* gt = Timer::get_timer("loading dataflow"); |
| 90 | gt->start(); |
| 91 | #endif |
| 92 | |
| 93 | const DataFlow::NodeList& nodes = df.getNodes(); |
| 94 | |
| 95 | // create processing steps |
| 96 | map<DataFlow::Node*,ProcessFlow::Node*> mapping; |
| 97 | for (DataFlow::NodeList::const_iterator nodeIt = nodes.begin(); nodeIt |
| 98 | != nodes.end(); nodeIt++) { |
| 99 | DataFlow::Node* n = *nodeIt; |
| 100 | ProcessFlow::Node* s = m_graph->createNode(); |
| 101 | if ((n->v.componentId!="Input") && (n->v.componentId!="Output")) |
| 102 | s->v.m_pool = &m_pool; |
| 103 | s->v.m_id = n->v.componentId; |
| 104 | s->v.m_params = n->v.params; |
| 105 | mapping[n] = s; |
| 106 | if (verboseFlag) |
| 107 | cout << "create step for component " << s->v.m_id << endl; |
| 108 | } |
| 109 | |
| 110 | // set names |
| 111 | for (DataFlow::NameMapCIt nameIt=df.getNames().begin(); |
| 112 | nameIt!=df.getNames().end();nameIt++) |
| 113 | { |
| 114 | m_graph->setNodeName(mapping[nameIt->second],nameIt->first); |
| 115 | } |
| 116 | |
| 117 | // create links |
| 118 | const DataFlow::LinkList& links = df.getLinks(); |
| 119 | for (DataFlow::LinkListCIt it=links.begin();it!=links.end();it++) |
| 120 | { |
| 121 | const DataFlow::Link* l = *it; |
| 122 | m_graph->link(mapping[l->source],l->sourceOutputPort,mapping[l->target],l->targetInputPort); |
| 123 | } |
| 124 | // initialize components in order |
| 125 | bool initOK = m_graph->visitAll<Engine::initStep>(); |
| 126 | |
| 127 | #ifdef WITH_TIMERS |
| 128 | gt->stop(); |
| 129 | #endif |
| 130 | |
| 131 | // set start nodes |
no test coverage detected