68 #ifndef _REC_RPC_COMMON_H_ 69 #define _REC_RPC_COMMON_H_ 76 #include <QHostAddress> 150 virtual serialization::SerializablePtr
createData()
const = 0;
163 typedef QSharedPointer< TopicListenerBase > TopicListenerBasePtr;
167 template<
typename T >
168 inline QSharedPointer< T > createSerializable()
170 return QSharedPointer< T >(
new T );
173 template<
typename T,
typename P >
174 inline QSharedPointer< T > createSerializable(
const P& param )
176 return QSharedPointer< T >(
new T( param ) );
180 inline rec::rpc::serialization::SerializablePtr createSerializable()
185 template<
typename Parent_t,
typename Data_t >
190 TopicListener( Parent_t* parent, Listen_f listener ) : _parent( parent ), _listener( listener ) { }
191 rec::rpc::serialization::SerializablePtr
createData()
const {
return createSerializable< Data_t >(); }
195 if (
typeid( data ) ==
typeid( Data_t ) )
197 ( _parent->*_listener )( static_cast< const Data_t& >( data ), client, errorCode );
222 #define DECLARE_TOPICLISTENER( TOPICNAME ) \ 224 void set_##TOPICNAME##_enabled( bool enable ); \ 225 bool is_##TOPICNAME##_enabled() const; \ 227 rec::rpc::TopicListenerBasePtr createTopic##TOPICNAME##Listener(); \ 228 void topic##TOPICNAME( const topic##TOPICNAME##Data& data, const rec::rpc::ClientInfo& client, rec::rpc::ErrorCode errorCode ); 242 #define BEGIN_TOPICLISTENER_DEFINITION( CLASSNAME, TOPICNAME ) \ 243 void CLASSNAME::set_##TOPICNAME##_enabled( bool enable ) \ 247 REGISTER_TOPICLISTENER( TOPICNAME ); \ 251 UNREGISTER_TOPICLISTENER( TOPICNAME ); \ 254 bool CLASSNAME::is_##TOPICNAME##_enabled() const \ 256 return IS_TOPICLISTENER_REGISTERED( TOPICNAME ); \ 258 inline rec::rpc::TopicListenerBasePtr CLASSNAME::createTopic##TOPICNAME##Listener() \ 260 return rec::rpc::TopicListenerBasePtr( new rec::rpc::detail::TopicListener< CLASSNAME, topic##TOPICNAME##Data >( this, &CLASSNAME::topic##TOPICNAME ) ); \ 262 void CLASSNAME::topic##TOPICNAME( const topic##TOPICNAME##Data& data, const rec::rpc::ClientInfo& client, rec::rpc::ErrorCode errorCode ) \ 268 #define END_TOPICLISTENER_DEFINITION } 282 #define REGISTER_TOPICLISTENER( TOPICNAME ) registerTopicListener( #TOPICNAME, createTopic##TOPICNAME##Listener() ); 293 #define UNREGISTER_TOPICLISTENER( TOPICNAME ) unregisterTopicListener( #TOPICNAME ); 302 #define IS_TOPICLISTENER_REGISTERED( TOPICNAME ) isTopicListenerRegistered( #TOPICNAME ); 313 #define DECLARE_TOPICINFOCHANGED( TOPICNAME ) \ 315 void set_##TOPICNAME##_info_enabled( bool enable ); \ 316 bool is_##TOPICNAME##_info_enabled() const; \ 318 rec::rpc::TopicListenerBasePtr createTopic##TOPICNAME##InfoChanged(); \ 319 void topic##TOPICNAME##_infoChanged_raw( const rec::rpc::serialization::TopicInfo& data, const rec::rpc::ClientInfo& client, rec::rpc::ErrorCode errorCode ) \ 321 topic##TOPICNAME##_infoChanged( data, errorCode ); \ 323 void topic##TOPICNAME##_infoChanged( const rec::rpc::ClientInfoSet& info, rec::rpc::ErrorCode errorCode ); 335 #define BEGIN_TOPICINFOCHANGED_DEFINITION( CLASSNAME, TOPICNAME ) \ 336 void CLASSNAME::set_##TOPICNAME##_info_enabled( bool enable ) \ 340 REGISTER_TOPICINFOCHANGED( TOPICNAME ); \ 344 UNREGISTER_TOPICINFOCHANGED( TOPICNAME ); \ 347 bool CLASSNAME::is_##TOPICNAME##_info_enabled() const \ 349 return IS_TOPICINFOCHANGED_REGISTERED( TOPICNAME ); \ 351 inline rec::rpc::TopicListenerBasePtr CLASSNAME::createTopic##TOPICNAME##InfoChanged() \ 353 return rec::rpc::TopicListenerBasePtr( new rec::rpc::detail::TopicListener< CLASSNAME, rec::rpc::serialization::TopicInfo >( this, &CLASSNAME::topic##TOPICNAME##_infoChanged_raw ) ); \ 355 void CLASSNAME::topic##TOPICNAME##_infoChanged( const rec::rpc::ClientInfoSet& info, rec::rpc::ErrorCode errorCode ) \ 361 #define END_TOPICINFOCHANGED_DEFINITION } 374 #define REGISTER_TOPICINFOCHANGED( TOPICNAME ) registerTopicListener( #TOPICNAME "__info", createTopic##TOPICNAME##InfoChanged() ); 385 #define UNREGISTER_TOPICINFOCHANGED( TOPICNAME ) unregisterTopicListener( #TOPICNAME "__info" ); 394 #define IS_TOPICINFOCHANGED_REGISTERED( TOPICNAME ) isTopicListenerRegistered( #TOPICNAME "__info" ); 405 #define PREPARE_TOPIC( TOPICNAME ) \ 406 const char* topicName = #TOPICNAME; \ 407 topic##TOPICNAME##DataPtr dataPtr = rec::rpc::detail::createSerializable< topic##TOPICNAME##Data >(); \ 408 topic##TOPICNAME##Data& data = *dataPtr; 418 #define PUBLISH_TOPIC publishTopic( topicName, dataPtr ); 432 #define PUBLISH_TOPIC_SIMPLE( TOPICNAME, DATA ) publishTopic( #TOPICNAME, rec::rpc::detail::createSerializable< topic##TOPICNAME##Data >( DATA ) ); 434 #define PUBLISH_TOPIC_SIMPLE_EMPTY( TOPICNAME ) publishTopic( #TOPICNAME, rec::rpc::detail::createSerializable< rec::rpc::serialization::Serializable >() ); 436 #endif // _REC_RPC_COMMON_H_ ErrorCode
Pre-defined error codes.
REC_RPC_EXPORT int getLibraryMajorVersion()
Get the library's major version.
static SerializablePtr empty
virtual void listen(const serialization::Serializable &data, const rec::rpc::ClientInfo &client, rec::rpc::ErrorCode errorCode) const =0
const int defaultPort
The TCP port which will be used by default if no other one is specified.
REC_RPC_EXPORT QString getLibraryVersionString()
Get the library's version as string.
REC_RPC_EXPORT QString getLibraryVersionSuffix()
Get the library's version suffix.
Base class for all serializable data.
REC_RPC_EXPORT int getLibraryDate()
Get the library's version date.
topic listener wrapper interface
REC_RPC_EXPORT void getLibraryVersion(int *major, int *minor, int *patch, QString *suffix, int *date)
Get the library's version.
REC_RPC_EXPORT int getLibraryMinorVersion()
Get the library's minor version.
REC_RPC_EXPORT int getLibraryPatchVersion()
Get the library's patch version.
virtual serialization::SerializablePtr createData() const =0