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 | Static Protected Attributes | List of all members
granada::plugin::MapSpidermonkeyPluginHandler Class Reference

#include <map_spidermonkey_plugin.h>

Inheritance diagram for granada::plugin::MapSpidermonkeyPluginHandler:
granada::plugin::SpidermonkeyPluginHandler granada::plugin::PluginHandler

Public Member Functions

 MapSpidermonkeyPluginHandler ()
 
 MapSpidermonkeyPluginHandler (const std::string id)
 
virtual ~MapSpidermonkeyPluginHandler ()
 
virtual
granada::cache::CacheHandler
cache () override
 
virtual
granada::plugin::PluginFactory
plugin_factory () override
 
virtual granada::runner::Runnerrunner () override
 
- Public Member Functions inherited from granada::plugin::SpidermonkeyPluginHandler
 SpidermonkeyPluginHandler ()
 
 SpidermonkeyPluginHandler (const std::string id)
 
virtual ~SpidermonkeyPluginHandler ()
 
virtual void Extend (const web::json::array &extended_plugins_ids, granada::plugin::Plugin *plugin) override
 
virtual void Run (granada::plugin::Plugin *plugin, web::json::value &parameters, const std::string &event_name, function_void_json success, function_void_json failure) override
 
virtual web::json::value Run (const std::vector< std::string > &plugin_ids, const std::string &event_name, web::json::value &parameters) override
 
virtual void Fire (const std::string &event_name, web::json::value &parameters, function_void_json success, function_void_json failure) override
 
virtual web::json::value SendMessage (const std::string &from, const std::vector< std::string > &to_ids, const web::json::value &message) override
 
- Public Member Functions inherited from granada::plugin::PluginHandler
 PluginHandler ()
 
 PluginHandler (const std::string id)
 
virtual ~PluginHandler ()
 
virtual const std::string & GetId ()
 
virtual bool Exists ()
 
virtual web::json::value Init (const std::vector< std::string > &paths)
 
virtual void Stop ()
 
virtual void Reset ()
 
virtual bool AddPluginLoader (web::json::value &header, const std::string &configuration, const std::string &script)
 
virtual void RemovePluginLoader (const std::string &plugin_id)
 
virtual void AddLoadEvent (const std::string &event_name, const std::string &plugin_id, const web::json::value &plugin_loader)
 
virtual void AddLoadEvent (const std::string &plugin_id, const web::json::value &header)
 
virtual void RemoveLoadEvent (const std::string &event_name)
 
virtual bool Add (const std::string &header, const std::string &configuration, const std::string &script)
 
virtual bool Add (web::json::value &header, const web::json::value &configuration, const std::string &script)
 
virtual bool Add (granada::plugin::Plugin *plugin)
 
virtual bool Add (granada::plugin::Plugin *plugin, web::json::value &parameters)
 
virtual void Extend (granada::plugin::Plugin *plugin)
 
virtual void Extend (granada::plugin::Plugin *extended_plugin, granada::plugin::Plugin *plugin)
 
virtual void AddExtension (const std::string &extended_plugin_id, const std::string &plugin_id)
 
virtual bool ApplyExtensions (granada::plugin::Plugin *plugin)
 
virtual void RemoveExtension (const std::string &extended_plugin_id, const std::string &plugin_id)
 
virtual void RemoveExtensions (const std::string &plugin_id)
 
virtual void AddEventListener (const std::string &event_name, const std::string &plugin_id)
 
virtual void RemoveEventListener (const std::string &event_name, const std::string &plugin_id)
 
virtual void RemoveEventListeners (const std::string &plugin_id)
 
virtual void RemoveEventListeners (granada::plugin::Plugin *plugin)
 
virtual web::json::value RemoveEventListeners (const web::json::value &parameters)
 
virtual std::unique_ptr
< granada::plugin::Plugin
GetPluginById (const std::string &plugin_id)
 
virtual void Run (const std::string &plugin_id, web::json::value &parameters, function_void_json success, function_void_json failure)
 
virtual void Run (const std::string &plugin_id, web::json::value &parameters, const std::string &event_name, function_void_json success, function_void_json failure)
 
virtual web::json::value Run (const web::json::value &parameters)
 
virtual void Remove (const std::string &plugin_id)
 
virtual web::json::value Remove (const web::json::value &parameters)
 
virtual void Fire (const std::string &event_name)
 
virtual void Fire (const std::string &event_name, web::json::value &parameters)
 
virtual web::json::value Fire (const web::json::value &parameters)
 
virtual web::json::value SendMessage (const std::string &from, const web::json::value &to_ids, const web::json::value &message)
 
virtual web::json::value SendMessage (const web::json::value &parameters)
 
virtual web::json::value SetValue (const web::json::value &parameters)
 
virtual web::json::value GetValue (const web::json::value &parameters)
 
virtual web::json::value DestroyValue (const web::json::value &parameters)
 
virtual web::json::value ClearValues (const web::json::value &parameters)
 
virtual void RunnerLock ()
 
virtual std::string plugin_handler_value_hash ()
 
virtual std::string plugin_loader_value_hash (const std::string &plugin_id)
 
virtual std::string plugin_value_hash (const std::string &plugin_id)
 
virtual std::string plugin_store_hash (const std::string &plugin_handler_id, const std::string &plugin_id)
 
virtual std::string plugin_event_value_hash (const std::string &event_name)
 

Static Protected Attributes

static std::unique_ptr
< granada::cache::CacheHandler
cache_
 
static std::unique_ptr
< granada::plugin::PluginFactory
plugin_factory_
 
static std::unique_ptr
< granada::runner::Runner
runner_
 
- Static Protected Attributes inherited from granada::plugin::PluginHandler
static int PLUGIN_BYTES_LIMIT_
 
static int SEND_MESSAGE_PLUGIN_GROUP_SIZE_
 
static int RUNNER_USE_FREQUENCY_LIMIT_
 
static std::once_flag properties_flag_
 
static std::once_flag functions_to_runner_flag_
 
static unsigned long long uid_
 
static std::mutex uid_mtx_
 

Additional Inherited Members

- Protected Member Functions inherited from granada::plugin::SpidermonkeyPluginHandler
virtual web::json::value ExtendsAddition (const web::json::value &extended_plugin_extends, const web::json::value &plugin_extends, const std::string &plugin_id)
 
virtual bool Load (granada::plugin::Plugin *plugin, const web::json::value &loader) override
 
virtual std::string MultiplePluginScript (const std::vector< std::string > &plugin_ids)
 
virtual web::json::value Run (std::string &script, const std::string &event_name, web::json::value &parameters)
 
virtual std::string GetJavaScriptPluginCore (granada::plugin::Plugin *plugin)
 
virtual std::string GetJavaScriptPluginExtension (granada::plugin::Plugin *plugin)
 
- Protected Member Functions inherited from granada::plugin::PluginHandler
virtual void LoadProperties ()
 
virtual std::string GetUID ()
 
virtual int PreloadRepositories ()
 
virtual int PreloadPackages (const std::string &repository_path)
 
virtual int PreloadPackagedPlugins (const std::string &package_directory_path)
 
virtual void FireLoadEvent (const std::string &event_name)
 
virtual std::string TransformPluginScriptPath (const std::string &plugin_script_path)
 
virtual std::string TransformPluginConfigurationPath (const std::string &plugin_configuration_path)
 
virtual void AddFunctionsToRunner ()
 
- Protected Attributes inherited from granada::plugin::SpidermonkeyPluginHandler
const std::string javascript_plugin_core_
 
const std::string javascript_plugin_extension_
 
- Protected Attributes inherited from granada::plugin::PluginHandler
std::string id_
 
std::vector< std::string > paths_
 

Detailed Description

Plugin Handler: Handles the lifecycle and communication of server side plugins. Manages plug-ins lifecycle: Loads and adds plug-ins, runs plug-ins and removes them.

Use example:

// creating a plug-in that multiplies a number by a pre-configured factor.
// create header
// {"id":"product.tax","events":["calculate-tax","save-product-before"],"extends":["math.multiplication"]}
web::json::value header = web::json::value::parse("{\"id\":\"product.tax\",\"events\":[\"calculate-tax\",\"save-product-before\"],\"extends\":[\"math.multiplication\"]}");
// create configuration
// {"USTaxFactor":{"value":0.07,"editor":"number-2-decimal"},"FRTaxFactor":{"value":0.18,"editor":"number-2-decimal"}}
web::json::value header = web::json::value::parse("{\"USTaxFactor\":{\"value\":0.07,\"editor\":\"number-2-decimal\"},\"FRTaxFactor\":{\"value\":0.20,\"editor\":\"number-2-decimal\"}}");
// script -----------------------
std::string script = "{
run : function(parameters){
var me = this;
var result = -1;
var configuration = getConfiguration();
// default tax factor
var taxFactor = null;
if (parameters["currency"] && configuration["taxFactor"] && configuration["USTaxFactor"]["value"]){
if (parameters["currency"] == "EUR"){
taxFactor = configuration["FRTaxFactor"]["value"];
}else{
taxFactor = configuration["USTaxFactor"]["value"];
}
}else{
taxFactor = 0.07;
}
if (parameters["price"] && taxFactor){
parameters["price"] = me.multiplication(parameters["price"],taxFactor);
}
return parameters;
}
}";
// end script --------------------------
// Adding the plug-in
plugin_handler->Add(header,configuration,script);
// Running the plug-in, 2 options
// 1) Firing an event:
web::json::value parameters = web::json::value::parse("{\"price\":24,\"currency\":\"USD\"}");
plugin_handler->Fire("save-product-before",parameters,[=](const web::json::value& data){
// success callback.
},[=](const web::json::value& data){
// error callback
});
// 2) Retrieving the plug-in by its id:
std::shared_ptr<granada::plugin::Plugin> plugin = plugin_handler->GetPluginById("product.tax");
web::json::value parameters = web::json::value::parse("{\"price\":24,\"currency\":\"USD\"}");
plugin->Run(parameters,[=](const web::json::value& data){
// success callback.
},[=](const web::json::value& data){
// error callback
});

Constructor & Destructor Documentation

granada::plugin::MapSpidermonkeyPluginHandler::MapSpidermonkeyPluginHandler ( )
inline

Constructor. Plug-in handler without an id. Load Plug-in Handler properties.

granada::plugin::MapSpidermonkeyPluginHandler::MapSpidermonkeyPluginHandler ( const std::string  id)
inline

Constructor. Assigns an id to the plug-in handler. Load Plug-in Handler properties.

Parameters
idUnique Identifier of the PluginHandler.
virtual granada::plugin::MapSpidermonkeyPluginHandler::~MapSpidermonkeyPluginHandler ( )
inlinevirtual

Destructor.

Member Function Documentation

virtual granada::cache::CacheHandler* granada::plugin::MapSpidermonkeyPluginHandler::cache ( )
inlineoverridevirtual

Returns a pointer to the Cache Handler. Used to cache plug-ins headers, loaders, configuration and script paths as well as plug-ins global values. Needs to be overridden.

Returns
Pointer to the Cache Handler.

Reimplemented from granada::plugin::PluginHandler.

virtual granada::plugin::PluginFactory* granada::plugin::MapSpidermonkeyPluginHandler::plugin_factory ( )
inlineoverridevirtual

Returns a pointer to a Plug-in Factory. Used to create PluginHandlers and Plugins.

Returns
Pointer to a plug-in Factory.

Reimplemented from granada::plugin::PluginHandler.

virtual granada::runner::Runner* granada::plugin::MapSpidermonkeyPluginHandler::runner ( )
inlineoverridevirtual

Returns a pointer to the responsible of running or executing the plug-in scripts/executables.

Returns
Pointer to the scripts/executables runner.

Reimplemented from granada::plugin::PluginHandler.

Member Data Documentation

std::unique_ptr<granada::cache::CacheHandler> granada::plugin::MapSpidermonkeyPluginHandler::cache_
staticprotected

Pointer to the Cache Handler. Used to cache plug-ins headers, loaders, configuration and script paths as well as plug-ins global values.

std::unique_ptr<granada::plugin::PluginFactory> granada::plugin::MapSpidermonkeyPluginHandler::plugin_factory_
staticprotected

Pointer to a Plug-in Factory. Used to create PluginHandlers and Plugins.

std::unique_ptr<granada::runner::Runner> granada::plugin::MapSpidermonkeyPluginHandler::runner_
staticprotected

Pointer to the responsible of running or executing the plug-in scripts/executables.


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