From 8143c597fc5f62ec0d931d2d5b887730e06aec04 Mon Sep 17 00:00:00 2001
From: lbsa71
Date: Thu, 27 Sep 2007 13:25:45 +0000
Subject: * Tleiades grid mode inventory (#444) - thanx Tleiades!   * updated
 to rev 1413 on libsecondlife.dll and libsecondlife.dll.config (#423)

---
 OpenSim/Grid/InventoryServer/InventoryManager.cs | 131 ++++++++++++++--------
 OpenSim/Grid/InventoryServer/InventoryService.cs | 136 +++++++++++++++++++++++
 OpenSim/Grid/InventoryServer/Main.cs             | 113 ++++++++++++++++---
 OpenSim/Grid/UserServer/Main.cs                  |  11 +-
 OpenSim/Grid/UserServer/UserLoginService.cs      |  39 ++++---
 5 files changed, 350 insertions(+), 80 deletions(-)
 create mode 100644 OpenSim/Grid/InventoryServer/InventoryService.cs

(limited to 'OpenSim/Grid')

diff --git a/OpenSim/Grid/InventoryServer/InventoryManager.cs b/OpenSim/Grid/InventoryServer/InventoryManager.cs
index 016b8bb..a46f359 100644
--- a/OpenSim/Grid/InventoryServer/InventoryManager.cs
+++ b/OpenSim/Grid/InventoryServer/InventoryManager.cs
@@ -26,37 +26,34 @@
 * 
 */
 using System;
+using System.Text;
+using System.Reflection;
 using System.Collections;
 using System.Collections.Generic;
-using System.Text;
-using OpenGrid.Framework.Data;
 using libsecondlife;
-using System.Reflection;
 
 using System.Xml;
-using Nwc.XmlRpc;
-using OpenSim.Framework.Sims;
-using OpenSim.Framework.Inventory;
+using OpenSim.Framework.Console;
 using OpenSim.Framework.Utilities;
+using OpenSim.Framework.Data;
+using InventoryCategory = OpenSim.Framework.Data.InventoryCategory;
 
-using System.Security.Cryptography;
-
-namespace OpenGridServices.InventoryServer
+namespace OpenSim.Grid.InventoryServer
 {
-    class InventoryManager
+    class InventoryManager : IInventoryData 
     {
-        Dictionary<string, IInventoryData> _plugins = new Dictionary<string, IInventoryData>();
+        IInventoryData _databasePlugin;
 
         /// <summary>
         /// Adds a new inventory server plugin - user servers will be requested in the order they were loaded.
         /// </summary>
         /// <param name="FileName">The filename to the inventory server plugin DLL</param>
-        public void AddPlugin(string FileName)
+        public void AddDatabasePlugin(string FileName)
         {
-            OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Invenstorage: Attempting to load " + FileName);
+            MainLog.Instance.Verbose(OpenInventory_Main.MainLogName, "Invenstorage: Attempting to load " + FileName);
             Assembly pluginAssembly = Assembly.LoadFrom(FileName);
 
-            OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Invenstorage: Found " + pluginAssembly.GetTypes().Length + " interfaces.");
+            MainLog.Instance.Verbose(OpenInventory_Main.MainLogName, "Invenstorage: Found " + pluginAssembly.GetTypes().Length + " interfaces.");
             foreach (Type pluginType in pluginAssembly.GetTypes())
             {
                 if (!pluginType.IsAbstract)
@@ -67,8 +64,9 @@ namespace OpenGridServices.InventoryServer
                     {
                         IInventoryData plug = (IInventoryData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
                         plug.Initialise();
-                        this._plugins.Add(plug.getName(), plug);
-                        OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Invenstorage: Added IUserData Interface");
+                        _databasePlugin = plug;
+                        MainLog.Instance.Verbose(OpenInventory_Main.MainLogName, "Invenstorage: Added IInventoryData Interface");
+                        break;
                     }
 
                     typeInterface = null;
@@ -80,46 +78,87 @@ namespace OpenGridServices.InventoryServer
 
         public List<InventoryFolderBase> getRootFolders(LLUUID user)
         {
-            foreach (KeyValuePair<string, IInventoryData> kvp in _plugins)
-            {
-                try
-                {
-                    return kvp.Value.getUserRootFolders(user);
-                }
-                catch (Exception e)
-                {
-                    OpenSim.Framework.Console.MainConsole.Instance.Notice("Unable to get root folders via " + kvp.Key + " (" + e.ToString() + ")");
-                }
-            }
             return null;
         }
 
-        public XmlRpcResponse XmlRpcInventoryRequest(XmlRpcRequest request)
+        #region IInventoryData Members
+
+
+        public List<InventoryItemBase> getInventoryInFolder(LLUUID folderID)
+        {
+            return _databasePlugin.getInventoryInFolder(folderID);
+        }
+
+        public List<InventoryFolderBase> getUserRootFolders(LLUUID user)
         {
-            XmlRpcResponse response = new XmlRpcResponse();
-            Hashtable requestData = (Hashtable)request.Params[0];
+            return _databasePlugin.getUserRootFolders(user);
+        }
 
-            Hashtable responseData = new Hashtable();
+        public List<InventoryFolderBase> getInventoryFolders(LLUUID parentID)
+        {
+            return _databasePlugin.getInventoryFolders(parentID);
+        }
 
-            // Stuff happens here
+        public InventoryItemBase getInventoryItem(LLUUID item)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
 
-            if (requestData.ContainsKey("Access-type"))
-            {
-                if (requestData["access-type"] == "rootfolders")
-                {
-//                    responseData["rootfolders"] =
-                }
-            }
-            else
-            {
-                responseData["error"] = "No access-type specified.";
-            }
+        public InventoryFolderBase getInventoryFolder(LLUUID folder)
+        {
+            return _databasePlugin.getInventoryFolder(folder);
+        }
+
+        public void addInventoryItem(InventoryItemBase item)
+        {
+            _databasePlugin.addInventoryItem(item);
+        }
+
+        public void updateInventoryItem(InventoryItemBase item)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        public void deleteInventoryItem(InventoryItemBase item)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        public void addInventoryFolder(InventoryFolderBase folder)
+        {
+            _databasePlugin.addInventoryFolder(folder);
+        }
+
+        public void updateInventoryFolder(InventoryFolderBase folder)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        public void Initialise()
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        public void Close()
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
 
+        public string getName()
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
 
-            // Stuff stops happening here
+        public string getVersion()
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
 
-            response.Value = responseData;
-            return response;
+        public void deleteInventoryCategory(InventoryCategory inventoryCategory)
+        {
+            _databasePlugin.deleteInventoryCategory(inventoryCategory);
         }
+
+        #endregion
     }
 }
diff --git a/OpenSim/Grid/InventoryServer/InventoryService.cs b/OpenSim/Grid/InventoryServer/InventoryService.cs
new file mode 100644
index 0000000..cbc0558
--- /dev/null
+++ b/OpenSim/Grid/InventoryServer/InventoryService.cs
@@ -0,0 +1,136 @@
+using System;
+using System.Runtime.Remoting;
+using System.Runtime.Remoting.Channels;
+using System.Runtime.Remoting.Channels.Tcp;
+using System.Runtime.Serialization.Formatters;
+using System.Collections;
+using System.Collections.Generic;
+
+
+using libsecondlife;
+using OpenSim.Framework.Data;
+using OpenSim.Framework.Communications;
+using OpenSim.Framework.Configuration;
+using InventoryCategory = OpenSim.Framework.Data.InventoryCategory;
+
+namespace OpenSim.Grid.InventoryServer
+{
+    class InventoryServiceSingleton : OpenSim.Framework.Communications.InventoryServiceBase
+    {
+        static InventoryManager _inventoryManager;
+
+        static public InventoryManager InventoryManager
+        {
+            set { _inventoryManager = value; }
+            get { return _inventoryManager; }
+        }
+
+#region Singleton Pattern
+        static InventoryServiceSingleton instance=null;
+
+        InventoryServiceSingleton()
+        {
+        }
+
+        public static InventoryServiceSingleton Instance
+        {
+            get
+            {
+                if (instance==null)
+                {
+                    instance = new InventoryServiceSingleton();
+                }
+                return instance;
+            }
+        }
+#endregion
+
+#region IInventoryServices Members
+
+        public override void RequestInventoryForUser(LLUUID userID, InventoryFolderInfo folderCallBack, InventoryItemInfo itemCallBack)
+        {
+            List<InventoryFolderBase> folders = this.RequestFirstLevelFolders(userID);
+            InventoryFolderBase rootFolder = null;
+
+            //need to make sure we send root folder first
+            foreach (InventoryFolderBase folder in folders)
+            {
+                if (folder.parentID == libsecondlife.LLUUID.Zero)
+                {
+                    rootFolder = folder;
+                    folderCallBack(userID, folder);
+                }
+            }
+
+            if (rootFolder != null)
+            {
+                foreach (InventoryFolderBase folder in folders)
+                {
+                    if (folder.folderID != rootFolder.folderID)
+                    {
+                        folderCallBack(userID, folder);
+
+                        List<InventoryItemBase> items = this.RequestFolderItems(folder.folderID);
+                        foreach (InventoryItemBase item in items)
+                        {
+                            itemCallBack(userID, item);
+                        }
+                    }
+                }
+            }
+
+        }
+
+        public override void AddNewInventoryFolder(LLUUID userID, InventoryFolderBase folder)
+        {
+            _inventoryManager.addInventoryFolder(folder);
+        }
+
+        public override void AddNewInventoryItem(LLUUID userID, InventoryItemBase item)
+        {
+            throw new Exception("Not implemented exception");
+        }
+
+        public override void DeleteInventoryItem(LLUUID userID, InventoryItemBase item)
+        {
+            throw new Exception("Not implemented exception");
+        }
+
+        public List<InventoryItemBase> RequestFolderItems(LLUUID folderID)
+        {
+            return _inventoryManager.getInventoryInFolder(folderID);
+        }
+
+
+#endregion
+    }
+
+    class InventoryService 
+    {
+        InventoryServiceSingleton _inventoryServiceMethods;
+        public InventoryService(InventoryManager inventoryManager, InventoryConfig cfg)
+        {
+            // we only need to register the tcp channel once, and we don't know which other modules use remoting
+            if (ChannelServices.GetChannel("tcp") == null)
+            {
+                // Creating a custom formatter for a TcpChannel sink chain.
+                BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
+                serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
+
+                IDictionary props = new Hashtable();
+                props["port"] = cfg.RemotingPort;
+                props["typeFilterLevel"] = TypeFilterLevel.Full;
+
+                // Pass the properties for the port setting and the server provider in the server chain argument. (Client remains null here.)
+                ChannelServices.RegisterChannel(new TcpChannel(props, null, serverProvider), true);
+            }
+
+            // Register the object
+            RemotingConfiguration.RegisterWellKnownServiceType(typeof(InventoryServiceSingleton), "Inventory", WellKnownObjectMode.Singleton);
+
+            _inventoryServiceMethods = InventoryServiceSingleton.Instance;
+            InventoryServiceSingleton.InventoryManager = inventoryManager; 
+        }
+
+    }
+}
diff --git a/OpenSim/Grid/InventoryServer/Main.cs b/OpenSim/Grid/InventoryServer/Main.cs
index 97addb0..392c741 100644
--- a/OpenSim/Grid/InventoryServer/Main.cs
+++ b/OpenSim/Grid/InventoryServer/Main.cs
@@ -31,49 +31,130 @@ using System.Collections.Generic;
 using System.Reflection;
 using System.IO;
 using System.Text;
+using System.Xml;
+
 using libsecondlife;
-using OpenSim.Framework.User;
-using OpenSim.Framework.Sims;
-using OpenSim.Framework.Inventory;
 using OpenSim.Framework.Interfaces;
 using OpenSim.Framework.Console;
-using OpenSim.Servers;
 using OpenSim.Framework.Utilities;
+using OpenSim.Framework.Configuration;
+using OpenSim.Framework.Data;
+using InventoryCategory = OpenSim.Framework.Data.InventoryCategory;
 
-namespace OpenGridServices.InventoryServer
+namespace OpenSim.Grid.InventoryServer
 {
-    public class OpenInventory_Main : BaseServer, conscmd_callback
+
+    public class OpenInventory_Main : conscmd_callback
     {
-        ConsoleBase m_console;
-        InventoryManager m_inventoryManager;
 
+        public const string MainLogName = "INVENTORY";
+
+        private InventoryConfig m_config;
+        LogBase m_console;
+        InventoryManager m_inventoryManager;    ///connection the database backend
+        InventoryService m_inventoryService;    ///Remoting interface, where messages arrive
+        [STAThread]
         public static void Main(string[] args)
         {
+            Console.WriteLine("Launching InventoryServer...");
+
+            OpenInventory_Main inventoryServer = new OpenInventory_Main();
+
+            inventoryServer.Startup();
+
+//            inventoryServer.RunCmd("load", new string[] { "library", "inventory_library.xml" });
+//            inventoryServer.RunCmd("load", new string[] { "default", "inventory_default.xml" });
+
+            inventoryServer.Work();
         }
 
         public OpenInventory_Main()
         {
-            m_console = new ConsoleBase("opengrid-inventory-console.log", "OpenInventory", this, false);
-            MainConsole.Instance = m_console;
+
+            if (!Directory.Exists(Util.logDir()))
+            {
+                Directory.CreateDirectory(Util.logDir());
+            }
+
+            m_console = new LogBase(Path.Combine(Util.logDir(), "opensim-inventory-console.log"), "OpenInventory", this, false);
+            MainLog.Instance = m_console;
+        }
+
+        private void Work()
+        {
+            m_console.Notice(OpenInventory_Main.MainLogName, "Enter help for a list of commands\n");
+
+            while (true)
+            {
+                m_console.MainLogPrompt();
+            }
         }
 
         public void Startup()
         {
-            MainConsole.Instance.Notice("Initialising inventory manager...");
+            MainLog.Instance.Verbose(OpenInventory_Main.MainLogName, "Initialising inventory manager...");
+
+            m_config = new InventoryConfig(OpenInventory_Main.MainLogName, (Path.Combine(Util.configDir(), "InventoryServer_Config.xml")));
+            
+            // instantiate the manager, responsible for doing the actual storage
             m_inventoryManager = new InventoryManager();
+            m_inventoryManager.AddDatabasePlugin(m_config.DatabaseProvider);
+
+            m_inventoryService = new InventoryService(m_inventoryManager, m_config);
 
-            MainConsole.Instance.Notice("Starting HTTP server");
-            BaseHttpServer httpServer = new BaseHttpServer(8004);
+            // Dig out the embedded version number of this assembly
+            Assembly assembly = Assembly.GetExecutingAssembly();
+            string serverExeName = assembly.ManifestModule.Name;
+            Version serverExeVersion = AssemblyName.GetAssemblyName(serverExeName).Version;
 
-            httpServer.AddXmlRPCHandler("rootfolders", m_inventoryManager.XmlRpcInventoryRequest);
-            //httpServer.AddRestHandler("GET","/rootfolders/",Rest
+            m_console.Status(OpenInventory_Main.MainLogName, "Inventoryserver {0}.{1}.{2}.{3} - Startup complete", serverExeVersion.Major, serverExeVersion.Minor, serverExeVersion.Revision, serverExeVersion.Build);
         }
 
-        public void RunCmd(string cmd, string[] cmdparams)
+
+        public void Load(string[] cmdparams)
         {
+            string cmd = cmdparams[0];
+            string fileName = cmdparams[1];
+
+            if (cmdparams.Length != 2)
+            {
+                cmd = "help"; 
+            }
+
             switch (cmd)
             {
+                case "library":
+                    InventoryServiceSingleton.Instance.loadInventoryFromXmlFile(InventoryCategory.Library, fileName);
+                    break;
+                case "default":
+                    InventoryServiceSingleton.Instance.loadInventoryFromXmlFile(InventoryCategory.Default, fileName);
+                    break;
+                case "user":
+                    InventoryServiceSingleton.Instance.loadInventoryFromXmlFile(InventoryCategory.User, fileName);
+                    break;
+                case "help":
+                    m_console.Notice("load library <filename>, load library inventory, shared between all users");
+                    m_console.Notice("load default <filename>, load template inventory, used when creating a new user inventory");
+                    m_console.Notice("load user <first> <last>, load inventory for a specific users, warning this will reset the contents of the inventory");
+                    break;
+            }
+        }
+
+        public void RunCmd(string cmd, string[] cmdparams)
+        {
+            switch (cmd)
+            {   
+                case "help":
+                    m_console.Notice("load - load verious inventories, use \"load help\", to see a list of commands");
+                    m_console.Notice("shutdown - shutdown the grid (USE CAUTION!)");
+                    m_console.Notice("quit - shutdown the grid (USE CAUTION!)");
+                    break;
+                case "load":
+                    Load(cmdparams);
+                    break;
+                case "quit":
                 case "shutdown":
+                    MainLog.Instance.Verbose(OpenInventory_Main.MainLogName, "Shutting down inventory server");
                     m_console.Close();
                     Environment.Exit(0);
                     break;
diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs
index c2822b6..28635dd 100644
--- a/OpenSim/Grid/UserServer/Main.cs
+++ b/OpenSim/Grid/UserServer/Main.cs
@@ -36,6 +36,8 @@ using OpenSim.Framework.Interfaces;
 using OpenSim.Framework.Servers;
 using OpenSim.Framework.Utilities;
 using OpenSim.Framework.Configuration;
+using OpenSim.Framework.Communications;
+using OpenSim.Region.Communications.OGS1;
 
 namespace OpenSim.Grid.UserServer
 {
@@ -48,6 +50,8 @@ namespace OpenSim.Grid.UserServer
         public UserManager m_userManager;
         public UserLoginService m_loginService;
 
+        public IInventoryServices m_inventoryService;
+
         LogBase m_console;
 
         [STAThread]
@@ -90,7 +94,11 @@ namespace OpenSim.Grid.UserServer
             m_userManager._config = Cfg;
             m_userManager.AddPlugin(Cfg.DatabaseProvider);
 
-            m_loginService = new UserLoginService(m_userManager, Cfg, Cfg.DefaultStartupMsg);
+            // prepare connection to the inventory server
+            m_inventoryService = new OGS1InventoryService(Cfg.InventoryServerName, Cfg.InventoryServerPort, null);
+
+            
+            m_loginService = new UserLoginService(m_userManager, m_inventoryService, Cfg, Cfg.DefaultStartupMsg);
 
             MainLog.Instance.Verbose("Main.cs:Startup() - Starting HTTP process");
             BaseHttpServer httpServer = new BaseHttpServer((int)Cfg.HttpPort);
@@ -103,6 +111,7 @@ namespace OpenSim.Grid.UserServer
             httpServer.AddStreamHandler( new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod ));
             
             httpServer.Start();
+
             m_console.Status("SERVER", "Userserver 0.3 - Startup complete");
         }
 
diff --git a/OpenSim/Grid/UserServer/UserLoginService.cs b/OpenSim/Grid/UserServer/UserLoginService.cs
index 95192e3..f0140a5 100644
--- a/OpenSim/Grid/UserServer/UserLoginService.cs
+++ b/OpenSim/Grid/UserServer/UserLoginService.cs
@@ -6,6 +6,7 @@ using OpenSim.Framework.Data;
 using OpenSim.Framework.UserManagement;
 using OpenSim.Framework.Utilities;
 using OpenSim.Framework.Configuration;
+using OpenSim.Framework.Communications;
 
 namespace OpenSim.Grid.UserServer
 {
@@ -13,8 +14,8 @@ namespace OpenSim.Grid.UserServer
     {
         public UserConfig m_config;
 
-        public UserLoginService(UserManagerBase userManager, UserConfig config, string welcomeMess)
-            : base(userManager, welcomeMess)
+        public UserLoginService(UserManagerBase userManager, IInventoryServices inventoryServer, UserConfig config, string welcomeMess)
+            : base(userManager, inventoryServer, welcomeMess)
         {
             m_config = config;
         }
@@ -71,25 +72,29 @@ namespace OpenSim.Grid.UserServer
             theUser.currentAgent.currentHandle = SimInfo.regionHandle;
 
             System.Console.WriteLine("Informing region --> " + SimInfo.httpServerURI);
-            // Send
-            try
-            {
-                XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams);
-                XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000);
+            // Send
+            try
+            {
+                XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams);
+                XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000);
             }
             catch( WebException e )
-            {
-                switch( e.Status )
-                {
-                    case WebExceptionStatus.Timeout:
-                        //TODO: Send him to nearby or default region instead
-                        break;
-                       
-                    default:
-                        throw;
-                }
+            {
+                switch( e.Status )
+                {
+                    case WebExceptionStatus.Timeout:
+                        //TODO: Send him to nearby or default region instead
+                        break;
+                       
+                    default:
+                        throw;
+                }
             }
         }
     }
 }
 
+
+
+
+
-- 
cgit v1.1