1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651
|
/**
* \mainpage
*
* This C/C++ SDK allows external developers to create plugins that
* can be loaded into Orthanc to extend its functionality. Each
* Orthanc plugin must expose 4 public functions with the following
* signatures:
*
* -# <tt>int32_t OrthancPluginInitialize(const OrthancPluginContext* context)</tt>:
* This function is invoked by Orthanc when it loads the plugin on startup.
* The plugin must:
* - Check its compatibility with the Orthanc version using
* ::OrthancPluginCheckVersion().
* - Store the context pointer so that it can use the plugin
* services of Orthanc.
* - Register all its REST callbacks using ::OrthancPluginRegisterRestCallback().
* - Register all its callbacks for received instances using ::OrthancPluginRegisterOnStoredInstanceCallback().
* - Possibly register a custom storage area using ::OrthancPluginRegisterStorageArea().
* -# <tt>void OrthancPluginFinalize()</tt>:
* This function is invoked by Orthanc during its shutdown. The plugin
* must free all its memory.
* -# <tt>const char* OrthancPluginGetName()</tt>:
* The plugin must return a short string to identify itself.
* -# <tt>const char* OrthancPluginGetVersion()</tt>:
* The plugin must return a string containing its version number.
*
* The name and the version of a plugin is only used to prevent it
* from being loaded twice.
*
*
**/
/**
* @defgroup CInterface C Interface
* @brief The C interface to create Orthanc plugins.
*
* These functions must be used to create C plugins for Orthanc.
**/
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
* Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* In addition, as a special exception, the copyright holders of this
* program give permission to link the code of its release with the
* OpenSSL project's "OpenSSL" library (or with modified versions of it
* that use the same license as the "OpenSSL" library), and distribute
* the linked executables. You must obey the GNU General Public License
* in all respects for all of the code used other than "OpenSSL". If you
* modify file(s) with this exception, you may extend this exception to
* your version of the file(s), but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source files
* in the program, then also delete it here.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
#pragma once
#include <stdio.h>
#include <string.h>
#ifdef WIN32
#define ORTHANC_PLUGINS_API __declspec(dllexport)
#else
#define ORTHANC_PLUGINS_API
#endif
#define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 0
#define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 8
#define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 3
/********************************************************************
** Check that function inlining is properly supported. The use of
** inlining is required, to avoid the duplication of object code
** between two compilation modules that would use the Orthanc Plugin
** API.
********************************************************************/
/* If the auto-detection of the "inline" keyword below does not work
automatically and that your compiler is known to properly support
inlining, uncomment the following #define and adapt the definition
of "static inline". */
/* #define ORTHANC_PLUGIN_INLINE static inline */
#ifndef ORTHANC_PLUGIN_INLINE
# if __STDC_VERSION__ >= 199901L
/* This is C99 or above: http://predef.sourceforge.net/prestd.html */
# define ORTHANC_PLUGIN_INLINE static inline
# elif defined(__cplusplus)
/* This is C++ */
# define ORTHANC_PLUGIN_INLINE static inline
# elif defined(__GNUC__)
/* This is GCC running in C89 mode */
# define ORTHANC_PLUGIN_INLINE static __inline
# elif defined(_MSC_VER)
/* This is Visual Studio running in C89 mode */
# define ORTHANC_PLUGIN_INLINE static __inline
# else
# error Your compiler is not known to support the "inline" keyword
# endif
#endif
/********************************************************************
** Inclusion of standard libraries.
********************************************************************/
#ifdef _MSC_VER
#include "../../Resources/ThirdParty/VisualStudio/stdint.h"
#else
#include <stdint.h>
#endif
#include <stdlib.h>
/********************************************************************
** Definition of the Orthanc Plugin API.
********************************************************************/
/** @{ */
#ifdef __cplusplus
extern "C"
{
#endif
/**
* The various HTTP methods for a REST call.
**/
typedef enum
{
OrthancPluginHttpMethod_Get = 1, /*!< GET request */
OrthancPluginHttpMethod_Post = 2, /*!< POST request */
OrthancPluginHttpMethod_Put = 3, /*!< PUT request */
OrthancPluginHttpMethod_Delete = 4 /*!< DELETE request */
} OrthancPluginHttpMethod;
/**
* @brief The parameters of a REST request.
**/
typedef struct
{
/**
* @brief The HTTP method.
**/
OrthancPluginHttpMethod method;
/**
* @brief The number of groups of the regular expression.
**/
uint32_t groupsCount;
/**
* @brief The matched values for the groups of the regular expression.
**/
const char* const* groups;
/**
* @brief For a GET request, the number of GET parameters.
**/
uint32_t getCount;
/**
* @brief For a GET request, the keys of the GET parameters.
**/
const char* const* getKeys;
/**
* @brief For a GET request, the values of the GET parameters.
**/
const char* const* getValues;
/**
* @brief For a PUT or POST request, the content of the body.
**/
const char* body;
/**
* @brief For a PUT or POST request, the number of bytes of the body.
**/
uint32_t bodySize;
/* --------------------------------------------------
New in version 0.8.1
-------------------------------------------------- */
/**
* @brief The number of HTTP headers.
**/
uint32_t headersCount;
/**
* @brief The keys of the HTTP headers (always converted to low-case).
**/
const char* const* headersKeys;
/**
* @brief The values of the HTTP headers.
**/
const char* const* headersValues;
} OrthancPluginHttpRequest;
typedef enum
{
/* Generic services */
_OrthancPluginService_LogInfo = 1,
_OrthancPluginService_LogWarning = 2,
_OrthancPluginService_LogError = 3,
_OrthancPluginService_GetOrthancPath = 4,
_OrthancPluginService_GetOrthancDirectory = 5,
_OrthancPluginService_GetConfigurationPath = 6,
/* Registration of callbacks */
_OrthancPluginService_RegisterRestCallback = 1000,
_OrthancPluginService_RegisterOnStoredInstanceCallback = 1001,
_OrthancPluginService_RegisterStorageArea = 1002,
/* Sending answers to REST calls */
_OrthancPluginService_AnswerBuffer = 2000,
_OrthancPluginService_CompressAndAnswerPngImage = 2001,
_OrthancPluginService_Redirect = 2002,
_OrthancPluginService_SendHttpStatusCode = 2003,
_OrthancPluginService_SendUnauthorized = 2004,
_OrthancPluginService_SendMethodNotAllowed = 2005,
_OrthancPluginService_SetCookie = 2006,
_OrthancPluginService_SetHttpHeader = 2007,
/* Access to the Orthanc database and API */
_OrthancPluginService_GetDicomForInstance = 3000,
_OrthancPluginService_RestApiGet = 3001,
_OrthancPluginService_RestApiPost = 3002,
_OrthancPluginService_RestApiDelete = 3003,
_OrthancPluginService_RestApiPut = 3004,
_OrthancPluginService_LookupPatient = 3005,
_OrthancPluginService_LookupStudy = 3006,
_OrthancPluginService_LookupSeries = 3007,
_OrthancPluginService_LookupInstance = 3008,
_OrthancPluginService_LookupStudyWithAccessionNumber = 3009,
/* Access to DICOM instances */
_OrthancPluginService_GetInstanceRemoteAet = 4000,
_OrthancPluginService_GetInstanceSize = 4001,
_OrthancPluginService_GetInstanceData = 4002,
_OrthancPluginService_GetInstanceJson = 4003,
_OrthancPluginService_GetInstanceSimplifiedJson = 4004,
_OrthancPluginService_HasInstanceMetadata = 4005,
_OrthancPluginService_GetInstanceMetadata = 4006
} _OrthancPluginService;
/**
* The memory layout of the pixels of an image.
**/
typedef enum
{
/**
* @brief Graylevel 8bpp image.
*
* The image is graylevel. Each pixel is unsigned and stored in
* one byte.
**/
OrthancPluginPixelFormat_Grayscale8 = 1,
/**
* @brief Graylevel, unsigned 16bpp image.
*
* The image is graylevel. Each pixel is unsigned and stored in
* two bytes.
**/
OrthancPluginPixelFormat_Grayscale16 = 2,
/**
* @brief Graylevel, signed 16bpp image.
*
* The image is graylevel. Each pixel is signed and stored in two
* bytes.
**/
OrthancPluginPixelFormat_SignedGrayscale16 = 3,
/**
* @brief Color image in RGB24 format.
*
* This format describes a color image. The pixels are stored in 3
* consecutive bytes. The memory layout is RGB.
**/
OrthancPluginPixelFormat_RGB24 = 4,
/**
* @brief Color image in RGBA32 format.
*
* This format describes a color image. The pixels are stored in 4
* consecutive bytes. The memory layout is RGBA.
**/
OrthancPluginPixelFormat_RGBA32 = 5
} OrthancPluginPixelFormat;
/**
* The content types that are supported by Orthanc plugins.
**/
typedef enum
{
OrthancPluginContentType_Unknown = 0, /*!< Unknown content type */
OrthancPluginContentType_Dicom = 1, /*!< DICOM */
OrthancPluginContentType_DicomAsJson = 2 /*!< JSON summary of a DICOM file */
} OrthancPluginContentType;
/**
* @brief A memory buffer allocated by the core system of Orthanc.
*
* A memory buffer allocated by the core system of Orthanc. When the
* content of the buffer is not useful anymore, it must be free by a
* call to ::OrthancPluginFreeMemoryBuffer().
**/
typedef struct
{
/**
* @brief The content of the buffer.
**/
void* data;
/**
* @brief The number of bytes in the buffer.
**/
uint32_t size;
} OrthancPluginMemoryBuffer;
/**
* @brief Opaque structure that represents the HTTP connection to the client application.
**/
typedef struct _OrthancPluginRestOutput_t OrthancPluginRestOutput;
/**
* @brief Opaque structure that represents a DICOM instance received by Orthanc.
**/
typedef struct _OrthancPluginDicomInstance_t OrthancPluginDicomInstance;
/**
* @brief Signature of a callback function that answers to a REST request.
**/
typedef int32_t (*OrthancPluginRestCallback) (
OrthancPluginRestOutput* output,
const char* url,
const OrthancPluginHttpRequest* request);
/**
* @brief Signature of a callback function that is triggered when Orthanc receives a DICOM instance.
**/
typedef int32_t (*OrthancPluginOnStoredInstanceCallback) (
OrthancPluginDicomInstance* instance,
const char* instanceId);
/**
* @brief Signature of a function to free dynamic memory.
**/
typedef void (*OrthancPluginFree) (void* buffer);
/**
* @brief Callback for writing to the storage area.
*
* Signature of a callback function that is triggered when Orthanc writes a file to the storage area.
*
* @param uuid The UUID of the file.
* @param content The content of the file.
* @param size The size of the file.
* @param type The content type corresponding to this file.
* @return 0 if success, other value if error.
**/
typedef int32_t (*OrthancPluginStorageCreate) (
const char* uuid,
const void* content,
int64_t size,
OrthancPluginContentType type);
/**
* @brief Callback for reading from the storage area.
*
* Signature of a callback function that is triggered when Orthanc reads a file from the storage area.
*
* @param content The content of the file (output).
* @param size The size of the file (output).
* @param uuid The UUID of the file of interest.
* @param type The content type corresponding to this file.
* @return 0 if success, other value if error.
**/
typedef int32_t (*OrthancPluginStorageRead) (
void** content,
int64_t* size,
const char* uuid,
OrthancPluginContentType type);
/**
* @brief Callback for removing a file from the storage area.
*
* Signature of a callback function that is triggered when Orthanc deletes a file from the storage area.
*
* @param uuid The UUID of the file to be removed.
* @param type The content type corresponding to this file.
* @return 0 if success, other value if error.
**/
typedef int32_t (*OrthancPluginStorageRemove) (
const char* uuid,
OrthancPluginContentType type);
/**
* @brief Opaque structure that contains information about the Orthanc core.
**/
typedef struct _OrthancPluginContext_t
{
void* pluginsManager;
const char* orthancVersion;
OrthancPluginFree Free;
int32_t (*InvokeService) (struct _OrthancPluginContext_t* context,
_OrthancPluginService service,
const void* params);
} OrthancPluginContext;
/**
* @brief Free a string.
*
* Free a string that was allocated by the core system of Orthanc.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param str The string to be freed.
**/
ORTHANC_PLUGIN_INLINE void OrthancPluginFreeString(
OrthancPluginContext* context,
char* str)
{
if (str != NULL)
{
context->Free(str);
}
}
/**
* @brief Check the compatibility of the plugin wrt. the version of its hosting Orthanc.
*
* This function checks whether the version of this C header is
* compatible with the current version of Orthanc. The result of
* this function should always be checked in the
* OrthancPluginInitialize() entry point of the plugin.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @return 1 if and only if the versions are compatible. If the
* result is 0, the initialization of the plugin should fail.
**/
ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersion(
OrthancPluginContext* context)
{
int major, minor, revision;
/* Assume compatibility with the mainline */
if (!strcmp(context->orthancVersion, "mainline"))
{
return 1;
}
/* Parse the version of the Orthanc core */
if (
#ifdef _MSC_VER
sscanf_s
#else
sscanf
#endif
(context->orthancVersion, "%d.%d.%d", &major, &minor, &revision) != 3)
{
return 0;
}
/* Check the major number of the version */
if (major > ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER)
{
return 1;
}
if (major < ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER)
{
return 0;
}
/* Check the minor number of the version */
if (minor > ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER)
{
return 1;
}
if (minor < ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER)
{
return 0;
}
/* Check the revision number of the version */
if (revision >= ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER)
{
return 1;
}
else
{
return 0;
}
}
/**
* @brief Free a memory buffer.
*
* Free a memory buffer that was allocated by the core system of Orthanc.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param buffer The memory buffer to release.
**/
ORTHANC_PLUGIN_INLINE void OrthancPluginFreeMemoryBuffer(
OrthancPluginContext* context,
OrthancPluginMemoryBuffer* buffer)
{
context->Free(buffer->data);
}
/**
* @brief Log an error.
*
* Log an error message using the Orthanc logging system.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param message The message to be logged.
**/
ORTHANC_PLUGIN_INLINE void OrthancPluginLogError(
OrthancPluginContext* context,
const char* message)
{
context->InvokeService(context, _OrthancPluginService_LogError, message);
}
/**
* @brief Log a warning.
*
* Log a warning message using the Orthanc logging system.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param message The message to be logged.
**/
ORTHANC_PLUGIN_INLINE void OrthancPluginLogWarning(
OrthancPluginContext* context,
const char* message)
{
context->InvokeService(context, _OrthancPluginService_LogWarning, message);
}
/**
* @brief Log an information.
*
* Log an information message using the Orthanc logging system.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param message The message to be logged.
**/
ORTHANC_PLUGIN_INLINE void OrthancPluginLogInfo(
OrthancPluginContext* context,
const char* message)
{
context->InvokeService(context, _OrthancPluginService_LogInfo, message);
}
typedef struct
{
const char* pathRegularExpression;
OrthancPluginRestCallback callback;
} _OrthancPluginRestCallback;
/**
* @brief Register a REST callback.
*
* This function registers a REST callback against a regular
* expression for a URI. This function must be called during the
* initialization of the plugin, i.e. inside the
* OrthancPluginInitialize() public function.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param pathRegularExpression Regular expression for the URI. May contain groups.
* @param callback The callback function to handle the REST call.
**/
ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallback(
OrthancPluginContext* context,
const char* pathRegularExpression,
OrthancPluginRestCallback callback)
{
_OrthancPluginRestCallback params;
params.pathRegularExpression = pathRegularExpression;
params.callback = callback;
context->InvokeService(context, _OrthancPluginService_RegisterRestCallback, ¶ms);
}
typedef struct
{
OrthancPluginOnStoredInstanceCallback callback;
} _OrthancPluginOnStoredInstanceCallback;
/**
* @brief Register a callback for received instances.
*
* This function registers a callback function that is called
* whenever a new DICOM instance is stored into the Orthanc core.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param callback The callback function.
**/
ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnStoredInstanceCallback(
OrthancPluginContext* context,
OrthancPluginOnStoredInstanceCallback callback)
{
_OrthancPluginOnStoredInstanceCallback params;
params.callback = callback;
context->InvokeService(context, _OrthancPluginService_RegisterOnStoredInstanceCallback, ¶ms);
}
typedef struct
{
OrthancPluginRestOutput* output;
const char* answer;
uint32_t answerSize;
const char* mimeType;
} _OrthancPluginAnswerBuffer;
/**
* @brief Answer to a REST request.
*
* This function answers to a REST request with the content of a memory buffer.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param output The HTTP connection to the client application.
* @param answer Pointer to the memory buffer containing the answer.
* @param answerSize Number of bytes of the answer.
* @param mimeType The MIME type of the answer.
**/
ORTHANC_PLUGIN_INLINE void OrthancPluginAnswerBuffer(
OrthancPluginContext* context,
OrthancPluginRestOutput* output,
const char* answer,
uint32_t answerSize,
const char* mimeType)
{
_OrthancPluginAnswerBuffer params;
params.output = output;
params.answer = answer;
params.answerSize = answerSize;
params.mimeType = mimeType;
context->InvokeService(context, _OrthancPluginService_AnswerBuffer, ¶ms);
}
typedef struct
{
OrthancPluginRestOutput* output;
OrthancPluginPixelFormat format;
uint32_t width;
uint32_t height;
uint32_t pitch;
const void* buffer;
} _OrthancPluginCompressAndAnswerPngImage;
/**
* @brief Answer to a REST request with a PNG image.
*
* This function answers to a REST request with a PNG image. The
* parameters of this function describe a memory buffer that
* contains an uncompressed image. The image will be automatically compressed
* as a PNG image by the core system of Orthanc.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param output The HTTP connection to the client application.
* @param format The memory layout of the uncompressed image.
* @param width The width of the image.
* @param height The height of the image.
* @param pitch The pitch of the image (i.e. the number of bytes
* between 2 successive lines of the image in the memory buffer.
* @param buffer The memory buffer containing the uncompressed image.
**/
ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerPngImage(
OrthancPluginContext* context,
OrthancPluginRestOutput* output,
OrthancPluginPixelFormat format,
uint32_t width,
uint32_t height,
uint32_t pitch,
const void* buffer)
{
_OrthancPluginCompressAndAnswerPngImage params;
params.output = output;
params.format = format;
params.width = width;
params.height = height;
params.pitch = pitch;
params.buffer = buffer;
context->InvokeService(context, _OrthancPluginService_CompressAndAnswerPngImage, ¶ms);
}
typedef struct
{
OrthancPluginMemoryBuffer* target;
const char* instanceId;
} _OrthancPluginGetDicomForInstance;
/**
* @brief Retrieve a DICOM instance using its Orthanc identifier.
*
* Retrieve a DICOM instance using its Orthanc identifier. The DICOM
* file is stored into a newly allocated memory buffer.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param target The target memory buffer.
* @param instanceId The Orthanc identifier of the DICOM instance of interest.
* @return 0 if success, other value if error.
**/
ORTHANC_PLUGIN_INLINE int OrthancPluginGetDicomForInstance(
OrthancPluginContext* context,
OrthancPluginMemoryBuffer* target,
const char* instanceId)
{
_OrthancPluginGetDicomForInstance params;
params.target = target;
params.instanceId = instanceId;
return context->InvokeService(context, _OrthancPluginService_GetDicomForInstance, ¶ms);
}
typedef struct
{
OrthancPluginMemoryBuffer* target;
const char* uri;
} _OrthancPluginRestApiGet;
/**
* @brief Make a GET call to the built-in Orthanc REST API.
*
* Make a GET call to the built-in Orthanc REST API. The result to
* the query is stored into a newly allocated memory buffer.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param target The target memory buffer.
* @param uri The URI in the built-in Orthanc API.
* @return 0 if success, other value if error.
**/
ORTHANC_PLUGIN_INLINE int OrthancPluginRestApiGet(
OrthancPluginContext* context,
OrthancPluginMemoryBuffer* target,
const char* uri)
{
_OrthancPluginRestApiGet params;
params.target = target;
params.uri = uri;
return context->InvokeService(context, _OrthancPluginService_RestApiGet, ¶ms);
}
typedef struct
{
OrthancPluginMemoryBuffer* target;
const char* uri;
const char* body;
uint32_t bodySize;
} _OrthancPluginRestApiPostPut;
/**
* @brief Make a POST call to the built-in Orthanc REST API.
*
* Make a POST call to the built-in Orthanc REST API. The result to
* the query is stored into a newly allocated memory buffer.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param target The target memory buffer.
* @param uri The URI in the built-in Orthanc API.
* @param body The body of the POST request.
* @param bodySize The size of the body.
* @return 0 if success, other value if error.
**/
ORTHANC_PLUGIN_INLINE int OrthancPluginRestApiPost(
OrthancPluginContext* context,
OrthancPluginMemoryBuffer* target,
const char* uri,
const char* body,
uint32_t bodySize)
{
_OrthancPluginRestApiPostPut params;
params.target = target;
params.uri = uri;
params.body = body;
params.bodySize = bodySize;
return context->InvokeService(context, _OrthancPluginService_RestApiPost, ¶ms);
}
/**
* @brief Make a DELETE call to the built-in Orthanc REST API.
*
* Make a DELETE call to the built-in Orthanc REST API.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param uri The URI to delete in the built-in Orthanc API.
* @return 0 if success, other value if error.
**/
ORTHANC_PLUGIN_INLINE int OrthancPluginRestApiDelete(
OrthancPluginContext* context,
const char* uri)
{
return context->InvokeService(context, _OrthancPluginService_RestApiDelete, uri);
}
/**
* @brief Make a PUT call to the built-in Orthanc REST API.
*
* Make a PUT call to the built-in Orthanc REST API. The result to
* the query is stored into a newly allocated memory buffer.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param target The target memory buffer.
* @param uri The URI in the built-in Orthanc API.
* @param body The body of the PUT request.
* @param bodySize The size of the body.
* @return 0 if success, other value if error.
**/
ORTHANC_PLUGIN_INLINE int OrthancPluginRestApiPut(
OrthancPluginContext* context,
OrthancPluginMemoryBuffer* target,
const char* uri,
const char* body,
uint32_t bodySize)
{
_OrthancPluginRestApiPostPut params;
params.target = target;
params.uri = uri;
params.body = body;
params.bodySize = bodySize;
return context->InvokeService(context, _OrthancPluginService_RestApiPut, ¶ms);
}
typedef struct
{
OrthancPluginRestOutput* output;
const char* argument;
} _OrthancPluginOutputPlusArgument;
/**
* @brief Redirect a REST request.
*
* This function answers to a REST request by redirecting the user
* to another URI using HTTP status 301.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param output The HTTP connection to the client application.
* @param redirection Where to redirect.
**/
ORTHANC_PLUGIN_INLINE void OrthancPluginRedirect(
OrthancPluginContext* context,
OrthancPluginRestOutput* output,
const char* redirection)
{
_OrthancPluginOutputPlusArgument params;
params.output = output;
params.argument = redirection;
context->InvokeService(context, _OrthancPluginService_Redirect, ¶ms);
}
typedef struct
{
char** result;
const char* argument;
} _OrthancPluginRetrieveDynamicString;
/**
* @brief Look for a patient.
*
* Look for a patient stored in Orthanc, using its Patient ID tag (0x0010, 0x0020).
* This function uses the database index to run as fast as possible (it does not loop
* over all the stored patients).
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param patientID The Patient ID of interest.
* @return The NULL value if the patient is non-existent, or a string containing the
* Orthanc ID of the patient. This string must be freed by OrthancPluginFreeString().
**/
ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupPatient(
OrthancPluginContext* context,
const char* patientID)
{
char* result;
_OrthancPluginRetrieveDynamicString params;
params.result = &result;
params.argument = patientID;
if (context->InvokeService(context, _OrthancPluginService_LookupPatient, ¶ms))
{
/* Error */
return NULL;
}
else
{
return result;
}
}
/**
* @brief Look for a study.
*
* Look for a study stored in Orthanc, using its Study Instance UID tag (0x0020, 0x000d).
* This function uses the database index to run as fast as possible (it does not loop
* over all the stored studies).
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param studyUID The Study Instance UID of interest.
* @return The NULL value if the study is non-existent, or a string containing the
* Orthanc ID of the study. This string must be freed by OrthancPluginFreeString().
**/
ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudy(
OrthancPluginContext* context,
const char* studyUID)
{
char* result;
_OrthancPluginRetrieveDynamicString params;
params.result = &result;
params.argument = studyUID;
if (context->InvokeService(context, _OrthancPluginService_LookupStudy, ¶ms))
{
/* Error */
return NULL;
}
else
{
return result;
}
}
/**
* @brief Look for a study, using the accession number.
*
* Look for a study stored in Orthanc, using its Accession Number tag (0x0008, 0x0050).
* This function uses the database index to run as fast as possible (it does not loop
* over all the stored studies).
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param accessionNumber The Accession Number of interest.
* @return The NULL value if the study is non-existent, or a string containing the
* Orthanc ID of the study. This string must be freed by OrthancPluginFreeString().
**/
ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudyWithAccessionNumber(
OrthancPluginContext* context,
const char* accessionNumber)
{
char* result;
_OrthancPluginRetrieveDynamicString params;
params.result = &result;
params.argument = accessionNumber;
if (context->InvokeService(context, _OrthancPluginService_LookupStudyWithAccessionNumber, ¶ms))
{
/* Error */
return NULL;
}
else
{
return result;
}
}
/**
* @brief Look for a series.
*
* Look for a series stored in Orthanc, using its Series Instance UID tag (0x0020, 0x000e).
* This function uses the database index to run as fast as possible (it does not loop
* over all the stored series).
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param seriesUID The Series Instance UID of interest.
* @return The NULL value if the series is non-existent, or a string containing the
* Orthanc ID of the series. This string must be freed by OrthancPluginFreeString().
**/
ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupSeries(
OrthancPluginContext* context,
const char* seriesUID)
{
char* result;
_OrthancPluginRetrieveDynamicString params;
params.result = &result;
params.argument = seriesUID;
if (context->InvokeService(context, _OrthancPluginService_LookupSeries, ¶ms))
{
/* Error */
return NULL;
}
else
{
return result;
}
}
/**
* @brief Look for an instance.
*
* Look for an instance stored in Orthanc, using its SOP Instance UID tag (0x0008, 0x0018).
* This function uses the database index to run as fast as possible (it does not loop
* over all the stored instances).
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param sopInstanceUID The SOP Instance UID of interest.
* @return The NULL value if the instance is non-existent, or a string containing the
* Orthanc ID of the instance. This string must be freed by OrthancPluginFreeString().
**/
ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupInstance(
OrthancPluginContext* context,
const char* sopInstanceUID)
{
char* result;
_OrthancPluginRetrieveDynamicString params;
params.result = &result;
params.argument = sopInstanceUID;
if (context->InvokeService(context, _OrthancPluginService_LookupInstance, ¶ms))
{
/* Error */
return NULL;
}
else
{
return result;
}
}
typedef struct
{
OrthancPluginRestOutput* output;
uint16_t status;
} _OrthancPluginSendHttpStatusCode;
/**
* @brief Send a HTTP status code.
*
* This function answers to a REST request by sending a HTTP status
* code (such as "400 - Bad Request"). Note that:
* - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer().
* - Redirections (status 301) must use ::OrthancPluginRedirect().
* - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized().
* - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed().
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param output The HTTP connection to the client application.
* @param status The HTTP status code to be sent.
**/
ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatusCode(
OrthancPluginContext* context,
OrthancPluginRestOutput* output,
uint16_t status)
{
_OrthancPluginSendHttpStatusCode params;
params.output = output;
params.status = status;
context->InvokeService(context, _OrthancPluginService_SendHttpStatusCode, ¶ms);
}
/**
* @brief Signal that a REST request is not authorized.
*
* This function answers to a REST request by signaling that it is
* not authorized.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param output The HTTP connection to the client application.
* @param realm The realm for the authorization process.
**/
ORTHANC_PLUGIN_INLINE void OrthancPluginSendUnauthorized(
OrthancPluginContext* context,
OrthancPluginRestOutput* output,
const char* realm)
{
_OrthancPluginOutputPlusArgument params;
params.output = output;
params.argument = realm;
context->InvokeService(context, _OrthancPluginService_SendUnauthorized, ¶ms);
}
/**
* @brief Signal that this URI does not support this HTTP method.
*
* This function answers to a REST request by signaling that the
* queried URI does not support this method.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param output The HTTP connection to the client application.
* @param allowedMethods The allowed methods for this URI (e.g. "GET,POST" after a PUT or a POST request).
**/
ORTHANC_PLUGIN_INLINE void OrthancPluginSendMethodNotAllowed(
OrthancPluginContext* context,
OrthancPluginRestOutput* output,
const char* allowedMethods)
{
_OrthancPluginOutputPlusArgument params;
params.output = output;
params.argument = allowedMethods;
context->InvokeService(context, _OrthancPluginService_SendMethodNotAllowed, ¶ms);
}
typedef struct
{
OrthancPluginRestOutput* output;
const char* key;
const char* value;
} _OrthancPluginSetHttpHeader;
/**
* @brief Set a cookie.
*
* This function sets a cookie in the HTTP client.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param output The HTTP connection to the client application.
* @param cookie The cookie to be set.
* @param value The value of the cookie.
**/
ORTHANC_PLUGIN_INLINE void OrthancPluginSetCookie(
OrthancPluginContext* context,
OrthancPluginRestOutput* output,
const char* cookie,
const char* value)
{
_OrthancPluginSetHttpHeader params;
params.output = output;
params.key = cookie;
params.value = value;
context->InvokeService(context, _OrthancPluginService_SetCookie, ¶ms);
}
/**
* @brief Set some HTTP header.
*
* This function sets a HTTP header in the HTTP answer.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param output The HTTP connection to the client application.
* @param key The HTTP header to be set.
* @param value The value of the HTTP header.
**/
ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpHeader(
OrthancPluginContext* context,
OrthancPluginRestOutput* output,
const char* key,
const char* value)
{
_OrthancPluginSetHttpHeader params;
params.output = output;
params.key = key;
params.value = value;
context->InvokeService(context, _OrthancPluginService_SetHttpHeader, ¶ms);
}
typedef struct
{
char** resultStringToFree;
const char** resultString;
int64_t* resultInt64;
const char* key;
OrthancPluginDicomInstance* instance;
} _OrthancPluginAccessDicomInstance;
/**
* @brief Get the AET of a DICOM instance.
*
* This function returns the Application Entity Title (AET) of the
* DICOM modality from which a DICOM instance originates.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param instance The instance of interest.
* @return The AET if success, NULL if error.
**/
ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceRemoteAet(
OrthancPluginContext* context,
OrthancPluginDicomInstance* instance)
{
const char* result;
_OrthancPluginAccessDicomInstance params;
memset(¶ms, 0, sizeof(params));
params.resultString = &result;
params.instance = instance;
if (context->InvokeService(context, _OrthancPluginService_GetInstanceRemoteAet, ¶ms))
{
/* Error */
return NULL;
}
else
{
return result;
}
}
/**
* @brief Get the size of a DICOM file.
*
* This function returns the number of bytes of the given DICOM instance.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param instance The instance of interest.
* @return The size of the file, -1 in case of error.
**/
ORTHANC_PLUGIN_INLINE int64_t OrthancPluginGetInstanceSize(
OrthancPluginContext* context,
OrthancPluginDicomInstance* instance)
{
int64_t size;
_OrthancPluginAccessDicomInstance params;
memset(¶ms, 0, sizeof(params));
params.resultInt64 = &size;
params.instance = instance;
if (context->InvokeService(context, _OrthancPluginService_GetInstanceSize, ¶ms))
{
/* Error */
return -1;
}
else
{
return size;
}
}
/**
* @brief Get the data of a DICOM file.
*
* This function returns a pointer to the content of the given DICOM instance.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param instance The instance of interest.
* @return The pointer to the DICOM data, NULL in case of error.
**/
ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceData(
OrthancPluginContext* context,
OrthancPluginDicomInstance* instance)
{
const char* result;
_OrthancPluginAccessDicomInstance params;
memset(¶ms, 0, sizeof(params));
params.resultString = &result;
params.instance = instance;
if (context->InvokeService(context, _OrthancPluginService_GetInstanceData, ¶ms))
{
/* Error */
return NULL;
}
else
{
return result;
}
}
/**
* @brief Get the DICOM tag hierarchy as a JSON file.
*
* This function returns a pointer to a newly created string
* containing a JSON file. This JSON file encodes the tag hierarchy
* of the given DICOM instance.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param instance The instance of interest.
* @return The NULL value in case of error, or a string containing the JSON file.
* This string must be freed by OrthancPluginFreeString().
**/
ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceJson(
OrthancPluginContext* context,
OrthancPluginDicomInstance* instance)
{
char* result;
_OrthancPluginAccessDicomInstance params;
memset(¶ms, 0, sizeof(params));
params.resultStringToFree = &result;
params.instance = instance;
if (context->InvokeService(context, _OrthancPluginService_GetInstanceJson, ¶ms))
{
/* Error */
return NULL;
}
else
{
return result;
}
}
/**
* @brief Get the DICOM tag hierarchy as a JSON file (with simplification).
*
* This function returns a pointer to a newly created string
* containing a JSON file. This JSON file encodes the tag hierarchy
* of the given DICOM instance. In contrast with
* ::OrthancPluginGetInstanceJson(), the returned JSON file is in
* its simplified version.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param instance The instance of interest.
* @return The NULL value in case of error, or a string containing the JSON file.
* This string must be freed by OrthancPluginFreeString().
**/
ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceSimplifiedJson(
OrthancPluginContext* context,
OrthancPluginDicomInstance* instance)
{
char* result;
_OrthancPluginAccessDicomInstance params;
memset(¶ms, 0, sizeof(params));
params.resultStringToFree = &result;
params.instance = instance;
if (context->InvokeService(context, _OrthancPluginService_GetInstanceSimplifiedJson, ¶ms))
{
/* Error */
return NULL;
}
else
{
return result;
}
}
/**
* @brief Check whether a DICOM instance is associated with some metadata.
*
* This function checks whether the DICOM instance of interest is
* associated with some metadata. As of Orthanc 0.8.1, in the
* callbacks registered by
* ::OrthancPluginRegisterOnStoredInstanceCallback(), the only
* possibly available metadata are "ReceptionDate", "RemoteAET" and
* "IndexInSeries".
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param instance The instance of interest.
* @param metadata The metadata of interest.
* @return 1 if the metadata is present, 0 if it is absent, -1 in case of error.
**/
ORTHANC_PLUGIN_INLINE int OrthancPluginHasInstanceMetadata(
OrthancPluginContext* context,
OrthancPluginDicomInstance* instance,
const char* metadata)
{
int64_t result;
_OrthancPluginAccessDicomInstance params;
memset(¶ms, 0, sizeof(params));
params.resultInt64 = &result;
params.instance = instance;
params.key = metadata;
if (context->InvokeService(context, _OrthancPluginService_HasInstanceMetadata, ¶ms))
{
/* Error */
return -1;
}
else
{
return (result != 0);
}
}
/**
* @brief Get the value of some metadata associated with a given DICOM instance.
*
* This functions returns the value of some metadata that is associated with the DICOM instance of interest.
* Before calling this function, the existence of the metadata must have been checked with
* ::OrthancPluginHasInstanceMetadata().
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param instance The instance of interest.
* @param metadata The metadata of interest.
* @return The metadata value if success, NULL if error.
**/
ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceMetadata(
OrthancPluginContext* context,
OrthancPluginDicomInstance* instance,
const char* metadata)
{
const char* result;
_OrthancPluginAccessDicomInstance params;
memset(¶ms, 0, sizeof(params));
params.resultString = &result;
params.instance = instance;
params.key = metadata;
if (context->InvokeService(context, _OrthancPluginService_GetInstanceMetadata, ¶ms))
{
/* Error */
return NULL;
}
else
{
return result;
}
}
typedef struct
{
OrthancPluginStorageCreate create_;
OrthancPluginStorageRead read_;
OrthancPluginStorageRemove remove_;
OrthancPluginFree free_;
} _OrthancPluginRegisterStorageArea;
/**
* @brief Register a custom storage area.
*
* This function registers a custom storage area, to replace the
* built-in way Orthanc stores its files on the filesystem. This
* function must be called during the initialization of the plugin,
* i.e. inside the OrthancPluginInitialize() public function.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @param create The callback function to store a file on the custom storage area.
* @param read The callback function to read a file from the custom storage area.
* @param remove The callback function to remove a file from the custom storage area.
**/
ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterStorageArea(
OrthancPluginContext* context,
OrthancPluginStorageCreate create,
OrthancPluginStorageRead read,
OrthancPluginStorageRemove remove)
{
_OrthancPluginRegisterStorageArea params;
params.create_ = create;
params.read_ = read;
params.remove_ = remove;
#ifdef __cplusplus
params.free_ = ::free;
#else
params.free_ = free;
#endif
context->InvokeService(context, _OrthancPluginService_RegisterStorageArea, ¶ms);
}
/**
* @brief Return the path to the Orthanc executable.
*
* This function returns the path to the Orthanc executable.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @return NULL in the case of an error, or a newly allocated string
* containing the path. This string must be freed by
* OrthancPluginFreeString().
**/
ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancPath(OrthancPluginContext* context)
{
char* result;
_OrthancPluginRetrieveDynamicString params;
params.result = &result;
params.argument = NULL;
if (context->InvokeService(context, _OrthancPluginService_GetOrthancPath, ¶ms))
{
/* Error */
return NULL;
}
else
{
return result;
}
}
/**
* @brief Return the directory containing the Orthanc.
*
* This function returns the path to the directory containing the Orthanc executable.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @return NULL in the case of an error, or a newly allocated string
* containing the path. This string must be freed by
* OrthancPluginFreeString().
**/
ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancDirectory(OrthancPluginContext* context)
{
char* result;
_OrthancPluginRetrieveDynamicString params;
params.result = &result;
params.argument = NULL;
if (context->InvokeService(context, _OrthancPluginService_GetOrthancDirectory, ¶ms))
{
/* Error */
return NULL;
}
else
{
return result;
}
}
/**
* @brief Return the path to the configuration file.
*
* This function returns the path to the configuration file that was
* specified when starting Orthanc.
*
* @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
* @return NULL in the case of an error, or a newly allocated string
* containing the path. This string must be freed by
* OrthancPluginFreeString().
**/
ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfigurationPath(OrthancPluginContext* context)
{
char* result;
_OrthancPluginRetrieveDynamicString params;
params.result = &result;
params.argument = NULL;
if (context->InvokeService(context, _OrthancPluginService_GetConfigurationPath, ¶ms))
{
/* Error */
return NULL;
}
else
{
return result;
}
}
#ifdef __cplusplus
}
#endif
/** @} */
|