mirror of
https://github.com/mamedev/mame.git
synced 2024-11-16 07:48:32 +01:00
Implemented first commands for web interface (nw)
This commit is contained in:
parent
db65236016
commit
961c8d924a
4 changed files with 63 additions and 4 deletions
1
.gitattributes
vendored
1
.gitattributes
vendored
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
3
web/commands.html
Normal file
3
web/commands.html
Normal file
|
@ -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>
|
|
@ -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">
|
||||
|
|
Loading…
Reference in a new issue