Mercurial > hg > orthanc
comparison Plugins/Engine/OrthancPlugins.cpp @ 1627:da7854deb662
Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 18 Sep 2015 16:32:29 +0200 |
parents | c17b1142caab |
children | 77c4cc4def0f |
comparison
equal
deleted
inserted
replaced
1626:8dc468f44661 | 1627:da7854deb662 |
---|---|
368 | 368 |
369 for (PImpl::OnStoredCallbacks::const_iterator | 369 for (PImpl::OnStoredCallbacks::const_iterator |
370 callback = pimpl_->onStoredCallbacks_.begin(); | 370 callback = pimpl_->onStoredCallbacks_.begin(); |
371 callback != pimpl_->onStoredCallbacks_.end(); ++callback) | 371 callback != pimpl_->onStoredCallbacks_.end(); ++callback) |
372 { | 372 { |
373 (*callback) (reinterpret_cast<OrthancPluginDicomInstance*>(&instance), | 373 OrthancPluginErrorCode error = (*callback) |
374 instanceId.c_str()); | 374 (reinterpret_cast<OrthancPluginDicomInstance*>(&instance), |
375 instanceId.c_str()); | |
376 | |
377 if (error != OrthancPluginErrorCode_Success) | |
378 { | |
379 throw OrthancException(Plugins::Convert(error)); | |
380 } | |
375 } | 381 } |
376 } | 382 } |
377 | 383 |
378 | 384 |
379 | 385 |
380 void OrthancPlugins::SignalChange(const ServerIndexChange& change) | 386 void OrthancPlugins::SignalChange(const ServerIndexChange& change) |
381 { | 387 { |
382 try | 388 boost::recursive_mutex::scoped_lock lock(pimpl_->changeCallbackMutex_); |
383 { | 389 |
384 boost::recursive_mutex::scoped_lock lock(pimpl_->changeCallbackMutex_); | 390 for (std::list<OrthancPluginOnChangeCallback>::const_iterator |
385 | 391 callback = pimpl_->onChangeCallbacks_.begin(); |
386 for (std::list<OrthancPluginOnChangeCallback>::const_iterator | 392 callback != pimpl_->onChangeCallbacks_.end(); ++callback) |
387 callback = pimpl_->onChangeCallbacks_.begin(); | 393 { |
388 callback != pimpl_->onChangeCallbacks_.end(); ++callback) | 394 OrthancPluginErrorCode error = (*callback) |
389 { | 395 (Plugins::Convert(change.GetChangeType()), |
390 (*callback) (Plugins::Convert(change.GetChangeType()), | 396 Plugins::Convert(change.GetResourceType()), |
391 Plugins::Convert(change.GetResourceType()), | 397 change.GetPublicId().c_str()); |
392 change.GetPublicId().c_str()); | 398 |
393 } | 399 if (error != OrthancPluginErrorCode_Success) |
394 } | 400 { |
395 catch (OrthancException&) | 401 throw OrthancException(Plugins::Convert(error)); |
396 { | 402 } |
397 // This change type or resource type is not supported by the plugin SDK | |
398 return; | |
399 } | 403 } |
400 } | 404 } |
401 | 405 |
402 | 406 |
403 | 407 |
1575 public: | 1579 public: |
1576 PluginStorageArea(const _OrthancPluginRegisterStorageArea& params) : params_(params) | 1580 PluginStorageArea(const _OrthancPluginRegisterStorageArea& params) : params_(params) |
1577 { | 1581 { |
1578 } | 1582 } |
1579 | 1583 |
1584 | |
1580 virtual void Create(const std::string& uuid, | 1585 virtual void Create(const std::string& uuid, |
1581 const void* content, | 1586 const void* content, |
1582 size_t size, | 1587 size_t size, |
1583 FileContentType type) | 1588 FileContentType type) |
1584 { | 1589 { |
1585 if (params_.create(uuid.c_str(), content, size, Plugins::Convert(type)) != 0) | 1590 OrthancPluginErrorCode error = params_.create |
1586 { | 1591 (uuid.c_str(), content, size, Plugins::Convert(type)); |
1587 throw OrthancException(ErrorCode_Plugin); | 1592 |
1588 } | 1593 if (error != OrthancPluginErrorCode_Success) |
1589 } | 1594 { |
1595 throw OrthancException(Plugins::Convert(error)); | |
1596 } | |
1597 } | |
1598 | |
1590 | 1599 |
1591 virtual void Read(std::string& content, | 1600 virtual void Read(std::string& content, |
1592 const std::string& uuid, | 1601 const std::string& uuid, |
1593 FileContentType type) | 1602 FileContentType type) |
1594 { | 1603 { |
1595 void* buffer = NULL; | 1604 void* buffer = NULL; |
1596 int64_t size = 0; | 1605 int64_t size = 0; |
1597 | 1606 |
1598 if (params_.read(&buffer, &size, uuid.c_str(), Plugins::Convert(type)) != 0) | 1607 OrthancPluginErrorCode error = params_.read |
1599 { | 1608 (&buffer, &size, uuid.c_str(), Plugins::Convert(type)); |
1600 throw OrthancException(ErrorCode_Plugin); | 1609 |
1601 } | 1610 if (error != OrthancPluginErrorCode_Success) |
1611 { | |
1612 throw OrthancException(Plugins::Convert(error)); | |
1613 } | |
1602 | 1614 |
1603 try | 1615 try |
1604 { | 1616 { |
1605 content.resize(static_cast<size_t>(size)); | 1617 content.resize(static_cast<size_t>(size)); |
1606 } | 1618 } |
1607 catch (OrthancException&) | 1619 catch (...) |
1608 { | 1620 { |
1609 Free(buffer); | 1621 Free(buffer); |
1610 throw; | 1622 throw; |
1611 } | 1623 } |
1612 | 1624 |
1616 } | 1628 } |
1617 | 1629 |
1618 Free(buffer); | 1630 Free(buffer); |
1619 } | 1631 } |
1620 | 1632 |
1633 | |
1621 virtual void Remove(const std::string& uuid, | 1634 virtual void Remove(const std::string& uuid, |
1622 FileContentType type) | 1635 FileContentType type) |
1623 { | 1636 { |
1624 if (params_.remove(uuid.c_str(), Plugins::Convert(type)) != 0) | 1637 OrthancPluginErrorCode error = params_.remove |
1625 { | 1638 (uuid.c_str(), Plugins::Convert(type)); |
1626 throw OrthancException(ErrorCode_Plugin); | 1639 |
1627 } | 1640 if (error != OrthancPluginErrorCode_Success) |
1641 { | |
1642 throw OrthancException(Plugins::Convert(error)); | |
1643 } | |
1628 } | 1644 } |
1629 }; | 1645 }; |
1630 } | 1646 } |
1631 | 1647 |
1632 | 1648 |