infoviewerbb: determination of hdd-percentage in a seperate thread

Origin commit data
------------------
Branch: ni/coolstream
Commit: 87f7a224f7
Author: vanhofen <vanhofen@gmx.de>
Date: 2012-09-19 (Wed, 19 Sep 2012)

Origin message was:
------------------
- infoviewerbb: determination of hdd-percentage in a seperate thread

------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
vanhofen
2012-09-19 21:23:50 +02:00
parent 02f699a0fb
commit e5b03811b9
4 changed files with 78 additions and 28 deletions

View File

@@ -86,6 +86,8 @@ CInfoViewerBB::CInfoViewerBB()
pthread_detach(scrambledT);
}
#endif
hddperT = 0;
hddperTflag = false;
Init();
}
@@ -117,6 +119,10 @@ CInfoViewerBB::~CInfoViewerBB()
pthread_cancel(scrambledT);
scrambledT = 0;
}
if(hddperT) {
pthread_cancel(hddperT);
hddperT = 0;
}
}
CInfoViewerBB* CInfoViewerBB::getInstance()
@@ -589,26 +595,45 @@ void CInfoViewerBB::showIcon_Tuner()
void CInfoViewerBB::showSysfsHdd()
{
if ((g_settings.infobar_show_sysfs_hdd) && (is_visible)) {
long blocks_used;
struct statfs s;
int per = 0;
if (::statfs("/", &s) == 0 && s.f_blocks) {
// per = (s.f_blocks - s.f_bfree) / (s.f_blocks/100);
blocks_used = s.f_blocks - s.f_bfree;
per = (blocks_used * 100ULL) / s.f_blocks;
}
varscale->paintProgressBar(bbIconMinX, BBarY + InfoHeightY_Info / 2 - 2 - 6, hddwidth , 6, per, 100);
per = 0;
//HD info
if(!check_dir(g_settings.network_nfs_recordingdir)){
if (::statfs(g_settings.network_nfs_recordingdir, &s) == 0 && s.f_blocks) {
blocks_used = s.f_blocks - s.f_bfree;
per = (blocks_used * 100ULL) / s.f_blocks;
if (g_settings.infobar_show_sysfs_hdd) {
//sysFS info
int sysper = 0;
sysper = get_fs_usage("/");
showBarSys(sysper);
//HDD info in a seperate thread
if(!hddperTflag) {
hddperTflag=true;
pthread_create(&hddperT, NULL, hddperThread, (void*) this);
pthread_detach(hddperT);
}
}
hddscale->paintProgressBar(bbIconMinX, BBarY + InfoHeightY_Info / 2 + 2, hddwidth, 6, per, 100);
}
void* CInfoViewerBB::hddperThread(void *arg)
{
CInfoViewerBB *infoViewerBB = (CInfoViewerBB*) arg;
int hddper = 0;
hddper = get_fs_usage(g_settings.network_nfs_recordingdir);
infoViewerBB->showBarHdd(hddper);
infoViewerBB->hddperTflag=false;
pthread_exit(NULL);
}
void CInfoViewerBB::showBarSys(int percent)
{
if (is_visible)
varscale->paintProgressBar(bbIconMinX, BBarY + InfoHeightY_Info / 2 - 2 - 6, hddwidth, 6, percent, 100);
}
void CInfoViewerBB::showBarHdd(int percent)
{
if (percent < 0)
percent = 0;
if (is_visible)
hddscale->paintProgressBar(bbIconMinX, BBarY + InfoHeightY_Info / 2 + 2 + 0, hddwidth, 6, percent, 100);
}
void CInfoViewerBB::paint_ca_icons(int caid, char * icon, int &icon_space_offset)

View File

@@ -121,6 +121,13 @@ class CInfoViewerBB
static void* scrambledThread(void *arg);
void scrambledCheck(bool force=false);
void showBarSys(int percent = 0);
void showBarHdd(int percent = 0);
pthread_t hddperT;
static void* hddperThread(void *arg);
bool hddperTflag;
public:
CInfoViewerBB();
~CInfoViewerBB();

View File

@@ -158,11 +158,11 @@ int safe_mkdir(char * path)
return ret;
}
int check_dir(const char * newdir)
int check_dir(const char * dir)
{
int ret = 0;
struct statfs s;
if (::statfs(newdir, &s) == 0) {
if (::statfs(dir, &s) == 0) {
switch (s.f_type) /* f_type is long */
{
case 0xEF53L: /*EXT2 & EXT3*/
@@ -174,12 +174,29 @@ int check_dir(const char * newdir)
case 0x58465342L: /*xfs*/
case 0x4d44L: /*msdos*/
case 0x0187: /* AUTOFS_SUPER_MAGIC */
case 0x858458f6: /*ramfs*/
return 0;//ok
case 0x858458f6L: /*ramfs*/
case 0x72b6L: /*jffs2*/
break; //ok
default:
fprintf( stderr,"%s Unknow File system type: %i\n",newdir ,s.f_type);
break;
fprintf(stderr, "%s Unknow File system type: %i\n" ,dir ,s.f_type);
ret = -1;
break; // error
}
}
return 1; // error
return ret;
}
int get_fs_usage(const char * dir)
{
int ret = check_dir(dir);
long blocks_used;
struct statfs s;
if (ret == 0) {
if (::statfs(dir, &s) == 0 && s.f_blocks) {
blocks_used = s.f_blocks - s.f_bfree;
ret = (blocks_used * 100ULL) / s.f_blocks;
}
}
return ret;
}

View File

@@ -28,8 +28,9 @@ int my_system(const char * cmd);
FILE* my_popen( pid_t& pid, const char *cmdstring, const char *type);
int safe_mkdir(char * path);
int check_dir(const char * newdir);
bool file_exists(const char *filename);
void wakeup_hdd(const char *hdd_dir);
int check_dir(const char * dir);
int get_fs_usage(const char * dir);
#endif