]> gitweb @ CieloNegro.org - bindings-librrd.git/commitdiff
initial revision
authorPHO <pho@cielonegro.org>
Tue, 20 Apr 2010 08:16:18 +0000 (17:16 +0900)
committerPHO <pho@cielonegro.org>
Tue, 20 Apr 2010 08:16:18 +0000 (17:16 +0900)
.gitignore [new file with mode: 0644]
Bindings/Librrd.hsc [new file with mode: 0644]
Bindings/Posix/Time.hsc [new file with mode: 0644]
COPYING [new file with mode: 0644]
GNUmakefile [new file with mode: 0644]
Setup.hs [new file with mode: 0644]
bindings-librrd.cabal [new file with mode: 0644]
cabal-package.mk [new file with mode: 0644]
cbits/inlines.c [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..8fe8ffa
--- /dev/null
@@ -0,0 +1,4 @@
+*.hi
+*.o
+Setup
+dist
\ No newline at end of file
diff --git a/Bindings/Librrd.hsc b/Bindings/Librrd.hsc
new file mode 100644 (file)
index 0000000..1c4c972
--- /dev/null
@@ -0,0 +1,158 @@
+#include <bindings.dsl.h>
+#include <rrd.h>
+
+-- |<http://oss.oetiker.ch/rrdtool/doc/librrd.en.html>
+
+module Bindings.Librrd where
+import Bindings.Posix.Time
+import System.Posix.Types
+#strict_import
+
+-- Formerly rrd_nan_inf.h
+#cinline DNAN, IO CDouble
+#cinline DINF, IO CDouble
+#ccall rrd_set_to_DNAN, IO CDouble
+#ccall rrd_set_to_DINF, IO CDouble
+
+-- Transplanted from rrd_format.h
+#synonym_t rrd_value_t, CDouble
+
+-- Information about an rrd file
+#starttype struct rrd_file_t
+#field header_len, COff
+#field file_len  , COff
+#field pos       , COff
+#field pvt       , Ptr ()
+#stoptype
+
+-- information used for the conventional file access methods
+#starttype struct rrd_simple_file_t
+#field fd        , CInt
+#if HAVE_MMAP
+#field file_start, Ptr CChar
+#field mm_prot   , CInt
+#field mm_flags  , CInt
+#endif
+#stoptype
+
+-- rrd info interface
+#starttype struct rrd_blob_t
+#field size, CULong
+#field ptr , Ptr CUChar
+#stoptype
+
+#integral_t rrd_info_type_t
+#num RD_I_VAL
+#num RD_I_CNT
+#num RD_I_STR
+#num RD_I_INT
+#num RD_I_BLO
+
+#starttype union rrd_infoval
+#union_field u_cnt, CULong
+#union_field u_val, <rrd_value_t>
+#union_field u_str, CString
+#union_field u_int, CInt
+#union_field u_blo, <rrd_blob_t>
+#stoptype
+#synonym_t rrd_infoval_t, <rrd_infoval>
+
+#starttype struct rrd_info_t
+#field key  , CString
+#field type , <rrd_info_type_t>
+#field value, <rrd_infoval_t>
+#field next , Ptr <rrd_info_t>
+#stoptype
+
+{-|The correct type for this callback should be @'Ptr' a -> 'CSize'
+  -> 'Ptr' b -> 'IO' 'CSize'@ but that's impossible because of
+  bindings-DSL restriction.
+ -}
+#callback rrd_output_callback_t, Ptr () -> CSize -> Ptr () -> IO CSize
+
+-- main function blocks
+#ccall   rrd_create      , CInt -> Ptr CString -> IO CInt
+#ccall   rrd_info        , CInt -> Ptr CString -> IO (Ptr <rrd_info_t>)
+#cinline rrd_info_push   , Ptr <rrd_info_t> -> CString -> <rrd_info_type_t> -> Ptr <rrd_infoval_t> -> IO (Ptr <rrd_info_t>)
+#ccall   rrd_info_print  , Ptr <rrd_info_t> -> IO ()
+#ccall   rrd_info_free   , Ptr <rrd_info_t> -> IO ()
+#ccall   rrd_update      , CInt -> Ptr CString -> IO CInt
+#ccall   rrd_update_v    , CInt -> Ptr CString -> IO (Ptr <rrd_info_t>)
+#ccall   rrd_graph       , CInt -> Ptr CString -> Ptr (Ptr CString) -> Ptr CInt -> Ptr CInt -> Ptr CFile -> Ptr CDouble -> Ptr CDouble -> IO CInt
+#ccall   rrd_graph_v     , CInt -> Ptr CString -> IO (Ptr <rrd_info_t>)
+#ccall   rrd_fetch       , CInt -> Ptr CString -> Ptr CTime -> Ptr CTime -> Ptr CULong -> Ptr CULong -> Ptr (Ptr CString) -> Ptr (Ptr <rrd_value_t>) -> IO CInt
+#ccall   rrd_restore     , CInt -> Ptr CString -> IO CInt
+#ccall   rrd_dump        , CInt -> Ptr CString -> IO CInt
+#ccall   rrd_tune        , CInt -> Ptr CString -> IO CInt
+#ccall   rrd_last        , CInt -> Ptr CString -> IO CTime
+#ccall   rrd_lastupdate  , CInt -> Ptr CString -> Ptr CTime -> Ptr CULong -> Ptr (Ptr CString) -> Ptr (Ptr CString) -> IO CInt
+#ccall   rrd_first       , CInt -> Ptr CString -> IO CTime
+#ccall   rrd_resize      , CInt -> Ptr CString -> IO CInt
+#ccall   rrd_strversion  , IO CString
+#ccall   rrd_version     , IO CDouble
+#ccall   rrd_xport       , CInt -> Ptr CString -> Ptr CInt -> Ptr CTime -> Ptr CTime -> Ptr CULong -> Ptr CULong -> Ptr (Ptr CString) -> Ptr (Ptr <rrd_value_t>) -> IO CInt
+#ccall   rrd_flushcached , CInt -> Ptr CString -> IO CInt
+#ccall   rrd_freemem     , Ptr a -> IO ()
+
+-- thread-safe (hopefully)
+#ccall   rrd_create_r    , CString -> CULong -> CTime -> CInt -> Ptr CString -> IO CInt
+-- NOTE: rrd_update_r are only thread-safe if no at-style time
+-- specifications get used!!!
+#ccall   rrd_info_r      , CString -> IO (Ptr <rrd_info_t>)
+#ccall   rrd_update_r    , CString -> CString -> CInt -> Ptr CString -> IO CInt
+#ccall   rrd_fetch_r     , CString -> CString -> Ptr CTime -> Ptr CTime -> Ptr CULong -> Ptr CULong -> Ptr (Ptr CString) -> Ptr (Ptr <rrd_value_t>) -> IO CInt
+#ccall   rrd_dump_r      , CString -> CString -> IO CInt
+#ccall   rrd_last_r      , CString -> IO CTime
+#ccall   rrd_lastupdate_r, CString -> Ptr CTime -> Ptr CULong -> Ptr (Ptr CString) -> Ptr (Ptr CString) -> IO CInt
+#ccall   rrd_first_r     , CString -> CInt -> IO CTime
+
+#ccall   rrd_dump_cb_r   , CString -> CInt -> <rrd_output_callback_t> -> Ptr b -> IO CInt
+
+-- Transplanted from rrd_parsetime.h
+#integral_t rrd_timetype_t
+#num ABSOLUTE_TIME
+#num RELATIVE_TO_START_TIME
+#num RELATIVE_TO_END_TIME
+
+#pointer TIME_OK
+
+#starttype struct rrd_time_value
+#field type  , <rrd_timetype_t>
+#field offset, CLong
+#field tm    , <tm>
+#stoptype
+#synonym_t rrd_time_value_t, <rrd_time_value>
+
+#ccall rrd_parsetime, CString -> Ptr <rrd_time_value_t> -> IO CString
+
+#starttype struct rrd_context
+#array_field lib_errstr, CChar
+#array_field rrd_error , CChar
+#stoptype
+#synonym_t rrd_context_t, <rrd_context>
+
+-- returns the current per-thread rrd_context
+#ccall rrd_get_context, IO (Ptr <rrd_context_t>)
+
+#ccall rrd_proc_start_end, Ptr <rrd_time_value_t> -> Ptr <rrd_time_value_t> -> Ptr CTime -> Ptr CTime -> IO CInt
+
+-- HELPER FUNCTIONS
+-- rrd_set_error() is unavailable as it uses C varargs.
+#ccall rrd_clear_error, IO ()
+#ccall rrd_test_error , IO CInt
+#ccall rrd_get_error  , IO CString
+-- rrd_strerror is thread safe, but still it uses a global buffer (but
+-- one per thread), thus subsequent calls within a single thread
+-- overwrite the same buffer
+#ccall rrd_strerror   , CInt -> IO CString
+
+-- MULTITHREADED HELPER FUNCTIONS
+#ccall rrd_new_context , IO (Ptr <rrd_context_t>)
+#ccall rrd_free_context, Ptr <rrd_context_t> -> IO ()
+
+-- UTILITY FUNCTIONS
+#ccall rrd_random     , IO CLong
+#ccall rrd_add_ptr    , Ptr (Ptr (Ptr a)) -> Ptr CSize -> Ptr a -> IO CInt
+#ccall rrd_add_strdump, Ptr (Ptr CString) -> Ptr CSize -> CString -> IO CInt
+#ccall rrd_free_ptrs  , Ptr (Ptr (Ptr a)) -> CSize -> IO ()
+#ccall rrd_mkdir_p    , CString -> CMode -> IO CInt
\ No newline at end of file
diff --git a/Bindings/Posix/Time.hsc b/Bindings/Posix/Time.hsc
new file mode 100644 (file)
index 0000000..4855480
--- /dev/null
@@ -0,0 +1,30 @@
+#include <bindings.dsl.h>
+#include <time.h>
+
+-- |This module temporarily exists here, only because bindings-posix
+-- currently doesn't have struct tm.
+
+module Bindings.Posix.Time where
+#strict_import
+
+#starttype struct tm
+#field tm_sec , CInt
+#field tm_min , CInt
+#field tm_hour , CInt
+#field tm_mday , CInt
+#field tm_mon , CInt
+#field tm_year , CInt
+#field tm_wday , CInt
+#field tm_yday , CInt
+#field tm_isdst , CInt
+#stoptype
+
+#num CLOCKS_PER_SEC
+
+#ccall clock , IO CClock
+#ccall difftime , CTime -> CTime -> IO CDouble
+#ccall gmtime , Ptr CTime -> IO (Ptr <tm>)
+#ccall localtime , Ptr CTime -> IO (Ptr <tm>)
+#ccall mktime , Ptr <tm> -> IO CTime
+#ccall strftime , CString -> CSize -> CString -> Ptr <tm> -> IO CSize
+#ccall time , Ptr CTime -> IO CTime
diff --git a/COPYING b/COPYING
new file mode 100644 (file)
index 0000000..1a91250
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,29 @@
+<!-- -*- xml -*-
+
+bindings-librrd はパブリックドメインに在ります。
+bindings-librrd is in the public domain.
+
+See http://creativecommons.org/licenses/publicdomain/
+
+-->
+
+<rdf:RDF xmlns="http://web.resource.org/cc/"
+            xmlns:dc="http://purl.org/dc/elements/1.1/"
+            xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+  <Work rdf:about="http://cielonegro.org/Bindings-librrd.html">
+       <dc:title>bindings-librrd</dc:title>
+       <dc:rights>
+      <Agent>
+           <dc:title>PHO</dc:title>
+         </Agent>
+    </dc:rights>
+       <license rdf:resource="http://web.resource.org/cc/PublicDomain" />
+  </Work>
+      
+  <License rdf:about="http://web.resource.org/cc/PublicDomain">
+       <permits rdf:resource="http://web.resource.org/cc/Reproduction" />
+       <permits rdf:resource="http://web.resource.org/cc/Distribution" />
+       <permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
+  </License>
+
+</rdf:RDF>
diff --git a/GNUmakefile b/GNUmakefile
new file mode 100644 (file)
index 0000000..15098cd
--- /dev/null
@@ -0,0 +1,5 @@
+#RUN_COMMAND = $(MAKE) -C examples run
+
+CONFIGURE_ARGS = -O
+
+include cabal-package.mk
diff --git a/Setup.hs b/Setup.hs
new file mode 100644 (file)
index 0000000..f7af188
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,4 @@
+#!/usr/bin/env runhaskell
+
+import Distribution.Simple
+main = defaultMain
diff --git a/bindings-librrd.cabal b/bindings-librrd.cabal
new file mode 100644 (file)
index 0000000..d7d2660
--- /dev/null
@@ -0,0 +1,40 @@
+Name:           bindings-librrd
+Synopsis:       Low level bindings to RRDtool
+Description:
+    RRDtool is a high performance data logging and graphing system for
+    time series data.
+
+    This package provides low-level bindings to librrd, which contains
+    most of the functionality in RRDtool.
+Version:        0.1
+License:        PublicDomain
+License-File:   COPYING
+Author:         PHO <pho at cielonegro dot org>
+Maintainer:     PHO <pho at cielonegro dot org>
+Homepage:       http://cielonegro.org/Bindings-librrd.html
+Category:       FFI
+Tested-With:    GHC == 6.12.1
+Cabal-Version:  >= 1.6
+Build-Type:     Simple
+
+Source-Repository head
+    Type:       git
+    Location:   git://git.cielonegro.org/bindings-librrd.git
+
+Library
+    Build-Depends:
+        base         == 4.2.*,
+        bindings-DSL == 1.0.*
+
+    PkgConfig-Depends:
+        librrd >= 1.4.3
+
+    Extensions:
+        ForeignFunctionInterface
+
+    Exposed-Modules:
+        Bindings.Librrd
+        Bindings.Posix.Time
+
+    C-Sources:
+        cbits/inlines.c
diff --git a/cabal-package.mk b/cabal-package.mk
new file mode 100644 (file)
index 0000000..d8bbaad
--- /dev/null
@@ -0,0 +1,95 @@
+# -*- makefile-gmake -*-
+#
+# Variables:
+#
+#   CONFIGURE_ARGS :: arguments to be passed to ./Setup configure
+#     default: --disable-optimization
+#
+#   RUN_COMMAND :: command to be run for "make run"
+#
+
+GHC      ?= ghc
+FIND     ?= find
+RM_RF    ?= rm -rf
+SUDO     ?= sudo
+AUTOCONF ?= autoconf
+HLINT    ?= hlint
+
+CONFIGURE_ARGS ?= --disable-optimization
+
+SETUP_FILE := $(wildcard Setup.*hs)
+CABAL_FILE := $(wildcard *.cabal)
+
+ifeq ($(shell ls configure.ac 2>/dev/null),configure.ac)
+  AUTOCONF_AC_FILE := configure.ac
+  AUTOCONF_FILE    := configure
+else
+  ifeq ($(shell ls configure.in 2>/dev/null),configure.in)
+    AUTOCONF_AC_FILE := configure.in
+    AUTOCONF_FILE    := configure
+  else
+    AUTOCONF_AC_FILE :=
+    AUTOCONF_FILE    :=
+  endif
+endif
+
+BUILDINFO_IN_FILE := $(wildcard *.buildinfo.in)
+BUILDINFO_FILE    := $(BUILDINFO_IN_FILE:.in=)
+
+all: build
+
+build: setup-config build-hook
+       ./Setup build
+
+build-hook:
+
+ifeq ($(RUN_COMMAND),)
+run:
+       @echo "cabal-package.mk: No command to run."
+       @echo "cabal-package.mk: If you want to run something, define RUN_COMMAND variable."
+else
+run: build
+       @echo ".:.:. Let's go .:.:."
+       $(RUN_COMMAND)
+endif
+
+setup-config: dist/setup-config setup-config-hook $(BUILDINFO_FILE)
+
+setup-config-hook:
+
+dist/setup-config: $(CABAL_FILE) Setup $(AUTOCONF_FILE)
+       ./Setup configure $(CONFIGURE_ARGS)
+
+$(AUTOCONF_FILE): $(AUTOCONF_AC_FILE)
+       $(AUTOCONF)
+
+$(BUILDINFO_FILE): $(BUILDINFO_IN_FILE) configure
+       ./Setup configure $(CONFIGURE_ARGS)
+
+Setup: $(SETUP_FILE)
+       $(GHC) --make Setup
+
+clean: clean-hook
+       $(RM_RF) dist Setup *.o *.hi .setup-config *.buildinfo
+       $(FIND) . -name '*~' -exec rm -f {} \;
+
+clean-hook:
+
+doc: setup-config
+       ./Setup haddock
+
+install: build
+       $(SUDO) ./Setup install
+
+sdist: setup-config
+       ./Setup sdist
+
+test: build
+       ./Setup test
+
+lint:
+       $(HLINT) . --report \
+               --ignore="Use string literal" \
+               --ignore="Use concatMap"
+
+.PHONY: build build-hook setup-config setup-config-hook run clean clean-hook install doc sdist test lint
diff --git a/cbits/inlines.c b/cbits/inlines.c
new file mode 100644 (file)
index 0000000..7f44248
--- /dev/null
@@ -0,0 +1,12 @@
+#include <bindings.cmacros.h>
+#include <rrd.h>
+
+BC_INLINE_(DNAN, double)
+BC_INLINE_(DINF, double)
+
+rrd_info_t*
+inline_rrd_info_push(rrd_info_t * info,
+                     char *key, rrd_info_type_t type, rrd_infoval_t* value) {
+    return rrd_info_push(info, key, type, *value);
+}
+