PageRenderTime 35ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcommon/lleventcoro.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 146 lines | 78 code | 9 blank | 59 comment | 11 complexity | d583c16b248b6e5de673dd94e91e8df5 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lleventcoro.cpp
  3. * @author Nat Goodspeed
  4. * @date 2009-04-29
  5. * @brief Implementation for lleventcoro.
  6. *
  7. * $LicenseInfo:firstyear=2009&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. // Precompiled header
  29. #include "linden_common.h"
  30. // associated header
  31. #include "lleventcoro.h"
  32. // STL headers
  33. #include <map>
  34. // std headers
  35. // external library headers
  36. // other Linden headers
  37. #include "llsdserialize.h"
  38. #include "llerror.h"
  39. #include "llcoros.h"
  40. std::string LLEventDetail::listenerNameForCoroImpl(const void* self_id)
  41. {
  42. // First, if this coroutine was launched by LLCoros::launch(), find that name.
  43. std::string name(LLCoros::instance().getNameByID(self_id));
  44. if (! name.empty())
  45. {
  46. return name;
  47. }
  48. // Apparently this coroutine wasn't launched by LLCoros::launch(). Check
  49. // whether we have a memo for this self_id.
  50. typedef std::map<const void*, std::string> MapType;
  51. static MapType memo;
  52. MapType::const_iterator found = memo.find(self_id);
  53. if (found != memo.end())
  54. {
  55. // this coroutine instance has called us before, reuse same name
  56. return found->second;
  57. }
  58. // this is the first time we've been called for this coroutine instance
  59. name = LLEventPump::inventName("coro");
  60. memo[self_id] = name;
  61. LL_INFOS("LLEventCoro") << "listenerNameForCoroImpl(" << self_id << "): inventing coro name '"
  62. << name << "'" << LL_ENDL;
  63. return name;
  64. }
  65. void LLEventDetail::storeToLLSDPath(LLSD& dest, const LLSD& rawPath, const LLSD& value)
  66. {
  67. if (rawPath.isUndefined())
  68. {
  69. // no-op case
  70. return;
  71. }
  72. // Arrange to treat rawPath uniformly as an array. If it's not already an
  73. // array, store it as the only entry in one.
  74. LLSD path;
  75. if (rawPath.isArray())
  76. {
  77. path = rawPath;
  78. }
  79. else
  80. {
  81. path.append(rawPath);
  82. }
  83. // Need to indicate a current destination -- but that current destination
  84. // needs to change as we step through the path array. Where normally we'd
  85. // use an LLSD& to capture a subscripted LLSD lvalue, this time we must
  86. // instead use a pointer -- since it must be reassigned.
  87. LLSD* pdest = &dest;
  88. // Now loop through that array
  89. for (LLSD::Integer i = 0; i < path.size(); ++i)
  90. {
  91. if (path[i].isString())
  92. {
  93. // *pdest is an LLSD map
  94. pdest = &((*pdest)[path[i].asString()]);
  95. }
  96. else if (path[i].isInteger())
  97. {
  98. // *pdest is an LLSD array
  99. pdest = &((*pdest)[path[i].asInteger()]);
  100. }
  101. else
  102. {
  103. // What do we do with Real or Array or Map or ...?
  104. // As it's a coder error -- not a user error -- rub the coder's
  105. // face in it so it gets fixed.
  106. LL_ERRS("lleventcoro") << "storeToLLSDPath(" << dest << ", " << rawPath << ", " << value
  107. << "): path[" << i << "] bad type " << path[i].type() << LL_ENDL;
  108. }
  109. }
  110. // Here *pdest is where we should store value.
  111. *pdest = value;
  112. }
  113. LLSD errorException(const LLEventWithID& result, const std::string& desc)
  114. {
  115. // If the result arrived on the error pump (pump 1), instead of
  116. // returning it, deliver it via exception.
  117. if (result.second)
  118. {
  119. throw LLErrorEvent(desc, result.first);
  120. }
  121. // That way, our caller knows a simple return must be from the reply
  122. // pump (pump 0).
  123. return result.first;
  124. }
  125. LLSD errorLog(const LLEventWithID& result, const std::string& desc)
  126. {
  127. // If the result arrived on the error pump (pump 1), log it as a fatal
  128. // error.
  129. if (result.second)
  130. {
  131. LL_ERRS("errorLog") << desc << ":" << std::endl;
  132. LLSDSerialize::toPrettyXML(result.first, LL_CONT);
  133. LL_CONT << LL_ENDL;
  134. }
  135. // A simple return must therefore be from the reply pump (pump 0).
  136. return result.first;
  137. }