examples/vm/main.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
3 
4  This file is part of the TerraLib - a Framework for building GIS enabled
5  applications.
6 
7  TerraLib is free software: you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation, either version 3 of the License,
10  or (at your option) any later version.
11 
12  TerraLib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with TerraLib. See COPYING. If not, write to
19  TerraLib Team at <terralib-team@terralib.org>.
20  */
21 
22 /*!
23  \file terralib/examples/vm/main.cpp
24 
25  \brief Examples for the Terralib Virtual Machine Module
26 
27  \author Frederico Augusto Bedê Teotônio
28 */
29 
30 // TerraLib
31 #include <terralib/common.h>
32 #include <terralib/core.h>
33 
34 #include <terralib/vm.h>
35 
36 // STL
37 #include <iostream>
38 #include <string>
39 
40 int main(int /*argc*/, char** /*argv*/)
41 {
43 
44  try
45  {
46  // load Lua Virtual Machine
47  std::string lvm_lua_manifest = te::core::FindInTerraLibPath(
48  "share/terralib/plugins/te.vm.lua.teplg.json");
49  std::string lvm_python_manifest = te::core::FindInTerraLibPath(
50  "share/terralib/plugins/te.vm.python.teplg.json");
51  te::core::PluginInfo lvm_lua_info(
52  te::core::JSONPluginInfoSerializer(lvm_lua_manifest));
53  te::core::PluginInfo lvm_python_info(
54  te::core::JSONPluginInfoSerializer(lvm_python_manifest));
57  te::core::PluginManager::instance().insert(lvm_python_info);
58  te::core::PluginManager::instance().load(lvm_python_info.name);
59 
60  std::cout << "=== LUA VIRTUAL MACHINE ===\n";
61 
62  std::string lua_script =
63  te::core::FindInTerraLibPath("examples/vm/vm_example.lua");
64 
67 
68  vm_lua->setFileName(lua_script.c_str());
69 
70  vm_lua->execute();
71 
72  std::cout << "=== PYTHON VIRTUAL MACHINE ===\n";
73 
74  std::string py_script =
75  te::core::FindInTerraLibPath("examples/vm/vm_example.py");
76 
77  te::vm::core::VirtualMachine* vm_python =
79 
80  vm_python->setFileName(py_script.c_str());
81 
82  vm_python->execute();
83 
85  }
86  catch(const te::vm::core::Exception& e)
87  {
88  if(const std::string* d = boost::get_error_info<te::ErrorDescription>(e))
89  {
90  std::cerr << *d << std::endl;
91  }
92  }
93 
95 
96  return EXIT_SUCCESS;
97 }
virtual void setFileName(QString file)=0
setFileName Sets the file that will be used in the Virtual Machine.
int main(int, char **)
void insert(const PluginInfo &pinfo)
Adds plugin with its plugin information to the list of unloaded plugins.
Include files for Core Library.
Basic information about a plugin.
void load(const std::string &plugin_name, const bool start=true)
It tries to load the informed plugin.
virtual void execute()=0
execute Executes the script file previously set.
std::string name
The plugin name: an internal value used to identify the plugin in the system. Must be a unique value...
static PluginManager & instance()
Access the singleton.
void finalize()
It finalizes the TerraLib Platform.
static TerraLib & getInstance()
It returns a reference to the singleton instance.
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
static VirtualMachineManager & instance()
Return a reference to the singleton.
void initialize()
It initializes the TerraLib Platform.
TECOREEXPORT PluginInfo JSONPluginInfoSerializer(const std::string &file_name)
A plugin finder that search for plugins in some special directories defined by compile time macros...
Definition: Serializers.cpp:44
TECOREEXPORT std::string FindInTerraLibPath(const std::string &path)
Returns the path relative to a directory or file in the context of TerraLib.
This file contains include headers for the TerraLib Common Runtime module.
VirtualMachine * get(const std::string &id) const
It returns the VM identified by id.
Base exception class for TerraLib Virtual Machine Library.
Include files for Virtual Machine Library.
void clear()
Stop and unload all plugins, then clear the internal list of plugins.