OSDN Git Service

Added plugin attribute class, and marked plugins with meta data.
authorLatif Khalifa <latifer@streamgrid.net>
Sun, 21 Mar 2010 00:48:10 +0000 (00:48 +0000)
committerLatif Khalifa <latifer@streamgrid.net>
Sun, 21 Mar 2010 00:48:10 +0000 (00:48 +0000)
git-svn-id: https://radegast.googlecode.com/svn/trunk@536 f7a694da-4d33-11de-9ad6-1127a62b9fcd

Radegast/Core/PluginInterface/IRadegastPlugin.cs
Radegast/Core/PluginInterface/PluginAttribute.cs [new file with mode: 0644]
Radegast/Core/PluginInterface/PluginManager.cs
Radegast/Radegast.csproj
plugins/Radegast.Plugin.Alice/Alice.cs
plugins/Radegast.Plugin.Demo/DemoPlugin.cs
plugins/Radegast.Plugin.Speech/RadSpeech/PluginControl.cs

index 335d995..d35ee2f 100644 (file)
@@ -1,8 +1,50 @@
+// 
+// Radegast Metaverse Client
+// Copyright (c) 2009, Radegast Development Team
+// All rights reserved.
+// 
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// 
+//     * Redistributions of source code must retain the above copyright notice,
+//       this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above copyright
+//       notice, this list of conditions and the following disclaimer in the
+//       documentation and/or other materials provided with the distribution.
+//     * Neither the name of the application "Radegast", nor the names of its
+//       contributors may be used to endorse or promote products derived from
+//       this software without specific prior written permission.
+// 
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// $Id$
+//
 namespace Radegast
 {
+    /// <summary>
+    /// Interface of Radegast plugins
+    /// </summary>
     public interface IRadegastPlugin
     {
+        /// <summary>
+        /// Called in plugin initialization
+        /// </summary>
+        /// <param name="inst">RadegastInstance plugin is loaded into</param>
         void StartPlugin(RadegastInstance inst);
+
+        /// <summary>
+        /// Called on plugin shutdown
+        /// </summary>
+        /// <param name="inst">RadegastInstance plugin is unloaded from</param>
         void StopPlugin(RadegastInstance inst);
     }
-}
\ No newline at end of file
+}
diff --git a/Radegast/Core/PluginInterface/PluginAttribute.cs b/Radegast/Core/PluginInterface/PluginAttribute.cs
new file mode 100644 (file)
index 0000000..743f75e
--- /dev/null
@@ -0,0 +1,49 @@
+// 
+// Radegast Metaverse Client
+// Copyright (c) 2009, Radegast Development Team
+// All rights reserved.
+// 
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// 
+//     * Redistributions of source code must retain the above copyright notice,
+//       this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above copyright
+//       notice, this list of conditions and the following disclaimer in the
+//       documentation and/or other materials provided with the distribution.
+//     * Neither the name of the application "Radegast", nor the names of its
+//       contributors may be used to endorse or promote products derived from
+//       this software without specific prior written permission.
+// 
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// $Id$
+//
+using System;
+
+namespace Radegast
+{
+    /// <summary>
+    /// Metadata about Radegast Plugins
+    /// </summary>
+    public class PluginAttribute : Attribute
+    {
+        /// <summary>Plugin short name</summary>
+        public string Name = string.Empty;
+
+        /// <summary>Plugin description</summary>
+        public string Description = string.Empty;
+
+        /// <summary>Plugin version</summary>
+        public string Version = string.Empty;
+    }
+}
index f93119e..c0e8780 100644 (file)
@@ -75,6 +75,25 @@ namespace Radegast
             }
         }
 
+        public static PluginAttribute GetAttributes(IRadegastPlugin plug)
+        {
+            PluginAttribute a = null;
+
+            foreach(Attribute attr in Attribute.GetCustomAttributes(plug.GetType()))
+            {
+                if (attr is PluginAttribute)
+                    a = (PluginAttribute)attr;
+            }
+
+            if (a == null)
+            {
+                a = new PluginAttribute();
+                a.Name = plug.GetType().FullName;
+            }
+
+            return a;
+        }
+
         public void StartPlugins()
         {
             lock (PluginsLoaded)
@@ -225,7 +244,8 @@ namespace Radegast
                         lock (PluginsLoaded) PluginsLoaded.Add(plug);
                         if (startPlugins && plug != null)
                         {
-                            plug.StartPlugin(instance);
+                            try { plug.StartPlugin(instance); }
+                            catch (Exception ex) { Logger.Log(string.Format("Failed starting plugin {0}:", type), Helpers.LogLevel.Error, ex); }
                         }
                     }
                     catch (Exception ex)
index 5e34164..b51fc37 100644 (file)
     <Compile Include="Core\Media\MediaObject.cs" />\r
     <Compile Include="Core\Media\Sound.cs" />\r
     <Compile Include="Core\PluginInterface\IRadegastPlugin.cs" />\r
+    <Compile Include="Core\PluginInterface\PluginAttribute.cs" />\r
     <Compile Include="Core\PluginInterface\PluginManager.cs" />\r
     <Compile Include="Core\RLV\RLVEventArgs.cs" />\r
     <Compile Include="Core\RLV\RLVManager.cs" />\r
index e56ebe8..95c684e 100644 (file)
@@ -42,7 +42,8 @@ using AIMLbot;
 
 namespace Radegast.Plugin.Alice
 {
-    public class DemoPlugin : IRadegastPlugin
+    [Radegast.Plugin(Name = "ALICE Chatbot", Description = "A.L.I.C.E. based AI chat bot", Version = "1.0")]
+    public class AliceAI : IRadegastPlugin
     {
         private RadegastInstance Instance;
         private GridClient Client { get { return Instance.Client; } }
index 792c92f..134022f 100644 (file)
@@ -38,6 +38,7 @@ using OpenMetaverse;
 
 namespace Radegast.Plugin.Demo
 {
+    [Radegast.Plugin(Name="Demo Plugin", Description="Demontration of plugin capabilites", Version="1.0")]
     public class DemoPlugin : IRadegastPlugin
     {
         private RadegastInstance Instance;
index 0e135ea..9cbefd5 100644 (file)
@@ -41,6 +41,7 @@ using OpenMetaverse.StructuredData;
 
 namespace RadegastSpeech
 {
+    [Radegast.Plugin(Name = "Speech", Description = "Adds TTS and STT accesibility capabilities to Radegast", Version = "0.3")]
     public class PluginControl : IRadegastPlugin
     {
         private const string VERSION = "0.3";