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

/indra/llmessage/llchainio.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 135 lines | 47 code | 12 blank | 76 comment | 0 complexity | ac1286ded88eb50b62a94929dc760f5f MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llchainio.h
  3. * @author Phoenix
  4. * @date 2005-08-04
  5. * @brief This class declares the interface for constructing io chains.
  6. *
  7. * $LicenseInfo:firstyear=2005&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_LLCHAINIO_H
  29. #define LL_LLCHAINIO_H
  30. #include "llpumpio.h"
  31. /**
  32. * @class LLDeferredChain
  33. * @brief This class allows easy addition of a chain which will sleep
  34. * and then process another chain.
  35. */
  36. class LLDeferredChain
  37. {
  38. public:
  39. /**
  40. * @brief Add a chain to a pump in a finite # of seconds
  41. *
  42. * @prarm pump The pump to work on.
  43. * @prarm in_seconds The number of seconds from now when chain should start.
  44. * @prarm chain The chain to add in in_seconds seconds.
  45. * @prarm chain_timeout timeout for chain on the pump.
  46. * @return Returns true if the operation was queued.
  47. */
  48. static bool addToPump(
  49. LLPumpIO* pump,
  50. F32 in_seconds,
  51. const LLPumpIO::chain_t& chain,
  52. F32 chain_timeout);
  53. };
  54. /**
  55. * @class LLChainIOFactory
  56. * @brief This class is an abstract base class for building io chains.
  57. *
  58. * This declares an abstract base class for a chain factory. The
  59. * factory is used to connect an input pipe to the first pipe in the
  60. * chain, and an output pipe to the last pipe in the chain. This will
  61. * allow easy construction for buffer based io like services to for
  62. * API centered IO while abstracting the input and output to simple
  63. * data passing.
  64. * To use this class, you should derive a class which implements the
  65. * <code>build</code> method.
  66. */
  67. class LLChainIOFactory
  68. {
  69. public:
  70. // Constructor
  71. LLChainIOFactory();
  72. // Destructor
  73. virtual ~LLChainIOFactory();
  74. /**
  75. * @brief Build the chian with in as the first and end as the last
  76. *
  77. * The caller of the LLChainIOFactory is responsible for managing
  78. * the memory of the in pipe. All of the chains generated by the
  79. * factory will be ref counted as usual, so the caller will also
  80. * need to break the links in the chain.
  81. * @param chain The chain which will have new pipes appended
  82. * @param context A context for use by this factory if you choose
  83. * @retrun Returns true if the call was successful.
  84. */
  85. virtual bool build(LLPumpIO::chain_t& chain, LLSD context) const = 0;
  86. protected:
  87. };
  88. /**
  89. * @class LLSimpleIOFactory
  90. * @brief Basic implementation for making a factory that returns a
  91. * 'chain' of one object
  92. */
  93. template<class Pipe>
  94. class LLSimpleIOFactory : public LLChainIOFactory
  95. {
  96. public:
  97. virtual bool build(LLPumpIO::chain_t& chain, LLSD context) const
  98. {
  99. chain.push_back(LLIOPipe::ptr_t(new Pipe));
  100. return true;
  101. }
  102. };
  103. /**
  104. * @class LLCloneIOFactory
  105. * @brief Implementation for a facory which copies a particular pipe.
  106. */
  107. template<class Pipe>
  108. class LLCloneIOFactory : public LLChainIOFactory
  109. {
  110. public:
  111. LLCloneIOFactory(Pipe* original) :
  112. mHandle(original),
  113. mOriginal(original) {}
  114. virtual bool build(LLPumpIO::chain_t& chain, LLSD context) const
  115. {
  116. chain.push_back(LLIOPipe::ptr_t(new Pipe(*mOriginal)));
  117. return true;
  118. }
  119. protected:
  120. LLIOPipe::ptr_t mHandle;
  121. Pipe* mOriginal;
  122. };
  123. #endif // LL_LLCHAINIO_H