Mercurial > hg > orthanc
comparison Plugins/Engine/OrthancPlugins.cpp @ 1651:2e692c83e2f3
improved custom error login
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 25 Sep 2015 17:29:39 +0200 |
parents | 8040d56cb0b3 |
children | 5360cdba70d8 |
comparison
equal
deleted
inserted
replaced
1650:9f34ebfaf2c9 | 1651:2e692c83e2f3 |
---|---|
64 { | 64 { |
65 class PluginStorageArea : public IStorageArea | 65 class PluginStorageArea : public IStorageArea |
66 { | 66 { |
67 private: | 67 private: |
68 _OrthancPluginRegisterStorageArea callbacks_; | 68 _OrthancPluginRegisterStorageArea callbacks_; |
69 PluginsErrorDictionary& errorDictionary_; | |
69 | 70 |
70 void Free(void* buffer) const | 71 void Free(void* buffer) const |
71 { | 72 { |
72 if (buffer != NULL) | 73 if (buffer != NULL) |
73 { | 74 { |
74 callbacks_.free(buffer); | 75 callbacks_.free(buffer); |
75 } | 76 } |
76 } | 77 } |
77 | 78 |
78 public: | 79 public: |
79 PluginStorageArea(const _OrthancPluginRegisterStorageArea& callbacks) : callbacks_(callbacks) | 80 PluginStorageArea(const _OrthancPluginRegisterStorageArea& callbacks, |
81 PluginsErrorDictionary& errorDictionary) : | |
82 callbacks_(callbacks), | |
83 errorDictionary_(errorDictionary) | |
80 { | 84 { |
81 } | 85 } |
82 | 86 |
83 | 87 |
84 virtual void Create(const std::string& uuid, | 88 virtual void Create(const std::string& uuid, |
89 OrthancPluginErrorCode error = callbacks_.create | 93 OrthancPluginErrorCode error = callbacks_.create |
90 (uuid.c_str(), content, size, Plugins::Convert(type)); | 94 (uuid.c_str(), content, size, Plugins::Convert(type)); |
91 | 95 |
92 if (error != OrthancPluginErrorCode_Success) | 96 if (error != OrthancPluginErrorCode_Success) |
93 { | 97 { |
98 errorDictionary_.LogError(error, true); | |
94 throw OrthancException(static_cast<ErrorCode>(error)); | 99 throw OrthancException(static_cast<ErrorCode>(error)); |
95 } | 100 } |
96 } | 101 } |
97 | 102 |
98 | 103 |
106 OrthancPluginErrorCode error = callbacks_.read | 111 OrthancPluginErrorCode error = callbacks_.read |
107 (&buffer, &size, uuid.c_str(), Plugins::Convert(type)); | 112 (&buffer, &size, uuid.c_str(), Plugins::Convert(type)); |
108 | 113 |
109 if (error != OrthancPluginErrorCode_Success) | 114 if (error != OrthancPluginErrorCode_Success) |
110 { | 115 { |
116 errorDictionary_.LogError(error, true); | |
111 throw OrthancException(static_cast<ErrorCode>(error)); | 117 throw OrthancException(static_cast<ErrorCode>(error)); |
112 } | 118 } |
113 | 119 |
114 try | 120 try |
115 { | 121 { |
136 OrthancPluginErrorCode error = callbacks_.remove | 142 OrthancPluginErrorCode error = callbacks_.remove |
137 (uuid.c_str(), Plugins::Convert(type)); | 143 (uuid.c_str(), Plugins::Convert(type)); |
138 | 144 |
139 if (error != OrthancPluginErrorCode_Success) | 145 if (error != OrthancPluginErrorCode_Success) |
140 { | 146 { |
147 errorDictionary_.LogError(error, true); | |
141 throw OrthancException(static_cast<ErrorCode>(error)); | 148 throw OrthancException(static_cast<ErrorCode>(error)); |
142 } | 149 } |
143 } | 150 } |
144 }; | 151 }; |
145 | 152 |
147 class StorageAreaFactory : public boost::noncopyable | 154 class StorageAreaFactory : public boost::noncopyable |
148 { | 155 { |
149 private: | 156 private: |
150 SharedLibrary& sharedLibrary_; | 157 SharedLibrary& sharedLibrary_; |
151 _OrthancPluginRegisterStorageArea callbacks_; | 158 _OrthancPluginRegisterStorageArea callbacks_; |
159 PluginsErrorDictionary& errorDictionary_; | |
152 | 160 |
153 public: | 161 public: |
154 StorageAreaFactory(SharedLibrary& sharedLibrary, | 162 StorageAreaFactory(SharedLibrary& sharedLibrary, |
155 const _OrthancPluginRegisterStorageArea& callbacks) : | 163 const _OrthancPluginRegisterStorageArea& callbacks, |
164 PluginsErrorDictionary& errorDictionary) : | |
156 sharedLibrary_(sharedLibrary), | 165 sharedLibrary_(sharedLibrary), |
157 callbacks_(callbacks) | 166 callbacks_(callbacks), |
167 errorDictionary_(errorDictionary) | |
158 { | 168 { |
159 } | 169 } |
160 | 170 |
161 SharedLibrary& GetSharedLibrary() | 171 SharedLibrary& GetSharedLibrary() |
162 { | 172 { |
163 return sharedLibrary_; | 173 return sharedLibrary_; |
164 } | 174 } |
165 | 175 |
166 IStorageArea* Create() const | 176 IStorageArea* Create() const |
167 { | 177 { |
168 return new PluginStorageArea(callbacks_); | 178 return new PluginStorageArea(callbacks_, errorDictionary_); |
169 } | 179 } |
170 }; | 180 }; |
171 } | 181 } |
172 | 182 |
173 | 183 |
462 { | 472 { |
463 return true; | 473 return true; |
464 } | 474 } |
465 else | 475 else |
466 { | 476 { |
477 GetErrorDictionary().LogError(error, true); | |
467 throw OrthancException(static_cast<ErrorCode>(error)); | 478 throw OrthancException(static_cast<ErrorCode>(error)); |
468 } | 479 } |
469 } | 480 } |
470 | 481 |
471 | 482 |
483 (reinterpret_cast<OrthancPluginDicomInstance*>(&instance), | 494 (reinterpret_cast<OrthancPluginDicomInstance*>(&instance), |
484 instanceId.c_str()); | 495 instanceId.c_str()); |
485 | 496 |
486 if (error != OrthancPluginErrorCode_Success) | 497 if (error != OrthancPluginErrorCode_Success) |
487 { | 498 { |
499 GetErrorDictionary().LogError(error, true); | |
488 throw OrthancException(static_cast<ErrorCode>(error)); | 500 throw OrthancException(static_cast<ErrorCode>(error)); |
489 } | 501 } |
490 } | 502 } |
491 } | 503 } |
492 | 504 |
505 Plugins::Convert(change.GetResourceType()), | 517 Plugins::Convert(change.GetResourceType()), |
506 change.GetPublicId().c_str()); | 518 change.GetPublicId().c_str()); |
507 | 519 |
508 if (error != OrthancPluginErrorCode_Success) | 520 if (error != OrthancPluginErrorCode_Success) |
509 { | 521 { |
522 GetErrorDictionary().LogError(error, true); | |
510 throw OrthancException(static_cast<ErrorCode>(error)); | 523 throw OrthancException(static_cast<ErrorCode>(error)); |
511 } | 524 } |
512 } | 525 } |
513 } | 526 } |
514 | 527 |
1376 const _OrthancPluginRegisterStorageArea& p = | 1389 const _OrthancPluginRegisterStorageArea& p = |
1377 *reinterpret_cast<const _OrthancPluginRegisterStorageArea*>(parameters); | 1390 *reinterpret_cast<const _OrthancPluginRegisterStorageArea*>(parameters); |
1378 | 1391 |
1379 if (pimpl_->storageArea_.get() == NULL) | 1392 if (pimpl_->storageArea_.get() == NULL) |
1380 { | 1393 { |
1381 pimpl_->storageArea_.reset(new StorageAreaFactory(plugin, p)); | 1394 pimpl_->storageArea_.reset(new StorageAreaFactory(plugin, p, GetErrorDictionary())); |
1382 } | 1395 } |
1383 else | 1396 else |
1384 { | 1397 { |
1385 throw OrthancException(ErrorCode_StorageAreaAlreadyRegistered); | 1398 throw OrthancException(ErrorCode_StorageAreaAlreadyRegistered); |
1386 } | 1399 } |
1455 const _OrthancPluginRegisterDatabaseBackend& p = | 1468 const _OrthancPluginRegisterDatabaseBackend& p = |
1456 *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackend*>(parameters); | 1469 *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackend*>(parameters); |
1457 | 1470 |
1458 if (pimpl_->database_.get() == NULL) | 1471 if (pimpl_->database_.get() == NULL) |
1459 { | 1472 { |
1460 pimpl_->database_.reset(new OrthancPluginDatabase(plugin, *p.backend, NULL, 0, p.payload)); | 1473 pimpl_->database_.reset(new OrthancPluginDatabase(plugin, GetErrorDictionary(), |
1474 *p.backend, NULL, 0, p.payload)); | |
1461 } | 1475 } |
1462 else | 1476 else |
1463 { | 1477 { |
1464 throw OrthancException(ErrorCode_DatabaseBackendAlreadyRegistered); | 1478 throw OrthancException(ErrorCode_DatabaseBackendAlreadyRegistered); |
1465 } | 1479 } |
1476 const _OrthancPluginRegisterDatabaseBackendV2& p = | 1490 const _OrthancPluginRegisterDatabaseBackendV2& p = |
1477 *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackendV2*>(parameters); | 1491 *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackendV2*>(parameters); |
1478 | 1492 |
1479 if (pimpl_->database_.get() == NULL) | 1493 if (pimpl_->database_.get() == NULL) |
1480 { | 1494 { |
1481 pimpl_->database_.reset(new OrthancPluginDatabase(plugin, *p.backend, p.extensions, | 1495 pimpl_->database_.reset(new OrthancPluginDatabase(plugin, GetErrorDictionary(), |
1496 *p.backend, p.extensions, | |
1482 p.extensionsSize, p.payload)); | 1497 p.extensionsSize, p.payload)); |
1483 } | 1498 } |
1484 else | 1499 else |
1485 { | 1500 { |
1486 throw OrthancException(ErrorCode_DatabaseBackendAlreadyRegistered); | 1501 throw OrthancException(ErrorCode_DatabaseBackendAlreadyRegistered); |