Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/consumerstatetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace swss {

ConsumerStateTable::ConsumerStateTable(DBConnector *db, std::string tableName, int popBatchSize, int pri)
ConsumerStateTable::ConsumerStateTable(DBConnector *db, const std::string &tableName, int popBatchSize, int pri)
: ConsumerTableBase(db, tableName, popBatchSize, pri)
, TableName_KeySet(tableName)
{
Expand All @@ -30,7 +30,7 @@ ConsumerStateTable::ConsumerStateTable(DBConnector *db, std::string tableName, i
setQueueLength(r.getReply<long long int>());
}

void ConsumerStateTable::pops(std::deque<KeyOpFieldsValuesTuple> &vkco, std::string /*prefix*/)
void ConsumerStateTable::pops(std::deque<KeyOpFieldsValuesTuple> &vkco, const std::string& /*prefix*/)
{
static std::string luaScript = loadLuaScript("consumer_state_table_pops.lua");

Expand Down
4 changes: 2 additions & 2 deletions common/consumerstatetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace swss {
class ConsumerStateTable : public ConsumerTableBase, public TableName_KeySet
{
public:
ConsumerStateTable(DBConnector *db, std::string tableName, int popBatchSize = DEFAULT_POP_BATCH_SIZE, int pri = 0);
ConsumerStateTable(DBConnector *db, const std::string &tableName, int popBatchSize = DEFAULT_POP_BATCH_SIZE, int pri = 0);

/* Get multiple pop elements */
void pops(std::deque<KeyOpFieldsValuesTuple> &vkco, std::string prefix = EMPTY_PREFIX);
void pops(std::deque<KeyOpFieldsValuesTuple> &vkco, const std::string &prefix = EMPTY_PREFIX);
};

}
4 changes: 2 additions & 2 deletions common/consumertable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using namespace std;

namespace swss {

ConsumerTable::ConsumerTable(DBConnector *db, string tableName, int popBatchSize, int pri)
ConsumerTable::ConsumerTable(DBConnector *db, const string &tableName, int popBatchSize, int pri)
: ConsumerTableBase(db, tableName, popBatchSize, pri)
, TableName_KeyValueOpQueues(tableName)
{
Expand All @@ -34,7 +34,7 @@ ConsumerTable::ConsumerTable(DBConnector *db, string tableName, int popBatchSize
setQueueLength(r.getReply<long long int>());
}

void ConsumerTable::pops(deque<KeyOpFieldsValuesTuple> &vkco, string prefix)
void ConsumerTable::pops(deque<KeyOpFieldsValuesTuple> &vkco, const string &prefix)
{
static std::string luaScript = loadLuaScript("consumer_table_pops.lua");

Expand Down
4 changes: 2 additions & 2 deletions common/consumertable.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ namespace swss {
class ConsumerTable : public ConsumerTableBase, public TableName_KeyValueOpQueues
{
public:
ConsumerTable(DBConnector *db, std::string tableName, int popBatchSize = DEFAULT_POP_BATCH_SIZE, int pri = 0);
ConsumerTable(DBConnector *db, const std::string &tableName, int popBatchSize = DEFAULT_POP_BATCH_SIZE, int pri = 0);

/* Get multiple pop elements */
void pops(std::deque<KeyOpFieldsValuesTuple> &vkco, std::string prefix = EMPTY_PREFIX);
void pops(std::deque<KeyOpFieldsValuesTuple> &vkco, const std::string &prefix = EMPTY_PREFIX);
};

}
Expand Down
6 changes: 3 additions & 3 deletions common/consumertablebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace swss {

ConsumerTableBase::ConsumerTableBase(DBConnector *db, std::string tableName, int popBatchSize, int pri):
ConsumerTableBase::ConsumerTableBase(DBConnector *db, const std::string &tableName, int popBatchSize, int pri):
TableConsumable(db->getDbId(), tableName, pri),
RedisTransactioner(db),
POP_BATCH_SIZE(popBatchSize)
Expand All @@ -13,12 +13,12 @@ ConsumerTableBase::~ConsumerTableBase()
{
}

void ConsumerTableBase::pop(KeyOpFieldsValuesTuple &kco, std::string prefix)
void ConsumerTableBase::pop(KeyOpFieldsValuesTuple &kco, const std::string &prefix)
{
pop(kfvKey(kco), kfvOp(kco), kfvFieldsValues(kco), prefix);
}

void ConsumerTableBase::pop(std::string &key, std::string &op, std::vector<FieldValueTuple> &fvs, std::string prefix)
void ConsumerTableBase::pop(std::string &key, std::string &op, std::vector<FieldValueTuple> &fvs, const std::string &prefix)
{
if (m_buffer.empty())
{
Expand Down
6 changes: 3 additions & 3 deletions common/consumertablebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class ConsumerTableBase: public TableConsumable, public RedisTransactioner
public:
const int POP_BATCH_SIZE;

ConsumerTableBase(DBConnector *db, std::string tableName, int popBatchSize = DEFAULT_POP_BATCH_SIZE, int pri = 0);
ConsumerTableBase(DBConnector *db, const std::string &tableName, int popBatchSize = DEFAULT_POP_BATCH_SIZE, int pri = 0);

virtual ~ConsumerTableBase();

void pop(KeyOpFieldsValuesTuple &kco, std::string prefix = EMPTY_PREFIX);
void pop(KeyOpFieldsValuesTuple &kco, const std::string &prefix = EMPTY_PREFIX);

void pop(std::string &key, std::string &op, std::vector<FieldValueTuple> &fvs, std::string prefix = EMPTY_PREFIX);
void pop(std::string &key, std::string &op, std::vector<FieldValueTuple> &fvs, const std::string &prefix = EMPTY_PREFIX);

protected:

Expand Down
8 changes: 4 additions & 4 deletions common/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace swss {

static inline uint64_t __to_uint64(std::string str, uint64_t min = std::numeric_limits<uint64_t>::min(), uint64_t max = std::numeric_limits<uint64_t>::max())
static inline uint64_t __to_uint64(const std::string &str, uint64_t min = std::numeric_limits<uint64_t>::min(), uint64_t max = std::numeric_limits<uint64_t>::max())
{
size_t idx = 0;
uint64_t ret = stoul(str, &idx, 0);
Expand All @@ -27,7 +27,7 @@ static inline uint64_t __to_uint64(std::string str, uint64_t min = std::numeric_
return ret;
}

static inline int64_t __to_int64(std::string str, int64_t min = std::numeric_limits<int64_t>::min(), int64_t max = std::numeric_limits<int64_t>::max())
static inline int64_t __to_int64(const std::string &str, int64_t min = std::numeric_limits<int64_t>::min(), int64_t max = std::numeric_limits<int64_t>::max())
{
size_t idx = 0;
int64_t ret = stol(str, &idx, 0);
Expand All @@ -45,7 +45,7 @@ static inline int64_t __to_int64(std::string str, int64_t min = std::numeric_lim
}

template <typename T>
T to_int(std::string str, T min = std::numeric_limits<T>::min(), T max = std::numeric_limits<T>::max())
T to_int(const std::string &str, T min = std::numeric_limits<T>::min(), T max = std::numeric_limits<T>::max())
{
static_assert(std::is_signed<T>::value, "Signed integer is expected");
static_assert(std::numeric_limits<T>::max() <= std::numeric_limits<int64_t>::max(), "Type is too big");
Expand All @@ -54,7 +54,7 @@ T to_int(std::string str, T min = std::numeric_limits<T>::min(), T max = std::nu
}

template <typename T>
T to_uint(std::string str, T min = std::numeric_limits<T>::min(), T max = std::numeric_limits<T>::max())
T to_uint(const std::string &str, T min = std::numeric_limits<T>::min(), T max = std::numeric_limits<T>::max())
{
static_assert(std::is_unsigned<T>::value, "Unsigned integer is expected");
static_assert(std::numeric_limits<T>::max() <= std::numeric_limits<uint64_t>::max(), "Type is too big");
Expand Down
4 changes: 2 additions & 2 deletions common/dbconnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ DBConnector::~DBConnector()
redisFree(m_conn);
}

DBConnector::DBConnector(int dbId, string hostname, int port,
DBConnector::DBConnector(int dbId, const string& hostname, int port,
unsigned int timeout) :
m_dbId(dbId)
{
Expand All @@ -46,7 +46,7 @@ DBConnector::DBConnector(int dbId, string hostname, int port,
select(this);
}

DBConnector::DBConnector(int dbId, string unixPath, unsigned int timeout) :
DBConnector::DBConnector(int dbId, const string& unixPath, unsigned int timeout) :
m_dbId(dbId)
{
struct timeval tv = {0, (suseconds_t)timeout * 1000};
Expand Down
4 changes: 2 additions & 2 deletions common/dbconnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class DBConnector
* Timeout - The time in milisecond until exception is been thrown. For
* infinite wait, set this value to 0
*/
DBConnector(int dbId, std::string hostname, int port, unsigned int timeout);
DBConnector(int dbId, std::string unixPath, unsigned int timeout);
DBConnector(int dbId, const std::string &hostname, int port, unsigned int timeout);
DBConnector(int dbId, const std::string &unixPath, unsigned int timeout);

~DBConnector();

Expand Down
2 changes: 1 addition & 1 deletion common/ipaddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ IpAddress::IpAddress(uint32_t ip)

IpAddress::IpAddress(const std::string &ipStr)
{
if (ipStr.find(":") != std::string::npos)
if (ipStr.find(':') != std::string::npos)
{
m_ip.family = AF_INET6;
}
Expand Down
2 changes: 1 addition & 1 deletion common/ipaddresses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using namespace swss;
IpAddresses::IpAddresses(const string &ipsStr)
{
auto ips = tokenize(ipsStr, IP_DELIMITER);
for (auto ip : ips)
for (const auto &ip : ips)
m_ips.insert(ip);
}

Expand Down
24 changes: 12 additions & 12 deletions common/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#include <sstream>
#include <iomanip>
#include <stdexcept>
#include <schema.h>
#include <select.h>
#include <dbconnector.h>
#include <redisclient.h>
#include <consumerstatetable.h>
#include <producerstatetable.h>
#include "schema.h"
#include "select.h"
#include "dbconnector.h"
#include "redisclient.h"
#include "consumerstatetable.h"
#include "producerstatetable.h"

namespace swss {

Expand All @@ -34,7 +34,7 @@ const Logger::PriorityStringMap Logger::priorityStringMap = {
{ "DEBUG", SWSS_DEBUG }
};

void Logger::swssPrioNotify(std::string component, std::string prioStr)
void Logger::swssPrioNotify(const std::string &component, const std::string &prioStr)
{
auto& logger = getInstance();

Expand All @@ -55,7 +55,7 @@ const Logger::OutputStringMap Logger::outputStringMap = {
{ "STDERR", SWSS_STDERR }
};

void Logger::swssOutputNotify(std::string component, std::string outputStr)
void Logger::swssOutputNotify(const std::string &component, const std::string &outputStr)
{
auto& logger = getInstance();

Expand All @@ -70,7 +70,7 @@ void Logger::swssOutputNotify(std::string component, std::string outputStr)
}
}

void Logger::linkToDbWithOutput(const std::string dbName, const PriorityChangeNotify& prioNotify, const std::string& defPrio, const OutputChangeNotify& outputNotify, const std::string& defOutput)
void Logger::linkToDbWithOutput(const std::string &dbName, const PriorityChangeNotify& prioNotify, const std::string& defPrio, const OutputChangeNotify& outputNotify, const std::string& defOutput)
{
auto& logger = getInstance();

Expand Down Expand Up @@ -122,12 +122,12 @@ void Logger::linkToDbWithOutput(const std::string dbName, const PriorityChangeNo
outputNotify(dbName, output);
}

void Logger::linkToDb(const std::string dbName, const PriorityChangeNotify& prioNotify, const std::string& defPrio)
void Logger::linkToDb(const std::string &dbName, const PriorityChangeNotify& prioNotify, const std::string& defPrio)
{
linkToDbWithOutput(dbName, prioNotify, defPrio, swssOutputNotify, "SYSLOG");
}

void Logger::linkToDbNative(const std::string dbName)
void Logger::linkToDbNative(const std::string &dbName)
{
auto& logger = getInstance();

Expand Down Expand Up @@ -188,7 +188,7 @@ Logger::Priority Logger::getMinPrio()
auto values = kfvFieldsValues(koValues);
for (const auto& i : values)
{
std::string field = fvField(i), value = fvValue(i);
const std::string &field = fvField(i), &value = fvValue(i);
if ((field == DAEMON_LOGLEVEL) && (value != m_currentPrios[key]))
{
m_currentPrios[key] = value;
Expand Down
12 changes: 6 additions & 6 deletions common/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ class Logger
static Logger &getInstance();
static void setMinPrio(Priority prio);
static Priority getMinPrio();
static void linkToDbWithOutput(const std::string dbName, const PriorityChangeNotify& prioNotify, const std::string& defPrio, const OutputChangeNotify& outputNotify, const std::string& defOutput);
static void linkToDb(const std::string dbName, const PriorityChangeNotify& notify, const std::string& defPrio);
static void linkToDbWithOutput(const std::string &dbName, const PriorityChangeNotify& prioNotify, const std::string& defPrio, const OutputChangeNotify& outputNotify, const std::string& defOutput);
static void linkToDb(const std::string &dbName, const PriorityChangeNotify& notify, const std::string& defPrio);
// Must be called after all linkToDb to start select from DB
static void linkToDbNative(const std::string dbName);
static void linkToDbNative(const std::string &dbName);
void write(Priority prio, const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 3, 4)))
Expand Down Expand Up @@ -112,9 +112,9 @@ class Logger
Logger(const Logger&);
Logger &operator=(const Logger&);

static void swssPrioNotify(std::string component, std::string prioStr);
static void swssOutputNotify(std::string component, std::string outputStr);
void settingThread();
static void swssPrioNotify(const std::string &component, const std::string &prioStr);
static void swssOutputNotify(const std::string &component, const std::string &outputStr);
[[ noreturn ]] void settingThread();

LogSettingChangeObservers m_settingChangeObservers;
std::map<std::string, std::string> m_currentPrios;
Expand Down
9 changes: 5 additions & 4 deletions common/loglevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

using namespace swss;

[[ noreturn ]] void usage(std::string program, int status, std::string message)
[[ noreturn ]] void usage(const std::string &program, int status, const std::string &message)
{
if (message.size() != 0)
{
Expand Down Expand Up @@ -44,7 +44,7 @@ void setLoglevel(DBConnector& db, const std::string& component, const std::strin
table.set(component, fieldValues);
}

bool validateSaiLoglevel(std::string prioStr)
bool validateSaiLoglevel(const std::string &prioStr)
{
static const std::vector<std::string> saiPrios = {
"SAI_LOG_LEVEL_CRITICAL",
Expand Down Expand Up @@ -112,7 +112,7 @@ int main(int argc, char **argv)
auto keys = redisClient.keys("*");
for (auto& key : keys)
{
size_t colonPos = key.find(":");
size_t colonPos = key.find(':');
if (colonPos == std::string::npos)
{
continue;
Expand All @@ -133,7 +133,8 @@ int main(int argc, char **argv)
std::sort(keys.begin(), keys.end());
for (const auto& key : keys)
{
auto level = redisClient.hget(key + ":" + key, DAEMON_LOGLEVEL);
const auto redis_key = std::string(key).append(":").append(key);
auto level = redisClient.hget(redis_key, DAEMON_LOGLEVEL);
std::cout << std::left << std::setw(30) << key << *level << std::endl;
}
return (EXIT_SUCCESS);
Expand Down
2 changes: 1 addition & 1 deletion common/notificationconsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define REDIS_PUBLISH_MESSAGE_INDEX (2)
#define REDIS_PUBLISH_MESSAGE_ELEMNTS (3)

swss::NotificationConsumer::NotificationConsumer(swss::DBConnector *db, std::string channel, int pri):
swss::NotificationConsumer::NotificationConsumer(swss::DBConnector *db, const std::string &channel, int pri):
Selectable(pri),
m_db(db),
m_subscribe(NULL),
Expand Down
2 changes: 1 addition & 1 deletion common/notificationconsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace swss {
class NotificationConsumer : public Selectable
{
public:
NotificationConsumer(swss::DBConnector *db, std::string channel, int pri = 100);
NotificationConsumer(swss::DBConnector *db, const std::string &channel, int pri = 100);

void pop(std::string &op, std::string &data, std::vector<FieldValueTuple> &values);

Expand Down
4 changes: 2 additions & 2 deletions common/notificationproducer.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "notificationproducer.h"

swss::NotificationProducer::NotificationProducer(swss::DBConnector *db, std::string channel):
swss::NotificationProducer::NotificationProducer(swss::DBConnector *db, const std::string &channel):
m_db(db), m_channel(channel)
{
}

void swss::NotificationProducer::send(std::string op, std::string data, std::vector<FieldValueTuple> &values)
void swss::NotificationProducer::send(const std::string &op, const std::string &data, std::vector<FieldValueTuple> &values)
{
SWSS_LOG_ENTER();

Expand Down
4 changes: 2 additions & 2 deletions common/notificationproducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace swss {
class NotificationProducer
{
public:
NotificationProducer(swss::DBConnector *db, std::string channel);
NotificationProducer(swss::DBConnector *db, const std::string &channel);

void send(std::string op, std::string data, std::vector<FieldValueTuple> &values);
void send(const std::string &op, const std::string &data, std::vector<FieldValueTuple> &values);

private:

Expand Down
2 changes: 1 addition & 1 deletion common/portmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using namespace std;

namespace swss {

map<set<int>, string> handlePortMap(string file)
map<set<int>, string> handlePortMap(const string &file)
{
map<set<int>, string> port_map;

Expand Down
2 changes: 1 addition & 1 deletion common/portmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace swss {

std::map<std::set<int>, std::string> handlePortMap(std::string file);
std::map<std::set<int>, std::string> handlePortMap(const std::string &file);

}

Expand Down
Loading