PageRenderTime 50ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llremoteparcelrequest.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 197 lines | 126 code | 28 blank | 43 comment | 16 complexity | cb5d101b1b8d744dab25da232ab68a64 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llremoteparcelrequest.cpp
  3. * @author Sam Kolb
  4. * @brief Get information about a parcel you aren't standing in to display
  5. * landmark/teleport information.
  6. *
  7. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. #include "llviewerprecompiledheaders.h"
  29. #include "message.h"
  30. #include "llpanel.h"
  31. #include "llhttpclient.h"
  32. #include "llsdserialize.h"
  33. #include "llurlentry.h"
  34. #include "llviewerregion.h"
  35. #include "llview.h"
  36. #include "llagent.h"
  37. #include "llremoteparcelrequest.h"
  38. LLRemoteParcelRequestResponder::LLRemoteParcelRequestResponder(LLHandle<LLRemoteParcelInfoObserver> observer_handle)
  39. : mObserverHandle(observer_handle)
  40. {}
  41. //If we get back a normal response, handle it here
  42. //virtual
  43. void LLRemoteParcelRequestResponder::result(const LLSD& content)
  44. {
  45. LLUUID parcel_id = content["parcel_id"];
  46. // Panel inspecting the information may be closed and destroyed
  47. // before this response is received.
  48. LLRemoteParcelInfoObserver* observer = mObserverHandle.get();
  49. if (observer)
  50. {
  51. observer->setParcelID(parcel_id);
  52. }
  53. }
  54. //If we get back an error (not found, etc...), handle it here
  55. //virtual
  56. void LLRemoteParcelRequestResponder::error(U32 status, const std::string& reason)
  57. {
  58. llinfos << "LLRemoteParcelRequest::error("
  59. << status << ": " << reason << ")" << llendl;
  60. // Panel inspecting the information may be closed and destroyed
  61. // before this response is received.
  62. LLRemoteParcelInfoObserver* observer = mObserverHandle.get();
  63. if (observer)
  64. {
  65. observer->setErrorStatus(status, reason);
  66. }
  67. }
  68. void LLRemoteParcelInfoProcessor::addObserver(const LLUUID& parcel_id, LLRemoteParcelInfoObserver* observer)
  69. {
  70. observer_multimap_t::iterator it;
  71. observer_multimap_t::iterator start = mObservers.lower_bound(parcel_id);
  72. observer_multimap_t::iterator end = mObservers.upper_bound(parcel_id);
  73. // Check if the observer is already in observers list for this UUID
  74. for(it = start; it != end; ++it)
  75. {
  76. if (it->second.get() == observer)
  77. {
  78. return;
  79. }
  80. }
  81. mObservers.insert(std::make_pair(parcel_id, observer->getObserverHandle()));
  82. }
  83. void LLRemoteParcelInfoProcessor::removeObserver(const LLUUID& parcel_id, LLRemoteParcelInfoObserver* observer)
  84. {
  85. if (!observer)
  86. {
  87. return;
  88. }
  89. observer_multimap_t::iterator it;
  90. observer_multimap_t::iterator start = mObservers.lower_bound(parcel_id);
  91. observer_multimap_t::iterator end = mObservers.upper_bound(parcel_id);
  92. for(it = start; it != end; ++it)
  93. {
  94. if (it->second.get() == observer)
  95. {
  96. mObservers.erase(it);
  97. break;
  98. }
  99. }
  100. }
  101. //static
  102. void LLRemoteParcelInfoProcessor::processParcelInfoReply(LLMessageSystem* msg, void**)
  103. {
  104. LLParcelData parcel_data;
  105. msg->getUUID ("Data", "ParcelID", parcel_data.parcel_id);
  106. msg->getUUID ("Data", "OwnerID", parcel_data.owner_id);
  107. msg->getString ("Data", "Name", parcel_data.name);
  108. msg->getString ("Data", "Desc", parcel_data.desc);
  109. msg->getS32 ("Data", "ActualArea", parcel_data.actual_area);
  110. msg->getS32 ("Data", "BillableArea", parcel_data.billable_area);
  111. msg->getU8 ("Data", "Flags", parcel_data.flags);
  112. msg->getF32 ("Data", "GlobalX", parcel_data.global_x);
  113. msg->getF32 ("Data", "GlobalY", parcel_data.global_y);
  114. msg->getF32 ("Data", "GlobalZ", parcel_data.global_z);
  115. msg->getString ("Data", "SimName", parcel_data.sim_name);
  116. msg->getUUID ("Data", "SnapshotID", parcel_data.snapshot_id);
  117. msg->getF32 ("Data", "Dwell", parcel_data.dwell);
  118. msg->getS32 ("Data", "SalePrice", parcel_data.sale_price);
  119. msg->getS32 ("Data", "AuctionID", parcel_data.auction_id);
  120. LLRemoteParcelInfoProcessor::observer_multimap_t & observers = LLRemoteParcelInfoProcessor::getInstance()->mObservers;
  121. typedef std::vector<observer_multimap_t::iterator> deadlist_t;
  122. deadlist_t dead_iters;
  123. observer_multimap_t::iterator oi = observers.lower_bound(parcel_data.parcel_id);
  124. observer_multimap_t::iterator end = observers.upper_bound(parcel_data.parcel_id);
  125. while (oi != end)
  126. {
  127. // increment the loop iterator now since it may become invalid below
  128. observer_multimap_t::iterator cur_oi = oi++;
  129. LLRemoteParcelInfoObserver * observer = cur_oi->second.get();
  130. if(observer)
  131. {
  132. // may invalidate cur_oi if the observer removes itself
  133. observer->processParcelInfo(parcel_data);
  134. }
  135. else
  136. {
  137. // the handle points to an expired observer, so don't keep it
  138. // around anymore
  139. dead_iters.push_back(cur_oi);
  140. }
  141. }
  142. deadlist_t::iterator i;
  143. deadlist_t::iterator end_dead = dead_iters.end();
  144. for(i = dead_iters.begin(); i != end_dead; ++i)
  145. {
  146. observers.erase(*i);
  147. }
  148. LLUrlEntryParcel::LLParcelData url_data;
  149. url_data.parcel_id = parcel_data.parcel_id;
  150. url_data.name = parcel_data.name;
  151. url_data.sim_name = parcel_data.sim_name;
  152. url_data.global_x = parcel_data.global_x;
  153. url_data.global_y = parcel_data.global_y;
  154. url_data.global_z = parcel_data.global_z;
  155. // Pass the parcel data to LLUrlEntryParcel to render
  156. // human readable parcel name.
  157. LLUrlEntryParcel::processParcelInfo(url_data);
  158. }
  159. void LLRemoteParcelInfoProcessor::sendParcelInfoRequest(const LLUUID& parcel_id)
  160. {
  161. LLMessageSystem *msg = gMessageSystem;
  162. msg->newMessage("ParcelInfoRequest");
  163. msg->nextBlockFast(_PREHASH_AgentData);
  164. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
  165. msg->addUUID("SessionID", gAgent.getSessionID());
  166. msg->nextBlock("Data");
  167. msg->addUUID("ParcelID", parcel_id);
  168. gAgent.sendReliableMessage();
  169. }