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