Skip to content

Commit

Permalink
Pass arguments by reference
Browse files Browse the repository at this point in the history
  • Loading branch information
syyyr committed Nov 25, 2024
1 parent 53996d6 commit 0c782c6
Show file tree
Hide file tree
Showing 33 changed files with 94 additions and 94 deletions.
4 changes: 2 additions & 2 deletions examples/cli/minimalshvclient/src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ void Application::unsubscribeChanges(const string &shv_path)
}

void Application::callShvMethod(const std::string &shv_path, const std::string &method, const shv::chainpack::RpcValue &params, const QObject *context
, std::function<void (const shv::chainpack::RpcValue &)> success_callback
, std::function<void (const shv::chainpack::RpcError &)> error_callback)
, const std::function<void (const shv::chainpack::RpcValue &)>& success_callback
, const std::function<void (const shv::chainpack::RpcError &)>& error_callback)
{
auto *rpcc = RpcCall::create(m_rpcConnection)
->setShvPath(shv_path)
Expand Down
4 changes: 2 additions & 2 deletions examples/cli/minimalshvclient/src/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class Application : public QCoreApplication
private:
void callShvMethod(const std::string &shv_path, const std::string &method, const shv::chainpack::RpcValue &params,
const QObject *context = nullptr,
std::function<void(const shv::chainpack::RpcValue &)> success_callback = nullptr,
std::function<void (const shv::chainpack::RpcError &)> error_callback = nullptr);
const std::function<void(const shv::chainpack::RpcValue &)>& success_callback = nullptr,
const std::function<void (const shv::chainpack::RpcError &)>& error_callback = nullptr);
void subscribeChanges(const std::string &shv_path);
void unsubscribeChanges(const std::string &shv_path);
void onRpcMessageReceived(const shv::chainpack::RpcMessage &msg);
Expand Down
2 changes: 1 addition & 1 deletion libshvbroker/include/shv/broker/brokerapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class SHVBROKER_DECL_EXPORT BrokerApp : public QCoreApplication
void reloadConfigRemountDevices();
bool checkTunnelSecret(const std::string &s);

void checkLogin(const chainpack::UserLoginContext &ctx, const QObject* connection_ctx, const std::function<void(chainpack::UserLoginResult)> cb);
void checkLogin(const chainpack::UserLoginContext &ctx, const QObject* connection_ctx, const std::function<void(chainpack::UserLoginResult)>& cb);

void sendNewLogEntryNotify(const std::string &msg);

Expand Down
2 changes: 1 addition & 1 deletion libshvbroker/src/brokeraclnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const chainpack::MetaMethod *BrokerAclNode::metaMethod(const iotqt::node::ShvNod
SHV_EXCEPTION("Invalid method index: " + std::to_string(ix) + " on shv path: " + shv_path.join('/'));
}

std::string BrokerAclNode::saveConfigFile(const std::string &file_name, const chainpack::RpcValue val)
std::string BrokerAclNode::saveConfigFile(const std::string &file_name, const chainpack::RpcValue& val)
{
BrokerApp *app = BrokerApp::instance();
std::string fn = app->cliOptions()->configDir() + '/' + file_name;
Expand Down
2 changes: 1 addition & 1 deletion libshvbroker/src/brokeraclnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BrokerAclNode : public shv::iotqt::node::MethodsTableNode
size_t methodCount(const StringViewList &shv_path) override;
const shv::chainpack::MetaMethod* metaMethod(const StringViewList &shv_path, size_t ix) override;

std::string saveConfigFile(const std::string &file_name, const shv::chainpack::RpcValue val);
std::string saveConfigFile(const std::string &file_name, const shv::chainpack::RpcValue& val);
};

class MountsAclNode : public BrokerAclNode
Expand Down
2 changes: 1 addition & 1 deletion libshvbroker/src/brokerapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ class AzureAuth : public QObject {
};
#endif

void BrokerApp::checkLogin(const chainpack::UserLoginContext &ctx, const QObject* connection_ctx, const std::function<void(chainpack::UserLoginResult)> cb)
void BrokerApp::checkLogin(const chainpack::UserLoginContext &ctx, const QObject* connection_ctx, const std::function<void(chainpack::UserLoginResult)>& cb)
{
if (ctx.userLogin().loginType == chainpack::UserLogin::LoginType::AzureAccessToken && m_azureConfig) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
Expand Down
20 changes: 10 additions & 10 deletions libshvchainpack/include/shv/chainpack/irpcconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ class SHVCHAINPACK_DECL_EXPORT IRpcConnection
void sendResponse(const shv::chainpack::RpcValue &request_id, const shv::chainpack::RpcValue &result);
void sendError(const shv::chainpack::RpcValue &request_id, const shv::chainpack::RpcResponse::Error &error);
int callMethod(const shv::chainpack::RpcRequest &rq);
int callShvMethod(const std::string &shv_path, std::string method, const shv::chainpack::RpcValue &params = shv::chainpack::RpcValue());
int callShvMethod(const std::string &shv_path, std::string method, const shv::chainpack::RpcValue &params, const shv::chainpack::RpcValue &user_id);
int callShvMethod(int rq_id, const std::string &shv_path, std::string method, const shv::chainpack::RpcValue &params = shv::chainpack::RpcValue());
int callShvMethod(int rq_id, const std::string &shv_path, std::string method, const shv::chainpack::RpcValue &params, const shv::chainpack::RpcValue &user_id);

int callMethodSubscribeGlob(std::string glob);
int callMethodSubscribe(const std::string &shv_path, std::string method, const std::string& source = "");
int callMethodSubscribe(int rq_id, const std::string &shv_path, std::string method, const std::string& source = "");
int callMethodUnsubscribe(const std::string &shv_path, std::string method, const std::string& source = "");
int callMethodUnsubscribe(int rq_id, const std::string &shv_path, std::string method, const std::string& source = "");
int callShvMethod(const std::string &shv_path, const std::string& method, const shv::chainpack::RpcValue &params = shv::chainpack::RpcValue());
int callShvMethod(const std::string &shv_path, const std::string& method, const shv::chainpack::RpcValue &params, const shv::chainpack::RpcValue &user_id);
int callShvMethod(int rq_id, const std::string &shv_path, const std::string& method, const shv::chainpack::RpcValue &params = shv::chainpack::RpcValue());
int callShvMethod(int rq_id, const std::string &shv_path, const std::string& method, const shv::chainpack::RpcValue &params, const shv::chainpack::RpcValue &user_id);

int callMethodSubscribeGlob(const std::string& glob);
int callMethodSubscribe(const std::string &shv_path, const std::string& method, const std::string& source = "");
int callMethodSubscribe(int rq_id, const std::string &shv_path, const std::string& method, const std::string& source = "");
int callMethodUnsubscribe(const std::string &shv_path, const std::string& method, const std::string& source = "");
int callMethodUnsubscribe(int rq_id, const std::string &shv_path, const std::string& method, const std::string& source = "");
protected:
static int nextConnectionId();
protected:
Expand Down
10 changes: 5 additions & 5 deletions libshvchainpack/include/shv/chainpack/metamethod.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ class SHVCHAINPACK_DECL_EXPORT MetaMethod
static constexpr auto KEY_SIGNALS = "signals";
public:
struct SHVCHAINPACK_DECL_EXPORT Signal {
Signal(std::string name, std::optional<std::string> param_type = {});
Signal(const std::string& name, const std::optional<std::string>& param_type = {});
std::string name;
std::optional<std::string> param_type;
};

MetaMethod();
MetaMethod(
std::string name,
const std::string& name,
unsigned flags = 0,
std::optional<std::string> param = {},
std::optional<std::string> result = {},
const std::optional<std::string>& param = {},
const std::optional<std::string>& result = {},
AccessLevel access_level = AccessLevel::Browse,
const std::vector<Signal>& signal_definitions = {},
const std::string& description = {},
const std::string& label = {},
const RpcValue::Map& extra = {});

// SHV 2 compatibility constructor
MetaMethod(std::string name,
MetaMethod(const std::string& name,
Signature signature,
unsigned flags,
const std::string &access_grant,
Expand Down
2 changes: 1 addition & 1 deletion libshvchainpack/include/shv/chainpack/rpcmessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class SHVCHAINPACK_DECL_EXPORT RpcSignal : public RpcRequest
public:
RpcRequest& setRequestId(const RpcValue::Int requestId) = delete;

static void write(AbstractStreamWriter &wr, const std::string &method, std::function<void (AbstractStreamWriter &)> write_params_callback);
static void write(AbstractStreamWriter &wr, const std::string &method, const std::function<void (AbstractStreamWriter &)>& write_params_callback);
};

class SHVCHAINPACK_DECL_EXPORT RpcException : public Exception
Expand Down
24 changes: 12 additions & 12 deletions libshvchainpack/src/irpcconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,27 @@ int IRpcConnection::callMethod(const RpcRequest &rq)
return id;
}

int IRpcConnection::callShvMethod(const std::string &shv_path, std::string method, const RpcValue &params)
int IRpcConnection::callShvMethod(const std::string &shv_path, const std::string& method, const RpcValue &params)
{
return callShvMethod(shv_path, method, params, {});
}

int IRpcConnection::callShvMethod(const std::string &shv_path, std::string method, const RpcValue &params, const RpcValue &user_id)
int IRpcConnection::callShvMethod(const std::string &shv_path, const std::string& method, const RpcValue &params, const RpcValue &user_id)
{
int id = nextRequestId();
return callShvMethod(id, shv_path, method, params, user_id);
}

int IRpcConnection::callShvMethod(int rq_id, const std::string &shv_path, std::string method, const RpcValue &params)
int IRpcConnection::callShvMethod(int rq_id, const std::string &shv_path, const std::string& method, const RpcValue &params)
{
return callShvMethod(rq_id, shv_path, method, params, {});
}

int IRpcConnection::callShvMethod(int rq_id, const std::string &shv_path, std::string method, const RpcValue &params, const RpcValue &user_id)
int IRpcConnection::callShvMethod(int rq_id, const std::string &shv_path, const std::string& method, const RpcValue &params, const RpcValue &user_id)
{
RpcRequest rq;
rq.setRequestId(rq_id);
rq.setMethod(std::move(method));
rq.setMethod(method);
if(params.isValid())
rq.setParams(params);
if(user_id.isValid())
Expand All @@ -104,7 +104,7 @@ int IRpcConnection::callShvMethod(int rq_id, const std::string &shv_path, std::s
return rq_id;
}

int IRpcConnection::callMethodSubscribeGlob(std::string glob)
int IRpcConnection::callMethodSubscribeGlob(const std::string& glob)
{
logSubscriptionsD() << "call subscribe for connection id:" << connectionId() << "glob:" << glob;
int rq_id = nextRequestId();
Expand All @@ -119,13 +119,13 @@ int IRpcConnection::callMethodSubscribeGlob(std::string glob)
return 0;
}

int IRpcConnection::callMethodSubscribe(const std::string &shv_path, std::string method, const std::string& source)
int IRpcConnection::callMethodSubscribe(const std::string &shv_path, const std::string& method, const std::string& source)
{
int rq_id = nextRequestId();
return callMethodSubscribe(rq_id, shv_path, method, source);
}

int IRpcConnection::callMethodSubscribe(int rq_id, const std::string &shv_path, std::string method, const std::string& source)
int IRpcConnection::callMethodSubscribe(int rq_id, const std::string &shv_path, const std::string& method, const std::string& source)
{
logSubscriptionsD() << "call subscribe for connection id:" << connectionId() << "path:" << shv_path << "method:" << method << "source:" << source;
if(m_shvApiVersion == ShvApiVersion::V3) {
Expand All @@ -142,18 +142,18 @@ int IRpcConnection::callMethodSubscribe(int rq_id, const std::string &shv_path,
, Rpc::METH_SUBSCRIBE
, RpcValue::Map{
{Rpc::PAR_PATH, shv_path},
{Rpc::PAR_METHOD, std::move(method)},
{Rpc::PAR_METHOD, method},
{Rpc::PAR_SOURCE, source},
});
}

int IRpcConnection::callMethodUnsubscribe(const std::string &shv_path, std::string method, const std::string& source)
int IRpcConnection::callMethodUnsubscribe(const std::string &shv_path, const std::string& method, const std::string& source)
{
int rq_id = nextRequestId();
return callMethodUnsubscribe(rq_id, shv_path, method, source);
}

int IRpcConnection::callMethodUnsubscribe(int rq_id, const std::string &shv_path, std::string method, const std::string& source)
int IRpcConnection::callMethodUnsubscribe(int rq_id, const std::string &shv_path, const std::string& method, const std::string& source)
{
logSubscriptionsD() << "call unsubscribe for connection id:" << connectionId() << "path:" << shv_path << "method:" << method << "source:" << source;
if(m_shvApiVersion == ShvApiVersion::V3) {
Expand All @@ -170,7 +170,7 @@ int IRpcConnection::callMethodUnsubscribe(int rq_id, const std::string &shv_path
, Rpc::METH_UNSUBSCRIBE
, RpcValue::Map{
{Rpc::PAR_PATH, shv_path},
{Rpc::PAR_METHOD, std::move(method)},
{Rpc::PAR_METHOD, method},
{Rpc::PAR_SOURCE, source},
});
}
Expand Down
10 changes: 5 additions & 5 deletions libshvchainpack/src/metamethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ constexpr auto KEY_ACCESSGRANT = "accessGrant";
constexpr auto VOID_TYPE_NAME = "Null";
}

MetaMethod::Signal::Signal(std::string _name, std::optional<std::string> _param_type)
MetaMethod::Signal::Signal(const std::string& _name, const std::optional<std::string>& _param_type)
: name(_name)
, param_type(_param_type)
{
}

MetaMethod::MetaMethod() = default;

MetaMethod::MetaMethod(std::string name,
MetaMethod::MetaMethod(const std::string& name,
unsigned flags,
std::optional<std::string> param,
std::optional<std::string> result,
const std::optional<std::string>& param,
const std::optional<std::string>& result,
AccessLevel access_level,
const std::vector<Signal>& signal_definitions,
const std::string& description,
Expand All @@ -41,7 +41,7 @@ MetaMethod::MetaMethod(std::string name,
}
}

MetaMethod::MetaMethod(std::string name,
MetaMethod::MetaMethod(const std::string& name,
Signature signature,
unsigned int flags,
const std::string &access_grant,
Expand Down
2 changes: 1 addition & 1 deletion libshvchainpack/src/rpcmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ RpcSignal::RpcSignal(const RpcMessage &msg)

RpcSignal::~RpcSignal() = default;

void RpcSignal::write(AbstractStreamWriter &wr, const std::string &method, std::function<void (AbstractStreamWriter &)> write_params_callback)
void RpcSignal::write(AbstractStreamWriter &wr, const std::string &method, const std::function<void (AbstractStreamWriter &)>& write_params_callback)
{
RpcValue::MetaData md;
md.setMetaTypeId(RpcMessage::MetaType::ID);
Expand Down
4 changes: 2 additions & 2 deletions libshvcore/include/shv/core/utils/clioptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ class SHVCORE_DECL_EXPORT CLIOptions
bool optionExists(const std::string &name) const;
chainpack::RpcValue::Map values() const;
chainpack::RpcValue value(const std::string &name) const;
chainpack::RpcValue value(const std::string &name, const chainpack::RpcValue default_value) const;
chainpack::RpcValue value(const std::string &name, const chainpack::RpcValue& default_value) const;
/// value is explicitly set from command line or in config file
/// defaultValue is not considered to be an explicitly set value
bool isValueSet(const std::string &name) const;
bool setValue(const std::string &name, const chainpack::RpcValue val, bool throw_exc = true);
bool setValue(const std::string &name, const chainpack::RpcValue& val, bool throw_exc = true);
protected:
chainpack::RpcValue value_helper(const std::string &name, bool throw_exception) const;
std::tuple<std::string, std::string> applicationDirAndName() const;
Expand Down
4 changes: 2 additions & 2 deletions libshvcore/include/shv/core/utils/crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class SHVCORE_DECL_EXPORT Crypt
public:
using Generator = std::function< uint32_t (uint32_t) >;
public:
Crypt(Generator gen = nullptr);
Crypt(const Generator& gen = nullptr);
public:
static Generator createGenerator(uint32_t a, uint32_t b, uint32_t max_rand);

/// any of function, functor or lambda can be set as a random number generator
void setGenerator(Generator gen);
void setGenerator(const Generator& gen);

/// @a min_length minimal length of digest
/// @return string crypted by 0-9, A-Z, a-z characters
Expand Down
2 changes: 1 addition & 1 deletion libshvcore/include/shv/core/utils/shvfilejournal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SHVCORE_DECL_EXPORT ShvFileJournal : public AbstractShvJournal
static const std::string FILE_EXT;
public:
ShvFileJournal();
ShvFileJournal(std::string device_id);
ShvFileJournal(const std::string& device_id);

void setJournalDir(std::string s);
const std::string& journalDir();
Expand Down
12 changes: 6 additions & 6 deletions libshvcore/include/shv/core/utils/shvjournalentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class SHVCORE_DECL_EXPORT ShvJournalEntry
std::string userId;

ShvJournalEntry();
ShvJournalEntry(std::string path_, shv::chainpack::RpcValue value_, std::string domain_, int short_time, ValueFlags flags, int64_t epoch_msec = 0);
ShvJournalEntry(std::string path_, shv::chainpack::RpcValue value_);
ShvJournalEntry(std::string path_, shv::chainpack::RpcValue value_, int short_time);
ShvJournalEntry(std::string path_, shv::chainpack::RpcValue value_, std::string domain_);
ShvJournalEntry(const std::string& path_, const shv::chainpack::RpcValue& value_, const std::string& domain_, int short_time, ValueFlags flags, int64_t epoch_msec = 0);
ShvJournalEntry(const std::string& path_, const shv::chainpack::RpcValue& value_);
ShvJournalEntry(const std::string& path_, const shv::chainpack::RpcValue& value_, int short_time);
ShvJournalEntry(const std::string& path_, const shv::chainpack::RpcValue& value_, const std::string& domain_);

bool isValid() const;
bool isSpontaneous() const;
Expand All @@ -65,13 +65,13 @@ class SHVCORE_DECL_EXPORT ShvJournalEntry
void setShortTime(int short_time);
shv::chainpack::RpcValue::DateTime dateTime() const;
shv::chainpack::RpcValue toRpcValueMap() const;
shv::chainpack::RpcValue toRpcValueList(std::function< chainpack::RpcValue (const std::string &)> map_path = nullptr) const;
shv::chainpack::RpcValue toRpcValueList(const std::function< chainpack::RpcValue (const std::string &)>& map_path = nullptr) const;

static bool isShvJournalEntry(const shv::chainpack::RpcValue &rv);
shv::chainpack::RpcValue toRpcValue() const;
static ShvJournalEntry fromRpcValue(const shv::chainpack::RpcValue &rv);
static ShvJournalEntry fromRpcValueMap(const shv::chainpack::RpcValue::Map &m);
static ShvJournalEntry fromRpcValueList(const shv::chainpack::RpcList &row, std::function< std::string (const chainpack::RpcValue &)> unmap_path = nullptr, std::string *err = nullptr);
static ShvJournalEntry fromRpcValueList(const shv::chainpack::RpcList &row, const std::function< std::string (const chainpack::RpcValue &)>& unmap_path = nullptr, std::string *err = nullptr);

shv::chainpack::DataChange toDataChange() const;
};
Expand Down
4 changes: 2 additions & 2 deletions libshvcore/include/shv/core/utils/shvtypeinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ class SHVCORE_DECL_EXPORT ShvTypeInfo
shv::chainpack::RpcValue applyTypeDescription(const shv::chainpack::RpcValue &val, const std::string &type_name, bool translate_enums = true, bool recursive_bitfields = true) const;
shv::chainpack::RpcValue applyTypeDescription(const shv::chainpack::RpcValue &val, const ShvTypeDescr &type_descr, bool translate_enums = true, bool recursive_bitfields = true) const;

void forEachDeviceProperty(const std::string &device_type, std::function<void (const ShvPropertyDescr &)> fn) const;
void forEachProperty(std::function<void (const std::string &shv_path, const ShvPropertyDescr &)> fn) const;
void forEachDeviceProperty(const std::string &device_type, const std::function<void (const ShvPropertyDescr &)>& fn) const;
void forEachProperty(const std::function<void (const std::string &shv_path, const ShvPropertyDescr &)>& fn) const;
private:
static ShvTypeInfo fromNodesTree(const chainpack::RpcValue &v);
void fromNodesTree_helper(const shv::chainpack::RpcValue::Map &node_types,
Expand Down
4 changes: 2 additions & 2 deletions libshvcore/src/utils/clioptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ RpcValue CLIOptions::value(const std::string &name) const
return ret;
}

RpcValue CLIOptions::value(const std::string& name, const RpcValue default_value) const
RpcValue CLIOptions::value(const std::string& name, const RpcValue& default_value) const
{
RpcValue ret = value_helper(name, !shv::core::Exception::Throw);
if(!ret.isValid())
Expand Down Expand Up @@ -254,7 +254,7 @@ bool CLIOptions::optionExists(const std::string &name) const
return option(name, !shv::core::Exception::Throw).isValid();
}

bool CLIOptions::setValue(const std::string& name, const RpcValue val, bool throw_exc)
bool CLIOptions::setValue(const std::string& name, const RpcValue& val, bool throw_exc)
{
Option o = option(name, false);
if(optionExists(name)) {
Expand Down
4 changes: 2 additions & 2 deletions libshvcore/src/utils/crypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace shv::core::utils {
// Crypt
//===================================================================
/// http://www.math.utah.edu/~pa/Random/Random.html
Crypt::Crypt(Crypt::Generator gen)
Crypt::Crypt(const Crypt::Generator& gen)
: m_generator(gen)
{
if(m_generator == nullptr)
Expand All @@ -31,7 +31,7 @@ Crypt::Generator Crypt::createGenerator(uint32_t a, uint32_t b, uint32_t max_ran
return ret;
}

void Crypt::setGenerator(Generator gen)
void Crypt::setGenerator(const Generator& gen)
{
m_generator = gen;
}
Expand Down
2 changes: 1 addition & 1 deletion libshvcore/src/utils/shvfilejournal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const std::string ShvFileJournal::FILE_EXT = ".log2";

ShvFileJournal::ShvFileJournal() = default;

ShvFileJournal::ShvFileJournal(std::string device_id)
ShvFileJournal::ShvFileJournal(const std::string& device_id)
{
setDeviceId(device_id);
}
Expand Down
Loading

0 comments on commit 0c782c6

Please sign in to comment.