Skip to content

Commit

Permalink
Fix redis
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyyeh committed Oct 12, 2022
1 parent 0330abc commit 713a305
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
22 changes: 12 additions & 10 deletions src/configInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ constexpr auto DEFAULT_TIMEOUT_MSEC = 1000;

bool pollSwssNotifcation = true;
std::shared_ptr<boost::thread> mSwssThreadPtr;

std::shared_ptr<swss::DBConnector> configDbPtr = std::make_shared<swss::DBConnector> ("CONFIG_DB", 0);
swss::SubscriberStateTable ipHelpersTable(configDbPtr.get(), "DHCP_RELAY");
swss::Select swssSelect;

/**
Expand All @@ -22,9 +19,14 @@ swss::Select swssSelect;
void initialize_swss(std::vector<relay_config> *vlans)
{
try {
std::shared_ptr<swss::DBConnector> configDbPtr = std::make_shared<swss::DBConnector> ("CONFIG_DB", 0);
swss::SubscriberStateTable ipHelpersTable(configDbPtr.get(), "DHCP_RELAY");
swssSelect.addSelectable(&ipHelpersTable);
get_dhcp(vlans);
mSwssThreadPtr = std::make_shared<boost::thread> (&handleSwssNotification, vlans);
get_dhcp(vlans, &ipHelpersTable);
struct swssNotification test;
test.vlans = vlans;
test.ipHelpersTable = &ipHelpersTable;
mSwssThreadPtr = std::make_shared<boost::thread> (&handleSwssNotification, test);
}
catch (const std::bad_alloc &e) {
syslog(LOG_ERR, "Failed allocate memory. Exception details: %s", e.what());
Expand Down Expand Up @@ -52,15 +54,15 @@ void deinitialize_swss()
*
* @return none
*/
void get_dhcp(std::vector<relay_config> *vlans) {
void get_dhcp(std::vector<relay_config> *vlans, swss::SubscriberStateTable *ipHelpersTable) {
swss::Selectable *selectable;
int ret = swssSelect.select(&selectable, DEFAULT_TIMEOUT_MSEC);
if (ret == swss::Select::ERROR) {
syslog(LOG_WARNING, "Select: returned ERROR");
} else if (ret == swss::Select::TIMEOUT) {
}
if (selectable == static_cast<swss::Selectable *> (&ipHelpersTable)) {
handleRelayNotification(ipHelpersTable, vlans);
if (selectable == static_cast<swss::Selectable *> (ipHelpersTable)) {
handleRelayNotification(*ipHelpersTable, vlans);
}
}
/**
Expand All @@ -72,10 +74,10 @@ void get_dhcp(std::vector<relay_config> *vlans) {
*
* @return none
*/
void handleSwssNotification(std::vector<relay_config> *vlans)
void handleSwssNotification(swssNotification test)
{
while (pollSwssNotifcation) {
get_dhcp(vlans);
get_dhcp(test.vlans, test.ipHelpersTable);
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/configInterface.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#pragma once

#include <boost/thread.hpp>
#include "subscriberstatetable.h"
#include "select.h"
#include "relay.h"

struct swssNotification {
std::vector<relay_config> *vlans;
swss::SubscriberStateTable *ipHelpersTable;
};
/**
* @code void initialize_swss()
*
Expand All @@ -28,18 +34,18 @@ void deinitialize_swss();
*
* @return none
*/
void get_dhcp(std::vector<relay_config> *vlans);
void get_dhcp(std::vector<relay_config> *vlans, swss::SubscriberStateTable *ipHelpersTable);

/**
* @code void handleSwssNotification(std::vector<relay_config> *vlans)
* @code void swssNotification test
*
* @brief main thread for handling SWSS notification
*
* @param vlans list of vlans/argument config that contains strings of server and option
* @param test swssNotification that includes list of vlans/argument config that contains strings of server and option
*
* @return none
*/
void handleSwssNotification(std::vector<relay_config> *vlans);
void handleSwssNotification(swssNotification test);

/**
* @code void handleRelayNotification(swss::SubscriberStateTable &ipHelpersTable, std::vector<relay_config> *vlans)
Expand Down

0 comments on commit 713a305

Please sign in to comment.