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 | List of all members
granada::plugin::SpidermonkeyPluginHandler Class Reference

#include <spidermonkey_plugin.h>

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

Public Member Functions

 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
granada::cache::CacheHandler
cache ()
 
virtual
granada::plugin::PluginFactory
plugin_factory ()
 
virtual granada::runner::Runnerrunner ()
 
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)
 

Protected Member Functions

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

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_
 

Additional Inherited Members

- 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_
 

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. This is an abstract class that can't work on its own. Cache and Plug-in Factory need to be overridden.

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::SpidermonkeyPluginHandler::SpidermonkeyPluginHandler ( )
inline

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

granada::plugin::SpidermonkeyPluginHandler::SpidermonkeyPluginHandler ( 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::SpidermonkeyPluginHandler::~SpidermonkeyPluginHandler ( )
inlinevirtual

Destructor.

Member Function Documentation

virtual void granada::plugin::SpidermonkeyPluginHandler::Extend ( const web::json::array &  extended_plugins_ids,
granada::plugin::Plugin plugin 
)
overridevirtual

Cross Extends plug-ins. If this method is called, the "plugin" will extend "extended_plugins", this means that "plugin" will integrate the "extended_plugins" members that it does not override. Both plug-in "extends" members are concatenated.

Parameters
extended_plugins_idsJSON array with the ids of the plug-ins that are going to be extended.
pluginPointer to the plug-in that is going to extend other plug-ins.

Reimplemented from granada::plugin::PluginHandler.

virtual web::json::value granada::plugin::SpidermonkeyPluginHandler::ExtendsAddition ( const web::json::value &  extended_plugin_extends,
const web::json::value &  plugin_extends,
const std::string &  plugin_id 
)
protectedvirtual

Adds the extended plug-in extends to the plug-in extends. If an extend already exist it does not add it.

Parameters
extended_plugin_extendsJSON Array with the extended plug-in extends.
plugin_extendsJSON Array with the plug-in extends.
plugin_idId of the plug-in.
Returns
Extends added.
virtual void granada::plugin::SpidermonkeyPluginHandler::Fire ( const std::string &  event_name,
web::json::value &  parameters,
function_void_json  success,
function_void_json  failure 
)
overridevirtual

Called to fire an event. All plug-ins listening to that event will run.

Parameters
event_nameName of the event.
parametersParameters in form of JSON object that are passed to the plug-ins. that listen to the event. Example: {"number":"9285","factor1":"9285","factor2":"4",addend1":"9285","addend2":"25"}
successCallback function called when the plug-ins successfully run passing the plug-ins responses in form of a JSON object:
{
"data" :
{
"math.sum" : {"data":{"response":9310}},
"math.multiplication" : {"data":{"response":37140}}
}
}
If there was an error in one of the plug-ins:
{
"data" :
{
"math.sum" : {"data":{"response":9310}},
"math.multiplication" : {"error":"undefined_plugin", "error_description":"Plug-in could not be found with given plug-in id."}
}
}
failureCallback function called when there is a problem running plug-ins with the error code and error description.

Reimplemented from granada::plugin::PluginHandler.

virtual std::string granada::plugin::SpidermonkeyPluginHandler::GetJavaScriptPluginCore ( granada::plugin::Plugin plugin)
protectedvirtual

Returns the Javascript basic functions for parsing communications between javascript plug-ins and C++ functions. Inserts the values of the plug-in in the script such as the Plug-in id, the Plug-in Handler id, the plug-in configuration.

Parameters
pluginPlugin
Returns
Javascript plugin basic functions.
virtual std::string granada::plugin::SpidermonkeyPluginHandler::GetJavaScriptPluginExtension ( granada::plugin::Plugin plugin)
protectedvirtual

Returns the Javascript functions for applying script inheritance. Inserts the plug-in configuration in the script.

Parameters
pluginPlugin
Returns
Javascript plugin basic functions.
virtual bool granada::plugin::SpidermonkeyPluginHandler::Load ( granada::plugin::Plugin plugin,
const web::json::value &  loader 
)
overrideprotectedvirtual

Loads a plug-in, and returns true if plug-in loaded successfully, false if not. This function is normally called by the Plug-in Handler when the event loader of the plug-in is fired. Can be also called to force the plug-in load

Parameters
pluginPointer to the plug-in to load.
loaderPlug-in loader. JSON object containing the information about how to load a plug-in. Example:
{
"events" : ["init-ph-after"]
}
Returns
True if plug-in loaded successfully, false if not.

Reimplemented from granada::plugin::PluginHandler.

virtual std::string granada::plugin::SpidermonkeyPluginHandler::MultiplePluginScript ( const std::vector< std::string > &  plugin_ids)
protectedvirtual

Joins and returns multiple plug-in scripts and configurations in one script.

Parameters
plugin_idsVector with the ids of the plug-in.
Returns
Joined plug-in scripts and configurations. Example:
var __PLUGIN;
[javascript-plugin-core.js]
var __PLUGINS = {"math.sum":{...},"math.square":{...}};
var __PLUGINS_CONFIGURATIONS = {{"math.sum":{...},"math.square":{...}};
virtual void granada::plugin::SpidermonkeyPluginHandler::Run ( granada::plugin::Plugin plugin,
web::json::value &  parameters,
const std::string &  event_name,
function_void_json  success,
function_void_json  failure 
)
overridevirtual

Runs a plug-in. Call a success or failure callback, depending if the plug-in was successfully run or not.

Parameters
pluginPointer to the plug-in that has to be run.
parametersJSON with the parameters to pass to the plug-in. Example: {"addend1":"4","addend2":"6"}
event_nameName of the event that has triggered the plug-in, empty if the plug-in was not triggered firing an event.
successCallback function called after the plug-in has been run with a response in form of JSON. Example:
{
"data" :
{
"math.sum" : {"data":{"response":10}},
}
}
failureCallback function called if the plug-in is not run successfully with a response in form of a JSON, in such case normally containing an error code and an error description. Example:
{
"error" : "script_error"
}

Reimplemented from granada::plugin::PluginHandler.

virtual web::json::value granada::plugin::SpidermonkeyPluginHandler::Run ( const std::vector< std::string > &  plugin_ids,
const std::string &  event_name,
web::json::value &  parameters 
)
overridevirtual

Runs multiple plug-ins at a time. Used by the Fire function to run the plug-ins listening to a certain event.

Parameters
plugin_idsVector of strings containing the ids of the plug-ins to run.
event_nameName of the event, or empty string if there is no event, to pass to the plug-ins.
parametersJSON with the Params to pass to the plug-ins. Example: {"number":"9285","factor1":"9285","factor2":"4",addend1":"9285","addend2":"25"}
Returns
JSON object with the response of the plug-in. Example:
{
"data" :
{
"math.sum" : {"data":{"response":9310}},
"math.multiplication" : {"data":{"response":37140}}
}
}
If there was an error in one of the plug-ins:
{
"data" :
{
"math.sum" : {"data":{"response":9310}},
"math.multiplication" : {"error":"undefined_plugin", "error_description":"Plug-in could not be found with given plug-in id."}
}
}

Reimplemented from granada::plugin::PluginHandler.

virtual web::json::value granada::plugin::SpidermonkeyPluginHandler::Run ( std::string &  script,
const std::string &  event_name,
web::json::value &  parameters 
)
protectedvirtual

Run multiple plug-ins at a time using a script containing more than one plug-in. Used by the Fire function to run the cached script of plug-ins listening to a certain event.

Parameters
scriptScript containing more than one plug-in.
event_nameName of the event, or empty string if there is no event, to pass to the plug-ins.
parametersJSON with the Params to pass to the plug-ins.
Returns
JSON object with the response of the plug-in.
virtual web::json::value granada::plugin::SpidermonkeyPluginHandler::SendMessage ( const std::string &  from,
const std::vector< std::string > &  to_ids,
const web::json::value &  message 
)
overridevirtual

Send messag to more than one plug-in, and returns the responses to the message in form of JSON value.

Parameters
fromId of the sender of the message. Normally a plug-in Id.
to_idsIds of the Plug-ins that recieve the message. Empty JSON array if we want to send the message to all plug-ins (be-careful, doing this can seriously harm performance).
messageMessage in JSON format. Example: {"message":"square calculated! Somebody wants to tell me something?"}
Returns
JSON object with the response to the message or JSON with an error code and an error_description if the message couldn't be delivered correctly. Response Examples:
{"data":{"math.multiplication":{"data":{"response":"8795"}}}}
{"math.multiplication":
{
"error" : "undefined_plugin",
"error_description" : "Plug-in could not be found with given plug-in id."
}
}

Reimplemented from granada::plugin::PluginHandler.

Member Data Documentation

const std::string granada::plugin::SpidermonkeyPluginHandler::javascript_plugin_core_
protected
Initial value:
=
# 1 "/opt/github_granada/Release/include/granada/plugin/javascript-plugin-core.min.js" 1
"var __PLUGIN_ID=\"{{__PLUGIN_ID}}\";var __PLUGIN_HANDLER_ID=\"{{__PLUGIN_HANDLER_ID}}\";function getConfiguration(){return __PLUGIN.configuration_;};function setValue(key,value){if(key&&value&&typeof key==\"string\"&&typeof value==\"string\"){var value=__setValue(\"{\\\"key\\\":\\\"\"+key+\"\\\",\\\"value\\\":\\\"\"+value+\"\\\",\\\"__PLUGIN_ID\\\":\\\"\"+__PLUGIN_ID+\"\\\",\\\"__PLUGIN_HANDLER_ID\\\":\\\"{{__PLUGIN_HANDLER_ID}}\\\"}\");var value_json;try{value_json=JSON.parse(value);}catch(e){value_json={\"error\":\"server_error\"};}if(!value_json[\"error\"]){return true;}}return false;};function getValue(key){if(key&&typeof key==\"string\"){var value=__getValue(\"{\\\"key\\\":\\\"\"+key+\"\\\",\\\"__PLUGIN_ID\\\":\\\"\"+__PLUGIN_ID+\"\\\",\\\"__PLUGIN_HANDLER_ID\\\":\\\"{{__PLUGIN_HANDLER_ID}}\\\"}\");var value_json;try{value_json=JSON.parse(value);}catch(e){value_json={\"error\":\"server_error\"};}if(!value_json[\"error\"]&&value_json[\"value\"]){return value_json[\"value\"];}}return\"\";};function destroyValue(key){if(key&&typeof key==\"string\"){__destroyValue(\"{\\\"key\\\":\\\"\"+key+\"\\\",\\\"__PLUGIN_ID\\\":\\\"\"+__PLUGIN_ID+\"\\\",\\\"__PLUGIN_HANDLER_ID\\\":\\\"{{__PLUGIN_HANDLER_ID}}\\\"}\");}};function clearValues(){__clearValues(\"{\\\"__PLUGIN_ID\\\":\\\"\"+__PLUGIN_ID+\"\\\",\\\"__PLUGIN_HANDLER_ID\\\":\\\"{{__PLUGIN_HANDLER_ID}}\\\"}\");};function sendMessage(params,toIds,callback){var stringifiedParams;var stringifiedToIds;var errorMessage=\"\";try{stringifiedParams=JSON.stringify(params);}catch(e){stringifiedParams=null;errorMessage=e.message;}if(stringifiedParams==null){if(callback){callback({\"error\":\"message_parameters_error\",\"error_description\":errorMessage});}}else{var responseData={};try{if(toIds==null){stringifiedToIds=\"[]\";}else{if(toIds.constructor===Array){stringifiedToIds=JSON.stringify(toIds);var len=toIds.length;if(len>0&&typeof __PLUGINS!==\"undefined\"){ var IdsNotInPlugins=[];while(len--){var pluginId=toIds[len];var plugin=__PLUGINS[pluginId];if(plugin&&plugin[\"onMessage\"]&&typeof plugin[\"onMessage\"]==\"function\"){responseData[pluginId]=__sendIntraMessage(params,pluginId,__PLUGIN_ID);}else{IdsNotInPlugins.push(toIds[len]);}}if(IdsNotInPlugins.length>0){stringifiedToIds=JSON.stringify(IdsNotInPlugins);}else{var responseJSON={\"data\":responseData};callback(responseJSON);return;}}else{stringifiedToIds=JSON.stringify(toIds);}}else{stringifiedToIds=\"[]\";}}}catch(e){stringifiedToIds=null;errorMessage=e.message;}if(stringifiedToIds==null){if(callback){callback({\"error\":\"message_to_ids_error\",\"error_description\":errorMessage});}}else{var response=__sendMessage(\"{\\\"parameters\\\":\"+stringifiedParams+\",\\\"to_ids\\\":\"+stringifiedToIds+\",\\\"__PLUGIN_ID\\\":\\\"\"+__PLUGIN_ID+\"\\\",\\\"__PLUGIN_HANDLER_ID\\\":\\\"{{__PLUGIN_HANDLER_ID}}\\\"}\");if(callback){var responseJSON;try{responseJSON=JSON.parse(response);}catch(e){responseJSON={\"data\":{}};}if(responseJSON[\"data\"]){for(var key in responseData){responseJSON[\"data\"][key]=responseData[key];}}callback(responseJSON);}}}};function remove(pluginId){if(pluginId){if(typeof pluginId==\"string\"){__remove(\"{\\\"id\\\":\\\"\"+pluginId+\"\\\",\\\"__PLUGIN_HANDLER_ID\\\":\\\"{{__PLUGIN_HANDLER_ID}}\\\"}\");}}else{__remove(\"{\\\"id\\\":\\\"\"+__PLUGIN_ID+\"\\\",\\\"__PLUGIN_HANDLER_ID\\\":\\\"{{__PLUGIN_HANDLER_ID}}\\\"}\");}};function removeEvents(){__removeEvents(\"{\\\"__PLUGIN_ID\\\":\\\"\"+__PLUGIN_ID+\"\\\",\\\"__PLUGIN_HANDLER_ID\\\":\\\"{{__PLUGIN_HANDLER_ID}}\\\"}\");};function call(name,params){var fn=__PLUGIN[name];if(fn&&__type(fn)==\"function\"){fn(params);}};function __sendIntraMessage(params,toId,fromId){if(typeof __PLUGINS!==\"undefined\"){var plugin=__PLUGINS[toId];if(plugin&&plugin[\"onMessage\"]&&typeof plugin[\"onMessage\"]==\"function\"){var message=null;if(params[\"message\"]){message=params[\"message\"];}var responseData=plugin.onMessage(message,fromId);if(responseData[\"error\"]){return responseData;}else{return{\"data\":responseData};}}}else{return{\"error\":\"undefined_plugins\",\"error_description\":\"There are no __PLUGINS.\"};}};function __onMessage(message,_from){__setPluginConfiguration();var returnData;if(__PLUGIN[\"onMessage\"]&&__type(__PLUGIN[\"onMessage\"])==\"function\"){returnData=JSON.stringify(__PLUGIN.onMessage(message,_from));}else{returnData=\"{\\\"error\\\":\\\"undefined_onmessage_function\\\",\\\"error_description\\\":\\\"Undefined onMessage function\\\"}\";}return returnData;};function __multiOnMessage(message,_from){__setPluginsConfigurations();var response=\"{\";var i=0;var returnData;for(var pluginId in __PLUGINS){__PLUGIN_ID=pluginId;__PLUGIN=__PLUGINS[pluginId];if(i>0){response+=\",\";}if(__PLUGIN[\"onMessage\"]&&__type(__PLUGIN[\"onMessage\"])==\"function\"){var messageResponse=__PLUGIN.onMessage(message,_from);if(!messageResponse[\"error\"]){try{returnData=JSON.stringify(messageResponse);response+=\"\\\"\"+pluginId+\"\\\":{\\\"data\\\":\"+returnData+\"}\";}catch(e){}}}i++;}response+=\"}\";return response;};function fire(eventName,params,success,failure){var stringifiedParams;var errorMessage=\"\";try{stringifiedParams=JSON.stringify(params);}catch(e){stringifiedParams=null;errorMessage=e.message;}if(stringifiedParams==null){if(failure){failure({\"error\":\"message_parameters_error\",\"error_description\":errorMessage});}}var response=__fire(\"{\\\"parameters\\\":\"+stringifiedParams+\",\\\"event_name\\\":\\\"\"+eventName+\"\\\",\\\"__PLUGIN_ID\\\":\\\"\"+__PLUGIN_ID+\"\\\",\\\"__PLUGIN_HANDLER_ID\\\":\\\"{{__PLUGIN_HANDLER_ID}}\\\"}\");if(response[\"error\"]){if(failure){failure(response);}}else{if(success){success(response);}}};function runPlugin(id,params,success,failure){var stringifiedParams;var errorMessage=\"\";try{stringifiedParams=JSON.stringify(params);}catch(e){stringifiedParams=null;errorMessage=e.message;}if(stringifiedParams==null){if(callback){callback({\"error\":\"message_parameters_error\",\"error_description\":errorMessage});}}var response=__runPlugin(\"{\\\"parameters\\\":\"+stringifiedParams+\",\\\"id\\\":\\\"\"+id+\"\\\",\\\"__PLUGIN_ID\\\":\\\"\"+__PLUGIN_ID+\"\\\",\\\"__PLUGIN_HANDLER_ID\\\":\\\"{{__PLUGIN_HANDLER_ID}}\\\"}\");if(response[\"error\"]){if(failure){failure(response);}}else{if(success){success(response);}}};function __getResponseFirstElementData(data){if(data){var data=data[\"data\"];if(data&&__type(data)==\"object\"){for(var key in data){var pluginData=newData[key];if(!pluginData[\"error\"]){return pluginData;}}}}return null;};function __wrappedRun(params,eventName){__setPluginConfiguration();fire(__PLUGIN_ID+\"-before\",params,function(data){data=__getResponseFirstElementData(data);if(data){params=data;}},function(data){});fire(__PLUGIN_ID+\"-in-process\",params);var data=__PLUGIN.run(params,eventName);fire(__PLUGIN_ID+\"-after\",params,function(_data){_data=__getResponseFirstElementData(_data);if(_data){data=_data;}},function(data){});return data;};function __runPlugins(params,eventName){__setPluginsConfigurations();var response=\"{\";var i=0;for(var pluginId in __PLUGINS){__PLUGIN_ID=pluginId;__PLUGIN=__PLUGINS[pluginId];if(i>0){response+=\",\";}response+=\"\\\"\"+pluginId+\"\\\":{\\\"data\\\":\"+__wrappedRun(params,eventName)+\"}\";i++;}response+=\"}\";return response;};function __setPluginConfiguration(){if(!__PLUGIN[\"configuration_\"]){__PLUGIN[\"configuration_\"]={{__PLUGIN_CONFIGURATION}};}};function __setPluginsConfigurations(){ var configuration=null;for(var pluginId in __PLUGINS){if(!__PLUGINS[pluginId][\"configuration_\"]){configuration=__PLUGINS_CONFIGURATIONS[pluginId];if(configuration){__PLUGINS[pluginId][\"configuration_\"]=configuration;}}}};function __type(obj){if(Array.isArray(obj)){return\"array\";}else if(typeof obj==\"string\"){return\"string\";}else if(obj!=null&&typeof obj==\"object\"){return\"object\";}else if(typeof obj==\"function\"){return\"function\";}else{return\"other\";}};"# 269 "/opt/github_granada/Release/include/granada/plugin/spidermonkey_plugin.h" 2

Javascript basic functions for parsing communications between javascript plug-ins and C++ functions.

const std::string granada::plugin::SpidermonkeyPluginHandler::javascript_plugin_extension_
protected
Initial value:
=
# 1 "/opt/github_granada/Release/include/granada/plugin/javascript-plugin-extension.min.js" 1
" function __extend(){var pluginExtends=__PLUGIN_JSON[\"extends\"];var plugin;var pluginJSONConfiguration=__PLUGIN_JSON[\"configuration_\"];if(!pluginJSONConfiguration||type(pluginJSONConfiguration)!=\"object\"){pluginJSONConfiguration={{__PLUGIN_CONFIGURATION}};} for(var pluginId in __EXTENDED_PLUGINS){plugin=__EXTENDED_PLUGINS[pluginId]; for(var memberName in plugin){if(typeof __PLUGIN_JSON[memberName]==\"undefined\"){__PLUGIN_JSON[memberName]=plugin[memberName];}} if(__EXTENDED_CONFIGURATIONS){var configuration=__EXTENDED_CONFIGURATIONS[pluginId]; if(configuration){for(var key in __EXTENDED_CONFIGURATIONS){if(typeof pluginJSONConfiguration[key]==\"undefined\"){pluginJSONConfiguration[key]=configuration[key];}}}} pluginToExtendExtends=plugin[\"extends\"];if(__type(pluginToExtendExtends)==\"array\"){var len=pluginToExtendExtends.length;while(len--){var extendedId=pluginToExtendExtends[len];if(pluginExtends.indexOf(extendedId)==-1){pluginExtends.push(extendedId);}}}} __PLUGIN_JSON[\"configuration_\"]=pluginJSONConfiguration;__PLUGIN_JSON[\"extends\"]=pluginExtends;};function __print(obj){var stringifiedObj=\"{\";var item;var i=0;for(var key in obj){var stringifiedItem=false;item=obj[key];var type=__type(item);if(type==\"string\"){if(i>0){stringifiedObj+=\",\";} stringifiedObj+=\"\\\"\"+key+\"\\\":\\\"\"+item+\"\\\"\";stringifiedItem=true;}else if(type==\"object\"){if(i>0){stringifiedObj+=\",\";} stringifiedObj+=\"\\\"\"+key+\"\\\":\"+__print(item);stringifiedItem=true;}else if(type==\"function\"){if(i>0){stringifiedObj+=\",\";} stringifiedObj+=\"\\\"\"+key+\"\\\":\"+item;stringifiedItem=true;} if(stringifiedItem){i++;}} stringifiedObj+=\"}\";return stringifiedObj;};function __type(obj){if(Array.isArray(obj)){return\"array\";}else if(typeof obj==\"string\"){return\"string\";}else if(obj!=null&&typeof obj==\"object\"){return\"object\";}else if(typeof obj==\"function\"){return\"function\";}else{return\"other\";}};"# 277 "/opt/github_granada/Release/include/granada/plugin/spidermonkey_plugin.h" 2

Javascript functions for extending plug-ins.


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