2019-12-09 13:29:37 -07:00
|
|
|
#define PY_SSIZE_T_CLEAN
|
|
|
|
#include <Python.h>
|
|
|
|
#include "scode.h"
|
2019-12-09 13:33:23 -07:00
|
|
|
#include "log.h"
|
2019-12-09 13:29:37 -07:00
|
|
|
#include "msg_queue.h"
|
|
|
|
#include "sysinput.h"
|
|
|
|
#include "ep_upiwin.h"
|
|
|
|
#include "ep_init.h"
|
|
|
|
|
2019-12-09 13:33:23 -07:00
|
|
|
static HRESULT convert_msg(PyObject *target, PMSG source)
|
2019-12-09 13:29:37 -07:00
|
|
|
{
|
|
|
|
PyObject *attr;
|
|
|
|
|
2019-12-09 13:33:23 -07:00
|
|
|
ASSERT(PyDict_CheckExact(target));
|
2019-12-09 13:29:37 -07:00
|
|
|
PyDict_Clear(target);
|
|
|
|
attr = PyLong_FromUnsignedLong(source->target);
|
|
|
|
if (!attr)
|
|
|
|
return E_FAIL;
|
|
|
|
if (PyDict_SetItemString(target, "target", attr))
|
|
|
|
return E_FAIL;
|
|
|
|
attr = PyLong_FromUnsignedLong(source->message);
|
|
|
|
if (!attr)
|
|
|
|
return E_FAIL;
|
|
|
|
if (PyDict_SetItemString(target, "message", attr))
|
|
|
|
return E_FAIL;
|
|
|
|
attr = Py_BuildValue("[k,k]", source->attrs[0], source->attrs[1]);
|
|
|
|
if (!attr)
|
|
|
|
return E_FAIL;
|
|
|
|
if (PyDict_SetItemString(target, "attrs", attr))
|
|
|
|
return E_FAIL;
|
|
|
|
attr = PyLong_FromUnsignedLongLong(source->timestamp);
|
|
|
|
if (!attr)
|
|
|
|
return E_FAIL;
|
|
|
|
if (PyDict_SetItemString(target, "timestamp", attr))
|
|
|
|
return E_FAIL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *Epython_get_message(PyObject *self, PyObject *args)
|
|
|
|
{
|
2019-12-09 13:34:49 -07:00
|
|
|
PyObject *out;
|
2019-12-09 13:29:37 -07:00
|
|
|
MSG msg;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &out))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* release the GIL to allow us to block waiting for input if necessary */
|
|
|
|
Py_BEGIN_ALLOW_THREADS
|
|
|
|
while (!Mq_peek(Sys_Queue, &msg, PEEK_REMOVE))
|
|
|
|
Sys_wait_for_input();
|
|
|
|
Py_END_ALLOW_THREADS
|
|
|
|
|
|
|
|
if (FAILED(convert_msg(out, &msg)))
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "could not convert received message");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return PyBool_FromLong(msg.message != WM_QUIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *Epython_post_quit_message(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
INT32 exitcode;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "i", &exitcode))
|
|
|
|
return NULL;
|
|
|
|
Sys_Exit_Code = exitcode;
|
2019-12-09 13:33:23 -07:00
|
|
|
Mq_post1(Sys_Queue, 0, WM_QUIT, exitcode);
|
2019-12-09 13:29:37 -07:00
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|