Skip to content

Commit

Permalink
Code clean refactor (sonic-net#712)
Browse files Browse the repository at this point in the history
Remove global functions and variables, make them static.
  • Loading branch information
kcudnik committed Nov 19, 2020
1 parent 425ffbc commit e713473
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 11 deletions.
3 changes: 3 additions & 0 deletions lib/src/Sai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ sai_status_t Sai::set(
{
// skip metadata if attribute is redis extension attribute

// TODO this is setting on all contextes, but maybe we want one specific?
// and do set on all if obejctId == NULL

bool success = true;

for (auto& kvp: m_contextMap)
Expand Down
3 changes: 2 additions & 1 deletion saidump/saidump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ const TableMap* get_table_map(sai_object_id_t object_id)

if (it == g_oid_map.end())
{
SWSS_LOG_THROW("unable to find oid 0x%" PRIx64 " in oid map", object_id);
SWSS_LOG_THROW("unable to find oid %s in oid map",
sai_serialize_object_id(object_id).c_str());
}

return it->second;
Expand Down
10 changes: 5 additions & 5 deletions syncd/SaiSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using namespace syncd;

#define MAX_OBJLIST_LEN 128

const int maxLanesPerPort = 8;
#define MAX_LANES_PER_PORT 8

/*
* NOTE: If real ID will change during hard restarts, then we need to remap all
Expand Down Expand Up @@ -244,14 +244,14 @@ std::unordered_map<sai_uint32_t, sai_object_id_t> SaiSwitch::saiGetHardwareLaneM

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

memset(lanes, 0, sizeof(lanes));

sai_attribute_t attr;

attr.id = SAI_PORT_ATTR_HW_LANE_LIST;
attr.value.u32list.count = maxLanesPerPort;
attr.value.u32list.count = MAX_LANES_PER_PORT;
attr.value.u32list.list = lanes;

sai_status_t status = m_vendorSai->get(SAI_OBJECT_TYPE_PORT, port_rid, 1, &attr);
Expand Down Expand Up @@ -956,12 +956,12 @@ std::vector<uint32_t> SaiSwitch::saiGetPortLanes(

std::vector<uint32_t> lanes;

lanes.resize(maxLanesPerPort);
lanes.resize(MAX_LANES_PER_PORT);

sai_attribute_t attr;

attr.id = SAI_PORT_ATTR_HW_LANE_LIST;
attr.value.u32list.count = maxLanesPerPort;
attr.value.u32list.count = MAX_LANES_PER_PORT;
attr.value.u32list.list = lanes.data();

sai_status_t status = m_vendorSai->get(SAI_OBJECT_TYPE_PORT, port_rid, 1, &attr);
Expand Down
4 changes: 2 additions & 2 deletions syncd/ServiceMethodTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ const sai_service_method_table_t& ServiceMethodTable::SlotBase::getServiceMethod
#pragma GCC diagnostic ignored "-Winline"

template<class B, template<size_t> class D, size_t... i>
constexpr auto declare_static(std::index_sequence<i...>)
static constexpr auto declare_static(std::index_sequence<i...>)
{
SWSS_LOG_ENTER();
return std::array<B*, sizeof...(i)>{{new D<i>()...}};
}

template<class B, template<size_t> class D, size_t size>
constexpr auto declare_static()
static constexpr auto declare_static()
{
SWSS_LOG_ENTER();
auto arr = declare_static<B,D>(std::make_index_sequence<size>{});
Expand Down
4 changes: 2 additions & 2 deletions syncd/SwitchNotifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ const sai_switch_notifications_t& SwitchNotifications::SlotBase::getSwitchNotifi
#pragma GCC diagnostic ignored "-Winline"

template<class B, template<size_t> class D, size_t... i>
constexpr auto declare_static(std::index_sequence<i...>)
static constexpr auto declare_static(std::index_sequence<i...>)
{
SWSS_LOG_ENTER();
return std::array<B*, sizeof...(i)>{{new D<i>()...}};
}

template<class B, template<size_t> class D, size_t size>
constexpr auto declare_static()
static constexpr auto declare_static()
{
SWSS_LOG_ENTER();
auto arr = declare_static<B,D>(std::make_index_sequence<size>{});
Expand Down
3 changes: 3 additions & 0 deletions vslib/inc/SwitchStateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ namespace saivs
static int promisc(
_In_ const char *dev);

static int get_default_gw_mac_address(
_Out_ sai_mac_t& mac);

int vs_set_dev_mtu(
_In_ const char*name,
_In_ int mtu);
Expand Down
2 changes: 1 addition & 1 deletion vslib/src/SwitchStateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ sai_status_t SwitchStateBase::bulkSet(
return status;
}

static int get_default_gw_mac_address(
int SwitchStateBase::get_default_gw_mac_address(
_Out_ sai_mac_t& mac)
{
SWSS_LOG_ENTER();
Expand Down

0 comments on commit e713473

Please sign in to comment.