diff mbox

[v2,1/3] python: Add binding for xs_fileno()

Message ID 1506012428-59769-2-git-send-email-euan.harris@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Euan Harris Sept. 21, 2017, 4:47 p.m. UTC
xs_fileno() returns a file descriptor which receives events when Xenstore
watches fire.   Exposing this in the Python bindings is a prerequisite
for writing event-driven clients in Python.

Signed-off-by: Euan Harris <euan.harris@citrix.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
---
 tools/python/xen/lowlevel/xs/xs.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Marek Marczykowski-Górecki Sept. 21, 2017, 6:04 p.m. UTC | #1
On Thu, Sep 21, 2017 at 05:47:06PM +0100, Euan Harris wrote:
> xs_fileno() returns a file descriptor which receives events when Xenstore
> watches fire.   Exposing this in the Python bindings is a prerequisite
> for writing event-driven clients in Python.
> 
> Signed-off-by: Euan Harris <euan.harris@citrix.com>
> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Reviewed-by: Wei Liu <wei.liu2@citrix.com>
> ---
>  tools/python/xen/lowlevel/xs/xs.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/tools/python/xen/lowlevel/xs/xs.c b/tools/python/xen/lowlevel/xs/xs.c
> index aba5a20..9f1b916 100644
> --- a/tools/python/xen/lowlevel/xs/xs.c
> +++ b/tools/python/xen/lowlevel/xs/xs.c
> @@ -453,6 +453,25 @@ static PyObject *xspy_watch(XsHandle *self, PyObject *args)
>  }
>  
>  
> +#define xspy_fileno_doc "\n"                              \
> +	"Return the FD to poll for notifications when watches fire.\n"   \
> +	"Returns: [int] file descriptor.\n"                \
> +	"\n"
> +
> +static PyObject *xspy_fileno(XsHandle *self)
> +{
> +    struct xs_handle *xh = xshandle(self);
> +    int fd;
> +
> +    if (!xh)
> +        return NULL;
> +
> +    fd = xs_fileno(xh);
> +
> +    return PyInt_FromLong(fd);

Use PyLong_FromLong. There is no PyInt_* in py3k. But for convenience we
have #define PyLong_FromLong -> PyInt_FromLong for python 2.

> +}
> +
> +
>  #define xspy_read_watch_doc "\n"				\
>  	"Read a watch notification.\n"				\
>  	"\n"							\
> @@ -887,6 +906,7 @@ static PyMethodDef xshandle_methods[] = {
>      XSPY_METH(release_domain,    METH_VARARGS),
>      XSPY_METH(close,             METH_NOARGS),
>      XSPY_METH(get_domain_path,   METH_VARARGS),
> +    XSPY_METH(fileno,            METH_NOARGS),
>      { NULL /* Sentinel. */ },
>  };
>
diff mbox

Patch

diff --git a/tools/python/xen/lowlevel/xs/xs.c b/tools/python/xen/lowlevel/xs/xs.c
index aba5a20..9f1b916 100644
--- a/tools/python/xen/lowlevel/xs/xs.c
+++ b/tools/python/xen/lowlevel/xs/xs.c
@@ -453,6 +453,25 @@  static PyObject *xspy_watch(XsHandle *self, PyObject *args)
 }
 
 
+#define xspy_fileno_doc "\n"                              \
+	"Return the FD to poll for notifications when watches fire.\n"   \
+	"Returns: [int] file descriptor.\n"                \
+	"\n"
+
+static PyObject *xspy_fileno(XsHandle *self)
+{
+    struct xs_handle *xh = xshandle(self);
+    int fd;
+
+    if (!xh)
+        return NULL;
+
+    fd = xs_fileno(xh);
+
+    return PyInt_FromLong(fd);
+}
+
+
 #define xspy_read_watch_doc "\n"				\
 	"Read a watch notification.\n"				\
 	"\n"							\
@@ -887,6 +906,7 @@  static PyMethodDef xshandle_methods[] = {
     XSPY_METH(release_domain,    METH_VARARGS),
     XSPY_METH(close,             METH_NOARGS),
     XSPY_METH(get_domain_path,   METH_VARARGS),
+    XSPY_METH(fileno,            METH_NOARGS),
     { NULL /* Sentinel. */ },
 };