ArnLib  4.0.x
Active Registry Network
ArnSapi.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2022 Michael Wiklund.
2 // All rights reserved.
3 // Contact: arnlib@wiklunden.se
4 //
5 // This file is part of the ArnLib - Active Registry Network.
6 // Parts of ArnLib depend on Qt and/or other libraries that have their own
7 // licenses. Usage of these other libraries is subject to their respective
8 // license agreements.
9 //
10 // GNU Lesser General Public License Usage
11 // This file may be used under the terms of the GNU Lesser General Public
12 // License version 2.1 as published by the Free Software Foundation and
13 // appearing in the file LICENSE_LGPL.txt included in the packaging of this
14 // file. In addition, as a special exception, you may use the rights described
15 // in the Nokia Qt LGPL Exception version 1.1, included in the file
16 // LGPL_EXCEPTION.txt in this package.
17 //
18 // GNU General Public License Usage
19 // Alternatively, this file may be used under the terms of the GNU General Public
20 // License version 3.0 as published by the Free Software Foundation and appearing
21 // in the file LICENSE_GPL.txt included in the packaging of this file.
22 //
23 // Other Usage
24 // Alternatively, this file may be used in accordance with the terms and conditions
25 // contained in a signed written agreement between you and Michael Wiklund.
26 //
27 // This program is distributed in the hope that it will be useful, but WITHOUT ANY
28 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
29 // PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
30 //
31 
32 #include "ArnInc/ArnSapi.hpp"
33 #include "private/ArnSapi_p.hpp"
34 #include <QDebug>
35 
36 
37 ArnSapiPrivate::ArnSapiPrivate()
38 {
39 }
40 
41 
42 ArnSapiPrivate::~ArnSapiPrivate()
43 {
44 }
45 
46 
47 ArnSapi::ArnSapi( QObject* parent)
48  : ArnRpc( *new ArnSapiPrivate, parent)
49 {
50 }
51 
52 
53 ArnSapi::ArnSapi( const QString& defaultPath, QObject* parent)
54  : ArnRpc( *new ArnSapiPrivate, parent)
55 {
57 }
58 
59 
60 ArnSapi::ArnSapi(ArnSapiPrivate& dd, QObject* parent)
61  : ArnRpc( dd, parent)
62 {
63 }
64 
65 
66 bool ArnSapi::open( const QString& pipePath, Mode mode,
67  const char *providerPrefix, const char *requesterPrefix)
68 {
69  Q_D(ArnSapi);
70 
71  if (mode.is( mode.Provider)) {
72  d->_receivePrefix = providerPrefix ? providerPrefix : "pv_";
73  d->_sendPrefix = requesterPrefix ? requesterPrefix : "rq_";
74  }
75  else {
76  d->_receivePrefix = requesterPrefix ? requesterPrefix : "rq_";
77  d->_sendPrefix = providerPrefix ? providerPrefix : "pv_";
78  }
79 
80  ArnRpc::setMethodPrefix( d->_receivePrefix);
81  ArnRpc::addSenderSignals( this, d->_sendPrefix);
82  ArnRpc::setReceiver( this, false);
84 
85  return ArnRpc::open( pipePath.isEmpty() ? d->_defaultPath : pipePath);
86 }
87 
88 
89 void ArnSapi::batchConnectTo( const QObject* receiver, const QString& prefix, ArnRpc::Mode mode) {
90  Q_D(ArnSapi);
91 
92  batchConnect( this,
93  ARN_RegExp("^" + d->_receivePrefix + "(.+)"),
94  receiver,
95  prefix + "\\1",
96  mode);
98  batchConnect( this,
99  ARN_RegExp("^defaultCall"),
100  receiver,
101  prefix + "Default",
102  mode);
103  }
104 }
105 
106 
107 void ArnSapi::batchConnectFrom( const QObject* sender, const QString& prefix, ArnRpc::Mode mode) {
108  Q_D(ArnSapi);
109 
110  batchConnect( sender,
111  ARN_RegExp("^" + prefix + "(.+)"),
112  this,
113  d->_sendPrefix + "\\1",
114  mode);
115 }
116 
117 
118 QString ArnSapi::defaultPath() const
119 {
120  Q_D(const ArnSapi);
121 
122  return d->_defaultPath;
123 }
124 
125 
126 void ArnSapi::setDefaultPath( const QString& defaultPath)
127 {
128  Q_D(ArnSapi);
129 
130  d->_defaultPath = Arn::providerPathIf( defaultPath, false);
131 }
void setMethodPrefix(const QString &prefix)
Definition: ArnRpc.cpp:337
Mode mode() const
Get the mode.
Definition: ArnRpc.cpp:386
bool setReceiver(QObject *receiver, bool useTrackRpcSender=true)
Definition: ArnRpc.cpp:300
void addSenderSignals(QObject *sender, const QString &prefix)
Definition: ArnRpc.cpp:440
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.
Definition: ArnRpc.cpp:1487
void setDefaultPath(const QString &defaultPath)
Set default path for the pipe to be used.
Definition: ArnSapi.cpp:126
QString defaultPath() const
Get default path for the pipe to be used.
Definition: ArnSapi.cpp:118
Service API.
Definition: ArnSapi.hpp:115
ArnSapi(QObject *parent=arnNullptr)
Definition: ArnSapi.cpp:47
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.
Definition: ArnSapi.cpp:89
#define ARN_RegExp
Definition: ArnCompat.hpp:70
When receiver method missing, send defaultCall() signal instead of error.
Definition: ArnRpc.hpp:109
Remote Procedure Call.
Definition: ArnRpc.hpp:156
QObject * receiver() const
Definition: ArnRpc.cpp:329
Provider side (opposed to requester)
Definition: ArnRpc.hpp:91
bool open(const QString &pipePath=QString(), Mode mode=Mode(), const char *providerPrefix=arnNullptr, const char *requesterPrefix=arnNullptr)
Open a new Service API.
Definition: ArnSapi.cpp:66
QString pipePath() const
Get the path for the used pipe
Definition: ArnRpc.cpp:226
QString providerPathIf(const QString &path, bool giveProviderPath)
Get provider path or requester path
Definition: Arn.cpp:204
void batchConnectFrom(const QObject *sender, const QString &prefix=QString(), Mode mode=Mode())
Make batch connection from one senders signals to this ArnSapi:s signals.
Definition: ArnSapi.cpp:107
bool open(const QString &pipePath)
Definition: ArnRpc.cpp:236
void setMode(Mode mode)
Definition: ArnRpc.cpp:378