PageRenderTime 62ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/indra/test/llpipeutil.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 163 lines | 92 code | 25 blank | 46 comment | 0 complexity | cdac9994c913b72d2370b3f00f1bb3ae MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpipeutil.h
  3. * @date 2006-05-18
  4. * @brief Utility pipe fittings for injecting and extracting strings
  5. *
  6. * $LicenseInfo:firstyear=2006&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. #ifndef LL_LLPIPEUTIL_H
  28. #define LL_LLPIPEUTIL_H
  29. #include "lliopipe.h"
  30. /**
  31. * @brief Simple function which pumps for the specified time.
  32. */
  33. F32 pump_loop(LLPumpIO* pump, F32 seconds);
  34. /**
  35. * @brief Simple class which writes a string and then marks the stream
  36. * as done.
  37. */
  38. class LLPipeStringInjector : public LLIOPipe
  39. {
  40. public:
  41. LLPipeStringInjector(const std::string& string)
  42. : mString(string)
  43. { }
  44. protected:
  45. virtual EStatus process_impl(
  46. const LLChannelDescriptors& channels,
  47. buffer_ptr_t& buffer,
  48. bool& eos,
  49. LLSD& context,
  50. LLPumpIO* pump);
  51. private:
  52. std::string mString;
  53. };
  54. class LLPipeStringExtractor : public LLIOPipe
  55. {
  56. public:
  57. LLPipeStringExtractor() : mDone(false) { }
  58. bool done() { return mDone; }
  59. std::string string() { return mString; }
  60. protected:
  61. // LLIOPipe API implementation.
  62. virtual EStatus process_impl(
  63. const LLChannelDescriptors& channels,
  64. LLIOPipe::buffer_ptr_t& buffer,
  65. bool& eos,
  66. LLSD& context,
  67. LLPumpIO* pump);
  68. private:
  69. bool mDone;
  70. std::string mString;
  71. };
  72. /**
  73. * @brief Generate a specified number of bytes of random data
  74. */
  75. class LLIOFuzz : public LLIOPipe
  76. {
  77. public:
  78. LLIOFuzz(int byte_count) : mByteCount(byte_count) {}
  79. protected:
  80. virtual EStatus process_impl(
  81. const LLChannelDescriptors& channels,
  82. buffer_ptr_t& buffer,
  83. bool& eos,
  84. LLSD& context,
  85. LLPumpIO* pump);
  86. private:
  87. int mByteCount;
  88. };
  89. /**
  90. * @brief Generate some ascii fuz
  91. */
  92. class LLIOASCIIFuzz : public LLIOPipe
  93. {
  94. public:
  95. LLIOASCIIFuzz(int byte_count) : mByteCount(byte_count) {}
  96. protected:
  97. virtual EStatus process_impl(
  98. const LLChannelDescriptors& channels,
  99. buffer_ptr_t& buffer,
  100. bool& eos,
  101. LLSD& context,
  102. LLPumpIO* pump);
  103. private:
  104. int mByteCount;
  105. };
  106. /**
  107. * @brief Pipe that does nothing except return STATUS_OK
  108. */
  109. class LLIONull : public LLIOPipe
  110. {
  111. public:
  112. LLIONull() {}
  113. protected:
  114. virtual EStatus process_impl(
  115. const LLChannelDescriptors& channels,
  116. buffer_ptr_t& buffer,
  117. bool& eos,
  118. LLSD& context,
  119. LLPumpIO* pump);
  120. };
  121. /**
  122. * @brief Pipe that sleeps, and then responds later.
  123. */
  124. class LLIOSleeper : public LLIOPipe
  125. {
  126. public:
  127. LLIOSleeper() : mRespond(false) {}
  128. protected:
  129. virtual EStatus process_impl(
  130. const LLChannelDescriptors& channels,
  131. buffer_ptr_t& buffer,
  132. bool& eos,
  133. LLSD& context,
  134. LLPumpIO* pump);
  135. private:
  136. bool mRespond;
  137. };
  138. #endif // LL_LLPIPEUTIL_H