tufao
0.8.1
An asynchronous web framework for C++ built on top of Qt
|
When you are developing web applications, usually you are faced with the problem of develop applications that will be running for years, without stop.
Solutions in interpreted languages usually handle this problem by reloading the source file each time it changes. In C++, we can achieve a similar behaviour through plugins.
Tufão provides the class Tufao::HttpPluginServer, the application tufao-routes-editor and a QtCreator's plugin to facilitate the integration of Qt plugins and Tufao::HttpServerRequestRouter.
To help you understand the Tufão's plugin system, let's revisit the application created in Creating a Tufão-based application. This application should be the same generated by the application template, under Tufão QtCreator's plugin.
The Tufao::HttpServerRequestRouter provides a robust request router interface and would be useful if we could tell it to use a plugin located in the file system as a handler. This is where Tufao::HttpPluginServer enters.
Tufao::HttpPluginServer implements the Tufao::AbstractHttpServerRequestHandler interface, then you can use it as a handler in Tufao::HttpServerRequestRouter. Tufao::HttpPluginServer has its own set of mapping rules and handlers, but it will load its handlers from plugins.
In the plugin server created previously, we pass a file in the constructor. This is how we set the plugins from Tufao::HttpPluginServer. This file can be edited using the tufao-routes-editor tool (see tufao-routes-editor).
Enough text! Let's create our plugin. First, you must open QtCreator, go to the new project dialog and select the plugin template in the Tufão Web Server project.
You'll get the following files:
The Tufao::AbstractHttpServerRequestHandlerFactory class is just a factory used by Tufao::HttpPluginServer to instantiate new Tufao::AbstractHttpServerRequestHandler objects. If you intend to create a plugin to be used by Tufao::HttpPluginServer, you must:
Finally we have:
The only thing missing here is tell the application to use the plugin we created. To do that, we need:
To accomplish the final step, the routes.conf file, you must use tufao-routes-editor tool. Open the tool, click in "Add handler" and you'll have access to the mapping rules. In the field "Plugin location", you must put the path of the compiled object file generated from the plugin project.