# HG changeset patch # User Sebastien Jodogne # Date 1559899752 -7200 # Node ID b458aa0321a255045c4e8dbd17ecd331e2c9b9ae # Parent bff26b6f69f52832d52362c80976b873aea25937 testing multipart server diff -r bff26b6f69f5 -r b458aa0321a2 Plugin/Plugin.cpp --- a/Plugin/Plugin.cpp Thu Jun 06 16:49:12 2019 +0200 +++ b/Plugin/Plugin.cpp Fri Jun 07 11:29:12 2019 +0200 @@ -174,6 +174,65 @@ #include #include + +class StowServer : public OrthancPlugins::MultipartRestCallback +{ +private: + class Handler : public IHandler + { + private: + unsigned int count_; + + public: + Handler(unsigned int count) : + count_(count) + { + printf("new handler: %d\n", count_); + } + + virtual OrthancPluginErrorCode AddPart(const std::string& contentType, + const std::map& headers, + const void* data, + size_t size) + { + printf("%d - part received: %d\n", count_, size); + throw Orthanc::OrthancException(Orthanc::ErrorCode_CanceledJob); + return OrthancPluginErrorCode_Success; + } + + virtual OrthancPluginErrorCode Execute(OrthancPluginRestOutput* output) + { + printf("%d - execute\n", count_); + //throw Orthanc::OrthancException(Orthanc::ErrorCode_CanceledJob); + + std::string s = "ok"; + + OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), s.size(), "text/plain"); + return OrthancPluginErrorCode_Success; + } + }; + + unsigned int count_; + +public: + StowServer() : count_(0) + { + } + + virtual IHandler* CreateHandler(OrthancPluginHttpMethod method, + const std::string& url, + const std::string& contentType, + const std::vector& groups, + const std::map& headers) + { + return new Handler(count_++); + } +}; + + +static StowServer stowServer_; + + class StowClientBody : public OrthancPlugins::HttpClient::IRequestBody { private: @@ -308,6 +367,7 @@ OrthancPlugins::Configuration::Initialize(); //OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback); // TODO => REMOVE + //stowServer_.Register("/toto"); // TODO => REMOVE // Initialize GDCM OrthancPlugins::GdcmParsedDicomFile::Initialize();