From: PHO Date: Tue, 20 Apr 2010 08:16:18 +0000 (+0900) Subject: initial revision X-Git-Tag: RELEASE-0.1~1 X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=bindings-librrd.git;a=commitdiff_plain;h=11431e2090eb04af77645232df98dea64303736b initial revision --- 11431e2090eb04af77645232df98dea64303736b diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8fe8ffa --- /dev/null +++ b/.gitignore @@ -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 index 0000000..1c4c972 --- /dev/null +++ b/Bindings/Librrd.hsc @@ -0,0 +1,158 @@ +#include +#include + +-- | + +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, +#union_field u_str, CString +#union_field u_int, CInt +#union_field u_blo, +#stoptype +#synonym_t rrd_infoval_t, + +#starttype struct rrd_info_t +#field key , CString +#field type , +#field value, +#field next , Ptr +#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 ) +#cinline rrd_info_push , Ptr -> CString -> -> Ptr -> IO (Ptr ) +#ccall rrd_info_print , Ptr -> IO () +#ccall rrd_info_free , Ptr -> IO () +#ccall rrd_update , CInt -> Ptr CString -> IO CInt +#ccall rrd_update_v , CInt -> Ptr CString -> IO (Ptr ) +#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 ) +#ccall rrd_fetch , CInt -> Ptr CString -> Ptr CTime -> Ptr CTime -> Ptr CULong -> Ptr CULong -> Ptr (Ptr CString) -> Ptr (Ptr ) -> 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 ) -> 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 ) +#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 ) -> 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 -> -> 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 , +#field offset, CLong +#field tm , +#stoptype +#synonym_t rrd_time_value_t, + +#ccall rrd_parsetime, CString -> Ptr -> IO CString + +#starttype struct rrd_context +#array_field lib_errstr, CChar +#array_field rrd_error , CChar +#stoptype +#synonym_t rrd_context_t, + +-- returns the current per-thread rrd_context +#ccall rrd_get_context, IO (Ptr ) + +#ccall rrd_proc_start_end, Ptr -> Ptr -> 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 ) +#ccall rrd_free_context, Ptr -> 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 index 0000000..4855480 --- /dev/null +++ b/Bindings/Posix/Time.hsc @@ -0,0 +1,30 @@ +#include +#include + +-- |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 ) +#ccall localtime , Ptr CTime -> IO (Ptr ) +#ccall mktime , Ptr -> IO CTime +#ccall strftime , CString -> CSize -> CString -> Ptr -> IO CSize +#ccall time , Ptr CTime -> IO CTime diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..1a91250 --- /dev/null +++ b/COPYING @@ -0,0 +1,29 @@ + + + + + bindings-librrd + + + PHO + + + + + + + + + + + + diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..15098cd --- /dev/null +++ b/GNUmakefile @@ -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 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 index 0000000..d7d2660 --- /dev/null +++ b/bindings-librrd.cabal @@ -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 +Maintainer: PHO +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 index 0000000..d8bbaad --- /dev/null +++ b/cabal-package.mk @@ -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 index 0000000..7f44248 --- /dev/null +++ b/cbits/inlines.c @@ -0,0 +1,12 @@ +#include +#include + +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); +} +