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

/indra/newview/llmainlooprepeater.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 88 lines | 45 code | 16 blank | 27 comment | 4 complexity | 864075d634d0c75a59bda98f6522cc6f MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llmachineid.cpp
  3. * @brief retrieves unique machine ids
  4. *
  5. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llapr.h"
  28. #include "llevents.h"
  29. #include "llmainlooprepeater.h"
  30. // LLMainLoopRepeater
  31. //-----------------------------------------------------------------------------
  32. LLMainLoopRepeater::LLMainLoopRepeater(void):
  33. mQueue(0)
  34. {
  35. ; // No op.
  36. }
  37. void LLMainLoopRepeater::start(void)
  38. {
  39. if(mQueue != 0) return;
  40. mQueue = new LLThreadSafeQueue<LLSD>(gAPRPoolp, 1024);
  41. mMainLoopConnection = LLEventPumps::instance().
  42. obtain("mainloop").listen(LLEventPump::inventName(), boost::bind(&LLMainLoopRepeater::onMainLoop, this, _1));
  43. mRepeaterConnection = LLEventPumps::instance().
  44. obtain("mainlooprepeater").listen(LLEventPump::inventName(), boost::bind(&LLMainLoopRepeater::onMessage, this, _1));
  45. }
  46. void LLMainLoopRepeater::stop(void)
  47. {
  48. mMainLoopConnection.release();
  49. mRepeaterConnection.release();
  50. delete mQueue;
  51. mQueue = 0;
  52. }
  53. bool LLMainLoopRepeater::onMainLoop(LLSD const &)
  54. {
  55. LLSD message;
  56. while(mQueue->tryPopBack(message)) {
  57. std::string pump = message["pump"].asString();
  58. if(pump.length() == 0 ) continue; // No pump.
  59. LLEventPumps::instance().obtain(pump).post(message["payload"]);
  60. }
  61. return false;
  62. }
  63. bool LLMainLoopRepeater::onMessage(LLSD const & event)
  64. {
  65. try {
  66. mQueue->pushFront(event);
  67. } catch(LLThreadSafeQueueError & e) {
  68. llwarns << "could not repeat message (" << e.what() << ")" <<
  69. event.asString() << LL_ENDL;
  70. }
  71. return false;
  72. }