PageRenderTime 32ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/llioutil.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 172 lines | 63 code | 14 blank | 95 comment | 0 complexity | f779c8991ee31cf6026f7b0091b69368 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llioutil.h
  3. * @author Phoenix
  4. * @date 2005-10-05
  5. * @brief Helper classes for dealing with IOPipes
  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_LLIOUTIL_H
  29. #define LL_LLIOUTIL_H
  30. #include "llbuffer.h"
  31. #include "lliopipe.h"
  32. #include "llpumpio.h"
  33. /**
  34. * @class LLIOFlush
  35. * @brief This class is used as a mini chain head which drains the buffer.
  36. * @see LLIOPipe
  37. *
  38. * An instance of this class acts as a useful chain head when all data
  39. * is known, and you simply want to get the chain moving.
  40. */
  41. class LLIOFlush : public LLIOPipe
  42. {
  43. public:
  44. LLIOFlush() {}
  45. virtual ~LLIOFlush() {}
  46. protected:
  47. /* @name LLIOPipe virtual implementations
  48. */
  49. //@{
  50. /**
  51. * @brief Process the data in buffer
  52. */
  53. EStatus process_impl(
  54. const LLChannelDescriptors& channels,
  55. buffer_ptr_t& buffer,
  56. bool& eos,
  57. LLSD& context,
  58. LLPumpIO* pump);
  59. //@}
  60. protected:
  61. };
  62. /**
  63. * @class LLIOSleep
  64. * @brief This is a simple helper class which will hold a chain and
  65. * process it later using pump mechanisms
  66. * @see LLIOPipe
  67. */
  68. class LLIOSleep : public LLIOPipe
  69. {
  70. public:
  71. LLIOSleep(F64 sleep_seconds) : mSeconds(sleep_seconds) {}
  72. virtual ~LLIOSleep() {}
  73. protected:
  74. /* @name LLIOPipe virtual implementations
  75. */
  76. //@{
  77. /**
  78. * @brief Process the data in buffer
  79. */
  80. EStatus process_impl(
  81. const LLChannelDescriptors& channels,
  82. buffer_ptr_t& buffer,
  83. bool& eos,
  84. LLSD& context,
  85. LLPumpIO* pump);
  86. //@}
  87. protected:
  88. F64 mSeconds;
  89. };
  90. /**
  91. * @class LLIOAddChain
  92. * @brief Simple pipe that just adds a chain to a pump.
  93. * @see LLIOPipe
  94. */
  95. class LLIOAddChain : public LLIOPipe
  96. {
  97. public:
  98. LLIOAddChain(const LLPumpIO::chain_t& chain, F32 timeout) :
  99. mChain(chain),
  100. mTimeout(timeout)
  101. {}
  102. virtual ~LLIOAddChain() {}
  103. protected:
  104. /* @name LLIOPipe virtual implementations
  105. */
  106. //@{
  107. /**
  108. * @brief Process the data in buffer
  109. */
  110. EStatus process_impl(
  111. const LLChannelDescriptors& channels,
  112. buffer_ptr_t& buffer,
  113. bool& eos,
  114. LLSD& context,
  115. LLPumpIO* pump);
  116. //@}
  117. protected:
  118. LLPumpIO::chain_t mChain;
  119. F32 mTimeout;
  120. };
  121. /**
  122. * @class LLChangeChannel
  123. * @brief This class changes the channel of segments in the buffer
  124. * @see LLBufferArray
  125. *
  126. * This class is useful for iterating over the segments in a buffer
  127. * array and changing each channel that matches to a different
  128. * channel.
  129. * Example:
  130. * <code>
  131. * set_in_to_out(LLChannelDescriptors channels, LLBufferArray* buf)
  132. * {
  133. * std::for_each(
  134. * buf->beginSegment(),
  135. * buf->endSegment(),
  136. * LLChangeChannel(channels.in(), channels.out()));
  137. * }
  138. * </code>
  139. */
  140. class LLChangeChannel //: public unary_function<T, void>
  141. {
  142. public:
  143. /**
  144. * @brief Constructor for iterating over a segment range to change channel.
  145. *
  146. * @param is The channel to match when looking at a segment.
  147. * @param becomes The channel to set the segment when a match is found.
  148. */
  149. LLChangeChannel(S32 is, S32 becomes);
  150. /**
  151. * @brief Do the work of changing the channel
  152. */
  153. void operator()(LLSegment& segment);
  154. protected:
  155. S32 mIs;
  156. S32 mBecomes;
  157. };
  158. #endif // LL_LLIOUTIL_H