120 std::string
mMark=
"% simfaudes: ========================================= ";
128 std::cout << std::endl;
133 signal(sig, SIG_DFL);
141 static sig_atomic_t exit_in_progress = 0;
142 if(exit_in_progress>0)
return;
144 std::cout <<
mMark <<
"simfaudes: exit handler" << std::endl;
145 #ifdef FAUDES_PLUGIN_IODEVICE
148 dev->WritePerformance();
159 std::cout <<
mMark <<
"statistics for simulation condition \"" <<
176 std::cout <<
"simfaudes: " << message << std::endl;
177 std::cout <<
"" << std::endl;
180 std::cout <<
"simfaudes: version " <<
VersionString() << std::endl;
181 std::cout <<
"" << std::endl;
182 std::cout <<
"simfaudes: usage: " << std::endl;
183 std::cout <<
" simfaudes [-q][-v][-i][-bc] [-bt <nnn>][-bs <nnn>] [-l <logfile>] [-ls] [-le] [-lt] <simfile> " << std::endl;
184 std::cout <<
"where " << std::endl;
185 std::cout <<
" <simfile>: simulation configuration file" << std::endl;
186 std::cout <<
"" << std::endl;
187 std::cout <<
" -q: less console output " << std::endl;
188 std::cout <<
" -qq: absolutely no console output " << std::endl;
189 std::cout <<
" -v: more console output" << std::endl;
190 std::cout <<
" -vv: even more console output" << std::endl;
191 std::cout <<
" -i: interactive mode " << std::endl;
192 std::cout <<
"" << std::endl;
193 std::cout <<
" -bc: break on condition" << std::endl;
194 std::cout <<
" -bt <nnn>: break on time <nnn> " << std::endl;
195 std::cout <<
" -bs <nnn>: break on step <nnn> " << std::endl;
196 std::cout <<
"" << std::endl;
197 std::cout <<
" -l <logfile>: log to <logfile> " << std::endl;
198 std::cout <<
" -ls: log states" << std::endl;
199 std::cout <<
" -le: log events" << std::endl;
200 std::cout <<
" -lt: log time" << std::endl;
201 std::cout <<
" -la: log all" << std::endl;
202 std::cout <<
" -t <nnn>: fifo trace buffer length <nnn> " << std::endl;
203 #ifdef FAUDES_PLUGIN_IODEVICE
204 std::cout <<
"" << std::endl;
205 std::cout <<
" -d <devfile>: use io device configured from file" << std::endl;
206 std::cout <<
" -dt <nnn>: tolerance in time synchronisation" << std::endl;
207 std::cout <<
" -dr: executer reset on device request" << std::endl;
209 std::cout <<
"" << std::endl;
210 std::cout <<
"" << std::endl;
215 int main(
int argc,
char* argv[])
226 bool mInteractive=
false;
227 std::string mSimFile=
"";
228 std::string mDevFile=
"";
230 bool mBreakCondition=
false;
233 std::string mLogFile=
"";
236 bool mResetRequest=
false;
239 for(
int i=1; i<argc; i++) {
240 std::string option(argv[i]);
242 if((option==
"-q") || (option==
"--quiet")) {
247 if((option==
"-qq") || (option==
"--quietquiet")) {
252 if((option==
"-v") || (option==
"--verbose")) {
257 if((option==
"-vv") || (option==
"--verboseverbose")) {
262 if((option==
"-i") || (option==
"--interactive")) {
267 if((option==
"-d") || (option==
"--device")) {
273 if((option==
"-dt") || (option==
"--tolerance")) {
279 if((option==
"-dr") || (option==
"--resetrequest")) {
284 if((option==
"-bc") || (option==
"--breakcondition")) {
285 mBreakCondition=
true;
289 if((option==
"-bt") || (option==
"--breaktime")) {
295 if((option==
"-bs") || (option==
"--breakstep")) {
297 mBreakStep=(int)
ToIdx(argv[i]);
301 if((option==
"-l") || (option==
"--logfile")) {
307 if((option==
"-ls") || (option==
"--logstates")) {
312 if((option==
"-le") || (option==
"--logevents")) {
317 if((option==
"-lt") || (option==
"--logtime")) {
322 if((option==
"-la") || (option==
"--logall")) {
327 if((option==
"-t") || (option==
"--trace")) {
329 mTraceLength=(int)
ToIdx(argv[i]);
333 if((option==
"-?") || (option==
"--help")) {
338 if(option.c_str()[0]==
'-') {
344 usage_exit(
"more than one filname specified" );
353 if(mDevFile!=
"" && mInteractive)
354 usage_exit(
"you must not specify both interactive and synchrone mode");
380 std::cout << std::flush;
381 std::cerr <<
"simfaudes: caught [[" << fe.
Message() <<
"]]" << std::endl;
382 std::cerr <<
"simfaudes: presumably missing/missformed configuration file" << std::endl;
388 std::cout <<
mMark <<
"dumping configuration" << std::endl;
391 std::cout <<
mMark <<
"found generator #" << i+1 <<
397 std::cout <<
mMark <<
"found event attributes for \"" <<
404 std::cout <<
mMark <<
"found simulation condition \"" <<
414 std::cout <<
mMark <<
"generator #" << i+1 << std::endl;
423 if(mLogFile==
"" && mLogMode!=0) {
433 #ifdef FAUDES_PLUGIN_IODEVICE
440 std::cout << std::flush;
441 std::cerr <<
"simfaudes: [[" << fe.
Message() <<
"]]" << std::endl;
442 std::cerr <<
"simfaudes: presumably missing/missformed configuration file" << std::endl;
447 #ifdef FAUDES_NETWORK
448 #ifdef FAUDES_WINDOWS
451 std::cout <<
mMark <<
"Initialze network" << std::endl;
453 if(WSAStartup(MAKEWORD(2,2), &wsaData)!=0) {
454 usage_exit(
"cannot start winsock (network error)");
461 std::cout <<
mMark <<
"Execute via IO device: \""<< dev->
Name() <<
"\"" << std::endl;
472 std::cout <<
mMark <<
"Starting IO device \""<< dev->
Name() <<
"\" Status: " << dev->
StatusString() << std::endl;
476 std::cout <<
mMark <<
"IO device \""<< dev->
Name() <<
"\" is Up" << std::endl;
479 usage_exit(
"cannot load device \""+mDevFile+
"\": device plugin not present");
488 bool mInterTemp=mInteractive;
490 mSatisfied.
Name(
"SatisfiedConditions");
494 std::cout <<
mMark <<
"current state:" << std::endl;
496 std::cout <<
mMark <<
"marking reached:" << std::endl;
504 std::cout <<
mMark <<
"current state:" << std::endl;
509 std::cout <<
mMark <<
"current time:" << std::endl;
515 std::cout <<
mMark <<
"current time:" << std::endl;
525 if(mSatisfied.
Size()>0) {
526 std::cout <<
mMark <<
"found conditions satisfied:" << std::endl;
527 std::cout << mSatisfied.
ToString() << std::endl;
532 std::cout <<
mMark <<
"simulation event states:" << std::endl;
537 std::cout <<
mMark <<
"disabled events (per component):" << std::endl;
545 std::cout <<
mMark <<
"enabled events:" << std::endl;
547 std::cout <<
mMark <<
"enabled interval:" << std::endl;
549 std::cout <<
mMark <<
"enabled time:" << std::endl;
561 if(
mConsoleOut>=-1) std::cout <<
mMark <<
"break condition triggered" << std::endl;
562 mInterTemp=mInteractive;
563 mRunning=mInteractive;
568 if(
mConsoleOut>=-1) std::cout <<
mMark <<
"break time reached" << std::endl;
569 mInterTemp=mInteractive;
570 mRunning=mInteractive;
575 if(
mConsoleOut>=-1) std::cout <<
mMark <<
"break step reached" << std::endl;
576 mInterTemp=mInteractive;
577 mRunning=mInteractive;
581 if(
mConsoleOut>=-1) std::cout <<
mMark <<
"device out of sync" << std::endl;
589 std::cout <<
mMark <<
"proposed action:" << std::endl;
590 if(mPropTrans.
mTime>0)
591 std::cout <<
"<ProposedTime> " <<
ToStringInteger(mPropTrans.
mTime) <<
" </ProposedTime>" << std::endl;
594 if((mPropTrans.
mTime<=0) && (mPropTrans.
mEvent==0) )
595 std::cout <<
"+DeadLock+" << std::endl;
602 std::cout <<
mMark <<
"enter command:" << std::endl;
604 std::getline(std::cin,line);
608 std::istringstream sline(line);
613 std::istringstream schoice(choice);
615 if(!schoice) ichoice=-1;
617 std::istringstream sparam(param);
619 if(!sparam) iparam=-1;
621 std::string nchoice=choice;
622 if(choice.length()>2)
623 if(choice.at(0)==
'"' && choice.at(choice.length()-1)==
'"')
624 nchoice=choice.substr(1,choice.length()-2);
627 if(choice==
"x" || choice ==
"exit") {
630 if(choice==
"p" || choice==
"proposal" || choice==
"") {
635 if(choice==
"r" || choice==
"run") {
638 if(choice==
"v" || choice==
"revert") {
640 if(iparam!=-1) step=iparam;
641 std::cout <<
mMark <<
"revert to step " << step << std::endl;
644 if(choice==
"t" || choice==
"trace") {
645 std::cout <<
mMark <<
"system trace" << std::endl;
656 std::cout <<
mMark <<
"simfaudes interactive mode" << std::endl;
657 std::cout <<
"%" << std::endl;
658 std::cout <<
"% execute time and/or transitions" << std::endl;
659 std::cout <<
"% * <nn> to pass a specified duration <nn> (excl brackets)" << std::endl;
660 std::cout <<
"% * \"event\" to execute an event (incl quotes)" << std::endl;
661 std::cout <<
"% * [P] or [Ret] to execute the recent proPosal " << std::endl;
662 std::cout <<
"%" << std::endl;
663 std::cout <<
"% show trace and revert" << std::endl;
664 std::cout <<
"% * [T] to show a Trace of recent events and states" << std::endl;
665 std::cout <<
"% * [V] <nn> to reVert to step <nn> (obmit <nn> for one step backward) "<< std::endl;
666 std::cout <<
"%" << std::endl;
667 std::cout <<
"% other" << std::endl;
668 std::cout <<
"% * [X] to eXit" << std::endl<< std::endl;
674 if(!mInterTemp && mDevFile==
"") {
679 #ifdef FAUDES_PLUGIN_IODEVICE
685 std::cout <<
mMark <<
"ignoring reset request" << std::endl;
689 std::cout <<
mMark <<
"reset on request" << std::endl;
695 std::cout <<
mMark <<
"sync wait" << std::endl;
703 std::cout <<
mMark <<
"execute event:" << std::endl;
704 std::cout <<
"<ExecutedEvent> \"" <<
mExecutor.
EventName(mEvent) <<
"\" </ExecutedEvent>"
bool Enabled(void) const
Test whether condition is enabled.
SampledDensityFunction mSamplesDuration
Sampled durations, for which this condition remains satisfied.
bool Satisfied(void) const
Test whether the condition is currently satisfied.
SampledDensityFunction mSamplesPeriod
Sampled period, at which this condition becomes satisfied.
static ConsoleOut * G(void)
Acess static instance.
Executer with IO device to handle external/physical events.
bool ExecuteEvent(Idx event)
Execute event.
void Devicep(vDevice *dev)
Set device.
bool IsSynchronous(void) const
Test Syncronisation.
bool SyncTime(void)
Execute generator clock time to sync with device time.
void DeviceStart(void)
Convenience: Start the device.
Idx SyncStep(Time::Type duration=Time::Max())
Execute one transition with synchronous physical signals.
virtual bool DeviceResetRequest(void)
Query the device whther it has received an external reset request.
void ToleranceTime(Time::Type maxgap)
Set tolerance for time synchonisation.
virtual void Reset(long int seed=0)
Reset the DeviceExecutor.
std::string Str(void) const
virtual const char * Message() const
Returns error description.
bool CurrentState(Idx index)
Set discrete state.
const std::string & Name(void) const
Generator name (for convenience)
void Generator(const TimedGenerator &rGen)
Initialise from TimedGenerator.
const EventSet & DisabledEvents() const
Get set of events that are disabled at current (timed) state.
void TraceClear(int length=-2)
Clear buffer and set max buffer.
bool BreakCondition(void) const
Simulation state: true if some break condition is currently satisfied.
void TraceWrite(TokenWriter &rTw, const TraceSample &sample) const
Access buffer: tokenwriter output.
ConditionIterator ConditionsEnd(void) const
Condition iterator: end
const SimConditionSet & Conditions(void) const
Read-only access to simulation conditions.
SimConditionSet::Iterator ConditionIterator
Condition iterator: typedef.
int CurrentStep(void) const
Get logical time, ie number of transitions so far,.
void LogOpen(TokenWriter &rTw, int mode)
Start logging to TokenWriter.
Time::Type CurrentTime(void) const
Get clock time.
ConditionIterator ConditionsBegin(void) const
Condition iterator: begin.
bool CurrentParallelTimedState(const ParallelTimedState &ptstate)
Set current state of the ParallelExecutor.
const AttributeSimCondition & Condition(const std::string &rName) const
Read-only access to a simulation condition by name.
void LogClose(void)
Stop logging.
void SymbolicName(Idx index, const std::string &rName)
Set new name for existing index.
Idx Size(void) const
Number of TimedGenerators.
const EventSet & EnabledEvents() const
Get events that are enabled at current (timed) state.
Idx EventIndex(const std::string &rName) const
Event index lookup.
void Insert(const std::string &rFileName)
Add a TimedGenerator from file.
const TimeInterval & EnabledInterval() const
Get an interval on which the set of enabled events is constant.
const TimeInterval & EnabledTime() const
Get maximal duration that can pass without executing an event.
std::string EventName(Idx index) const
Event name lookup.
const Executor & At(int i) const
void Alphabet(const sEventSet &rAlphabet)
Set all simulation event attributes.
bool ExecuteTime(Time::Type duration)
Execute time duration.
bool RevertToStep(Idx step)
Revert executor to past step.
std::string EventStatesToString(void) const
Inspect stochastic event states (debugging)
const TimedEvent & ProposeNextTransition()
Propose next transition.
Set of simulation named conditions.
virtual bool Insert(const Idx &rIndex)
Add an element by index.
std::string Str(void) const
Pretty printable string.
static Type UnDef(void)
Undefined time value.
Int Type
Datatype for point on time axis.
static Type Max(void)
Maximum time, associated with infinitiy.
A TokenReader reads sequential tokens from a file or string.
bool Peek(Token &token)
Peek next token.
A TokenWriter writes sequential tokens to a file, a string or stdout.
Tokens model atomic data for stream IO.
const std::string & StringValue(void) const
Get string value of a name token.
@ Begin
<label> (begin of section)
TokenType Type(void) const
Get token Type.
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Read configuration data from file with label specified.
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
Write configuration data to a string.
Virtual base class to define the interface for event io.
virtual std::string StatusString(void)
Get status as infromal string.
static void StopAll(void)
Stop all devices.
virtual DeviceState Status(void)
Get status.
static vDevice * FromFile(const std::string &rFileName)
Construct on heap from file.
void Name(const std::string &rName)
Set the device name.
virtual Time::Type CurrentTime(void)
Report physical time in ftu.
virtual void Clear(void)
Clear all set.
const std::string & Name(void) const
Return name of TBaseSet.
Idx Size(void) const
Get Size of TBaseSet.
Includes all libFAUDES headers, incl plugings
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
std::string VersionString()
Return FAUDES_VERSION as std::string.
Idx ToIdx(const std::string &rString)
Convert a string to Idx.
std::string ToStringInteger(Int number)
integer to string
void catch_termsignal(int sig)
int main(int argc, char *argv[])
void simfaudes_exit(void)
void usage_exit(const std::string &message="")