Stellarium  0.90.0
APIController.hpp
1 /*
2  * Stellarium Remote Control plugin
3  * Copyright (C) 2015 Florian Schaukowitsch
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef APIHANDLER_HPP_
21 #define APIHANDLER_HPP_
22 
24 #include "AbstractAPIService.hpp"
25 
31 {
32  Q_OBJECT
33 public:
37  APIController(int prefixLength, QObject* parent = Q_NULLPTR);
38  virtual ~APIController();
39 
42  void update(double deltaTime);
43 
50  virtual void service(HttpRequest& request, HttpResponse& response);
51 
55 private slots:
56  void performGet(RemoteControlServiceInterface* service, const QByteArray& operation, const APIParameters& parameters, APIServiceResponse* response);
57  void performPost(RemoteControlServiceInterface* service, const QByteArray& operation, const APIParameters& parameters, const QByteArray& data, APIServiceResponse* response);
58 private:
59  static void applyAPIResponse(const APIServiceResponse& apiresponse, HttpResponse& httpresponse);
60  int m_prefixLength;
61  typedef QMap<QByteArray,RemoteControlServiceInterface*> ServiceMap;
62  ServiceMap m_serviceMap;
63 };
64 
65 #endif
The request handler generates a response for each HTTP request.
virtual void service(HttpRequest &request, HttpResponse &response)
Handles an API-specific request.
Thread-safe version of HttpResponse that can be passed around through QMetaObject::invokeMethod.
QMultiMap< QByteArray, QByteArray > APIParameters
Defines the HTTP request parameters for the service.
APIController(int prefixLength, QObject *parent=Q_NULLPTR)
Constructs an APIController.
void update(double deltaTime)
Should be called each frame from the main thread, like from StelModule::update.
Interface for all Remote Control Plug-in services.
This object represents a single HTTP request.
Definition: httprequest.h:36
This class handles the API-specific requests and dispatches them to the correct RemoteControlServiceI...
void registerService(RemoteControlServiceInterface *service)
Registers a service with the APIController.
This object represents a HTTP response, used to return something to the web client.
Definition: httpresponse.h:35