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 StateType::Get( CommandInterpreter& inInterpreter ) { Lock lock( inInterpreter.StateMachine() ); const State& state = GetState( inInterpreter ); // GetState() tests for existence of the state. inInterpreter.Out() << inInterpreter.StateMachine().GetStateValue( state.Name().c_str() ); 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 StatesType::Clear( CommandInterpreter& inInterpreter ) { Lock lock( inInterpreter.StateMachine() ); if( inInterpreter.StateMachine().SystemState() != StateMachine::Idle ) throw bciexception( "Must be in idle state to clear states" ); inInterpreter.StateMachine().States().Clear(); return true; }
bool StatesType::List( CommandInterpreter& inInterpreter ) { Lock lock( inInterpreter.StateMachine() ); string pattern = inInterpreter.GetRemainingTokens(); if( pattern.empty() ) pattern = "*"; const StateList& states = inInterpreter.StateMachine().States(); for( int i = 0; i < states.Size(); ++i ) if( WildcardMatch( pattern, states[i].Name(), false ) ) inInterpreter.Out() << states[i] << '\n'; return true; }
bool StateType::List( CommandInterpreter& inInterpreter ) { Lock lock( inInterpreter.StateMachine() ); inInterpreter.Out() << GetState( inInterpreter ); return true; }
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; }