bool
FileType::Extract( CommandInterpreter& inInterpreter )
{
  string file = inInterpreter.GetToken();
  if( !::stricmp( file.c_str(), "Base" ) )
    inInterpreter.Out() << FileUtils::ExtractBase( inInterpreter.GetToken() );
  else
    inInterpreter.Out() << FileUtils::ExtractFile( file );
  return true;
}
bool
FileType::Rename( CommandInterpreter& inInterpreter )
{
  string file = inInterpreter.GetToken(),
         newName = inInterpreter.GetToken();
  if( !FileUtils::IsFile( file ) )
    throw bciexception( "There is no file named \"" << file << "\"" );
  if( !FileUtils::Rename( file, newName ) )
    throw bciexception( "Could not rename file \"" << file << "\" to \"" << newName << "\"" );
  return true;
}
bool
DirectoryType::Rename( CommandInterpreter& inInterpreter )
{
  string dir = inInterpreter.GetToken(),
         newName = inInterpreter.GetToken();
  if( !FileUtils::IsDirectory( dir ) )
    throw bciexception( "There is no directory named \"" << dir << "\"" );
  if( !FileUtils::Rename( dir, newName ) )
    throw bciexception( "Could not rename \"" << dir << "\" to \"" << newName << "\"" );
  return true;
}
bool
DirectoryType::Exists( CommandInterpreter& inInterpreter )
{
  bool result = FileUtils::IsDirectory( inInterpreter.GetToken() );
  inInterpreter.Out() << ( result ? "true" : "false" );
  return true;
}
bool
StateType::Insert( CommandInterpreter& inInterpreter )
{
  string name = inInterpreter.GetToken();
  string line = inInterpreter.GetRemainder(),
         stateline = name + " " + line + " 0 0";
  State state;
  istringstream iss( stateline );
  if( !( iss >> state ) )
    throw bciexception( "Invalid state definition" );
  {
    Lock lock( inInterpreter.StateMachine() );
    switch( inInterpreter.StateMachine().SystemState() )
    {
      case StateMachine::Idle:
      case StateMachine::WaitingForConnection:
      case StateMachine::Publishing:
      case StateMachine::Information:
        break;
      default:
        throw bciexception( "Could not add state " << name << " to list after information phase" );
    }
    inInterpreter.StateMachine().States().Add( state );
  }
  inInterpreter.StateMachine().ExecuteCallback( BCI_OnState, stateline.c_str() );
  inInterpreter.Log() << "Added state " << name << " to list";
  return true;
}
bool
Interpreter::SignalType::Get( CommandInterpreter& inInterpreter )
{
    Lock lock( inInterpreter.StateMachine() );
    const GenericSignal& signal = inInterpreter.StateMachine().ControlSignal();
    string name = inInterpreter.GetToken();
    if( !::stricmp( name.c_str(), "Channels" ) )
    {
        inInterpreter.Out() << signal.Channels();
    }
    else if( !::stricmp( name.c_str(), "Elements" ) )
    {
        inInterpreter.Out() << signal.Elements();
    }
    else
    {
        CommandInterpreter::ArgumentList args;
        inInterpreter.ParseArguments( name, args );
        if( ::stricmp( name.c_str(), "Signal" ) )
            throw bciexception( "Use 'Signal' to address the signal" );
        if( args.size() != 1 || args[0].size() != 2 )
            throw bciexception( "Expected two signal indices" );
        int idx1 = ::atoi( args[0][0].c_str() ) - 1,
            idx2 = ::atoi( args[0][1].c_str() ) - 1;
        if( idx1 < 0 || idx2 < 0 || idx1 >= signal.Channels() || idx2 >= signal.Elements() )
            throw bciexception( "Signal index out of range" );
        inInterpreter.Out() << signal( idx1, idx2 );
    }
    return true;
}
bool
DirectoryType::Make( CommandInterpreter& inInterpreter )
{
  string dir = inInterpreter.GetToken();
  if( !FileUtils::MakeDirectory( dir ) )
    inInterpreter.Out() << "Could not make directory \"" << dir << "\"";
  return true;
}
bool
PathType::Exists( CommandInterpreter& inInterpreter )
{
  string path = inInterpreter.GetToken();
  bool result = FileUtils::IsFile( path ) || FileUtils::IsDirectory( path );
  inInterpreter.Out() << ( result ? "true" : "false" );
  return true;
}
bool
StateType::Exists( CommandInterpreter& inInterpreter )
{
  Lock lock( inInterpreter.StateMachine() );
  bool exists = inInterpreter.StateMachine().States().Exists( inInterpreter.GetToken() );
  inInterpreter.Out() << ( exists ? "true" : "false" );
  return true;
}
bool
DirectoryType::ForceRemove( CommandInterpreter& inInterpreter )
{
  string dir = inInterpreter.GetToken();
  if( !FileUtils::IsDirectory( dir ) )
    throw bciexception( "There is no directory named \"" << dir << "\"" );
  if( !FileUtils::RemoveDirectory( dir, true ) )
    throw bciexception( "Could not remove directory \"" << dir << "\"" );
  return true;
}
Esempio n. 11
0
bool
StateType::Set( CommandInterpreter& inInterpreter )
{
  string name;
  State::ValueType value = 0;
  ostringstream oss;
  {
    Lock lock( inInterpreter.StateMachine() );
    State& state = GetState( inInterpreter );
    name = state.Name();
    value = ::atoi( inInterpreter.GetToken().c_str() );
    if( !inInterpreter.StateMachine().SetStateValue( name.c_str(), value ) )
      throw bciexception( "Could not set state " << name << " to " << value );
    // StateMachine::SetStateValue() does not set the value of the state object in its state list.
    state.SetValue( value );
    oss << state;
  }
  inInterpreter.StateMachine().ExecuteCallback( BCI_OnState, oss.str().c_str() );
  inInterpreter.Log() << "Set state " << name << " to " << value;
  return true;
}
bool
DirectoryType::Parent( CommandInterpreter& inInterpreter )
{
  inInterpreter.Out() << FileUtils::ParentDirectoryS( inInterpreter.GetToken() );
  return true;
}
bool
PathType::Canonicalize( CommandInterpreter& inInterpreter )
{
  inInterpreter.Out() << FileUtils::CanonicalPath( inInterpreter.GetToken() );
  return true;
}
bool
FileType::List( CommandInterpreter& inInterpreter )
{
  return DirectoryType::ListSelection( inInterpreter, ".", inInterpreter.GetToken(), &FileUtils::IsFile );
}