component.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2006 Tommi Maekitalo
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * As a special exception, you may use this file as part of a free
10  * software library without restriction. Specifically, if other files
11  * instantiate templates or use macros or inline functions from this
12  * file, or you compile this file and link it with other files to
13  * produce an executable, this file does not by itself cause the
14  * resulting executable to be covered by the GNU General Public
15  * License. This exception does not however invalidate any other
16  * reasons why the executable file might be covered by the GNU Library
17  * General Public License.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27  */
28 
29 
30 #ifndef TNT_COMPONENT_H
31 #define TNT_COMPONENT_H
32 
33 #include <tnt/compident.h>
34 #include <tnt/sessionscope.h>
35 
36 namespace tnt
37 {
38  class HttpRequest;
39  class HttpReply;
40  class QueryParams;
41  struct TntConfig;
42 
43  class Component
44  {
45  public:
46  virtual ~Component() { }
47 
48  virtual void configure(const tnt::TntConfig&);
49 
50  virtual unsigned topCall(HttpRequest&, HttpReply&, tnt::QueryParams&);
51  virtual unsigned operator() (HttpRequest&, HttpReply&, tnt::QueryParams&);
52  virtual unsigned endTag (HttpRequest&, HttpReply&, tnt::QueryParams&);
53 
58  virtual std::string getAttribute(const std::string& name, const std::string& def = std::string()) const;
59 
61  unsigned call(HttpRequest& request, HttpReply& reply, tnt::QueryParams& qparam)
62  { return operator() (request, reply, qparam); }
63 
65  unsigned call(HttpRequest&, HttpReply&);
66 
68  std::string scall(HttpRequest&, tnt::QueryParams&);
70  std::string scall(HttpRequest&);
71  };
72 
73 #define TNT_VAR(scope, type, varname, key, construct) \
74  type* varname##_pointer; \
75  { \
76  const std::string varname##_scopekey = key; \
77  tnt::Scope& _scope = scope; \
78  varname##_pointer = _scope.get< type >(varname##_scopekey); \
79  if ( ! varname##_pointer ) \
80  _scope.put< type >(varname##_scopekey, \
81  varname##_pointer = new type construct); \
82  } \
83  type& varname = *varname##_pointer;
84 
85 #define TNT_SESSION_COMPONENT_VAR(type, varname, construct) \
86  TNT_VAR(request.getSessionScope(), type, varname, getCompident().toString() + "%" #type "%" #varname, construct)
87 
88 #define TNT_SESSION_PAGE_VAR(type, varname, construct) \
89  TNT_VAR(request.getSessionScope(), type, varname, getCompident().toString() + "%" #type "%" #varname, construct)
90 
91 #define TNT_SESSION_SHARED_VAR(type, varname, construct) \
92  TNT_VAR(request.getSessionScope(), type, varname, #type "%" #varname, construct)
93 
94 #define TNT_SESSION_GLOBAL_VAR(type, varname, construct) \
95  TNT_VAR(request.getSessionScope(), type, varname, #type "%" #varname, construct)
96 
97 #define TNT_SESSION_FILE_VAR(type, varname, file, construct) \
98  TNT_VAR(request.getSessionScope(), type, varname, #file "%" #type "%" #varname, construct)
99 
100 #define TNT_SECURE_SESSION_COMPONENT_VAR(type, varname, construct) \
101  TNT_VAR(request.getSecureSessionScope(), type, varname, getCompident().toString() + ":" #type "%" #varname, construct)
102 
103 #define TNT_SECURE_SESSION_PAGE_VAR(type, varname, construct) \
104  TNT_VAR(request.getSecureSessionScope(), type, varname, getCompident().toString() + ":" #type "%" #varname, construct)
105 
106 #define TNT_SECURE_SESSION_SHARED_VAR(type, varname, construct) \
107  TNT_VAR(request.getSecureSessionScope(), type, varname, #type "%" #varname, construct)
108 
109 #define TNT_SECURE_SESSION_GLOBAL_VAR(type, varname, construct) \
110  TNT_VAR(request.getSecureSessionScope(), type, varname, #type "%" #varname, construct)
111 
112 #define TNT_SECURE_SESSION_FILE_VAR(type, varname, file, construct) \
113  TNT_VAR(request.getSecureSessionScope(), type, varname, #file "%" #type "%" #varname, construct)
114 
115 #define TNT_APPLICATION_COMPONENT_VAR(type, varname, construct) \
116  TNT_VAR(request.getApplicationScope(), type, varname, getCompident().toString() + ":" #type "%" #varname, construct)
117 
118 #define TNT_APPLICATION_PAGE_VAR(type, varname, construct) \
119  TNT_VAR(request.getApplicationScope(), type, varname, getCompident().toString() + ":" #type "%" #varname, construct)
120 
121 #define TNT_APPLICATION_SHARED_VAR(type, varname, construct) \
122  TNT_VAR(request.getApplicationScope(), type, varname, #type "%" #varname, construct)
123 
124 #define TNT_APPLICATION_GLOBAL_VAR(type, varname, construct) \
125  TNT_VAR(request.getApplicationScope(), type, varname, #type "%" #varname, construct)
126 
127 #define TNT_APPLICATION_FILE_VAR(type, varname, file, construct) \
128  TNT_VAR(request.getApplicationScope(), type, varname, #file "%" #type "%" #varname, construct)
129 
130 #define TNT_THREAD_COMPONENT_VAR(type, varname, construct) \
131  TNT_VAR(request.getThreadScope(), type, varname, getCompident().toString() + ":" #type "%" #varname, construct)
132 
133 #define TNT_THREAD_PAGE_VAR(type, varname, construct) \
134  TNT_VAR(request.getThreadScope(), type, varname, getCompident().toString() + ":" #type "%" #varname, construct)
135 
136 #define TNT_THREAD_SHARED_VAR(type, varname, construct) \
137  TNT_VAR(request.getThreadScope(), type, varname, #type "%" #varname, construct)
138 
139 #define TNT_THREAD_GLOBAL_VAR(type, varname, construct) \
140  TNT_VAR(request.getThreadScope(), type, varname, #type "%" #varname, construct)
141 
142 #define TNT_THREAD_FILE_VAR(type, varname, file, construct) \
143  TNT_VAR(request.getThreadScope(), type, varname, #file "%" #type "%" #varname, construct)
144 
145 #define TNT_REQUEST_COMPONENT_VAR(type, varname, construct) \
146  TNT_VAR(request.getRequestScope(), type, varname, getCompident().toString() + ":" #type "%" #varname, construct)
147 
148 #define TNT_REQUEST_PAGE_VAR(type, varname, construct) \
149  TNT_VAR(request.getRequestScope(), type, varname, getCompident().toString() + ":" #type "%" #varname, construct)
150 
151 #define TNT_REQUEST_SHARED_VAR(type, varname, construct) \
152  TNT_VAR(request.getRequestScope(), type, varname, #type "%" #varname, construct)
153 
154 #define TNT_REQUEST_GLOBAL_VAR(type, varname, construct) \
155  TNT_VAR(request.getRequestScope(), type, varname, #type "%" #varname, construct)
156 
157 #define TNT_REQUEST_FILE_VAR(type, varname, file, construct) \
158  TNT_VAR(request.getRequestScope(), type, varname, #file "%" #type "%" #varname, construct)
159 
160 #define TNT_PARAM(type, varname, construct) \
161  TNT_VAR(qparam.getScope(), type, varname, #varname, construct)
162 }
163 
164 #endif // TNT_COMPONENT_H
165