forked from sonoble/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[saiplayer] Convert saiplayer to static library (sonic-net#600)
- Loading branch information
Showing
8 changed files
with
1,962 additions
and
1,621 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.