fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Contrib / WebInterface / OSGWebInterface.h
blob4eb25f1c153fe2441a81c49b59f83fbef2f21637
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGWEBINTERFACE_H_
40 #define _OSGWEBINTERFACE_H_
42 #include <string>
43 #include <map>
44 #include <sstream>
46 #include "OSGConfig.h"
47 #include "OSGContribWebInterfaceDef.h"
49 #include "OSGStreamSocket.h"
50 #include "OSGBaseTypes.h"
51 #include "OSGMemoryObject.h"
52 #include "OSGNode.h"
54 OSG_BEGIN_NAMESPACE
56 class OSG_CONTRIBWEBINTERFACE_DLLMAPPING WebInterface : public MemoryObject
58 public:
60 typedef std::map<std::string, std::string> ParameterT;
62 typedef void (WebInterface::*MethodT)( std::ostream &,
63 const char*,
64 ParameterT &);
66 typedef std::map<std::string, MethodT> HandlerT;
68 OSG_GEN_INTERNAL_MEMOBJPTR(WebInterface);
70 typedef boost::function<ObjTransitPtr (UInt32)> CreateFunc;
72 /*---------------------------------------------------------------------*/
73 /*! \name request handling */
74 /*! \{ */
76 static ObjTransitPtr create (UInt32 port = 8080);
77 static void setCreatorFunc(CreateFunc createFunc );
79 /*! \} */
80 /*---------------------------------------------------------------------*/
81 /*! \name request handling */
82 /*! \{ */
84 virtual void handleRequests(void );
85 virtual bool waitRequest (double duration = -1);
86 virtual void flush (void );
88 /*! \} */
89 /*---------------------------------------------------------------------*/
90 /*! \name Set */
91 /*! \{ */
93 virtual void setSystemContainer( FieldContainer *system);
94 virtual void setRoot ( Node *root );
95 virtual void setChangeList ( ChangeList *clist );
97 virtual void setHeader (const std::string &header);
98 virtual void setFooter (const std::string &footer);
100 /*! \} */
101 /*---------------------------------------------------------------------*/
102 /*! \name Get */
103 /*! \{ */
105 virtual FieldContainer *getSystemContainer(void);
106 virtual Node *getRoot (void);
108 virtual const std::string &getHeader (void);
109 virtual const std::string &getFooter (void);
111 /*! \} */
112 /*========================= PROTECTED ===============================*/
114 protected:
116 typedef MemoryObject Inherited;
118 static CreateFunc _createFunc;
120 /*---------------------------------------------------------------------*/
121 /*! \name Constructors */
122 /*! \{ */
124 WebInterface(void);
125 WebInterface(UInt32 port);
127 /*! \} */
128 /*---------------------------------------------------------------------*/
129 /*! \name Destructor */
130 /*! \{ */
132 virtual ~WebInterface(void);
134 /*! \} */
135 /*---------------------------------------------------------------------*/
136 /*! \name handler management */
137 /*! \{ */
139 void addHandler(const Char8 *key, MethodT method);
141 /*! \} */
142 /*---------------------------------------------------------------------*/
143 /*! \name url encoding/decoding */
144 /*! \{ */
146 std::string encodeUrl(const std::string &path,
147 const ParameterT &param);
149 void decodeUrl(const std::string &url,
150 std::string &path,
151 ParameterT &param);
153 /*! \} */
154 /*---------------------------------------------------------------------*/
155 /*! \name Helper */
156 /*! \{ */
158 std::string createFCViewReference( FieldContainer *fcPtr,
159 UInt32 id=0 );
161 const char *getParam ( ParameterT &param,
162 const char *name );
164 void setParam ( ParameterT &param,
165 const char *name ,
166 const char *value );
168 void treeViewNode (std::ostream &os,
169 Node *node,
170 ParameterT &param );
172 const char *getNodeName (const FieldContainer *fcPtr);
175 /*! \} */
176 /*---------------------------------------------------------------------*/
177 /*! \name Helper */
178 /*! \{ */
180 bool checkRequest (std::string &url );
181 std::string getDefaultHeader (void);
183 /*! \} */
184 /*---------------------------------------------------------------------*/
185 /*! \name web page handler */
186 /*! \{ */
188 void rootHandler (std::ostream &os,
189 const char *path,ParameterT &param);
190 void changelistHandler(std::ostream &os,
191 const char *path,ParameterT &param);
192 void fcViewHandler (std::ostream &os,
193 const char *path,ParameterT &param);
194 void fcEditHandler (std::ostream &os,
195 const char *path,ParameterT &param);
196 void treeViewHandler (std::ostream &os,
197 const char *path,ParameterT &param);
199 /*! \} */
200 /*---------------------------------------------------------------------*/
201 /*! \name private members */
202 /*! \{ */
204 StreamSocket _socket;
205 StreamSocket _accepted;
206 std::stringstream _body;
207 HandlerT _handler;
208 NodeUnrecPtr _root;
209 FieldContainerUnrecPtr _systemContainer;
210 std::string _header;
211 std::string _footer;
212 ChangeList *_clist;
214 /*! \} */
215 /*========================== PRIVATE ================================*/
217 private:
219 WebInterface(const WebInterface &other);
220 void operator=(const WebInterface &rhs);
223 OSG_GEN_MEMOBJPTR(WebInterface);
225 OSG_END_NAMESPACE
227 #endif