|
|
|
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
|
|
/* Copyright 2022 Ivan Polyakov */
|
|
|
|
|
|
|
|
#ifndef RAPIDA_APP_HXX_ENTRY
|
|
|
|
#define RAPIDA_APP_HXX_ENTRY
|
|
|
|
|
|
|
|
#include "Request.hxx"
|
|
|
|
#include "Response.hxx"
|
|
|
|
#include "Route.hxx"
|
|
|
|
#include "app.h"
|
|
|
|
|
|
|
|
namespace rpd {
|
|
|
|
/*!
|
|
|
|
* \brief C++ wrapper for Rapida application.
|
|
|
|
*/
|
|
|
|
class App {
|
|
|
|
public:
|
|
|
|
/*!
|
|
|
|
* Creates an rpd app and initializes FastCGI.
|
|
|
|
* \brief Default constructor
|
|
|
|
* \param socket_path UNIX Socket path.
|
|
|
|
*/
|
|
|
|
App()
|
|
|
|
{
|
|
|
|
rpd_app_create(&app);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns C implementation of the application.
|
|
|
|
*
|
|
|
|
* Usable when you need to start C server.
|
|
|
|
*
|
|
|
|
* \return C implementation of the application.
|
|
|
|
*/
|
|
|
|
rpd_app *c_app() const
|
|
|
|
{
|
|
|
|
return (rpd_app *) &app;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Adds handler for the path.
|
|
|
|
*
|
|
|
|
* \param path Enpoint.
|
|
|
|
* \param route Route handler.
|
|
|
|
*/
|
|
|
|
void add_route(const char *const path, Route *route)
|
|
|
|
{
|
|
|
|
rpd_app_add_route(&app, path, &Route::handle_request, route);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Destructor.
|
|
|
|
*/
|
|
|
|
virtual ~App() { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
rpd_app app; //< Composition with C implementation.
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // RAPIDA_APP_HXX_ENTRY
|