ChangeSet 1.1713.1.25, 2005/06/17 18:57:29+01:00, cl349@xxxxxxxxxxxxxxxxxxxx
xs.c:
Fix some oversights in watch/token code.
Cleanup whitespace.
Move method documentation next to method definition.
Reorder functions in file.
Signed-off-by: Mike Wray <mike.wray@xxxxxx>
Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>
xs.c | 296 ++++++++++++++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 215 insertions(+), 81 deletions(-)
diff -Nru a/tools/python/xen/lowlevel/xs/xs.c
b/tools/python/xen/lowlevel/xs/xs.c
--- a/tools/python/xen/lowlevel/xs/xs.c 2005-06-17 21:03:56 -04:00
+++ b/tools/python/xen/lowlevel/xs/xs.c 2005-06-17 21:03:56 -04:00
@@ -52,35 +52,13 @@
: PyErr_SetFromErrno(PyExc_RuntimeError));
}
-static PyObject *xspy_write(PyObject *self, PyObject *args, PyObject *kwds)
-{
- static char *kwd_spec[] = { "path", "data", "create", "excl", NULL };
- static char *arg_spec = "ss#|ii";
- char *path = NULL;
- char *data = NULL;
- int data_n = 0;
- int create = 0;
- int excl = 0;
-
- struct xs_handle *xh = xshandle(self);
- PyObject *val = NULL;
- int flags = 0;
- int xsval = 0;
-
- if (!xh)
- goto exit;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
- &path, &data, &data_n, &create, &excl))
- goto exit;
- if (create)
- flags |= O_CREAT;
- if (excl)
- flags |= O_EXCL;
- xsval = xs_write(xh, path, data, data_n, flags);
- val = pyvalue_int(xsval);
- exit:
- return val;
-}
+#define xspy_read_doc "\n" \
+ "Read data from a path.\n" \
+ " path [string]: xenstore path\n" \
+ "\n" \
+ "Returns: [string] data read.\n" \
+ "Raises RuntimeError on error.\n" \
+ "\n"
static PyObject *xspy_read(PyObject *self, PyObject *args, PyObject *kwds)
{
@@ -110,26 +88,55 @@
return val;
}
-static PyObject *xspy_mkdir(PyObject *self, PyObject *args, PyObject *kwds)
+#define xspy_write_doc "\n" \
+ "Write data to a path.\n" \
+ " path [string] : xenstore path to write to\n." \
+ " data [string] : data to write.\n" \
+ " create [int] : create flag, default 0.\n" \
+ " excl [int] : exclusive flag, default 0.\n" \
+ "\n" \
+ "Returns: [int] 0 on success.\n" \
+ "Raises RuntimeError on error.\n" \
+ "\n"
+
+static PyObject *xspy_write(PyObject *self, PyObject *args, PyObject *kwds)
{
- static char *kwd_spec[] = { "path", NULL };
- static char *arg_spec = "s|";
+ static char *kwd_spec[] = { "path", "data", "create", "excl", NULL };
+ static char *arg_spec = "ss#|ii";
char *path = NULL;
+ char *data = NULL;
+ int data_n = 0;
+ int create = 0;
+ int excl = 0;
struct xs_handle *xh = xshandle(self);
PyObject *val = NULL;
+ int flags = 0;
int xsval = 0;
if (!xh)
goto exit;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
+ &path, &data, &data_n, &create, &excl))
goto exit;
- xsval = xs_mkdir(xh, path);
+ if (create)
+ flags |= O_CREAT;
+ if (excl)
+ flags |= O_EXCL;
+ xsval = xs_write(xh, path, data, data_n, flags);
val = pyvalue_int(xsval);
exit:
return val;
}
+#define xspy_ls_doc "\n" \
+ "List a directory.\n" \
+ " path [string]: path to list.\n" \
+ "\n" \
+ "Returns: [string array] list of subdirectory names.\n" \
+ "Raises RuntimeError on error.\n" \
+ "\n"
+
static PyObject *xspy_ls(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *kwd_spec[] = { "path", NULL };
@@ -158,6 +165,41 @@
return val;
}
+#define xspy_mkdir_doc "\n" \
+ "Make a directory.\n" \
+ " path [string]: path to directory to create.\n" \
+ "\n" \
+ "Returns: [int] 0 on success.\n" \
+ "Raises RuntimeError on error.\n" \
+ "\n"
+
+static PyObject *xspy_mkdir(PyObject *self, PyObject *args, PyObject *kwds)
+{
+ static char *kwd_spec[] = { "path", NULL };
+ static char *arg_spec = "s|";
+ char *path = NULL;
+
+ struct xs_handle *xh = xshandle(self);
+ PyObject *val = NULL;
+ int xsval = 0;
+
+ if (!xh)
+ goto exit;
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
+ goto exit;
+ xsval = xs_mkdir(xh, path);
+ val = pyvalue_int(xsval);
+ exit:
+ return val;
+}
+
+#define xspy_rm_doc "\n" \
+ "Remove a path.\n" \
+ " path [string] : path to remove\n" \
+ "Returns: [int] 0 on success.\n" \
+ "Raises RuntimeError on error.\n" \
+ "\n"
+
static PyObject *xspy_rm(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *kwd_spec[] = { "path", NULL };
@@ -178,6 +220,14 @@
return val;
}
+#define xspy_get_permissions_doc "\n" \
+ "Get the permissions for a path\n" \
+ " path [string]: xenstore path.\n" \
+ "\n" \
+ "Returns: permissions array.\n" \
+ "Raises RuntimeError on error.\n" \
+ "\n"
+
static PyObject *xspy_get_permissions(PyObject *self, PyObject *args,
PyObject *kwds)
{
@@ -214,6 +264,15 @@
return val;
}
+#define xspy_set_permissions_doc "\n" \
+ "Set the permissions for a path\n" \
+ " path [string] : xenstore path.\n" \
+ " perms : permissions.\n" \
+ "\n" \
+ "Returns: [int] 0 on success.\n" \
+ "Raises RuntimeError on error.\n" \
+ "\n"
+
static PyObject *xspy_set_permissions(PyObject *self, PyObject *args,
PyObject *kwds)
{
@@ -280,13 +339,22 @@
return val;
}
+#define xspy_watch_doc "\n" \
+ "Watch a path, get notifications when it changes.\n" \
+ " path [string] : xenstore path.\n" \
+ " token [string] : returned in watch notification\n" \
+ "\n" \
+ "Returns: [int] 0 on success.\n" \
+ "Raises RuntimeError on error.\n" \
+ "\n"
+
static PyObject *xspy_watch(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *kwd_spec[] = { "path", "priority", "token", NULL };
static char *arg_spec = "s|is";
char *path = NULL;
int priority = 0;
- char *token;
+ char *token = "";
struct xs_handle *xh = xshandle(self);
PyObject *val = NULL;
@@ -303,6 +371,14 @@
return val;
}
+#define xspy_read_watch_doc "\n" \
+ "Read a watch notification.\n" \
+ " path [string]: xenstore path.\n" \
+ "\n" \
+ "Returns: [tuple] (path, token).\n" \
+ "Raises RuntimeError on error.\n" \
+ "\n"
+
static PyObject *xspy_read_watch(PyObject *self, PyObject *args,
PyObject *kwds)
{
@@ -318,7 +394,7 @@
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec))
goto exit;
xsval = xs_read_watch(xh);
- if(!xsval){
+ if (!xsval) {
val = PyErr_SetFromErrno(PyExc_RuntimeError);
goto exit;
}
@@ -330,12 +406,20 @@
return val;
}
+#define xspy_acknowledge_watch_doc "\n"
\
+ "Acknowledge a watch notification that has been read.\n" \
+ " token [string] : returned in watch notification\n" \
+ "\n" \
+ "Returns: [int] 0 on success.\n" \
+ "Raises RuntimeError on error.\n" \
+ "\n"
+
static PyObject *xspy_acknowledge_watch(PyObject *self, PyObject *args,
PyObject *kwds)
{
- static char *kwd_spec[] = { NULL };
+ static char *kwd_spec[] = { "token", NULL };
static char *arg_spec = "s";
- char *token = "";
+ char *token;
struct xs_handle *xh = xshandle(self);
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|