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

ProcessResolver.h « src - github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c5c7173983327496f51be53114f6cdaae804f393 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2021 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#ifndef MUMBLE_PROCESS_RESOLVER_H_
#define MUMBLE_PROCESS_RESOLVER_H_

#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 {
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();
	/// @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_