Skip to content

Commit

Permalink
[syncd] Move syncd classes to syncd namespace (sonic-net#742)
Browse files Browse the repository at this point in the history
Code clean refactor
  • Loading branch information
kcudnik authored Dec 14, 2020
1 parent be2ff20 commit 48815df
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 66 deletions.
6 changes: 4 additions & 2 deletions syncd/PortMap.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "swss/logger.h"
#include "PortMap.h"

#include "swss/logger.h"

using namespace syncd;

/**
* @brief Port map global map.
*
Expand Down Expand Up @@ -48,4 +51,3 @@ void PortMap::setGlobalPortMap(

gPortMap = portMap->getRawPortMap();
}

41 changes: 22 additions & 19 deletions syncd/PortMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,36 @@
#include <string>
#include <memory>

class PortMap
namespace syncd
{
public:
class PortMap
{
public:

PortMap() = default;
PortMap() = default;

virtual ~PortMap() = default;
virtual ~PortMap() = default;

public:
public:

void insert(
_In_ const std::set<int>& laneSet,
_In_ const std::string& name);
void insert(
_In_ const std::set<int>& laneSet,
_In_ const std::string& name);

void clear();
void clear();

size_t size() const;
size_t size() const;

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

/**
* @brief Set global object for RPC server binding.
*/
static void setGlobalPortMap(
_In_ std::shared_ptr<PortMap> portMap);
/**
* @brief Set global object for RPC server binding.
*/
static void setGlobalPortMap(
_In_ std::shared_ptr<PortMap> portMap);

private:
private:

std::map<std::set<int>, std::string> m_portMap;
};
std::map<std::set<int>, std::string> m_portMap;
};
}
2 changes: 2 additions & 0 deletions syncd/PortMapParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <sstream>
#include <cstring>

using namespace syncd;

// TODO: introduce common config format for SONiC
std::shared_ptr<PortMap> PortMapParser::parsePortMap(
_In_ const std::string& portMapFile)
Expand Down
19 changes: 11 additions & 8 deletions syncd/PortMapParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@

#include <memory>

class PortMapParser
namespace syncd
{
private:
class PortMapParser
{
private:

PortMapParser() = delete;
~PortMapParser() = delete;
PortMapParser() = delete;
~PortMapParser() = delete;

public:
public:

static std::shared_ptr<PortMap> parsePortMap(
_In_ const std::string& portMapFile);
};
static std::shared_ptr<PortMap> parsePortMap(
_In_ const std::string& portMapFile);
};
}
4 changes: 3 additions & 1 deletion syncd/TimerWatchdog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <chrono>

using namespace syncd;

TimerWatchdog::TimerWatchdog(
_In_ int64_t warnTimespan):
m_run(true),
Expand Down Expand Up @@ -55,7 +57,7 @@ void TimerWatchdog::setEndTime()
}

void TimerWatchdog::setCallback(
_In_ Callback callback)
_In_ std::function<void(uint64_t)> callback)
{
SWSS_LOG_ENTER();

Expand Down
70 changes: 34 additions & 36 deletions syncd/TimerWatchdog.h
Original file line number Diff line number Diff line change
@@ -1,57 +1,55 @@
#pragma once

#include "swss/sal.h"

#include <thread>
#include <atomic>
#include <functional>

#ifndef _In_
#define _In_
#endif

class TimerWatchdog
namespace syncd
{
typedef void (*Callback)(
_In_ int64_t span);

public:

TimerWatchdog(
_In_ int64_t warnTimespan);
class TimerWatchdog
{
public:

virtual ~TimerWatchdog();
TimerWatchdog(
_In_ int64_t warnTimespan);

public:
virtual ~TimerWatchdog();

void setStartTime();
public:

void setEndTime();
void setStartTime();

void setCallback(
_In_ Callback callback);
void setEndTime();

/**
* @brief Gets timestamp since epoch.
*
* @return Time since epoch in microseconds.
*/
static int64_t getTimeSinceEpoch();
void setCallback(
_In_ std::function<void(uint64_t)> callback);

private:
/**
* @brief Gets timestamp since epoch.
*
* @return Time since epoch in microseconds.
*/
static int64_t getTimeSinceEpoch();

void threadFunction();
private:

private:
void threadFunction();

volatile bool m_run;
private:

// all values are in microseconds
volatile bool m_run;

std::atomic_int_fast64_t m_warnTimespan;
std::atomic_int_fast64_t m_startTimestamp;
std::atomic_int_fast64_t m_endTimestamp;
std::atomic_int_fast64_t m_lastCheckTimestamp;
// all values are in microseconds

std::shared_ptr<std::thread> m_thread;
std::atomic_int_fast64_t m_warnTimespan;
std::atomic_int_fast64_t m_startTimestamp;
std::atomic_int_fast64_t m_endTimestamp;
std::atomic_int_fast64_t m_lastCheckTimestamp;

Callback m_callback;
std::shared_ptr<std::thread> m_thread;

};
std::function<void(uint64_t)> m_callback;
};
}

0 comments on commit 48815df

Please sign in to comment.