summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--.gitattributes1
-rw-r--r--src/emu/webengine.c38
-rw-r--r--web/commands.html3
-rw-r--r--web/index.html25
4 files changed, 63 insertions, 4 deletions
diff --git a/.gitattributes b/.gitattributes
index 8474f6bc3a5..011b22393f5 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -8885,6 +8885,7 @@ src/ume/ume.c svneol=native#text/plain
src/ume/ume.lst svneol=native#text/plain
src/ume/ume.mak svneol=native#text/plain
src/version.c svneol=native#text/plain
+web/commands.html svneol=native#text/html
web/css/images/ajax-loader.gif -text
web/css/images/icons-18-black.png -text svneol=unset#image/png
web/css/images/icons-18-white.png -text svneol=unset#image/png
diff --git a/src/emu/webengine.c b/src/emu/webengine.c
index 602144ea577..356bc906a0e 100644
--- a/src/emu/webengine.c
+++ b/src/emu/webengine.c
@@ -69,6 +69,12 @@ int web_engine::websocket_data_handler(struct mg_connection *conn, int flags,
return memcmp(data, "exit", 4);
}
+static void get_qsvar(const struct mg_request_info *request_info,
+ const char *name, char *dst, size_t dst_len) {
+ const char *qs = request_info->query_string;
+ mg_get_var(qs, strlen(qs == NULL ? "" : qs), name, dst, dst_len);
+}
+
// This function will be called by mongoose on every new request.
int web_engine::begin_request_handler(struct mg_connection *conn)
{
@@ -102,7 +108,37 @@ int web_engine::begin_request_handler(struct mg_connection *conn)
return 1;
}
}
- if (!strncmp(request_info->uri, "/screenshot.png",15))
+ else if (!strncmp(request_info->uri, "/cmd",4))
+ {
+ char cmd_name[64];
+ get_qsvar(request_info, "name", cmd_name, sizeof(cmd_name));
+
+ if(!strcmp(cmd_name,"softreset"))
+ {
+ m_machine->schedule_soft_reset();
+ }
+ else if(!strcmp(cmd_name,"hardreset"))
+ {
+ m_machine->schedule_hard_reset();
+ }
+ else if(!strcmp(cmd_name,"exit"))
+ {
+ m_machine->schedule_exit();
+ }
+
+ // Send HTTP reply to the client
+ mg_printf(conn,
+ "HTTP/1.1 200 OK\r\n"
+ "Content-Type: text/plain\r\n"
+ "Content-Length: 2\r\n" // Always set Content-Length
+ "\r\n"
+ "OK");
+
+ // Returning non-zero tells mongoose that our function has replied to
+ // the client, and mongoose should not send client any more data.
+ return 1;
+ }
+ else if (!strncmp(request_info->uri, "/screenshot.png",15))
{
screen_device_iterator iter(m_machine->root_device());
screen_device *screen = iter.first();
diff --git a/web/commands.html b/web/commands.html
new file mode 100644
index 00000000000..1a38f257688
--- /dev/null
+++ b/web/commands.html
@@ -0,0 +1,3 @@
+<a href="javascript:executeCommands('softreset');" data-role="button">Soft reset</a>
+<a href="javascript:executeCommands('hardreset');" data-role="button">Hard reset</a>
+<a href="javascript:executeCommands('exit');" data-role="button">Exit</a>
diff --git a/web/index.html b/web/index.html
index d733b190bb3..0bfda89104d 100644
--- a/web/index.html
+++ b/web/index.html
@@ -23,9 +23,28 @@
function takeScreenshot()
{
- document.getElementById('content').innerHTML = '<center><img src="/screenshot.png"/></center>';
+ document.getElementById('main').innerHTML = '<center><img src="/screenshot.png"/></center>';
}
+ function loadCommands()
+ {
+ $("#main").load('commands.html', function () {
+ $(this).trigger('create');
+ });
+ }
+ function executeCommands(command)
+ {
+ $.ajax({
+ url: "/cmd?name="+command,
+ cache: false,
+ dataType: "text",
+ success: function(data) {
+ },
+ error: function (request, status, error) { alert(status + ", " + error); }
+ });
+ }
+
+
function startWebSocket() {
var url = 'ws://localhost:8080/foo';
websocket = new WebSocket(url);
@@ -85,12 +104,12 @@
<a href="#page1" data-transition="fade" data-icon="grid">Image</a>
</li>
<li>
- <a href="#page1" data-transition="fade" data-icon="star">Commands</a>
+ <a href="javascript:loadCommands();" data-transition="fade" data-icon="star">Commands</a>
</li>
</ul>
</div>
</div>
- <div data-role="content" id ="content">
+ <div data-role="content" id ="main">
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
<div data-role="navbar" data-iconpos="top">