14 static const char*
const LIRCRC_ID =
"lircd.lircrc";
18 static PyObject* client_lirc_init(PyObject *
self, PyObject *args)
24 if (!PyArg_ParseTuple(args,
"s", &prog))
28 PyErr_SetString(PyExc_RuntimeError,
29 "Cannot open lircd socket");
32 intval = Py_BuildValue(
"i", r);
38 static PyObject* client_lirc_deinit(PyObject *
self, PyObject *args)
44 return PyErr_SetFromErrno(PyExc_OSError);
45 return Py_BuildValue(
"i", r);
50 static PyObject* client_lirc_readconfig(PyObject *
self, PyObject *args)
57 if (!PyArg_ParseTuple(args,
"s", &path))
59 if (access(path, R_OK) != 0) {
60 snprintf(text,
sizeof(text),
"Cannot open %s for read", path);
61 PyErr_SetString(PyExc_RuntimeError, text);
65 PyErr_SetString(PyExc_RuntimeError,
66 "Cannot parse lircrc file");
69 lircrc = PyCapsule_New(config, LIRCRC_ID, NULL);
75 static PyObject* client_lirc_freeconfig(PyObject *
self, PyObject *args)
80 if (!PyArg_ParseTuple(args,
"O", &lircrc))
82 config = PyCapsule_GetPointer(lircrc, LIRCRC_ID);
92 static PyObject* client_lirc_code2char(PyObject *
self, PyObject *args)
102 PyObject* list = PyList_New(0);
105 if (!PyArg_ParseTuple(args,
"Oss", &lircrc, &program, &code)) {
106 PyErr_SetString(PyExc_RuntimeError,
"Cannot parse arguments");
109 config = PyCapsule_GetPointer(lircrc, LIRCRC_ID);
110 for (i = 0; i < 10; i += 1) {
112 if (r != 0 || s == NULL || !*s)
114 string = Py_BuildValue(
"s", s);
117 PyExc_RuntimeError,
"Cannot decode string");
121 if (PyList_Append(list,
string) == -1) {
122 PyErr_SetString(PyExc_RuntimeError,
123 "Cannot append string");
134 PyMethodDef ClientMethods[] = {
135 {
"lirc_init", client_lirc_init, METH_VARARGS,
136 "initiate lirc connection"},
137 {
"lirc_deinit", client_lirc_deinit, METH_VARARGS,
138 "close lirc connection opened by lirc_init()"},
139 {
"lirc_readconfig", client_lirc_readconfig, METH_VARARGS,
140 "parse a lircrc file"},
141 {
"lirc_freeconfig", client_lirc_freeconfig, METH_VARARGS,
142 "Deallocate memory obtained using lirc_readconfig()"},
143 {
"lirc_code2char", client_lirc_code2char, METH_VARARGS,
144 "lircrc-translate a keypress"},
149 static struct PyModuleDef clientmodule = {
150 PyModuleDef_HEAD_INIT,
158 PyMODINIT_FUNC PyInit__client(
void)
160 return PyModule_Create(&clientmodule);
int lirc_init(const char *prog, int verbose)
Initial setup: connect to lircd socket.
int lirc_code2char(struct lirc_config *config, char *code, char **string)
Translate a code string to an application string using .lircrc.
int lirc_readconfig(const char *file, struct lirc_config **config, int(check)(char *s))
Parse a lircrc configuration file.
void lirc_freeconfig(struct lirc_config *config)
Deallocate an object retrieved using lirc_readconfig().
3-rd party application interface.
int lirc_deinit(void)
Release resources allocated by lirc_init(), basically disconnect from socket.