mirror of https://github.com/odrling/Aegisub
Basic Linux support for the reporter.
Gather basic CPU and memory information by parsing /proc/cpuinfo and /proc/meminfo. Originally committed to SVN as r3562.
This commit is contained in:
parent
ce6cdd77ce
commit
a299f79515
|
@ -27,6 +27,7 @@
|
|||
#include "include/platform.h"
|
||||
#include "platform_unix.h"
|
||||
#include "platform_unix_bsd.h"
|
||||
#include "platform_unix_linux.h"
|
||||
|
||||
/// @brief Constructor.
|
||||
Platform* Platform::GetPlatform() {
|
||||
|
@ -35,7 +36,11 @@ Platform* Platform::GetPlatform() {
|
|||
# ifdef __FREEBSD__
|
||||
Platform *p = new PlatformUnixBSD;
|
||||
# else
|
||||
# ifdef __LINUX__
|
||||
Platform *p = new PlatformUnixLinux;
|
||||
# else
|
||||
Platform *p = new PlatformUnix;
|
||||
# endif
|
||||
# endif
|
||||
#endif // __UNIX__
|
||||
p->Init();
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
// Copyright (c) 2009, Grigori Goronzy <greg@geekmind.org>
|
||||
//
|
||||
// Permission to use, copy, modify, and distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
/// @file platform_unix_linux.cpp
|
||||
/// @brief Linux Platform extensions.
|
||||
/// @ingroup unix
|
||||
|
||||
#ifndef R_PRECOMP
|
||||
#include <wx/string.h>
|
||||
#include <wx/textfile.h>
|
||||
#include <wx/log.h>
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
}
|
||||
|
||||
#include "include/platform.h"
|
||||
#include "platform_unix.h"
|
||||
#include "platform_unix_linux.h"
|
||||
|
||||
|
||||
wxString PlatformUnixLinux::CPUId() {
|
||||
return getProcValue("/proc/cpuinfo", "model name\t");
|
||||
};
|
||||
|
||||
wxString PlatformUnixLinux::CPUSpeed() {
|
||||
return getProcValue("/proc/cpuinfo", "cpu MHz\t\t");
|
||||
};
|
||||
|
||||
wxString PlatformUnixLinux::CPUCores() {
|
||||
return "";
|
||||
};
|
||||
|
||||
wxString PlatformUnixLinux::CPUCount() {
|
||||
// This returns the index of the last processor.
|
||||
// Increment and return as string.
|
||||
wxString procIndex = getProcValue("/proc/cpuinfo", "processor\t");
|
||||
if (procIndex.IsNumber()) {
|
||||
long val;
|
||||
procIndex.ToLong(&val);
|
||||
return wxString::Format("%ld", val + 1);
|
||||
}
|
||||
|
||||
// Fallback
|
||||
return "1";
|
||||
};
|
||||
|
||||
wxString PlatformUnixLinux::CPUFeatures() {
|
||||
return getProcValue("/proc/cpuinfo", "flags\t\t");
|
||||
};
|
||||
|
||||
wxString PlatformUnixLinux::CPUFeatures2() {
|
||||
return "";
|
||||
};
|
||||
|
||||
wxString PlatformUnixLinux::Memory() {
|
||||
return getProcValue("/proc/meminfo", "MemTotal");
|
||||
};
|
||||
|
||||
wxString PlatformUnixLinux::Video() {
|
||||
return "";
|
||||
};
|
||||
|
||||
wxString PlatformUnixLinux::UnixLibraries() {
|
||||
return "";
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Parse a /proc "key: value" style text file and extract a value.
|
||||
* The last valid value will be returned.
|
||||
*/
|
||||
wxString PlatformUnixLinux::getProcValue(const wxString path, const wxString key) {
|
||||
const wxString prefix = wxString(key) + ":";
|
||||
wxTextFile *file = new wxTextFile(path);
|
||||
wxString val = wxString();
|
||||
|
||||
file->Open();
|
||||
for (wxString str = file->GetFirstLine(); !file->Eof(); str = file->GetNextLine()) {
|
||||
str.Trim(false);
|
||||
if (str.StartsWith(prefix)) {
|
||||
val = wxString(str.Mid(key.Len() + 1));
|
||||
val.Trim(false);
|
||||
}
|
||||
}
|
||||
|
||||
delete file;
|
||||
return val;
|
||||
};
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright (c) 2009, Grigori Goronzy <greg@geekmind.org>
|
||||
//
|
||||
// Permission to use, copy, modify, and distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
/// @file platform_unix_linux.h
|
||||
/// @see platform_unix_linux.cpp
|
||||
/// @ingroup unix
|
||||
|
||||
class Platform;
|
||||
|
||||
/// @brief Linux values.
|
||||
class PlatformUnixLinux : public PlatformUnix {
|
||||
public:
|
||||
PlatformUnixLinux() {};
|
||||
virtual ~PlatformUnixLinux() {};
|
||||
|
||||
// Hardware
|
||||
virtual wxString CPUId();
|
||||
virtual wxString CPUSpeed();
|
||||
virtual wxString CPUCores();
|
||||
virtual wxString CPUCount();
|
||||
virtual wxString CPUFeatures();
|
||||
virtual wxString CPUFeatures2();
|
||||
virtual wxString Memory();
|
||||
virtual wxString Video();
|
||||
|
||||
// Unix Specific
|
||||
virtual wxString UnixLibraries();
|
||||
private:
|
||||
virtual wxString getProcValue(const wxString path, const wxString key);
|
||||
};
|
Loading…
Reference in New Issue