2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 3
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
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/>.
29
#include "applet-struct.h"
30
#include "applet-rame.h"
32
#define RAME_DATA_PIPE CD_SYSMONITOR_PROC_FS"/meminfo"
34
#define goto_next_line \
35
str = strchr (str, '\n'); \
37
myData.bAcquisitionOK = FALSE; \
41
#define get_value(iValue) \
42
str = strchr (str, ':'); \
44
myData.bAcquisitionOK = FALSE; \
52
void cd_sysmonitor_get_ram_data (CairoDockModuleInstance *myApplet)
54
gchar *cContent = NULL;
56
GError *erreur = NULL;
57
g_file_get_contents (RAME_DATA_PIPE, &cContent, &length, &erreur);
60
cd_warning("ram : %s", erreur->message);
63
myData.bAcquisitionOK = FALSE;
68
gchar *str = cContent;
70
get_value (myData.ramTotal) // MemTotal
74
get_value (myData.ramFree) // MemFree
77
myData.ramUsed = myData.ramTotal - myData.ramFree;
79
get_value (myData.ramBuffers) // Buffers.
82
get_value (myData.ramCached) // Cached.
85
myData.fRamPercent = 100. * (myData.ramUsed - myData.ramCached - myData.ramBuffers) / myData.ramTotal;
87
if (fabs (myData.fRamPercent - myData.fPrevRamPercent) > 1)
89
myData.fPrevRamPercent = myData.fRamPercent;
90
myData.bNeedsUpdate = TRUE;
93
if (myConfig.bShowSwap)
95
goto_next_line // SwapCached:
96
goto_next_line // Active:
97
goto_next_line // Inactive:
99
while (strncmp (str, "SwapTotal", 9) != 0) // apres, suivant la version su noyau, les lignes ne sont pas les memes, on fait donc une recherche.
103
get_value (myData.swapTotal) // SwapTotal.
105
get_value (myData.swapFree) // SwapFree.
107
myData.swapUsed = myData.swapTotal - myData.swapFree;
109
myData.fSwapPercent = 100. * myData.swapUsed / myData.swapTotal; // que faire de SwapCached ?...
110
if (fabs (myData.fSwapPercent - myData.fPrevSwapPercent) > 1)
112
myData.fPrevSwapPercent = myData.fSwapPercent;
113
myData.bNeedsUpdate = TRUE;