APIController.hpp   APIController.hpp 
skipping to change at line 26 skipping to change at line 26
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#ifndef APIHANDLER_HPP_ #ifndef APIHANDLER_HPP_
#define APIHANDLER_HPP_ #define APIHANDLER_HPP_
#include "httpserver/httprequesthandler.h" #include "httpserver/httprequesthandler.h"
#include "AbstractAPIService.hpp" #include "AbstractAPIService.hpp"
#include <QMutex>
//! @ingroup remoteControl //! @ingroup remoteControl
//! This class handles the API-specific requests and dispatches them to the correct AbstractAPISerice implementation. //! This class handles the API-specific requests and dispatches them to the correct RemoteControlServiceInterface implementation.
//! Services are registered using registerService(). //! Services are registered using registerService().
//! To see the default services used, see the RequestHandler::RequestHandle r constructor. //! To see the default services used, see the RequestHandler::RequestHandle r constructor.
class APIController : public HttpRequestHandler class APIController : public HttpRequestHandler
{ {
Q_OBJECT Q_OBJECT
public: public:
//! Constructs an APIController //! Constructs an APIController
//! @param prefixLength Determines how many characters to strip from the front of the request path //! @param prefixLength Determines how many characters to strip from the front of the request path
//! @param parent passed on to QObject constructor //! @param parent passed on to QObject constructor
APIController(int prefixLength, QObject* parent = 0); APIController(int prefixLength, QObject* parent = Q_NULLPTR);
virtual ~APIController(); virtual ~APIController();
//! Should be called each frame from the main thread, like from Stel Module::update. //! Should be called each frame from the main thread, like from Stel Module::update.
//! Passed on to each AbstractAPIService::update method for optional processing. //! Passed on to each AbstractAPIService::update method for optional processing.
void update(double deltaTime); void update(double deltaTime);
//! Handles an API-specific request. It finds out which AbstractAPIS ervice to use //! Handles an API-specific request. It finds out which RemoteContro lServiceInterface to use
//! depending on the service name (first part of path until slash). An error is returned for invalid requests. //! depending on the service name (first part of path until slash). An error is returned for invalid requests.
//! If a service was found, the request is passed on to its Abstract APIService::get or AbstractAPIService::post //! If a service was found, the request is passed on to its RemoteCo ntrolServiceInterface::get or RemoteControlServiceInterface::post
//! method depending on the HTTP request type. //! method depending on the HTTP request type.
//! If AbstractAPIService::supportsThreadedOperation is false, these methods are called in the Stellarium main thread //! If RemoteControlServiceInterface::isThreadSafe is false, these m ethods are called in the Stellarium main thread
//! using QMetaObject::invokeMethod, otherwise they are directly exe cuted in the current thread (HTTP worker thread). //! using QMetaObject::invokeMethod, otherwise they are directly exe cuted in the current thread (HTTP worker thread).
virtual void service(HttpRequest& request, HttpResponse& response); virtual void service(HttpRequest& request, HttpResponse& response);
//! Registers a service with the APIController. //! Registers a service with the APIController.
//! The AbstractAPIService::serviceName() determines the request pat //! The RemoteControlServiceInterface::getPath() determines the requ
h of the service. est path of the service.
void registerService(AbstractAPIService* service); void registerService(RemoteControlServiceInterface* service);
private slots:
void performGet(RemoteControlServiceInterface* service, const QByteA
rray& operation, const APIParameters& parameters, APIServiceResponse* respo
nse);
void performPost(RemoteControlServiceInterface* service, const QByte
Array& operation, const APIParameters& parameters, const QByteArray& data,
APIServiceResponse* response);
private: private:
static void applyAPIResponse(const APIServiceResponse& apiresponse, HttpResponse& httpresponse);
int m_prefixLength; int m_prefixLength;
typedef QMap<QByteArray,AbstractAPIService*> ServiceMap; typedef QMap<QByteArray,RemoteControlServiceInterface*> ServiceMap;
ServiceMap m_serviceMap; ServiceMap m_serviceMap;
QMutex mutex;
}; };
#endif #endif
 End of changes. 10 change blocks. 
12 lines changed or deleted 17 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/