Stellarium 0.15.2
List of all members | Public Member Functions | Protected Member Functions | Static Protected Attributes
AbstractAPIService Class Reference

Abstract base class for all Remote Control Plug-in service implementations. More...

#include <AbstractAPIService.hpp>

+ Inheritance diagram for AbstractAPIService:
+ Collaboration diagram for AbstractAPIService:

Public Member Functions

 AbstractAPIService (const QByteArray &serviceName, QObject *parent=0)
 Abstract constructor. The service name is used by the APIController for request path mapping. More...
 
QByteArray serviceName ()
 Returns the service name, used for request path mapping by the APIController. More...
 
virtual bool supportsThreadedOperation () const
 Return true if the service can safely be run in the HTTP handler thread, instead of having to queue it into the Stellarium main thread. More...
 
virtual void update (double deltaTime)
 Called in the main thread each frame. More...
 
Q_INVOKABLE APIServiceResponse get (const QByteArray &operation, const APIParameters &parameters)
 Wrapper around getImpl(), constructs an APIServiceResponse object for the response and passes it on. More...
 
Q_INVOKABLE APIServiceResponse post (const QByteArray &operation, const APIParameters &parameters, const QByteArray &data)
 Wrapper around postImpl(), constructs an APIServiceResponse object for the response and passes it on. More...
 

Protected Member Functions

virtual void getImpl (const QByteArray &operation, const APIParameters &parameters, APIServiceResponse &response)
 Subclasses should implement this to define reactions to HTTP GET requests. More...
 
virtual void postImpl (const QByteArray &operation, const APIParameters &parameters, const QByteArray &data, APIServiceResponse &response)
 Subclasses should implement this to define reactions to HTTP POST requests. More...
 
QString wrapHtml (QString &text, const QString &title) const
 Because the HTML descriptions in Stellarium are often not compatible with "clean" HTML5 which is used for the main interface, this method can be used to explicitely set the doctype to 4.01 transitional for better results, and include the stylesheet iframestyle.css. More...
 

Static Protected Attributes

static const Qt::ConnectionType SERVICE_DEFAULT_INVOKETYPE
 This defines the connection type QMetaObject::invokeMethod has to use inside a service: either Qt::DirectConnection for main thread handling, or Qt::BlockingQueuedConnection for HTTP thread handling. More...
 

Detailed Description

Abstract base class for all Remote Control Plug-in service implementations.

Different implementations of this class are mapped to different HTTP request paths. For each API request, the APIController finds out which service to use, and calls its get() or post() method.

Definition at line 89 of file AbstractAPIService.hpp.

Constructor & Destructor Documentation

AbstractAPIService::AbstractAPIService ( const QByteArray &  serviceName,
QObject *  parent = 0 
)
inline

Abstract constructor. The service name is used by the APIController for request path mapping.

Definition at line 94 of file AbstractAPIService.hpp.

Member Function Documentation

Q_INVOKABLE APIServiceResponse AbstractAPIService::get ( const QByteArray &  operation,
const APIParameters parameters 
)

Wrapper around getImpl(), constructs an APIServiceResponse object for the response and passes it on.

Note
The thread this is called in depends on the supportThreadedOperation() return value
virtual void AbstractAPIService::getImpl ( const QByteArray &  operation,
const APIParameters parameters,
APIServiceResponse response 
)
protectedvirtual

Subclasses should implement this to define reactions to HTTP GET requests.

GET requests generally should only query data or program state, and not change it. If there is an error with the request, use APIServiceResponse::writeRequestError to notify the client.

Parameters
operationThe operation string of the request (i.e. the part of the request URL after the service name, without parameters)
parametersThe extracted service parameters (extracted from the URL)
responseThe response object, write your response into this
Note
The thread this is called in depends on the supportThreadedOperation() return value

Reimplemented in MainService, LocationSearchService, ObjectService, SimbadService, LocationService, StelActionService, ViewService, ScriptService, and StelPropertyService.

Q_INVOKABLE APIServiceResponse AbstractAPIService::post ( const QByteArray &  operation,
const APIParameters parameters,
const QByteArray &  data 
)

Wrapper around postImpl(), constructs an APIServiceResponse object for the response and passes it on.

Note
The thread this is called in depends on the supportThreadedOperation() return value
virtual void AbstractAPIService::postImpl ( const QByteArray &  operation,
const APIParameters parameters,
const QByteArray &  data,
APIServiceResponse response 
)
protectedvirtual

Subclasses should implement this to define reactions to HTTP POST requests.

POST requests generally should change data or perform some action. If there is an error with the request, use APIServiceResponse::writeRequestError to notify the client.

Parameters
operationThe operation string of the request (i.e. the part of the request URL after the service name, without parameters)
parametersThe extracted service parameters (extracted from the URL, and form data, if applicable)
dataThe unmodified data as sent from the client
responseThe response object, write your response into this
Note
The thread this is called in depends on the supportThreadedOperation() return value

Reimplemented in MainService, LocationService, StelActionService, ScriptService, and StelPropertyService.

QByteArray AbstractAPIService::serviceName ( )
inline

Returns the service name, used for request path mapping by the APIController.

Definition at line 102 of file AbstractAPIService.hpp.

virtual bool AbstractAPIService::supportsThreadedOperation ( ) const
virtual

Return true if the service can safely be run in the HTTP handler thread, instead of having to queue it into the Stellarium main thread.

Default implementation returns false, i.e. no special threading precautions have to be used in the get() and post() implementation.

Warning
If the macro FORCE_THREADED_SERVICES is set, all services will be run in the HTTP threads for testing, and this method will be ignored.

Reimplemented in LocationSearchService, and SimbadService.

virtual void AbstractAPIService::update ( double  deltaTime)
virtual

Called in the main thread each frame.

Default implementation does nothing. Can be used for ongoing actions, for example movement control.

Reimplemented in MainService.

QString AbstractAPIService::wrapHtml ( QString &  text,
const QString &  title 
) const
protected

Because the HTML descriptions in Stellarium are often not compatible with "clean" HTML5 which is used for the main interface, this method can be used to explicitely set the doctype to 4.01 transitional for better results, and include the stylesheet iframestyle.css.

Parameters
textThe text to wrap with HTML document tags
titleThe title of the page

Member Data Documentation

const Qt::ConnectionType AbstractAPIService::SERVICE_DEFAULT_INVOKETYPE
staticprotected

This defines the connection type QMetaObject::invokeMethod has to use inside a service: either Qt::DirectConnection for main thread handling, or Qt::BlockingQueuedConnection for HTTP thread handling.

Definition at line 144 of file AbstractAPIService.hpp.


The documentation for this class was generated from the following file: