27 #ifndef _REC_RPC_CLIENT_H_ 28 #define _REC_RPC_CLIENT_H_ 64 typedef QSharedPointer< NotifierBase > NotifierBasePtr;
68 template<
typename Parent_t,
typename Result_t >
73 Notifier( Parent_t* parent, Notify_f notifier ) : _parent( parent ), _notifier( notifier ) { }
77 if (
typeid( result ) ==
typeid( Result_t ) )
79 ( _parent->*_notifier )( static_cast< const Result_t& >( result ), errorCode );
104 static const unsigned int DefaultTimeout = 2000;
111 Client( QObject* parent = 0 );
120 QString name()
const;
126 bool isMultiThreadedSerializationEnabled()
const;
132 bool isLocalIPCEnabled()
const;
138 bool isConnected()
const;
145 QString address()
const;
152 QHostAddress localAddress()
const;
159 quint16 localPort()
const;
166 QHostAddress peerAddress()
const;
173 quint16 peerPort()
const;
186 QString expectedGreeting()
const;
198 unsigned int msTimeout()
const;
211 void getServerVersion(
int* major,
int* minor,
int* patch,
int* date = 0, QString* suffix = 0 );
220 QString getServerVersion();
228 void setName(
const QString& name );
236 void setMultiThreadedSerializationEnabled(
bool enabled );
244 void setLocalIPCEnabled(
bool enabled );
253 void setAddress(
const QString& address );
266 void setExpectedGreeting(
const QString& greeting );
278 void setMsTimeout(
unsigned int timeout );
291 void setAutoReconnectEnabled(
bool enable,
unsigned int ms = 200 );
303 void connectToServer(
unsigned int msTimeout = DefaultTimeout );
312 void disconnectFromServer();
336 void stateChanged( QAbstractSocket::SocketState state );
344 void error( QAbstractSocket::SocketError socketError,
const QString& errorString );
352 void log(
const QString& message,
int level = 1 );
370 void invoke(
const QString& name, serialization::SerializablePtrConst param, serialization::SerializablePtr result,
bool blocking );
385 void publishTopic(
const QString& name, serialization::SerializablePtrConst data );
399 void registerNotifier(
const QString& name, NotifierBasePtr notifier );
411 void unregisterNotifier(
const QString& name );
422 bool isNotifierRegistered(
const QString& name )
const;
437 void registerTopicListener(
const QString& name, TopicListenerBasePtr listener );
449 void unregisterTopicListener(
const QString& name );
460 bool isTopicListenerRegistered(
const QString& name )
const;
463 client::Client* _client;
476 #define DECLARE_NOTIFIER( FUNCTIONNAME ) \ 478 rec::rpc::NotifierBasePtr create##FUNCTIONNAME##Notifier(); \ 479 void FUNCTIONNAME##Finished( const FUNCTIONNAME##Result& result, rec::rpc::ErrorCode errorCode ); 491 #define BEGIN_NOTIFIER( CLASSNAME, FUNCTIONNAME ) \ 492 inline rec::rpc::NotifierBasePtr CLASSNAME::create##FUNCTIONNAME##Notifier() \ 494 return rec::rpc::NotifierBasePtr( new rec::rpc::detail::Notifier< CLASSNAME, FUNCTIONNAME##Result >( this, &CLASSNAME::FUNCTIONNAME##Finished ) ); \ 496 void CLASSNAME::FUNCTIONNAME##Finished( const FUNCTIONNAME##Result& result, rec::rpc::ErrorCode errorCode ) \ 502 #define END_NOTIFIER } 514 #define REGISTER_NOTIFIER( FUNCTIONNAME ) registerNotifier( #FUNCTIONNAME, create##FUNCTIONNAME##Notifier() ); 525 #define UNREGISTER_NOTIFIER( FUNCTIONNAME ) unregisterNotifier( #FUNCTIONNAME ); 534 #define IS_NOTIFIER_REGISTERED( FUNCTIONNAME ) isNotifierRegistered( #FUNCTIONNAME ); 545 #define PREPARE( FUNCTIONNAME ) \ 546 const char* funcName = #FUNCTIONNAME; \ 547 FUNCTIONNAME##ParamPtr paramPtr = rec::rpc::detail::createSerializable< FUNCTIONNAME##Param >(); \ 548 FUNCTIONNAME##Param& param = *paramPtr; \ 549 FUNCTIONNAME##ResultPtr resultPtr = rec::rpc::detail::createSerializable< FUNCTIONNAME##Result >(); \ 550 FUNCTIONNAME##Result& result = *resultPtr; 563 #define INVOKE( BLOCKING ) invoke( funcName, paramPtr, resultPtr, BLOCKING ); 579 #define INVOKE_SIMPLE( FUNCTIONNAME, PARAM, BLOCKING ) \ 580 FUNCTIONNAME##ResultPtr resultPtr = rec::rpc::detail::createSerializable< FUNCTIONNAME##Result >(); \ 581 FUNCTIONNAME##Result& result = *resultPtr; \ 582 invoke( #FUNCTIONNAME, rec::rpc::detail::createSerializable< FUNCTIONNAME##Param >( PARAM ), resultPtr, BLOCKING ); 597 #define INVOKE_SIMPLE_EMPTY( FUNCTIONNAME, BLOCKING ) \ 598 FUNCTIONNAME##ResultPtr resultPtr = rec::rpc::detail::createSerializable< FUNCTIONNAME##Result >(); \ 599 FUNCTIONNAME##Result& result = *resultPtr; \ 600 invoke( #FUNCTIONNAME, rec::rpc::detail::createSerializable< rec::rpc::serialization::Serializable >(), resultPtr, BLOCKING ); 602 #endif //_REC_RPC_CLIENT_H_ ErrorCode
Pre-defined error codes.
RPC response notifier wrapper interface.
Base class for all serializable data.