summaryrefslogtreecommitdiff
path: root/code/core/tracepoints.cpp
blob: 7243f1ccb729cdb930ce4457661cc4bbd2637d4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "event.h"
#include "regex.h"

#include "simulate.h"

/* input event streams */

template<class T>
static void FileInputEvent<T>::CreateInputStream(InputInterface<T> *iface) {
  double time = iface->peekNextTime();
  if (time == INFINITY) {
    delete iface;
    return;
  }
  if (time < s.currentTime) {
    DIE("tried to include a file with events of the past");
  }
  s.addEvent(new FileInputEvent(iface, time));
}

template<class T>
void FileInputEvent<T>::vexecute() {
  iface->readFileUntil(time);
  CreateInputStream(iface);
}

/* command loop */

bool executeTracepoints() {
  // the main loop of the program
  char *str = NULL;
  size_t _foo;

  // loop over trace commands
  while (getline(&str, &_foo, stdin) > 0) {
    // parse request
    if (!regex::parseRequest(str))
      DIE("Invalid tracepoint format");

    // proceed time if a run command was given
    if (regex::targetTimeOffset != 0.0) {
      if (!s.proceedTime(s.currentTime + tracepoints::targetTimeOffset))
	fprintf(stderr, "Warning: network is dead\n");
      // reset target time
      targetTimeOffset = 0.0;
      // reset spike output list
      BOOST_FOREARCH(SpikeMUX *i, s.spikeOIfList) { delete i; }
      s.spikeOIfList.empty();
    }


    free(str);
    str = NULL;
  }
  
  return true;
}
contact: Jan Huwald // Impressum