本文整理汇总了C++中OrthancException函数的典型用法代码示例。如果您正苦于以下问题:C++ OrthancException函数的具体用法?C++ OrthancException怎么用?C++ OrthancException使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OrthancException函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OrthancException
void HttpClient::Setup()
{
pimpl_->postHeaders_ = NULL;
if ((pimpl_->postHeaders_ = curl_slist_append(pimpl_->postHeaders_, "Expect:")) == NULL)
{
throw OrthancException(ErrorCode_NotEnoughMemory);
}
pimpl_->curl_ = curl_easy_init();
if (!pimpl_->curl_)
{
curl_slist_free_all(pimpl_->postHeaders_);
throw OrthancException(ErrorCode_NotEnoughMemory);
}
CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEFUNCTION, &CurlCallback));
CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADER, 0));
CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 1));
#if ORTHANC_SSL_ENABLED == 1
CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSL_VERIFYPEER, 0));
#endif
// This fixes the "longjmp causes uninitialized stack frame" crash
// that happens on modern Linux versions.
// http://stackoverflow.com/questions/9191668/error-longjmp-causes-uninitialized-stack-frame
CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOSIGNAL, 1));
url_ = "";
method_ = HttpMethod_Get;
lastStatus_ = HttpStatus_200_Ok;
isVerbose_ = false;
timeout_ = 0;
}
示例2: PngRabi
PngRabi()
{
png_ = NULL;
info_ = NULL;
endInfo_ = NULL;
png_ = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_)
{
throw OrthancException(ErrorCode_NotEnoughMemory);
}
info_ = png_create_info_struct(png_);
if (!info_)
{
png_destroy_read_struct(&png_, NULL, NULL);
throw OrthancException(ErrorCode_NotEnoughMemory);
}
endInfo_ = png_create_info_struct(png_);
if (!info_)
{
png_destroy_read_struct(&png_, &info_, NULL);
throw OrthancException(ErrorCode_NotEnoughMemory);
}
}
示例3: path_
SharedLibrary::SharedLibrary(const std::string& path) :
path_(path),
handle_(NULL)
{
#if defined(_WIN32)
handle_ = ::LoadLibraryA(path_.c_str());
if (handle_ == NULL)
{
LOG(ERROR) << "LoadLibrary(" << path_ << ") failed: Error " << ::GetLastError();
throw OrthancException(ErrorCode_SharedLibrary);
}
#elif defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
handle_ = ::dlopen(path_.c_str(), RTLD_NOW);
if (handle_ == NULL)
{
std::string explanation;
const char *tmp = ::dlerror();
if (tmp)
{
explanation = ": Error " + std::string(tmp);
}
LOG(ERROR) << "dlopen(" << path_ << ") failed" << explanation;
throw OrthancException(ErrorCode_SharedLibrary);
}
#else
#error Support your platform here
#endif
}
示例4: switch
void HttpOutput::StateMachine::CloseBody()
{
switch (state_)
{
case State_WritingHeader:
SetContentLength(0);
SendBody(NULL, 0);
break;
case State_WritingBody:
if (!hasContentLength_ ||
contentPosition_ == contentLength_)
{
state_ = State_Done;
}
else
{
LOG(ERROR) << "The body size has not reached what was declared with SetContentSize()";
throw OrthancException(ErrorCode_BadSequenceOfCalls);
}
break;
case State_WritingMultipart:
LOG(ERROR) << "Cannot invoke CloseBody() with multipart outputs";
throw OrthancException(ErrorCode_BadSequenceOfCalls);
case State_Done:
return; // Ignore
default:
throw OrthancException(ErrorCode_InternalError);
}
}
示例5: OrthancException
StatementReference::~StatementReference()
{
if (IsRoot())
{
if (refCount_ != 0)
{
// There remain references to this object
throw OrthancException(ErrorCode_InternalError);
}
else if (statement_ != NULL)
{
sqlite3_finalize(statement_);
}
}
else
{
if (root_->refCount_ == 0)
{
throw OrthancException(ErrorCode_InternalError);
}
else
{
root_->refCount_--;
}
}
}
示例6: OrthancException
void PngReader::ReadFromMemory(const void* buffer,
size_t size)
{
if (size < 8)
{
throw OrthancException(ErrorCode_BadFileFormat);
}
CheckHeader(buffer);
PngRabi rabi;
if (setjmp(png_jmpbuf(rabi.png_)))
{
rabi.Destruct();
throw OrthancException(ErrorCode_BadFileFormat);
}
MemoryBuffer tmp;
tmp.buffer_ = reinterpret_cast<const uint8_t*>(buffer) + 8; // We skip the header
tmp.size_ = size - 8;
tmp.pos_ = 0;
tmp.ok_ = true;
png_set_read_fn(rabi.png_, &tmp, PngRabi::MemoryCallback);
Read(rabi);
if (!tmp.ok_)
{
throw OrthancException(ErrorCode_BadFileFormat);
}
}
示例7: Prepare
void PngWriter::WriteToFile(const char* filename,
unsigned int width,
unsigned int height,
unsigned int pitch,
PixelFormat format,
const void* buffer)
{
Prepare(width, height, pitch, format, buffer);
FILE* fp = fopen(filename, "wb");
if (!fp)
{
throw OrthancException(ErrorCode_CannotWriteFile);
}
png_init_io(pimpl_->png_, fp);
if (setjmp(png_jmpbuf(pimpl_->png_)))
{
// Error during writing PNG
throw OrthancException(ErrorCode_CannotWriteFile);
}
Compress(width, height, pitch, format);
fclose(fp);
}
示例8: OrthancException
void DicomServer::SetApplicationEntityTitle(const std::string& aet)
{
if (aet.size() == 0)
{
throw OrthancException(ErrorCode_BadApplicationEntityTitle);
}
if (aet.size() > 16)
{
throw OrthancException(ErrorCode_BadApplicationEntityTitle);
}
for (size_t i = 0; i < aet.size(); i++)
{
if (!(aet[i] == '-' ||
aet[i] == '_' ||
isdigit(aet[i]) ||
(aet[i] >= 'A' && aet[i] <= 'Z')))
{
LOG(WARNING) << "For best interoperability, only upper case, alphanumeric characters should be present in AET: \"" << aet << "\"";
break;
}
}
Stop();
aet_ = aet;
}
示例9: Prepare
void PngWriter::WriteToFileInternal(const std::string& filename,
unsigned int width,
unsigned int height,
unsigned int pitch,
PixelFormat format,
const void* buffer)
{
Prepare(width, height, pitch, format, buffer);
FILE* fp = Toolbox::OpenFile(filename, FileMode_WriteBinary);
if (!fp)
{
throw OrthancException(ErrorCode_CannotWriteFile);
}
png_init_io(pimpl_->png_, fp);
if (setjmp(png_jmpbuf(pimpl_->png_)))
{
// Error during writing PNG
throw OrthancException(ErrorCode_CannotWriteFile);
}
Compress(width, height, pitch, format);
fclose(fp);
}
示例10: OrthancException
void ZipWriter::Open()
{
if (IsOpen())
{
return;
}
if (path_.size() == 0)
{
throw OrthancException("Please call SetOutputPath() before creating the file");
}
hasFileInZip_ = false;
if (isZip64_)
{
pimpl_->file_ = zipOpen64(path_.c_str(), APPEND_STATUS_CREATE);
}
else
{
pimpl_->file_ = zipOpen(path_.c_str(), APPEND_STATUS_CREATE);
}
if (!pimpl_->file_)
{
throw OrthancException(ErrorCode_CannotWriteFile);
}
}
示例11: ParseListOfTags
static void ParseListOfTags(DicomModification& target,
const Json::Value& query,
TagOperation operation)
{
if (!query.isArray())
{
throw OrthancException(ErrorCode_BadRequest);
}
for (Json::Value::ArrayIndex i = 0; i < query.size(); i++)
{
std::string name = query[i].asString();
DicomTag tag = FromDcmtkBridge::ParseTag(name);
switch (operation)
{
case TagOperation_Keep:
target.Keep(tag);
VLOG(1) << "Keep: " << name << " " << tag << std::endl;
break;
case TagOperation_Remove:
target.Remove(tag);
VLOG(1) << "Remove: " << name << " " << tag << std::endl;
break;
default:
throw OrthancException(ErrorCode_InternalError);
}
}
}
示例12: compressBound
void ZlibCompressor::Compress(std::string& compressed,
const void* uncompressed,
size_t uncompressedSize)
{
if (uncompressedSize == 0)
{
compressed.clear();
return;
}
uLongf compressedSize = compressBound(uncompressedSize) + 1024 /* security margin */;
if (compressedSize == 0)
{
compressedSize = 1;
}
uint8_t* target;
if (HasPrefixWithUncompressedSize())
{
compressed.resize(compressedSize + sizeof(uint64_t));
target = reinterpret_cast<uint8_t*>(&compressed[0]) + sizeof(uint64_t);
}
else
{
compressed.resize(compressedSize);
target = reinterpret_cast<uint8_t*>(&compressed[0]);
}
int error = compress2(target,
&compressedSize,
const_cast<Bytef *>(static_cast<const Bytef *>(uncompressed)),
uncompressedSize,
GetCompressionLevel());
if (error != Z_OK)
{
compressed.clear();
switch (error)
{
case Z_MEM_ERROR:
throw OrthancException(ErrorCode_NotEnoughMemory);
default:
throw OrthancException(ErrorCode_InternalError);
}
}
// The compression was successful
if (HasPrefixWithUncompressedSize())
{
uint64_t s = static_cast<uint64_t>(uncompressedSize);
memcpy(&compressed[0], &s, sizeof(uint64_t));
compressed.resize(compressedSize + sizeof(uint64_t));
}
else
{
compressed.resize(compressedSize);
}
}
示例13: OrthancException
void DicomInstanceToStore::ComputeMissingInformation()
{
if (buffer_.HasContent() &&
summary_.HasContent() &&
json_.HasContent())
{
// Fine, everything is available
return;
}
if (!buffer_.HasContent())
{
if (!parsed_.HasContent())
{
throw OrthancException(ErrorCode_NotImplemented);
}
else
{
// Serialize the parsed DICOM file
buffer_.Allocate();
if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer_.GetContent(), GetDataset(parsed_.GetContent())))
{
LOG(ERROR) << "Unable to serialize a DICOM file to a memory buffer";
throw OrthancException(ErrorCode_InternalError);
}
}
}
if (summary_.HasContent() &&
json_.HasContent())
{
return;
}
// At this point, we know that the DICOM file is available as a
// memory buffer, but that its summary or its JSON version is
// missing
if (!parsed_.HasContent())
{
parsed_.TakeOwnership(new ParsedDicomFile(buffer_.GetConstContent()));
}
// At this point, we have parsed the DICOM file
if (!summary_.HasContent())
{
summary_.Allocate();
FromDcmtkBridge::Convert(summary_.GetContent(), GetDataset(parsed_.GetContent()));
}
if (!json_.HasContent())
{
json_.Allocate();
FromDcmtkBridge::ToJson(json_.GetContent(), GetDataset(parsed_.GetContent()));
}
}
示例14: LoadEngine
static ENGINE* LoadEngine()
{
// This function creates an engine for PKCS#11 and inspired by
// the "ENGINE_load_dynamic" function from OpenSSL, in file
// "crypto/engine/eng_dyn.c"
ENGINE* engine = ENGINE_new();
if (!engine)
{
LOG(ERROR) << "Cannot create an OpenSSL engine for PKCS#11";
throw OrthancException(ErrorCode_InternalError);
}
// Create a PKCS#11 context using libp11
context_ = pkcs11_new();
if (!context_)
{
LOG(ERROR) << "Cannot create a libp11 context for PKCS#11";
ENGINE_free(engine);
throw OrthancException(ErrorCode_InternalError);
}
if (!ENGINE_set_id(engine, PKCS11_ENGINE_ID) ||
!ENGINE_set_name(engine, PKCS11_ENGINE_NAME) ||
!ENGINE_set_cmd_defns(engine, PKCS11_ENGINE_COMMANDS) ||
// Register the callback functions
!ENGINE_set_init_function(engine, EngineInitialize) ||
!ENGINE_set_finish_function(engine, EngineFinalize) ||
!ENGINE_set_destroy_function(engine, EngineDestroy) ||
!ENGINE_set_ctrl_function(engine, EngineControl) ||
!ENGINE_set_load_pubkey_function(engine, EngineLoadPublicKey) ||
!ENGINE_set_load_privkey_function(engine, EngineLoadPrivateKey) ||
!ENGINE_set_RSA(engine, PKCS11_get_rsa_method()) ||
!ENGINE_set_ECDSA(engine, PKCS11_get_ecdsa_method()) ||
!ENGINE_set_ECDH(engine, PKCS11_get_ecdh_method()) ||
#if OPENSSL_VERSION_NUMBER >= 0x10100002L
!ENGINE_set_EC(engine, PKCS11_get_ec_key_method()) ||
#endif
// Make OpenSSL know about our PKCS#11 engine
!ENGINE_add(engine))
{
LOG(ERROR) << "Cannot initialize the OpenSSL engine for PKCS#11";
pkcs11_finish(context_);
ENGINE_free(engine);
throw OrthancException(ErrorCode_InternalError);
}
// If the "ENGINE_add" worked, it gets a structural
// reference. We release our just-created reference.
ENGINE_free(engine);
return ENGINE_by_id(PKCS11_ENGINE_ID);
}
示例15: OrthancException
void Toolbox::SplitUriComponents(UriComponents& components,
const std::string& uri)
{
static const char URI_SEPARATOR = '/';
components.clear();
if (uri.size() == 0 ||
uri[0] != URI_SEPARATOR)
{
throw OrthancException(ErrorCode_UriSyntax);
}
// Count the number of slashes in the URI to make an assumption
// about the number of components in the URI
unsigned int estimatedSize = 0;
for (unsigned int i = 0; i < uri.size(); i++)
{
if (uri[i] == URI_SEPARATOR)
estimatedSize++;
}
components.reserve(estimatedSize - 1);
unsigned int start = 1;
unsigned int end = 1;
while (end < uri.size())
{
// This is the loop invariant
assert(uri[start - 1] == '/' && (end >= start));
if (uri[end] == '/')
{
components.push_back(std::string(&uri[start], end - start));
end++;
start = end;
}
else
{
end++;
}
}
if (start < uri.size())
{
components.push_back(std::string(&uri[start], end - start));
}
for (size_t i = 0; i < components.size(); i++)
{
if (components[i].size() == 0)
{
// Empty component, as in: "/coucou//e"
throw OrthancException(ErrorCode_UriSyntax);
}
}
}