From: Florian Forster Date: Mon, 29 Nov 2010 15:33:00 +0000 (+0100) Subject: dotnet plugin: Some C# glue code. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=695695b1d6cd49aafb3808d20b1bf90e61451a1c;p=collectd.git dotnet plugin: Some C# glue code. --- diff --git a/bindings/csharp/collectd.cs b/bindings/csharp/collectd.cs new file mode 100644 index 00000000..b79676e5 --- /dev/null +++ b/bindings/csharp/collectd.cs @@ -0,0 +1,160 @@ +/** + * collectd - bindings/csharp/collectd.cs + * Copyright (C) 2010 Florian Forster + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Florian Forster + **/ + +using System; +using System.Collections; +using System.Runtime.CompilerServices; + +namespace CollectdAPI +{ + public interface IRead /* {{{ */ + { + int read (); + } /* }}} interface IRead */ + + public class Collectd /* {{{ */ + { + [MethodImplAttribute(MethodImplOptions.InternalCall)] + public extern static int log (int severity, string message); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + public extern static int registerRead (string name, IRead obj); + } /* }}} class Collectd */ + + public abstract class Value /* {{{ */ + { + public abstract long toLong (); + public abstract double toDouble (); + } /* }}} class Value */ + + public class gaugeValue: Value /* {{{ */ + { + private double _value; + + public gaugeValue (double v) + { + this._value = v; + } + + public override long toLong () { return ((long) this._value); } + public override double toDouble () { return (this._value); } + } /* }}} class gaugeValue */ + + public class deriveValue: Value /* {{{ */ + { + private long _value; + + public deriveValue (long v) + { + this._value = v; + } + + public override long toLong () { return (this._value); } + public override double toDouble () { return ((double) this._value); } + } /* }}} class deriveValue */ + + public class Identifier /* {{{ */ + { + protected string _host; + protected string _plugin; + protected string _pluginInstance; + protected string _type; + protected string _typeInstance; + + public Identifier (string host, + string plugin, string pluginInstance, + string type, string typeInstance) + { + this._host = host; + this._plugin = plugin; + this._pluginInstance = pluginInstance; + this._type = type; + this._typeInstance = typeInstance; + } /* Identifier() */ + + string getHost () { return (this._host); } + string getPlugin () { return (this._plugin); } + string getPluginInstance () { return (this._pluginInstance); } + string getType () { return (this._type); } + string getTypeInstance () { return (this._typeInstance); } + + void setHost (string s) { this._host = s; } + void setPlugin (string s) { this._plugin = s; } + void setPluginInstance (string s) { this._pluginInstance = s; } + void setType (string s) { this._type = s; } + void setTypeInstance (string s) { this._typeInstance = s; } + } /* }}} class Identifier */ + + public class ValueList: Identifier /* {{{ */ + { + protected double _time; + protected double _interval; + protected ArrayList _values; + + public ValueList (string host, + string plugin, string pluginInstance, + string type, string typeInstance) + :base (host, plugin, pluginInstance, type, typeInstance) + { + this._time = 0.0; + this._interval = 10.0; + this._values = new ArrayList (); + } + + public ArrayList getValues () + { + return (this._values); + } + + public void setValues (ArrayList values) + { + this._values = values; + } + + public void addValue (Value v) + { + this._values.Add (v); + } + + public void clearValues () + { + this._values.Clear (); + } + + public double getInterval () + { + return (this._interval); + } + + public void setInterval (double interval) + { + if (interval > 0.0) + this._interval = interval; + } + } /* }}} class ValueList */ +} + +/* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/bindings/csharp/test.cs b/bindings/csharp/test.cs new file mode 100644 index 00000000..15449ee5 --- /dev/null +++ b/bindings/csharp/test.cs @@ -0,0 +1,28 @@ +using CollectdAPI; + +public class EmbedTest: IRead +{ + public EmbedTest () + { + System.Console.WriteLine ("EmbedTest ();"); + Collectd.registerRead ("EmbedTest::read", this); + } + + public int read () + { + ValueList vl = new ValueList ("host", "plugin", "pinst", "type", "tinst"); + + vl.setInterval (10.0); + vl.addValue (new gaugeValue (3.1337)); + + System.Console.WriteLine ("EmbedTest::read ();"); + Collectd.log (42, "Hello World!"); + return (0); + } + + public static void Main() + { + System.Console.WriteLine("Hello, World!"); + } +} +