2 * collectd - bindings/csharp/collectd.cs
3 * Copyright (C) 2010 Florian Forster
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Florian Forster <ff at octo.it>
28 using System.Collections;
29 using System.Runtime.CompilerServices;
33 public interface IRead /* {{{ */
36 } /* }}} interface IRead */
38 public class Collectd /* {{{ */
40 [MethodImplAttribute(MethodImplOptions.InternalCall)]
41 public extern static int log (int severity, string message);
43 [MethodImplAttribute(MethodImplOptions.InternalCall)]
44 public extern static int registerRead (string name, IRead obj);
46 [MethodImplAttribute(MethodImplOptions.InternalCall)]
47 public extern static int dispatchValues (ValueList vl);
48 } /* }}} class Collectd */
50 public abstract class Value /* {{{ */
52 public abstract long toLong ();
53 public abstract double toDouble ();
54 } /* }}} class Value */
56 public class gaugeValue: Value /* {{{ */
58 private double _value;
60 public gaugeValue (double v)
65 public override long toLong () { return ((long) this._value); }
66 public override double toDouble () { return (this._value); }
67 } /* }}} class gaugeValue */
69 public class deriveValue: Value /* {{{ */
73 public deriveValue (long v)
78 public override long toLong () { return (this._value); }
79 public override double toDouble () { return ((double) this._value); }
80 } /* }}} class deriveValue */
82 public class Identifier /* {{{ */
84 protected string _host;
85 protected string _plugin;
86 protected string _pluginInstance;
87 protected string _type;
88 protected string _typeInstance;
90 public Identifier (string host,
91 string plugin, string pluginInstance,
92 string type, string typeInstance)
95 this._plugin = plugin;
96 this._pluginInstance = pluginInstance;
98 this._typeInstance = typeInstance;
101 public string getHost () { return (this._host); }
102 public string getPlugin () { return (this._plugin); }
103 public string getPluginInstance () { return (this._pluginInstance); }
104 public string getType () { return (this._type); }
105 public string getTypeInstance () { return (this._typeInstance); }
107 public void setHost (string s) { this._host = s; }
108 public void setPlugin (string s) { this._plugin = s; }
109 public void setPluginInstance (string s) { this._pluginInstance = s; }
110 public void setType (string s) { this._type = s; }
111 public void setTypeInstance (string s) { this._typeInstance = s; }
112 } /* }}} class Identifier */
114 public class ValueList: Identifier /* {{{ */
116 protected double _time;
117 protected double _interval;
118 protected IList _values;
120 public ValueList (string host,
121 string plugin, string pluginInstance,
122 string type, string typeInstance)
123 :base (host, plugin, pluginInstance, type, typeInstance)
125 this._interval = 10.0;
126 this._values = new ArrayList ();
127 this.setTime (DateTime.Now);
130 public IList getValues ()
132 return (this._values);
135 public void setValues (IList values)
137 this._values = new ArrayList (values);
140 public void addValue (Value v)
142 this._values.Add (v);
145 public void clearValues ()
147 this._values.Clear ();
150 public double getInterval ()
152 return (this._interval);
155 public void setInterval (double interval)
158 this._interval = interval;
161 public double getTime ()
166 public void setTime (DateTime dt)
168 DateTime dtBase = new DateTime (1970,1,1,0,0,0);
169 TimeSpan tsDiff = dt.ToUniversalTime () - dtBase;
171 this._time = (double) tsDiff.TotalSeconds;
174 public void setTime (double t)
179 } /* }}} class ValueList */
182 /* vim: set sw=2 sts=2 et fdm=marker : */