Skip to content

Commit

Permalink
[saiplayer] Convert saiplayer to static library (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Apr 10, 2020
1 parent fc3a413 commit e566f7a
Show file tree
Hide file tree
Showing 8 changed files with 1,962 additions and 1,621 deletions.
35 changes: 35 additions & 0 deletions saiplayer/CommandLineOptions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "CommandLineOptions.h"

#include "swss/logger.h"

#include <sstream>

using namespace saiplayer;

CommandLineOptions::CommandLineOptions()
{
SWSS_LOG_ENTER();

// default values for command line options

m_useTempView = false;
m_inspectAsic = false;
m_skipNotifySyncd = false;
m_enableDebug = false;
m_sleep = false;
}

std::string CommandLineOptions::getCommandLineString() const
{
SWSS_LOG_ENTER();

std::stringstream ss;

ss << " UseTempView=" << (m_useTempView ? "YES" : "NO");
ss << " InspectAsic=" << (m_inspectAsic ? "YES" : "NO");
ss << " SkipNotifySyncd=" << (m_skipNotifySyncd ? "YES" : "NO");
ss << " EnableDebug=" << (m_enableDebug ? "YES" : "NO");
ss << " Sleep=" << (m_sleep ? "YES" : "NO");

return ss.str();
}
36 changes: 36 additions & 0 deletions saiplayer/CommandLineOptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include "swss/sal.h"

#include <string>
#include <vector>

namespace saiplayer
{
class CommandLineOptions
{
public:

CommandLineOptions();

virtual ~CommandLineOptions() = default;

public:

virtual std::string getCommandLineString() const;

public:

bool m_useTempView;

bool m_inspectAsic;

bool m_skipNotifySyncd;

bool m_enableDebug;

bool m_sleep;

std::vector<std::string> m_files;
};
}
113 changes: 113 additions & 0 deletions saiplayer/CommandLineOptionsParser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#include "CommandLineOptionsParser.h"

#include "swss/logger.h"

#include <getopt.h>

#include <iostream>

using namespace saiplayer;

std::shared_ptr<CommandLineOptions> CommandLineOptionsParser::parseCommandLine(
_In_ int argc,
_In_ char **argv)
{
SWSS_LOG_ENTER();

auto options = std::make_shared<CommandLineOptions>();

const char* const optstring = "uiCdsh";

while(true)
{
static struct option long_options[] =
{
{ "useTempView", no_argument, 0, 'u' },
{ "inspectAsic", no_argument, 0, 'i' },
{ "skipNotifySyncd", no_argument, 0, 'C' },
{ "enableDebug", no_argument, 0, 'd' },
{ "sleep", no_argument, 0, 's' },
{ "help", no_argument, 0, 'h' },
};

int option_index = 0;

int c = getopt_long(argc, argv, optstring, long_options, &option_index);

if (c == -1)
{
break;
}

switch (c)
{
case 'u':
options->m_useTempView = true;
break;

case 'i':
options->m_inspectAsic = true;
break;

case 'C':
options->m_skipNotifySyncd = true;
break;

case 'd':
options->m_enableDebug = true;
break;

case 's':
options->m_sleep = true;
break;

case 'h':
printUsage();
exit(EXIT_SUCCESS);

case '?':
SWSS_LOG_WARN("unknown option %c", optopt);
printUsage();
exit(EXIT_FAILURE);

default:
SWSS_LOG_ERROR("getopt_long failure");
exit(EXIT_FAILURE);
}
}


for (int i = optind; i < argc; i++)
{
options->m_files.push_back(argv[i]);
}

if (options->m_files.size() == 0)
{
SWSS_LOG_ERROR("no files to replay");
exit(EXIT_FAILURE);
}

return options;
}

void CommandLineOptionsParser::printUsage()
{
SWSS_LOG_ENTER();

std::cout << "Usage: saiplayer [-u] [-i] [-C] [-d] [-s] [-h] recordfile" << std::endl << std::endl;

std::cout << " -u --useTempView:" << std::endl;
std::cout << " Enable temporary view between init and apply" << std::endl << std::endl;
std::cout << " -i --inspectAsic:" << std::endl;
std::cout << " Inspect ASIC by ASIC DB" << std::endl << std::endl;
std::cout << " -C --skipNotifySyncd:" << std::endl;
std::cout << " Will not send notify init/apply view to syncd" << std::endl << std::endl;
std::cout << " -d --enableDebug:" << std::endl;
std::cout << " Enable syslog debug messages" << std::endl << std::endl;
std::cout << " -s --sleep:" << std::endl;
std::cout << " Sleep after success reply, to notice any switch notifications" << std::endl << std::endl;

std::cout << " -h --help:" << std::endl;
std::cout << " Print out this message" << std::endl << std::endl;
}
25 changes: 25 additions & 0 deletions saiplayer/CommandLineOptionsParser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include "CommandLineOptions.h"

#include <memory>

namespace saiplayer
{
class CommandLineOptionsParser
{
private:

CommandLineOptionsParser() = delete;

~CommandLineOptionsParser() = delete;

public:

static std::shared_ptr<CommandLineOptions> parseCommandLine(
_In_ int argc,
_In_ char **argv);

static void printUsage();
};
}
13 changes: 11 additions & 2 deletions saiplayer/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ else
DBGFLAGS = -g
endif

noinst_LIBRARIES = libSaiPlayer.a
libSaiPlayer_a_SOURCES = \
CommandLineOptions.cpp \
CommandLineOptionsParser.cpp \
SaiPlayer.cpp


libSaiPlayer_a_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) -std=c++14

saiplayer_SOURCES = saiplayer.cpp
saiplayer_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON)
saiplayer_LDADD = -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -L$(top_srcdir)/lib/src/.libs -lsairedis
saiplayer_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) -std=c++14
saiplayer_LDADD = libSaiPlayer.a ../syncd/libSyncd.a ../lib/src/libSaiRedis.a -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta
Loading

0 comments on commit e566f7a

Please sign in to comment.