annotate Sphinx/source/developers/creating-plugins.rst @ 660:a6e371768a70

dicom-as-json
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 29 Apr 2021 12:41:31 +0200
parents b3e75cef601d
children 17c1ff4e6ae4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 25
diff changeset
1 .. _creating-plugins:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 25
diff changeset
2
24
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 Creating new plugins
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 ====================
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5
250
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
6 .. contents::
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
8 Overview
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
9 --------
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
10
56
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
11 The recommended way of :ref:`contributing to the Orthanc code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
12 <contributing>` consists in extending it by creating new :ref:`plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
13 <plugins>`.
24
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 Orthanc plugins must use the `plugin SDK
358
011b01ccf52d fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
16 <https://sdk.orthanc-server.com/>`__ and must be written in C or
300
22d567933381 tutorials about plugins by Marco Barnig
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 290
diff changeset
17 C++. They must also fullfil the terms of the `GPLv3 license
24
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 <http://www.gnu.org/licenses/quick-guide-gplv3.en.html>`__ that is
364
234de55ed125 usage of the python plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 360
diff changeset
19 used by the core of Orthanc.
234de55ed125 usage of the python plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 360
diff changeset
20
234de55ed125 usage of the python plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 360
diff changeset
21 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
22 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
23 :ref:`dedicated Python plugin <python-plugin>`.
234de55ed125 usage of the python plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 360
diff changeset
24
234de55ed125 usage of the python plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 360
diff changeset
25 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
26
22d567933381 tutorials about plugins by Marco Barnig
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 290
diff changeset
27 * 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
28 repository
449
2922fb1bd65e fix links
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 441
diff changeset
29 <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
30 (in the ``Plugins/Samples`` folder).
25
669ea65ba7fb fix links
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
31
300
22d567933381 tutorials about plugins by Marco Barnig
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 290
diff changeset
32 * 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
33 `available on CodeProject
358
011b01ccf52d fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
34 <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
35
22d567933381 tutorials about plugins by Marco Barnig
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 290
diff changeset
36 * Marco Barnig provides `tutorial lessons to create Orthanc plugins
358
011b01ccf52d fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
37 <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
38 as part of his `RadioLogic project
22d567933381 tutorials about plugins by Marco Barnig
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 290
diff changeset
39 <https://github.com/mbarnig/RadioLogic/>`__.
408
f97e9c9bb173 bgo tutorial
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 392
diff changeset
40
f97e9c9bb173 bgo tutorial
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 392
diff changeset
41 * Technical workshop about "`Writing an Orthanc C++ plugin
f97e9c9bb173 bgo tutorial
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 392
diff changeset
42 <https://bitbucket.org/bgo-osimis/orcon19-plugin-workshop/>`__"
f97e9c9bb173 bgo tutorial
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 392
diff changeset
43 presented by Benjamin Golinvaux at `OrthancCon 2019
f97e9c9bb173 bgo tutorial
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 392
diff changeset
44 <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
45
25
669ea65ba7fb fix links
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
46 We suggest developers to adopt the :ref:`coding style of the Orthanc
669ea65ba7fb fix links
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
47 core <coding-style>`, although this is of course not required.
669ea65ba7fb fix links
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
48
669ea65ba7fb fix links
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
49 Do not hesitate to `contact us
358
011b01ccf52d fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
50 <https://www.orthanc-server.com/static.php?page=contact>`__ if you wish
66
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 61
diff changeset
51 your plugin to be **indexed** in :ref:`the dedicated part of the
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 61
diff changeset
52 Orthanc Book <plugins-contributed>`!
25
669ea65ba7fb fix links
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
53
669ea65ba7fb fix links
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
54 Structure of the plugins
669ea65ba7fb fix links
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
55 ------------------------
24
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 A plugin takes the form of a shared library (``.DLL`` under Windows,
67
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 66
diff changeset
58 ``.so`` under GNU/Linux, ``.dylib`` under Apple OS X...) that uses the
42
a52f1dc48ebc GNU/Linux
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 38
diff changeset
59 `ABI of the C language
25
669ea65ba7fb fix links
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
60 <https://en.wikipedia.org/wiki/Application_binary_interface>`__ to
669ea65ba7fb fix links
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
61 declare 4 public functions/symbols:
24
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 * ``int32_t OrthancPluginInitialize(OrthancPluginContext* context)``. This
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 callback function is responsible for initializing the plugin. The
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 ``context`` argument gives access to the API of Orthanc.
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 * ``void OrthancPluginFinalize()``. This function is responsible
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 for finalizing the plugin, releasing all the allocated resources.
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 * ``const char* OrthancPluginGetName()``. This function must give a
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 name to the plugin.
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 * ``const char* OrthancPluginGetVersion()``. This function must
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 provide the version of the plugin.
25fa874803ab plugins inside book
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
25
669ea65ba7fb fix links
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
73 *Remark:* The size of the memory buffers that are exchanged between
669ea65ba7fb fix links
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
74 the Orthanc core and the plugins must be below 4GB. This is a
669ea65ba7fb fix links
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
75 consequence of the fact that the Orthanc plugin SDK uses ``uint32_t``
669ea65ba7fb fix links
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
76 to encode the size of a memory buffer. We might extend the SDK in
250
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
77 the future to deal with buffers whose size is above 4GB.
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
78
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
79 Plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
80 ----------
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
81
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
82 Any plugin project should include the **official C header** file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
83 that is part of the Orthanc source distribution:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
84
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
85 * `Plugins/Include/orthanc/OrthancCPlugin.h
638
b3e75cef601d Orthanc 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 618
diff changeset
86 <https://hg.orthanc-server.com/orthanc/file/Orthanc-1.9.2/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h>`__
250
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
87
358
011b01ccf52d fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
88 `Online documentation <https://sdk.orthanc-server.com/>`__ for this C
250
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
89 header is available, as generated by `Doxygen
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
90 <https://en.wikipedia.org/wiki/Doxygen>`__.
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
91
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
92 **Convenience C++ wrappers** around the plain C API are available in
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
93 the Orthanc source distribution. The following three files can be used
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
94 in your projects, and only depend on `Boost
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
95 <https://www.boost.org/>`__ and `JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
96 <https://github.com/open-source-parsers/jsoncpp>`__ if macro
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
97 ``HAS_ORTHANC_EXCEPTION`` is set to ``0``:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
98
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
99 * `Plugins/Samples/Common/OrthanPluginCppWrapper.h
638
b3e75cef601d Orthanc 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 618
diff changeset
100 <https://hg.orthanc-server.com/orthanc/file/Orthanc-1.9.2/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.h>`__
250
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
101 * `Plugins/Samples/Common/OrthanPluginCppWrapper.cpp
638
b3e75cef601d Orthanc 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 618
diff changeset
102 <https://hg.orthanc-server.com/orthanc/file/Orthanc-1.9.2/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp>`__
250
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
103 * `Plugins/Samples/Common/OrthanPluginException.h
638
b3e75cef601d Orthanc 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 618
diff changeset
104 <https://hg.orthanc-server.com/orthanc/file/Orthanc-1.9.2/OrthancServer/Plugins/Samples/Common/OrthancPluginException.h>`__