Nemiver  0.3
nmv-plugin.h
Go to the documentation of this file.
1 /* -*- Mode: C++; indent-tabs-mode:nil; c-basic-offset:4;-*- */
2 
3 /*Copyright (c) 2005-2006 Dodji Seketeli
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this
7  * software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute,
10  * sublicense, and/or sell copies of the Software, and to permit
11  * persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  *
14  * The above copyright notice and this permission
15  * notice shall be included in all copies
16  * or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS",
19  * WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
20  * INCLUDING BUT NOT LIMITED TO THE
21  * WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE
23  * AND NONINFRINGEMENT.
24  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25  * HOLDERS BE LIABLE FOR ANY CLAIM,
26  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
27  * CONTRACT, TORT OR OTHERWISE,
28  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
29  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30  *
31  */
32 #ifndef __NMV_PLUGIN_H__
33 #define __NMV_PLUGIN_H__
34 
35 #include "nmv-api-macros.h"
36 #include <vector>
37 #include <string>
38 #include "nmv-safe-ptr-utils.h"
39 #include "nmv-dynamic-module.h"
40 
41 using namespace std;
42 
43 namespace nemiver {
44 namespace common {
45 
48 
49 class Plugin;
51 
52 class NEMIVER_API Plugin : public Object {
53 
54 public:
55 
56  class Descriptor;
58 
59  class EntryPoint;
61 
62 private:
63 
64  friend class PluginManager;
65 
66  struct Priv;
67  SafePtr<Priv> m_priv;
68 
69  //non copyable
70  Plugin (const Plugin &);
71  Plugin& operator= (const Plugin &);
72  //forbid default constructor
73  Plugin ();
74 
75 private:
76  Plugin (DescriptorSafePtr &a_descriptor,
77  DynamicModuleManager &a_bootstrap_module_manager);
78 
79  void load_entry_point ();
80 
81 public:
82 
83  class Descriptor : public Object {
84  bool m_auto_activate;
85  bool m_can_deactivate;
86  UString m_name;
87  UString m_version;
88  UString m_plugin_path;
89  UString m_entry_point_module_name;
90  UString m_entry_point_interface_name;
91  //map of deps, made of plugin/versions
92  std::map<UString, UString> m_dependencies;
93 
94  public:
95 
97  m_auto_activate (false),
98  m_can_deactivate (true)
99  {}
100 
101  void auto_activate (bool a_in) {m_auto_activate = a_in;}
102  bool auto_activate () {return m_auto_activate;}
103 
104  void can_deactivate (bool a_in) {m_can_deactivate = a_in;}
105  bool can_deactivate () {return m_can_deactivate;}
106 
107  const UString& name () const {return m_name;}
108  void name (const UString &a_in) {m_name = a_in;}
109 
111  {
112  return m_entry_point_module_name;
113  }
114  void entry_point_module_name (const UString &a_in)
115  {
116  m_entry_point_module_name = a_in;
117  }
118 
120  {
121  return m_entry_point_interface_name;
122  }
124  {
125  m_entry_point_interface_name = a_in;
126  }
127 
128  std::map<UString, UString>& dependencies () {return m_dependencies;}
129  const std::map<UString, UString>& dependencies () const
130  {
131  return m_dependencies;
132  }
133  void dependencies (const std::map<UString, UString> &a_in)
134  {
135  m_dependencies = a_in;
136  }
137 
138  const UString& plugin_path () const {return m_plugin_path;}
139  void plugin_path (const UString &a_in) {m_plugin_path = a_in;}
140 
141  const UString& version () const {return m_version;}
142  void version (const UString &a_in) {m_version = a_in;}
143  };//end class Descriptor
144 
145 public:
146 
148  friend class Plugin;
149  public:
150  class Loader;
152 
153  private:
154  friend class PluginManager;
155  class Priv;
156  SafePtr<Priv> m_priv;
157 
158  //non copyable
159  EntryPoint (const EntryPoint &);
160  EntryPoint& operator= (const EntryPoint &);
161  EntryPoint ();
162 
163 
164  protected:
165 
166  Plugin::EntryPoint::LoaderSafePtr plugin_entry_point_loader ();
167  void plugin_entry_point_loader (Plugin::EntryPoint::LoaderSafePtr &);
168 
169  //must be created by a factory
170  EntryPoint (DynamicModuleSafePtr &a_module);
171  EntryPoint (DynamicModule *a_module);
172 
173  virtual void activate (bool a_activate,
174  ObjectSafePtr &a_activation_context);
175  virtual bool is_activated ();
176 
177  void descriptor (DescriptorSafePtr &a_desc);
178 
179  public:
180 
181  bool build_absolute_resource_path (const UString &a_relative_path,
182  std::string &a_absolute_path);
183 
184  const UString& plugin_path ();
185 
187  struct Priv;
188  SafePtr<Priv> m_priv;
189 
190  Loader ();
191  public:
192  Loader (const UString &a_plugin_path);
193  virtual ~Loader ();
194  const UString& plugin_path ();
195  };//end Loader
196 
197  virtual ~EntryPoint ();
198  DescriptorSafePtr descriptor ();
199  };//end class EntryPoint
200 
201  virtual ~Plugin ();
202  DescriptorSafePtr descriptor ();
203  void descriptor (const DescriptorSafePtr &a_desc);
204  EntryPoint& entry_point ();
205  EntryPointSafePtr entry_point_ptr ();
206  void activate (bool a_activate, ObjectSafePtr &a_activation_context);
207  bool is_activated ();
208 };//end class Plugin
209 
211  struct Priv;
212  SafePtr<Priv> m_priv;
213 
214  UString find_plugin_path_from_name (const UString &a_name);
215  bool parse_descriptor (const UString &a_path,
217  static const UString& descriptor_name ();
218  bool load_descriptor_from_plugin_path (const UString &a_plugin_path,
220  bool load_descriptor_from_plugin_name (const UString &a_name,
222  bool load_dependant_descriptors
223  (const Plugin::Descriptor &a_desc,
224  std::vector<Plugin::DescriptorSafePtr> &a_descs);
225  bool load_dependant_descriptors_recursive
226  (const Plugin::Descriptor &a_desc,
227  std::vector<Plugin::DescriptorSafePtr> &);
228 public:
229 
230  PluginManager (DynamicModuleManager &a_module_manager);
231 
232  virtual ~PluginManager ();
233  PluginSafePtr load_plugin_from_path
234  (const UString &a_plugin_path,
235  std::vector<PluginSafePtr> &a_deps);
236  PluginSafePtr load_plugin_from_name (const UString &a_name,
237  std::vector<PluginSafePtr> &a_deps);
238  bool load_plugins ();
239  std::vector<UString>& plugins_search_path ();
240  void entry_point_loader (Plugin::EntryPoint::LoaderSafePtr &a_loader);
241  Plugin::EntryPoint::LoaderSafePtr entry_point_loader ();
242  std::map<UString, PluginSafePtr>& plugins_map ();
243 };//end class PluginManager
244 
245 }//end namespace common
246 };//end namespace nemiver
247 
248 #endif //__NMV_PLUGIN_H__
249 
nmv-safe-ptr-utils.h
nemiver::common::PluginSafePtr
SafePtr< Plugin, ObjectRef, ObjectUnref > PluginSafePtr
Definition: nmv-plugin.h:49
nemiver::common::PluginManagerSafePtr
SafePtr< PluginManager, ObjectRef, ObjectUnref > PluginManagerSafePtr
Definition: nmv-plugin.h:46
nemiver::common::Object
Definition: nmv-object.h:43
nemiver
Definition: nmv-address.h:31
nemiver::common::Plugin::Descriptor::dependencies
std::map< UString, UString > & dependencies()
Definition: nmv-plugin.h:128
NEMIVER_API
#define NEMIVER_API
Definition: nmv-api-macros.h:53
nemiver::common::Plugin::Descriptor
Definition: nmv-plugin.h:83
nmv-api-macros.h
nemiver::common::Plugin::Descriptor::entry_point_module_name
const UString & entry_point_module_name() const
Definition: nmv-plugin.h:110
nemiver::common::Plugin::Descriptor::can_deactivate
bool can_deactivate()
Definition: nmv-plugin.h:105
nemiver::common::DynamicModule
The base class for loadable modules.
Definition: nmv-dynamic-module.h:76
nemiver::common::Plugin::Descriptor::entry_point_interface_name
void entry_point_interface_name(const UString &a_in)
Definition: nmv-plugin.h:123
nemiver::common::Plugin::EntryPoint::LoaderSafePtr
SafePtr< Loader, ObjectRef, ObjectUnref > LoaderSafePtr
Definition: nmv-plugin.h:150
nemiver::common::Plugin::Descriptor::version
const UString & version() const
Definition: nmv-plugin.h:141
nemiver::common::UString
Definition: nmv-ustring.h:45
nemiver::common::Plugin::EntryPoint
Definition: nmv-plugin.h:147
nemiver::common::Plugin::Descriptor::plugin_path
const UString & plugin_path() const
Definition: nmv-plugin.h:138
nemiver::common::DynModIface
Definition: nmv-dynamic-module.h:220
nemiver::common::Plugin::Descriptor::auto_activate
bool auto_activate()
Definition: nmv-plugin.h:102
nemiver::common::Plugin::Descriptor::Descriptor
Descriptor()
Definition: nmv-plugin.h:96
nemiver::common::Plugin::DescriptorSafePtr
SafePtr< Descriptor, ObjectRef, ObjectUnref > DescriptorSafePtr
Definition: nmv-plugin.h:56
nemiver::common::Plugin::Descriptor::entry_point_interface_name
const UString & entry_point_interface_name() const
Definition: nmv-plugin.h:119
nemiver::common::Plugin::Descriptor::plugin_path
void plugin_path(const UString &a_in)
Definition: nmv-plugin.h:139
nemiver::common::Plugin::Descriptor::version
void version(const UString &a_in)
Definition: nmv-plugin.h:142
nmv-dynamic-module.h
nemiver::common::Plugin::Descriptor::name
void name(const UString &a_in)
Definition: nmv-plugin.h:108
nemiver::common::Plugin::EntryPoint::Loader
Definition: nmv-plugin.h:186
nemiver::common::Plugin::Descriptor::can_deactivate
void can_deactivate(bool a_in)
Definition: nmv-plugin.h:104
nemiver::common::Plugin::EntryPointSafePtr
SafePtr< EntryPoint, ObjectRef, ObjectUnref > EntryPointSafePtr
Definition: nmv-plugin.h:59
nemiver::common::PluginManager
Definition: nmv-plugin.h:210
nemiver::common::DynamicModuleManager
Definition: nmv-dynamic-module.h:265
nemiver::common::DynamicModule::Loader
Definition: nmv-dynamic-module.h:103
nemiver::common::Plugin::Descriptor::name
const UString & name() const
Definition: nmv-plugin.h:107
nemiver::common::Plugin::Descriptor::dependencies
const std::map< UString, UString > & dependencies() const
Definition: nmv-plugin.h:129
nemiver::common::Plugin::Descriptor::dependencies
void dependencies(const std::map< UString, UString > &a_in)
Definition: nmv-plugin.h:133
nemiver::common::SafePtr
Definition: nmv-safe-ptr.h:71
nemiver::common::Plugin::Descriptor::entry_point_module_name
void entry_point_module_name(const UString &a_in)
Definition: nmv-plugin.h:114
common
Definition: nmv-proc-list-dialog.h:32
nemiver::common::Plugin::Descriptor::auto_activate
void auto_activate(bool a_in)
Definition: nmv-plugin.h:101
nemiver::common::Plugin
Definition: nmv-plugin.h:52