Mercurial > hg > orthanc
comparison Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 2850:9f949922d603
fix
author | am@osimis.io |
---|---|
date | Mon, 01 Oct 2018 14:19:10 +0200 |
parents | dd3914a44b87 |
children | 859e880ac9a8 |
comparison
equal
deleted
inserted
replaced
2848:dd3914a44b87 | 2850:9f949922d603 |
---|---|
18 * modify file(s) with this exception, you may extend this exception to | 18 * modify file(s) with this exception, you may extend this exception to |
19 * your version of the file(s), but you are not obligated to do so. If | 19 * your version of the file(s), but you are not obligated to do so. If |
20 * you do not wish to do so, delete this exception statement from your | 20 * you do not wish to do so, delete this exception statement from your |
21 * version. If you delete this exception statement from all source files | 21 * version. If you delete this exception statement from all source files |
22 * in the program, then also delete it here. | 22 * in the program, then also delete it here. |
23 * | 23 * |
24 * This program is distributed in the hope that it will be useful, but | 24 * This program is distributed in the hope that it will be useful, but |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | 25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
27 * General Public License for more details. | 27 * General Public License for more details. |
28 * | 28 * |
74 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); | 74 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); |
75 } | 75 } |
76 } | 76 } |
77 | 77 |
78 | 78 |
79 MemoryBuffer::MemoryBuffer(OrthancPluginContext* context) : | 79 MemoryBuffer::MemoryBuffer(OrthancPluginContext* context) : |
80 context_(context) | 80 context_(context) |
81 { | 81 { |
82 buffer_.data = NULL; | 82 buffer_.data = NULL; |
83 buffer_.size = 0; | 83 buffer_.size = 0; |
84 } | 84 } |
229 std::string s = writer.write(tags); | 229 std::string s = writer.write(tags); |
230 | 230 |
231 Check(OrthancPluginCreateDicom(context_, &buffer_, s.c_str(), NULL, flags)); | 231 Check(OrthancPluginCreateDicom(context_, &buffer_, s.c_str(), NULL, flags)); |
232 } | 232 } |
233 | 233 |
234 void MemoreyBuffer::CreateDicom(const Json::Value& tags, | 234 void MemoryBuffer::CreateDicom(const Json::Value& tags, |
235 const OrthancPluginImage& pixelData, | 235 const OrthancImage& pixelData, |
236 OrthancPluginCreateDicomFlags flags) | 236 OrthancPluginCreateDicomFlags flags) |
237 { | 237 { |
238 Clear(); | 238 Clear(); |
239 | 239 |
240 Json::FastWriter writer; | 240 Json::FastWriter writer; |
241 std::string s = writer.write(tags); | 241 std::string s = writer.write(tags); |
344 body.c_str(), body.size(), | 344 body.c_str(), body.size(), |
345 username.empty() ? NULL : username.c_str(), | 345 username.empty() ? NULL : username.c_str(), |
346 password.empty() ? NULL : password.c_str())); | 346 password.empty() ? NULL : password.c_str())); |
347 } | 347 } |
348 | 348 |
349 | 349 |
350 bool MemoryBuffer::HttpPut(const std::string& url, | 350 bool MemoryBuffer::HttpPut(const std::string& url, |
351 const std::string& body, | 351 const std::string& body, |
352 const std::string& username, | 352 const std::string& username, |
353 const std::string& password) | 353 const std::string& password) |
354 { | 354 { |
372 const std::string& url, | 372 const std::string& url, |
373 const std::string& username, | 373 const std::string& username, |
374 const std::string& password) | 374 const std::string& password) |
375 { | 375 { |
376 OrthancPluginErrorCode error = OrthancPluginHttpDelete | 376 OrthancPluginErrorCode error = OrthancPluginHttpDelete |
377 (context_, url.c_str(), | 377 (context_, url.c_str(), |
378 username.empty() ? NULL : username.c_str(), | 378 username.empty() ? NULL : username.c_str(), |
379 password.empty() ? NULL : password.c_str()); | 379 password.empty() ? NULL : password.c_str()); |
380 | 380 |
381 if (error == OrthancPluginErrorCode_Success) | 381 if (error == OrthancPluginErrorCode_Success) |
382 { | 382 { |
383 return true; | 383 return true; |
384 } | 384 } |
385 else if (error == OrthancPluginErrorCode_UnknownResource || | 385 else if (error == OrthancPluginErrorCode_UnknownResource || |
392 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); | 392 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); |
393 } | 393 } |
394 } | 394 } |
395 | 395 |
396 | 396 |
397 OrthancConfiguration::OrthancConfiguration(OrthancPluginContext* context) : | 397 OrthancConfiguration::OrthancConfiguration(OrthancPluginContext* context) : |
398 context_(context) | 398 context_(context) |
399 { | 399 { |
400 OrthancString str(context); | 400 OrthancString str(context); |
401 str.Assign(OrthancPluginGetConfiguration(context)); | 401 str.Assign(OrthancPluginGetConfiguration(context)); |
402 | 402 |
517 return false; | 517 return false; |
518 } | 518 } |
519 | 519 |
520 switch (configuration_[key].type()) | 520 switch (configuration_[key].type()) |
521 { | 521 { |
522 case Json::intValue: | 522 case Json::intValue: |
523 target = configuration_[key].asInt(); | 523 target = configuration_[key].asInt(); |
524 return true; | 524 return true; |
525 | 525 |
526 case Json::uintValue: | 526 case Json::uintValue: |
527 target = configuration_[key].asUInt(); | 527 target = configuration_[key].asUInt(); |
528 return true; | 528 return true; |
529 | 529 |
530 default: | 530 default: |
531 if (context_ != NULL) | 531 if (context_ != NULL) |
532 { | 532 { |
533 std::string s = "The configuration option \"" + GetPath(key) + "\" is not an integer as expected"; | 533 std::string s = "The configuration option \"" + GetPath(key) + "\" is not an integer as expected"; |
534 OrthancPluginLogError(context_, s.c_str()); | 534 OrthancPluginLogError(context_, s.c_str()); |
535 } | 535 } |
536 | 536 |
537 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | 537 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
538 } | 538 } |
539 } | 539 } |
540 | 540 |
541 | 541 |
542 bool OrthancConfiguration::LookupUnsignedIntegerValue(unsigned int& target, | 542 bool OrthancConfiguration::LookupUnsignedIntegerValue(unsigned int& target, |
602 return false; | 602 return false; |
603 } | 603 } |
604 | 604 |
605 switch (configuration_[key].type()) | 605 switch (configuration_[key].type()) |
606 { | 606 { |
607 case Json::realValue: | 607 case Json::realValue: |
608 target = configuration_[key].asFloat(); | 608 target = configuration_[key].asFloat(); |
609 return true; | 609 return true; |
610 | 610 |
611 case Json::intValue: | 611 case Json::intValue: |
612 target = static_cast<float>(configuration_[key].asInt()); | 612 target = static_cast<float>(configuration_[key].asInt()); |
613 return true; | 613 return true; |
614 | 614 |
615 case Json::uintValue: | 615 case Json::uintValue: |
616 target = static_cast<float>(configuration_[key].asUInt()); | 616 target = static_cast<float>(configuration_[key].asUInt()); |
617 return true; | 617 return true; |
618 | 618 |
619 default: | 619 default: |
620 if (context_ != NULL) | 620 if (context_ != NULL) |
621 { | 621 { |
622 std::string s = "The configuration option \"" + GetPath(key) + "\" is not an integer as expected"; | 622 std::string s = "The configuration option \"" + GetPath(key) + "\" is not an integer as expected"; |
623 OrthancPluginLogError(context_, s.c_str()); | 623 OrthancPluginLogError(context_, s.c_str()); |
624 } | 624 } |
625 | 625 |
626 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | 626 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
627 } | 627 } |
628 } | 628 } |
629 | 629 |
630 | 630 |
631 bool OrthancConfiguration::LookupListOfStrings(std::list<std::string>& target, | 631 bool OrthancConfiguration::LookupListOfStrings(std::list<std::string>& target, |
641 return false; | 641 return false; |
642 } | 642 } |
643 | 643 |
644 switch (configuration_[key].type()) | 644 switch (configuration_[key].type()) |
645 { | 645 { |
646 case Json::arrayValue: | 646 case Json::arrayValue: |
647 { | 647 { |
648 bool ok = true; | 648 bool ok = true; |
649 | 649 |
650 for (Json::Value::ArrayIndex i = 0; ok && i < configuration_[key].size(); i++) | 650 for (Json::Value::ArrayIndex i = 0; ok && i < configuration_[key].size(); i++) |
651 { | |
652 if (configuration_[key][i].type() == Json::stringValue) | |
651 { | 653 { |
652 if (configuration_[key][i].type() == Json::stringValue) | 654 target.push_back(configuration_[key][i].asString()); |
653 { | |
654 target.push_back(configuration_[key][i].asString()); | |
655 } | |
656 else | |
657 { | |
658 ok = false; | |
659 } | |
660 } | 655 } |
661 | 656 else |
662 if (ok) | |
663 { | 657 { |
664 return true; | 658 ok = false; |
665 } | 659 } |
666 | 660 } |
667 break; | 661 |
668 } | 662 if (ok) |
669 | 663 { |
670 case Json::stringValue: | 664 return true; |
671 if (allowSingleString) | 665 } |
672 { | 666 |
673 target.push_back(configuration_[key].asString()); | 667 break; |
674 return true; | 668 } |
675 } | 669 |
676 | 670 case Json::stringValue: |
677 break; | 671 if (allowSingleString) |
678 | 672 { |
679 default: | 673 target.push_back(configuration_[key].asString()); |
680 break; | 674 return true; |
675 } | |
676 | |
677 break; | |
678 | |
679 default: | |
680 break; | |
681 } | 681 } |
682 | 682 |
683 if (context_ != NULL) | 683 if (context_ != NULL) |
684 { | 684 { |
685 std::string s = ("The configuration option \"" + GetPath(key) + | 685 std::string s = ("The configuration option \"" + GetPath(key) + |
700 if (LookupListOfStrings(lst, key, allowSingleString)) | 700 if (LookupListOfStrings(lst, key, allowSingleString)) |
701 { | 701 { |
702 target.clear(); | 702 target.clear(); |
703 | 703 |
704 for (std::list<std::string>::const_iterator | 704 for (std::list<std::string>::const_iterator |
705 it = lst.begin(); it != lst.end(); ++it) | 705 it = lst.begin(); it != lst.end(); ++it) |
706 { | 706 { |
707 target.insert(*it); | 707 target.insert(*it); |
708 } | 708 } |
709 | 709 |
710 return true; | 710 return true; |
980 { | 980 { |
981 CheckImageAvailable(); | 981 CheckImageAvailable(); |
982 return OrthancPluginGetImagePitch(context_, image_); | 982 return OrthancPluginGetImagePitch(context_, image_); |
983 } | 983 } |
984 | 984 |
985 | 985 |
986 const void* OrthancImage::GetBuffer() | 986 const void* OrthancImage::GetBuffer() |
987 { | 987 { |
988 CheckImageAvailable(); | 988 CheckImageAvailable(); |
989 return OrthancPluginGetImageBuffer(context_, image_); | 989 return OrthancPluginGetImageBuffer(context_, image_); |
990 } | 990 } |
993 void OrthancImage::CompressPngImage(MemoryBuffer& target) | 993 void OrthancImage::CompressPngImage(MemoryBuffer& target) |
994 { | 994 { |
995 CheckImageAvailable(); | 995 CheckImageAvailable(); |
996 | 996 |
997 OrthancPluginMemoryBuffer tmp; | 997 OrthancPluginMemoryBuffer tmp; |
998 OrthancPluginCompressPngImage(context_, &tmp, GetPixelFormat(), | 998 OrthancPluginCompressPngImage(context_, &tmp, GetPixelFormat(), |
999 GetWidth(), GetHeight(), GetPitch(), GetBuffer()); | 999 GetWidth(), GetHeight(), GetPitch(), GetBuffer()); |
1000 | 1000 |
1001 target.Assign(tmp); | 1001 target.Assign(tmp); |
1002 } | 1002 } |
1003 | 1003 |
1006 uint8_t quality) | 1006 uint8_t quality) |
1007 { | 1007 { |
1008 CheckImageAvailable(); | 1008 CheckImageAvailable(); |
1009 | 1009 |
1010 OrthancPluginMemoryBuffer tmp; | 1010 OrthancPluginMemoryBuffer tmp; |
1011 OrthancPluginCompressJpegImage(context_, &tmp, GetPixelFormat(), | 1011 OrthancPluginCompressJpegImage(context_, &tmp, GetPixelFormat(), |
1012 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); | 1012 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); |
1013 | 1013 |
1014 target.Assign(tmp); | 1014 target.Assign(tmp); |
1015 } | 1015 } |
1016 | 1016 |
1062 } | 1062 } |
1063 | 1063 |
1064 | 1064 |
1065 FindMatcher::~FindMatcher() | 1065 FindMatcher::~FindMatcher() |
1066 { | 1066 { |
1067 // The "worklist_" field | 1067 // The "worklist_" field |
1068 | 1068 |
1069 if (matcher_ != NULL) | 1069 if (matcher_ != NULL) |
1070 { | 1070 { |
1071 OrthancPluginFreeFindMatcher(context_, matcher_); | 1071 OrthancPluginFreeFindMatcher(context_, matcher_); |
1072 } | 1072 } |
1228 std::string s = ("Your version of the Orthanc core (" + | 1228 std::string s = ("Your version of the Orthanc core (" + |
1229 std::string(context->orthancVersion) + | 1229 std::string(context->orthancVersion) + |
1230 ") is too old to run this plugin (version " + | 1230 ") is too old to run this plugin (version " + |
1231 boost::lexical_cast<std::string>(major) + "." + | 1231 boost::lexical_cast<std::string>(major) + "." + |
1232 boost::lexical_cast<std::string>(minor) + "." + | 1232 boost::lexical_cast<std::string>(minor) + "." + |
1233 boost::lexical_cast<std::string>(revision) + | 1233 boost::lexical_cast<std::string>(revision) + |
1234 " is required)"); | 1234 " is required)"); |
1235 | 1235 |
1236 OrthancPluginLogError(context, s.c_str()); | 1236 OrthancPluginLogError(context, s.c_str()); |
1237 } | 1237 } |
1238 | 1238 |
1242 unsigned int minor, | 1242 unsigned int minor, |
1243 unsigned int revision) | 1243 unsigned int revision) |
1244 { | 1244 { |
1245 if (context == NULL) | 1245 if (context == NULL) |
1246 { | 1246 { |
1247 OrthancPluginLogError(context, "Bad Orthanc context in the plugin"); | 1247 OrthancPluginLogError(context, "Bad Orthanc context in the plugin"); |
1248 return false; | 1248 return false; |
1249 } | 1249 } |
1250 | 1250 |
1251 if (!strcmp(context->orthancVersion, "mainline")) | 1251 if (!strcmp(context->orthancVersion, "mainline")) |
1252 { | 1252 { |
1254 return true; | 1254 return true; |
1255 } | 1255 } |
1256 | 1256 |
1257 // Parse the version of the Orthanc core | 1257 // Parse the version of the Orthanc core |
1258 int aa, bb, cc; | 1258 int aa, bb, cc; |
1259 if ( | 1259 if ( |
1260 #ifdef _MSC_VER | 1260 #ifdef _MSC_VER |
1261 sscanf_s | 1261 sscanf_s |
1262 #else | 1262 #else |
1263 sscanf | 1263 sscanf |
1264 #endif | 1264 #endif |
1265 (context->orthancVersion, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 || | 1265 (context->orthancVersion, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 || |
1266 aa < 0 || | 1266 aa < 0 || |
1267 bb < 0 || | 1267 bb < 0 || |
1268 cc < 0) | 1268 cc < 0) |
1269 { | 1269 { |
1270 return false; | 1270 return false; |
1271 } | 1271 } |
1272 | 1272 |
1273 unsigned int a = static_cast<unsigned int>(aa); | 1273 unsigned int a = static_cast<unsigned int>(aa); |
1338 peers_(NULL), | 1338 peers_(NULL), |
1339 timeout_(0) | 1339 timeout_(0) |
1340 { | 1340 { |
1341 if (context_ == NULL) | 1341 if (context_ == NULL) |
1342 { | 1342 { |
1343 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); | 1343 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); |
1344 } | 1344 } |
1345 | 1345 |
1346 peers_ = OrthancPluginGetPeers(context_); | 1346 peers_ = OrthancPluginGetPeers(context_); |
1347 | 1347 |
1348 if (peers_ == NULL) | 1348 if (peers_ == NULL) |
1482 } | 1482 } |
1483 | 1483 |
1484 OrthancPluginMemoryBuffer answer; | 1484 OrthancPluginMemoryBuffer answer; |
1485 uint16_t status; | 1485 uint16_t status; |
1486 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | 1486 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
1487 (context_, &answer, NULL, &status, peers_, | 1487 (context_, &answer, NULL, &status, peers_, |
1488 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Get, uri.c_str(), | 1488 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Get, uri.c_str(), |
1489 0, NULL, NULL, NULL, 0, timeout_); | 1489 0, NULL, NULL, NULL, 0, timeout_); |
1490 | 1490 |
1491 if (code == OrthancPluginErrorCode_Success) | 1491 if (code == OrthancPluginErrorCode_Success) |
1492 { | 1492 { |
1493 target.Assign(answer); | 1493 target.Assign(answer); |
1494 return (status == 200); | 1494 return (status == 200); |
1513 bool OrthancPeers::DoGet(Json::Value& target, | 1513 bool OrthancPeers::DoGet(Json::Value& target, |
1514 size_t index, | 1514 size_t index, |
1515 const std::string& uri) const | 1515 const std::string& uri) const |
1516 { | 1516 { |
1517 MemoryBuffer buffer(context_); | 1517 MemoryBuffer buffer(context_); |
1518 | 1518 |
1519 if (DoGet(buffer, index, uri)) | 1519 if (DoGet(buffer, index, uri)) |
1520 { | 1520 { |
1521 buffer.ToJson(target); | 1521 buffer.ToJson(target); |
1522 return true; | 1522 return true; |
1523 } | 1523 } |
1525 { | 1525 { |
1526 return false; | 1526 return false; |
1527 } | 1527 } |
1528 } | 1528 } |
1529 | 1529 |
1530 | 1530 |
1531 bool OrthancPeers::DoGet(Json::Value& target, | 1531 bool OrthancPeers::DoGet(Json::Value& target, |
1532 const std::string& name, | 1532 const std::string& name, |
1533 const std::string& uri) const | 1533 const std::string& uri) const |
1534 { | 1534 { |
1535 MemoryBuffer buffer(context_); | 1535 MemoryBuffer buffer(context_); |
1536 | 1536 |
1537 if (DoGet(buffer, name, uri)) | 1537 if (DoGet(buffer, name, uri)) |
1538 { | 1538 { |
1539 buffer.ToJson(target); | 1539 buffer.ToJson(target); |
1540 return true; | 1540 return true; |
1541 } | 1541 } |
1561 size_t index, | 1561 size_t index, |
1562 const std::string& uri, | 1562 const std::string& uri, |
1563 const std::string& body) const | 1563 const std::string& body) const |
1564 { | 1564 { |
1565 MemoryBuffer buffer(context_); | 1565 MemoryBuffer buffer(context_); |
1566 | 1566 |
1567 if (DoPost(buffer, index, uri, body)) | 1567 if (DoPost(buffer, index, uri, body)) |
1568 { | 1568 { |
1569 buffer.ToJson(target); | 1569 buffer.ToJson(target); |
1570 return true; | 1570 return true; |
1571 } | 1571 } |
1573 { | 1573 { |
1574 return false; | 1574 return false; |
1575 } | 1575 } |
1576 } | 1576 } |
1577 | 1577 |
1578 | 1578 |
1579 bool OrthancPeers::DoPost(Json::Value& target, | 1579 bool OrthancPeers::DoPost(Json::Value& target, |
1580 const std::string& name, | 1580 const std::string& name, |
1581 const std::string& uri, | 1581 const std::string& uri, |
1582 const std::string& body) const | 1582 const std::string& body) const |
1583 { | 1583 { |
1584 MemoryBuffer buffer(context_); | 1584 MemoryBuffer buffer(context_); |
1585 | 1585 |
1586 if (DoPost(buffer, name, uri, body)) | 1586 if (DoPost(buffer, name, uri, body)) |
1587 { | 1587 { |
1588 buffer.ToJson(target); | 1588 buffer.ToJson(target); |
1589 return true; | 1589 return true; |
1590 } | 1590 } |
1606 } | 1606 } |
1607 | 1607 |
1608 OrthancPluginMemoryBuffer answer; | 1608 OrthancPluginMemoryBuffer answer; |
1609 uint16_t status; | 1609 uint16_t status; |
1610 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | 1610 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
1611 (context_, &answer, NULL, &status, peers_, | 1611 (context_, &answer, NULL, &status, peers_, |
1612 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Post, uri.c_str(), | 1612 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Post, uri.c_str(), |
1613 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); | 1613 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); |
1614 | 1614 |
1615 if (code == OrthancPluginErrorCode_Success) | 1615 if (code == OrthancPluginErrorCode_Success) |
1616 { | 1616 { |
1617 target.Assign(answer); | 1617 target.Assign(answer); |
1618 return (status == 200); | 1618 return (status == 200); |
1634 } | 1634 } |
1635 | 1635 |
1636 OrthancPluginMemoryBuffer answer; | 1636 OrthancPluginMemoryBuffer answer; |
1637 uint16_t status; | 1637 uint16_t status; |
1638 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | 1638 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
1639 (context_, &answer, NULL, &status, peers_, | 1639 (context_, &answer, NULL, &status, peers_, |
1640 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(), | 1640 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(), |
1641 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); | 1641 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); |
1642 | 1642 |
1643 if (code == OrthancPluginErrorCode_Success) | 1643 if (code == OrthancPluginErrorCode_Success) |
1644 { | 1644 { |
1645 OrthancPluginFreeMemoryBuffer(context_, &answer); | 1645 OrthancPluginFreeMemoryBuffer(context_, &answer); |
1646 return (status == 200); | 1646 return (status == 200); |
1671 } | 1671 } |
1672 | 1672 |
1673 OrthancPluginMemoryBuffer answer; | 1673 OrthancPluginMemoryBuffer answer; |
1674 uint16_t status; | 1674 uint16_t status; |
1675 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | 1675 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
1676 (context_, &answer, NULL, &status, peers_, | 1676 (context_, &answer, NULL, &status, peers_, |
1677 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(), | 1677 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(), |
1678 0, NULL, NULL, NULL, 0, timeout_); | 1678 0, NULL, NULL, NULL, 0, timeout_); |
1679 | 1679 |
1680 if (code == OrthancPluginErrorCode_Success) | 1680 if (code == OrthancPluginErrorCode_Success) |
1681 { | 1681 { |
1682 OrthancPluginFreeMemoryBuffer(context_, &answer); | 1682 OrthancPluginFreeMemoryBuffer(context_, &answer); |
1683 return (status == 200); | 1683 return (status == 200); |
1872 if (progress < 0 || | 1872 if (progress < 0 || |
1873 progress > 1) | 1873 progress > 1) |
1874 { | 1874 { |
1875 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | 1875 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); |
1876 } | 1876 } |
1877 | 1877 |
1878 progress_ = progress; | 1878 progress_ = progress; |
1879 } | 1879 } |
1880 | 1880 |
1881 | 1881 |
1882 OrthancJob::OrthancJob(const std::string& jobType) : | 1882 OrthancJob::OrthancJob(const std::string& jobType) : |
1883 jobType_(jobType), | 1883 jobType_(jobType), |
1884 progress_(0) | 1884 progress_(0) |
1885 { | 1885 { |
1886 ClearContent(); | 1886 ClearContent(); |
1887 ClearSerialized(); | 1887 ClearSerialized(); |
1888 } | 1888 } |
1889 | 1889 |
1890 | 1890 |
1891 OrthancPluginJob* OrthancJob::Create(OrthancPluginContext* context, | 1891 OrthancPluginJob* OrthancJob::Create(OrthancPluginContext* context, |
1892 OrthancJob* job) | 1892 OrthancJob* job) |
1893 { | 1893 { |
1894 if (job == NULL) | 1894 if (job == NULL) |
1895 { | 1895 { |
1896 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); | 1896 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); |
1897 } | 1897 } |
1898 | 1898 |
1899 OrthancPluginJob* orthanc = OrthancPluginCreateJob( | 1899 OrthancPluginJob* orthanc = OrthancPluginCreateJob( |
1900 context, job, CallbackFinalize, job->jobType_.c_str(), | 1900 context, job, CallbackFinalize, job->jobType_.c_str(), |
1901 CallbackGetProgress, CallbackGetContent, CallbackGetSerialized, | 1901 CallbackGetProgress, CallbackGetContent, CallbackGetSerialized, |
1902 CallbackStep, CallbackStop, CallbackReset); | 1902 CallbackStep, CallbackStop, CallbackReset); |
1903 | 1903 |
1904 if (orthanc == NULL) | 1904 if (orthanc == NULL) |
1905 { | 1905 { |
1906 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | 1906 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); |
1907 } | 1907 } |