Skip to content

Commit

Permalink
Merge pull request tklab-tud#163 from tklab-tud/sradomski
Browse files Browse the repository at this point in the history
DOM with Lua DataModel and dropped V8
  • Loading branch information
sradomski authored Jul 19, 2017
2 parents 4a9b497 + e0a7e43 commit 998e624
Show file tree
Hide file tree
Showing 29 changed files with 5,541 additions and 1,271 deletions.
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,13 @@ OPTION(WITH_DM_ECMA_V8 "Do search for the V8 ECMAScript implementation" ON)
if (WITH_DM_ECMA_V8)
find_package(V8)
if (V8_FOUND)
set(ECMA_FOUND ON)
include_directories(${V8_INCLUDE_DIR})
list (APPEND USCXML_OPT_LIBS ${V8_LIBRARY})
# set(ECMA_FOUND ON)
# include_directories(${V8_INCLUDE_DIR})
# list (APPEND USCXML_OPT_LIBS ${V8_LIBRARY})

message(WARNING "We no longer support the V8 ECMAScript engine - contributions are welcome")
set(V8_FOUND OFF)
set(WITH_DM_ECMA_V8 OFF)
else()
set(WITH_DM_ECMA_V8 OFF)
endif()
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#### Quick Links

- [Building from source](http://tklab-tud.github.io/uscxml/building.html)
- [Changes](docs/CHANGES.md)
- [Tests passed](test/w3c/TESTS.md)
- [Publications](docs/PUBLICATIONS.md)
- [Benchmarks](docs/BENCHMARKS.md)
Expand Down Expand Up @@ -50,6 +49,12 @@ For more detailled information, refer to the [documentation](http://tklab-tud.gi

### Embedded as a Library
uscxml::Interpreter scxml = uscxml::Interpreter::fromURL("...");
scxml.on().enterState([](const std::string& sessionId,
const std::string& stateName,
const xercesc_3_1::DOMElement* state) {
std::cout << "Entered " << stateName << std::endl;
});

while(scxml.step() != uscxml::USCXML_FINISHED) {
...
}
Expand All @@ -74,11 +79,15 @@ For more detailled information, refer to the [documentation](http://tklab-tud.gi
**Examples:**

* [test-gen-c.cpp](https://github.com/tklab-tud/uscxml/blob/master/test/src/test-gen-c.cpp) (**C++**)
* [WaterPump.cxx](https://github.com/tklab-tud/uscxml/blob/master/src/apps/arduino/WaterPump.cxx) (**C++ on Arduino**)
* [WaterPump.cxx](https://github.com/tklab-tud/uscxml/blob/master/examples/cpp/transpiled/arduino/WaterPump.cxx) (**C++ on Arduino**)


## Changes

* **[9db80409b3ca048c4b404a43d2c224f374c0090a](https://github.com/tklab-tud/uscxml/pull/163/commits/9db80409b3ca048c4b404a43d2c224f374c0090a):**

We **dropped support for Google's V8 ECMAScript engine**. The API is changing too fast and there is no reliable way to get / build / identify older versions. The latest branch will not work with the wrappers generated from even SWIG 4.0 and I have no time to keep up with them. Use JavaScriptCore, its API is unchanged since we started to support it in 2012. If you feel capable to maintain the [](V8DataModel.cpp) send a push request. Everything will be left in place but we will ignore `libv8` at configure time. I may have another look when a number of Linux distribution settled on a more recent version, most are still shipping v8 in version 3.14.

* **[bfefa5fd44b9ed1491612f26b099db8ad624247b](https://github.com/tklab-tud/uscxml/pull/155/commits/bfefa5fd44b9ed1491612f26b099db8ad624247b):**

We **broke the InterpreterMonitor** API by substituting the Interpreter instance in the first formal parameter by its sessionId throughout all callbacks. Retrieving the actual Interpreter involved locking a weak_ptr into a shared_ptr which proved to be a performance bottleneck. You can retrieve the Interpreter from its sessionId via the new static method `Interpreter::fromSessionId` if you actually need.
Expand Down
1 change: 0 additions & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Arraybuffers
PGO
124 changes: 62 additions & 62 deletions src/apps/uscxml-browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,32 @@ int main(int argc, char** argv) {
InterpreterOptions::printUsageAndExit(argv[0]);
}

if (!options.validate) {
// setup HTTP server
HTTPServer::SSLConfig* sslConf = NULL;
if (options.certificate.length() > 0) {
sslConf = new HTTPServer::SSLConfig();
sslConf->privateKey = options.certificate;
sslConf->publicKey = options.certificate;
sslConf->port = options.httpsPort;

} else if (options.privateKey.length() > 0 && options.publicKey.length() > 0) {
sslConf = new HTTPServer::SSLConfig();
sslConf->privateKey = options.privateKey;
sslConf->publicKey = options.publicKey;
sslConf->port = options.httpsPort;

}
HTTPServer::getInstance(options.httpPort, options.wsPort, sslConf);
}
if (options.pluginPath.length() > 0) {
Factory::setDefaultPluginPath(options.pluginPath);
}
if (options.verbose) {
Factory::getInstance()->listComponents();
}
if (!options.validate) {
// setup HTTP server
HTTPServer::SSLConfig* sslConf = NULL;
if (options.certificate.length() > 0) {
sslConf = new HTTPServer::SSLConfig();
sslConf->privateKey = options.certificate;
sslConf->publicKey = options.certificate;
sslConf->port = options.httpsPort;

} else if (options.privateKey.length() > 0 && options.publicKey.length() > 0) {
sslConf = new HTTPServer::SSLConfig();
sslConf->privateKey = options.privateKey;
sslConf->publicKey = options.publicKey;
sslConf->port = options.httpsPort;

}
HTTPServer::getInstance(options.httpPort, options.wsPort, sslConf);
}

if (options.pluginPath.length() > 0) {
Factory::setDefaultPluginPath(options.pluginPath);
}

if (options.verbose) {
Factory::getInstance()->listComponents();
}

// instantiate and configure interpreters
std::list<Interpreter> interpreters;
Expand All @@ -73,7 +73,7 @@ int main(int argc, char** argv) {
if (issues.size() == 0) {
LOGD(USCXML_DEBUG) << "No issues found" << std::endl;
}

}

if (options.verbose) {
Expand All @@ -92,41 +92,41 @@ int main(int argc, char** argv) {
}
}

if (options.validate) {
return EXIT_SUCCESS;
}
if (options.withDebugger) {
DebuggerServlet* debugger;
debugger = new DebuggerServlet();
debugger->copyToInvokers(true);
HTTPServer::getInstance()->registerServlet("/debug", debugger);
for (auto interpreter : interpreters) {
interpreter.addMonitor(debugger);
}
}
if (options.validate) {
return EXIT_SUCCESS;
}

if (options.withDebugger) {
DebuggerServlet* debugger;
debugger = new DebuggerServlet();
debugger->copyToInvokers(true);
HTTPServer::getInstance()->registerServlet("/debug", debugger);
for (auto interpreter : interpreters) {
interpreter.addMonitor(debugger);
}
}

// run interpreters
if (interpreters.size() > 0) {
try {
std::list<Interpreter>::iterator interpreterIter = interpreters.begin();
while (interpreters.size() > 0) {
while(interpreterIter != interpreters.end()) {
InterpreterState state = interpreterIter->step();
if (state == USCXML_FINISHED) {
interpreterIter = interpreters.erase(interpreterIter);
} else {
interpreterIter++;
}
}
interpreterIter = interpreters.begin();
}
} catch (Event e) {
LOGD(USCXML_ERROR) << e << std::endl;
}
} else if (options.withDebugger) {
while(true)
std::this_thread::sleep_for(std::chrono::seconds(1));
}
if (interpreters.size() > 0) {
try {
std::list<Interpreter>::iterator interpreterIter = interpreters.begin();
while (interpreters.size() > 0) {
while(interpreterIter != interpreters.end()) {
InterpreterState state = interpreterIter->step();
if (state == USCXML_FINISHED) {
interpreterIter = interpreters.erase(interpreterIter);
} else {
interpreterIter++;
}
}
interpreterIter = interpreters.begin();
}
} catch (Event e) {
LOGD(USCXML_ERROR) << e << std::endl;
}
} else if (options.withDebugger) {
while(true)
std::this_thread::sleep_for(std::chrono::seconds(1));
}
return EXIT_SUCCESS;
}
102 changes: 51 additions & 51 deletions src/apps/uscxml-transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ void printUsageAndExit(const char* progName) {
printf("Options\n");
printf("\t-t c : convert to C program\n");
printf("\t-t pml : convert to spin/promela program\n");
printf("\t-t vhdl : convert to VHDL hardware description\n");
printf("\t-t java : convert to Java classes\n");
printf("\t-t vhdl : convert to VHDL hardware description\n");
printf("\t-t java : convert to Java classes\n");
printf("\t-t flat : flatten to SCXML state-machine\n");
printf("\t-a FILE : write annotated SCXML document for transformation\n");
printf("\t-X {PARAMETER} : pass additional parameters to the transformation\n");
Expand All @@ -60,8 +60,8 @@ int main(int argc, char** argv) {
bool verbose = false;
std::string outType;
std::string pluginPath;
std::string inputFile;
std::string annotatedFile;
std::string inputFile;
std::string annotatedFile;
std::string outputFile;
std::list<std::string> options;
std::multimap<std::string, std::string> extensions;
Expand Down Expand Up @@ -112,7 +112,7 @@ int main(int argc, char** argv) {
inputFile = optarg;
break;
case 'a':
annotatedFile = optarg;
annotatedFile = optarg;
break;
case 'X': {
std::list<std::string> extension = tokenize(optarg, '=');
Expand All @@ -125,7 +125,7 @@ int main(int argc, char** argv) {
break;
case 'o':
outputFile = optarg;
extensions.insert(std::pair<std::string, std::string>("outputFile", outputFile));
extensions.insert(std::pair<std::string, std::string>("outputFile", outputFile));
break;
case 'l':
break;
Expand Down Expand Up @@ -190,8 +190,8 @@ int main(int argc, char** argv) {
outType != "scxml" &&
outType != "pml" &&
outType != "c" &&
outType != "vhdl" &&
outType != "java" &&
outType != "vhdl" &&
outType != "java" &&
outType != "min" &&
std::find(options.begin(), options.end(), "priority") == options.end() &&
std::find(options.begin(), options.end(), "domain") == options.end() &&
Expand All @@ -218,7 +218,7 @@ int main(int argc, char** argv) {
ss << line;
}
URL tmp("anonymous.scxml");
tmp = URL::resolveWithCWD(tmp);
tmp = URL::resolveWithCWD(tmp);
interpreter = Interpreter::fromXML(ss.str(), tmp);
} else {
interpreter = Interpreter::fromURL(inputFile);
Expand All @@ -231,8 +231,8 @@ int main(int argc, char** argv) {

if (!interpreter) {
URL tmp(inputFile);
tmp = URL::resolveWithCWD(tmp);
std::string content = tmp.getInContent();
tmp = URL::resolveWithCWD(tmp);
std::string content = tmp.getInContent();

std::string inlineBeginMarker = "INLINE SCXML BEGIN\n";
std::string inlineEndMarker = "\nINLINE SCXML END";
Expand Down Expand Up @@ -267,12 +267,12 @@ int main(int argc, char** argv) {
}
}

Transformer transformer;
Transformer transformer;
if (outType == "c") {
transformer = ChartToC::transform(interpreter);
transformer.setExtensions(extensions);
transformer.setOptions(options);

if (outputFile.size() == 0 || outputFile == "-") {
transformer.writeTo(std::cout);
} else {
Expand All @@ -283,25 +283,25 @@ int main(int argc, char** argv) {
}
}

if (outType == "java") {
transformer = ChartToJava::transform(interpreter);
transformer.setExtensions(extensions);
transformer.setOptions(options);
if (outputFile.size() == 0 || outputFile == "-") {
transformer.writeTo(std::cout);
} else {
std::ofstream outStream;
outStream.open(outputFile.c_str());
transformer.writeTo(outStream);
outStream.close();
}
}
if (outType == "java") {
transformer = ChartToJava::transform(interpreter);
transformer.setExtensions(extensions);
transformer.setOptions(options);

if (outputFile.size() == 0 || outputFile == "-") {
transformer.writeTo(std::cout);
} else {
std::ofstream outStream;
outStream.open(outputFile.c_str());
transformer.writeTo(outStream);
outStream.close();
}
}

if (outType == "vhdl") {
transformer = ChartToVHDL::transform(interpreter);
transformer.setExtensions(extensions);
transformer.setOptions(options);
transformer = ChartToVHDL::transform(interpreter);
transformer.setExtensions(extensions);
transformer.setOptions(options);

if (outputFile.size() == 0 || outputFile == "-") {
transformer.writeTo(std::cout);
Expand All @@ -314,18 +314,18 @@ int main(int argc, char** argv) {
}

if (outType == "pml") {
transformer = ChartToPromela::transform(interpreter);
transformer.setExtensions(extensions);
transformer.setOptions(options);
if (outputFile.size() == 0 || outputFile == "-") {
transformer.writeTo(std::cout);
} else {
std::ofstream outStream;
outStream.open(outputFile.c_str());
transformer.writeTo(outStream);
outStream.close();
}
transformer = ChartToPromela::transform(interpreter);
transformer.setExtensions(extensions);
transformer.setOptions(options);

if (outputFile.size() == 0 || outputFile == "-") {
transformer.writeTo(std::cout);
} else {
std::ofstream outStream;
outStream.open(outputFile.c_str());
transformer.writeTo(outStream);
outStream.close();
}
}

// if (outType == "tex") {
Expand Down Expand Up @@ -364,22 +364,22 @@ int main(int argc, char** argv) {
// exit(EXIT_SUCCESS);
// }

if (annotatedFile.size() > 0) {
std::ofstream outStream;
outStream.open(annotatedFile.c_str());
outStream << (*transformer.getImpl()->getDocument());
outStream.close();
if (annotatedFile.size() > 0) {
std::ofstream outStream;
outStream.open(annotatedFile.c_str());
outStream << (*transformer.getImpl()->getDocument());
outStream.close();

}
}


} catch (Event e) {
std::cout << e << std::endl;
return EXIT_FAILURE;
return EXIT_FAILURE;
} catch (const std::exception &e) {
std::cout << e.what() << std::endl;
return EXIT_FAILURE;
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
return EXIT_SUCCESS;
}
Loading

0 comments on commit 998e624

Please sign in to comment.