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