Exemplo n.º 1
0
bool Port::RPC( const HTTPRequest &request, const std::string &cat, const std::string &action )
{
  if( action == "set" )
  {
    int port_num;
    std::string name;
    int source_id;

    if( !request.GetParam( "port_num", port_num ))
      return false;
    this->port_num = port_num;

    if( !request.GetParam( "name", name ))
      return false;
    this->name = name;

    if( !request.GetParam( "source_id", source_id ))
      return false;

    if( source && ( source_id == -1 || source_id != source->GetKey( )))
    {
      source->RemovePort( this );
      source = NULL;
    }

    if( source_id != -1 )
    {
      if( !source || ( source && source_id != source->GetKey( )))
      {
        source = TVDaemon::Instance( )->GetSource( source_id );
        source->AddPort( this );
        SetSource( source );
      }
    }

    request.Reply( HTTP_OK );
    return true;
  }

  request.NotFound( "Port::RPC unknown action '%s'", action.c_str( ));
  return false;
}
Exemplo n.º 2
0
bool Adapter::RPC( const HTTPRequest &request, const std::string &cat, const std::string &action )
{
  if( cat == "port" or cat == "frontend" )
  {
    std::string t;
    if( !request.GetParam( "frontend_id", t ))
      return false;
    int i = atoi( t.c_str( ));
    if( i >= 0 && i < frontends.size( ))
    {
      return frontends[i]->RPC( request, cat, action );
    }
  }

  request.NotFound( "RPC: unknown action '%s'", action.c_str( ));
  return false;
}
Exemplo n.º 3
0
bool Frontend::RPC( const HTTPRequest &request, const std::string &cat, const std::string &action )
{
  if( cat == "port" )
  {
    int port_id;
    if( !request.GetParam( "port_id", port_id ))
      return false;

    LockPorts( );
    std::map<int, Port *>::iterator it = ports.find( port_id );
    if( it == ports.end( ))
    {
      LogError( "Port %d not found", port_id );
      return false;
    }
    bool ret = it->second->RPC( request, cat, action );
    UnlockPorts( );
    return ret;
  }

  if( action == "create_port" )
  {
    int port_num;
    if( !request.GetParam( "port_num", port_num ))
      return false;
    std::string name;
    if( !request.GetParam( "name", name ))
      return false;
    int source_id;
    if( !request.GetParam( "source_id", source_id ))
      return false;

    Port *port = AddPort( name, port_num );
    if( port == NULL )
    {
      request.NotFound( "Port with number %d already exists", port_num );
      return false;
    }

    Source *source = TVDaemon::Instance( )->GetSource( source_id );
    if( !source )
      LogError( "Source not found: %d", source_id );
    else
    {
      source->AddPort( port );
      port->SetSource( source );
    }
    request.Reply( HTTP_OK, port->GetKey( ));
    return true;
  }

  if( action == "delete_port" )
  {
    int port_id;
    if( !request.GetParam( "port_id", port_id ))
      return false;
    LockPorts( );
    std::map<int, Port *>::iterator it = ports.find( port_id );
    if( it == ports.end( ))
    {
      LogError( "Port not found: %d", port_id );
      UnlockPorts( );
      return false;
    }
    it->second->Delete( );
    delete it->second;
    ports.erase( it );
    UnlockPorts( );

    return true;
  }

  request.NotFound( "RPC unknown action: '%s'", action.c_str( ));
  return false;
}