397e75bee2ef191c0e2e34f8e69fc22cc3a1e182
[collectd.git] / bindings / csharp / collectd.cs
1 /**
2  * collectd - bindings/csharp/collectd.cs
3  * Copyright (C) 2010  Florian Forster
4  *
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:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
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.
22  *
23  * Authors:
24  *   Florian Forster <ff at octo.it>
25  **/
26
27 using System;
28 using System.Collections;
29 using System.Runtime.CompilerServices;
30
31 namespace CollectdAPI
32 {
33   public interface IRead /* {{{ */
34   {
35     int read ();
36   } /* }}} interface IRead */
37
38   public class Collectd /* {{{ */
39   {
40     [MethodImplAttribute(MethodImplOptions.InternalCall)]
41       public extern static int log (int severity, string message);
42
43     [MethodImplAttribute(MethodImplOptions.InternalCall)]
44       public extern static int registerRead (string name, IRead obj);
45   } /* }}} class Collectd */
46
47   public abstract class Value /* {{{ */
48   {
49     public abstract long toLong ();
50     public abstract double toDouble ();
51   } /* }}} class Value */
52
53   public class gaugeValue: Value /* {{{ */
54   {
55     private double _value;
56
57     public gaugeValue (double v)
58     {
59       this._value = v;
60     }
61
62     public override long toLong () { return ((long) this._value); }
63     public override double toDouble () { return (this._value); }
64   } /* }}} class gaugeValue */
65
66   public class deriveValue: Value /* {{{ */
67   {
68     private long _value;
69
70     public deriveValue (long v)
71     {
72       this._value = v;
73     }
74
75     public override long toLong () { return (this._value); }
76     public override double toDouble () { return ((double) this._value); }
77   } /* }}} class deriveValue */
78
79   public class Identifier /* {{{ */
80   {
81     protected string _host;
82     protected string _plugin;
83     protected string _pluginInstance;
84     protected string _type;
85     protected string _typeInstance;
86
87     public Identifier (string host,
88         string plugin, string pluginInstance,
89         string type, string typeInstance)
90     {
91       this._host = host;
92       this._plugin = plugin;
93       this._pluginInstance = pluginInstance;
94       this._type = type;
95       this._typeInstance = typeInstance;
96     } /* Identifier() */
97
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);   }
103
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 */
110
111   public class ValueList: Identifier /* {{{ */
112   {
113     protected double _time;
114     protected double _interval;
115     protected IList  _values;
116     
117     public ValueList (string host,
118         string plugin, string pluginInstance,
119         string type, string typeInstance)
120       :base (host, plugin, pluginInstance, type, typeInstance)
121     {
122       this._interval = 10.0;
123       this._values = new ArrayList ();
124       this.setTime (DateTime.Now);
125     }
126
127     public IList getValues ()
128     {
129       return (this._values);
130     }
131
132     public void setValues (IList values)
133     {
134       this._values = new ArrayList (values);
135     }
136
137     public void addValue (Value v)
138     {
139       this._values.Add (v);
140     }
141
142     public void clearValues ()
143     {
144       this._values.Clear ();
145     }
146
147     public double getInterval ()
148     {
149       return (this._interval);
150     }
151
152     public void setInterval (double interval)
153     {
154       if (interval > 0.0)
155         this._interval = interval;
156     }
157
158     public double getTime ()
159     {
160       return (this._time);
161     }
162
163     public void setTime (DateTime dt)
164     {
165       DateTime dtBase = new DateTime (1970,1,1,0,0,0);
166       TimeSpan tsDiff = dt.ToUniversalTime () - dtBase;
167
168       this._time = (double) tsDiff.TotalSeconds;
169     }
170
171     public void setTime (double t)
172     {
173       if (t > 0.0)
174         this._time = t;
175     }
176   } /* }}} class ValueList */
177 }
178
179 /* vim: set sw=2 sts=2 et fdm=marker : */