src/terralib/binding/v8/plugin/Plugin.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file Plugin.cpp
22 
23  \brief A class that handles JavaScript Plugins using Google's V8 engine.
24  */
25 
26 // TerraLib
27 #include "../../../common/Exception.h"
28 #include "../common/JsContext.h"
29 #include "Plugin.h"
30 
32  : te::plugin::Plugin(pInfo),
33  m_ctx(0)
34 {
35 }
36 
38 {
39  m_startup.Dispose();
40  m_shutdown.Dispose();
41  m_jsplugin.Dispose();
42  m_jspluginFtor.Dispose();
43 }
44 
46 {
47  if(m_initialized || m_jsplugin.IsEmpty() || m_startup.IsEmpty() || (m_ctx == 0))
48  return;
49 
50  ::v8::HandleScope handleScope;
51 
52  ::v8::TryCatch trycatch;
53 
54  ::v8::Handle<::v8::Value> result = m_startup->Call(m_jsplugin, 0, 0);
55 
56  if(result.IsEmpty())
57  {
58  ::v8::Handle<::v8::Value> e = trycatch.Exception();
59  ::v8::String::AsciiValue estr(e);
60  throw te::common::Exception(*estr);
61  }
62 
63  m_initialized = true;
64 }
65 
67 {
68  if(!m_initialized || m_jsplugin.IsEmpty() || m_shutdown.IsEmpty() || (m_ctx == 0))
69  return;
70 
71  ::v8::HandleScope handleScope;
72 
73  ::v8::TryCatch trycatch;
74 
75  ::v8::Handle<::v8::Value> result = m_shutdown->Call(m_jsplugin, 0, 0);
76 
77  if(result.IsEmpty())
78  {
79  ::v8::Handle<::v8::Value> e = trycatch.Exception();
80  ::v8::String::AsciiValue estr(e);
81  throw te::common::Exception(*estr);
82  }
83 
84  m_initialized = false;
85 }
86 
void shutdown()
Do nothing! Just set plugin as stopped.
bool m_initialized
A flag that indicates if the plugin was started or not.
::v8::Persistent<::v8::Function > m_jspluginFtor
A reference to plugin&#39;s class constructor function.
::v8::Persistent<::v8::Function > m_startup
A reference to plugin startup method.
URI C++ Library.
Definition: Attributes.h:37
void startup()
Do nothing! Just set plugin as started.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
::v8::Persistent<::v8::Function > m_shutdown
A reference to plugin shutdown method.
te::v8::common::JsContext * m_ctx
The context used to run this plugin. (note: the manager is the owner of this context!) ...
The basic information about a plugin.
Plugin(const te::plugin::PluginInfo &pInfo)
It creates a new Java plugin.
::v8::Persistent<::v8::Object > m_jsplugin
A reference to an instance of the plugin.
A class that handles JavaScript Plugins using Google&#39;s V8 engine.