Mercurial > hg > orthanc-book
annotate Sphinx/source/developers/creating-plugins.rst @ 985:ab706fe809ba
minimal quality message
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 28 Sep 2023 16:43:56 +0200 |
parents | a6bf749b3c04 |
children | 1316bc62b5d5 |
rev | line source |
---|---|
38 | 1 .. _creating-plugins: |
2 | |
24 | 3 Creating new plugins |
4 ==================== | |
5 | |
250 | 6 .. contents:: |
7 | |
8 Overview | |
9 -------- | |
10 | |
56 | 11 The recommended way of :ref:`contributing to the Orthanc code |
12 <contributing>` consists in extending it by creating new :ref:`plugins | |
13 <plugins>`. | |
24 | 14 |
794
e22c1284ea0e
plugins can be written in rust
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
763
diff
changeset
|
15 Native Orthanc plugins must use the `plugin SDK |
e22c1284ea0e
plugins can be written in rust
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
763
diff
changeset
|
16 <https://sdk.orthanc-server.com/>`__ whose interface is available as a |
e22c1284ea0e
plugins can be written in rust
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
763
diff
changeset
|
17 `C header |
963 | 18 <https://hg.orthanc-server.com/orthanc/file/Orthanc-1.12.1/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h>`__. |
794
e22c1284ea0e
plugins can be written in rust
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
763
diff
changeset
|
19 As a consequence, an Orthanc plugin will typically be written using C |
e22c1284ea0e
plugins can be written in rust
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
763
diff
changeset
|
20 or C++, although it is also possible to create native plugins using |
795
23271902921a
replace ABI by more adequate FFI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
794
diff
changeset
|
21 languages that feature compatibility with C headers and with `FFI of |
23271902921a
replace ABI by more adequate FFI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
794
diff
changeset
|
22 the C language |
23271902921a
replace ABI by more adequate FFI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
794
diff
changeset
|
23 <https://en.wikipedia.org/wiki/Foreign_function_interface>`__ (such as |
23271902921a
replace ABI by more adequate FFI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
794
diff
changeset
|
24 Rust or Objective-C). |
364
234de55ed125
usage of the python plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
360
diff
changeset
|
25 |
234de55ed125
usage of the python plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
360
diff
changeset
|
26 For developers who are more familiar with Python, it is also possible |
234de55ed125
usage of the python plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
360
diff
changeset
|
27 to create plugins using this simpler language. Check out the |
234de55ed125
usage of the python plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
360
diff
changeset
|
28 :ref:`dedicated Python plugin <python-plugin>`. |
234de55ed125
usage of the python plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
360
diff
changeset
|
29 |
794
e22c1284ea0e
plugins can be written in rust
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
763
diff
changeset
|
30 Because the C header providing the Orthanc SDK interface is licensed |
e22c1284ea0e
plugins can be written in rust
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
763
diff
changeset
|
31 using the GPLv3 license, any Orthanc plugin must be licensed either |
e22c1284ea0e
plugins can be written in rust
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
763
diff
changeset
|
32 under the `GPLv3 license |
e22c1284ea0e
plugins can be written in rust
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
763
diff
changeset
|
33 <http://www.gnu.org/licenses/quick-guide-gplv3.en.html>`__ that is |
e22c1284ea0e
plugins can be written in rust
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
763
diff
changeset
|
34 used by the :ref:`core of Orthanc <licensing>`, or under a more |
e22c1284ea0e
plugins can be written in rust
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
763
diff
changeset
|
35 restrictive license that is compatible with the GPL (typically the |
e22c1284ea0e
plugins can be written in rust
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
763
diff
changeset
|
36 AGPL). |
e22c1284ea0e
plugins can be written in rust
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
763
diff
changeset
|
37 |
364
234de55ed125
usage of the python plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
360
diff
changeset
|
38 Here are some resources about creating C/C++ plugins: |
300
22d567933381
tutorials about plugins by Marco Barnig
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
290
diff
changeset
|
39 |
22d567933381
tutorials about plugins by Marco Barnig
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
290
diff
changeset
|
40 * Sample code for plugins can be found `in the official Orthanc |
22d567933381
tutorials about plugins by Marco Barnig
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
290
diff
changeset
|
41 repository |
449 | 42 <https://hg.orthanc-server.com/orthanc/file/default/OrthancServer/Plugins/Samples/>`__ |
300
22d567933381
tutorials about plugins by Marco Barnig
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
290
diff
changeset
|
43 (in the ``Plugins/Samples`` folder). |
25 | 44 |
300
22d567933381
tutorials about plugins by Marco Barnig
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
290
diff
changeset
|
45 * A tutorial showing how to implement a basic WADO server is |
22d567933381
tutorials about plugins by Marco Barnig
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
290
diff
changeset
|
46 `available on CodeProject |
358
011b01ccf52d
fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
336
diff
changeset
|
47 <https://www.codeproject.com/Articles/797118/Implementing-a-WADO-Server-using-Orthanc>`__. |
300
22d567933381
tutorials about plugins by Marco Barnig
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
290
diff
changeset
|
48 |
22d567933381
tutorials about plugins by Marco Barnig
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
290
diff
changeset
|
49 * Marco Barnig provides `tutorial lessons to create Orthanc plugins |
358
011b01ccf52d
fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
336
diff
changeset
|
50 <https://github.com/mbarnig/RadioLogic/wiki#user-content-orthanc-plugin-development>`__ |
300
22d567933381
tutorials about plugins by Marco Barnig
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
290
diff
changeset
|
51 as part of his `RadioLogic project |
22d567933381
tutorials about plugins by Marco Barnig
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
290
diff
changeset
|
52 <https://github.com/mbarnig/RadioLogic/>`__. |
408 | 53 |
54 * Technical workshop about "`Writing an Orthanc C++ plugin | |
55 <https://bitbucket.org/bgo-osimis/orcon19-plugin-workshop/>`__" | |
56 presented by Benjamin Golinvaux at `OrthancCon 2019 | |
57 <https://www.orthanc-server.com/static.php?page=conference-schedule>`__. | |
300
22d567933381
tutorials about plugins by Marco Barnig
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
290
diff
changeset
|
58 |
25 | 59 We suggest developers to adopt the :ref:`coding style of the Orthanc |
60 core <coding-style>`, although this is of course not required. | |
61 | |
62 Do not hesitate to `contact us | |
358
011b01ccf52d
fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
336
diff
changeset
|
63 <https://www.orthanc-server.com/static.php?page=contact>`__ if you wish |
66 | 64 your plugin to be **indexed** in :ref:`the dedicated part of the |
65 Orthanc Book <plugins-contributed>`! | |
25 | 66 |
67 Structure of the plugins | |
68 ------------------------ | |
24 | 69 |
70 A plugin takes the form of a shared library (``.DLL`` under Windows, | |
67 | 71 ``.so`` under GNU/Linux, ``.dylib`` under Apple OS X...) that uses the |
795
23271902921a
replace ABI by more adequate FFI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
794
diff
changeset
|
72 `FFI of the C language |
25 | 73 <https://en.wikipedia.org/wiki/Application_binary_interface>`__ to |
74 declare 4 public functions/symbols: | |
24 | 75 |
76 * ``int32_t OrthancPluginInitialize(OrthancPluginContext* context)``. This | |
77 callback function is responsible for initializing the plugin. The | |
78 ``context`` argument gives access to the API of Orthanc. | |
79 * ``void OrthancPluginFinalize()``. This function is responsible | |
80 for finalizing the plugin, releasing all the allocated resources. | |
81 * ``const char* OrthancPluginGetName()``. This function must give a | |
82 name to the plugin. | |
83 * ``const char* OrthancPluginGetVersion()``. This function must | |
84 provide the version of the plugin. | |
85 | |
25 | 86 *Remark:* The size of the memory buffers that are exchanged between |
87 the Orthanc core and the plugins must be below 4GB. This is a | |
88 consequence of the fact that the Orthanc plugin SDK uses ``uint32_t`` | |
89 to encode the size of a memory buffer. We might extend the SDK in | |
250 | 90 the future to deal with buffers whose size is above 4GB. |
91 | |
92 Plugin SDK | |
93 ---------- | |
94 | |
95 Any plugin project should include the **official C header** file | |
96 that is part of the Orthanc source distribution: | |
97 | |
98 * `Plugins/Include/orthanc/OrthancCPlugin.h | |
963 | 99 <https://hg.orthanc-server.com/orthanc/file/Orthanc-1.12.1/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h>`__ |
250 | 100 |
358
011b01ccf52d
fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
336
diff
changeset
|
101 `Online documentation <https://sdk.orthanc-server.com/>`__ for this C |
250 | 102 header is available, as generated by `Doxygen |
103 <https://en.wikipedia.org/wiki/Doxygen>`__. | |
104 | |
105 **Convenience C++ wrappers** around the plain C API are available in | |
106 the Orthanc source distribution. The following three files can be used | |
107 in your projects, and only depend on `Boost | |
108 <https://www.boost.org/>`__ and `JsonCpp | |
109 <https://github.com/open-source-parsers/jsoncpp>`__ if macro | |
110 ``HAS_ORTHANC_EXCEPTION`` is set to ``0``: | |
111 | |
112 * `Plugins/Samples/Common/OrthanPluginCppWrapper.h | |
963 | 113 <https://hg.orthanc-server.com/orthanc/file/Orthanc-1.12.1/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.h>`__ |
250 | 114 * `Plugins/Samples/Common/OrthanPluginCppWrapper.cpp |
963 | 115 <https://hg.orthanc-server.com/orthanc/file/Orthanc-1.12.1/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp>`__ |
250 | 116 * `Plugins/Samples/Common/OrthanPluginException.h |
963 | 117 <https://hg.orthanc-server.com/orthanc/file/Orthanc-1.12.1/OrthancServer/Plugins/Samples/Common/OrthancPluginException.h>`__ |