add thread for determining free hdd (recording dir) space, enable hdd usage icons on vfd (untested)

Conflicts:
	data/locale/deutsch.locale
	data/locale/english.locale
	src/driver/simple_display.cpp
	src/gui/hdd_menu.cpp
	src/gui/infoviewer_bb.cpp
	src/gui/infoviewer_bb.h
	src/gui/moviebrowser.cpp
	src/gui/record_setup.cpp
	src/neutrino.cpp
	src/system/ytcache.h
This commit is contained in:
martii
2013-11-27 20:08:32 +01:00
committed by [CST] Focus
parent b74e80ee6f
commit 7c15db185f
15 changed files with 231 additions and 38 deletions

View File

@@ -36,6 +36,7 @@ libneutrino_system_a_SOURCES = \
debug.cpp \
flashtool.cpp \
fsmounter.cpp \
hddstat.cpp \
httptool.cpp \
lastchannel.cpp \
localize.cpp \

124
src/system/hddstat.cpp Normal file
View File

@@ -0,0 +1,124 @@
/*
Neutrino-HD
License: GPL
(C) 2013 martii
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __USE_FILE_OFFSET64
#define __USE_FILE_OFFSET64 1
#endif
#include <string>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/vfs.h>
#include <fcntl.h>
#include <time.h>
#include <stdarg.h>
#include <global.h>
#include "hddstat.h"
#include <gui/widget/menue.h>
//#include <system/ytcache.h>
#include <system/set_threadname.h>
#include <driver/record.h>
#include <driver/display.h>
static cHddStat *instance = NULL;
cHddStat *cHddStat::getInstance(void)
{
if (!instance)
instance = new cHddStat;
return instance;
}
void cHddStat::setDir(std::string &_dir)
{
pthread_mutex_lock(&mutex);
dir = _dir;
pthread_mutex_unlock(&mutex);
}
void *cHddStat::Run(void *arg)
{
set_threadname("hddstat");
class cHddStat *caller = (class cHddStat *)arg;
timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
long long oldperc = -2;
caller->once = g_settings.hdd_statfs_mode != SNeutrinoSettings::HDD_STATFS_OFF;
while (caller->running) {
std::string _dir;
pthread_mutex_lock(&caller->mutex);
_dir = caller->dir;
pthread_mutex_unlock(&caller->mutex);
long long perc = -1;
if (caller->once || (g_settings.hdd_statfs_mode == SNeutrinoSettings::HDD_STATFS_ALWAYS)
|| (g_settings.hdd_statfs_mode == SNeutrinoSettings::HDD_STATFS_RECORDING && (CRecordManager::getInstance()->RecordingStatus() /* || cYTCache::getInstance()->isActive() */ ))) {
caller->once = false;
struct statfs st;
if (statfs(_dir.c_str(), &st) || !st.f_blocks)
perc = -1;
else
perc = 100 * (long long)(st.f_blocks - st.f_bfree) / (long long) st.f_blocks;
} else
perc = oldperc;
if (oldperc != perc) {
oldperc = perc;
caller->percent = (int) perc;
//CVFD::getInstance()->setHddUsage(perc);
}
ts.tv_sec += caller->period;
sem_timedwait(&caller->sem, &ts);
}
pthread_exit(NULL);
}
cHddStat::cHddStat(void)
{
dir = g_settings.network_nfs_recordingdir;
period = 60;
percent = -1;
running = true;
sem_init(&sem, 0, 0);
pthread_mutex_init(&mutex, NULL);
if (pthread_create(&thr, NULL, Run, this))
running = false;
}
cHddStat::~cHddStat(void)
{
if (running) {
running = false;
sem_post(&sem);
pthread_join(thr, NULL);
}
sem_destroy(&sem);
}
void cHddStat::statOnce(void)
{
once = true;
sem_post(&sem);
}

55
src/system/hddstat.h Normal file
View File

@@ -0,0 +1,55 @@
/*
Neutrino-HD
License: GPL
(C) 2013 martii
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __SYSTEM_HDDSTAT__H_
#define __SYSTEM_HDDSTAT__H_
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string>
#include <pthread.h>
#include <semaphore.h>
class cHddStat
{
private:
pthread_t thr;
std::string dir;
static void* Run(void *);
cHddStat();
public:
unsigned int period;
bool running;
bool once;
int percent;
sem_t sem;
pthread_mutex_t mutex;
~cHddStat(void);
static cHddStat *getInstance(void);
void setDir(std::string &_dir);
void setPeriod(unsigned int _period) { period = _period; }
int getPercent(void) { return percent; }
void statOnce(void);
};
#endif

View File

@@ -716,6 +716,9 @@ typedef enum
LOCALE_HDD_SETTINGS,
LOCALE_HDD_SLEEP,
LOCALE_HDD_SLOW,
LOCALE_HDD_STATFS,
LOCALE_HDD_STATFS_ALWAYS,
LOCALE_HDD_STATFS_RECORDING,
LOCALE_HDD_UMOUNT,
LOCALE_HDD_UMOUNT_WARN,
LOCALE_HDD_UMOUNTED,
@@ -973,6 +976,7 @@ typedef enum
LOCALE_MENU_HINT_HDD_FORMAT,
LOCALE_MENU_HINT_HDD_NOISE,
LOCALE_MENU_HINT_HDD_SLEEP,
LOCALE_MENU_HINT_HDD_STATFS,
LOCALE_MENU_HINT_HDD_TOOLS,
LOCALE_MENU_HINT_HEAD_BACK,
LOCALE_MENU_HINT_HEAD_TEXTCOLOR,

View File

@@ -716,6 +716,9 @@ const char * locale_real_names[] =
"hdd_settings",
"hdd_sleep",
"hdd_slow",
"hdd_statfs",
"hdd_statfs_always",
"hdd_statfs_recording",
"hdd_umount",
"hdd_umount_warn",
"hdd_umounted",
@@ -973,6 +976,7 @@ const char * locale_real_names[] =
"menu.hint_hdd_format",
"menu.hint_hdd_noise",
"menu.hint_hdd_sleep",
"menu.hint_hdd_statfs",
"menu.hint_hdd_tools",
"menu.hint_head_back",
"menu.hint_head_textcolor",

View File

@@ -662,6 +662,8 @@ struct SNeutrinoSettings
int hdd_sleep;
int hdd_noise;
int hdd_fs;
enum { HDD_STATFS_OFF = 0, HDD_STATFS_ALWAYS, HDD_STATFS_RECORDING };
int hdd_statfs_mode;
int zap_cycle;
int sms_channel;
std::string font_file;