diff --git a/Modules/CppRestSdk/include/mitkIRESTManager.h b/Modules/CppRestSdk/include/mitkIRESTManager.h index 331bc6aeed..27cec032b7 100644 --- a/Modules/CppRestSdk/include/mitkIRESTManager.h +++ b/Modules/CppRestSdk/include/mitkIRESTManager.h @@ -1,37 +1,81 @@ +/*=================================================================== + +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 mitkIRESTManager_h #define mitkIRESTManager_h #include "cpprest/uri.h" #include "cpprest/json.h" #include #include #include namespace mitk { class IRESTManager { public: virtual ~IRESTManager(); enum RequestType { get, post, put }; - virtual pplx::task SendRequest(web::uri uri, RequestType type = get, web::json::value = NULL) = 0; + /** + * @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) + * @return task to wait for + */ + virtual pplx::task SendRequest(web::uri uri, RequestType type = get, web::json::value body= NULL) = 0; + /** + * @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 + */ virtual void ReceiveRequest(web::uri uri, IRESTObserver *observer) = 0; - virtual web::json::value Handle(web::uri, web::json::value) = 0; - //virtual void HandleDeleteObserver(IRESTObserver *observer) = 0; - virtual void HandleDeleteObserver(IRESTObserver *observer, web::uri = L"") = 0; + + /** + * @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 + */ + virtual web::json::value Handle(web::uri uri, web::json::value body) = 0; + + /** + * @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, web::uri uri = L"") = 0; }; } // namespace mitk MITK_DECLARE_SERVICE_INTERFACE(mitk::IRESTManager, "org.mitk.IRESTManager") #endif diff --git a/Modules/CppRestSdk/include/mitkIRESTObserver.h b/Modules/CppRestSdk/include/mitkIRESTObserver.h index 2210808c98..097c948e6c 100644 --- a/Modules/CppRestSdk/include/mitkIRESTObserver.h +++ b/Modules/CppRestSdk/include/mitkIRESTObserver.h @@ -1,20 +1,48 @@ +/*=================================================================== + +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 mitkIRESTObserver_h #define mitkIRESTObserver_h #include "cpprest/json.h" #include namespace mitk { class MITKCPPRESTSDK_EXPORT IRESTObserver { public: + /** + * @brief Deletes an observer and calls HandleDeleteObserver() in RESTManager class + * + * @see HandleDeleteObserver() + */ virtual ~IRESTObserver(); + + /** + * @brief Called if there's an incoming request for the observer, observer implements how to handle request + * + * @param data the data of the incoming request + * @return the modified data + */ virtual web::json::value Notify(web::json::value data) = 0; private: }; } #endif // !mitkIRESTObserver diff --git a/Modules/CppRestSdk/include/mitkRESTClientMicroService.h b/Modules/CppRestSdk/include/mitkRESTClientMicroService.h index 377d5e0afa..ea0cbca9eb 100644 --- a/Modules/CppRestSdk/include/mitkRESTClientMicroService.h +++ b/Modules/CppRestSdk/include/mitkRESTClientMicroService.h @@ -1,78 +1,78 @@ /*=================================================================== 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 mitkRESTClientMicroService_h #define mitkRESTClientMicroService_h #include "cpprest/asyncrt_utils.h" #include "cpprest/containerstream.h" #include "cpprest/http_client.h" #include "cpprest/json.h" #include "cpprest/producerconsumerstream.h" #include "cpprest/uri.h" #include "MitkCppRestSdkExports.h" #include #include #include #include typedef web::http::client::http_client MitkClient; typedef web::http::http_request MitkRequest; typedef web::http::http_response MitkResponse; typedef web::http::methods MitkRESTMethods; typedef web::http::uri_builder MitkUriBuilder; typedef web::http::status_codes MitkRestStatusCodes; typedef web::json::json_exception MitkJsonException; namespace mitk { class RESTClientMicroService { public: RESTClientMicroService(); ~RESTClientMicroService(); /** - * @brief Executes a HTTP GET request with the given uri and returns a task waiting for a json object + *@brief Executes a HTTP GET request with the given uri and returns a task waiting for a json object * * @param uri the URI resulting the target of the HTTP request * @return task with to wait for with resulting json object */ pplx::task Get(web::uri uri); /** * @brief Executes a HTTP PUT request with given uri and the content given as json * * @param uri defines the URI resulting the target of the HTTP request * @param content the content as json value which should be the body of the request and thus the content of the * created resources * @return task to wait for with resulting json object */ pplx::task PUT(web::uri uri, web::json::value content); /** * @brief Executes a HTTP POST request with given uri and the content given as json * * @param uri defines the URI resulting the target of the HTTP request * @param content the content as json value which should be the body of the request and thus the content of the created resource * @return task to wait for with resulting json object */ pplx::task POST(web::uri uri, web::json::value content); }; } // namespace mitk #endif // !mitkRESTClientMicroService_h diff --git a/Modules/CppRestSdk/include/mitkRESTManager.h b/Modules/CppRestSdk/include/mitkRESTManager.h index 4aa1201487..f3c8a6e114 100644 --- a/Modules/CppRestSdk/include/mitkRESTManager.h +++ b/Modules/CppRestSdk/include/mitkRESTManager.h @@ -1,41 +1,82 @@ +/*=================================================================== + +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 mitkRESTManager_h #define mitkRESTManager_h #include #include #include #include #include #include #include namespace mitk { class MITKCPPRESTSDK_EXPORT RESTManager : public QObject, public IRESTManager { Q_OBJECT public: RESTManager(); ~RESTManager() override; - // calls RESTClient + /** + * @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) + * @return task to wait for + */ pplx::task SendRequest(web::uri uri, RequestType type = get, web::json::value = NULL) override; - // calls RESTServer + + /** + * @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(web::uri uri, IRESTObserver *observer) override; - web::json::value Handle(web::uri, web::json::value) 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(web::uri uri, web::json::value body) override; - //virtual void HandleDeleteObserver(IRESTObserver *observer) override; - virtual void HandleDeleteObserver(IRESTObserver *observer, web::uri) 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, web::uri uri) override; private: std::map m_ClientMap; // Map with port client pairs std::map m_ServerMap; // Map with port server pairs std::map m_ServerThreadMap; // Map with threads for servers std::map, IRESTObserver *> m_Observer; // Map with all observers }; } // namespace mitk #endif // !mitkRESTManager_h diff --git a/Modules/CppRestSdk/include/mitkRESTServerMicroService.h b/Modules/CppRestSdk/include/mitkRESTServerMicroService.h index 6f9c7723e3..ca3673ba14 100644 --- a/Modules/CppRestSdk/include/mitkRESTServerMicroService.h +++ b/Modules/CppRestSdk/include/mitkRESTServerMicroService.h @@ -1,66 +1,82 @@ +/*=================================================================== + +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 mitkRESTServerMicroService_h #define mitkRESTServerMicroService_h #include #include "cpprest/asyncrt_utils.h" #include "cpprest/containerstream.h" #include "cpprest/filestream.h" #include "cpprest/http_listener.h" #include "cpprest/json.h" #include "cpprest/producerconsumerstream.h" #include "cpprest/uri.h" #include "MitkCppRestSdkExports.h" #include #include #include #include typedef web::http::experimental::listener::http_listener MitkListener; typedef web::http::http_request MitkRequest; typedef web::http::http_response MitkResponse; typedef web::http::methods MitkRESTMethods; typedef web::http::status_codes MitkRestStatusCodes; typedef web::json::json_exception MitkJsonException; namespace mitk { class RESTServerMicroService : public QObject { Q_OBJECT public: /** * @brief Creates an server listening to the given URI * * @param uri the URI at which the server is listening for requests */ RESTServerMicroService(web::uri uri); ~RESTServerMicroService(); web::uri GetUri(); private: /** * @brief Handle for incoming GET requests * * @param MitkRequest incoming request object */ void HandleGet(MitkRequest request); MitkListener m_Listener; web::uri m_Uri; public slots: /** * @brief Opens the listener and starts the listening process */ void OpenListener(); /** * @brief Closes the listener and stops the listening process */ void CloseListener(); }; } // namespace mitk #endif \ No newline at end of file diff --git a/Modules/CppRestSdk/src/mitkCppRestSdkActivator.h b/Modules/CppRestSdk/src/mitkCppRestSdkActivator.h index 9d7a416ad2..6e368eb4d3 100644 --- a/Modules/CppRestSdk/src/mitkCppRestSdkActivator.h +++ b/Modules/CppRestSdk/src/mitkCppRestSdkActivator.h @@ -1,21 +1,37 @@ +/*=================================================================== + +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 MITKCPPRESTSDKACTIVATOR_H_ #define MITKCPPRESTSDKACTIVATOR_H_ #include #include #include #include #include class MitkCppRestSdkActivator : public us::ModuleActivator { public: void Load(us::ModuleContext *context) override; void Unload(us::ModuleContext *) override; private: std::unique_ptr m_RESTManager; }; #endif