RPC client base class.
More...
#include <rec_rpc_Client.h>
|
static const unsigned int | DefaultTimeout = 2000 |
| Default value for the maximum amount of time the client has to wait for a response from the server. More...
|
|
RPC client base class.
Base class to implement a RPC client. Derive from that class to implement your own client.
Definition at line 99 of file rec_rpc_Client.h.
rec::rpc::Client::Client |
( |
QObject * |
parent = 0 | ) |
|
virtual rec::rpc::Client::~Client |
( |
| ) |
|
|
virtual |
QString rec::rpc::Client::address |
( |
| ) |
const |
Get RPC server's network address.
- Returns
- The network address of the RPC server.
- See also
- setAddress()
void rec::rpc::Client::connected |
( |
| ) |
|
|
signal |
void rec::rpc::Client::connectToServer |
( |
unsigned int |
msTimeout = DefaultTimeout | ) |
|
|
slot |
Connect to a RPC server.
The client trys to establish a connection to a RPC server. This methood does not block. If the connection is successfully established, the connected() signal will be emittet. If the connection attempt fails, disconnected() will be emitted.
- Parameters
-
msTimeout | Connection timeout in milliseconds (default is 2000). |
- See also
- connected(), disconnected(), disconnectFromServer()
void rec::rpc::Client::disconnectFromServer |
( |
| ) |
|
|
slot |
void rec::rpc::Client::error |
( |
QAbstractSocket::SocketError |
socketError, |
|
|
const QString & |
errorString |
|
) |
| |
|
signal |
This signal is emitted when an error occurs.
- Parameters
-
socketError | Error code |
errorString | Human readable description of the error that occurred. |
QString rec::rpc::Client::expectedGreeting |
( |
| ) |
const |
The greeting message that is expected from the server when connecting.
When a client connects to the server, the server sends a "greeting" (which is just a short ASCII string) to the client. If the expected greeting string is not empty, it will be compared with the greeting sent by the server. If they are different, an Exception with error code IncompatibleServer will be thrown.
- Returns
- Expected greeting string.
- See also
- setExpectedGreeting()
void rec::rpc::Client::getServerVersion |
( |
int * |
major, |
|
|
int * |
minor, |
|
|
int * |
patch, |
|
|
int * |
date = 0 , |
|
|
QString * |
suffix = 0 |
|
) |
| |
Get the server's version.
Send a RPC blocking request to the server to retrieve its version.
- Parameters
-
major | Pointer to an int that shall contain the major version number. |
minor | Pointer to an int that shall contain the minor version number. |
patch | Pointer to an int that shall contain the patch version number. |
date | Pointer to an int that shall contain the date when this version was released (format YYYYMMDD). |
suffix | Pointer to a string that is appended to the version number (can be empty or "a", "beta" or so). |
QString rec::rpc::Client::getServerVersion |
( |
| ) |
|
Get the server's version.
Send a RPC blocking request to the server to retrieve its version.
- Returns
- Version string.
void rec::rpc::Client::invoke |
( |
const QString & |
name, |
|
|
serialization::SerializablePtrConst |
param, |
|
|
serialization::SerializablePtr |
result, |
|
|
bool |
blocking |
|
) |
| |
|
protected |
Invoke a RPC function on the server.
This method is used to invoke a RPC function on the server. It is recommended to use the preprocessor macro instead of calling the method directly.
- Parameters
-
name | Name if the RPC function. |
param | RPC function parameters. This must be a shared pointer containing an instance of a rec::rpc::serialization::Serializable subclass. |
result | RPC function return values. This must be a shared pointer containing an instance of a rec::rpc::serialization::Serializable subclass. |
blocking | If true, the function call will block until a response has been received. If an error occurs during a blocking function call, a rec::rpc::Exception will be thrown. |
- Exceptions
-
rec::rpc::Exception | Error codes: NoConnection, UnknownFunction, WrongDataFormat, ExecutionTimeout, ExecutionCancelled. |
- See also
- PREPARE, INVOKE, INVOKE_SIMPLE, INVOKE_SIMPLE_EMPTY
bool rec::rpc::Client::isConnected |
( |
| ) |
const |
bool rec::rpc::Client::isLocalIPCEnabled |
( |
| ) |
const |
Get local IPC enabled flag state.
- Returns
- True if local IPC is enabled.
- See also
- setLocalIPCEnabled
bool rec::rpc::Client::isMultiThreadedSerializationEnabled |
( |
| ) |
const |
bool rec::rpc::Client::isNotifierRegistered |
( |
const QString & |
name | ) |
const |
|
protected |
Check if a RPC response notifier for a given function 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_NOTIFIER_REGISTERED
bool rec::rpc::Client::isTopicListenerRegistered |
( |
const QString & |
name | ) |
const |
|
protected |
QHostAddress rec::rpc::Client::localAddress |
( |
| ) |
const |
Get the clients local address.
- Returns
- The local address
quint16 rec::rpc::Client::localPort |
( |
| ) |
const |
Get the clients local port.
- Returns
- The local port
void rec::rpc::Client::log |
( |
const QString & |
message, |
|
|
int |
level = 1 |
|
) |
| |
|
signal |
This signal is used to forward log messages from the client to the application.
- Parameters
-
message | The log message. |
level | The log level. Default is 1. |
unsigned int rec::rpc::Client::msTimeout |
( |
| ) |
const |
Timeout for RPC requests.
When a RPC request is sent to the server and no response arrived within a certain time period, the request will be cancelled with error code ExecutionTimeout. Default value is 2000.
- Returns
- Timeout in milliseconds.
- See also
- setMsTimeout()
QString rec::rpc::Client::name |
( |
| ) |
const |
Get the Client's name.
- Returns
- Client's name that will be transmitted to the server.
- See also
- setName
QHostAddress rec::rpc::Client::peerAddress |
( |
| ) |
const |
Get the clients peer address.
- Returns
- The peer address
quint16 rec::rpc::Client::peerPort |
( |
| ) |
const |
Get the clients peer port.
- Returns
- The peer port
void rec::rpc::Client::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::Client::registerNotifier |
( |
const QString & |
name, |
|
|
NotifierBasePtr |
notifier |
|
) |
| |
|
protected |
Register a RPC response notifier.
This method is used to add a response notifier for a RPC function. In case of a non-blocking function call the notifier is invoked when the result is received from the server or a timeout has occurred. It is recommended to use the preprocessor macro instead of calling the method directly.
- Parameters
-
name | Name of the RPC function. |
notifier | Response notifier. This must be a QSharedPointer pointing to an instance of a struct derived from NotifierBase. |
- See also
- REGISTER_NOTIFIER
void rec::rpc::Client::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::Client::setAddress |
( |
const QString & |
address | ) |
|
|
slot |
Set the network address of the RPC server.
- Parameters
-
address | Address of the RPC server (can be IPv4 or IPv6). |
- See also
- address()
void rec::rpc::Client::setAutoReconnectEnabled |
( |
bool |
enable, |
|
|
unsigned int |
ms = 200 |
|
) |
| |
|
slot |
Enable/disable automatic reconnection.
When enabled the client tries to reconnect automatically after the specified number of milliseconds.
- Parameters
-
enable | If true the automatic reconnect will be enabled. If false the client does not reconnect to the server automatically. |
ms | The time in millisconds after which to automatically reconnect to the server. |
- See also
- connected(), disconnected(), disconnectFromServer()
void rec::rpc::Client::setExpectedGreeting |
( |
const QString & |
greeting | ) |
|
|
slot |
Set the greeting message that is expected from the server when connecting.
When a client connects to the server, the server sends a "greeting" (which is just a short ASCII string) to the client. If the expected greeting string is not empty, it will be compared with the greeting sent by the server. If they are different, an Exception with error code IncompatibleServer will be thrown.
- Parameters
-
greeting | New expected greeting string. |
- See also
- expectedGreeting()
void rec::rpc::Client::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::Client::setMsTimeout |
( |
unsigned int |
timeout | ) |
|
|
slot |
Set the timeout for RPC requests.
When a RPC request is sent to the server and no response arrived within a certain time period, the request will be cancelled with error code ExecutionTimeout. Default value is 2000.
- Parameters
-
timeout | Timeout in milliseconds. |
- See also
- msTimeout()
void rec::rpc::Client::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
void rec::rpc::Client::setName |
( |
const QString & |
name | ) |
|
|
slot |
Set the Client's name. Default is the application name.
- Parameters
-
name | Client's name that will be transmitted to the server. |
- See also
- name
void rec::rpc::Client::stateChanged |
( |
QAbstractSocket::SocketState |
state | ) |
|
|
signal |
This signal is emitted when the client's socket state has changed
- Parameters
-
void rec::rpc::Client::unregisterNotifier |
( |
const QString & |
name | ) |
|
|
protected |
Unregister a RPC response notifier.
This method is used to remove a notifier. It is recommended to use the preprocessor macro instead of calling the method directly.
- Parameters
-
name | Name of the RPC function. |
- See also
- UNREGISTER_NOTIFIER
void rec::rpc::Client::unregisterTopicListener |
( |
const QString & |
name | ) |
|
|
protected |
const unsigned int rec::rpc::Client::DefaultTimeout = 2000 |
|
static |
Default value for the maximum amount of time the client has to wait for a response from the server.
Definition at line 104 of file rec_rpc_Client.h.
The documentation for this class was generated from the following file: