ArnLib  4.0.x
Active Registry Network
ArnSapi Class Reference

Service API. More...

#include <ArnSapi.hpp>

Inheritance diagram for ArnSapi:
Collaboration diagram for ArnSapi:

Public Member Functions

 ArnSapi (QObject *parent=arnNullptr)
 
bool open (const QString &pipePath=QString(), Mode mode=Mode(), const char *providerPrefix=arnNullptr, const char *requesterPrefix=arnNullptr)
 Open a new Service API. More...
 
void batchConnectTo (const QObject *receiver, const QString &prefix=QString(), Mode mode=Mode())
 Make batch connection from this ArnSapi:s signals to another receivers slots/signals. More...
 
void batchConnectFrom (const QObject *sender, const QString &prefix=QString(), Mode mode=Mode())
 Make batch connection from one senders signals to this ArnSapi:s signals. More...
 
QString defaultPath () const
 Get default path for the pipe to be used. More...
 
- Public Member Functions inherited from ArnRpc
 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...
 

Protected Member Functions

 ArnSapi (const QString &defaultPath, QObject *parent=arnNullptr)
 
void setDefaultPath (const QString &defaultPath)
 Set default path for the pipe to be used. More...
 

Additional Inherited Members

- Public Types inherited from ArnRpc
typedef ArnRpcMode Mode
 
- Public Slots inherited from ArnRpc
void sendText (const QString &txt)
 Send a general text message to the other end of the used pipe More...
 
- Signals inherited from ArnRpc
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...
 
- Static Public Member Functions inherited from ArnRpc
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

Service API.

About RPC and SAPI

This class serves as a base class for Service Application Programming Interface. It should be derived to a custom class that descibe a specific SAPI.

By default all provider services are prefixed by "pv_" and all requester "services" are prefixed by "rq_". This standard can be changed.

The meta prefix no_queue is used to limit the filling of sendqueue with recuring RPC calls during some kind of client disconnection. Matched function name in sendqueue is overwritten by the last call. This functionality uses pipe anti congest. This is internally used for heart beat, but other typical usages can be ping, request update etc.

Example usage

class ChatSapi : public ArnSapi
{
Q_OBJECT
public:
explicit ChatSapi( QObject* parent = arnNullptr) : ArnSapi( parent) {}
signals:
no_queue void pv_list();
void pv_newMsg( QString name, QString msg);
void pv_infoQ();
void rq_updateMsg( int seq, QString name, QString msg);
void rq_info( QString name, QString ver);
};
// In class declare (MyClass)
ChatSapi* _commonSapi;
// In class code (MyClass)
typedef ArnSapi::Mode SMode;
_commonSapi = new ChatSapi( this);
_commonSapi->open("//Chat/Pipes/pipeCommon", SMode::Provider | SMode::UseDefaultCall);
_commonSapi->batchConnectTo( this, "sapi");
.
.
void ServerMain::sapiNewMsg( QString name, QString msg)
{
int seq = ...;
_commonSapi->rq_updateMsg( seq, name, msg);
}
void MyClass::sapiInfoQ()
{
ChatSapi* sapi = qobject_cast<ChatSapi*>( sender());
sapi->rq_info("Arn Chat Demo", "1.0");
}
void MainWindow::sapiDefault( const QByteArray& data)
{
ChatSapi* sapi = qobject_cast<ChatSapi*>( sender());
qDebug() << "chatDefault:" << data;
sapi->sendText("Chat Sapi: Can't find method, use $help.");
}
Examples:
ArnDemoChatServer/ChatSapi.hpp.

Definition at line 115 of file ArnSapi.hpp.

Constructor & Destructor Documentation

◆ ArnSapi() [1/2]

ArnSapi::ArnSapi ( QObject *  parent = arnNullptr)
explicit
Examples:
ArnDemoChatServer/ChatSapi.hpp.

Definition at line 47 of file ArnSapi.cpp.

◆ ArnSapi() [2/2]

ArnSapi::ArnSapi ( const QString &  defaultPath,
QObject *  parent = arnNullptr 
)
protected

Definition at line 53 of file ArnSapi.cpp.

Member Function Documentation

◆ batchConnectFrom()

void ArnSapi::batchConnectFrom ( const QObject *  sender,
const QString &  prefix = QString(),
ArnRpc::Mode  mode = Mode() 
)

Make batch connection from one senders signals to this ArnSapi:s signals.

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

Example: Requester doing _commonSapi.batchConnectFrom( mySender, "sapi"); Can connect signal: sapiNewMsg(QString,QString) to signal: pv_newMsg(QString,QString)

Parameters
[in]senderis the sending QObject.
[in]prefixis the prefix for sending signal names.
[in]mode
See also
ArnRpc::batchConnect(const QObject*, const ARN_RegExp&, const QObject*, const QString&, Mode)

Definition at line 107 of file ArnSapi.cpp.

◆ batchConnectTo()

void ArnSapi::batchConnectTo ( const QObject *  receiver,
const QString &  prefix = QString(),
ArnRpc::Mode  mode = Mode() 
)

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

Used when there is a specific 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.

When Mode::UseDefaultCall is active, then also the defaultCall() signal is connected to the receiver. Method name will be using the prefix and end with "Default". E.g. prefix is "sapi" will give method name "sapiDefault".

Example: Provider doing _commonSapi.batchConnectTo( myReceiver, "sapi"); Can connect signal: pv_newMsg(QString,QString) to slot: sapiNewMsg(QString,QString)

Parameters
[in]receiveris the receiving QObject.
[in]prefixis the prefix for receiving slot/signal names.
[in]mode
See also
ArnRpc::batchConnect( const QObject*, const ARN_RegExp&, const QObject*, const QString&, Mode)

Definition at line 89 of file ArnSapi.cpp.

◆ defaultPath()

QString ArnSapi::defaultPath ( ) const

Get default path for the pipe to be used.

Returns
default path

Definition at line 118 of file ArnSapi.cpp.

◆ open()

bool ArnSapi::open ( const QString &  pipePath = QString(),
Mode  mode = Mode(),
const char *  providerPrefix = arnNullptr,
const char *  requesterPrefix = arnNullptr 
)

Open a new Service API.

The opened Sapi can be either the provider side or the requester side, which is indicated by mode. The provider marker "!" in the pipePath will automatically be set/removed in accordance to the mode.

Typically the provider is only using mode Provider. The requester can use default mode for a static pipe and typically use the UuidAutoDestroy mode for dynamic session pipes.

Parameters
[in]pipePathis the path used for Sapi. Empty string gives default.
[in]mode
[in]providerPrefixto set a custom prefix for provider signals.
[in]requesterPrefixto set a custom prefix for requester signals.
Return values
falseif error
See also
Pipe Arn Data Objects
setDefaultPath()

Definition at line 66 of file ArnSapi.cpp.

◆ setDefaultPath()

void ArnSapi::setDefaultPath ( const QString &  defaultPath)
protected

Set default path for the pipe to be used.

A provider path will always be converted to a non provider path.

Parameters
[in]defaultPath
See also
defaultPath()
open()

Definition at line 126 of file ArnSapi.cpp.


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