Commit e6dad07c authored by Jan Möbius's avatar Jan Möbius

REvert



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@20886 383ad7c9-94d9-4d36-a494-682f7c89f535
parent f1581e4d
......@@ -82,10 +82,7 @@ set (directories
../INIFile
../widgets/glWidget
../publicWidgets/objectSelectionWidget
../widgets/filePicker
../Utils/Memory
../Utils/FileIO
../Utils/Memory/procps
../widgets/filePicker
)
# collect all header,source and ui files
......@@ -114,9 +111,6 @@ endif ()
# Create library
#=======================================================
add_definitions( -DPROCPS_ENABLED )
if (QT5_FOUND)
acg_add_library (OpenFlipperPluginLib SHARED ${uic_targets} ${sources} ${headers} ${moc_targets})
elseif (QT4_FOUND)
......
#include "NumberParsing.hh"
#include <QString>
#include <cmath>
#include <sstream>
namespace Utils
{
float getFloat(QTextStream &_source)
{
QString rawNumber;
_source >> rawNumber;
//decimal part > 0
float highPart = 0.0f;
//decimal part < 0
float lowPart = 0.0f;
//sign of the decimal
float sign = 1.0;
//counter to concatenate high and lowaprt
int n = 0;
QString::Iterator it = rawNumber.begin();
QString::Iterator end = rawNumber.end();
if(*it == QLatin1Char('-'))
{
//we have a negative float
sign = sign * -1.0;
it++;
}
for (;it != end;it++)
{
//we have read a digit
if(it->isDigit())
{
highPart *=10;
highPart += it->digitValue();
}
else
{
//stop counting the highPart if its not a digit
it++;
break;
}
}
for (;it != end;it++)
{
//we assume to have read a digit
if(it->isDigit())
{
lowPart *=10;
lowPart += it->digitValue();
n++;
}
else
{
//stop counting the highPart dont increment here!
// otherwise we cant detect if we successful converted
break;
}
}
// if something went wrong during decoding use the standard decoding
if(it != end)
{
return rawNumber.toFloat();
}
return sign * (highPart + lowPart / std::pow(10.0,n));
}
float getFloat(std::istream &_source)
{
std::string rawNumber;
_source >> rawNumber;
//decimal part > 0
float highPart = 0.0f;
//decimal part < 0
float lowPart = 0.0f;
//sign of the decimal
float sign = 1.0;
//counter to concatenate high and lowaprt
int n = 0;
std::string::iterator it = rawNumber.begin();
std::string::iterator end = rawNumber.end();
if(*it == '-')
{
//we have a negative float
sign = sign * -1.0;
it++;
}
for (;it != end;it++)
{
//we have read a digit
if(isdigit(*it))
{
highPart *=10;
highPart += (int)(*it - '0');
}
else
{
//stop counting the highPart if its not a digit
it++;
break;
}
}
for (;it != end;it++)
{
//we assume to have read a digit
if(isdigit(*it))
{
lowPart *=10;
lowPart += (int)(*it - '0');
n++;
}
else
{
//stop counting the highPart dont increment here!
// otherwise we cant detect if we successful converted
break;
}
}
// if something went wrong during decoding use the standard decoding
if(it != end)
{
float fallback;
std::stringstream converter;
converter<<rawNumber;
converter>>fallback;
return fallback;
}
return sign * (highPart + lowPart / std::pow(10.0,n));
}
double getDouble(QTextStream &_source)
{
QString rawNumber;
_source >> rawNumber;
//decimal part > 0
double highPart = 0.0f;
//decimal part < 0
double lowPart = 0.0f;
//sign of the decimal
double sign = 1.0;
//counter to concatenate high and lowaprt
int n = 0;
QString::Iterator it = rawNumber.begin();
QString::Iterator end = rawNumber.end();
if(*it == QLatin1Char('-'))
{
//we have a negative float
sign = sign * -1.0;
it++;
}
for (;it != end;it++)
{
//we have read a digit
if(it->isDigit())
{
highPart *=10;
highPart += it->digitValue();
}
else
{
//stop counting the highPart if its not a digit
it++;
break;
}
}
for (;it != end;it++)
{
//we assume to have read a digit
if(it->isDigit())
{
lowPart *=10;
lowPart += it->digitValue();
n++;
}
else
{
//stop counting the highPart dont increment here!
// otherwise we cant detect if we successful converted
break;
}
}
// if something went wrong during decoding use the standard decoding
if(it != end)
{
return rawNumber.toDouble();
}
return sign * (highPart + lowPart / std::pow(10.0,n));
}
}
/**
* \file NumberParsing.hh
* This file contains functions which can be used to parse numbers from streams.
* The algorithms are designed to parse Numbers very fast, however for numbers with scientific notation the performance may not improve.
* (e.g. parsing 123e10 will be slower with this algorithm)
**/
#ifndef NUMBERPARSING_HH
#define NUMBERPARSING_HH
#include "OpenFlipper/common/GlobalDefines.hh"
#include <QTextStream>
namespace Utils{
/**
* @brief getDouble parses a QTextStream for a double. the double has to be the next word in the QTextStream.
* if parsing fails, the standard extraction is performed and returned.
* @param _source The QTextStream that holds at least one double.
* @return double the extracted double.
*/
DLLEXPORT
double getDouble( QTextStream& _source);
/**
* @brief getFloat parses a QTextStream for a float. the float has to be the next word in the QTextStream.
* if parsing fails, the standard extraction is performed and returned.
* @param _source The QTextStream that holds at least one float.
* @return float the extracted float.
*/
DLLEXPORT
float getFloat( QTextStream& _source);
/**
* @brief getFloat parses a std::istream for a float. the float has to be the next word in the std::istream.
* if parsing fails, the standard extraction is performed and returned.
* @param _source The std::istream that holds at least one float.
* @return float the extracted float.
*/
DLLEXPORT
float getFloat( std::istream& _source);
}
#endif // NUMBERPARSING_HH
#include "RAMInfo.hh"
// Main Memory information
#ifdef WIN32
#elif defined ARCH_DARWIN
#else
#include <sys/sysinfo.h>
//Info class returned by sysinfo
//struct sysinfo {
// long uptime; /* Sekunden seit dem letzten Systemstart */
// unsigned long loads[3]; /* 1, 5 und 15 minütige Systemlast */
// unsigned long totalram; /* nutzbare Hauptspeichergröße */
// unsigned long freeram; /* verfügbare Speichergröße */
// unsigned long sharedram; /* Größe des gemeinsamen Speichers */
// unsigned long bufferram; /* von Puffern benutzter Speicher */
// unsigned long totalswap; /* Größe des Auslagerungsspeichers */
// unsigned long freeswap; /* verfügbarer Auslagerungsspeicher */
// unsigned short procs; /* Aktuelle Prozesszahl */
// unsigned long totalhigh; /* Gesamtgröße des oberen Speicherbereichs */
// unsigned long freehigh; /* verfügbarer oberer Speicherbereich */
// unsigned int mem_unit; /* Größe der Speichereinheit in Byte */
// char _f[20-2*sizeof(long)-sizeof(int)]; /* Auffüllung auf 64 bytes */
//};
#endif
#if PROCPS_ENABLED
#include "procps/sysinfo.h"
#endif
namespace Utils
{
namespace Memory
{
void MemoryInfoUpdate(MemoryVacancy & _outMemoryVacancy) {
//initialize to 0 just in case something fails or cant be read
_outMemoryVacancy.totalRamMB = 0;
_outMemoryVacancy.freeRamMB = 0;
_outMemoryVacancy.bufferRamMB = 0;
// Main Memory information
#ifdef WIN32 //Windows
// Define memory structure
MEMORYSTATUSEX ms;
// Set the size ( required according to spec ... why???? )
ms.dwLength = sizeof(ms);
// Get the info
GlobalMemoryStatusEx(&ms);
_outMemoryVacancy.totalRamMB = ms.ullTotalPhys / 1024 / 1024;
_outMemoryVacancy.freeRamMB = ms.ullAvailPhys / 1024 / 1024;
#elif defined ARCH_DARWIN // Apple
#elif PROCPS_ENABLED
meminfo();
_outMemoryVacancy.totalRamMB = kb_main_total / 1024;
_outMemoryVacancy.freeRamMB = kb_main_free / 1024;
_outMemoryVacancy.bufferRamMB = (kb_main_buffers + kb_main_cached) / 1024;
#else // Linux
struct sysinfo sys_info;
sysinfo(&sys_info);
// Unit in bytes ; /1024 -> KB ; /1024 MB
_outMemoryVacancy.totalRamMB = sys_info.totalram / 1024 / 1024 * sys_info.mem_unit;
_outMemoryVacancy.freeRamMB = sys_info.freeram / 1024 / 1024 * sys_info.mem_unit;
_outMemoryVacancy.bufferRamMB = sys_info.bufferram / 1024 / 1024 * sys_info.mem_unit; // Buffers get freed, if we don't have enough free ram
#endif
}
}
}
#ifndef RAMINFO_HH
#define RAMINFO_HH
#include "OpenFlipper/common/GlobalDefines.hh"
namespace Utils
{
namespace Memory {
/**
* @brief The MemoryVacancy struct holds information about vacant buffered and total memory
*/
struct DLLEXPORT MemoryVacancy{
unsigned long totalRamMB;
unsigned long freeRamMB;
unsigned long bufferRamMB;
};
/**
* @brief MemoryInfoUpdate queries information about the RAM and writes them to a MemoryVacancy struct
* @param _outMemoryVacancy the Struct that shall hold the queried information.
*/
DLLEXPORT
void MemoryInfoUpdate(MemoryVacancy& _outMemoryVacancy);
}
}
#endif // RAMINFO_HH
add_library(procps SHARED version.c sysinfo.c alloc.c)
set_target_properties(procps PROPERTIES
COMPILE_DEFINITIONS "PACKAGE_NAME=\"OpenFlipper\";PACKAGE_VERSION=\"3.3.3\";_XOPEN_SOURCE=700"
COMPILE_FLAGS "-std=c99")
/*
* alloc.c - memory allocation functions
* Copyright (C) 1992-1998 by Michael K. Johnson, johnsonm@redhat.com
* Copyright 2002 Albert Cahalan
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "alloc.h"
static void xdefault_error(const char *restrict fmts, ...) __attribute__((format(printf,1,2)));
static void xdefault_error(const char *restrict fmts, ...) {
va_list va;
va_start(va, fmts);
fprintf(stderr, fmts, va);
va_end(va);
}
message_fn xalloc_err_handler = xdefault_error;
void *xcalloc(unsigned int size) {
void * p;
if (size == 0)
++size;
p = calloc(1, size);
if (!p) {
xalloc_err_handler("%s failed to allocate %u bytes of memory", __func__, size);
exit(EXIT_FAILURE);
}
return p;
}
void *xmalloc(unsigned int size) {
void *p;
if (size == 0)
++size;
p = malloc(size);
if (!p) {
xalloc_err_handler("%s failed to allocate %u bytes of memory", __func__, size);
exit(EXIT_FAILURE);
}
return(p);
}
void *xrealloc(void *oldp, unsigned int size) {
void *p;
if (size == 0)
++size;
p = realloc(oldp, size);
if (!p) {
xalloc_err_handler("%s failed to allocate %u bytes of memory", __func__, size);
exit(EXIT_FAILURE);
}
return(p);
}
char *xstrdup(const char *str) {
char *p = NULL;
if (str) {
unsigned int size = strlen(str) + 1;
p = malloc(size);
if (!p) {
xalloc_err_handler("%s failed to allocate %u bytes of memory", __func__, size);
exit(EXIT_FAILURE);
}
strcpy(p, str);
}
return(p);
}
#ifndef PROCPS_PROC_ALLOC_H
#define PROCPS_PROC_ALLOC_H
#include "procps.h"
EXTERN_C_BEGIN
/* change xalloc_err_handler to override the default fprintf(stderr... */
extern message_fn xalloc_err_handler;
extern void *xcalloc(unsigned int size) MALLOC;
extern void *xmalloc(unsigned int size) MALLOC;
extern void *xrealloc(void *oldp, unsigned int size) MALLOC;
extern char *xstrdup(const char *str) MALLOC;
EXTERN_C_END
#endif
#ifndef PROCPS_PROC_PROCPS_H
#define PROCPS_PROC_PROCPS_H
#ifdef __cplusplus
#define EXTERN_C_BEGIN extern "C" {
#define EXTERN_C_END }
#else
#define EXTERN_C_BEGIN
#define EXTERN_C_END
#endif
// Some ports make the mistake of running a 32-bit userspace
// on a 64-bit kernel. Shame on them. It's not at all OK to
// make everything "long long", since that causes unneeded
// slowness on 32-bit hardware.
//
// SPARC: The 32-bit kernel was looking like an ex-penguin,
// but it lives! ("I'm not dead yet.") So, 64-bit users will
// just have to compile for 64-bit. Aw, the suffering.
//
// MIPS: Used 32-bit for embedded systems and obsolete hardware.
// The 64-bit systems use an n32 format executable, defining
// _ABIN32 to indicate this. Since n32 doesn't currently run on
// any 32-bit system, nobody get hurt if it's bloated. Not that
// this is sane of course, but it won't hurt the 32-bit users.
// __mips_eabi means eabi, which comes in both sizes, but isn't used.
//
// PowerPC: Big ugly problem! 32-bit Macs are still popular. :-/
//
// x86-64: So far, nobody has been dumb enough to go 32-bit.
//
// Unknown: PA-RISC and zSeries
//
#if defined(k64test) || (defined(_ABIN32) && _MIPS_SIM == _ABIN32)
#define KLONG long long // not typedef; want "unsigned KLONG" to work
#define KLF "L"
#define STRTOUKL strtoull
#else
#define KLONG long
#define KLF "l"
#define STRTOUKL strtoul
#endif
// since gcc-2.5
#define NORETURN __attribute__((__noreturn__))
#define FUNCTION __attribute__((__const__)) // no access to global mem, even via ptr, and no side effect
#if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
// won't alias anything, and aligned enough for anything
#define MALLOC __attribute__ ((__malloc__))
// no side effect, may read globals
#define PURE __attribute__ ((__pure__))
// tell gcc what to expect: if(unlikely(err)) die(err);
#define likely(x) __builtin_expect(!!(x),1)
#define unlikely(x) __builtin_expect(!!(x),0)
#define expected(x,y) __builtin_expect((x),(y))
#else
#define MALLOC
#define PURE
#define likely(x) (x)
#define unlikely(x) (x)
#define expected(x,y) (x)
#endif
#ifdef SHARED
# if SHARED==1 && (__GNUC__ > 2 || __GNUC_MINOR__ >= 96)
# define LABEL_OFFSET
# endif
#endif
#define STRINGIFY_ARG(a) #a
#define STRINGIFY(a) STRINGIFY_ARG(a)
// marks old junk, to warn non-procps-ng library users
#if ( __GNUC__ == 3 && __GNUC_MINOR__ > 0 ) || __GNUC__ > 3
#define OBSOLETE __attribute__((deprecated))
#else
#define OBSOLETE
#endif
#if ( __GNUC__ == 3 && __GNUC_MINOR__ > 1 ) || __GNUC__ > 3
// Tells gcc that function is library-internal;
// so no need to do dynamic linking at run-time.
// This might work with slightly older compilers too.
#define HIDDEN __attribute__((visibility("hidden")))
// The opposite, in case -fvisibility=hidden used
#define EXPORT __attribute__((visibility("default")))
// Tell g++ that a function won't throw exceptions.
#define NOTHROW __attribute__((__nothrow__))
#else
#define HIDDEN
#define EXPORT
#define NOTHROW
#endif
// Like HIDDEN, but for an alias that gets created.
// In gcc-3.2 there is an alias+hidden conflict.
// Many will have patched this bug, but oh well.
#if ( __GNUC__ == 3 && __GNUC_MINOR__ > 2 ) || __GNUC__ > 3
#define HIDDEN_ALIAS(x) extern __typeof(x) x##_direct __attribute__((alias(#x),visibility("hidden")))
#else
#define HIDDEN_ALIAS(x) extern __typeof(x) x##_direct __attribute__((alias(#x)))
#endif
typedef void (*message_fn)(const char *__restrict, ...) __attribute__((format(printf,1,2)));
#endif
This diff is collapsed.
#ifndef PROC_SYSINFO_H
#define PROC_SYSINFO_H
#include <sys/types.h>
#include <sys/dir.h>
#include "procps.h"
EXTERN_C_BEGIN
extern unsigned long long Hertz; /* clock tick frequency */
extern long smp_num_cpus; /* number of CPUs */
extern int have_privs; /* boolean, true if setuid or similar */
#if 0
#define JT double
extern void eight_cpu_numbers(JT *uret, JT *nret, JT *sret, JT *iret, JT *wret, JT *xret, JT *yret, JT *zret);
#undef JT
#endif
extern int uptime (double *uptime_secs, double *idle_secs);
extern unsigned long getbtime(void);
extern void loadavg(double *av1, double *av5, double *av15);
/* obsolete */
extern unsigned long kb_main_shared;
/* old but still kicking -- the important stuff */
extern unsigned long kb_main_buffers;
extern unsigned long kb_main_cached;
extern unsigned long kb_main_free;
extern unsigned long kb_main_total;
extern unsigned long kb_swap_free;
extern unsigned long kb_swap_total;
/* recently introduced */
extern unsigned long kb_high_free;
extern unsigned long kb_high_total;
extern unsigned long kb_low_free;
extern unsigned long kb_low_total;
/* 2.4.xx era */
extern unsigned long kb_active;
extern unsigned long kb_inact_laundry; // grrr...
extern unsigned long kb_inact_dirty;
extern unsigned long kb_inact_clean;
extern unsigned long kb_inact_target;
extern unsigned long kb_swap_cached; /* late 2.4+ */
/* derived values */
extern unsigned long kb_swap_used;
extern unsigned long kb_main_used;
/* 2.5.41+ */
extern unsigned long kb_writeback;
extern unsigned long kb_slab;
extern unsigned long nr_reversemaps;
extern unsigned long kb_committed_as;
extern unsigned long kb_dirty;
extern unsigned long kb_inactive;
extern unsigned long kb_mapped;
extern unsigned long kb_pagetables;
#define BUFFSIZE (64*1024)
typedef unsigned long long jiff;
extern void getstat(jiff *__restrict cuse, jiff *__restrict cice, jiff *__restrict csys, jiff *__restrict cide, jiff *__restrict ciow, jiff *__restrict cxxx, jiff *__restrict cyyy, jiff *__restrict czzz,
unsigned long *__restrict pin, unsigned long *__restrict pout, unsigned long *__restrict s_in, unsigned long *__restrict sout,
unsigned *__restrict intr, unsigned *__restrict ctxt,
unsigned int *__restrict running, unsigned int *__restrict blocked,
unsigned int *__restrict btime, unsigned int *__restrict processes);
extern void meminfo(void);
extern unsigned long vm_nr_dirty;
extern unsigned long vm_nr_writeback;
extern unsigned long vm_nr_pagecache;
extern unsigned long vm_nr_page_table_pages;
extern unsigned long vm_nr_reverse_maps;
extern unsigned long vm_nr_mapped;
extern unsigned long vm_nr_slab;
extern unsigned long vm_pgpgin;
extern unsigned long vm_pgpgout;
extern unsigned long vm_pswpin;
extern unsigned long vm_pswpout;
extern unsigned long vm_pgalloc;
extern unsigned long vm_pgfree;
extern unsigned long vm_pgactivate;
extern unsigned long vm_pgdeactivate;
extern unsigned long vm_pgfault;
extern unsigned long vm_pgmajfault;
extern unsigned long vm_pgscan;
extern unsigned long vm_pgrefill;
extern unsigned long vm_pgsteal;
extern unsigned long vm_kswapd_steal;
extern unsigned long vm_pageoutrun;
extern unsigned long vm_allocstall;
extern void vminfo(void);
typedef struct disk_stat{
unsigned long long reads_sectors;
unsigned long long written_sectors;
char disk_name [16];
unsigned inprogress_IO;
unsigned merged_reads;
unsigned merged_writes;
unsigned milli_reading;
unsigned milli_spent_IO;
unsigned milli_writing;
unsigned partitions;
unsigned reads;
unsigned weighted_milli_spent_IO;
unsigned writes;
}disk_stat;
typedef struct partition_stat{
char partition_name [16];
unsigned long long reads_sectors;
unsigned parent_disk; // index into a struct disk_stat array
unsigned reads;
unsigned writes;
unsigned long long requested_writes;
}partition_stat;
extern unsigned int getpartitions_num(struct disk_stat *disks, int ndisks);
extern unsigned int getdiskstat (struct disk_stat**,struct partition_stat**);
typedef struct slab_cache{
char name[48];
unsigned active_objs;
unsigned num_objs;
unsigned objsize;
unsigned objperslab;
}slab_cache;
extern unsigned int getslabinfo (struct slab_cache**);
extern unsigned get_pid_digits(void) FUNCTION;
extern void cpuinfo (void);
EXTERN_C_END
#endif /* SYSINFO_H */
/*
* Suite version information for procps-ng utilities
* Copyright (c) 1995 Martin Schulze <joey@infodrom.north.de>
* Ammended by cblake to only export the function symbol.
*
* Modified by Albert Cahalan, ????-2003
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either