Granada  1.54.0
Structured layer on top of C++ REST SDK for building server applications in C++. Granada implements sessions, server side plug-in framework, C++ OAuth 2.0 server, data storage access, server script running, server browsing.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
granada::http::controller::PluginController Class Reference

#include <plugin_controller.h>

Inheritance diagram for granada::http::controller::PluginController:
granada::http::controller::Controller

Public Member Functions

 PluginController (utility::string_t url, std::shared_ptr< granada::http::session::SessionFactory > session_factory, std::shared_ptr< granada::plugin::PluginFactory > plugin_factory)
 
virtual ~PluginController ()
 
- Public Member Functions inherited from granada::http::controller::Controller
virtual ~Controller ()
 
virtual pplx::task< void > open ()
 
virtual pplx::task< void > close ()
 

Protected Member Functions

virtual void LoadProperties ()
 
virtual void LoadClientPermissionProperty (const std::string &property_name, bool &property)
 
virtual void PluginHandlerInitialization (granada::plugin::PluginHandler *plugin_handler, granada::http::session::Session *session)
 
virtual void PluginHandlerLock (granada::plugin::PluginHandler *plugin_handler)
 
virtual web::json::value FireEvent (const web::json::value &request_json, granada::plugin::PluginHandler *plugin_handler)
 
virtual web::json::value RunPlugin (const web::json::value &request_json, granada::plugin::PluginHandler *plugin_handler)
 
virtual web::json::value SendMessage (const web::json::value &request_json, granada::plugin::PluginHandler *plugin_handler)
 
virtual web::json::value RunCommand (const web::json::value &request_json, granada::plugin::PluginHandler *plugin_handler)
 
virtual void handle_post (web::http::http_request request)
 

Protected Attributes

std::shared_ptr
< granada::http::session::SessionFactory
session_factory_
 
std::shared_ptr
< granada::plugin::PluginFactory
plugin_factory_
 
- Protected Attributes inherited from granada::http::controller::Controller
std::unique_ptr
< web::http::experimental::listener::http_listener > 
m_listener_
 

Static Protected Attributes

static int PLUGIN_HANDLER_USE_FREQUENCY_LIMIT_
 
static bool ALLOW_CLIENT_TO_FIRE_EVENTS_
 
static bool ALLOW_CLIENT_TO_RUN_PLUGINS_
 
static bool ALLOW_CLIENT_TO_SEND_MESSAGES_
 
static bool ALLOW_CLIENT_TO_RUN_COMMANDS_
 
static std::string PUBLICFILES_DIRECTORY_
 
static std::string USERFILES_DIRECTORY_
 
static std::once_flag properties_flag_
 

Detailed Description

Plugin controller, execute user plugins and give a response to the client. The communication between the client and the plugin and vice versa is done using JSON.

Constructor & Destructor Documentation

granada::http::controller::PluginController::PluginController ( utility::string_t  url,
std::shared_ptr< granada::http::session::SessionFactory session_factory,
std::shared_ptr< granada::plugin::PluginFactory plugin_factory 
)

Constructor.

Parameters
urlURI the controller listens to.
session_factorySession factory. Allows to have a unique point for checking and setting sessions. Used to create a new session if it does not exist or if it is timed out.
virtual granada::http::controller::PluginController::~PluginController ( )
inlinevirtual

Destructor

Member Function Documentation

virtual web::json::value granada::http::controller::PluginController::FireEvent ( const web::json::value &  request_json,
granada::plugin::PluginHandler plugin_handler 
)
protectedvirtual

Fires Plug-in event

Parameters
request_jsonRequest containing the parameters to pass to the plug-ins when firing event. Example:
{"event":"calculate","parameters":{"number":"5416","addend1":"5416","addend2":"25","factor1":"5416","factor2":"2"}}
plugin_handlerPlugin Handler.
Returns
Response to the event. Example:
{
"data": {
"math.multiplication": {
"data": {
"message": {
"data": {
"math.square": {
"data": {
"response": "Hello I'm the square plug-in!!!"
}
},
"math.sum": {
"data": {
"response": "Hello I'm the sum plug-in!!!"
}
}
}
},
"old_value": "10832",
"result": 10832
}
}
}
}
virtual void granada::http::controller::PluginController::handle_post ( web::http::http_request  request)
protectedvirtual

Handles POST HTTP request.

Parameters
requestHTTP request.
virtual void granada::http::controller::PluginController::LoadClientPermissionProperty ( const std::string &  property_name,
bool &  property 
)
protectedvirtual

Function for loading true/false properties.

Parameters
property_nameName of the property in the server.conf file.
propertyProperty.
virtual void granada::http::controller::PluginController::LoadProperties ( )
protectedvirtual

Loads the controller properties from the server configuration file, if properties and their values are not indicated in the server.conf file then take the values from granada/defaults.h.

virtual void granada::http::controller::PluginController::PluginHandlerInitialization ( granada::plugin::PluginHandler plugin_handler,
granada::http::session::Session session 
)
protectedvirtual

Initializes a Plug-in Handler if it is not already initialized. It associates a Plug-in Handler with a session. The id of the Plug-in Handler will be equal to the session token.

Parameters
sessionSession.
virtual void granada::http::controller::PluginController::PluginHandlerLock ( granada::plugin::PluginHandler plugin_handler)
protectedvirtual

Locks the thread until Plug-in Handler is usable. Plug-in Handler use can be limited using the PLUGIN_HANDLER_USE_FREQUENCY_LIMIT_ to prevent abuse.

Parameters
plugin_handlerPlug-in Handler.
virtual web::json::value granada::http::controller::PluginController::RunCommand ( const web::json::value &  request_json,
granada::plugin::PluginHandler plugin_handler 
)
protectedvirtual

Runs commands such as "reset" or "stop" to Reset or Stop the Plug-in Handler.

Parameters
request_jsonRequest containing the parameters to pass to the plug-ins when firing event. Example:
{"command":"reset"}
plugin_handlerPlugin Handler.
Returns
Command Response.
virtual web::json::value granada::http::controller::PluginController::RunPlugin ( const web::json::value &  request_json,
granada::plugin::PluginHandler plugin_handler 
)
protectedvirtual

Runs a plug-in with the given event

Parameters
request_jsonRequest containing the parameters to pass to the plug-ins when firing event. Example:
{"plugin_id":"math.sum","parameters":{"addend1":"8","addend2":"5"}
plugin_handlerPlugin Handler.
Returns
Plug-in response. Example:
{
"data": {
"math.sum": {
"data": {
"configurationtest": {
"mainContainerId": {
"editor": "text",
"value": "demo-container"
}
},
"message": {
"data": {
"math.multiplication": {
"data": {
"response": "Hello I'm the multiplication plug-in!!!"
}
},
"math.square": {
"data": {
"response": "Hello I'm the square plug-in!!!"
}
}
}
},
"old_value": "5441",
"result": 5441
}
}
}
}
virtual web::json::value granada::http::controller::PluginController::SendMessage ( const web::json::value &  request_json,
granada::plugin::PluginHandler plugin_handler 
)
protectedvirtual

Send message to plug-ins.

Parameters
request_jsonRequest containing the parameters to pass to the plug-ins when firing event. Example:
{"from":"client","to_ids":["math.sum"],"parameters":{"param1":"hi"}}
plugin_handlerPlugin Handler.
Returns
Response. Example:
{"data":{"math.sum":{"data":{"response":"Hello I'm the sum plug-in!!!"}}}}

Member Data Documentation

bool granada::http::controller::PluginController::ALLOW_CLIENT_TO_FIRE_EVENTS_
staticprotected

True if the client is allowed to fire plug-in events in the server. False if not. True by default. The value of this property is taken from the property "plugin_allow_client_to_fire_events" of the server configuration file, if the property is not in the server.conf file TRUE will be the default value.

bool granada::http::controller::PluginController::ALLOW_CLIENT_TO_RUN_COMMANDS_
staticprotected

True if the client is allowed to run commands such as reset the plug-in handler or stop the plug-in handler. False if not. True by default. The value of this property is taken from the property "plugin_allow_client_to_run_commands" of the server configuration file, if the property is not in the server.conf file TRUE will be the default value.

bool granada::http::controller::PluginController::ALLOW_CLIENT_TO_RUN_PLUGINS_
staticprotected

True if the client is allowed to run plug-ins in the server. False if not. True by default. The value of this property is taken from the property "plugin_allow_client_to_run_plugins" of the server configuration file, if the property is not in the server.conf file TRUE will be the default value.

bool granada::http::controller::PluginController::ALLOW_CLIENT_TO_SEND_MESSAGES_
staticprotected

True if the client is allowed to send messages to the plug-ins in the server. False if not. True by default. The value of this property is taken from the property "plugin_allow_client_to_send_messages" of the server configuration file, if the property is not in the server.conf file TRUE will be the default value.

std::shared_ptr<granada::plugin::PluginFactory> granada::http::controller::PluginController::plugin_factory_
protected

Object for creating PluginHandlers and Plugins.

int granada::http::controller::PluginController::PLUGIN_HANDLER_USE_FREQUENCY_LIMIT_
staticprotected

The minimum time in milliseconds a user has to wait between each plug-in handler use. This property takes the value of the "plugin_handler_use_frequency_limit" property from the server.conf file. If the property is not set in the server configuration file, there will be no use limit.

std::once_flag granada::http::controller::PluginController::properties_flag_
staticprotected

Once flag for loading properties only once.

std::string granada::http::controller::PluginController::PUBLICFILES_DIRECTORY_
staticprotected

Where the public plug-ins repositories are. the value is taken from the "plugin_publicfiles_directory" property in the server.conf file. If there is no value assigned, a default value will be taken from defaults.h.

std::shared_ptr<granada::http::session::SessionFactory> granada::http::controller::PluginController::session_factory_
protected

Object for creating a session if it does not exist or if it is timed out.

std::string granada::http::controller::PluginController::USERFILES_DIRECTORY_
staticprotected

Where the user plug-ins repositories are. the value is taken from the "plugin_publicfiles_directory" property in the server.conf file. If there is no value assigned, a default value will be taken from defaults.h.


The documentation for this class was generated from the following file: