Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Adam <dev@robert-adam.de>2021-05-09 21:22:04 +0300
committerRobert Adam <dev@robert-adam.de>2021-05-10 15:50:51 +0300
commit5d56ec6889f82bfa863ea97fe3ab20fbf52c5bf8 (patch)
treedc7e53eec85f6abd075e50ddf07e1e4324ca36bd /src/ProcessResolver.h
parentf0eee51e8138fa1154262fbca5d55a569539f930 (diff)
REFAC: ProcessResolver
The new version now uses smart pointers instead of raw new and delete and also switched to using STL type for its API instead of Qt types.
Diffstat (limited to 'src/ProcessResolver.h')
-rw-r--r--src/ProcessResolver.h30
1 files changed, 14 insertions, 16 deletions
diff --git a/src/ProcessResolver.h b/src/ProcessResolver.h
index 6799c0df6..c5c717398 100644
--- a/src/ProcessResolver.h
+++ b/src/ProcessResolver.h
@@ -9,35 +9,33 @@
#include <QtCore/QVector>
#include <cstdint>
+#include <memory>
+#include <unordered_map>
/// This ProcessResolver can be used to get a QVector of running process names and associated PIDs on multiple
/// platforms. This object is by no means thread-safe!
class ProcessResolver {
-protected:
- /// The vector for the pointers to the process names
- QVector< const char * > m_processNames;
- /// The vector for the process PIDs
- QVector< uint64_t > m_processPIDs;
-
- /// Deletes all names currently stored in processNames and clears processNames and processPIDs
- void freeAndClearData();
- /// The OS specific implementation of filling in details about running process names and PIDs
- void doResolve();
-
public:
+ using ProcessMap = std::unordered_map< uint64_t, std::unique_ptr< char[] > >;
+
/// @param resolveImmediately Whether the constructor should directly invoke ProcesResolver::resolve()
ProcessResolver(bool resolveImmediately = true);
virtual ~ProcessResolver();
/// Resolves the namaes and PIDs of the running processes
void resolve();
- /// Gets a reference to the stored process names
- const QVector< const char * > &getProcessNames() const;
- /// Gets a reference to the stored process PIDs (corresponding to the names returned by
- /// ProcessResolver::getProcessNames())
- const QVector< uint64_t > &getProcessPIDs() const;
+ /// @returns The ProcessMap holding the mapping between PID and process name of all processes
+ /// found by this resolver
+ const ProcessMap &getProcessMap() const;
/// @returns The amount of processes that have been resolved by this object
size_t amountOfProcesses() const;
+
+protected:
+ /// A map containing the PID->name mapping for the found processes
+ ProcessMap m_processMap;
+
+ /// The OS specific implementation of filling in details about running process names and PIDs
+ void doResolve();
};
#endif // MUMBLE_PROCESS_RESOLVER_H_