OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
WorldViewModule.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 System;
29 using System.Collections.Generic;
30 using System.Drawing;
31 using System.Drawing.Imaging;
32 using System.Reflection;
33 using System.IO;
34 using log4net;
35 using Mono.Addins;
36 using Nini.Config;
37 using OpenMetaverse;
38 using OpenMetaverse.Imaging;
39 using OpenSim.Framework;
40 using OpenSim.Framework.Servers;
41 using OpenSim.Region.Framework.Interfaces;
42 using OpenSim.Region.Framework.Scenes;
43 using OpenSim.Server.Base;
44 using OpenSim.Framework.Servers.HttpServer;
45 using OpenSim.Services.Interfaces;
46 
47 namespace OpenSim.Region.OptionalModules.World.WorldView
48 {
49  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "WorldViewModule")]
51  {
52  private static readonly ILog m_log =
53  LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54 
55 
56  private bool m_Enabled = false;
57  private IMapImageGenerator m_Generator;
58 
59  public void Initialise(IConfigSource config)
60  {
61  IConfig moduleConfig = config.Configs["Modules"];
62  if (moduleConfig == null)
63  return;
64 
65  if (moduleConfig.GetString("WorldViewModule", String.Empty) != Name)
66  return;
67 
68  m_Enabled = true;
69  }
70 
71  public void AddRegion(Scene scene)
72  {
73  }
74 
75  public void RegionLoaded(Scene scene)
76  {
77  if (!m_Enabled)
78  return;
79 
80  m_Generator = scene.RequestModuleInterface<IMapImageGenerator>();
81  if (m_Generator == null)
82  {
83  m_Enabled = false;
84  return;
85  }
86 
87  m_log.Info("[WORLDVIEW]: Configured and enabled");
88 
89  IHttpServer server = MainServer.GetHttpServer(0);
90  server.AddStreamHandler(new WorldViewRequestHandler(this,
91  scene.RegionInfo.RegionID.ToString()));
92  }
93 
94  public void RemoveRegion(Scene scene)
95  {
96  }
97 
98  public string Name
99  {
100  get { return "WorldViewModule"; }
101  }
102 
103  public Type ReplaceableInterface
104  {
105  get { return null; }
106  }
107 
108  public void Close()
109  {
110  }
111 
112  public byte[] GenerateWorldView(Vector3 pos, Vector3 rot, float fov,
113  int width, int height, bool usetex)
114  {
115  if (!m_Enabled)
116  return new Byte[0];
117 
118  using (Bitmap bmp = m_Generator.CreateViewImage(pos, rot, fov, width, height, usetex))
119  {
120  using (MemoryStream str = new MemoryStream())
121  {
122  bmp.Save(str, ImageFormat.Jpeg);
123 
124  return str.ToArray();
125  }
126  }
127  }
128  }
129 }
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
byte[] GenerateWorldView(Vector3 pos, Vector3 rot, float fov, int width, int height, bool usetex)
Interface to OpenSimulator's built in HTTP server. Use this to register handlers (http, llsd, xmlrpc, etc.) for given URLs.
Definition: IHttpServer.cs:36
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
Interactive OpenSim region server
Definition: OpenSim.cs:55
void Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...