// file access #include #include #include #include #include #include #include #include "interface.h" #include "log.h" #include "simulate.h" #include "tracepoints.h" #include "global.h" #include "neuron.h" #include "synapse.h" #include "spike.h" #include "regex.h" // pollute seperate namespace with regex expressions namespace tracepoints { using namespace boost::xpressive; /* parser result variables */ std::set intSet; std::set stringSet; double targetTimeOffset = 0.0; std::string filename; bool ioDirection; // tue -> write; false -> read bool ioBinary; /* parser callback implementations */ struct push_impl { typedef void result_type; // Result type, needed for tr1::result_of template void operator()(Set &s, Value const &val) const { s.insert(val); } }; function::type const push = {{}}; /* I/O interface launcher */ template struct start_interface_impl { typedef void result_type; // Result type, needed for tr1::result_of void operator() () const { // open src/dst file int fd = open(filename.c_str, write ? (O_WRONLY | O_APPEND | O_CREAT) : (O_RDONLY | O_NONBLOCK)); if (fd == -1) DIE("could not open file"); // execute task if (ioDirection) { // write if (boost::is_same::value) { // create a persistent interface to write out spikes as they occur s.spikeOIfList.push_back(new OutputInterface(fd, ioBinary, stringSet, intSet)); }else{ // create a temporary interface to write out any state OutputInterface oif(fd, ioBinary, stringSet, intSet); oif.pushClass(); close(fd); } }else{ // read // create long living input interface (terminates itself when EOF is discovered) FileInputEvent::createInputStream(new InputInterface(fd, ioBinary, stringSet, intSet)); } // clean up vars for next command ioBinary = false; stringSet.empty(); intSet.empty(); } }; function >::type const start_interface_global = {{}}; function >::type const start_interface_neuron = {{}}; function >::type const start_interface_synapse = {{}}; function >::type const start_interface_spike = {{}}; /* regex pattern definitions */ // character sets cregex Delim = as_xpr(';'); cregex VarNameChar = alnum | as_xpr('_'); // basic elements cregex Time = (+_d >> !('.' >> +_d))[ ref(targetOffseTime)=as(_) ]; cregex Index = (+_d)[ push(as(_)) ]; cregex Element = (+varnamechar)[ push(as(_)) ]; cregex Filename = (+varnamechar)[ ref(filename)=(_) ]; cregex IODirWrite = as_xpr('>') [ ref(ioDirection)=true ]; cregex IODirRead = as_xpr('>') [ ref(ioDirection)=false ]; cregex IODirection = IODirWrite | IODirRead; cregex IOBinaryTrue = as_xpr('#') [ ref(ioBinary)=true ]; cregex IOBinary = !IOBinaryTrue; cregex IOCmd = IOBinary >> IODirection >> Filename; // lists cregex ObjectListInner = *space >> (s1= index) >> *space; cregex ObjectList = *space >> '(' >> object_list_inner >> *( delim >> object_list_inner ) >> ')'; cregex ElementListInner = *space >> (s1= element) >> *space; cregex ElementList = *space >> '{' >> element_list_inner >> *( delim >> element_list_inner ) >> '}'; // trace commands cregex TraceCmdTail = *space >> !ElementList >> *space >> !ObjectList >> *space >> IOCmd; cregex TraceGlobal = (icase( "global" ) >> TraceCmdTail [ start_interface_global() ]; cregex TraceNeuron = (icase( "neuron" ) >> TraceCmdTail [ start_interface_neuron() ]; cregex TraceSynapse = (icase( "synapse" ) >> TraceCmdTail [ start_interface_synapse() ]; cregex TraceSpike = (icase( "spike" ) >> TraceCmdTail [ start_interface_spike() ]; // whole line // target format what // cregex channel = *space >> +delim >> *space >> ( neuron | synapse | global | spikes ); // cregex traceline = time >> *channel >> *( delim | space ); cregex traceLine = !icase("proceed") >> +space >> time; cregex line = *space >> *(inputElem | outputElem | traceElem) >> *( delim | space )); bool parseRequest(char *str) { return regex_match(str, line); } };