|
|
| version 1.2, 2001/01/29 21:51:51 | version 1.4, 2001/01/30 13:07:31 |
|---|---|
| Line 6 | Line 6 |
| #define PA_REQUEST_H | #define PA_REQUEST_H |
| #include "pa_pool.h" | #include "pa_pool.h" |
| #include "pa_error.h" | #include "pa_exception.h" |
| class Local_request_exception; | |
| class Request { | class Request { |
| friend Local_request_exception; | |
| public: | public: |
| Request(Pool& apool) : fpool(apool) {} | |
| ~Request() {} | |
| Pool& pool() { return fpool; } | |
| Exception& exception() { return *fexception; } | |
| protected: | |
| // all request' objects are allocated in this pool | // all request' objects are allocated in this pool |
| // they die with request | Pool& fpool; |
| Pool pool; | |
| // these errors handled on global(request) level | |
| Error request_error; | |
| // these errors handled on local(operator) level | // exception replacement mechanism is protected from direct usage |
| Error operator_error; | // Local_request_exception object enforces paired set/restore |
| Exception *set_exception(Exception *e){ | |
| Exception *r=fexception; | |
| fexception=e; | |
| return r; | |
| } | |
| void restore_exception(Exception *e) { | |
| fexception=e; | |
| } | |
| private: | |
| // current request's exception object | |
| Exception *fexception; | |
| Request() {} | |
| ~Request() {} | |
| }; | }; |
| class Local_request_exception { | |
| Request request; | |
| Exception *saved_exception; | |
| public: | |
| Local_request_exception(Request& arequest, Exception& exception) : | |
| request(arequest), | |
| saved_exception(arequest.set_exception(&exception)) {} | |
| ~Local_request_exception() { request.restore_exception(saved_exception); } | |
| }; | |
| #endif | #endif |