Mercurial > hg > orthanc
comparison OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h @ 5138:d00db9fb48fb
added OrthancPluginCreateJob2() in the plugin SDK
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 19 Jan 2023 19:04:13 +0100 |
parents | 201a500dcff4 |
children | 0ea402b4d901 |
comparison
equal
deleted
inserted
replaced
5137:15109c3f0f7d | 5138:d00db9fb48fb |
---|---|
118 # define ORTHANC_PLUGINS_API | 118 # define ORTHANC_PLUGINS_API |
119 #endif | 119 #endif |
120 | 120 |
121 #define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 1 | 121 #define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 1 |
122 #define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 11 | 122 #define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 11 |
123 #define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 2 | 123 #define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 3 |
124 | 124 |
125 | 125 |
126 #if !defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) | 126 #if !defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) |
127 #define ORTHANC_PLUGINS_VERSION_IS_ABOVE(major, minor, revision) \ | 127 #define ORTHANC_PLUGINS_VERSION_IS_ABOVE(major, minor, revision) \ |
128 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER > major || \ | 128 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER > major || \ |
576 _OrthancPluginService_GetPeerUrl = 8005, | 576 _OrthancPluginService_GetPeerUrl = 8005, |
577 _OrthancPluginService_CallPeerApi = 8006, | 577 _OrthancPluginService_CallPeerApi = 8006, |
578 _OrthancPluginService_GetPeerUserProperty = 8007, | 578 _OrthancPluginService_GetPeerUserProperty = 8007, |
579 | 579 |
580 /* Primitives for handling jobs (new in 1.4.2) */ | 580 /* Primitives for handling jobs (new in 1.4.2) */ |
581 _OrthancPluginService_CreateJob = 9000, | 581 _OrthancPluginService_CreateJob = 9000, /* Deprecated since SDK 1.11.3 */ |
582 _OrthancPluginService_FreeJob = 9001, | 582 _OrthancPluginService_FreeJob = 9001, |
583 _OrthancPluginService_SubmitJob = 9002, | 583 _OrthancPluginService_SubmitJob = 9002, |
584 _OrthancPluginService_RegisterJobsUnserializer = 9003, | 584 _OrthancPluginService_RegisterJobsUnserializer = 9003, |
585 _OrthancPluginService_CreateJob2 = 9004, /* New in SDK 1.11.3 */ | |
585 | 586 |
586 _OrthancPluginService_INTERNAL = 0x7fffffff | 587 _OrthancPluginService_INTERNAL = 0x7fffffff |
587 } _OrthancPluginService; | 588 } _OrthancPluginService; |
588 | 589 |
589 | 590 |
1575 * tab of "Orthanc Explorer". | 1576 * tab of "Orthanc Explorer". |
1576 * | 1577 * |
1577 * @param job The job of interest. | 1578 * @param job The job of interest. |
1578 * @return The statistics, as a JSON object encoded as a string. | 1579 * @return The statistics, as a JSON object encoded as a string. |
1579 * @ingroup Toolbox | 1580 * @ingroup Toolbox |
1581 * @deprecated This signature should not be used anymore since Orthanc SDK 1.11.3. | |
1580 **/ | 1582 **/ |
1581 typedef const char* (*OrthancPluginJobGetContent) (void* job); | 1583 typedef const char* (*OrthancPluginJobGetContent) (void* job); |
1584 | |
1585 | |
1586 /** | |
1587 * @brief Callback to retrieve the content of one custom job. | |
1588 * | |
1589 * Signature of a callback function that returns human-readable | |
1590 * statistics about the job. This statistics must be formatted as a | |
1591 * JSON object. This information is notably displayed in the "Jobs" | |
1592 * tab of "Orthanc Explorer". | |
1593 * | |
1594 * @param target The target memory buffer where to store the JSON string. | |
1595 * This buffer must be allocated using OrthancPluginCreateMemoryBuffer() | |
1596 * and will be freed by the Orthanc core. | |
1597 * @param job The job of interest. | |
1598 * @return 0 if success, other value if error. | |
1599 * @ingroup Toolbox | |
1600 **/ | |
1601 typedef OrthancPluginErrorCode (*OrthancPluginJobGetContent2) (OrthancPluginMemoryBuffer* target, | |
1602 void* job); | |
1582 | 1603 |
1583 | 1604 |
1584 /** | 1605 /** |
1585 * @brief Callback to serialize one custom job. | 1606 * @brief Callback to serialize one custom job. |
1586 * | 1607 * |
1593 * | 1614 * |
1594 * @param job The job of interest. | 1615 * @param job The job of interest. |
1595 * @return The serialized job, as a JSON object encoded as a string. | 1616 * @return The serialized job, as a JSON object encoded as a string. |
1596 * @see OrthancPluginRegisterJobsUnserializer() | 1617 * @see OrthancPluginRegisterJobsUnserializer() |
1597 * @ingroup Toolbox | 1618 * @ingroup Toolbox |
1619 * @deprecated This signature should not be used anymore since Orthanc SDK 1.11.3. | |
1598 **/ | 1620 **/ |
1599 typedef const char* (*OrthancPluginJobGetSerialized) (void* job); | 1621 typedef const char* (*OrthancPluginJobGetSerialized) (void* job); |
1622 | |
1623 | |
1624 /** | |
1625 * @brief Callback to serialize one custom job. | |
1626 * | |
1627 * Signature of a callback function that returns a serialized | |
1628 * version of the job, formatted as a JSON object. This | |
1629 * serialization is stored in the Orthanc database, and is used to | |
1630 * reload the job on the restart of Orthanc. The "unserialization" | |
1631 * callback (with OrthancPluginJobsUnserializer signature) will | |
1632 * receive this serialized object. | |
1633 * | |
1634 * @param target The target memory buffer where to store the JSON string. | |
1635 * This buffer must be allocated using OrthancPluginCreateMemoryBuffer() | |
1636 * and will be freed by the Orthanc core. | |
1637 * @param job The job of interest. | |
1638 * @return 1 if the serialization has succeeded, 0 if serialization is | |
1639 * not implemented for this type of job, or -1 in case of error. | |
1640 **/ | |
1641 typedef int32_t (*OrthancPluginJobGetSerialized2) (OrthancPluginMemoryBuffer* target, | |
1642 void* job); | |
1600 | 1643 |
1601 | 1644 |
1602 /** | 1645 /** |
1603 * @brief Callback to execute one step of a custom job. | 1646 * @brief Callback to execute one step of a custom job. |
1604 * | 1647 * |
6690 * @param stop The callback that is invoked once the job leaves the "running" state. | 6733 * @param stop The callback that is invoked once the job leaves the "running" state. |
6691 * @param reset The callback that is invoked if a stopped job is started again. | 6734 * @param reset The callback that is invoked if a stopped job is started again. |
6692 * @return The newly allocated job. It must be freed with OrthancPluginFreeJob(), | 6735 * @return The newly allocated job. It must be freed with OrthancPluginFreeJob(), |
6693 * as long as it is not submitted with OrthancPluginSubmitJob(). | 6736 * as long as it is not submitted with OrthancPluginSubmitJob(). |
6694 * @ingroup Toolbox | 6737 * @ingroup Toolbox |
6738 * @deprecated This signature should not be used anymore since Orthanc SDK 1.11.3. | |
6695 **/ | 6739 **/ |
6696 ORTHANC_PLUGIN_INLINE OrthancPluginJob *OrthancPluginCreateJob( | 6740 ORTHANC_PLUGIN_INLINE OrthancPluginJob *OrthancPluginCreateJob( |
6697 OrthancPluginContext *context, | 6741 OrthancPluginContext *context, |
6698 void *job, | 6742 void *job, |
6699 OrthancPluginJobFinalize finalize, | 6743 OrthancPluginJobFinalize finalize, |
6720 params.step = step; | 6764 params.step = step; |
6721 params.stop = stop; | 6765 params.stop = stop; |
6722 params.reset = reset; | 6766 params.reset = reset; |
6723 | 6767 |
6724 if (context->InvokeService(context, _OrthancPluginService_CreateJob, ¶ms) != OrthancPluginErrorCode_Success || | 6768 if (context->InvokeService(context, _OrthancPluginService_CreateJob, ¶ms) != OrthancPluginErrorCode_Success || |
6769 target == NULL) | |
6770 { | |
6771 /* Error */ | |
6772 return NULL; | |
6773 } | |
6774 else | |
6775 { | |
6776 return target; | |
6777 } | |
6778 } | |
6779 | |
6780 | |
6781 typedef struct | |
6782 { | |
6783 OrthancPluginJob** target; | |
6784 void *job; | |
6785 OrthancPluginJobFinalize finalize; | |
6786 const char *type; | |
6787 OrthancPluginJobGetProgress getProgress; | |
6788 OrthancPluginJobGetContent2 getContent; | |
6789 OrthancPluginJobGetSerialized2 getSerialized; | |
6790 OrthancPluginJobStep step; | |
6791 OrthancPluginJobStop stop; | |
6792 OrthancPluginJobReset reset; | |
6793 } _OrthancPluginCreateJob2; | |
6794 | |
6795 /** | |
6796 * @brief Create a custom job. | |
6797 * | |
6798 * This function creates a custom job to be run by the jobs engine | |
6799 * of Orthanc. | |
6800 * | |
6801 * Orthanc starts one dedicated thread per custom job that is | |
6802 * running. It is guaranteed that all the callbacks will only be | |
6803 * called from this single dedicated thread, in mutual exclusion: As | |
6804 * a consequence, it is *not* mandatory to protect the various | |
6805 * callbacks by mutexes. | |
6806 * | |
6807 * The custom job can nonetheless launch its own processing threads | |
6808 * on the first call to the "step()" callback, and stop them once | |
6809 * the "stop()" callback is called. | |
6810 * | |
6811 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6812 * @param job The job to be executed. | |
6813 * @param finalize The finalization callback. | |
6814 * @param type The type of the job, provided to the job unserializer. | |
6815 * See OrthancPluginRegisterJobsUnserializer(). | |
6816 * @param getProgress The progress callback. | |
6817 * @param getContent The content callback. | |
6818 * @param getSerialized The serialization callback. | |
6819 * @param step The callback to execute the individual steps of the job. | |
6820 * @param stop The callback that is invoked once the job leaves the "running" state. | |
6821 * @param reset The callback that is invoked if a stopped job is started again. | |
6822 * @return The newly allocated job. It must be freed with OrthancPluginFreeJob(), | |
6823 * as long as it is not submitted with OrthancPluginSubmitJob(). | |
6824 * @ingroup Toolbox | |
6825 **/ | |
6826 ORTHANC_PLUGIN_INLINE OrthancPluginJob *OrthancPluginCreateJob2( | |
6827 OrthancPluginContext *context, | |
6828 void *job, | |
6829 OrthancPluginJobFinalize finalize, | |
6830 const char *type, | |
6831 OrthancPluginJobGetProgress getProgress, | |
6832 OrthancPluginJobGetContent2 getContent, | |
6833 OrthancPluginJobGetSerialized2 getSerialized, | |
6834 OrthancPluginJobStep step, | |
6835 OrthancPluginJobStop stop, | |
6836 OrthancPluginJobReset reset) | |
6837 { | |
6838 OrthancPluginJob* target = NULL; | |
6839 | |
6840 _OrthancPluginCreateJob2 params; | |
6841 memset(¶ms, 0, sizeof(params)); | |
6842 | |
6843 params.target = ⌖ | |
6844 params.job = job; | |
6845 params.finalize = finalize; | |
6846 params.type = type; | |
6847 params.getProgress = getProgress; | |
6848 params.getContent = getContent; | |
6849 params.getSerialized = getSerialized; | |
6850 params.step = step; | |
6851 params.stop = stop; | |
6852 params.reset = reset; | |
6853 | |
6854 if (context->InvokeService(context, _OrthancPluginService_CreateJob2, ¶ms) != OrthancPluginErrorCode_Success || | |
6725 target == NULL) | 6855 target == NULL) |
6726 { | 6856 { |
6727 /* Error */ | 6857 /* Error */ |
6728 return NULL; | 6858 return NULL; |
6729 } | 6859 } |