Skip to content

Commit e566f7a

Browse files
authored
[saiplayer] Convert saiplayer to static library (#600)
1 parent fc3a413 commit e566f7a

File tree

8 files changed

+1962
-1621
lines changed

8 files changed

+1962
-1621
lines changed

saiplayer/CommandLineOptions.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "CommandLineOptions.h"
2+
3+
#include "swss/logger.h"
4+
5+
#include <sstream>
6+
7+
using namespace saiplayer;
8+
9+
CommandLineOptions::CommandLineOptions()
10+
{
11+
SWSS_LOG_ENTER();
12+
13+
// default values for command line options
14+
15+
m_useTempView = false;
16+
m_inspectAsic = false;
17+
m_skipNotifySyncd = false;
18+
m_enableDebug = false;
19+
m_sleep = false;
20+
}
21+
22+
std::string CommandLineOptions::getCommandLineString() const
23+
{
24+
SWSS_LOG_ENTER();
25+
26+
std::stringstream ss;
27+
28+
ss << " UseTempView=" << (m_useTempView ? "YES" : "NO");
29+
ss << " InspectAsic=" << (m_inspectAsic ? "YES" : "NO");
30+
ss << " SkipNotifySyncd=" << (m_skipNotifySyncd ? "YES" : "NO");
31+
ss << " EnableDebug=" << (m_enableDebug ? "YES" : "NO");
32+
ss << " Sleep=" << (m_sleep ? "YES" : "NO");
33+
34+
return ss.str();
35+
}

saiplayer/CommandLineOptions.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#pragma once
2+
3+
#include "swss/sal.h"
4+
5+
#include <string>
6+
#include <vector>
7+
8+
namespace saiplayer
9+
{
10+
class CommandLineOptions
11+
{
12+
public:
13+
14+
CommandLineOptions();
15+
16+
virtual ~CommandLineOptions() = default;
17+
18+
public:
19+
20+
virtual std::string getCommandLineString() const;
21+
22+
public:
23+
24+
bool m_useTempView;
25+
26+
bool m_inspectAsic;
27+
28+
bool m_skipNotifySyncd;
29+
30+
bool m_enableDebug;
31+
32+
bool m_sleep;
33+
34+
std::vector<std::string> m_files;
35+
};
36+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#include "CommandLineOptionsParser.h"
2+
3+
#include "swss/logger.h"
4+
5+
#include <getopt.h>
6+
7+
#include <iostream>
8+
9+
using namespace saiplayer;
10+
11+
std::shared_ptr<CommandLineOptions> CommandLineOptionsParser::parseCommandLine(
12+
_In_ int argc,
13+
_In_ char **argv)
14+
{
15+
SWSS_LOG_ENTER();
16+
17+
auto options = std::make_shared<CommandLineOptions>();
18+
19+
const char* const optstring = "uiCdsh";
20+
21+
while(true)
22+
{
23+
static struct option long_options[] =
24+
{
25+
{ "useTempView", no_argument, 0, 'u' },
26+
{ "inspectAsic", no_argument, 0, 'i' },
27+
{ "skipNotifySyncd", no_argument, 0, 'C' },
28+
{ "enableDebug", no_argument, 0, 'd' },
29+
{ "sleep", no_argument, 0, 's' },
30+
{ "help", no_argument, 0, 'h' },
31+
};
32+
33+
int option_index = 0;
34+
35+
int c = getopt_long(argc, argv, optstring, long_options, &option_index);
36+
37+
if (c == -1)
38+
{
39+
break;
40+
}
41+
42+
switch (c)
43+
{
44+
case 'u':
45+
options->m_useTempView = true;
46+
break;
47+
48+
case 'i':
49+
options->m_inspectAsic = true;
50+
break;
51+
52+
case 'C':
53+
options->m_skipNotifySyncd = true;
54+
break;
55+
56+
case 'd':
57+
options->m_enableDebug = true;
58+
break;
59+
60+
case 's':
61+
options->m_sleep = true;
62+
break;
63+
64+
case 'h':
65+
printUsage();
66+
exit(EXIT_SUCCESS);
67+
68+
case '?':
69+
SWSS_LOG_WARN("unknown option %c", optopt);
70+
printUsage();
71+
exit(EXIT_FAILURE);
72+
73+
default:
74+
SWSS_LOG_ERROR("getopt_long failure");
75+
exit(EXIT_FAILURE);
76+
}
77+
}
78+
79+
80+
for (int i = optind; i < argc; i++)
81+
{
82+
options->m_files.push_back(argv[i]);
83+
}
84+
85+
if (options->m_files.size() == 0)
86+
{
87+
SWSS_LOG_ERROR("no files to replay");
88+
exit(EXIT_FAILURE);
89+
}
90+
91+
return options;
92+
}
93+
94+
void CommandLineOptionsParser::printUsage()
95+
{
96+
SWSS_LOG_ENTER();
97+
98+
std::cout << "Usage: saiplayer [-u] [-i] [-C] [-d] [-s] [-h] recordfile" << std::endl << std::endl;
99+
100+
std::cout << " -u --useTempView:" << std::endl;
101+
std::cout << " Enable temporary view between init and apply" << std::endl << std::endl;
102+
std::cout << " -i --inspectAsic:" << std::endl;
103+
std::cout << " Inspect ASIC by ASIC DB" << std::endl << std::endl;
104+
std::cout << " -C --skipNotifySyncd:" << std::endl;
105+
std::cout << " Will not send notify init/apply view to syncd" << std::endl << std::endl;
106+
std::cout << " -d --enableDebug:" << std::endl;
107+
std::cout << " Enable syslog debug messages" << std::endl << std::endl;
108+
std::cout << " -s --sleep:" << std::endl;
109+
std::cout << " Sleep after success reply, to notice any switch notifications" << std::endl << std::endl;
110+
111+
std::cout << " -h --help:" << std::endl;
112+
std::cout << " Print out this message" << std::endl << std::endl;
113+
}

saiplayer/CommandLineOptionsParser.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#include "CommandLineOptions.h"
4+
5+
#include <memory>
6+
7+
namespace saiplayer
8+
{
9+
class CommandLineOptionsParser
10+
{
11+
private:
12+
13+
CommandLineOptionsParser() = delete;
14+
15+
~CommandLineOptionsParser() = delete;
16+
17+
public:
18+
19+
static std::shared_ptr<CommandLineOptions> parseCommandLine(
20+
_In_ int argc,
21+
_In_ char **argv);
22+
23+
static void printUsage();
24+
};
25+
}

saiplayer/Makefile.am

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ else
88
DBGFLAGS = -g
99
endif
1010

11+
noinst_LIBRARIES = libSaiPlayer.a
12+
libSaiPlayer_a_SOURCES = \
13+
CommandLineOptions.cpp \
14+
CommandLineOptionsParser.cpp \
15+
SaiPlayer.cpp
16+
17+
18+
libSaiPlayer_a_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) -std=c++14
19+
1120
saiplayer_SOURCES = saiplayer.cpp
12-
saiplayer_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON)
13-
saiplayer_LDADD = -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -L$(top_srcdir)/lib/src/.libs -lsairedis
21+
saiplayer_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) -std=c++14
22+
saiplayer_LDADD = libSaiPlayer.a ../syncd/libSyncd.a ../lib/src/libSaiRedis.a -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta

0 commit comments

Comments
 (0)