Mercurial > hg > orthanc
comparison Plugins/Engine/OrthancPlugins.cpp @ 1628:77c4cc4def0f
OrthancPluginErrorCode in REST callbacks
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 18 Sep 2015 16:46:35 +0200 |
parents | da7854deb662 |
children | ffd23c0104af |
comparison
equal
deleted
inserted
replaced
1627:da7854deb662 | 1628:77c4cc4def0f |
---|---|
62 private: | 62 private: |
63 boost::regex regex_; | 63 boost::regex regex_; |
64 OrthancPluginRestCallback callback_; | 64 OrthancPluginRestCallback callback_; |
65 bool lock_; | 65 bool lock_; |
66 | 66 |
67 int32_t InvokeInternal(HttpOutput& output, | 67 OrthancPluginErrorCode InvokeInternal(HttpOutput& output, |
68 const std::string& flatUri, | 68 const std::string& flatUri, |
69 const OrthancPluginHttpRequest& request) | 69 const OrthancPluginHttpRequest& request) |
70 { | 70 { |
71 return callback_(reinterpret_cast<OrthancPluginRestOutput*>(&output), | 71 return callback_(reinterpret_cast<OrthancPluginRestOutput*>(&output), |
72 flatUri.c_str(), | 72 flatUri.c_str(), |
73 &request); | 73 &request); |
74 } | 74 } |
86 const boost::regex& GetRegularExpression() const | 86 const boost::regex& GetRegularExpression() const |
87 { | 87 { |
88 return regex_; | 88 return regex_; |
89 } | 89 } |
90 | 90 |
91 int32_t Invoke(boost::recursive_mutex& restCallbackMutex, | 91 OrthancPluginErrorCode Invoke(boost::recursive_mutex& restCallbackMutex, |
92 HttpOutput& output, | 92 HttpOutput& output, |
93 const std::string& flatUri, | 93 const std::string& flatUri, |
94 const OrthancPluginHttpRequest& request) | 94 const OrthancPluginHttpRequest& request) |
95 { | 95 { |
96 if (lock_) | 96 if (lock_) |
97 { | 97 { |
98 boost::recursive_mutex::scoped_lock lock(restCallbackMutex); | 98 boost::recursive_mutex::scoped_lock lock(restCallbackMutex); |
99 return InvokeInternal(output, flatUri, request); | 99 return InvokeInternal(output, flatUri, request); |
333 request.headersKeys = &headersKeys[0]; | 333 request.headersKeys = &headersKeys[0]; |
334 request.headersValues = &headersValues[0]; | 334 request.headersValues = &headersValues[0]; |
335 } | 335 } |
336 | 336 |
337 assert(callback != NULL); | 337 assert(callback != NULL); |
338 int32_t error = callback->Invoke(pimpl_->restCallbackMutex_, output, flatUri, request); | 338 OrthancPluginErrorCode error = callback->Invoke(pimpl_->restCallbackMutex_, output, flatUri, request); |
339 | 339 |
340 if (error == 0 && | 340 if (error == OrthancPluginErrorCode_Success && |
341 output.IsWritingMultipart()) | 341 output.IsWritingMultipart()) |
342 { | 342 { |
343 output.CloseMultipart(); | 343 output.CloseMultipart(); |
344 } | 344 } |
345 | 345 |
346 if (error < 0) | 346 if (error == OrthancPluginErrorCode_Success) |
347 { | 347 { |
348 LOG(ERROR) << "Plugin callback failed with error code " << error; | 348 return true; |
349 return false; | |
350 } | 349 } |
351 else | 350 else |
352 { | 351 { |
353 if (error > 0) | 352 throw OrthancException(Plugins::Convert(error)); |
354 { | |
355 LOG(WARNING) << "Plugin callback finished with warning code " << error; | |
356 } | |
357 | |
358 return true; | |
359 } | 353 } |
360 } | 354 } |
361 | 355 |
362 | 356 |
363 void OrthancPlugins::SignalStoredInstance(const std::string& instanceId, | 357 void OrthancPlugins::SignalStoredInstance(const std::string& instanceId, |