OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
FetchInventory2Module.cs
Go to the documentation of this file.
1 /*
2  * Copyright (c) Contributors, http://opensimulator.org/
3  * See CONTRIBUTORS.TXT for a full list of copyright holders.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the OpenSimulator Project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 using Mono.Addins;
29 using Nini.Config;
30 using OpenMetaverse;
31 using OpenSim.Capabilities.Handlers;
32 using OpenSim.Framework.Servers.HttpServer;
33 using OpenSim.Region.Framework.Interfaces;
34 using OpenSim.Region.Framework.Scenes;
35 using OpenSim.Services.Interfaces;
36 using System;
38 
39 namespace OpenSim.Region.ClientStack.Linden
40 {
44  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "FetchInventory2Module")]
46  {
47 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 
49  public bool Enabled { get; private set; }
50 
51  private Scene m_scene;
52 
53  private IInventoryService m_inventoryService;
54 
55  private string m_fetchInventory2Url;
56 
57  #region ISharedRegionModule Members
58 
59  public void Initialise(IConfigSource source)
60  {
61  IConfig config = source.Configs["ClientStack.LindenCaps"];
62  if (config == null)
63  return;
64 
65  m_fetchInventory2Url = config.GetString("Cap_FetchInventory2", string.Empty);
66 
67  if (m_fetchInventory2Url != string.Empty)
68  Enabled = true;
69  }
70 
71  public void AddRegion(Scene s)
72  {
73  if (!Enabled)
74  return;
75 
76  m_scene = s;
77  }
78 
79  public void RemoveRegion(Scene s)
80  {
81  if (!Enabled)
82  return;
83 
84  m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
85  m_scene = null;
86  }
87 
88  public void RegionLoaded(Scene s)
89  {
90  if (!Enabled)
91  return;
92 
93  m_inventoryService = m_scene.InventoryService;
94 
95  m_scene.EventManager.OnRegisterCaps += RegisterCaps;
96  }
97 
98  public void PostInitialise() {}
99 
100  public void Close() {}
101 
102  public string Name { get { return "FetchInventory2Module"; } }
103 
104  public Type ReplaceableInterface
105  {
106  get { return null; }
107  }
108 
109  #endregion
110 
111  private void RegisterCaps(UUID agentID, Caps caps)
112  {
113  RegisterFetchCap(agentID, caps, "FetchInventory2", m_fetchInventory2Url);
114  }
115 
116  private void RegisterFetchCap(UUID agentID, Caps caps, string capName, string url)
117  {
118  string capUrl;
119 
120  if (url == "localhost")
121  {
122  capUrl = "/CAPS/" + UUID.Random();
123 
124  FetchInventory2Handler fetchHandler = new FetchInventory2Handler(m_inventoryService, agentID);
125 
126  IRequestHandler reqHandler
127  = new RestStreamHandler(
128  "POST", capUrl, fetchHandler.FetchInventoryRequest, capName, agentID.ToString());
129 
130  caps.RegisterHandler(capName, reqHandler);
131  }
132  else
133  {
134  capUrl = url;
135 
136  caps.RegisterHandler(capName, capUrl);
137  }
138 
139 // m_log.DebugFormat(
140 // "[FETCH INVENTORY2 MODULE]: Registered capability {0} at {1} in region {2} for {3}",
141 // capName, capUrl, m_scene.RegionInfo.RegionName, agentID);
142  }
143  }
144 }
void RegionLoaded(Scene s)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void AddRegion(Scene s)
This is called whenever a Scene is added. For shared modules, this can happen several times...
OpenSim.Framework.Capabilities.Caps Caps
This module implements both WebFetchInventoryDescendents and FetchInventoryDescendents2 capabilities...
OpenSim.Framework.Capabilities.Caps Caps
void RemoveRegion(Scene s)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...