PageRenderTime 139ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/llservice.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 111 lines | 66 code | 10 blank | 35 comment | 8 complexity | 5fd966ca7ffd95ee60d8c3e240e3d7da MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llservice.cpp
  3. * @author Phoenix
  4. * @date 2005-04-20
  5. *
  6. * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #include "linden_common.h"
  28. #include "llservice.h"
  29. LLService::creators_t LLService::sCreatorFunctors;
  30. LLService::LLService()
  31. {
  32. }
  33. LLService::~LLService()
  34. {
  35. }
  36. // static
  37. bool LLService::registerCreator(const std::string& name, creator_t fn)
  38. {
  39. llinfos << "LLService::registerCreator(" << name << ")" << llendl;
  40. if(name.empty())
  41. {
  42. return false;
  43. }
  44. creators_t::value_type vt(name, fn);
  45. std::pair<creators_t::iterator, bool> rv = sCreatorFunctors.insert(vt);
  46. return rv.second;
  47. // alternately...
  48. //std::string name_str(name);
  49. //sCreatorFunctors[name_str] = fn;
  50. }
  51. // static
  52. LLIOPipe* LLService::activate(
  53. const std::string& name,
  54. LLPumpIO::chain_t& chain,
  55. LLSD context)
  56. {
  57. if(name.empty())
  58. {
  59. llinfos << "LLService::activate - no service specified." << llendl;
  60. return NULL;
  61. }
  62. creators_t::iterator it = sCreatorFunctors.find(name);
  63. LLIOPipe* rv = NULL;
  64. if(it != sCreatorFunctors.end())
  65. {
  66. if((*it).second->build(chain, context))
  67. {
  68. rv = chain[0].get();
  69. }
  70. else
  71. {
  72. // empty out the chain, because failed service creation
  73. // should just discard this stuff.
  74. llwarns << "LLService::activate - unable to build chain: " << name
  75. << llendl;
  76. chain.clear();
  77. }
  78. }
  79. else
  80. {
  81. llwarns << "LLService::activate - unable find factory: " << name
  82. << llendl;
  83. }
  84. return rv;
  85. }
  86. // static
  87. bool LLService::discard(const std::string& name)
  88. {
  89. if(name.empty())
  90. {
  91. return false;
  92. }
  93. creators_t::iterator it = sCreatorFunctors.find(name);
  94. if(it != sCreatorFunctors.end())
  95. {
  96. //(*it).second->discard();
  97. sCreatorFunctors.erase(it);
  98. return true;
  99. }
  100. return false;
  101. }