PageRenderTime 183ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/llservice.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 185 lines | 68 code | 18 blank | 99 comment | 3 complexity | c0d97d335a32c6ee6df0f7e6a26cf915 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llservice.h
  3. * @author Phoenix
  4. * @date 2004-11-21
  5. * @brief Declaration file for LLService and related classes.
  6. *
  7. * $LicenseInfo:firstyear=2004&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. #ifndef LL_LLSERVICE_H
  29. #define LL_LLSERVICE_H
  30. #include <string>
  31. #include <map>
  32. //#include <boost/intrusive_ptr.hpp>
  33. //#include <boost/shared_ptr.hpp>
  34. //#include "llframetimer.h"
  35. #include "lliopipe.h"
  36. #include "llchainio.h"
  37. #if 0
  38. class LLServiceCreator;
  39. /**
  40. * intrusive pointer support
  41. */
  42. namespace boost
  43. {
  44. void intrusive_ptr_add_ref(LLServiceCreator* p);
  45. void intrusive_ptr_release(LLServiceCreator* p);
  46. };
  47. #endif
  48. /**
  49. * @class LLServiceCreator
  50. * @brief This class is an abstract base class for classes which create
  51. * new <code>LLService</code> instances.
  52. *
  53. * Derive classes from this class which appropriately implement the
  54. * <code>operator()</code> and destructor.
  55. * @see LLService
  56. */
  57. #if 0
  58. class LLServiceCreator
  59. {
  60. public:
  61. typedef boost::intrusive_ptr<LLService> service_t;
  62. virtual ~LLServiceCreator() {}
  63. virtual service_t activate() = 0;
  64. virtual void discard() = 0;
  65. protected:
  66. LLServiceCreator() : mReferenceCount(0)
  67. {
  68. }
  69. private:
  70. friend void boost::intrusive_ptr_add_ref(LLServiceCreator* p);
  71. friend void boost::intrusive_ptr_release(LLServiceCreator* p);
  72. U32 mReferenceCount;
  73. };
  74. #endif
  75. #if 0
  76. namespace boost
  77. {
  78. inline void intrusive_ptr_add_ref(LLServiceCreator* p)
  79. {
  80. ++p->mReferenceCount;
  81. }
  82. inline void intrusive_ptr_release(LLServiceCreator* p)
  83. {
  84. if(p && 0 == --p->mReferenceCount)
  85. {
  86. delete p;
  87. }
  88. }
  89. };
  90. #endif
  91. /**
  92. * @class LLService
  93. * @brief This class is the base class for the service classes.
  94. * @see LLIOPipe
  95. *
  96. * The services map a string to a chain factory with a known interface
  97. * at the front of the chain. So, to activate a service, call
  98. * <code>activate()</code> with the name of the service needed which
  99. * will call the associated factory, and return a pointer to the
  100. * known interface.
  101. * <b>NOTE:</b> If you are implementing a service factory, it is
  102. * vitally important that the service pipe is at the front of the
  103. * chain.
  104. */
  105. class LLService : public LLIOPipe
  106. {
  107. public:
  108. //typedef boost::intrusive_ptr<LLServiceCreator> creator_t;
  109. //typedef boost::intrusive_ptr<LLService> service_t;
  110. typedef boost::shared_ptr<LLChainIOFactory> creator_t;
  111. /**
  112. * @brief This method is used to register a protocol name with a
  113. * a functor that creates the service.
  114. *
  115. * THOROUGH_DESCRIPTION
  116. * @param aParameter A brief description of aParameter.
  117. * @return Returns true if a service was successfully registered.
  118. */
  119. static bool registerCreator(const std::string& name, creator_t fn);
  120. /**
  121. * @brief This method connects to a service by name.
  122. *
  123. * @param name The name of the service to connect to.
  124. * @param chain The constructed chain including the service instance.
  125. * @param context Context for the activation.
  126. * @return An instance of the service for use or NULL on failure.
  127. */
  128. static LLIOPipe* activate(
  129. const std::string& name,
  130. LLPumpIO::chain_t& chain,
  131. LLSD context);
  132. /**
  133. * @brief
  134. *
  135. * @param name The name of the service to discard.
  136. * @return true if service creator was found and discarded.
  137. */
  138. static bool discard(const std::string& name);
  139. protected:
  140. // The creation factory static data.
  141. typedef std::map<std::string, creator_t> creators_t;
  142. static creators_t sCreatorFunctors;
  143. protected:
  144. // construction & destruction. since this class is an abstract
  145. // base class, it is up to Service implementations to actually
  146. // deal with construction and not a public method. How that
  147. // construction takes place will be handled by the service
  148. // creators.
  149. LLService();
  150. virtual ~LLService();
  151. protected:
  152. // This frame timer records how long this service has
  153. // existed. Useful for derived services to give themselves a
  154. // lifetime and expiration.
  155. // *NOTE: Phoenix - This functionaity has been moved to the
  156. // pump. 2005-12-13
  157. //LLFrameTimer mTimer;
  158. // Since services are designed in an 'ask now, respond later'
  159. // idiom which probably crosses thread boundaries, almost all
  160. // services will need a handle to a response pipe. It will usually
  161. // be the job of the service author to derive a useful
  162. // implementation of response, and up to the service subscriber to
  163. // further derive that class to do something useful when the
  164. // response comes in.
  165. LLIOPipe::ptr_t mResponse;
  166. };
  167. #endif // LL_LLSERVICE_H