PageRenderTime 32ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/lliobuffer.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 135 lines | 34 code | 13 blank | 88 comment | 0 complexity | a63ea8d286ee83fe0baa8914db5f7957 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lliobuffer.h
  3. * @author Phoenix
  4. * @date 2005-05-04
  5. * @brief Declaration of buffers for use in IO Pipes.
  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_LLIOBUFFER_H
  29. #define LL_LLIOBUFFER_H
  30. #include "lliopipe.h"
  31. /**
  32. * @class LLIOBuffer
  33. * @brief This class is an io class that represents an automtically
  34. * resizing io buffer.
  35. * @see LLIOPipe
  36. *
  37. * This class is currently impelemented quick and dirty, but should be
  38. * correct. This class should be extended to have a more flexible
  39. * (and capped) memory allocation and usage scheme. Eventually, I
  40. * would like to have the ability to share this buffer between
  41. * different objects.
  42. */
  43. class LLIOBuffer : public LLIOPipe
  44. {
  45. public:
  46. LLIOBuffer();
  47. virtual ~LLIOBuffer();
  48. /**
  49. * @brief Return a raw pointer to the current data set.
  50. *
  51. * The pointer returned can be used for reading or even adjustment
  52. * if you are a bit crazy up to size() bytes into memory.
  53. * @return A potentially NULL pointer to the raw buffer data
  54. */
  55. U8* data() const;
  56. /**
  57. * @brief Return the size of the buffer
  58. */
  59. S64 size() const;
  60. /**
  61. * @brief Return a raw pointer to the current read position in the data.
  62. *
  63. * The pointer returned can be used for reading or even adjustment
  64. * if you are a bit crazy up to bytesLeft() bytes into memory.
  65. * @return A potentially NULL pointer to the buffer data starting
  66. * at the read point
  67. */
  68. U8* current() const;
  69. /**
  70. * @brief Return the number of unprocessed bytes in buffer.
  71. */
  72. S64 bytesLeft() const;
  73. /**
  74. * @brief Move the buffer offsets back to the beginning.
  75. *
  76. * This method effectively clears what has been stored here,
  77. * without mucking around with memory allocation.
  78. */
  79. void clear();
  80. /**
  81. * @brief Enumeration passed into the seek function
  82. *
  83. * The READ head is used for where to start processing data for
  84. * the next link in the chain, while the WRITE head specifies
  85. * where new data processed from the previous link in the chain
  86. * will be written.
  87. */
  88. enum EHead
  89. {
  90. READ,
  91. WRITE
  92. };
  93. /**
  94. * @brief Seek to a place in the buffer
  95. *
  96. * @param head The READ or WRITE head.
  97. * @param delta The offset from the current position to seek.
  98. * @return The status of the operation. status >= if head moved.
  99. */
  100. EStatus seek(EHead head, S64 delta);
  101. public:
  102. /* @name LLIOPipe virtual implementations
  103. */
  104. //@{
  105. protected:
  106. /**
  107. * @brief Process the data in buffer
  108. */
  109. virtual EStatus process_impl(
  110. const LLChannelDescriptors& channels,
  111. buffer_ptr_t& buffer,
  112. bool& eos,
  113. LLSD& context,
  114. LLPumpIO* pump);
  115. //@}
  116. protected:
  117. U8* mBuffer;
  118. S64 mBufferSize;
  119. U8* mReadHead;
  120. U8* mWriteHead;
  121. };
  122. #endif // LL_LLIOBUFFER_H