1pluginmgr(n) Plugin management pluginmgr(n)
2
3
4
5______________________________________________________________________________
6
8 pluginmgr - Manage a plugin
9
11 package require Tcl 8.4
12
13 package require pluginmgr ?0.2?
14
15 ::pluginmgr objectName ?option value...?
16
17 ::pluginmgr::paths objectName name...
18
19 objectName method ?arg arg ...?
20
21 objectName clone
22
23 objectName configure
24
25 objectName configure option
26
27 objectName configure -option value...
28
29 objectName cget -option
30
31 objectName destroy
32
33 objectName do arg...
34
35 objectName interpreter
36
37 objectName plugin
38
39 objectName load string
40
41 objectName unload
42
43 objectName list
44
45 objectName path path
46
47 objectName paths
48
49_________________________________________________________________
50
52 This package provides commands and objects for the generic management
53 of plugins which can be loaded into an application.
54
55 To avoid the implementation of yet another system to locate Tcl code
56 the system provides by this package is built on top of the regular
57 package management system. Each plugin is considered as a package and a
58 simple invokation of package require is enough to locate and load it,
59 if it exists. The only time we will need additional paths is when a
60 plugin manager is part of a wrapped application and has to be able to
61 search for plugins existing outside of that application. For this situ‐
62 ation the package provides a command to create a general set of such
63 paths based on names for the plugin manager and/or application in ques‐
64 tion.
65
66 The main contribution of this package is a generic framework which
67 allows the easy declaration of
68
69 [1] How to translate a plugin name to the name of the package imple‐
70 menting it, and vice versa.
71
72 [2] The list of commands a plugin has to provide as API, and also of
73 more complex checks as code.
74
75 [3] The list of commands expected by the plugin from the environ‐
76 ment.
77
78 This then allows the easy generation of plugin managers customized to
79 particular types of plugins for an application.
80
81 It should be noted that all plugin code is considered untrusted and
82 will always be executed within a safe interpreter. The interpreter is
83 enabled enough to allow plugins the loading of all additional packages
84 they may need.
85
87 PACKAGE COMMANDS
88 ::pluginmgr objectName ?option value...?
89 This command creates a new plugin manager object with an associ‐
90 ated Tcl command whose name is objectName. This object command
91 is explained in full detail in the sections OBJECT COMMAND and
92 OBJECT METHODS. The object command will be created under the
93 current namespace if the objectName is not fully qualified, and
94 in the specified namespace otherwise.
95
96 The options and their values coming after the name of the object
97 are used to set the initial configuration of the mamager object,
98 specifying the applicable plugins and their API.
99
100 ::pluginmgr::paths objectName name...
101 This utility command adds a set of paths to the specified
102 object, based on the given names. It will search for:
103
104 [1] The environment variable name_PLUGINS. Its contents will
105 be interpreted as a list of package paths. The entries
106 have to be separated by either : (unix) or ; (windows).
107
108 The name will be converted to upper-case letters.
109
110 [2] The registry entry "HKEY_LOCAL_MACHINE\SOFT‐
111 WARE\name\PLUGINS". Its contents will be interpreted as
112 a list of package paths. The entries have to be separated
113 by ;. This item is considered only when on Windows (tm).
114
115 The casing of letters is not changed.
116
117 [3] The registry entry "HKEY_CURRENT_USER\SOFTWARE\name\PLUG‐
118 INS". Its contents will be interpreted as a list of
119 package paths. The entries have to be separated by ;.
120 This item is considered only when on Windows (tm).
121
122 The casing of letters is not changed.
123
124 [4] The directory "~/.name/plugin".
125
126 [5] The directory "~/.name/plugins".
127
128 The casing of letters is not changed.
129
130 and add all the paths found that way to the list of package paths main‐
131 tained by the object.
132
133 If name is namespaced each item in the list will be repeated per prefix
134 of name, with conversion of :-sequences into the proper separator
135 (underscore for environment variables, backslash for registry entries,
136 and / for directories).
137
138 Examples:
139
140
141 ::pluginmgr::paths ::obj docidx
142
143 => env DOCIDX_PLUGINS
144 reg HKEY_LOCAL_MACHINE\SOFTWARE\docidx\PLUGINS
145 reg HKEY_CURRENT_USER\SOFTWARE\docidx\PLUGINS
146 path ~/.docidx/plugins
147
148 ::pluginmgr::paths ::obj doctools::idx
149
150 => env DOCTOOLS_PLUGINS
151 env DOCTOOLS_IDX_PLUGINS
152 reg HKEY_LOCAL_MACHINE\SOFTWARE\doctools\PLUGINS
153 reg HKEY_LOCAL_MACHINE\SOFTWARE\doctools\idx\PLUGINS
154 reg HKEY_CURRENT_USER\SOFTWARE\doctools\PLUGINS
155 reg HKEY_CURRENT_USER\SOFTWARE\doctools\idx\PLUGINS
156 path ~/.doctools/plugin
157 path ~/.doctools/idx/plugin
158
159
160 OBJECT COMMAND
161 All commands created by the command ::pluginmgr (See section PACKAGE
162 COMMANDS) have the following general form and may be used to invoke
163 various operations on their plugin manager object.
164
165 objectName method ?arg arg ...?
166 The method method and its arg'uments determine the exact behav‐
167 ior of the command. See section OBJECT METHODS for the detailed
168 specifications.
169
170 OBJECT METHODS
171 objectName clone
172 This method creates a new plugin management object and returns
173 the associated object command. The generated object is a clone
174 of the object the method was invoked on. I.e. the new object
175 will have the same configuration as the current object. With
176 regard to state, if the current object has a plugin loaded then
177 this plugin and all associated state is moved to the generated
178 clone and the current object is reset into the base state (no
179 plugin loaded). In this manner a configured plugin manager is
180 also a factory for loaded plugins.
181
182 objectName configure
183 The method returns a list of all known options and their current
184 values when called without any arguments.
185
186 objectName configure option
187 The method behaves like the method cget when called with a sin‐
188 gle argument and returns the value of the option specified by
189 said argument.
190
191 objectName configure -option value...
192 The method reconfigures the specified options of the object,
193 setting them to the associated values, when called with an even
194 number of arguments, at least two.
195
196 The legal options are described in the section OBJECT CONFIGURA‐
197 TION.
198
199 objectName cget -option
200 This method expects a legal configuration option as argument and
201 will return the current value of that option for the object the
202 method was invoked for.
203
204 The legal configuration options are described in section OBJECT
205 CONFIGURATION.
206
207 objectName destroy
208 This method destroys the object it is invoked for.
209
210 objectName do arg...
211 This method interprets its list of arguments as the words of a
212 command and invokes this command in the execution context of the
213 plugin. The result of the invoked command is made the result of
214 the method. The call will fail with an error if no valid plugin
215 has been loaded into the manager object.
216
217 objectName interpreter
218 This method returns the handle of the safe interpreter the cur‐
219 rent plugin is loaded into. An empty string as return value sig‐
220 nals that the manager currently has no valid plugin loaded.
221
222 objectName plugin
223 This method returns the name of the plugin currently loaded. An
224 empty string as return value signals that the manager currently
225 has no valid plugin loaded.
226
227 objectName load string
228 This method loads, validates, and initializes a named plugin
229 into the manager object.
230
231 The algorithm to locate and load the plugin employed is:
232
233 [1] If the string contains the path to an existing file then
234 this file is taken as the implementation of the plugin.
235
236 [2] Otherwise the plugin name is translated into a package
237 name via the value of the option -pattern and then loaded
238 through the regular package management.
239
240 [3] The load fails.
241
242 The algorithm to validate and initialize the loaded code is:
243
244 [1] If the option -api is non-empty introspection commands
245 are used to ascertain that the plugin provides the listed
246 commands.
247
248 [2] If the option -check is non-empty the specified command
249 prefix is called.
250
251 [3] If either of the above fails the candidate plugin is
252 unloaded again
253
254 [4] Otherwise all the commands specified via the option -cmds
255 are installed in the plugin.
256
257 A previously loaded plugin is discarded, but only if the new plugin was
258 found and sucessfully validated and initialized. Note that there will
259 be no intereference between old and new plugin as both will be put into
260 separate safe interpreters.
261
262 objectName unload
263 This method unloads the currently loaded plugin. It returns the
264 empty string. The call will be silently ignored if no plugin is
265 loaded at all.
266
267 objectName list
268 This method uses the contents of the option -pattern to find all
269 packages which can be plugins under the purview of this manager
270 object. It translates their names into plugin names and returns
271 a list containing them.
272
273 objectName path path
274 This methods adds the specified path to the list of additional
275 package paths to look at when searching for a plugin. It returns
276 the empty string. Duplicate paths are ignored, i.e. each path is
277 added only once. Paths are made absolute, but are not normal‐
278 ized.
279
280 objectName paths
281 This method returns a list containing all additional paths which
282 have been added to the plugin manager object since its creation.
283
284 OBJECT CONFIGURATION
285 All plugin manager objects understand the following configuration
286 options:
287
288 -pattern string
289 The value of this option is a glob pattern which has to contain
290 exactly one '*'-operator. All packages whose names match this
291 pattern are the plugins recognized by the manager object. And
292 vice versa, the replacement of the '*'-operator with a plugin
293 name will yield the name of the package implementing that plug‐
294 in.
295
296 This option has no default, except if option -name was set. It
297 has to be set before attempting to load a plugin, either
298 directly, or through option -name.
299
300 -api list
301 The value of this option is a list of command names, and any
302 plugin loaded has to provide these commands. Names which are not
303 fully qualified are considered to be rooted in the global names‐
304 pace. If empty no expectations are made on the plugin. The
305 default value is the empty list.
306
307 -check cmdprefix
308 The value of this option is interpreted as a command prefix.
309 Its purpose is to perform complex checks on a loaded plugin
310 package to validate it, which go beyond a simple list of pro‐
311 vided commands.
312
313 It is called with the manager object command as the only argu‐
314 ment and has to return a boolean value. A value of true will be
315 interpreted to mean that the candidate plugin passed the test.
316 The call will happen if and only if the candidate plugin already
317 passed the basic API check specified through the option -api.
318
319 The default value is the empty list, which causes the manager
320 object to suppress the call and to assume the candidate plugin
321 passes.
322
323 -cmds dict
324 The value of this option is a dictionary. It specifies the com‐
325 mands which will be made available to the plugin (as keys), and
326 the trusted commands in the environment which implement them (as
327 values). The trusted commands will be executed in the inter‐
328 preter specified by the option -cmdip. The default value is the
329 empty dictionary.
330
331 -cmdip ipspec
332 The value of this option is the path of the interpreter where
333 the trusted commands given to the plugin will be executed in.
334 The default is the empty string, referring to the current inter‐
335 preter.
336
337 -setup cmdprefix
338 The value of this option is interpreted as a command prefix.
339
340 It is called whenever a new safe interpreter for a plugin has
341 been created, but before a plugin is loaded. It is provided with
342 the manager object command and the interpreter handle as its
343 only arguments. Any return value will be ignored.
344
345 Its purpose is give a user of the plugin management the ability
346 to define commands, packages, etc. a chosen plugin may need
347 while being loaded.
348
350 This document, and the package it describes, will undoubtedly contain
351 bugs and other problems. Please report such in the category pluginmgr
352 of the Tcllib SF Trackers [http://source‐
353 forge.net/tracker/?group_id=12883]. Please also report any ideas for
354 enhancements you may have for either package and/or documentation.
355
357 plugin management, plugin search
358
360 Copyright (c) 2005 Andreas Kupries <andreas_kupries@users.sourceforge.net>
361
362
363
364
365pluginmgr 0.2 pluginmgr(n)