27 #include "../../../common/Exception.h" 28 #include "../../../core/logger/Logger.h" 29 #include "../../../core/translator/Translator.h" 30 #include "../common/JsContext.h" 31 #include "../common/JsContextManager.h" 32 #include "../common/Utils.h" 33 #include "../jsi/platform/OpenModules.h" 44 #include <boost/filesystem.hpp> 52 std::auto_ptr<Plugin> jsplugin(
new Plugin(pInfo));
55 std::vector<te::plugin::PluginInfo::Parameter>::const_iterator itP = std::find_if(pInfo.m_parameters.begin(),
56 pInfo.m_parameters.end(),
59 std::string ctxid =
"DEFAULT";
61 if(itP != pInfo.m_parameters.end())
71 ctx = jsctx.release();
74 ::v8::Persistent<::v8::Context> context = ctx->getCtx();
75 ::v8::Context::Scope contextScope(context);
76 ::v8::HandleScope handleScope;
77 ::v8::Local<::v8::FunctionTemplate> jsPrintFunction = ::v8::FunctionTemplate::New(
te::v8::common::Print);
78 context->Global()->Set(::v8::String::New(
"print"), jsPrintFunction->GetFunction());
82 jsplugin->m_ctx = ctx;
85 ::v8::Persistent<::v8::Context> context = ctx->getCtx();
86 ::v8::Context::Scope contextScope(context);
87 ::v8::HandleScope handleScope;
90 std::vector<te::plugin::PluginInfo::Resource>::const_iterator itR = std::find_if(pInfo.m_resources.begin(),
91 pInfo.m_resources.end(),
94 if(itR == pInfo.m_resources.end())
97 boost::filesystem::path pluginFile(pInfo.m_folder);
98 pluginFile /= itR->second;
102 ::v8::Handle<::v8::Script> script = ::v8::Script::Compile(source);
104 ::v8::TryCatch trycatch;
106 ::v8::Handle<::v8::Value> result = script->Run();
110 ::v8::Handle<::v8::Value> e = trycatch.Exception();
111 ::v8::String::AsciiValue estr(e);
116 itP = std::find_if(pInfo.m_parameters.begin(),
117 pInfo.m_parameters.end(),
120 if(itP == pInfo.m_parameters.end())
121 return jsplugin.release();
123 const std::string& pluginClassName = itP->second;
126 ::v8::Local<::v8::String> jsPluginClassName = ::v8::String::New(pluginClassName.c_str());
127 ::v8::Local<::v8::Value> jsPluginClass = context->Global()->Get(jsPluginClassName);
129 if(jsPluginClass.IsEmpty())
132 if(!jsPluginClass->IsFunction())
135 ::v8::Handle<::v8::Function> jsPluginClassFtor = ::v8::Handle<::v8::Function>::Cast(jsPluginClass);
136 jsplugin->m_jspluginFtor = ::v8::Persistent<::v8::Function>::New(jsPluginClassFtor);
139 ::v8::Local<::v8::Object> jsPlugin = jsPluginClassFtor->NewInstance();
141 if(jsPlugin.IsEmpty())
144 jsplugin->m_jsplugin = ::v8::Persistent<::v8::Object>::New(jsPlugin);
152 return jsplugin.release();
#define TE_V8_PLUGIN_ENGINE_CODE
The plugin engine name for Java plugins.
An abstract class for TerraLib Plugins.
TEV8COMMONEXPORT::v8::Handle<::v8::String > ReadFile(const std::string &fileName)
It reads a file into a v8 string.
A class for keeping reference to a persistent context.
TEV8JSIEXPORT void RegisterModule(::v8::Local<::v8::Object > &global)
It register the Module class.
#define TR_V8PLUGIN(message)
It marks a string in order to get translated. This is a special mark used in the Vector Geometry modu...
static JsContextManager & getInstance()
It returns a reference to the singleton instance.
TEV8COMMONEXPORT void Cache(::v8::Local<::v8::Object > &obj, const std::string &methodName,::v8::Persistent<::v8::Function > &outFtor)
It caches the object method into the persistent output functor.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
void unload(te::plugin::AbstractPlugin *plugin)
It try to unload the informed plugin.
A plugin engine for plugins written in JavaScript using Google's V8 engine.
The basic information about a plugin.
TEV8COMMONEXPORT::v8::Handle<::v8::Value > Print(const ::v8::Arguments &args)
This function will print all the arguments to the standard output.
A class that handles JavaScript Plugins using Google's V8 engine.
te::plugin::AbstractPlugin * load(const te::plugin::PluginInfo &pInfo)
It try to create and load the informed plugin.