RPC server base class.
More...
#include <rec_rpc_Server.h>
RPC server base class.
Base class to implement a RPC server. Derive from that class to implement your own server.
Definition at line 176 of file rec_rpc_Server.h.
rec::rpc::Server::Server |
( |
QObject * |
parent = 0 | ) |
|
virtual rec::rpc::Server::~Server |
( |
| ) |
|
|
virtual |
void rec::rpc::Server::addEnqueuedTopic |
( |
const QString & |
name, |
|
|
bool |
serverOnly = false |
|
) |
| |
|
protected |
Add a non permanent enqueued topic.
This method is used to register a topic in the server. The server and the clients can publish data via the topic. The data is distributed via local IPC or the TCP connection. It is recommended to use the preprocessor macro instead of calling the method directly.
With a non permanent enqueued topic topic listeners are called only when someone published new data to the topic. It is ensured that no data published is dropped. This is different to a non enqueued topic where data can be dropped if published to fast. Enqueued topics can not use shared memory.
- Parameters
-
name | Name of the topic. |
serverOnly | Set to true if only the server should be able to publish data via this topic |
- Exceptions
-
- See also
- ADD_TOPIC, addPermanentTopic
void rec::rpc::Server::addPermanentTopic |
( |
const QString & |
name, |
|
|
int |
sharedMemorySize = 0 , |
|
|
bool |
serverOnly = false |
|
) |
| |
|
protected |
Add a permanent topic.
This method is used to register a topic in the server. The server and the clients can publish data via the topic. The data is distributed via shared memory, local IPC or the TCP connection. It is recommended to use the preprocessor macro instead of calling the method directly.
With a permanent topic topic listeners are called once after they registered to the topic and someone already published data into this topic.
- Parameters
-
name | Name of the topic. |
sharedMemorySize | Minimum size of the shared memory segment in bytes. If 0 (default), no shared memory will be used. |
serverOnly | Set to true if only the server should be able to publish data via this topic |
- Exceptions
-
- See also
- ADD_TOPIC, addTopic
void rec::rpc::Server::addTopic |
( |
const QString & |
name, |
|
|
int |
sharedMemorySize = 0 , |
|
|
bool |
serverOnly = false |
|
) |
| |
|
protected |
Add a non permanent topic.
This method is used to register a topic in the server. The server and the clients can publish data via the topic. The data is distributed via shared memory, local IPC or the TCP connection. It is recommended to use the preprocessor macro instead of calling the method directly.
With a non permanent topic topic listeners are called only when someone published new data to the topic.
- Parameters
-
name | Name of the topic. |
sharedMemorySize | Minimum size of the shared memory segment in bytes. If 0 (default), no shared memory will be used. |
serverOnly | Set to true if only the server should be able to publish data via this topic |
- Exceptions
-
- See also
- ADD_TOPIC, addPermanentTopic
void rec::rpc::Server::beginAddTopicGroup |
( |
| ) |
|
|
protected |
This signal is emitted when a client has established a connection to the server.
- Parameters
-
info | Client info containing the client's address, port and name. |
This signal is emitted when a client has disconnected from the server.
- Parameters
-
info | Client info containing the client's address, port and name. |
void rec::rpc::Server::clientError |
( |
QAbstractSocket::SocketError |
error, |
|
|
const QString & |
errorString |
|
) |
| |
|
signal |
This signal is emitted when an error occurs on a client.
- Parameters
-
error | Error code |
errorString | Human readable description of the error that occurred. |
int rec::rpc::Server::clientMsgWaitTime |
( |
| ) |
const |
Get client message wait time.
- Returns
- maximum amount of time (in milliseconds) the server waits for a message from the client after a connection has been established.
- See also
- setClientMsgWaitTime
void rec::rpc::Server::close |
( |
bool |
blocking = false | ) |
|
|
slot |
Stop server.
After calling this method, the server stops listening.
- Parameters
-
blocking | If true, this method blocks the calling thread until the server has really stopped listening! |
- See also
- closed
void rec::rpc::Server::closed |
( |
| ) |
|
|
signal |
This signal is emitted when the server has been stopped.
- See also
- close, isListening
int rec::rpc::Server::customTimeout |
( |
| ) |
const |
Get timeout for custom connections.
- Returns
- timeout for custom connections (in seconds).
- See also
- setCustomTimeout
void rec::rpc::Server::disconnectAllClients |
( |
| ) |
|
|
slot |
void rec::rpc::Server::disconnectClient |
( |
const QHostAddress & |
peerAddress, |
|
|
quint16 |
peerPort |
|
) |
| |
|
slot |
Disconnect a specific client.
void rec::rpc::Server::endAddTopicGroup |
( |
| ) |
|
|
protected |
void rec::rpc::Server::exit |
( |
| ) |
|
|
slot |
Shutdown the server.
After calling this method, the server is down and it is save to quit the application
void rec::rpc::Server::finished |
( |
| ) |
|
|
signal |
This signal is emitted when the server has been shutdown.
- See also
- exit
QString rec::rpc::Server::greeting |
( |
| ) |
const |
The server's greeting message.
When a client connects to the server, the server sends a "greeting" (which is just a short ASCII string) to the client. If you connect to the server via telnet, this is the first message you will see. Default is "REC RPC Server <Version>".
- Returns
- Greeting string.
- See also
- setGreeting()
int rec::rpc::Server::httpKeepAliveMaxRequests |
( |
| ) |
const |
Get maximum number of requests for HTTP connections.
- Returns
- maximum number of requests for a persistent HTTP connection.
- See also
- setHttpKeepAliveMaxRequests
int rec::rpc::Server::httpKeepAliveTimeout |
( |
| ) |
const |
bool rec::rpc::Server::isFunctionRegistered |
( |
const QString & |
name | ) |
const |
|
protected |
Check if a RPC function with a given name is registered.
It is recommended to use the preprocessor macro instead of calling the method directly.
- Parameters
-
name | Name of the RPC function. |
- See also
- IS_FUNCTION_REGISTERED
bool rec::rpc::Server::isListening |
( |
| ) |
const |
bool rec::rpc::Server::isLocalIPCEnabled |
( |
| ) |
const |
Get local IPC enabled flag state.
- Returns
- True if local IPC is enabled.
- See also
- setLocalIPCEnabled
bool rec::rpc::Server::isMultiThreadedSerializationEnabled |
( |
| ) |
const |
bool rec::rpc::Server::isTopicListenerRegistered |
( |
const QString & |
name | ) |
const |
|
protected |
bool rec::rpc::Server::listen |
( |
bool |
blocking = false | ) |
|
|
slot |
Start server.
After calling this method, the server will listen for connecting clients at the specified port.
- Parameters
-
blocking | If true, this method blocks the calling thread until the server has really been set up or the operation has been cancelled. |
- Returns
- If blocking, return value will be true if the server has been successfully set up and false if the operation has been cancelled. If non-blocking, return value will always be true.
- See also
- listening, isListening
void rec::rpc::Server::listening |
( |
| ) |
|
|
signal |
void rec::rpc::Server::log |
( |
const QString & |
message, |
|
|
int |
level = 1 |
|
) |
| |
|
signal |
This signal is used to forward log messages from the server to the application.
- Parameters
-
message | The log message. |
level | The log level. Default is 1. |
int rec::rpc::Server::numClientsConnected |
( |
| ) |
const |
Get the number connected clients.
- Returns
- Number of connected clients.
void rec::rpc::Server::numClientsConnectedChanged |
( |
int |
num | ) |
|
|
signal |
This signal is emitted when a client establishes a connection or is disconnected and hence the number of connected clients changes.
- Parameters
-
num | New number of connected clients. |
int rec::rpc::Server::port |
( |
| ) |
const |
Get the port the Server is supposed to use.
- Returns
- The port the Server is supposed to use. If it is already in use, the server will use a different port which will be returned by serverPort().
- See also
- setPort, serverPort
void rec::rpc::Server::publishTopic |
( |
const QString & |
name, |
|
|
serialization::SerializablePtrConst |
data |
|
) |
| |
|
protected |
Publish new topic data.
Use this method to modify topic data and notify all clients that listen to that topic. It is recommended to use the preprocessor macro instead of calling the method directly.
- Parameters
-
name | Name of the topic. |
data | Pointer to the data to be serialized and published. |
- Exceptions
-
- See also
- PREPARE_TOPIC, PUBLISH_TOPIC, PUBLISH_TOPIC_SIMPLE
void rec::rpc::Server::registerCustomRequestHandler |
( |
CustomRequestHandlerBasePtr |
handler = CustomRequestHandlerBasePtr() | ) |
|
|
protected |
Register a custom request handler.
This method is used to set a handler for custom (non-RPC and non-HTTP) requests from a client. It is recommended to use the preprocessor macro instead of calling the method directly.
- Parameters
-
handler | custom request handler. This must be a QSharedPointer pointing to an instance of a struct derived from CustomRequestHandlerBase. It replaces the existing handler. If NULL, the existing handler will be removed. |
- See also
- REGISTER_CUSTOM_REQUEST_HANDLER
void rec::rpc::Server::registeredTopicListener |
( |
const QString & |
name, |
|
|
const rec::rpc::ClientInfo & |
info |
|
) |
| |
|
signal |
This signal is emitted when a client has registered a topic listener.
- Parameters
-
name | Name of the topic. |
info | Client info containing the client's address, port and name. |
void rec::rpc::Server::registerFunction |
( |
const QString & |
name, |
|
|
RPCFunctionBasePtr |
function |
|
) |
| |
|
protected |
Register a RPC function.
This method is used to add a RPC function that can be invoked by a client. It is recommended to use the preprocessor macro instead of calling the method directly.
- Parameters
-
name | Name of the RPC function. |
function | RPC function wrapper. This must be a QSharedPointer pointing to an instance of a struct derived from RPCFunctionBase. |
- Exceptions
-
- See also
- REGISTER_FUNCTION
void rec::rpc::Server::registerHttpGetHandler |
( |
HTTPGetHandlerBasePtr |
handler = HTTPGetHandlerBasePtr() | ) |
|
|
protected |
Register a HTTP GET handler.
This method is used to set a handler for HTTP GET requests from a client. It is recommended to use the preprocessor macro instead of calling the method directly.
- Parameters
-
handler | HTTP GET handler. This must be a QSharedPointer pointing to an instance of a struct derived from HTTPGetHandlerBase. It replaces the existing handler. If NULL, the existing handler will be removed. |
- See also
- REGISTER_HTTP_GET_HANDLER
void rec::rpc::Server::registerTopicListener |
( |
const QString & |
name, |
|
|
TopicListenerBasePtr |
listener |
|
) |
| |
|
protected |
Register a topic listener.
This method is used to add a topic listener that is invoked when the data of a topic change. It is recommended to use the preprocessor macro instead of calling the method directly.
- Parameters
-
name | Name of the topic. |
listener | Topic listener. This must be a QSharedPointer pointing to an instance of a struct derived from TopicListenerBase. |
- Exceptions
-
- See also
- REGISTER_TOPICLISTENER, REGISTER_TOPICINFOCHANGED
void rec::rpc::Server::serverError |
( |
QAbstractSocket::SocketError |
error, |
|
|
const QString & |
errorString |
|
) |
| |
|
signal |
This signal is emitted when an error occurs on the server.
- Parameters
-
error | Error code |
errorString | Human readable description of the error that occurred. |
unsigned short rec::rpc::Server::serverPort |
( |
| ) |
const |
Get the TCP port currently in use.
This can be a different port than the one specified in setPort (in case that the specified port is already in use a differen one will be chosen automatically).
- Returns
- TCP port the server is currently using.
- See also
- port, setPort
Set client message wait time.
- Parameters
-
clientMsgWaitTime | maximum amount of time (in milliseconds) the server waits for a message from the client after a connection has been established. Default is 5000ms. |
- See also
- clientMsgWaitTime
"et timeout for custom connections
- Parameters
-
customTimeout | timeout for custom connections (in seconds). Default is 2s. |
- See also
- customTimeout
void rec::rpc::Server::setGreeting |
( |
const QString & |
greeting | ) |
|
|
slot |
Set a custom greeting message.
When a client connects to the server, the server sends a "greeting" (which is just a short ASCII string) to the client. If you connect to the server via telnet, this is the first message you will see. Default is "REC RPC Server <Version>".
- Parameters
-
greeting | New custom greeting. |
- See also
- greeting()
Set maximum number of requests for HTTP connections.
- Parameters
-
httpKeepAliveMaxRequests | maximum number of requests for a persistent HTTP connection. Default is 10. |
- See also
- httpKeepAliveMaxRequests
Set HTTP keep-alive timeout.
- Parameters
-
httpKeepAliveTimeout | http keep-alive timeout (in seconds). Default is 20s. |
- See also
- httpKeepAliveTimeout
void rec::rpc::Server::setLocalIPCEnabled |
( |
bool |
enabled | ) |
|
|
slot |
Enable or Disable local IPC. Enabled by default.
- Parameters
-
enabled | If false, the client will always use TCP to connect to the server, even if the client runs on the same machine as the server. |
- See also
- isLocalIPCEnabled
void rec::rpc::Server::setMultiThreadedSerializationEnabled |
( |
bool |
enabled | ) |
|
|
slot |
Enable or disable multi-threaded serialization. Disabled by default.
- Parameters
-
enabled | If true, (de)serialization tasks will be performed by multiple threads. This should perform better on multi core CPUs. |
- See also
- isMultiThreadedSerializationEnabled
Set the port the Server is supposed to use.
- Parameters
-
port | TCP port used by the server. Default is 9280. |
- See also
- port
void rec::rpc::Server::unregisteredTopicListener |
( |
const QString & |
name, |
|
|
const rec::rpc::ClientInfo & |
info |
|
) |
| |
|
signal |
This signal is emitted when a client has unregistered a topic listener.
- Parameters
-
name | Name of the topic. |
info | Client info containing the client's address, port and name. |
void rec::rpc::Server::unregisterFunction |
( |
const QString & |
name | ) |
|
|
protected |
Unregister a RPC function.
This method is used to remove a RPC function. It is recommended to use the preprocessor macro instead of calling the method directly.
- Parameters
-
name | Name of the RPC function. |
- See also
- UNREGISTER_FUNCTION
void rec::rpc::Server::unregisterTopicListener |
( |
const QString & |
name | ) |
|
|
protected |
const int rec::rpc::Server::DefaultClientMsgWaitTime = 5000 |
|
static |
Default value for the maximum amount of time (in milliseconds) the server waits for a message from the client after a connection has been established.
Definition at line 181 of file rec_rpc_Server.h.
const int rec::rpc::Server::DefaultCustomTimeout = 2 |
|
static |
Default value for the timeout for custom connections (in seconds).
Definition at line 190 of file rec_rpc_Server.h.
const int rec::rpc::Server::DefaultHttpKeepAliveMaxRequests = 10 |
|
static |
Default value for the maximum number of requests for a persistent HTTP connection.
Definition at line 187 of file rec_rpc_Server.h.
const int rec::rpc::Server::DefaultHttpKeepAliveTimeout = 20 |
|
static |
Default value for the http keep-alive timeout (in seconds).
Definition at line 184 of file rec_rpc_Server.h.
int rec::rpc::Server::sendFailSocketTimeout |
|
static |
The documentation for this class was generated from the following file: