1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_SYSTEMINFO_H
21 #define LIBREPCB_SYSTEMINFO_H
22 
23 /*******************************************************************************
24  *  Includes
25  ******************************************************************************/
26 #include "exceptions.h"
27 
28 #include <QtCore>
29 
30 /*******************************************************************************
31  *  Namespace / Forward Declarations
32  ******************************************************************************/
33 namespace librepcb {
34 
35 /*******************************************************************************
36  *  Class SystemInfo
37  ******************************************************************************/
38 
39 /**
40  * @brief This class provides some methods to get information from the operating
41  * system
42  *
43  * For example, this class is used to get the name of the user which is logged
44  * in and the hostname of the computer to create a lock file (see class
45  * ::librepcb::DirectoryLock).
46  *
47  * @note Only static methods are available. You cannot create objects of this
48  * class.
49  */
50 class SystemInfo final {
51   Q_DECLARE_TR_FUNCTIONS(SystemInfo)
52 
53 public:
54   // Constructors/Destructor
55   SystemInfo() = delete;
56 
57   /**
58    * @brief Get the name of the user which is logged in (like "homer")
59    *
60    * @return The username (in case of an error, this string can be empty!)
61    */
62   static const QString& getUsername() noexcept;
63 
64   /**
65    * @brief Get the full name of the user which is logged in (like "Homer
66    * Simpson")
67    *
68    * @return The full user name (can be empty)
69    */
70   static const QString& getFullUsername() noexcept;
71 
72   /**
73    * @brief Get the hostname of the computer (like "homer-workstation")
74    *
75    * @return The hostname (in case of an error, this string can be empty!)
76    */
77   static const QString& getHostname() noexcept;
78 
79   /**
80    * @brief Check whether a process with a given PID is running or not
81    *
82    * @param pid   The process ID to query
83    *
84    * @return  True if the process is running, fals if not
85    *
86    * @throw  Exception    In case of an error.
87    */
88   static bool isProcessRunning(qint64 pid);
89 
90   /**
91    * @brief Get the process name of a given PID
92    *
93    * @param pid   The process ID (may be a running process or not)
94    *
95    * @return  The name of the given process ID, or an empty string if no process
96    *          with the given PID exists.
97    *
98    * @throw  Exception    In case of an error.
99    */
100   static QString getProcessNameByPid(qint64 pid);
101 
102 private:
103   // Cached Data
104   static QString sUsername;
105   static QString sFullUsername;
106   static QString sHostname;
107 };
108 
109 /*******************************************************************************
110  *  End of File
111  ******************************************************************************/
112 
113 }  // namespace librepcb
114 
115 #endif  // LIBREPCB_SYSTEMINFO_H
116