Added docs for WebServer.

This commit is contained in:
Relintai 2022-08-21 18:24:20 +02:00
parent 0c9e77aab4
commit 70cc269b40

View File

@ -1,8 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<class name="WebServer" inherits="Node" version="3.7"> <class name="WebServer" inherits="Node" version="3.7">
<brief_description> <brief_description>
The WebServer class can be used as a base for Webserver implementations.
</brief_description> </brief_description>
<description> <description>
The WebServer class can be used as a base for Webserver implementations.
When the actual server implementation receives an HTTP request it needs to take it's [WebServerRequest] implementation, set it up properly, then it needs to call the [code]server_handle_request()[/code] method with it, to start handling it.
It sould have one [WebNode] (or a derived class) as a child, it will be set as the web root. If you add more than one, only the first one will be used. Requests will be sent to this [WebNode]'s [code]handle_request_main()[/code].
If a [HTTPSessionManager] is added as a child, it will be picked up automatically, and then it can be used by [WebNodes]s to store session information.
</description> </description>
<tutorials> <tutorials>
</tutorials> </tutorials>
@ -10,51 +15,64 @@
<method name="_start" qualifiers="virtual"> <method name="_start" qualifiers="virtual">
<return type="void" /> <return type="void" />
<description> <description>
The default implementation of start().
</description> </description>
</method> </method>
<method name="_stop" qualifiers="virtual"> <method name="_stop" qualifiers="virtual">
<return type="void" /> <return type="void" />
<description> <description>
The default implementation of stop().
</description> </description>
</method> </method>
<method name="get_session_manager"> <method name="get_session_manager">
<return type="HTTPSessionManager" /> <return type="HTTPSessionManager" />
<description> <description>
Returns the active [HTTPSessionManager].
</description> </description>
</method> </method>
<method name="get_web_root"> <method name="get_web_root">
<return type="WebNode" /> <return type="WebNode" />
<description> <description>
Returns the root [WebNode].
</description> </description>
</method> </method>
<method name="request_write_lock"> <method name="request_write_lock">
<return type="void" /> <return type="void" />
<description> <description>
Request a write lock, in order to be able to change your active [WebNode] tree. Actually change the tree in _notification, when you receive NOTIFICATION_WEB_SERVER_WRITE_LOCK_ACQUIRED.
Note that HTTP servers are highly asynchronous, and due to how the system works adding and even removing [WebNode]s from the tree is not that big of a deal, however deallocating [WebNode]s while they are processing requests will crash your app sooner or later. Just to be safe I recommended that you lock your [WebNode] tree branch before touching it.
Do not forget to make your nodes refresh their internal handler map when you change the tree using other helper methods like build_handler_map().
</description> </description>
</method> </method>
<method name="server_handle_request"> <method name="server_handle_request">
<return type="void" /> <return type="void" />
<argument index="0" name="request" type="WebServerRequest" /> <argument index="0" name="request" type="WebServerRequest" />
<description> <description>
The default request handler method that your implementations can use.
</description> </description>
</method> </method>
<method name="start"> <method name="start">
<return type="void" /> <return type="void" />
<description> <description>
Start the server.
</description> </description>
</method> </method>
<method name="stop"> <method name="stop">
<return type="void" /> <return type="void" />
<description> <description>
Stop the server.
</description> </description>
</method> </method>
</methods> </methods>
<constants> <constants>
<constant name="NOTIFICATION_WEB_SERVER_STARTED" value="2000"> <constant name="NOTIFICATION_WEB_SERVER_STARTED" value="2000">
This notification will be sent after the server is started.
</constant> </constant>
<constant name="NOTIFICATION_WEB_SERVER_STOPPED" value="2001"> <constant name="NOTIFICATION_WEB_SERVER_STOPPED" value="2001">
This notification will be sent after the server is stopped.
</constant> </constant>
<constant name="NOTIFICATION_WEB_SERVER_WRITE_LOCK_ACQUIRED" value="2002"> <constant name="NOTIFICATION_WEB_SERVER_WRITE_LOCK_ACQUIRED" value="2002">
This is sent to self, and children when a write lock is acquired. Only change the tree in _notification if you get this.
</constant> </constant>
</constants> </constants>
</class> </class>