|
|
Home » Developing U++ » UppHub » [SysInfo - Improvement - Koldo] Better way to find distribution version & more
|
|
Re: [SysInfo - Improvement - Koldo] Better way to find distribution version & more [message #40954 is a reply to message #40953] |
Sun, 13 October 2013 01:22   |
 |
Klugier
Messages: 1099 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello Koldo,
Following two lines of code are tricky:
for (FindFile ff(AppendFileName("/etc/", "*-release")); ff; ff.Next())
release += LoadFile_Safe(ff.GetPath());
This means, that find all files, that have "release" chain in their names. File "lsb-release" dosen't contain full version information, so we need to scan other files with "release" in their names.
************************************************************ ************************************************************ **
Here is the output (Ubuntu 13.04):
DISTRIB_VERSION=13.04
VERSION=13.04, Raring Ringtail
VERSION can be replaced with VERSION_ID (And even DISTRIB_VERSION to ID):
VERSION_ID=13.04
ID=ubuntu
************************************************************ ************************************************************ **
You can type following command in your terminal: "cat /etc/*-release":
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=13.04
DISTRIB_CODENAME=raring
DISTRIB_DESCRIPTION="Ubuntu 13.04"
NAME="Ubuntu"
VERSION="13.04, Raring Ringtail"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 13.04"
VERSION_ID="13.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
Personally, I think we can add more information about distribution to SysInfo.
************************************************************ ************************************************************ **
P.S.
I uploaded old file (It doesn't compile!!!).
*I enclose newer version with lowercase fix.
Sincerely,
Klugier
-
Attachment: os.cpp
(Size: 14.31KB, Downloaded 567 times)
U++ - one framework to rule them all.
[Updated on: Sun, 13 October 2013 13:06] Report message to a moderator
|
|
|
Re: [SysInfo - Improvement - Koldo] Better way to find distribution version & more [message #40955 is a reply to message #40954] |
Sun, 13 October 2013 01:58   |
 |
Klugier
Messages: 1099 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Here is the final version of the function:
static bool GetOsInfoCheckRelease(String &distro, String &distVersion)
{
StringParse release;
for (FindFile ff(AppendFileName("/etc/", "*-release")); ff; ff.Next())
release += LoadFile_Safe(ff.GetPath());
if (release.IsEmpty())
return false;
if (!release.GoAfter("DISTRIB_ID="))
return false;
distro = ToLower(release.GetText());
if (distro.IsEmpty())
return false;
release.GoAfter_Init("DISTRIB_RELEASE=");
distVersion = release.GetText();
return true;
}
I don't want to change current functionality, so i decided to stay with old qualifiers. In the future we can get more informations about distribution (with my extension). It is up to you.
P.S.
Moreover, you can change LoadFile_Safe function (Functions4U) to:
String LoadFile_Safe(const String& fileName);
insted of:
String LoadFile_Safe(String fileName);
U++ - one framework to rule them all.
[Updated on: Sun, 13 October 2013 13:06] Report message to a moderator
|
|
|
|
|
Re: [SysInfo - Improvement - Koldo] Better way to find distribution version & more [message #41002 is a reply to message #41001] |
Sat, 19 October 2013 00:37   |
 |
Klugier
Messages: 1099 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello Koldo,
Moreover, I wrote better handling for measuring cpu temperature on GNU/Linux (POSIX?). Now, SysInfo should use "hwmon" when "acpi" fails. Let's look at code:
static double GetCpuTemperatureViaAcpi()
{
FindFile ff;
if(ff.Search("/proc/acpi/thermal_zone/*")) {
do {
if (ff.IsDirectory()) {
String name = ff.GetName();
if (name != "." && name != "..") {
StringParse str = LoadFile_Safe(AppendFileName(AppendFileName("/proc/acpi/thermal_zone", name), "temperature"));
str.GoAfter("temperature:");
return str.GetDouble();
}
}
} while(ff.Next());
}
return Null;
}
static double GetCpuTemperatureViaHwmon()
{
Vector <double> temps;
for (FindFile ff(AppendFileName("/sys/class/hwmon/hwmon0/device", "*input")); ff; ff.Next()) {
if (!ff.IsHidden()) {
String temp = LoadFile_Safe(ff.GetPath());
if (!temp.IsEmpty())
temps.Add((double)StrInt(temp) / 1000.0);
}
}
double sumTemps = 0.0;
for (int i = 0; i < temps.GetCount(); i++)
sumTemps += temps[i];
if (!temps.IsEmpty())
return sumTemps / (double)temps.GetCount();
else
return Null;
}
double GetCpuTemperature()
{
double temp = Null;
if (temp == (double)Null) temp = GetCpuTemperatureViaAcpi();
if (temp == (double)Null) temp = GetCpuTemperatureViaHwmon();
return temp;
}
* in this case "static" means that function should be use only in file where it was declared.
P.S.
Toomorow, I will enclose source file with above improvement.
Sincerely,
Klugier
U++ - one framework to rule them all.
[Updated on: Sat, 19 October 2013 00:50] Report message to a moderator
|
|
|
|
|
|
Re: [SysInfo - Improvement - Koldo] Better way to find distribution version & more [message #41014 is a reply to message #41002] |
Sun, 20 October 2013 12:36   |
Zbych
Messages: 327 Registered: July 2009
|
Senior Member |
|
|
klugier wrote on Sat, 19 October 2013 00:37 |
static double GetCpuTemperatureViaHwmon()
{
Vector <double> temps;
for (FindFile ff(AppendFileName("/sys/class/hwmon/hwmon0/device", "*input")); ff; ff.Next()) {
|
Unfortunately it will not work on all systems. I checked some computers in my office:
1. intel, ubuntu 12.04, kernel 3.2, temperature location: /sys/class/hwmon/hwmon0/temp1_input (no device sub-dir)
2. intel, ubuntu 12.04, kernel 3.8, temperature location: /sys/devices/platform/coretemp.0/temp*_input
3. AMD, ubuntu 12.04, kernel 3.2, temperature location: /sys/class/hwmon/hwmon0/device/temp1_input
Maybe we should check libsensors to find out how it locates cpu temperature files.
|
|
|
|
|
Re: [SysInfo - Improvement - Koldo] Better way to find distribution version & more [message #41045 is a reply to message #41030] |
Wed, 23 October 2013 22:46   |
 |
Klugier
Messages: 1099 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello Koldo,
Koldo, please noticed that libsensor is GPL library. It means that all applications which are linking to SysInfo should also use GPL license. Only the latest version of libsensors use LGPL license. I do not think that people linking their programs with libsensors want to risk so much.
To use my trick with temperature you don't need to link with libsensors, beacuse I read only system file. In this way, you can also get more information about the computer sensors state. The main problem of this solution is how to find appropriate path on certain linux version.
More information about libsensors licence you can find on official site.
Sincerely,
Klugier
U++ - one framework to rule them all.
[Updated on: Thu, 24 October 2013 01:55] Report message to a moderator
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Fri Apr 25 12:17:26 CEST 2025
Total time taken to generate the page: 0.01334 seconds
|
|
|