annotate Plugins/Engine/PluginsManager.h @ 1581:357c4bb15701

Plugins have access to explicit error codes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Aug 2015 16:18:37 +0200
parents 6e7e5ed91c2d
children ffd23c0104af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
4 * Department, University Hospital of Liege, Belgium
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #pragma once
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "SharedLibrary.h"
898
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
36 #include "IPluginServiceProvider.h"
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
38 #include <map>
894
690aeb4cb899 REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 888
diff changeset
39 #include <list>
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 namespace Orthanc
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 class PluginsManager : boost::noncopyable
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 private:
1232
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
46 class Plugin
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
47 {
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
48 private:
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
49 SharedLibrary library_;
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
50 std::string version_;
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
51
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
52 public:
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
53 Plugin(const std::string& path) : library_(path)
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
54 {
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
55 }
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
56
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
57 SharedLibrary& GetLibrary()
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
58 {
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
59 return library_;
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
60 }
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
61
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
62 void SetVersion(const std::string& version)
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
63 {
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
64 version_ = version;
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
65 }
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
66
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
67 const std::string& GetVersion() const
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
68 {
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
69 return version_;
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
70 }
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
71 };
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
72
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
73 typedef std::map<std::string, Plugin*> Plugins;
898
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
74
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 OrthancPluginContext context_;
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 Plugins plugins_;
899
bb0a51561016 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 898
diff changeset
77 std::list<IPluginServiceProvider*> serviceProviders_;
898
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
78
1581
357c4bb15701 Plugins have access to explicit error codes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
79 static OrthancPluginErrorCode InvokeService(OrthancPluginContext* context,
357c4bb15701 Plugins have access to explicit error codes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
80 _OrthancPluginService service,
357c4bb15701 Plugins have access to explicit error codes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
81 const void* parameters);
894
690aeb4cb899 REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 888
diff changeset
82
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 public:
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 PluginsManager();
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 ~PluginsManager();
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 void RegisterPlugin(const std::string& path);
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
89
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
90 void ScanFolderForPlugins(const std::string& path,
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
91 bool isRecursive);
897
bafc9d592632 REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 896
diff changeset
92
899
bb0a51561016 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 898
diff changeset
93 void RegisterServiceProvider(IPluginServiceProvider& provider)
898
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
94 {
899
bb0a51561016 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 898
diff changeset
95 serviceProviders_.push_back(&provider);
897
bafc9d592632 REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 896
diff changeset
96 }
1232
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
97
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
98 void ListPlugins(std::list<std::string>& result) const;
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
99
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
100 bool HasPlugin(const std::string& name) const;
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
101
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
102 const std::string& GetPluginVersion(const std::string& name) const;
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 };
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }