diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llmessage/lliopipe.h | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llmessage/lliopipe.h')
-rw-r--r-- | linden/indra/llmessage/lliopipe.h | 310 |
1 files changed, 310 insertions, 0 deletions
diff --git a/linden/indra/llmessage/lliopipe.h b/linden/indra/llmessage/lliopipe.h new file mode 100644 index 0000000..f419703 --- /dev/null +++ b/linden/indra/llmessage/lliopipe.h | |||
@@ -0,0 +1,310 @@ | |||
1 | /** | ||
2 | * @file lliopipe.h | ||
3 | * @author Phoenix | ||
4 | * @date 2004-11-18 | ||
5 | * @brief Declaration of base IO class | ||
6 | * | ||
7 | * Copyright (c) 2004-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
10 | * to you under the terms of the GNU General Public License, version 2.0 | ||
11 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
12 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
13 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
14 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlife.com/developers/opensource/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | */ | ||
29 | |||
30 | #ifndef LL_LLIOPIPE_H | ||
31 | #define LL_LLIOPIPE_H | ||
32 | |||
33 | #include <boost/intrusive_ptr.hpp> | ||
34 | #include <boost/shared_ptr.hpp> | ||
35 | #include "apr-1/apr_poll.h" | ||
36 | |||
37 | #include "llsd.h" | ||
38 | |||
39 | class LLIOPipe; | ||
40 | class LLPumpIO; | ||
41 | class LLBufferArray; | ||
42 | class LLChannelDescriptors; | ||
43 | |||
44 | // Debugging schmutz for deadlocks | ||
45 | #define LL_DEBUG_PUMPS | ||
46 | #ifdef LL_DEBUG_PUMPS | ||
47 | void pump_debug(const char *file, S32 line); | ||
48 | #define PUMP_DEBUG pump_debug(__FILE__, __LINE__); | ||
49 | #define END_PUMP_DEBUG pump_debug("none", 0); | ||
50 | #endif | ||
51 | |||
52 | |||
53 | /** | ||
54 | * intrusive pointer support | ||
55 | */ | ||
56 | namespace boost | ||
57 | { | ||
58 | void intrusive_ptr_add_ref(LLIOPipe* p); | ||
59 | void intrusive_ptr_release(LLIOPipe* p); | ||
60 | }; | ||
61 | |||
62 | /** | ||
63 | * @class LLIOPipe | ||
64 | * @brief This class is an abstract base class for data processing units | ||
65 | * @see LLPumpIO | ||
66 | * | ||
67 | * The LLIOPipe is a base class for implementing the basic non-blocking | ||
68 | * processing of data subsystem in our system. | ||
69 | * | ||
70 | * Implementations of this class should behave like a stateful or | ||
71 | * stateless signal processor. Each call to <code>process()</code> | ||
72 | * hands the pipe implementation a buffer and a set of channels in the | ||
73 | * buffer to process, and the pipe returns the status of the | ||
74 | * operation. This is an abstract base class and developer created | ||
75 | * concrete implementations provide block or stream based processing | ||
76 | * of data to implement a particular protocol. | ||
77 | */ | ||
78 | class LLIOPipe | ||
79 | { | ||
80 | public: | ||
81 | /** | ||
82 | * @brief I have decided that IO objects should have a reference | ||
83 | * count. In general, you can pass bald LLIOPipe pointers around | ||
84 | * as you need, but if you need to maintain a reference to one, | ||
85 | * you need to hold a ptr_t. | ||
86 | */ | ||
87 | typedef boost::intrusive_ptr<LLIOPipe> ptr_t; | ||
88 | |||
89 | /** | ||
90 | * @brief Scattered memory container. | ||
91 | */ | ||
92 | typedef boost::shared_ptr<LLBufferArray> buffer_ptr_t; | ||
93 | |||
94 | /** | ||
95 | * @brief Enumeration for IO return codes | ||
96 | * | ||
97 | * A status code a positive integer value is considered a success, | ||
98 | * but may indicate special handling for future calls, for | ||
99 | * example, issuing a STATUS_STOP to an LLIOSocketReader instance | ||
100 | * will tell the instance to stop reading the socket. A status | ||
101 | * code with a negative value means that a problem has been | ||
102 | * encountered which will require further action on the caller or | ||
103 | * a developer to correct. Some mechanisms, such as the LLPumpIO | ||
104 | * may depend on this definition of success and failure. | ||
105 | */ | ||
106 | enum EStatus | ||
107 | { | ||
108 | // Processing occurred normally, future calls will be accepted. | ||
109 | STATUS_OK = 0, | ||
110 | |||
111 | // Processing occured normally, but stop unsolicited calls to | ||
112 | // process. | ||
113 | STATUS_STOP = 1, | ||
114 | |||
115 | // This pipe is done with the processing. Future calls to | ||
116 | // process will be accepted as long as new data is available. | ||
117 | STATUS_DONE = 2, | ||
118 | |||
119 | // This pipe is requesting that it become the head in a process. | ||
120 | STATUS_BREAK = 3, | ||
121 | |||
122 | // This pipe is requesting that it become the head in a process. | ||
123 | STATUS_NEED_PROCESS = 4, | ||
124 | |||
125 | // Keep track of the highest number of success codes here. | ||
126 | STATUS_SUCCESS_COUNT = 5, | ||
127 | |||
128 | // A generic error code. | ||
129 | STATUS_ERROR = -1, | ||
130 | |||
131 | // This method has not yet been implemented. This usually | ||
132 | // indicates the programmer working on the pipe is not yet | ||
133 | // done. | ||
134 | STATUS_NOT_IMPLEMENTED = -2, | ||
135 | |||
136 | // This indicates that a pipe precondition was not met. For | ||
137 | // example, many pipes require an element to appear after them | ||
138 | // in a chain (ie, mNext is not null) and will return this in | ||
139 | // response to method calls. To recover from this, it will | ||
140 | // require the caller to adjust the pipe state or may require | ||
141 | // a dev to adjust the code to satisfy the preconditions. | ||
142 | STATUS_PRECONDITION_NOT_MET = -3, | ||
143 | |||
144 | // This means we could not connect to a remote host. | ||
145 | STATUS_NO_CONNECTION = -4, | ||
146 | |||
147 | // This means we could not connect to a remote host. | ||
148 | STATUS_EXPIRED = -5, | ||
149 | |||
150 | // Keep track of the count of codes here. | ||
151 | STATUS_ERROR_COUNT = 5, | ||
152 | }; | ||
153 | |||
154 | /** | ||
155 | * @brief Helper function to check status. | ||
156 | * | ||
157 | * When writing code to check status codes, if you do not | ||
158 | * specifically check a particular value, use this method for | ||
159 | * checking an error condition. | ||
160 | * @param status The status to check. | ||
161 | * @return Returns true if the code indicates an error occurred. | ||
162 | */ | ||
163 | inline static bool isError(EStatus status) | ||
164 | { | ||
165 | return ((S32)status < 0); | ||
166 | } | ||
167 | |||
168 | /** | ||
169 | * @brief Helper function to check status. | ||
170 | * | ||
171 | * When writing code to check status codes, if you do not | ||
172 | * specifically check a particular value, use this method for | ||
173 | * checking an error condition. | ||
174 | * @param status The status to check. | ||
175 | * @return Returns true if the code indicates no error was generated. | ||
176 | */ | ||
177 | inline static bool isSuccess(EStatus status) | ||
178 | { | ||
179 | return ((S32)status >= 0); | ||
180 | } | ||
181 | |||
182 | /** | ||
183 | * @brief Helper function to turn status into a string. | ||
184 | * | ||
185 | * @param status The status to check. | ||
186 | * @return Returns the name of the status code or empty string on failure. | ||
187 | */ | ||
188 | static std::string lookupStatusString(EStatus status); | ||
189 | |||
190 | /** | ||
191 | * @brief Process the data in buffer. | ||
192 | * | ||
193 | * @param data The data processed | ||
194 | * @param eos True if this function call is the last because end of stream. | ||
195 | * @param pump The pump which is calling process. May be NULL. | ||
196 | * @param context Shared meta-data for the process. | ||
197 | * @return Returns a status code from the operation. | ||
198 | */ | ||
199 | EStatus process( | ||
200 | const LLChannelDescriptors& channels, | ||
201 | buffer_ptr_t& buffer, | ||
202 | bool& eos, | ||
203 | LLSD& context, | ||
204 | LLPumpIO* pump); | ||
205 | |||
206 | /** | ||
207 | * @brief Give this pipe a chance to handle a generated error | ||
208 | * | ||
209 | * If this pipe is in a chain being processed by a pump, and one | ||
210 | * of the pipes generates an error, the pump will rewind through | ||
211 | * the chain to see if any of the links can handle the error. For | ||
212 | * example, if a connection is refused in a socket connection, the | ||
213 | * socket client can try to find a new destination host. Return an | ||
214 | * error code if this pipe does not handle the error passed in. | ||
215 | * @param status The status code for the error | ||
216 | * @param pump The pump which was calling process before the error | ||
217 | * was generated. | ||
218 | * @return Returns a status code from the operation. Returns an | ||
219 | * error code if the error passed in was not handled. Returns | ||
220 | * STATUS_OK to indicate the error has been handled. | ||
221 | */ | ||
222 | virtual EStatus handleError(EStatus status, LLPumpIO* pump); | ||
223 | |||
224 | /** | ||
225 | * @brief Base Destructor - do not call <code>delete</code> directly. | ||
226 | */ | ||
227 | virtual ~LLIOPipe(); | ||
228 | |||
229 | protected: | ||
230 | /** | ||
231 | * @brief Base Constructor. | ||
232 | */ | ||
233 | LLIOPipe(); | ||
234 | |||
235 | /** | ||
236 | * @brief Process the data in buffer | ||
237 | */ | ||
238 | virtual EStatus process_impl( | ||
239 | const LLChannelDescriptors& channels, | ||
240 | buffer_ptr_t& buffer, | ||
241 | bool& eos, | ||
242 | LLSD& context, | ||
243 | LLPumpIO* pump) = 0; | ||
244 | |||
245 | private: | ||
246 | friend void boost::intrusive_ptr_add_ref(LLIOPipe* p); | ||
247 | friend void boost::intrusive_ptr_release(LLIOPipe* p); | ||
248 | U32 mReferenceCount; | ||
249 | }; | ||
250 | |||
251 | namespace boost | ||
252 | { | ||
253 | inline void intrusive_ptr_add_ref(LLIOPipe* p) | ||
254 | { | ||
255 | ++p->mReferenceCount; | ||
256 | } | ||
257 | inline void intrusive_ptr_release(LLIOPipe* p) | ||
258 | { | ||
259 | if(0 == --p->mReferenceCount) | ||
260 | { | ||
261 | delete p; | ||
262 | } | ||
263 | } | ||
264 | }; | ||
265 | |||
266 | |||
267 | #if 0 | ||
268 | /** | ||
269 | * @class LLIOBoiler | ||
270 | * @brief This class helps construct new LLIOPipe specializations | ||
271 | * @see LLIOPipe | ||
272 | * | ||
273 | * THOROUGH_DESCRIPTION | ||
274 | */ | ||
275 | class LLIOBoiler : public LLIOPipe | ||
276 | { | ||
277 | public: | ||
278 | LLIOBoiler(); | ||
279 | virtual ~LLIOBoiler(); | ||
280 | |||
281 | protected: | ||
282 | /* @name LLIOPipe virtual implementations | ||
283 | */ | ||
284 | //@{ | ||
285 | /** | ||
286 | * @brief Process the data in buffer | ||
287 | */ | ||
288 | virtual EStatus process_impl( | ||
289 | const LLChannelDescriptors& channels, | ||
290 | buffer_ptr_t& buffer, | ||
291 | bool& eos, | ||
292 | LLSD& context, | ||
293 | LLPumpIO* pump); | ||
294 | //@} | ||
295 | }; | ||
296 | |||
297 | // virtual | ||
298 | LLIOPipe::EStatus process_impl( | ||
299 | const LLChannelDescriptors& channels, | ||
300 | buffer_ptr_t& buffer, | ||
301 | bool& eos, | ||
302 | LLSD& context, | ||
303 | LLPumpIO* pump) | ||
304 | { | ||
305 | return STATUS_NOT_IMPLEMENTED; | ||
306 | } | ||
307 | |||
308 | #endif // #if 0 - use this block as a boilerplate | ||
309 | |||
310 | #endif // LL_LLIOPIPE_H | ||