From 961c8d924a7472cb1165cf57dadb8ebbb4f9da51 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Thu, 15 Aug 2013 08:57:26 +0000 Subject: Implemented first commands for web interface (nw) --- .gitattributes | 1 + src/emu/webengine.c | 38 +++++++++++++++++++++++++++++++++++++- web/commands.html | 3 +++ web/index.html | 25 ++++++++++++++++++++++--- 4 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 web/commands.html 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 @@ +Soft reset +Hard reset +Exit 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 = '
'; + document.getElementById('main').innerHTML = '
'; } + 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 @@ Image
  • - Commands + Commands
  • -
    +
    -- cgit v1.2.3-70-g09d2