aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-05-09 23:25:01 +0100
committerJustin Clark-Casey (justincc)2012-05-09 23:25:01 +0100
commitd8a78374aa11c5460d6e58a6f4110fca61dfded4 (patch)
tree4214094c092eeff11f2dcd60f71cfc294ab887be /OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs
parentImprove logging on the prim inventory script asset request path for future use. (diff)
downloadopensim-SC-d8a78374aa11c5460d6e58a6f4110fca61dfded4.zip
opensim-SC-d8a78374aa11c5460d6e58a6f4110fca61dfded4.tar.gz
opensim-SC-d8a78374aa11c5460d6e58a6f4110fca61dfded4.tar.bz2
opensim-SC-d8a78374aa11c5460d6e58a6f4110fca61dfded4.tar.xz
Where necessary, rename OpenSim/Services/Connectors/*.cs files to reflect the actual class names.
This is usually because the file name was singular (*Service*) but the class name was plural (*Services*). This is to make configuration easier rather than having to look in the c# code itself to find the slightly different name of the connector. This does not affect existing configuration since the files are being renamed rather than the classes.
Diffstat (limited to 'OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs159
1 files changed, 159 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs b/OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs
new file mode 100644
index 0000000..30bfb70
--- /dev/null
+++ b/OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs
@@ -0,0 +1,159 @@
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
28using log4net;
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Net;
33using System.Reflection;
34
35using Nini.Config;
36using OpenSim.Framework;
37using OpenSim.Framework.Console;
38using OpenSim.Framework.Communications;
39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces;
41using OpenMetaverse;
42using OpenMetaverse.StructuredData;
43
44namespace OpenSim.Services.Connectors
45{
46 public class MapImageServicesConnector : IMapImageService
47 {
48 private static readonly ILog m_log =
49 LogManager.GetLogger(
50 MethodBase.GetCurrentMethod().DeclaringType);
51
52 private string m_ServerURI = String.Empty;
53
54 public MapImageServicesConnector()
55 {
56 }
57
58 public MapImageServicesConnector(string serverURI)
59 {
60 m_ServerURI = serverURI.TrimEnd('/');
61 }
62
63 public MapImageServicesConnector(IConfigSource source)
64 {
65 Initialise(source);
66 }
67
68 public virtual void Initialise(IConfigSource source)
69 {
70 IConfig config = source.Configs["MapImageService"];
71 if (config == null)
72 {
73 m_log.Error("[MAP IMAGE CONNECTOR]: MapImageService missing");
74 throw new Exception("MapImage connector init error");
75 }
76
77 string serviceURI = config.GetString("MapImageServerURI",
78 String.Empty);
79
80 if (serviceURI == String.Empty)
81 {
82 m_log.Error("[MAP IMAGE CONNECTOR]: No Server URI named in section MapImageService");
83 throw new Exception("MapImage connector init error");
84 }
85 m_ServerURI = serviceURI;
86 m_ServerURI = serviceURI.TrimEnd('/');
87 }
88
89 public bool AddMapTile(int x, int y, byte[] jpgData, out string reason)
90 {
91 reason = string.Empty;
92 int tickstart = Util.EnvironmentTickCount();
93 Dictionary<string, object> sendData = new Dictionary<string, object>();
94 sendData["X"] = x.ToString();
95 sendData["Y"] = y.ToString();
96 sendData["TYPE"] = "image/jpeg";
97 sendData["DATA"] = Convert.ToBase64String(jpgData);
98
99 string reqString = ServerUtils.BuildQueryString(sendData);
100 string uri = m_ServerURI + "/map";
101
102 try
103 {
104 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
105 uri,
106 reqString);
107 if (reply != string.Empty)
108 {
109 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
110
111 if (replyData.ContainsKey("Result") && (replyData["Result"].ToString().ToLower() == "success"))
112 {
113 return true;
114 }
115 else if (replyData.ContainsKey("Result") && (replyData["Result"].ToString().ToLower() == "failure"))
116 {
117 m_log.DebugFormat("[MAP IMAGE CONNECTOR]: Registration failed: {0}", replyData["Message"].ToString());
118 reason = replyData["Message"].ToString();
119 return false;
120 }
121 else if (!replyData.ContainsKey("Result"))
122 {
123 m_log.DebugFormat("[MAP IMAGE CONNECTOR]: reply data does not contain result field");
124 }
125 else
126 {
127 m_log.DebugFormat("[MAP IMAGE CONNECTOR]: unexpected result {0}", replyData["Result"].ToString());
128 reason = "Unexpected result " + replyData["Result"].ToString();
129 }
130
131 }
132 else
133 {
134 m_log.DebugFormat("[MAP IMAGE CONNECTOR]: Map post received null reply");
135 }
136 }
137 catch (Exception e)
138 {
139 m_log.DebugFormat("[MAP IMAGE CONNECTOR]: Exception when contacting map server at {0}: {1}", uri, e.Message);
140 }
141 finally
142 {
143 // This just dumps a warning for any operation that takes more than 100 ms
144 int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
145 m_log.DebugFormat("[MAP IMAGE CONNECTOR]: map tile uploaded in {0}ms", tickdiff);
146 }
147
148 return false;
149
150 }
151
152 public byte[] GetMapTile(string fileName, out string format)
153 {
154 format = string.Empty;
155 new Exception("GetMapTile method not Implemented");
156 return null;
157 }
158 }
159}