summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/base/utils.cpp
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2015-12-30 18:27:13 +0100
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2016-01-17 19:18:26 +0100
commit537f9a4ab61b9be8f4bb6a8bc0d3c9d4c47993d4 (patch)
treeb6a0b912427609917185fadc243ab83fce7f2ce9 /rbutil/rbutilqt/base/utils.cpp
parent3b089b439fe4c87999aac9d4ed08a6ea9b267e66 (diff)
downloadrockbox-537f9a4ab61b9be8f4bb6a8bc0d3c9d4c47993d4.tar.gz
rockbox-537f9a4ab61b9be8f4bb6a8bc0d3c9d4c47993d4.tar.bz2
rockbox-537f9a4ab61b9be8f4bb6a8bc0d3c9d4c47993d4.zip
Return process IDs in Utils::findRunningProcess().
Rework to return mapping between (filtered) process names and their pid values (if running). Note that this functionality is not implemented for Linux (but as it's mostly intended to detect Itunes currently not needed on that platform). Change-Id: Ie348bfed46bda390f469c37635a96c75e5782616
Diffstat (limited to 'rbutil/rbutilqt/base/utils.cpp')
-rw-r--r--rbutil/rbutilqt/base/utils.cpp54
1 files changed, 33 insertions, 21 deletions
diff --git a/rbutil/rbutilqt/base/utils.cpp b/rbutil/rbutilqt/base/utils.cpp
index 6bd9e23230..f58d8c34e3 100644
--- a/rbutil/rbutilqt/base/utils.cpp
+++ b/rbutil/rbutilqt/base/utils.cpp
@@ -670,13 +670,13 @@ QStringList Utils::mountpoints(enum MountpointsFilter type)
/** Check if a process with a given name is running
- * @param names list of names to check
- * @return list of detected processes.
+ * @param names list of names to filter on. All processes if empty list.
+ * @return list of processname, process ID pairs.
*/
-QStringList Utils::findRunningProcess(QStringList names)
+QMap<QString, QList<int> > Utils::findRunningProcess(QStringList names)
{
- QStringList processlist;
- QStringList found;
+ QMap<QString, QList<int> > processlist;
+ QMap<QString, QList<int> > found;
#if defined(Q_OS_WIN32)
HANDLE hdl;
PROCESSENTRY32 entry;
@@ -694,14 +694,16 @@ QStringList Utils::findRunningProcess(QStringList names)
return found;
}
- processlist.append(QString::fromWCharArray(entry.szExeFile));
do {
+ int pid = entry.th32ProcessID; // FIXME: DWORD vs int!
+ QString name = QString::fromWCharArray(entry.szExeFile);
+ if(processlist.find(name) == processlist.end()) {
+ processlist.insert(name, QList<int>());
+ }
+ processlist[name].append(pid);
entry.dwSize = sizeof(PROCESSENTRY32);
entry.szExeFile[0] = '\0';
result = Process32Next(hdl, &entry);
- if(result) {
- processlist.append(QString::fromWCharArray(entry.szExeFile));
- }
} while(result);
CloseHandle(hdl);
#endif
@@ -726,28 +728,38 @@ QStringList Utils::findRunningProcess(QStringList names)
if(isprint(buf[i])) break;
}
// avoid adding duplicates.
- QString process = QString::fromUtf8(&buf[i]);
- if(!processlist.contains(process)) {
- processlist.append(process);
+ QString name = QString::fromUtf8(&buf[i]);
+ if(processlist.find(name) == processlist.end()) {
+ processlist.insert(name, QList<int>());
}
-
+ processlist[name].append(pid);
}
}
} while(err == noErr);
#endif
- // check for given names in list of processes
- for(int i = 0; i < names.size(); ++i) {
+#if defined(Q_OS_LINUX)
+ // not implemented for Linux!
+#endif
+ // Filter for names (unless empty)
+ if(names.size() > 0) {
+ for(int i = 0; i < names.size(); ++i) {
+ QStringList k(processlist.keys());
#if defined(Q_OS_WIN32)
- // the process name might be truncated. Allow the extension to be partial.
- int index = processlist.indexOf(QRegExp(names.at(i) + "(\\.(e(x(e?)?)?)?)?"));
+ // the process name might be truncated. Allow the extension to be partial.
+ int index = k.indexOf(QRegExp(names.at(i) + "(\\.(e(x(e?)?)?)?)?",
+ Qt::CaseInsensitive));
#else
- int index = processlist.indexOf(names.at(i));
+ int index = k.indexOf(names.at(i));
#endif
- if(index != -1) {
- found.append(processlist.at(index));
+ if(index != -1) {
+ found.insert(k[index], processlist[k[index]]);
+ }
}
}
- LOG_INFO() << "Found listed processes running:" << found;
+ else {
+ found = processlist;
+ }
+ LOG_INFO() << "Looking for processes" << names << "found" << found;
return found;
}