Example #1
0
        /// <summary>
        /// Call this from a region module to add a command to the OpenSim console.
        /// </summary>
        /// <param name="mod"></param>
        /// <param name="command"></param>
        /// <param name="shorthelp"></param>
        /// <param name="longhelp"></param>
        /// <param name="descriptivehelp"></param>
        /// <param name="callback"></param>
        public void AddCommand(
            object mod, string command, string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback)
        {
            if (MainConsole.Instance == null)
            {
                return;
            }

            string modulename = String.Empty;
            bool   shared     = false;

            if (mod != null)
            {
                if (mod is IRegionModule)
                {
                    IRegionModule module = (IRegionModule)mod;
                    modulename = module.Name;
                    shared     = module.IsSharedModule;
                }
                else if (mod is IRegionModuleBase)
                {
                    IRegionModuleBase module = (IRegionModuleBase)mod;
                    modulename = module.Name;
                    shared     = mod is ISharedRegionModule;
                }
                else
                {
                    throw new Exception("AddCommand module parameter must be IRegionModule or IRegionModuleBase");
                }
            }

            MainConsole.Instance.Commands.AddCommand(
                modulename, shared, command, shorthelp, longhelp, descriptivehelp, callback);
        }
Example #2
0
 /// <summary>
 /// Add a region-module to this scene. TODO: This will replace AddModule in the future.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="module"></param>
 public void AddRegionModule(string name, IRegionModuleBase module)
 {
     if (!RegionModules.ContainsKey(name))
     {
         RegionModules.Add(name, module);
     }
 }
Example #3
0
        /// <summary>
        /// Setup modules for scenes.
        /// </summary>
        /// <remarks>
        /// If called directly, then all the modules must be shared modules.
        /// 
        /// We are emulating here the normal calls made to setup region modules 
        /// (Initialise(), PostInitialise(), AddRegion, RegionLoaded()).
        /// TODO: Need to reuse normal runtime module code.
        /// </remarks>
        /// <param name="scenes"></param>
        /// <param name="config"></param>
        /// <param name="modules"></param>
        public static void SetupSceneModules(Scene[] scenes, IConfigSource config, params object[] modules)
        {
            List<IRegionModuleBase> newModules = new List<IRegionModuleBase>();
            foreach (object module in modules)
            {
                IRegionModuleBase m = (IRegionModuleBase)module;
//                Console.WriteLine("MODULE {0}", m.Name);
                m.Initialise(config);
                newModules.Add(m);
            }

            foreach (IRegionModuleBase module in newModules)
            {
                if (module is ISharedRegionModule) ((ISharedRegionModule)module).PostInitialise();
            }

            foreach (IRegionModuleBase module in newModules)
            {
                foreach (Scene scene in scenes)
                {
                    module.AddRegion(scene);
                    scene.AddRegionModule(module.Name, module);
                }
            }

            // RegionLoaded is fired after all modules have been appropriately added to all scenes
            foreach (IRegionModuleBase module in newModules)
                foreach (Scene scene in scenes)
                    module.RegionLoaded(scene);

            foreach (Scene scene in scenes) { scene.SetModuleInterfaces(); }
        }
 private void AddRegionModule(IScene scene, string p, IRegionModuleBase module)
 {
     if (!RegionModules.ContainsKey(scene))
     {
         RegionModules.Add(scene, new Dictionary <string, IRegionModuleBase>());
     }
     RegionModules[scene][p] = module;
 }
Example #5
0
 public void registerCommands(IRegionModuleBase regionModule, Scene scene)
 {
     scene.AddCommand("Aar", regionModule, "aar load", "load [id]", "load a session by id", loadSession);
     scene.AddCommand("Aar", regionModule, "aar unload", "unload", "halt playback and unload a session", unloadSession);
     scene.AddCommand("Aar", regionModule, "aar list", "list", "list recorded sessions", listSessions);
     scene.AddCommand("Aar", regionModule, "aar play", "play", "begin playback of a loaded session", beginPlayback);
     scene.AddCommand("Aar", regionModule, "aar pause", "pause", "pause the playback of a loaded session", pausePlayback);
     scene.AddCommand("Aar", regionModule, "aar purge", "purge", "delete all contents of the aar storage prim", purgeBox);
 }
Example #6
0
        /// <summary>
        /// Call this from a region module to add a command to the OpenSim console.
        /// </summary>
        /// <param name="mod"></param>
        /// <param name="command"></param>
        /// <param name="shorthelp"></param>
        /// <param name="longhelp"></param>
        /// <param name="descriptivehelp"></param>
        /// <param name="callback"></param>
        public void AddCommand(IRegionModuleBase module, string command, string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback)
        {
            string moduleName = "";

            if (module != null)
            {
                moduleName = module.Name;
            }

            AddCommand(moduleName, module, command, shorthelp, longhelp, descriptivehelp, callback);
        }
Example #7
0
 public void RegisterConstants(IRegionModuleBase target)
 {
     foreach (FieldInfo field in target.GetType().GetFields(
                  BindingFlags.Public | BindingFlags.Static |
                  BindingFlags.Instance))
     {
         if (field.GetCustomAttributes(
                 typeof(ScriptConstantAttribute), true).Any())
         {
             RegisterConstant(field.Name, field.GetValue(target));
         }
     }
 }
Example #8
0
        //queue of processed scene events
        //private Queue<AAREvent> processedActions = new Queue<AAREvent>();

        public AAR(Scene scene, IRegionModuleBase module, AARLog log)
        {
            this.log = log;

            scene.AddCommand("Aar", module, "aar status", "status", "Print the status of the AAR module", statusAction);

            recorder = new Recorder(log);
            recorder.initialize(scene);
            recorder.registerCommands(module, scene);

            player = new Player(log);
            player.initialize(scene);
            player.registerCommands(module, scene);
        }
Example #9
0
        public void Manage(Type t, IRegionModuleBase mod)
        {
            string typeName = t.ToString();

            if (!m_ManagedModules.ContainsKey(typeName))
            {
                m_ManagedModules[typeName] = new List <IRegionModuleBase>();
            }

            if (!m_ManagedModules[typeName].Contains(mod))
            {
                m_ManagedModules[typeName].Add(mod);
                m_log.DebugFormat("[Diva.ModuleShim]: Now managing {0} of type {1}", mod.Name, t.ToString());
            }
        }
Example #10
0
        /// <summary>
        /// Setup modules for a scene.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="config"></param>
        /// <param name="modules"></param>
        public static void SetupSceneModules(Scene scene, IConfigSource config, params object[] modules)
        {
            List <IRegionModuleBase> newModules = new List <IRegionModuleBase>();

            foreach (object module in modules)
            {
                if (module is IRegionModule)
                {
                    IRegionModule m = (IRegionModule)module;
                    m.Initialise(scene, config);
                    scene.AddModule(m.Name, m);
                    m.PostInitialise();
                }
                else if (module is IRegionModuleBase)
                {
                    // for the new system, everything has to be initialised first,
                    // shared modules have to be post-initialised, then all get an AddRegion with the scene
                    IRegionModuleBase m = (IRegionModuleBase)module;
                    m.Initialise(config);
                    newModules.Add(m);
                }
            }

            foreach (IRegionModuleBase module in newModules)
            {
                if (module is ISharedRegionModule)
                {
                    ((ISharedRegionModule)module).PostInitialise();
                }
            }

            foreach (IRegionModuleBase module in newModules)
            {
                module.AddRegion(scene);
                scene.AddRegionModule(module.Name, module);
            }

            // RegionLoaded is fired after all modules have been appropriately added to all scenes
            foreach (IRegionModuleBase module in newModules)
            {
                module.RegionLoaded(scene);
            }

            scene.SetModuleInterfaces();
        }
Example #11
0
        /// <summary>
        /// Call this from a region module to add a command to the OpenSim console.
        /// </summary>
        /// <param name="category">
        /// Category of the command.  This is the section under which it will appear when the user asks for help
        /// </param>
        /// <param name="mod"></param>
        /// <param name="command"></param>
        /// <param name="shorthelp"></param>
        /// <param name="longhelp"></param>
        /// <param name="descriptivehelp"></param>
        /// <param name="callback"></param>
        public void AddCommand(
            string category, IRegionModuleBase module, string command,
            string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback)
        {
            if (MainConsole.Instance == null)
            {
                return;
            }

            bool shared = false;

            if (module != null)
            {
                shared = module is ISharedRegionModule;
            }

            MainConsole.Instance.Commands.AddCommand(
                category, shared, command, shorthelp, longhelp, descriptivehelp, callback);
        }
Example #12
0
 public void RegisterScriptInvocations(IRegionModuleBase target)
 {
     foreach (MethodInfo method in target.GetType().GetMethods(
                  BindingFlags.Public | BindingFlags.Instance |
                  BindingFlags.Static))
     {
         if (method.GetCustomAttributes(
                 typeof(ScriptInvocationAttribute), true).Any())
         {
             if (method.IsStatic)
             {
                 RegisterScriptInvocation(target.GetType(), method);
             }
             else
             {
                 RegisterScriptInvocation(target, method);
             }
         }
     }
 }
Example #13
0
        /// <summary>
        /// Call this from a region module to add a command to the OpenSim console.
        /// </summary>
        /// <param name="mod"></param>
        /// <param name="command"></param>
        /// <param name="shorthelp"></param>
        /// <param name="longhelp"></param>
        /// <param name="descriptivehelp"></param>
        /// <param name="callback"></param>
        public void AddCommand(object mod, string command, string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback)
        {
            string moduleName = "";

            if (mod != null)
            {
                if (mod is IRegionModule)
                {
                    IRegionModule module = (IRegionModule)mod;
                    moduleName = module.Name;
                }
                else if (mod is IRegionModuleBase)
                {
                    IRegionModuleBase module = (IRegionModuleBase)mod;
                    moduleName = module.Name;
                }
                else
                {
                    throw new Exception("AddCommand module parameter must be IRegionModule or IRegionModuleBase");
                }
            }

            AddCommand(moduleName, mod, command, shorthelp, longhelp, descriptivehelp, callback);
        }
 void AddRegionModule(IScene scene, string p, IRegionModuleBase module)
 {
     if (!RegionModules.ContainsKey(scene))
         RegionModules.Add(scene, new Dictionary<string, IRegionModuleBase>());
     RegionModules[scene][p] = module;
 }
 public void RegisterScriptInvocations(IRegionModuleBase target)
 {
     foreach(MethodInfo method in target.GetType().GetMethods(
             BindingFlags.Public | BindingFlags.Instance |
             BindingFlags.Static))
     {
         if(method.GetCustomAttributes(
                 typeof(ScriptInvocationAttribute), true).Any())
         {
             if(method.IsStatic)
                 RegisterScriptInvocation(target.GetType(), method);
             else
                 RegisterScriptInvocation(target, method);
         }
     }
 }
        public void Manage(Type t, IRegionModuleBase mod)
        {
            string typeName = t.ToString();
            if (!m_ManagedModules.ContainsKey(typeName))
                m_ManagedModules[typeName] = new List<IRegionModuleBase>();

            if (!m_ManagedModules[typeName].Contains(mod))
            {
                m_ManagedModules[typeName].Add(mod);
                m_log.DebugFormat("[Diva.ModuleShim]: Now managing {0} of type {1}", mod.Name, t.ToString());
            }
        }
Example #17
0
        /// <summary>
        /// Load a plugin from a dll with the given class or interface
        /// </summary>
        /// <param name="dllName"></param>
        /// <param name="className"></param>
        /// <param name="args">The arguments which control which constructor is invoked on the plugin</param>
        /// <returns></returns>
        Modules LoadRegionModules(string dllName, string className, Object[] args)
        {
            string  interfaceName = "IRegionModuleBase";
            Modules plugins       = new Modules();

            try
            {
                Assembly pluginAssembly = Assembly.LoadFrom(dllName);

                foreach (Type pluginType in pluginAssembly.GetTypes())
                {
                    if (pluginType.IsPublic)
                    {
                        if (className != String.Empty &&
                            pluginType.ToString() != pluginType.Namespace + "." + className)
                        {
                            continue;
                        }

                        Type typeInterface = pluginType.GetInterface(interfaceName, true);

                        if (typeInterface != null)
                        {
                            IRegionModuleBase plug = null;
                            Type shared            = pluginType.GetInterface("ISharedRegionModule", true);
                            int  n_instances       = 1;
                            if (shared == null)
                            {
                                n_instances = m_Scenes.Count;
                            }
                            m_log.DebugFormat("[Diva.ModuleShim]: Found {0} {1}", pluginType.ToString(), (shared != null? "shared" : "non-shared"));
                            try
                            {
                                for (int i = 0; i < n_instances; i++)
                                {
                                    plug = (IRegionModuleBase)Activator.CreateInstance(pluginType,
                                                                                       args);
                                    if (shared == null)
                                    {
                                        Type t = plug.GetType();
                                        if (!plugins.m_NonShared.ContainsKey(t))
                                        {
                                            plugins.m_NonShared[t] = new List <INonSharedRegionModule>();
                                        }
                                        plugins.m_NonShared[t].Add((INonSharedRegionModule)plug);
                                    }
                                    else
                                    {
                                        plugins.m_Shared.Add((ISharedRegionModule)plug);
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                if (!(e is System.MissingMethodException))
                                {
                                    m_log.ErrorFormat("Error loading plugin {0} from {1}. Exception: {2}",
                                                      interfaceName, dllName, e.InnerException == null ? e.Message : e.InnerException.Message);
                                }
                                break;
                            }
                        }
                    }
                }

                return(plugins);
            }
            catch (ReflectionTypeLoadException rtle)
            {
                m_log.Error(string.Format("Error loading plugin from {0}:\n{1}", dllName,
                                          String.Join("\n", Array.ConvertAll(rtle.LoaderExceptions, e => e.ToString()))),
                            rtle);
                return(plugins);
            }
            catch (Exception e)
            {
                m_log.Error(string.Format("Error loading plugin from {0}", dllName), e);
                return(plugins);
            }
        }
Example #18
0
 /// <summary>
 /// Call this from a region module to add a command to the OpenSim console.
 /// </summary>
 /// <param name="mod">
 /// The use of IRegionModuleBase is a cheap trick to get a different method signature,
 /// though all new modules should be using interfaces descended from IRegionModuleBase anyway.
 /// </param>
 /// <param name="category">
 /// Category of the command.  This is the section under which it will appear when the user asks for help
 /// </param>
 /// <param name="command"></param>
 /// <param name="shorthelp"></param>
 /// <param name="longhelp"></param>
 /// <param name="callback"></param>
 public void AddCommand(
     string category, IRegionModuleBase module, string command, string shorthelp, string longhelp, CommandDelegate callback)
 {
     AddCommand(category, module, command, shorthelp, longhelp, string.Empty, callback);
 }
 public void RegisterConstants(IRegionModuleBase target)
 {
     foreach (FieldInfo field in target.GetType().GetFields(
             BindingFlags.Public | BindingFlags.Static |
             BindingFlags.Instance))
     {
         if (field.GetCustomAttributes(
                 typeof(ScriptConstantAttribute), true).Any())
         {
             RegisterConstant(field.Name, field.GetValue(target));
         }
     }
 }
Example #20
0
 public void registerCommands(IRegionModuleBase regionModule, Scene scene)
 {
     scene.AddCommand("Aar", regionModule, "aar record", "record", "Begin recording an event", startRecording);
     scene.AddCommand("Aar", regionModule, "aar stop", "stop", "Stop recording an event", stopRecording);
     scene.AddCommand("Aar", regionModule, "aar save", "save", "Persist a recorded event", saveSession);
 }