Skip to content

Commit

Permalink
Code style refactor (sonic-net#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Nov 14, 2020
1 parent fc50cf5 commit 6ace7d3
Show file tree
Hide file tree
Showing 26 changed files with 107 additions and 135 deletions.
2 changes: 1 addition & 1 deletion lib/src/Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ std::string Recorder::getTimestamp()

gettimeofday(&tv, NULL);

size_t size = strftime(buffer, 32 ,"%Y-%m-%d.%T.", localtime(&tv.tv_sec));
size_t size = strftime(buffer, 32, "%Y-%m-%d.%T.", localtime(&tv.tv_sec));

snprintf(&buffer[size], 32, "%06ld", tv.tv_usec);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/RedisChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RedisChannel::RedisChannel(
// TODO this connection info must be obtained from config

m_db = std::make_shared<swss::DBConnector>(dbAsic, 0);
m_redisPipeline = std::make_shared<swss::RedisPipeline>(m_db.get()); //enable default pipeline 128
m_redisPipeline = std::make_shared<swss::RedisPipeline>(m_db.get()); // enable default pipeline 128
m_asicState = std::make_shared<swss::ProducerTable>(m_redisPipeline.get(), ASIC_STATE_TABLE, true);
m_getConsumer = std::make_shared<swss::ConsumerTable>(m_db.get(), REDIS_TABLE_GETRESPONSE);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/Sai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ std::string joinFieldValues(
const std::string &str_attr_id = fvField(values[i]);
const std::string &str_attr_value = fvValue(values[i]);

if(i != 0)
if (i != 0)
{
ss << "|";
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ std::string joinFieldValues(
const std::string &str_attr_id = fvField(values[i]);
const std::string &str_attr_value = fvValue(values[i]);

if(i != 0)
if (i != 0)
{
ss << "|";
}
Expand Down
23 changes: 12 additions & 11 deletions meta/saiserialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1424,8 +1424,8 @@ std::string sai_serialize_acl_capability(
}

std::string sai_serialize_hex_binary(
_In_ const void *buffer,
_In_ size_t length)
_In_ const void *buffer,
_In_ size_t length)
{
SWSS_LOG_ENTER();

Expand All @@ -1437,6 +1437,7 @@ std::string sai_serialize_hex_binary(
}

s.resize(2 * length, '0');

const unsigned char *input = static_cast<const unsigned char *>(buffer);
char *output = &s[0];

Expand Down Expand Up @@ -2707,9 +2708,9 @@ void sai_deserialize_acl_capability(
}

void sai_deserialize_hex_binary(
_In_ const std::string &s,
_Out_ void *buffer,
_In_ size_t length)
_In_ const std::string &s,
_Out_ void *buffer,
_In_ size_t length)
{
SWSS_LOG_ENTER();

Expand All @@ -2720,7 +2721,7 @@ void sai_deserialize_hex_binary(

if (s.length() > (length * 2))
{
SWSS_LOG_THROW("Buffer length isn't sufficient.");
SWSS_LOG_THROW("Buffer length isn't sufficient");
}

size_t buffer_cur = 0;
Expand All @@ -2729,7 +2730,7 @@ void sai_deserialize_hex_binary(

while (hex_cur < s.length())
{
const char temp_buffer[] = {s[hex_cur], s[hex_cur + 1], 0};
const char temp_buffer[] = { s[hex_cur], s[hex_cur + 1], 0 };
unsigned int value = -1;

if (sscanf(temp_buffer, "%X", &value) <= 0 || value > 0xff)
Expand All @@ -2745,8 +2746,8 @@ void sai_deserialize_hex_binary(

template<typename T>
void sai_deserialize_hex_binary(
_In_ const std::string &s,
_Out_ T &value)
_In_ const std::string &s,
_Out_ T &value)
{
SWSS_LOG_ENTER();

Expand Down Expand Up @@ -3126,7 +3127,7 @@ static int sai_deserialize_object_id_buf(
{
SWSS_LOG_ENTER();

if (strncmp(buf,"oid:0x",6) != 0)
if (strncmp(buf, "oid:0x", 6) != 0)
{
SWSS_LOG_THROW("invalid oid %s", buf);
}
Expand Down Expand Up @@ -3681,7 +3682,7 @@ sai_redis_notify_syncd_t sai_deserialize_redis_notify_syncd(

sai_redis_notify_syncd_t value;

sai_deserialize(s,value);
sai_deserialize(s, value);

return value;
}
2 changes: 1 addition & 1 deletion python/sairedis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ static PyObject * generic_get(

auto *list = PyList_New(0);

for(auto&tok: tokens)
for (auto&tok: tokens)
{
PyList_Append(list, PyString_FromString(tok.c_str()));
}
Expand Down
8 changes: 4 additions & 4 deletions saidiscovery/saidiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ typedef std::chrono::duration<double, std::ratio<1>> second_t;
*/
int discover(
_In_ sai_object_id_t id,
_Inout_ std::map<sai_object_id_t,std::map<std::string,std::string>> &discovered)
_Inout_ std::map<sai_object_id_t, std::map<std::string, std::string>> &discovered)
{
SWSS_LOG_ENTER();

Expand Down Expand Up @@ -511,7 +511,7 @@ void handleCmdLine(int argc, char **argv)

const char* const optstring = "DdwIp:hf";

while(true)
while (true)
{
int option_index = 0;

Expand Down Expand Up @@ -627,7 +627,7 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}

std::map<sai_object_id_t, std::map<std::string,std::string>> discovered;
std::map<sai_object_id_t, std::map<std::string, std::string>> discovered;

auto m_start = std::chrono::high_resolution_clock::now();

Expand All @@ -640,7 +640,7 @@ int main(int argc, char **argv)
SWSS_LOG_NOTICE("discovered objects: %zu took %.3lf sec, call count: %d",
discovered.size(), duration, callCount);

std::map<sai_object_type_t,int> map;
std::map<sai_object_type_t, int> map;

for (const auto &p: discovered)
{
Expand Down
2 changes: 1 addition & 1 deletion saidump/saidump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CmdOptions handleCmdLine(int argc, char **argv)

const char* const optstring = "gth";

while(true)
while (true)
{
static struct option long_options[] =
{
Expand Down
2 changes: 1 addition & 1 deletion saiplayer/CommandLineOptionsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ std::shared_ptr<CommandLineOptions> CommandLineOptionsParser::parseCommandLine(

const char* const optstring = "uiCdsmp:x:h";

while(true)
while (true)
{
static struct option long_options[] =
{
Expand Down
4 changes: 2 additions & 2 deletions saiplayer/SaiPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ sai_status_t SaiPlayer::handle_neighbor(
neighbor_entry.switch_id = translate_local_to_redis(neighbor_entry.switch_id);
neighbor_entry.rif_id = translate_local_to_redis(neighbor_entry.rif_id);

switch(api)
switch (api)
{
case SAI_COMMON_API_CREATE:
return m_sai->create(&neighbor_entry, attr_count, attr_list);
Expand Down Expand Up @@ -620,7 +620,7 @@ sai_status_t SaiPlayer::handle_route(
route_entry.switch_id = translate_local_to_redis(route_entry.switch_id);
route_entry.vr_id = translate_local_to_redis(route_entry.vr_id);

switch(api)
switch (api)
{
case SAI_COMMON_API_CREATE:
return m_sai->create(&route_entry, attr_count, attr_list);
Expand Down
2 changes: 1 addition & 1 deletion saisdkdump/saisdkdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int main(int argc, char **argv)
int option_index = 0;
int c = 0;

while((c = getopt_long(argc, argv, "hf:p:", longOptions, &option_index)) != -1)
while ((c = getopt_long(argc, argv, "hf:p:", longOptions, &option_index)) != -1)
{
switch (c)
{
Expand Down
2 changes: 1 addition & 1 deletion syncd/CommandLineOptionsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ std::shared_ptr<CommandLineOptions> CommandLineOptionsParser::parseCommandLine(
const char* const optstring = "dp:t:g:x:b:uSUCslh";
#endif // SAITHRIFT

while(true)
while (true)
{
static struct option long_options[] =
{
Expand Down
2 changes: 1 addition & 1 deletion syncd/ComparisonLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3434,7 +3434,7 @@ void ComparisonLogic::executeOperationsOnAsic()

SWSS_LOG_NOTICE("optimized operations!");

std::map<std::string,int> opByObjectType;
std::map<std::string, int> opByObjectType;

for (const auto &op: currentView.asicGetWithOptimizedRemoveOperations())
{
Expand Down
4 changes: 2 additions & 2 deletions syncd/RedisClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ void RedisClient::createAsicObjects(

if (kvp.second.size() == 0)
{
hash[(ASIC_STATE_TABLE ":") + kvp.first].emplace_back(std::make_pair<std::string, std::string>("NULL","NULL"));
hash[(ASIC_STATE_TABLE ":") + kvp.first].emplace_back(std::make_pair<std::string, std::string>("NULL", "NULL"));
}
}

Expand All @@ -618,7 +618,7 @@ void RedisClient::createTempAsicObjects(

if (kvp.second.size() == 0)
{
hash[(TEMP_PREFIX ASIC_STATE_TABLE ":") + kvp.first].emplace_back(std::make_pair<std::string, std::string>("NULL","NULL"));
hash[(TEMP_PREFIX ASIC_STATE_TABLE ":") + kvp.first].emplace_back(std::make_pair<std::string, std::string>("NULL", "NULL"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion syncd/SaiSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ std::unordered_map<sai_uint32_t, sai_object_id_t> SaiSwitch::saiGetHardwareLaneM
* addressed in future.
*/

for (const auto &port_rid : portList)
for (const auto &port_rid: portList)
{
sai_uint32_t lanes[maxLanesPerPort];

Expand Down
19 changes: 0 additions & 19 deletions vslib/inc/SwitchBCM81724.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
/*
Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or
its subsidiaries.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#pragma once

#include "SwitchStateBase.h"
Expand Down
64 changes: 32 additions & 32 deletions vslib/src/CorePortIndexMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,38 +92,38 @@ std::shared_ptr<CorePortIndexMap> CorePortIndexMap::getDefaultCorePortIndexMap(
const uint32_t defaultPortCount = 32;

uint32_t defaultCorePortIndexMap[defaultPortCount * 2] = {
0,1,
0,2,
0,3,
0,4,
0,5,
0,6,
0,7,
0,8,
0,9,
0,10,
0,11,
0,12,
0,13,
0,14,
0,15,
0,16,
1,1,
1,2,
1,3,
1,4,
1,5,
1,6,
1,7,
1,8,
1,9,
1,10,
1,11,
1,12,
1,13,
1,14,
1,15,
1,16
0, 1,
0, 2,
0, 3,
0, 4,
0, 5,
0, 6,
0, 7,
0, 8,
0, 9,
0, 10,
0, 11,
0, 12,
0, 13,
0, 14,
0, 15,
0, 16,
1, 1,
1, 2,
1, 3,
1, 4,
1, 5,
1, 6,
1, 7,
1, 8,
1, 9,
1, 10,
1, 11,
1, 12,
1, 13,
1, 14,
1, 15,
1, 16
};

auto corePortIndexMap = std::make_shared<CorePortIndexMap>(switchIndex);
Expand Down
2 changes: 1 addition & 1 deletion vslib/src/CorePortIndexMapContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void CorePortIndexMapContainer::removeEmptyCorePortIndexMaps()
{
SWSS_LOG_ENTER();

for(auto it = m_map.begin(); it != m_map.end();)
for (auto it = m_map.begin(); it != m_map.end();)
{
if (it->second->isEmpty())
{
Expand Down
6 changes: 3 additions & 3 deletions vslib/src/CorePortIndexMapFileParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void CorePortIndexMapFileParser::parse(
return;
}

auto tokens = swss::tokenize(scpidx,',');
auto tokens = swss::tokenize(scpidx, ',');

size_t n = tokens.size();

Expand All @@ -70,6 +70,7 @@ void CorePortIndexMapFileParser::parse(
for (auto c: tokens)
{
uint32_t c_or_pidx;

if (sscanf(c.c_str(), "%u", &c_or_pidx) != 1)
{
SWSS_LOG_ERROR("failed to parse core or port index: %s", c.c_str());
Expand Down Expand Up @@ -148,7 +149,7 @@ std::shared_ptr<CorePortIndexMapContainer> CorePortIndexMapFileParser::parseCore

std::string line;

while(getline(ifs, line))
while (getline(ifs, line))
{
/*
* line can be in 2 forms:
Expand Down Expand Up @@ -222,4 +223,3 @@ std::shared_ptr<CorePortIndexMapContainer> CorePortIndexMapFileParser::parseCore

return parseCorePortIndexMapFile(name);
}

2 changes: 1 addition & 1 deletion vslib/src/LaneMapContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void LaneMapContainer::removeEmptyLaneMaps()
{
SWSS_LOG_ENTER();

for(auto it = m_map.begin(); it != m_map.end();)
for (auto it = m_map.begin(); it != m_map.end();)
{
if (it->second->isEmpty())
{
Expand Down
Loading

0 comments on commit 6ace7d3

Please sign in to comment.