llpathfindingobject.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /**
  2. * @file llpathfindingobject.cpp
  3. * @brief Implementation of llpathfindingobject
  4. *
  5. * $LicenseInfo:firstyear=2012&license=viewergpl$
  6. *
  7. * Copyright (c) 2012, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llpathfindingobject.h"
  34. #include "llcachename.h"
  35. #include "llsd.h"
  36. #define PATHFINDING_OBJECT_NAME_FIELD "name"
  37. #define PATHFINDING_OBJECT_DESCRIPTION_FIELD "description"
  38. #define PATHFINDING_OBJECT_OWNER_FIELD "owner"
  39. #define PATHFINDING_OBJECT_POSITION_FIELD "position"
  40. #define PATHFINDING_OBJECT_IS_GROUP_OWNED_FIELD "owner_is_group"
  41. //static
  42. LLPathfindingObject::pathfinding_obj_list_t LLPathfindingObject::sGroupQueriesList;
  43. uuid_list_t LLPathfindingObject::sPendingGroupUUIDs;
  44. LLPathfindingObject::LLPathfindingObject()
  45. : mHasOwnerName(false),
  46. mIsGroupOwned(false),
  47. mAvatarNameCacheConnection(),
  48. mOwnerNameSignal()
  49. {
  50. }
  51. LLPathfindingObject::LLPathfindingObject(const LLUUID& id, const LLSD& obj_data)
  52. : mUUID(id),
  53. mHasOwnerName(false),
  54. mIsGroupOwned(false),
  55. mAvatarNameCacheConnection(),
  56. mOwnerNameSignal()
  57. {
  58. parseObjectData(obj_data);
  59. }
  60. LLPathfindingObject::LLPathfindingObject(const LLPathfindingObject& obj)
  61. : mUUID(obj.mUUID),
  62. mName(obj.mName),
  63. mDescription(obj.mDescription),
  64. mOwnerUUID(obj.mOwnerUUID),
  65. mHasOwnerName(false),
  66. mIsGroupOwned(obj.mIsGroupOwned),
  67. mLocation(obj.mLocation),
  68. mAvatarNameCacheConnection(),
  69. mOwnerNameSignal()
  70. {
  71. fetchOwnerName();
  72. }
  73. LLPathfindingObject::~LLPathfindingObject()
  74. {
  75. disconnectAvatarNameCacheConnection();
  76. sGroupQueriesList.erase(this);
  77. }
  78. LLPathfindingObject& LLPathfindingObject::operator=(const LLPathfindingObject& obj)
  79. {
  80. mUUID = obj.mUUID;
  81. mName = obj.mName;
  82. mDescription = obj.mDescription;
  83. mOwnerUUID = obj.mOwnerUUID;
  84. fetchOwnerName();
  85. mIsGroupOwned = obj.mIsGroupOwned;
  86. mLocation = obj.mLocation;
  87. return *this;
  88. }
  89. std::string LLPathfindingObject::getOwnerName() const
  90. {
  91. if (!hasOwner())
  92. {
  93. return "";
  94. }
  95. return mIsGroupOwned ? mGroupName : mOwnerName.getLegacyName();
  96. }
  97. void LLPathfindingObject::parseObjectData(const LLSD& obj_data)
  98. {
  99. if (obj_data.has(PATHFINDING_OBJECT_NAME_FIELD) &&
  100. obj_data.get(PATHFINDING_OBJECT_NAME_FIELD).isString())
  101. {
  102. mName = obj_data.get(PATHFINDING_OBJECT_NAME_FIELD).asString();
  103. }
  104. else
  105. {
  106. llwarns << "Malformed pathfinding object data: no name" << llendl;
  107. }
  108. if (obj_data.has(PATHFINDING_OBJECT_DESCRIPTION_FIELD) &&
  109. obj_data.get(PATHFINDING_OBJECT_DESCRIPTION_FIELD).isString())
  110. {
  111. mDescription =
  112. obj_data.get(PATHFINDING_OBJECT_DESCRIPTION_FIELD).asString();
  113. }
  114. else
  115. {
  116. llwarns << "Malformed pathfinding object data: no description"
  117. << llendl;
  118. }
  119. if (obj_data.has(PATHFINDING_OBJECT_IS_GROUP_OWNED_FIELD))
  120. {
  121. if (obj_data.get(PATHFINDING_OBJECT_IS_GROUP_OWNED_FIELD).isBoolean())
  122. {
  123. mIsGroupOwned =
  124. obj_data.get(PATHFINDING_OBJECT_IS_GROUP_OWNED_FIELD).asBoolean();
  125. }
  126. else
  127. {
  128. llwarns << "Malformed pathfinding object data: bad group flag"
  129. << llendl;
  130. }
  131. }
  132. if (obj_data.has(PATHFINDING_OBJECT_OWNER_FIELD) &&
  133. obj_data.get(PATHFINDING_OBJECT_OWNER_FIELD).isUUID())
  134. {
  135. mOwnerUUID = obj_data.get(PATHFINDING_OBJECT_OWNER_FIELD).asUUID();
  136. fetchOwnerName();
  137. }
  138. else
  139. {
  140. llwarns << "Malformed pathfinding object data: no owner UUID"
  141. << llendl;
  142. }
  143. if (obj_data.has(PATHFINDING_OBJECT_POSITION_FIELD) &&
  144. obj_data.get(PATHFINDING_OBJECT_POSITION_FIELD).isArray())
  145. {
  146. mLocation.setValue(obj_data.get(PATHFINDING_OBJECT_POSITION_FIELD));
  147. }
  148. else
  149. {
  150. llwarns << "Malformed pathfinding object data: no position"
  151. << llendl;
  152. }
  153. }
  154. LLPathfindingObject::name_connection_t LLPathfindingObject::registerOwnerNameListener(name_callback_t callback)
  155. {
  156. llassert(hasOwner());
  157. name_connection_t connection;
  158. if (hasOwnerName())
  159. {
  160. callback(this);
  161. }
  162. else
  163. {
  164. connection = mOwnerNameSignal.connect(callback);
  165. }
  166. return connection;
  167. }
  168. void LLPathfindingObject::fetchOwnerName()
  169. {
  170. mHasOwnerName = false;
  171. if (!hasOwner())
  172. {
  173. return;
  174. }
  175. if (mIsGroupOwned)
  176. {
  177. if (!gCacheNamep) return; // Paranoia
  178. mHasOwnerName = gCacheNamep->getGroupName(mOwnerUUID, mGroupName);
  179. if (!mHasOwnerName)
  180. {
  181. sGroupQueriesList.insert(this);
  182. gCacheNamep->get(mOwnerUUID, true,
  183. boost::bind(&LLPathfindingObject::handleGroupNameFetch,
  184. _1, _2, _3, this));
  185. }
  186. }
  187. else
  188. {
  189. mHasOwnerName = LLAvatarNameCache::get(mOwnerUUID, &mOwnerName);
  190. if (!mHasOwnerName)
  191. {
  192. disconnectAvatarNameCacheConnection();
  193. mAvatarNameCacheConnection =
  194. LLAvatarNameCache::get(mOwnerUUID,
  195. boost::bind(&LLPathfindingObject::handleAvatarNameFetch,
  196. this, _1, _2));
  197. }
  198. }
  199. if (mHasOwnerName)
  200. {
  201. mOwnerNameSignal(this);
  202. }
  203. }
  204. //static
  205. void LLPathfindingObject::handleGroupNameFetch(const LLUUID& group_id,
  206. const std::string& name,
  207. bool is_group,
  208. LLPathfindingObject* self)
  209. {
  210. if (sGroupQueriesList.count(self))
  211. {
  212. sGroupQueriesList.erase(self);
  213. self->mGroupName = name;
  214. self->mHasOwnerName = true;
  215. self->mOwnerNameSignal(self);
  216. }
  217. }
  218. void LLPathfindingObject::handleAvatarNameFetch(const LLUUID& av_id,
  219. const LLAvatarName& av_name)
  220. {
  221. if (mOwnerUUID == av_id)
  222. {
  223. mOwnerName = av_name;
  224. mHasOwnerName = true;
  225. disconnectAvatarNameCacheConnection();
  226. mOwnerNameSignal(this);
  227. }
  228. else
  229. {
  230. llwarns << "Incorrect UUID in avatar name request reply" << llendl;
  231. }
  232. }
  233. void LLPathfindingObject::disconnectAvatarNameCacheConnection()
  234. {
  235. if (mAvatarNameCacheConnection.connected())
  236. {
  237. mAvatarNameCacheConnection.disconnect();
  238. }
  239. }