aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/InventoryServer
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Grid/InventoryServer')
-rw-r--r--OpenSim/Grid/InventoryServer/InventoryManager.cs131
-rw-r--r--OpenSim/Grid/InventoryServer/InventoryService.cs136
-rw-r--r--OpenSim/Grid/InventoryServer/Main.cs113
3 files changed, 318 insertions, 62 deletions
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 @@
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.Text;
30using System.Reflection;
29using System.Collections; 31using System.Collections;
30using System.Collections.Generic; 32using System.Collections.Generic;
31using System.Text;
32using OpenGrid.Framework.Data;
33using libsecondlife; 33using libsecondlife;
34using System.Reflection;
35 34
36using System.Xml; 35using System.Xml;
37using Nwc.XmlRpc; 36using OpenSim.Framework.Console;
38using OpenSim.Framework.Sims;
39using OpenSim.Framework.Inventory;
40using OpenSim.Framework.Utilities; 37using OpenSim.Framework.Utilities;
38using OpenSim.Framework.Data;
39using InventoryCategory = OpenSim.Framework.Data.InventoryCategory;
41 40
42using System.Security.Cryptography; 41namespace OpenSim.Grid.InventoryServer
43
44namespace OpenGridServices.InventoryServer
45{ 42{
46 class InventoryManager 43 class InventoryManager : IInventoryData
47 { 44 {
48 Dictionary<string, IInventoryData> _plugins = new Dictionary<string, IInventoryData>(); 45 IInventoryData _databasePlugin;
49 46
50 /// <summary> 47 /// <summary>
51 /// Adds a new inventory server plugin - user servers will be requested in the order they were loaded. 48 /// Adds a new inventory server plugin - user servers will be requested in the order they were loaded.
52 /// </summary> 49 /// </summary>
53 /// <param name="FileName">The filename to the inventory server plugin DLL</param> 50 /// <param name="FileName">The filename to the inventory server plugin DLL</param>
54 public void AddPlugin(string FileName) 51 public void AddDatabasePlugin(string FileName)
55 { 52 {
56 OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Invenstorage: Attempting to load " + FileName); 53 MainLog.Instance.Verbose(OpenInventory_Main.MainLogName, "Invenstorage: Attempting to load " + FileName);
57 Assembly pluginAssembly = Assembly.LoadFrom(FileName); 54 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
58 55
59 OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Invenstorage: Found " + pluginAssembly.GetTypes().Length + " interfaces."); 56 MainLog.Instance.Verbose(OpenInventory_Main.MainLogName, "Invenstorage: Found " + pluginAssembly.GetTypes().Length + " interfaces.");
60 foreach (Type pluginType in pluginAssembly.GetTypes()) 57 foreach (Type pluginType in pluginAssembly.GetTypes())
61 { 58 {
62 if (!pluginType.IsAbstract) 59 if (!pluginType.IsAbstract)
@@ -67,8 +64,9 @@ namespace OpenGridServices.InventoryServer
67 { 64 {
68 IInventoryData plug = (IInventoryData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); 65 IInventoryData plug = (IInventoryData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
69 plug.Initialise(); 66 plug.Initialise();
70 this._plugins.Add(plug.getName(), plug); 67 _databasePlugin = plug;
71 OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Invenstorage: Added IUserData Interface"); 68 MainLog.Instance.Verbose(OpenInventory_Main.MainLogName, "Invenstorage: Added IInventoryData Interface");
69 break;
72 } 70 }
73 71
74 typeInterface = null; 72 typeInterface = null;
@@ -80,46 +78,87 @@ namespace OpenGridServices.InventoryServer
80 78
81 public List<InventoryFolderBase> getRootFolders(LLUUID user) 79 public List<InventoryFolderBase> getRootFolders(LLUUID user)
82 { 80 {
83 foreach (KeyValuePair<string, IInventoryData> kvp in _plugins)
84 {
85 try
86 {
87 return kvp.Value.getUserRootFolders(user);
88 }
89 catch (Exception e)
90 {
91 OpenSim.Framework.Console.MainConsole.Instance.Notice("Unable to get root folders via " + kvp.Key + " (" + e.ToString() + ")");
92 }
93 }
94 return null; 81 return null;
95 } 82 }
96 83
97 public XmlRpcResponse XmlRpcInventoryRequest(XmlRpcRequest request) 84 #region IInventoryData Members
85
86
87 public List<InventoryItemBase> getInventoryInFolder(LLUUID folderID)
88 {
89 return _databasePlugin.getInventoryInFolder(folderID);
90 }
91
92 public List<InventoryFolderBase> getUserRootFolders(LLUUID user)
98 { 93 {
99 XmlRpcResponse response = new XmlRpcResponse(); 94 return _databasePlugin.getUserRootFolders(user);
100 Hashtable requestData = (Hashtable)request.Params[0]; 95 }
101 96
102 Hashtable responseData = new Hashtable(); 97 public List<InventoryFolderBase> getInventoryFolders(LLUUID parentID)
98 {
99 return _databasePlugin.getInventoryFolders(parentID);
100 }
103 101
104 // Stuff happens here 102 public InventoryItemBase getInventoryItem(LLUUID item)
103 {
104 throw new Exception("The method or operation is not implemented.");
105 }
105 106
106 if (requestData.ContainsKey("Access-type")) 107 public InventoryFolderBase getInventoryFolder(LLUUID folder)
107 { 108 {
108 if (requestData["access-type"] == "rootfolders") 109 return _databasePlugin.getInventoryFolder(folder);
109 { 110 }
110// responseData["rootfolders"] = 111
111 } 112 public void addInventoryItem(InventoryItemBase item)
112 } 113 {
113 else 114 _databasePlugin.addInventoryItem(item);
114 { 115 }
115 responseData["error"] = "No access-type specified."; 116
116 } 117 public void updateInventoryItem(InventoryItemBase item)
118 {
119 throw new Exception("The method or operation is not implemented.");
120 }
121
122 public void deleteInventoryItem(InventoryItemBase item)
123 {
124 throw new Exception("The method or operation is not implemented.");
125 }
126
127 public void addInventoryFolder(InventoryFolderBase folder)
128 {
129 _databasePlugin.addInventoryFolder(folder);
130 }
131
132 public void updateInventoryFolder(InventoryFolderBase folder)
133 {
134 throw new Exception("The method or operation is not implemented.");
135 }
136
137 public void Initialise()
138 {
139 throw new Exception("The method or operation is not implemented.");
140 }
141
142 public void Close()
143 {
144 throw new Exception("The method or operation is not implemented.");
145 }
117 146
147 public string getName()
148 {
149 throw new Exception("The method or operation is not implemented.");
150 }
118 151
119 // Stuff stops happening here 152 public string getVersion()
153 {
154 throw new Exception("The method or operation is not implemented.");
155 }
120 156
121 response.Value = responseData; 157 public void deleteInventoryCategory(InventoryCategory inventoryCategory)
122 return response; 158 {
159 _databasePlugin.deleteInventoryCategory(inventoryCategory);
123 } 160 }
161
162 #endregion
124 } 163 }
125} 164}
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 @@
1using System;
2using System.Runtime.Remoting;
3using System.Runtime.Remoting.Channels;
4using System.Runtime.Remoting.Channels.Tcp;
5using System.Runtime.Serialization.Formatters;
6using System.Collections;
7using System.Collections.Generic;
8
9
10using libsecondlife;
11using OpenSim.Framework.Data;
12using OpenSim.Framework.Communications;
13using OpenSim.Framework.Configuration;
14using InventoryCategory = OpenSim.Framework.Data.InventoryCategory;
15
16namespace OpenSim.Grid.InventoryServer
17{
18 class InventoryServiceSingleton : OpenSim.Framework.Communications.InventoryServiceBase
19 {
20 static InventoryManager _inventoryManager;
21
22 static public InventoryManager InventoryManager
23 {
24 set { _inventoryManager = value; }
25 get { return _inventoryManager; }
26 }
27
28#region Singleton Pattern
29 static InventoryServiceSingleton instance=null;
30
31 InventoryServiceSingleton()
32 {
33 }
34
35 public static InventoryServiceSingleton Instance
36 {
37 get
38 {
39 if (instance==null)
40 {
41 instance = new InventoryServiceSingleton();
42 }
43 return instance;
44 }
45 }
46#endregion
47
48#region IInventoryServices Members
49
50 public override void RequestInventoryForUser(LLUUID userID, InventoryFolderInfo folderCallBack, InventoryItemInfo itemCallBack)
51 {
52 List<InventoryFolderBase> folders = this.RequestFirstLevelFolders(userID);
53 InventoryFolderBase rootFolder = null;
54
55 //need to make sure we send root folder first
56 foreach (InventoryFolderBase folder in folders)
57 {
58 if (folder.parentID == libsecondlife.LLUUID.Zero)
59 {
60 rootFolder = folder;
61 folderCallBack(userID, folder);
62 }
63 }
64
65 if (rootFolder != null)
66 {
67 foreach (InventoryFolderBase folder in folders)
68 {
69 if (folder.folderID != rootFolder.folderID)
70 {
71 folderCallBack(userID, folder);
72
73 List<InventoryItemBase> items = this.RequestFolderItems(folder.folderID);
74 foreach (InventoryItemBase item in items)
75 {
76 itemCallBack(userID, item);
77 }
78 }
79 }
80 }
81
82 }
83
84 public override void AddNewInventoryFolder(LLUUID userID, InventoryFolderBase folder)
85 {
86 _inventoryManager.addInventoryFolder(folder);
87 }
88
89 public override void AddNewInventoryItem(LLUUID userID, InventoryItemBase item)
90 {
91 throw new Exception("Not implemented exception");
92 }
93
94 public override void DeleteInventoryItem(LLUUID userID, InventoryItemBase item)
95 {
96 throw new Exception("Not implemented exception");
97 }
98
99 public List<InventoryItemBase> RequestFolderItems(LLUUID folderID)
100 {
101 return _inventoryManager.getInventoryInFolder(folderID);
102 }
103
104
105#endregion
106 }
107
108 class InventoryService
109 {
110 InventoryServiceSingleton _inventoryServiceMethods;
111 public InventoryService(InventoryManager inventoryManager, InventoryConfig cfg)
112 {
113 // we only need to register the tcp channel once, and we don't know which other modules use remoting
114 if (ChannelServices.GetChannel("tcp") == null)
115 {
116 // Creating a custom formatter for a TcpChannel sink chain.
117 BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
118 serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
119
120 IDictionary props = new Hashtable();
121 props["port"] = cfg.RemotingPort;
122 props["typeFilterLevel"] = TypeFilterLevel.Full;
123
124 // Pass the properties for the port setting and the server provider in the server chain argument. (Client remains null here.)
125 ChannelServices.RegisterChannel(new TcpChannel(props, null, serverProvider), true);
126 }
127
128 // Register the object
129 RemotingConfiguration.RegisterWellKnownServiceType(typeof(InventoryServiceSingleton), "Inventory", WellKnownObjectMode.Singleton);
130
131 _inventoryServiceMethods = InventoryServiceSingleton.Instance;
132 InventoryServiceSingleton.InventoryManager = inventoryManager;
133 }
134
135 }
136}
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;
31using System.Reflection; 31using System.Reflection;
32using System.IO; 32using System.IO;
33using System.Text; 33using System.Text;
34using System.Xml;
35
34using libsecondlife; 36using libsecondlife;
35using OpenSim.Framework.User;
36using OpenSim.Framework.Sims;
37using OpenSim.Framework.Inventory;
38using OpenSim.Framework.Interfaces; 37using OpenSim.Framework.Interfaces;
39using OpenSim.Framework.Console; 38using OpenSim.Framework.Console;
40using OpenSim.Servers;
41using OpenSim.Framework.Utilities; 39using OpenSim.Framework.Utilities;
40using OpenSim.Framework.Configuration;
41using OpenSim.Framework.Data;
42using InventoryCategory = OpenSim.Framework.Data.InventoryCategory;
42 43
43namespace OpenGridServices.InventoryServer 44namespace OpenSim.Grid.InventoryServer
44{ 45{
45 public class OpenInventory_Main : BaseServer, conscmd_callback 46
47 public class OpenInventory_Main : conscmd_callback
46 { 48 {
47 ConsoleBase m_console;
48 InventoryManager m_inventoryManager;
49 49
50 public const string MainLogName = "INVENTORY";
51
52 private InventoryConfig m_config;
53 LogBase m_console;
54 InventoryManager m_inventoryManager; ///connection the database backend
55 InventoryService m_inventoryService; ///Remoting interface, where messages arrive
56 [STAThread]
50 public static void Main(string[] args) 57 public static void Main(string[] args)
51 { 58 {
59 Console.WriteLine("Launching InventoryServer...");
60
61 OpenInventory_Main inventoryServer = new OpenInventory_Main();
62
63 inventoryServer.Startup();
64
65// inventoryServer.RunCmd("load", new string[] { "library", "inventory_library.xml" });
66// inventoryServer.RunCmd("load", new string[] { "default", "inventory_default.xml" });
67
68 inventoryServer.Work();
52 } 69 }
53 70
54 public OpenInventory_Main() 71 public OpenInventory_Main()
55 { 72 {
56 m_console = new ConsoleBase("opengrid-inventory-console.log", "OpenInventory", this, false); 73
57 MainConsole.Instance = m_console; 74 if (!Directory.Exists(Util.logDir()))
75 {
76 Directory.CreateDirectory(Util.logDir());
77 }
78
79 m_console = new LogBase(Path.Combine(Util.logDir(), "opensim-inventory-console.log"), "OpenInventory", this, false);
80 MainLog.Instance = m_console;
81 }
82
83 private void Work()
84 {
85 m_console.Notice(OpenInventory_Main.MainLogName, "Enter help for a list of commands\n");
86
87 while (true)
88 {
89 m_console.MainLogPrompt();
90 }
58 } 91 }
59 92
60 public void Startup() 93 public void Startup()
61 { 94 {
62 MainConsole.Instance.Notice("Initialising inventory manager..."); 95 MainLog.Instance.Verbose(OpenInventory_Main.MainLogName, "Initialising inventory manager...");
96
97 m_config = new InventoryConfig(OpenInventory_Main.MainLogName, (Path.Combine(Util.configDir(), "InventoryServer_Config.xml")));
98
99 // instantiate the manager, responsible for doing the actual storage
63 m_inventoryManager = new InventoryManager(); 100 m_inventoryManager = new InventoryManager();
101 m_inventoryManager.AddDatabasePlugin(m_config.DatabaseProvider);
102
103 m_inventoryService = new InventoryService(m_inventoryManager, m_config);
64 104
65 MainConsole.Instance.Notice("Starting HTTP server"); 105 // Dig out the embedded version number of this assembly
66 BaseHttpServer httpServer = new BaseHttpServer(8004); 106 Assembly assembly = Assembly.GetExecutingAssembly();
107 string serverExeName = assembly.ManifestModule.Name;
108 Version serverExeVersion = AssemblyName.GetAssemblyName(serverExeName).Version;
67 109
68 httpServer.AddXmlRPCHandler("rootfolders", m_inventoryManager.XmlRpcInventoryRequest); 110 m_console.Status(OpenInventory_Main.MainLogName, "Inventoryserver {0}.{1}.{2}.{3} - Startup complete", serverExeVersion.Major, serverExeVersion.Minor, serverExeVersion.Revision, serverExeVersion.Build);
69 //httpServer.AddRestHandler("GET","/rootfolders/",Rest
70 } 111 }
71 112
72 public void RunCmd(string cmd, string[] cmdparams) 113
114 public void Load(string[] cmdparams)
73 { 115 {
116 string cmd = cmdparams[0];
117 string fileName = cmdparams[1];
118
119 if (cmdparams.Length != 2)
120 {
121 cmd = "help";
122 }
123
74 switch (cmd) 124 switch (cmd)
75 { 125 {
126 case "library":
127 InventoryServiceSingleton.Instance.loadInventoryFromXmlFile(InventoryCategory.Library, fileName);
128 break;
129 case "default":
130 InventoryServiceSingleton.Instance.loadInventoryFromXmlFile(InventoryCategory.Default, fileName);
131 break;
132 case "user":
133 InventoryServiceSingleton.Instance.loadInventoryFromXmlFile(InventoryCategory.User, fileName);
134 break;
135 case "help":
136 m_console.Notice("load library <filename>, load library inventory, shared between all users");
137 m_console.Notice("load default <filename>, load template inventory, used when creating a new user inventory");
138 m_console.Notice("load user <first> <last>, load inventory for a specific users, warning this will reset the contents of the inventory");
139 break;
140 }
141 }
142
143 public void RunCmd(string cmd, string[] cmdparams)
144 {
145 switch (cmd)
146 {
147 case "help":
148 m_console.Notice("load - load verious inventories, use \"load help\", to see a list of commands");
149 m_console.Notice("shutdown - shutdown the grid (USE CAUTION!)");
150 m_console.Notice("quit - shutdown the grid (USE CAUTION!)");
151 break;
152 case "load":
153 Load(cmdparams);
154 break;
155 case "quit":
76 case "shutdown": 156 case "shutdown":
157 MainLog.Instance.Verbose(OpenInventory_Main.MainLogName, "Shutting down inventory server");
77 m_console.Close(); 158 m_console.Close();
78 Environment.Exit(0); 159 Environment.Exit(0);
79 break; 160 break;