Skip to content

Commit

Permalink
Merge pull request #2176 from Nicogene/fix/yarpdataplayerPartMismatch
Browse files Browse the repository at this point in the history
Fix yarpdataplayer part mismatch
  • Loading branch information
Nicogene authored Jan 10, 2020
2 parents d7be22b + 8afa0fa commit d58a812
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 53 deletions.
8 changes: 8 additions & 0 deletions doc/release/yarp_3_3/fixYarpdataplayerPartMismatch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fixYarpdataplayerPartMismatch {#yarp_3_3}
-----------------------------

### Tools

#### yarpdataplayer

* Fixed the part-port mismatch due to bad sorting(#2173).
19 changes: 5 additions & 14 deletions src/yarpdataplayer/include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,7 @@ class MainWindow : public QMainWindow, public yarp::os::ResourceFinder, public y
QString moduleName;
bool add_prefix; //indicates if ports have to be opened with /<moduleName> as prefix
yarp::os::RpcServer rpcPort;
std::vector<std::string> partsName;
std::vector<std::string> partsFullPath;
std::vector<std::string> partsInfoPath;
std::vector<std::string> partsLogPath;
std::vector<RowInfo> rowInfoVec;
int subDirCnt;
std::vector<std::string> dataType;

Expand Down Expand Up @@ -267,11 +264,9 @@ class InitThread : public QThread
Q_OBJECT

public:
InitThread(Utilities *utilities, QString newPath,
std::vector<std::string> *partsName,
std::vector<std::string> *partsFullPath,
std::vector<std::string> *partsInfoPath,
std::vector<std::string> *partsLogPath,
InitThread(Utilities *utilities,
QString newPath,
std::vector<RowInfo>& rowInfoVec,
QObject *parent = 0);

protected:
Expand All @@ -281,11 +276,7 @@ class InitThread : public QThread
Utilities *utilities;
QString newPath;
QMainWindow *mainWindow;
std::vector<std::string> *partsName;
std::vector<std::string> *partsFullPath;
std::vector<std::string> *partsInfoPath;
std::vector<std::string> *partsLogPath;

std::vector<RowInfo> rowInfoVec;
signals:
void initDone(int subDirCount);
};
Expand Down
10 changes: 8 additions & 2 deletions src/yarpdataplayer/include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ struct partsData
bool hasNotified; //boolean used for individual part notification that it has reached eof
};

struct RowInfo {
std::string name;
std::string info;
std::string log;
std::string path;
};

/**********************************************************/
class Utilities : public QObject
{
Expand Down Expand Up @@ -98,8 +105,7 @@ class Utilities : public QObject
/**
* function that returns a vector containing path directories - works in a recursive way
*/
int getRecSubDirList(std::string dir, std::vector<std::string> &names, std::vector<std::string> &info,
std::vector<std::string> &logs, std::vector<std::string> &paths, int recursive);
int getRecSubDirList(const std::string& dir, std::vector<RowInfo>& rowInfoVec, int recursive);
/**
* function that checks validity of log files
*/
Expand Down
41 changes: 16 additions & 25 deletions src/yarpdataplayer/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,23 +502,20 @@ bool MainWindow::doGuiSetup(QString newPath)
//look for folders and log files associated with them
LOG("the full path is %s \n", newPath.toLatin1().data());
subDirCnt = 0;
partsName.clear();
partsFullPath.clear();
partsInfoPath.clear();
partsLogPath.clear();
rowInfoVec.clear();


itr = 0;
partMap.clear();

if(!initThread){
initThread = new InitThread(utilities,newPath,&partsName,&partsFullPath,&partsInfoPath,&partsLogPath,this);
initThread = new InitThread(utilities,newPath,rowInfoVec,this);
connect(initThread,SIGNAL(initDone(int)),this,SLOT(onInitDone(int)),Qt::QueuedConnection);
initThread->start();
}else{
if(!initThread->isRunning()){
delete initThread;
initThread = new InitThread(utilities,newPath,&partsName,&partsFullPath,&partsInfoPath,&partsLogPath,this);
initThread = new InitThread(utilities,newPath,rowInfoVec,this);
connect(initThread,SIGNAL(initDone(int)),this,SLOT(onInitDone(int)),Qt::QueuedConnection);
initThread->start();
}
Expand Down Expand Up @@ -1026,27 +1023,21 @@ void MainWindow::onClose()

/**********************************************************/
InitThread::InitThread(Utilities *utilities,
QString newPath,
std::vector<std::string> *partsName,
std::vector<std::string> *partsFullPath,
std::vector<std::string> *partsInfoPath,
std::vector<std::string> *partsLogPath,
QObject *parent) : QThread(parent)
{
this->utilities = utilities;
this->newPath = newPath;
this->partsName = partsName;
this->partsFullPath = partsFullPath;
this->partsInfoPath = partsInfoPath;
this->partsLogPath = partsLogPath;
this->mainWindow = (QMainWindow*)parent;
QString newPath,
std::vector<RowInfo>& rowInfoVec,
QObject *parent) : QThread(parent),
utilities(utilities),
newPath(std::move(newPath)),
mainWindow(dynamic_cast<QMainWindow*> (parent)),
rowInfoVec(rowInfoVec)
{
}

/**********************************************************/
void InitThread::run()
{
utilities->resetMaxTimeStamp();
int subDirCnt = utilities->getRecSubDirList(newPath.toLatin1().data(), *partsName, *partsInfoPath, *partsLogPath, *partsFullPath, 1);
int subDirCnt = utilities->getRecSubDirList(newPath.toLatin1().data(), rowInfoVec, 1);
LOG("the size of subDirs is: %d\n", subDirCnt);
//reset totalSent to 0
utilities->totalSent = 0;
Expand All @@ -1058,10 +1049,10 @@ void InitThread::run()

//fill in parts with all data
for (int x=0; x < subDirCnt; x++){
utilities->partDetails[x].name = partsName->at(x);
utilities->partDetails[x].infoFile = partsInfoPath->at(x);
utilities->partDetails[x].logFile = partsLogPath->at(x);
utilities->partDetails[x].path = partsFullPath->at(x);
utilities->partDetails[x].name = rowInfoVec[x].name;
utilities->partDetails[x].infoFile = rowInfoVec[x].info;
utilities->partDetails[x].logFile = rowInfoVec[x].log;
utilities->partDetails[x].path = rowInfoVec[x].path;

utilities->setupDataFromParts(utilities->partDetails[x]);

Expand Down
25 changes: 13 additions & 12 deletions src/yarpdataplayer/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ string Utilities::getCurrentPath()
return currentPath;
}
/**********************************************************/
int Utilities::getRecSubDirList(string dir, vector<string> &names, vector<string> &info,
vector<string> &logs, vector<string> &paths, int recursive)
int Utilities::getRecSubDirList(const string& dir, vector<RowInfo>& rowInfoVec, int recursive)
{

struct dirent *direntp = nullptr;
Expand Down Expand Up @@ -169,16 +168,18 @@ int Utilities::getRecSubDirList(string dir, vector<string> &names, vector<string
//check log file validity before proceeding
if ( checkLog && checkData && (stat(dataFileName.c_str(), &st) == 0)) {
LOG(" %s IS present adding it to the gui\n",filename);
RowInfo row;

if (recursiveName.empty()){
names.emplace_back( direntp->d_name );//pass also previous subDir name
row.name = direntp->d_name;//pass also previous subDir name
} else {
names.emplace_back(recursiveName + "_" + direntp->d_name );//pass only subDir name
row.name = recursiveName + "_" + direntp->d_name;//pass only subDir name
}

info.emplace_back(dir + "/" + direntp->d_name + "/info.log" );
logs.emplace_back(dir + "/" + direntp->d_name + "/data.log" );
paths.emplace_back(dir + "/" + direntp->d_name + "/" ); //pass full path
row.info = dir + "/" + direntp->d_name + "/info.log";
row.log = dir + "/" + direntp->d_name + "/data.log";
row.path = dir + "/" + direntp->d_name + "/"; //pass full path
rowInfoVec.emplace_back(row);
dir_count++;
} else {
if (!checkLog){
Expand All @@ -204,7 +205,7 @@ int Utilities::getRecSubDirList(string dir, vector<string> &names, vector<string
recursiveName = string( direntp->d_name );
}

getRecSubDirList(recDir, names, info, logs, paths, 1);
getRecSubDirList(recDir, rowInfoVec, 1);
}
if (recursiveIterations < 2 || recursiveIterations > 2){
recursiveName.erase();
Expand All @@ -215,10 +216,10 @@ int Utilities::getRecSubDirList(string dir, vector<string> &names, vector<string
/* close the dir */
(void)closedir(dirp);
//avoid this for alphabetical order in linux
sort(names.begin(), names.end());
sort(info.begin(), info.end());
sort(logs.begin(), logs.end());
sort(paths.begin(), paths.end());
std::sort(rowInfoVec.begin(), rowInfoVec.end(), [](const RowInfo& lhs, const RowInfo& rhs)
{
return lhs.name < rhs.name;
});

return dir_count;
}
Expand Down

0 comments on commit d58a812

Please sign in to comment.