1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGWEBINTERFACE_H_
40 #define _OSGWEBINTERFACE_H_
46 #include "OSGConfig.h"
47 #include "OSGContribWebInterfaceDef.h"
49 #include "OSGStreamSocket.h"
50 #include "OSGBaseTypes.h"
51 #include "OSGMemoryObject.h"
56 class OSG_CONTRIBWEBINTERFACE_DLLMAPPING WebInterface
: public MemoryObject
60 typedef std::map
<std::string
, std::string
> ParameterT
;
62 typedef void (WebInterface::*MethodT
)( std::ostream
&,
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 */
76 static ObjTransitPtr
create (UInt32 port
= 8080);
77 static void setCreatorFunc(CreateFunc createFunc
);
80 /*---------------------------------------------------------------------*/
81 /*! \name request handling */
84 virtual void handleRequests(void );
85 virtual bool waitRequest (double duration
= -1);
86 virtual void flush (void );
89 /*---------------------------------------------------------------------*/
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
);
101 /*---------------------------------------------------------------------*/
105 virtual FieldContainer
*getSystemContainer(void);
106 virtual Node
*getRoot (void);
108 virtual const std::string
&getHeader (void);
109 virtual const std::string
&getFooter (void);
112 /*========================= PROTECTED ===============================*/
116 typedef MemoryObject Inherited
;
118 static CreateFunc _createFunc
;
120 /*---------------------------------------------------------------------*/
121 /*! \name Constructors */
125 WebInterface(UInt32 port
);
128 /*---------------------------------------------------------------------*/
129 /*! \name Destructor */
132 virtual ~WebInterface(void);
135 /*---------------------------------------------------------------------*/
136 /*! \name handler management */
139 void addHandler(const Char8
*key
, MethodT method
);
142 /*---------------------------------------------------------------------*/
143 /*! \name url encoding/decoding */
146 std::string
encodeUrl(const std::string
&path
,
147 const ParameterT
¶m
);
149 void decodeUrl(const std::string
&url
,
154 /*---------------------------------------------------------------------*/
158 std::string
createFCViewReference( FieldContainer
*fcPtr
,
161 const char *getParam ( ParameterT
¶m
,
164 void setParam ( ParameterT
¶m
,
168 void treeViewNode (std::ostream
&os
,
172 const char *getNodeName (const FieldContainer
*fcPtr
);
176 /*---------------------------------------------------------------------*/
180 bool checkRequest (std::string
&url
);
181 std::string
getDefaultHeader (void);
184 /*---------------------------------------------------------------------*/
185 /*! \name web page handler */
188 void rootHandler (std::ostream
&os
,
189 const char *path
,ParameterT
¶m
);
190 void changelistHandler(std::ostream
&os
,
191 const char *path
,ParameterT
¶m
);
192 void fcViewHandler (std::ostream
&os
,
193 const char *path
,ParameterT
¶m
);
194 void fcEditHandler (std::ostream
&os
,
195 const char *path
,ParameterT
¶m
);
196 void treeViewHandler (std::ostream
&os
,
197 const char *path
,ParameterT
¶m
);
200 /*---------------------------------------------------------------------*/
201 /*! \name private members */
204 StreamSocket _socket
;
205 StreamSocket _accepted
;
206 std::stringstream _body
;
209 FieldContainerUnrecPtr _systemContainer
;
215 /*========================== PRIVATE ================================*/
219 WebInterface(const WebInterface
&other
);
220 void operator=(const WebInterface
&rhs
);
223 OSG_GEN_MEMOBJPTR(WebInterface
);