diff --git a/Modules/CppRestSdkQt/include/mitkRESTManagerQt.h b/Modules/CppRestSdkQt/include/mitkRESTManagerQt.h index 6e79d71420..3e7078ff2a 100644 --- a/Modules/CppRestSdkQt/include/mitkRESTManagerQt.h +++ b/Modules/CppRestSdkQt/include/mitkRESTManagerQt.h @@ -1,89 +1,61 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkRESTManagerQt_h #define mitkRESTManagerQt_h #include #include #include #include #include #include #include namespace mitk { class MITKCPPRESTSDKQT_EXPORT RESTManagerQt : public QObject, public RESTManager { Q_OBJECT public: RESTManagerQt(); ~RESTManagerQt() override; - /** - * @brief Executes a HTTP request in the mitkRESTClientMicroService class - * - * @param uri defines the URI the request is send to - * @param type the RequestType of the HTTP request (optional) - * @param body the body for the request (optional) - * @param filePath the file path to store the request to - * @return task to wait for - */ - pplx::task SendRequest(const web::uri &uri, - const RequestType &type = get, - const web::json::value &body = NULL, - const utility::string_t &filePath = L"") override; - /** * @brief starts listening for requests if there isn't another observer listening and the port is free * * @param uri defines the URI for which incoming requests should be send to the observer * @param observer the observer which handles the incoming requests */ void ReceiveRequest(const web::uri &uri, IRESTObserver *observer) override; - /** - * @brief Handles incoming requests by notifying the observer which should receive it - * - * @param uri defines the URI of the request - * @param body the body of the request - * @return the data which is modified by the notified observer - */ - web::json::value Handle(const web::uri &uri, web::json::value &body) override; - /** * @brief Handles the deletion of an observer for all or a specific uri * * @param observer the observer which shouldn't receive requests anymore * @param uri the uri for which the observer doesn't handle requests anymore (optional) */ virtual void HandleDeleteObserver(IRESTObserver *observer, const web::uri &uri) override; - virtual std::map GetM_ServerMap() override; - virtual std::map, IRESTObserver *> GetM_Observers() override; - private: - //std::map m_ServerMap; // Map with port server pairs std::map m_ServerThreadMap; // Map with threads for servers - //std::map, IRESTObserver *> m_Observers; // Map with all observers }; } // namespace mitk #endif // !mitkRESTManager_h \ No newline at end of file diff --git a/Modules/CppRestSdkQt/src/mitkRESTManagerQt.cpp b/Modules/CppRestSdkQt/src/mitkRESTManagerQt.cpp index 9f3cd66e0d..ae03300e43 100644 --- a/Modules/CppRestSdkQt/src/mitkRESTManagerQt.cpp +++ b/Modules/CppRestSdkQt/src/mitkRESTManagerQt.cpp @@ -1,105 +1,79 @@ #include "mitkRESTManagerQt.h" -#include #include mitk::RESTManagerQt::RESTManagerQt() {} mitk::RESTManagerQt::~RESTManagerQt() {} - -pplx::task mitk::RESTManagerQt::SendRequest(const web::uri &uri, - const RequestType &type, - const web::json::value &content, - const utility::string_t &filePath) -{ - return mitk::RESTManager::SendRequest(uri, type, content, filePath); -} - - void mitk::RESTManagerQt::ReceiveRequest(const web::uri &uri, mitk::IRESTObserver *observer) { // New instance of RESTServerMicroservice in m_ServerMap, key is port of the request int port = uri.port(); // Checking if port is free to add a new Server if (m_ServerMap.count(port) == 0) { mitk::RESTManager::AddObserver(uri, observer); // creating server instance RESTServerMicroServiceQt *server = new RESTServerMicroServiceQt(uri.authority()); // add reference to server instance to map m_ServerMap[port] = server; // Move server to seperate Thread and create connections between threads m_ServerThreadMap[port] = new QThread; server->moveToThread(m_ServerThreadMap[port]); connect(m_ServerThreadMap[port], &QThread::finished, server, &QObject::deleteLater); // starting Server m_ServerThreadMap[port]->start(); QMetaObject::invokeMethod(server, "OpenListener"); utility::string_t host = uri.authority().to_string(); std::string hoststring(host.begin(), host.end()); MITK_INFO << "new server" << hoststring << " at port" << port; } // If there is already a server under this port else { mitk::RESTManager::ServerUnderPort(uri, observer); } } - web::json::value mitk::RESTManagerQt::Handle(const web::uri &uri, web::json::value &body) -{ - return mitk::RESTManager::Handle(uri, body); -} - void mitk::RESTManagerQt::HandleDeleteObserver(IRESTObserver *observer, const web::uri &uri = L"") { for (auto it = m_Observers.begin(); it != m_Observers.end();) { mitk::IRESTObserver *obsMap = it->second; // Check wether observer is at this place in map if (obsMap == observer) { // Check wether it is the right uri to be deleted if (uri == L"" || it->first.second == uri.path()) { int port = it->first.first; bool noObserverForPort = mitk::RESTManager::DeleteObserver(it, uri); if (noObserverForPort) { // there isn't an observer at this port, delete m_ServerMap entry for this port // close listener QMetaObject::invokeMethod(static_cast(m_ServerMap[port]), "CloseListener"); // end thread m_ServerThreadMap[port]->quit(); m_ServerThreadMap[port]->wait(); // delete server from map m_ServerMap.erase(port); } } else { ++it; } } else { ++it; } } } - -std::map mitk::RESTManagerQt::GetM_ServerMap() -{ - return mitk::RESTManager::GetM_ServerMap(); -} - -std::map, mitk::IRESTObserver *> mitk::RESTManagerQt::GetM_Observers() -{ - return mitk::RESTManager::GetM_Observers(); -} \ No newline at end of file