ArnLib  4.0.x
Active Registry Network
ArnRpc Class Reference

Remote Procedure Call. More...

#include <ArnRpc.hpp>

Inheritance diagram for ArnRpc:
Collaboration diagram for ArnRpc:

Classes

struct  Invoke
 

Public Types

typedef ArnRpcMode Mode
 

Public Slots

void sendText (const QString &txt)
 Send a general text message to the other end of the used pipe More...
 

Signals

void pipeClosed ()
 Signal emitted when the used pipe is closed. More...
 
void textReceived (const QString &text)
 Signal emitted when a general text message is received. More...
 
void defaultCall (const QByteArray &data)
 Signal emitted when receiver method missing. More...
 
void outOfSequence ()
 Signal emitted when checked sequence order is wrong. More...
 
void heartBeatChanged (bool isOk)
 Signal emitted when Heart beat changes state. More...
 
void heartBeatReceived ()
 Signal emitted when Heart beat message is received. More...
 

Public Member Functions

 ArnRpc (QObject *parent=arnNullptr)
 
 ~ArnRpc ()
 
QString pipePath () const
 Get the path for the used pipe More...
 
bool open (const QString &pipePath)
 
void setPipe (ArnPipe *pipe)
 Set pipe for this Rpc. More...
 
ArnPipepipe () const
 Get the used pipe More...
 
bool setReceiver (QObject *receiver, bool useTrackRpcSender=true)
 
QObject * receiver () const
 
void setMethodPrefix (const QString &prefix)
 
QString methodPrefix () const
 
void setIncludeSender (bool v)
 Add sender as argument when calling a rpc method. More...
 
void setMode (Mode mode)
 
Mode mode () const
 Get the mode. More...
 
void setHeartBeatSend (int time)
 Set period time for sending heart beat message. More...
 
int getHeartBeatSend () const
 Get period time for sending heart beat message. More...
 
void setHeartBeatCheck (int time)
 Set max time period for receiving heart beat message. More...
 
int getHeartBeatCheck () const
 Get max time period for receiving heart beat message. More...
 
bool isHeartBeatOk () const
 Get the state of heart beat. More...
 
void addSenderSignals (QObject *sender, const QString &prefix)
 
bool invoke (const QString &funcName, MQGenericArgument val0=MQGenericArgument(0), MQGenericArgument val1=MQGenericArgument(), MQGenericArgument val2=MQGenericArgument(), MQGenericArgument val3=MQGenericArgument(), MQGenericArgument val4=MQGenericArgument(), MQGenericArgument val5=MQGenericArgument(), MQGenericArgument val6=MQGenericArgument(), MQGenericArgument val7=MQGenericArgument())
 Calls a named remote procedure. More...
 
bool invoke (const QString &funcName, Invoke invokeFlags, MQGenericArgument val0=MQGenericArgument(0), MQGenericArgument val1=MQGenericArgument(), MQGenericArgument val2=MQGenericArgument(), MQGenericArgument val3=MQGenericArgument(), MQGenericArgument val4=MQGenericArgument(), MQGenericArgument val5=MQGenericArgument(), MQGenericArgument val6=MQGenericArgument(), MQGenericArgument val7=MQGenericArgument())
 Calls a named remote procedure using invoke flags. More...
 
ArnRpcrpcSender ()
 
void batchConnect (const ARN_RegExp &rgx, const QObject *receiver, const QString &replace, Mode mode=Mode())
 Make batch connection from this ArnRpc:s signals to another receivers slots/signals. More...
 
void batchConnect (const QObject *sender, const ARN_RegExp &rgx, const QString &replace, Mode mode=Mode())
 Make batch connection from one senders signals to this ArnRpc:s slots/signals. More...
 

Static Public Member Functions

static ArnRpcrpcSender (QObject *receiver)
 
static void batchConnect (const QObject *sender, const ARN_RegExp &rgx, const QObject *receiver, const QString &replace, Mode mode=Mode())
 Make batch connection from one senders signals to another receivers slots/signals. More...
 

Detailed Description

Remote Procedure Call.

About RPC and SAPI

This is the basic funtionality of RPC. It's recommended to use ArnSapi which uses a higher level model. For now the ArnRpc class is more sparsely documented.

Example usage

// In class declare (MyClass)
ArnRpc* _rpcCommon;
// In class code (MyClass)
_rpcCommon = new ArnRpc( this);
_rpcCommon->setMethodPrefix("rpc_");
_rpcCommon->setReceiver( this);
_rpcCommon->open("//Pipes/pipeCommon");
.
.
void MyClass::rpc_test( QByteArray ba, QString str, int i)
{
ArnRpc* sender = ArnRpc::rpcSender( this);
if (sender) qDebug() << "RPC sender=" << sender->pipePath();
qDebug() << "RPC-test ba=" << ba << " str=" << str << " int=" << i;
}
void MyClass::rpc_ver()
{
ArnRpc* sender = ArnRpc::rpcSender( this);
if (!sender) return;
// Reply to requester the version text
sender->invoke("ver", MQ_ARG( QString, verText, "MySytem Version 1.0"));
}

Definition at line 156 of file ArnRpc.hpp.

Member Typedef Documentation

◆ Mode

Definition at line 162 of file ArnRpc.hpp.

Constructor & Destructor Documentation

◆ ArnRpc()

ArnRpc::ArnRpc ( QObject *  parent = arnNullptr)
explicit

Definition at line 204 of file ArnRpc.cpp.

◆ ~ArnRpc()

ArnRpc::~ArnRpc ( )

Definition at line 220 of file ArnRpc.cpp.

Member Function Documentation

◆ addSenderSignals()

void ArnRpc::addSenderSignals ( QObject *  sender,
const QString &  prefix 
)

Definition at line 440 of file ArnRpc.cpp.

◆ batchConnect() [1/3]

void ArnRpc::batchConnect ( const QObject *  sender,
const ARN_RegExp rgx,
const QObject *  receiver,
const QString &  replace,
Mode  mode = Mode() 
)
static

Make batch connection from one senders signals to another receivers slots/signals.

Used when there is a pattern in the naming of the signals and slots. It's assumed that naming for slots are unique regardless of its case i.e. using both test() and tesT() are not allowed.

Example: batchConnect( _commonSapi, ARN_RegExp("^rq_(.+)"), this, "chat\\1"); connects signal: rq_info(QString,QString) to slot: chatInfo(QString,QString)

Parameters
[in]senderis the sending QObject.
[in]rgxis the regular expression for selecting sender signals.
[in]receiveris the receiving QObject.
[in]replaceis the conversion for naming the receiver slots/signals.
[in]modeUsed modes: Debug, NoDefaultArgs

Definition at line 1487 of file ArnRpc.cpp.

◆ batchConnect() [2/3]

void ArnRpc::batchConnect ( const ARN_RegExp rgx,
const QObject *  receiver,
const QString &  replace,
Mode  mode = Mode() 
)
inline

Make batch connection from this ArnRpc:s signals to another receivers slots/signals.

Used when there is a pattern in the naming of the signals and slots. It's assumed that naming for slots are unique regardless of its case i.e. using both test() and tesT() are not allowed.

Example: _commonSapi.batchConnect( ARN_RegExp("^rq_(.+)"), this, "chat\\1"); connects signal: rq_info(QString,QString) to slot: chatInfo(QString,QString)

Parameters
[in]rgxis the regular expression for selecting sender signals.
[in]receiveris the receiving QObject.
[in]replaceis the conversion for naming the receiver slots/signals.
[in]mode
See also
batchConnect(const QObject*, const ARN_RegExp&, const QObject*, const QString&, Mode)

Definition at line 348 of file ArnRpc.hpp.

◆ batchConnect() [3/3]

void ArnRpc::batchConnect ( const QObject *  sender,
const ARN_RegExp rgx,
const QString &  replace,
Mode  mode = Mode() 
)
inline

Make batch connection from one senders signals to this ArnRpc:s slots/signals.

Used when there is a pattern in the naming of the signals and slots. It's assumed that naming for slots are unique regardless of its case i.e. using both test() and tesT() are not allowed.

Example: _commonSapi.batchConnect( _commonSapi, ARN_RegExp("^chat(.+)"), "rq_\\1"); connects signal: chatinfo(QString,QString) to slot: rq_Info(QString,QString)

Parameters
[in]senderis the sending QObject.
[in]rgxis the regular expression for selecting sender signals.
[in]replaceis the conversion for naming the receiver slots/signals.
[in]mode
See also
batchConnect(const QObject*, const ARN_RegExp&, const QObject*, const QString&, Mode)

Definition at line 369 of file ArnRpc.hpp.

◆ defaultCall

void ArnRpc::defaultCall ( const QByteArray &  data)
signal

Signal emitted when receiver method missing.

This signal is only emitted if Mode::useDefaultCall is active. Error notification is then canceled.

Parameters
[in]datais the received call message in XString format.

◆ getHeartBeatCheck()

int ArnRpc::getHeartBeatCheck ( ) const

Get max time period for receiving heart beat message.

Time zero is turned off checking.

Returns
time is the time period in seconds
See also
setHeartBeatCheck()

Definition at line 424 of file ArnRpc.cpp.

◆ getHeartBeatSend()

int ArnRpc::getHeartBeatSend ( ) const

Get period time for sending heart beat message.

Time zero is turned off sending.

Returns
time is the time period in seconds
See also
setHeartBeatSend()

Definition at line 405 of file ArnRpc.cpp.

◆ heartBeatChanged

void ArnRpc::heartBeatChanged ( bool  isOk)
signal

Signal emitted when Heart beat changes state.

Heart beat messages are detected and expected within a check time. If this is satisfied, the state of heart beat is ok.

Parameters
[in]isOkis the Heart beat state, false = Not received.

◆ heartBeatReceived

void ArnRpc::heartBeatReceived ( )
signal

Signal emitted when Heart beat message is received.

◆ invoke() [1/2]

Calls a named remote procedure.

This is the low level way to call a remote procedure. It can freely call anything without declaring it. For high level calls use ArnSapi.

This function works similar to QMetaObject::invokeMethod(). The called name is prefixed before the final call is made. Using the label in MQ_ARG() makes dubugging easier, as the parameter is named.

Example: rpc->invoke("myfunc", MQ_ARG( QString, mypar, "Test XYZ"));

Parameters
[in]funcNameis the name of the called procedure.
[in]val0first arg.
[in]val1
[in]val2
[in]val3
[in]val4
[in]val5
[in]val6
[in]val7

Definition at line 494 of file ArnRpc.cpp.

◆ invoke() [2/2]

Calls a named remote procedure using invoke flags.

This is the low level way to call a remote procedure. It can freely call anything without declaring it. For high level calls use ArnSapi.

This function works similar to QMetaObject::invokeMethod(). The called name is prefixed before the final call is made. Using the label in MQ_ARG() makes dubugging easier, as the parameter is named.

Example: rpc->invoke("myfunc", ArnRpc::Invoke::NoQueue, MQ_ARG( QString, mypar, "Test XYZ"));

Parameters
[in]funcNameis the name of the called procedure.
[in]invokeFlagsis flags for controlling the invoke
[in]val0first arg.
[in]val1
[in]val2
[in]val3
[in]val4
[in]val5
[in]val6
[in]val7

Definition at line 533 of file ArnRpc.cpp.

◆ isHeartBeatOk()

bool ArnRpc::isHeartBeatOk ( ) const

Get the state of heart beat.

Return values
falseif not getting heart beat in time
See also
heartBeatChanged()

Definition at line 432 of file ArnRpc.cpp.

◆ methodPrefix()

QString ArnRpc::methodPrefix ( ) const

Definition at line 346 of file ArnRpc.cpp.

◆ mode()

ArnRpc::Mode ArnRpc::mode ( ) const

Get the mode.

Returns
current mode

Definition at line 386 of file ArnRpc.cpp.

◆ open()

bool ArnRpc::open ( const QString &  pipePath)

Definition at line 236 of file ArnRpc.cpp.

◆ outOfSequence

void ArnRpc::outOfSequence ( )
signal

Signal emitted when checked sequence order is wrong.

◆ pipe()

ArnPipe * ArnRpc::pipe ( ) const

Get the used pipe

Returns
pipe
See also
setPipe()

Definition at line 292 of file ArnRpc.cpp.

◆ pipeClosed

void ArnRpc::pipeClosed ( )
signal

Signal emitted when the used pipe is closed.

The pipe closes when its Arn Data Object is destroyed, i.e. the session is considered ended.

◆ pipePath()

QString ArnRpc::pipePath ( ) const

Get the path for the used pipe

Returns
path

Definition at line 226 of file ArnRpc.cpp.

◆ receiver()

QObject * ArnRpc::receiver ( ) const

Definition at line 329 of file ArnRpc.cpp.

◆ rpcSender() [1/2]

ArnRpc * ArnRpc::rpcSender ( )

Definition at line 473 of file ArnRpc.cpp.

◆ rpcSender() [2/2]

ArnRpc * ArnRpc::rpcSender ( QObject *  receiver)
static

Definition at line 483 of file ArnRpc.cpp.

◆ sendText

void ArnRpc::sendText ( const QString &  txt)
slot

Send a general text message to the other end of the used pipe

Is used by ArnRpc to give errors and help messages, mostly for debugging.

Parameters
[in]txtis the text to be sent
See also
textReceived();

Definition at line 1466 of file ArnRpc.cpp.

◆ setHeartBeatCheck()

void ArnRpc::setHeartBeatCheck ( int  time)

Set max time period for receiving heart beat message.

Setting time to zero will turn off checking.

Parameters
[in]timeis the time period in seconds
See also
setHeartBeatSend();

Definition at line 413 of file ArnRpc.cpp.

◆ setHeartBeatSend()

void ArnRpc::setHeartBeatSend ( int  time)

Set period time for sending heart beat message.

Setting time to zero will turn off sending.

Parameters
[in]timeis the time period in seconds
See also
setHeartBeatCheck()

Definition at line 394 of file ArnRpc.cpp.

◆ setIncludeSender()

void ArnRpc::setIncludeSender ( bool  v)

Add sender as argument when calling a rpc method.

Deprecated:
Use rpcSender()

Definition at line 370 of file ArnRpc.cpp.

◆ setMethodPrefix()

void ArnRpc::setMethodPrefix ( const QString &  prefix)

Definition at line 337 of file ArnRpc.cpp.

◆ setMode()

void ArnRpc::setMode ( Mode  mode)

Definition at line 378 of file ArnRpc.cpp.

◆ setPipe()

void ArnRpc::setPipe ( ArnPipe pipe)

Set pipe for this Rpc.

The Rpc will take ownership of the pip.

Parameters
[in]pipe
See also
pipe()
pipePath()

Definition at line 273 of file ArnRpc.cpp.

◆ setReceiver()

bool ArnRpc::setReceiver ( QObject *  receiver,
bool  useTrackRpcSender = true 
)

Definition at line 300 of file ArnRpc.cpp.

◆ textReceived

void ArnRpc::textReceived ( const QString &  text)
signal

Signal emitted when a general text message is received.

The text message is received from the other end of the used pipe.

Parameters
[in]textis the received text
See also
sendText();

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