Wexus2 0.20
wexus2.src/wexus/HTTPHandlerStack.h
00001 
00002 /*
00003  * Copyright (c) 2011 Aleksander B. Demko
00004  * This source code is distributed under the MIT license.
00005  * See the accompanying file LICENSE.MIT.txt for details.
00006  */
00007 
00008 #ifndef __INCLUDED_WEXUS_HTTPHANDLERSTACK_H__
00009 #define __INCLUDED_WEXUS_HTTPHANDLERSTACK_H__
00010 
00011 #include <vector>
00012 
00013 #include <wexus/TR1.h>
00014 #include <wexus/HTTPHandler.h>
00015 
00016 namespace wexus
00017 {
00018   class HTTPHandlerStack;
00019 }
00020 
00021 /**
00022  * A handler that maintains a list of other handlers.
00023  * When it receives a request, it goes down this list of handlers
00024  * until one of them processes the event.
00025  *
00026  * @author Aleksander Demko
00027  */ 
00028 class wexus::HTTPHandlerStack : public wexus::HTTPHandler
00029 {
00030   public:
00031     /// constructor
00032     HTTPHandlerStack(void);
00033 
00034     virtual void handleRequest(wexus::HTTPRequest &req, wexus::HTTPReply &reply);
00035 
00036     /**
00037      * Adds a handler to the end of the handler stack.
00038      *
00039      * The stack is still sorted by priority, with lower priority
00040      * handlers.
00041      *
00042      * priorities should usually be between [1..99].
00043      * 
00044      * @author Aleksander Demko
00045      */ 
00046     void addHandler(std::shared_ptr<wexus::HTTPHandler> handler, int prio = 50);
00047 
00048   private:
00049     typedef std::pair<int, std::shared_ptr<wexus::HTTPHandler> > priohandler_t;
00050     static bool lessthan(const priohandler_t &left, const priohandler_t &right)
00051       { return left.first < right.first; }
00052 
00053     typedef std::vector<priohandler_t> handlers_t;
00054 
00055     handlers_t dm_handlers;
00056 };
00057 
00058 #endif
00059 
 All Classes Namespaces Functions Variables Enumerations Enumerator