Beispiel #1
0
Port* CreatePort (map<string, string> options)
{
    // Look for a type option
    string type;
    if (options.count ("type") == 0)
        throw PortException ("No port type specified.");
    else if (options.count ("type") != 1)
        throw PortException ("Multiple port types specified.");
    else
        type = options["type"];
    options.erase ("type");

#ifdef FLEXIPORT_INCLUDE_SERIAL
    if (type == "serial")
        return new SerialPort (options);
#endif // FLEXIPORT_INCLUDE_SERIAL
#ifdef FLEXIPORT_INCLUDE_TCP
    if (type == "tcp")
        return new TCPPort (options);
#endif // FLEXIPORT_INCLUDE_TCP
#ifdef FLEXIPORT_INCLUDE_UDP
    if (type == "udp")
        return new UDPPort (options);
#endif // FLEXIPORT_INCLUDE_UDP
#ifdef FLEXIPORT_INCLUDE_BT
    if (type == "rfcomm")
        return new RFCOMMPort(options);
#endif // FLEXIPORT_INCLUDE_BT

#ifdef FLEXIPORT_INCLUDE_LOGGING
    if (type == "logreader")
        return new LogReaderPort (options);
    #ifdef FLEXIPORT_INCLUDE_SERIAL
        if (type == "seriallog")
        {
            options["type"] = "serial";
            return new LogWriterPort (options);
        }
    #endif // FLEXIPORT_INCLUDE_SERIAL
    #ifdef FLEXIPORT_INCLUDE_TCP
        if (type == "tcplog")
        {
            options["type"] = "tcp";
            return new LogWriterPort (options);
        }
    #endif // FLEXIPORT_INCLUDE_TCP
#endif // FLEXIPORT_INCLUDE_LOGGING

    // If got to here, it's an unsupported port type
    stringstream ss;
    ss << "Unsupported port type: " << type;
    throw PortException (ss.str ());
}
Beispiel #2
0
void
GraphTools::__BFS( std::queue< raft::kernel* > &queue,
                   std::set<   raft::kernel* > &visited_set,
                   edge_func                   func,
                   void                        *data,
                   bool                        connected_error )
{
   while( queue.size() > 0 )
   {
      auto *k( queue.front() );
      queue.pop();
      if( k == nullptr ) break;
      /** iterate over all out-edges **/
      /** 1) get lock **/
      while( ! k->output.portmap.mutex_map.try_lock() )
      {
         std::this_thread::yield();
      }
      //we have lock, continue
      /** 2) get map **/
      std::map< std::string, PortInfo > &map_of_ports( k->output.portmap.map );
      for( auto &port : map_of_ports )
      {
         PortInfo &source( port.second );
         /** get dst edge to call function on **/
         if( source.other_kernel != nullptr  )
         {
            PortInfo &dst(
               source.other_kernel->input.getPortInfoFor( source.other_name ) );
            func( source, dst, data );
         }
         else
         if( connected_error )
         {
            std::stringstream ss;
            ss << "Unconnected port detected at " <<
               common::printClassName( *k ) <<
                  "[ \"" <<
                  source.my_name << " \"], please fix and recompile.";
            k->output.portmap.mutex_map.unlock();
            throw PortException( ss.str() );
         }
         /** if the dst kernel hasn't been visited, visit it **/
         if( visited_set.find( source.other_kernel ) == visited_set.end() )
         {
            queue.push( source.other_kernel );
            visited_set.insert( source.other_kernel );
         }
      }
      k->output.portmap.mutex_map.unlock();
   }
   return;
}
Beispiel #3
0
void
GraphTools::__BFS( std::queue< raft::kernel* > &queue,
                   std::set< raft::kernel*   > &visited_set,
                   vertex_func                 func,
                   void                        *data )
{
#if 0
   while( queue.size() > 0 )
   {
      auto *source( queue.front() );
      queue.pop();
      /** iterate over all out-edges **/
      /** 1) get lock **/
      std::lock_guard< std::mutex > lock( source->output.portmap.map_mutex );
      /** 2) get map **/
      std::map< std::string, PortInfo > &map_of_ports( source->output.portmap.map );
      /** 3) visit kernel **/
      func( *source, data );
      /** 4) add children to queue **/
      for( auto &port : map_of_ports )
      {
         PortInfo &source( port.second );
         /** get dst edge to call function on **/
         if( source.other_kernel != nullptr  )
         {
            PortInfo &dst( 
               source.other_kernel->input.getPortInfoFor( source.other_name ) );
            func( source, dst, data );
         }
         else
         if( connected_error )
         {
            std::stringstream ss;
            ss << "Unconnected port detected at " << 
               common::printClassName( *k ) <<  
                  "[ \"" <<
                  source.my_name << " \"], please fix and recompile.";
            throw PortException( ss.str() );
         }
         /** if the dst kernel hasn't been visited, visit it **/
         if( visited_set.find( source.other_kernel ) == visited_set.end() )
         {
            queue.push( source.other_kernel );
            visited_set.insert( source.other_kernel ); 
         }
      }
   }
   return;
#endif
   assert( false ); /** FIXME: error above with virtual function 'func', fix in a bit **/
}
Beispiel #4
0
Port* CreatePort (string options)
{
    const char* separators = ", \t\n";
    map<string, string> optionsMap;

    string::size_type pos = 0;
    // Find the start of the first option (skip delimeters at the beginning)
    string::size_type lastPos = options.find_first_not_of (separators, 0);
    // Check first that we did actually get something in the string
    if (lastPos == string::npos)
    {
        // No options. Go boom.
        throw PortException ("No options specified. Must specify a port type.");
    }

    do
    {
        pos = options.find_first_of (separators, lastPos);

        // Got an option, one way or the other
        string option = options.substr (lastPos, pos - lastPos);

        string::size_type splitPos = option.find ('=');
        if (splitPos != string::npos)
        {
            // Need to split this token
            optionsMap[option.substr (0, splitPos)] =
                    option.substr (splitPos + 1, option.length () - splitPos - 1);
        }
        else
        {
            // Boolean option
            optionsMap[option] = "1";
        }

        // Bring lastPos forward to the start of the next option (not just current pos)
        lastPos = options.find_first_not_of (separators, pos);
    }
    while (lastPos != string::npos && pos != string::npos);

    // Now that the options are in a map, call the standard CreatePort function
    return CreatePort (optionsMap);
}