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);
45 } /* }}} class Collectd */
47 public abstract class Value /* {{{ */
49 public abstract long toLong ();
50 public abstract double toDouble ();
51 } /* }}} class Value */
53 public class gaugeValue: Value /* {{{ */
55 private double _value;
57 public gaugeValue (double v)
62 public override long toLong () { return ((long) this._value); }
63 public override double toDouble () { return (this._value); }
64 } /* }}} class gaugeValue */
66 public class deriveValue: Value /* {{{ */
70 public deriveValue (long v)
75 public override long toLong () { return (this._value); }
76 public override double toDouble () { return ((double) this._value); }
77 } /* }}} class deriveValue */
79 public class Identifier /* {{{ */
81 protected string _host;
82 protected string _plugin;
83 protected string _pluginInstance;
84 protected string _type;
85 protected string _typeInstance;
87 public Identifier (string host,
88 string plugin, string pluginInstance,
89 string type, string typeInstance)
92 this._plugin = plugin;
93 this._pluginInstance = pluginInstance;
95 this._typeInstance = typeInstance;
98 public string getHost () { return (this._host); }
99 public string getPlugin () { return (this._plugin); }
100 public string getPluginInstance () { return (this._pluginInstance); }
101 public string getType () { return (this._type); }
102 public string getTypeInstance () { return (this._typeInstance); }
104 public void setHost (string s) { this._host = s; }
105 public void setPlugin (string s) { this._plugin = s; }
106 public void setPluginInstance (string s) { this._pluginInstance = s; }
107 public void setType (string s) { this._type = s; }
108 public void setTypeInstance (string s) { this._typeInstance = s; }
109 } /* }}} class Identifier */
111 public class ValueList: Identifier /* {{{ */
113 protected double _time;
114 protected double _interval;
115 protected IList _values;
117 public ValueList (string host,
118 string plugin, string pluginInstance,
119 string type, string typeInstance)
120 :base (host, plugin, pluginInstance, type, typeInstance)
122 this._interval = 10.0;
123 this._values = new ArrayList ();
124 this.setTime (DateTime.Now);
127 public IList getValues ()
129 return (this._values);
132 public void setValues (IList values)
134 this._values = new ArrayList (values);
137 public void addValue (Value v)
139 this._values.Add (v);
142 public void clearValues ()
144 this._values.Clear ();
147 public double getInterval ()
149 return (this._interval);
152 public void setInterval (double interval)
155 this._interval = interval;
158 public double getTime ()
163 public void setTime (DateTime dt)
165 DateTime dtBase = new DateTime (1970,1,1,0,0,0);
166 TimeSpan tsDiff = dt.ToUniversalTime () - dtBase;
168 this._time = (double) tsDiff.TotalSeconds;
171 public void setTime (double t)
176 } /* }}} class ValueList */
179 /* vim: set sw=2 sts=2 et fdm=marker : */