Wexus2 0.20
|
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_CONTROLLER_H__ 00009 #define __INCLUDED_WEXUS_CONTROLLER_H__ 00010 00011 #include <assert.h> 00012 00013 #include <map> 00014 00015 #include <QVariant> 00016 00017 #include <wexus/HTTPRequest.h> 00018 #include <wexus/HTTPReply.h> 00019 #include <wexus/Context.h> 00020 00021 namespace wexus 00022 { 00023 class ControllerContext; 00024 class Controller; 00025 } 00026 00027 // helper operator for QTextStream ouput of variants 00028 inline QTextStream & operator <<(QTextStream &o, const QVariant &v) { return o << v.toString(); } 00029 00030 /** 00031 * This contains useful input/output functions that are part of 00032 * Controller. 00033 * 00034 * It basically reflects a lot of the methods of the Context TLS global 00035 * into the Controller itself. 00036 * 00037 * @author Aleksander Demko 00038 */ 00039 class wexus::ControllerContext 00040 { 00041 private: 00042 wexus::Context &dm_context; // at the top as this should be initialized before cookies, etc 00043 00044 public: 00045 /** 00046 * Constructor. 00047 * 00048 * @author Aleksander Demko 00049 */ 00050 ControllerContext(void); 00051 00052 /** 00053 * Returns the raw output stream. 00054 * 00055 * @author Aleksander Demko 00056 */ 00057 QTextStream & output(void) { return dm_context.output(); } 00058 00059 /** 00060 * Returns a stream that HTML escapes all output 00061 * (except HTMLString). 00062 * 00063 * @author Aleksander Demko 00064 */ 00065 QTextStream & htmlOutput(void) { return dm_context.htmlOutput(); } 00066 00067 /** 00068 * The form parameters. 00069 * Object directly accessible so operator[] works. 00070 * 00071 * @author Aleksander Demko 00072 */ 00073 QVariantMap ¶ms; 00074 00075 /** 00076 * The cookies. 00077 * 00078 * @author Aleksander Demko 00079 */ 00080 Cookies &cookies; 00081 00082 /** 00083 * The session, if any. 00084 * 00085 * @author Aleksander Demko 00086 */ 00087 QVariantMap &session; 00088 00089 /** 00090 * The incoming flash sent by the previous calls. 00091 * 00092 * @author Aleksander Demko 00093 */ 00094 const QVariantMap &flash; 00095 00096 /** 00097 * The flash that will be preseved for the next calls. 00098 * In the next call, this will be the contents of inFlash. 00099 * 00100 * @author Aleksander Demko 00101 */ 00102 QVariantMap &setFlash; 00103 00104 /** 00105 * Errors. 00106 * 00107 * @author Aleksander Demko 00108 */ 00109 Context::Errors &errors; 00110 }; 00111 00112 /** 00113 * Base class for all user defined controllers. 00114 * Controller is the C in MVC. They are instantied 00115 * per request, with the appripriate sub message being called. 00116 * 00117 * @author Aleksander Demko 00118 */ 00119 class wexus::Controller : public wexus::ControllerContext 00120 { 00121 public: 00122 virtual ~Controller(); 00123 00124 protected: 00125 /// constructor 00126 Controller(void); 00127 }; 00128 00129 #endif 00130