[rrd-developers] [PATCH 2/2] expose 'rrdtool flush' to bindings/*

kevin brintnall kbrint at rufus.net
Fri Mar 6 20:10:23 CET 2009


---
 bindings/lua/rrdlua.c           |    7 +++++++
 bindings/perl-shared/RRDs.pm    |    1 +
 bindings/perl-shared/RRDs.xs    |   10 ++++++++++
 bindings/python/rrdtoolmodule.c |   29 +++++++++++++++++++++++++++++
 bindings/ruby/main.c            |    8 ++++++++
 bindings/tcl/tclrrd.c           |   25 +++++++++++++++++++++++++
 6 files changed, 80 insertions(+), 0 deletions(-)

diff --git a/bindings/lua/rrdlua.c b/bindings/lua/rrdlua.c
index a5b9fb7..2060f3b 100644
--- a/bindings/lua/rrdlua.c
+++ b/bindings/lua/rrdlua.c
@@ -292,6 +292,12 @@ lua_rrd_graph (lua_State * L)
   return 3;
 }
 
+static int
+lua_rrd_flush(lua_State *L)
+{
+  return rrd_common_call(L, "flush", rrd_cmd_flush);
+}
+
 #if defined(DINF)
 static int
 lua_rrd_info (lua_State * L)
@@ -347,6 +353,7 @@ static const struct luaL_reg rrd[] = {
   {"restore", lua_rrd_restore},
   {"tune", lua_rrd_tune},
   {"update", lua_rrd_update},
+  {"flush", lua_rrd_flush},
 #if defined(DINF)
   {"info", lua_rrd_info},
   {"updatev", lua_rrd_updatev},
diff --git a/bindings/perl-shared/RRDs.pm b/bindings/perl-shared/RRDs.pm
index ba2abfb..3f88c92 100644
--- a/bindings/perl-shared/RRDs.pm
+++ b/bindings/perl-shared/RRDs.pm
@@ -33,6 +33,7 @@ RRDs - Access RRDtool as a shared module
   RRDs::times(start, end)
   RRDs::dump ...
   RRDs::restore ...
+  RRDs::flush ...
 
 =head1 DESCRIPTION
 
diff --git a/bindings/perl-shared/RRDs.xs b/bindings/perl-shared/RRDs.xs
index 25d44a5..3cf1d24 100644
--- a/bindings/perl-shared/RRDs.xs
+++ b/bindings/perl-shared/RRDs.xs
@@ -444,3 +444,13 @@ rrd_restore(...)
        OUTPUT:
                RETVAL
 
+int
+rrd_flush(...)
+	PROTOTYPE: @
+	PREINIT:
+	int i;
+	char **argv;
+	CODE:
+		rrdcode(rrd_cmd_flush);
+	OUTPUT:
+		RETVAL
diff --git a/bindings/python/rrdtoolmodule.c b/bindings/python/rrdtoolmodule.c
index 2771720..bd16da1 100644
--- a/bindings/python/rrdtoolmodule.c
+++ b/bindings/python/rrdtoolmodule.c
@@ -516,6 +516,34 @@ static PyObject *PyRRD_updatev(
     return r;
 }
 
+static char PyRRD_flush__doc__[] =
+  "flush(args..): flush RRD files from memory\n"
+  "   flush [--daemon address] file [file ...]";
+
+static PyObject *PyRRD_flush(
+    PyObject UNUSED(*self),
+    PyObject * args)
+{
+    PyObject *r;
+    int       argc;
+    char    **argv;
+
+    if (create_args("flush", args, &argc, &argv) < 0)
+        return NULL;
+
+    if (rrd_cmd_flush(argc, argv) != 0) {
+        PyErr_SetString(ErrorObject, rrd_get_error());
+        rrd_clear_error();
+        r = NULL;
+    } else {
+        Py_INCREF(Py_None);
+        r = Py_None;
+    }
+
+    destroy_args(&argv);
+    return r;
+}
+
 /* List of methods defined in the module */
 #define meth(name, func, doc) {name, (PyCFunction)func, METH_VARARGS, doc}
 
@@ -531,6 +559,7 @@ static PyMethodDef _rrdtool_methods[] = {
     meth("info", PyRRD_info, PyRRD_info__doc__),
     meth("graphv", PyRRD_graphv, PyRRD_graphv__doc__),
     meth("updatev", PyRRD_updatev, PyRRD_updatev__doc__),
+    meth("flush", PyRRD_flush, PyRRD_flush__doc__),
     {NULL, NULL, 0, NULL}
 };
 
diff --git a/bindings/ruby/main.c b/bindings/ruby/main.c
index 551203b..408994f 100644
--- a/bindings/ruby/main.c
+++ b/bindings/ruby/main.c
@@ -144,6 +144,13 @@ VALUE rb_rrd_update(
     return rrd_call(rrd_update, args);
 }
 
+VALUE rb_rrd_flush(
+    VALUE self,
+    VALUE args)
+{
+    return rrd_call(rrd_cmd_flush, args);
+}
+
 
 /* Calls Returning Data via the Info Interface */
 
@@ -327,6 +334,7 @@ void Init_RRD(
     rb_define_module_function(mRRD, "restore", rb_rrd_restore, -2);
     rb_define_module_function(mRRD, "tune", rb_rrd_tune, -2);
     rb_define_module_function(mRRD, "update", rb_rrd_update, -2);
+    rb_define_module_function(mRRD, "flush", rb_rrd_flush, -2);
     rb_define_module_function(mRRD, "info", rb_rrd_info, -2);
     rb_define_module_function(mRRD, "updatev", rb_rrd_updatev, -2);
     rb_define_module_function(mRRD, "graphv", rb_rrd_graphv, -2);
diff --git a/bindings/tcl/tclrrd.c b/bindings/tcl/tclrrd.c
index 7f604d9..f8a3c84 100644
--- a/bindings/tcl/tclrrd.c
+++ b/bindings/tcl/tclrrd.c
@@ -230,6 +230,30 @@ static int Rrd_Dump(
     return TCL_OK;
 }
 
+/* Thread-safe version */
+static int Rrd_Flush(
+    ClientData __attribute__((unused)) clientData,
+    Tcl_Interp *interp,
+    int argc,
+    CONST84 char *argv[])
+{
+    if (argc < 2) {
+        Tcl_AppendResult(interp, "RRD Error: needs rrd filename",
+                         (char *) NULL);
+        return TCL_ERROR;
+    }
+
+    rrd_cmd_flush(argc, (char**)argv);
+
+    if (rrd_test_error()) {
+        Tcl_AppendResult(interp, "RRD Error: ",
+                         rrd_get_error(), (char *) NULL);
+        rrd_clear_error();
+        return TCL_ERROR;
+    }
+
+    return TCL_OK;
+}
 
 
 /* Thread-safe version */
@@ -626,6 +650,7 @@ typedef struct {
 static CmdInfo rrdCmds[] = {
     {"Rrd::create", Rrd_Create, 1}, /* Thread-safe version */
     {"Rrd::dump", Rrd_Dump, 0}, /* Thread-safe version */
+    {"Rrd::flush", Rrd_Flush, 0},
     {"Rrd::last", Rrd_Last, 0}, /* Thread-safe version */
     {"Rrd::lastupdate", Rrd_Lastupdate, 0}, /* Thread-safe version */
     {"Rrd::update", Rrd_Update, 1}, /* Thread-safe version */
-- 
1.6.1.3



More information about the rrd-developers mailing list