Skip to content

Commit e713473

Browse files
authored
Code clean refactor (sonic-net#712)
Remove global functions and variables, make them static.
1 parent 425ffbc commit e713473

File tree

7 files changed

+18
-11
lines changed

7 files changed

+18
-11
lines changed

lib/src/Sai.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ sai_status_t Sai::set(
198198
{
199199
// skip metadata if attribute is redis extension attribute
200200

201+
// TODO this is setting on all contextes, but maybe we want one specific?
202+
// and do set on all if obejctId == NULL
203+
201204
bool success = true;
202205

203206
for (auto& kvp: m_contextMap)

saidump/saidump.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ const TableMap* get_table_map(sai_object_id_t object_id)
134134

135135
if (it == g_oid_map.end())
136136
{
137-
SWSS_LOG_THROW("unable to find oid 0x%" PRIx64 " in oid map", object_id);
137+
SWSS_LOG_THROW("unable to find oid %s in oid map",
138+
sai_serialize_object_id(object_id).c_str());
138139
}
139140

140141
return it->second;

syncd/SaiSwitch.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using namespace syncd;
1212

1313
#define MAX_OBJLIST_LEN 128
1414

15-
const int maxLanesPerPort = 8;
15+
#define MAX_LANES_PER_PORT 8
1616

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

245245
for (const auto &port_rid: portList)
246246
{
247-
sai_uint32_t lanes[maxLanesPerPort];
247+
sai_uint32_t lanes[MAX_LANES_PER_PORT];
248248

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

251251
sai_attribute_t attr;
252252

253253
attr.id = SAI_PORT_ATTR_HW_LANE_LIST;
254-
attr.value.u32list.count = maxLanesPerPort;
254+
attr.value.u32list.count = MAX_LANES_PER_PORT;
255255
attr.value.u32list.list = lanes;
256256

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

957957
std::vector<uint32_t> lanes;
958958

959-
lanes.resize(maxLanesPerPort);
959+
lanes.resize(MAX_LANES_PER_PORT);
960960

961961
sai_attribute_t attr;
962962

963963
attr.id = SAI_PORT_ATTR_HW_LANE_LIST;
964-
attr.value.u32list.count = maxLanesPerPort;
964+
attr.value.u32list.count = MAX_LANES_PER_PORT;
965965
attr.value.u32list.list = lanes.data();
966966

967967
sai_status_t status = m_vendorSai->get(SAI_OBJECT_TYPE_PORT, port_rid, 1, &attr);

syncd/ServiceMethodTable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ const sai_service_method_table_t& ServiceMethodTable::SlotBase::getServiceMethod
6868
#pragma GCC diagnostic ignored "-Winline"
6969

7070
template<class B, template<size_t> class D, size_t... i>
71-
constexpr auto declare_static(std::index_sequence<i...>)
71+
static constexpr auto declare_static(std::index_sequence<i...>)
7272
{
7373
SWSS_LOG_ENTER();
7474
return std::array<B*, sizeof...(i)>{{new D<i>()...}};
7575
}
7676

7777
template<class B, template<size_t> class D, size_t size>
78-
constexpr auto declare_static()
78+
static constexpr auto declare_static()
7979
{
8080
SWSS_LOG_ENTER();
8181
auto arr = declare_static<B,D>(std::make_index_sequence<size>{});

syncd/SwitchNotifications.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ const sai_switch_notifications_t& SwitchNotifications::SlotBase::getSwitchNotifi
9797
#pragma GCC diagnostic ignored "-Winline"
9898

9999
template<class B, template<size_t> class D, size_t... i>
100-
constexpr auto declare_static(std::index_sequence<i...>)
100+
static constexpr auto declare_static(std::index_sequence<i...>)
101101
{
102102
SWSS_LOG_ENTER();
103103
return std::array<B*, sizeof...(i)>{{new D<i>()...}};
104104
}
105105

106106
template<class B, template<size_t> class D, size_t size>
107-
constexpr auto declare_static()
107+
static constexpr auto declare_static()
108108
{
109109
SWSS_LOG_ENTER();
110110
auto arr = declare_static<B,D>(std::make_index_sequence<size>{});

vslib/inc/SwitchStateBase.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ namespace saivs
397397
static int promisc(
398398
_In_ const char *dev);
399399

400+
static int get_default_gw_mac_address(
401+
_Out_ sai_mac_t& mac);
402+
400403
int vs_set_dev_mtu(
401404
_In_ const char*name,
402405
_In_ int mtu);

vslib/src/SwitchStateBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ sai_status_t SwitchStateBase::bulkSet(
765765
return status;
766766
}
767767

768-
static int get_default_gw_mac_address(
768+
int SwitchStateBase::get_default_gw_mac_address(
769769
_Out_ sai_mac_t& mac)
770770
{
771771
SWSS_LOG_ENTER();

0 commit comments

Comments
 (0)