]> gitweb @ CieloNegro.org - bindings-librrd.git/blob - Bindings/Librrd.hsc
fixed typo: rrd_add_strdump => rrd_add_strdup
[bindings-librrd.git] / Bindings / Librrd.hsc
1 #include <bindings.dsl.h>
2 #include <rrd.h>
3
4 -- |<http://oss.oetiker.ch/rrdtool/doc/librrd.en.html>
5
6 module Bindings.Librrd where
7 import Bindings.Posix.Time
8 import System.Posix.Types
9 #strict_import
10
11 -- Formerly rrd_nan_inf.h
12 #cinline DNAN, IO CDouble
13 #cinline DINF, IO CDouble
14 #ccall rrd_set_to_DNAN, IO CDouble
15 #ccall rrd_set_to_DINF, IO CDouble
16
17 -- Transplanted from rrd_format.h
18 #synonym_t rrd_value_t, CDouble
19
20 -- Information about an rrd file
21 #starttype struct rrd_file_t
22 #field header_len, COff
23 #field file_len  , COff
24 #field pos       , COff
25 #field pvt       , Ptr ()
26 #stoptype
27
28 -- information used for the conventional file access methods
29 #starttype struct rrd_simple_file_t
30 #field fd        , CInt
31 #if HAVE_MMAP
32 #field file_start, Ptr CChar
33 #field mm_prot   , CInt
34 #field mm_flags  , CInt
35 #endif
36 #stoptype
37
38 -- rrd info interface
39 #starttype struct rrd_blob_t
40 #field size, CULong
41 #field ptr , Ptr CUChar
42 #stoptype
43
44 #integral_t rrd_info_type_t
45 #num RD_I_VAL
46 #num RD_I_CNT
47 #num RD_I_STR
48 #num RD_I_INT
49 #num RD_I_BLO
50
51 #starttype union rrd_infoval
52 #union_field u_cnt, CULong
53 #union_field u_val, <rrd_value_t>
54 #union_field u_str, CString
55 #union_field u_int, CInt
56 #union_field u_blo, <rrd_blob_t>
57 #stoptype
58 #synonym_t rrd_infoval_t, <rrd_infoval>
59
60 #starttype struct rrd_info_t
61 #field key  , CString
62 #field type , <rrd_info_type_t>
63 #field value, <rrd_infoval_t>
64 #field next , Ptr <rrd_info_t>
65 #stoptype
66
67 {-|The correct type for this callback should be @'Ptr' a -> 'CSize'
68   -> 'Ptr' b -> 'IO' 'CSize'@ but that's impossible because of
69   bindings-DSL restriction.
70  -}
71 #callback rrd_output_callback_t, Ptr () -> CSize -> Ptr () -> IO CSize
72
73 -- main function blocks
74 #ccall   rrd_create      , CInt -> Ptr CString -> IO CInt
75 #ccall   rrd_info        , CInt -> Ptr CString -> IO (Ptr <rrd_info_t>)
76 #cinline rrd_info_push   , Ptr <rrd_info_t> -> CString -> <rrd_info_type_t> -> Ptr <rrd_infoval_t> -> IO (Ptr <rrd_info_t>)
77 #ccall   rrd_info_print  , Ptr <rrd_info_t> -> IO ()
78 #ccall   rrd_info_free   , Ptr <rrd_info_t> -> IO ()
79 #ccall   rrd_update      , CInt -> Ptr CString -> IO CInt
80 #ccall   rrd_update_v    , CInt -> Ptr CString -> IO (Ptr <rrd_info_t>)
81 #ccall   rrd_graph       , CInt -> Ptr CString -> Ptr (Ptr CString) -> Ptr CInt -> Ptr CInt -> Ptr CFile -> Ptr CDouble -> Ptr CDouble -> IO CInt
82 #ccall   rrd_graph_v     , CInt -> Ptr CString -> IO (Ptr <rrd_info_t>)
83 #ccall   rrd_fetch       , CInt -> Ptr CString -> Ptr CTime -> Ptr CTime -> Ptr CULong -> Ptr CULong -> Ptr (Ptr CString) -> Ptr (Ptr <rrd_value_t>) -> IO CInt
84 #ccall   rrd_restore     , CInt -> Ptr CString -> IO CInt
85 #ccall   rrd_dump        , CInt -> Ptr CString -> IO CInt
86 #ccall   rrd_tune        , CInt -> Ptr CString -> IO CInt
87 #ccall   rrd_last        , CInt -> Ptr CString -> IO CTime
88 #ccall   rrd_lastupdate  , CInt -> Ptr CString -> Ptr CTime -> Ptr CULong -> Ptr (Ptr CString) -> Ptr (Ptr CString) -> IO CInt
89 #ccall   rrd_first       , CInt -> Ptr CString -> IO CTime
90 #ccall   rrd_resize      , CInt -> Ptr CString -> IO CInt
91 #ccall   rrd_strversion  , IO CString
92 #ccall   rrd_version     , IO CDouble
93 #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
94 #ccall   rrd_flushcached , CInt -> Ptr CString -> IO CInt
95 #ccall   rrd_freemem     , Ptr a -> IO ()
96
97 -- thread-safe (hopefully)
98 #ccall   rrd_create_r    , CString -> CULong -> CTime -> CInt -> Ptr CString -> IO CInt
99 -- NOTE: rrd_update_r are only thread-safe if no at-style time
100 -- specifications get used!!!
101 #ccall   rrd_info_r      , CString -> IO (Ptr <rrd_info_t>)
102 #ccall   rrd_update_r    , CString -> CString -> CInt -> Ptr CString -> IO CInt
103 #ccall   rrd_fetch_r     , CString -> CString -> Ptr CTime -> Ptr CTime -> Ptr CULong -> Ptr CULong -> Ptr (Ptr CString) -> Ptr (Ptr <rrd_value_t>) -> IO CInt
104 #ccall   rrd_dump_r      , CString -> CString -> IO CInt
105 #ccall   rrd_last_r      , CString -> IO CTime
106 #ccall   rrd_lastupdate_r, CString -> Ptr CTime -> Ptr CULong -> Ptr (Ptr CString) -> Ptr (Ptr CString) -> IO CInt
107 #ccall   rrd_first_r     , CString -> CInt -> IO CTime
108
109 #ccall   rrd_dump_cb_r   , CString -> CInt -> <rrd_output_callback_t> -> Ptr b -> IO CInt
110
111 -- Transplanted from rrd_parsetime.h
112 #integral_t rrd_timetype_t
113 #num ABSOLUTE_TIME
114 #num RELATIVE_TO_START_TIME
115 #num RELATIVE_TO_END_TIME
116
117 #pointer TIME_OK
118
119 #starttype struct rrd_time_value
120 #field type  , <rrd_timetype_t>
121 #field offset, CLong
122 #field tm    , <tm>
123 #stoptype
124 #synonym_t rrd_time_value_t, <rrd_time_value>
125
126 #ccall rrd_parsetime, CString -> Ptr <rrd_time_value_t> -> IO CString
127
128 #starttype struct rrd_context
129 #array_field lib_errstr, CChar
130 #array_field rrd_error , CChar
131 #stoptype
132 #synonym_t rrd_context_t, <rrd_context>
133
134 -- returns the current per-thread rrd_context
135 #ccall rrd_get_context, IO (Ptr <rrd_context_t>)
136
137 #ccall rrd_proc_start_end, Ptr <rrd_time_value_t> -> Ptr <rrd_time_value_t> -> Ptr CTime -> Ptr CTime -> IO CInt
138
139 -- HELPER FUNCTIONS
140 -- rrd_set_error() is unavailable as it uses C varargs.
141 #ccall rrd_clear_error, IO ()
142 #ccall rrd_test_error , IO CInt
143 #ccall rrd_get_error  , IO CString
144 -- rrd_strerror is thread safe, but still it uses a global buffer (but
145 -- one per thread), thus subsequent calls within a single thread
146 -- overwrite the same buffer
147 #ccall rrd_strerror   , CInt -> IO CString
148
149 -- MULTITHREADED HELPER FUNCTIONS
150 #ccall rrd_new_context , IO (Ptr <rrd_context_t>)
151 #ccall rrd_free_context, Ptr <rrd_context_t> -> IO ()
152
153 -- UTILITY FUNCTIONS
154 #ccall rrd_random    , IO CLong
155 #ccall rrd_add_ptr   , Ptr (Ptr (Ptr a)) -> Ptr CSize -> Ptr a -> IO CInt
156 #ccall rrd_add_strdup, Ptr (Ptr CString) -> Ptr CSize -> CString -> IO CInt
157 #ccall rrd_free_ptrs , Ptr (Ptr (Ptr a)) -> CSize -> IO ()
158 #ccall rrd_mkdir_p   , CString -> CMode -> IO CInt