All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UserPlugins.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2012 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 terralib/qt/af/UserPlugins.cpp
22 
23  \brief A singleton for managing the plugins enabled by a specific user.
24 */
25 
26 // Boost => don't change this include order, otherwise you may have compile problems!
27 #include <boost/filesystem.hpp>
28 #include <boost/foreach.hpp>
29 
30 // TerraLib
31 #include "../../common/OSSettingsDir.h"
32 #include "../../common/SystemApplicationSettings.h"
33 #include "../../common/Translator.h"
34 #include "../../common/UserApplicationSettings.h"
35 #include "../../plugin/PluginInfo.h"
36 #include "../../plugin/PluginManager.h"
37 #include "../../plugin/Utils.h"
38 #include "ApplicationPlugins.h"
39 #include "Exception.h"
40 #include "UserPlugins.h"
41 
42 // STL
43 #include <memory>
44 #include <set>
45 
46 
48 {
49 // firs we need to acquire all the locks in order (otherwise we may dead-lock!): application plugins and then user plugins
51 
53 
54 // the list of installed plugins
55  std::set<std::pair<std::string, std::string> > sPlugins;
56  bool child_exists = false;
57 
58 // get system plugins
59  {
60  boost::property_tree::ptree& p = ApplicationPlugins::getInstance().getAllSettings();
61 
62  child_exists = p.count("Plugins") > 0;
63 
64  if(child_exists && (!p.empty()))
65  BOOST_FOREACH(boost::property_tree::ptree::value_type& v, p.get_child("Plugins"))
66  {
67  std::string first = v.first.data();
68 
69  if(first != "Plugin")
70  continue;
71 
72  const std::string& pname = v.second.get<std::string>("Name");
73  const std::string& pdir = v.second.get<std::string>("Path.<xmlattr>.xlink:href");
74 
75  sPlugins.insert(std::pair<std::string, std::string>(pname, pdir));
76  }
77  }
78 
79 // get specific user plugins
80  {
81  boost::property_tree::ptree& p = te::common::UserApplicationSettings::getInstance().getAllSettings().get_child("UserSettings");
82 
83  child_exists = p.count("SpecificPlugins") > 0;
84 
85  if(child_exists && (!p.empty()))
86  BOOST_FOREACH(boost::property_tree::ptree::value_type& v, p.get_child("SpecificPlugins"))
87  {
88  if(v.second.data().empty())
89  continue;
90 
91  const std::string& pname = v.second.get<std::string>("Name");
92  const std::string& pdir = v.second.get<std::string>("Path.<xmlattr>.xlink:href");
93 
94  sPlugins.insert(std::pair<std::string, std::string>(pname, pdir));
95  }
96  }
97 
98 // the plugins enabled by the user
99  std::set<std::string> uPlugins;
100 
101  {
102  boost::property_tree::ptree& p = te::common::UserApplicationSettings::getInstance().getAllSettings().get_child("UserSettings");
103 
104  child_exists = p.count("EnabledPlugins") > 0;
105 
106  if(child_exists && (!p.empty()))
107  BOOST_FOREACH(boost::property_tree::ptree::value_type& v, p.get_child("EnabledPlugins"))
108  {
109  if(v.second.data().empty())
110  continue;
111 
112  uPlugins.insert(v.second.data());
113  }
114  }
115 
116 // retrieve plugin information about each user plugin
117  boost::ptr_vector<te::plugin::PluginInfo> plugins;
118  std::set<std::pair<std::string, std::string> >::const_iterator it = sPlugins.begin();
119  std::set<std::pair<std::string, std::string> >::const_iterator itend = sPlugins.end();
120  std::set<std::string>::const_iterator ituend = uPlugins.end();
121 
122  while(it != itend)
123  {
124  std::set<std::string>::const_iterator itu = uPlugins.find(it->first);
125 
126  try
127  {
129 
130  if(itu != ituend)
131  plugins.push_back(pinfo);
132  else
134  }
135  catch(...)
136  {
137  }
138 
139  ++it;
140  }
141 
142 // load and start each plugin
144 
145  return;
146 }
147 
149 {
150 }
151 
153 {
154 }
155 
void load()
It starts all the plugins enabled by the user.
Definition: UserPlugins.cpp:47
The basic information about a plugin.
Definition: PluginInfo.h:61
An exception class for the TerraLib Application Framework.
TEPLUGINEXPORT PluginInfo * GetInstalledPlugin(const std::string &pluginFilePath)
It returns information about a given plugin provided its plugin configuration file name or dir...
Definition: Utils.cpp:82
const boost::property_tree::ptree & getAllSettings() const
It return a reading reference to the internal settings.
~UserPlugins()
Destructor.
A singleton for managing the application plugins.
A singleton for managing the plugins enabled by a specific user.
UserPlugins()
It initializes the singleton.
static ApplicationPlugins & getInstance()
It returns a reference to the singleton instance.