void copyPorts( ESMoL::Block inputBlock, ESMoL::Block outputBlock ) { PortVector portVector = inputBlock.Port_kind_children(); for( PortVector::iterator ptvItr = portVector.begin() ; ptvItr != portVector.end() ; ++ptvItr ) { ESMoL::Port inputPort = *ptvItr; ESMoL::Port outputPort = UdmEngine::copy( inputPort, outputBlock ); if ( outputPort == Udm::null ) { std::cerr << "Warning: could not copy output port" << std::endl; return; } getPortList().push_back( inputPort ); getPortMap().insert( std::make_pair( inputPort, outputPort ) ); ESMoL::TypeBaseRef inputTypeBaseRef = inputPort.TypeBaseRef_child(); if ( inputTypeBaseRef != Udm::null ) { ESMoL::TypeBaseRef outputTypeBaseRef = ESMoL::TypeBaseRef::Create( outputPort ); ESMoL::TypeBase inputTypeBase = inputTypeBaseRef.ref(); if ( inputTypeBase != Udm::null ) { TypeBaseMap::iterator tbmItr = getTypeBaseMap().find( inputTypeBase ); if ( tbmItr != getTypeBaseMap().end() ) { outputTypeBaseRef.name() = inputTypeBaseRef.name(); outputTypeBaseRef.ref() = tbmItr->second; } } } } }
PortID DelegateService::unusedODPPort(const SpaceObjectReference& sor) { // We want to make this efficient in most cases, but need to make it // exhaustively search for available ports when we can't easily find a free // one. The approach is simple: choose a random port to start with and check // if it's free. From there, perform a linear search (which must wrap and // avoid reserved ports). This won't perform well in extreme cases where we // the port space is almost completely full... PortID starting_port_id = (rand() % (OBJECT_PORT_SYSTEM_MAX-OBJECT_PORT_SYSTEM_RESERVED_MAX)) + (OBJECT_PORT_SYSTEM_RESERVED_MAX+1); // If we don't have a PortMap yet, then its definitely not allocated PortMap* pm = getPortMap(sor); if (pm == NULL) return starting_port_id; // Loop until we hit the starting point again PortID port_id = starting_port_id; do { // This port may be allocated already PortMap::iterator it = pm->find(port_id); if (it == pm->end()) return port_id; // Otherwise we need to move on, ensuring looping of Port IDs. port_id++; if (port_id > PortID(OBJECT_PORT_SYSTEM_MAX)) port_id = OBJECT_PORT_SYSTEM_RESERVED_MAX+1; } while(port_id != starting_port_id); // If we get here, we're really out of ports SILOG(odp-delegate-service, error, "Exhausted ODP ports for " << sor); return PortID::null(); }
void DelegateService::deallocatePort(DelegatePort* port) { PortMap* pm = getPortMap(port->endpoint().spaceObject()); if (pm == NULL) return; pm->erase(port->endpoint().port()); }
DelegateService::PortMap* DelegateService::getOrCreatePortMap(const SpaceObjectReference& sor) { PortMap* pm = getPortMap(sor); if (pm != NULL) return pm; PortMap* new_port_map = new PortMap(); mSpacePortMap[sor] = new_port_map; return new_port_map; }
void copyDataflows( ESMoL::ModelsFolder inputModelsFolder, ESMoL::ModelsFolder outputModelsFolder ) { getPortList().clear(); getPortMap().clear(); DataflowVector dataflowVector = inputModelsFolder.Dataflow_kind_children(); for( DataflowVector::iterator dfvItr = dataflowVector.begin() ; dfvItr != dataflowVector.end() ; ++dfvItr ) { ESMoL::Dataflow inputDataflow = *dfvItr; ESMoL::Dataflow outputDataflow = ESMoL::Dataflow::Create( outputModelsFolder ); outputDataflow.name() = inputDataflow.name(); copySubsystems_flatten( inputDataflow, outputDataflow ); } for( PortList::iterator ptlItr = getPortList().begin() ; ptlItr != getPortList().end() ; ++ptlItr ) { ESMoL::Port inputDstPort = *ptlItr; LineSet lineSet = inputDstPort.srcLine(); if ( lineSet.empty() ) continue; ESMoL::Line line = *lineSet.begin(); ESMoL::Port inputSrcPort = line.srcLine_end(); lineSet = inputSrcPort.srcLine(); while( getPortMap().find( inputSrcPort ) == getPortMap().end() && !lineSet.empty() ) { line = *lineSet.begin(); inputSrcPort = line.srcLine_end(); lineSet = inputSrcPort.srcLine(); } PortMap::iterator ptmItr = getPortMap().find( inputDstPort ); if ( ptmItr == getPortMap().end() ) { std::cerr << "Warning: port not in PortMap" << std::endl; continue; } ESMoL::Port outputDstPort = ptmItr->second; ptmItr = getPortMap().find( inputSrcPort ); if ( ptmItr == getPortMap().end() ) { std::cerr << "Warning: port not in PortMap" << std::endl; continue; } ESMoL::Port outputSrcPort = ptmItr->second; Udm::Object lineParent = outputSrcPort.GetParent(); if ( Udm::IsDerivedFrom( outputSrcPort.type(), ESMoL::OutPort::meta ) ) lineParent = lineParent.GetParent(); ESMoL::Line outputLine = ESMoL::Line::Create( lineParent ); outputLine.srcLine_end() = outputSrcPort; outputLine.dstLine_end() = outputDstPort; } }
bool DelegateService::deliver(const Endpoint& src, const Endpoint& dst, MemoryReference data) const { // Check from most to least specific PortMap const* pm = getPortMap(dst.spaceObject()); if (pm != NULL) { PortMap::const_iterator it = pm->find(dst.port()); if (it != pm->end()) { DelegatePort* port = it->second; bool delivered = port->deliver(src, dst, data); if (delivered) return true; } } // And finally, the default handler if (mDefaultHandler != 0) { mDefaultHandler(src, dst, data); return true; } return false; }