diff --git a/src/gui/imageinfo_ni.cpp b/src/gui/imageinfo_ni.cpp index c689432d0..9f7f55372 100644 --- a/src/gui/imageinfo_ni.cpp +++ b/src/gui/imageinfo_ni.cpp @@ -2,7 +2,7 @@ imageinfo_ni (C) 2009-2016 NG-Team - (C) 2016,2017 NI-Team + (C) 2016-2021 NI-Team License: GPL @@ -19,7 +19,6 @@ 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. - */ #ifdef HAVE_CONFIG_H @@ -64,17 +63,17 @@ #include #include -extern CPictureViewer * g_PicViewer; +extern CPictureViewer *g_PicViewer; #include -static unsigned long time2ms (const struct timeval *tv) +static unsigned long time2ms(const struct timeval *tv) { return (tv->tv_sec * 1000) + ((tv->tv_usec + 500) / 1000); } -long delta_time (struct timeval *tv, struct timeval *last_tv) +long delta_time(struct timeval *tv, struct timeval *last_tv) { - return time2ms (tv) - time2ms (last_tv); + return time2ms(tv) - time2ms(last_tv); } CImageInfoNI::CImageInfoNI() @@ -95,54 +94,55 @@ static const neutrino_locale_t info_items[] = LOCALE_IMAGEINFO_CREATOR, LOCALE_IMAGEINFO_HOMEPAGE }; -int info_items_count = sizeof(info_items)/sizeof(info_items[0]); +int info_items_count = sizeof(info_items) / sizeof(info_items[0]); void CImageInfoNI::Init(void) { - frameBuffer = CFrameBuffer::getInstance(); + frameBuffer = CFrameBuffer::getInstance(); - font_head = SNeutrinoSettings::FONT_TYPE_MENU_TITLE; - font_info = SNeutrinoSettings::FONT_TYPE_MENU; - font_small = SNeutrinoSettings::FONT_TYPE_MENU_INFO; + font_head = SNeutrinoSettings::FONT_TYPE_MENU_TITLE; + font_info = SNeutrinoSettings::FONT_TYPE_MENU; + font_small = SNeutrinoSettings::FONT_TYPE_MENU_INFO; - hheight = g_Font[font_head]->getHeight(); - iheight = g_Font[font_info]->getHeight(); - sheight = g_Font[font_small]->getHeight(); - swidth = g_Font[font_small]->getWidth(); + hheight = g_Font[font_head]->getHeight(); + iheight = g_Font[font_info]->getHeight(); + sheight = g_Font[font_small]->getHeight(); + swidth = g_Font[font_small]->getWidth(); - max_width = frameBuffer->getScreenWidth(true); - max_height = frameBuffer->getScreenHeight(true); + max_width = frameBuffer->getScreenWidth(true); + max_height = frameBuffer->getScreenHeight(true); - width = frameBuffer->getScreenWidth() - 2*OFFSET_INNER_MID; - height = frameBuffer->getScreenHeight() - 2*OFFSET_INNER_MID; - x = getScreenStartX(width); - y = getScreenStartY(height); + width = frameBuffer->getScreenWidth() - 2 * OFFSET_INNER_MID; + height = frameBuffer->getScreenHeight() - 2 * OFFSET_INNER_MID; + x = getScreenStartX(width); + y = getScreenStartY(height); // This single correction saves many offsets in code below - x += OFFSET_INNER_MID; - width -= OFFSET_INNER_MID; + x += OFFSET_INNER_MID; + width -= OFFSET_INNER_MID; - systemfs = 0; - revision = cs_get_revision(); - old_x = 0; - old_y = 0; - InfoThread = 0; - read_old = 0; - write_old = 0; - net_best = 0; - xcpu = x + width - width/3 - OFFSET_INNER_MID; - ycpu = y + OFFSET_INNER_MID + (height/3 /* pig-box height */) + (2 * iheight); - max_text_width = xcpu - x - OFFSET_INNER_MID; + systemfs = 0; + revision = cs_get_revision(); + old_x = 0; + old_y = 0; + InfoThread = 0; + read_old = 0; + write_old = 0; + net_best = 0; + xcpu = x + width - width / 3 - OFFSET_INNER_MID; + ycpu = y + OFFSET_INNER_MID + (height / 3 /* pig-box height */) + (2 * iheight); + max_text_width = xcpu - x - OFFSET_INNER_MID; - offset = 0; - for (int i = 0; i < info_items_count; i++) { + offset = 0; + for (int i = 0; i < info_items_count; i++) + { int tmpoffset = g_Font[font_info]->getRenderWidth(g_Locale->getText(info_items[i])); if (tmpoffset > offset) offset = tmpoffset; } - offset = offset + OFFSET_INNER_MID; + offset = offset + OFFSET_INNER_MID; - netIfName = "eth0"; //FIXME; What about the other ports? + netIfName = "eth0"; //FIXME; What about the other ports? } CImageInfoNI::~CImageInfoNI() @@ -150,7 +150,7 @@ CImageInfoNI::~CImageInfoNI() StopInfoThread(); } -int CImageInfoNI::exec(CMenuTarget* parent, const std::string &) +int CImageInfoNI::exec(CMenuTarget *parent, const std::string &) { int res = menu_return::RETURN_REPAINT; if (parent) @@ -160,18 +160,18 @@ int CImageInfoNI::exec(CMenuTarget* parent, const std::string &) neutrino_msg_t postmsg = 0; _stat cpu; - cpu.usr = 0; - cpu.nice = 0; - cpu.system = 0; - cpu.idle = 0; + cpu.usr = 0; + cpu.nice = 0; + cpu.system = 0; + cpu.idle = 0; - sigBox_pos = 0; + sigBox_pos = 0; COSDFader fader(g_settings.theme.menu_Content_alpha); fader.StartFadeIn(); bool fadeout = false; paint(); - paint_pic(xcpu, y + OFFSET_INNER_MID, width/3, height/3); + paint_pic(xcpu, y + OFFSET_INNER_MID, width / 3, height / 3); StartInfoThread(); while (1) @@ -251,7 +251,7 @@ void CImageInfoNI::hide() void CImageInfoNI::paint_pic(int px, int py, int w, int h) { - frameBuffer->paintBoxRel(px - OFFSET_INNER_MID, py - OFFSET_INNER_MID, w + 2*OFFSET_INNER_MID, h + 2*OFFSET_INNER_MID, COL_INFOBAR_PLUS_0); + frameBuffer->paintBoxRel(px - OFFSET_INNER_MID, py - OFFSET_INNER_MID, w + 2 * OFFSET_INNER_MID, h + 2 * OFFSET_INNER_MID, COL_INFOBAR_PLUS_0); g_PicViewer->DisplayImage(ICONSDIR "/start.jpg", px, py, w, h, frameBuffer->TM_NONE); } @@ -271,7 +271,7 @@ void CImageInfoNI::paint() int xpos = x; ypos = y; - const char * head_string; + const char *head_string; head_string = g_Locale->getText(LOCALE_IMAGEINFO_HEAD); CVFD::getInstance()->setMode(CVFD::MODE_MENU_UTF8, head_string); @@ -284,7 +284,7 @@ void CImageInfoNI::paint() ypos += hheight; g_Font[font_head]->RenderString(xpos, ypos, max_text_width, head_string, COL_MENUHEAD_TEXT); - ypos += iheight/2; + ypos += iheight / 2; CConfigFile config('\t'); config.loadConfig(IMAGE_VERSION_FILE); @@ -322,29 +322,29 @@ void CImageInfoNI::paint() ypos += iheight; paintLine(xpos, font_info, g_Locale->getText(LOCALE_IMAGEINFO_IMAGE)); - paintLine(xpos+offset, font_info, imagename); + paintLine(xpos + offset, font_info, imagename); ypos += iheight; paintLine(xpos, font_info, g_Locale->getText(LOCALE_IMAGEINFO_VERSION)); #if 0 - paintLine(xpos+offset, font_info, imageversion.str()); + paintLine(xpos + offset, font_info, imageversion.str()); #else - paintLine(xpos+offset, font_info, describe); + paintLine(xpos + offset, font_info, describe); #endif ypos += iheight; paintLine(xpos, font_info, g_Locale->getText(LOCALE_IMAGEINFO_DATE)); - paintLine(xpos+offset, font_info, builddate); + paintLine(xpos + offset, font_info, builddate); struct utsname uts_info; ypos += iheight; paintLine(xpos, font_info, g_Locale->getText(LOCALE_IMAGEINFO_KERNEL)); - paintLine(xpos+offset, font_info, uname(&uts_info) < 0 ? "n/a" : uts_info.release); + paintLine(xpos + offset, font_info, uname(&uts_info) < 0 ? "n/a" : uts_info.release); ypos += iheight; paintLine(xpos, font_info, g_Locale->getText(LOCALE_IMAGEINFO_GUI)); - paintLine(xpos+offset, font_info, guiversion.str()); + paintLine(xpos + offset, font_info, guiversion.str()); #if USE_STB_HAL hal_libversion_t halver; @@ -352,26 +352,26 @@ void CImageInfoNI::paint() ypos += iheight; paintLine(xpos, font_info, "libstb-hal:"); - paintLine(xpos+offset, font_info, halver.vVersion); + paintLine(xpos + offset, font_info, halver.vVersion); #endif #ifdef ENABLE_LUA ypos += iheight; paintLine(xpos, font_info, "Lua-API:"); - paintLine(xpos+offset, font_info, to_string(LUA_API_VERSION_MAJOR) + "." + to_string(LUA_API_VERSION_MINOR)); + paintLine(xpos + offset, font_info, to_string(LUA_API_VERSION_MAJOR) + "." + to_string(LUA_API_VERSION_MINOR)); #endif ypos += iheight; paintLine(xpos, font_info, "yWeb:"); - paintLine(xpos+offset, font_info, getYWebVersion()); + paintLine(xpos + offset, font_info, getYWebVersion()); ypos += iheight; paintLine(xpos, font_info, g_Locale->getText(LOCALE_IMAGEINFO_CREATOR)); - paintLine(xpos+offset, font_info, creator); + paintLine(xpos + offset, font_info, creator); ypos += iheight; paintLine(xpos, font_info, g_Locale->getText(LOCALE_IMAGEINFO_HOMEPAGE)); - paintLine(xpos+offset, font_info, homepage); + paintLine(xpos + offset, font_info, homepage); ypos += iheight; @@ -381,20 +381,21 @@ void CImageInfoNI::paint() //ypos += sheight; paint_DF_Info(xpos); - ypos+= sheight; + ypos += sheight; #endif - paint_Stat_Info_Box(xcpu, ycpu, width/3, height/3); + paint_Stat_Info_Box(xcpu, ycpu, width / 3, height / 3); } -void* CImageInfoNI::InfoProc(void *arg) +void *CImageInfoNI::InfoProc(void *arg) { - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,0); - pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS,0); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0); + pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0); - CImageInfoNI *imageInfo = (CImageInfoNI*) arg; + CImageInfoNI *imageInfo = (CImageInfoNI *) arg; - while(1) { + while (1) + { imageInfo->paint_MEM_Info(imageInfo->x, imageInfo->ypos); imageInfo->paint_NET_Info(imageInfo->x, imageInfo->ypos); sleep(1); @@ -404,16 +405,18 @@ void* CImageInfoNI::InfoProc(void *arg) void CImageInfoNI::StartInfoThread() { - if(!InfoThread) { + if (!InfoThread) + { printf("CImageInfoNI::StartInfoThread\n"); - pthread_create (&InfoThread, NULL, InfoProc, (void*) this) ; + pthread_create(&InfoThread, NULL, InfoProc, (void *) this) ; pthread_detach(InfoThread); } } void CImageInfoNI::StopInfoThread() { - if(InfoThread) { + if (InfoThread) + { printf("CImageInfoNI::StopInfoThread\n"); pthread_cancel(InfoThread); InfoThread = 0; @@ -430,7 +433,7 @@ std::string CImageInfoNI::get_systemRoot() fh.open(file.c_str(), std::ios::in); - if(!fh.is_open()) + if (!fh.is_open()) { return root; } @@ -443,7 +446,7 @@ std::string CImageInfoNI::get_systemRoot() std::string::size_type end = s.find(' ', begin); root = s.substr(begin, end - begin); - if(!root.empty()) + if (!root.empty()) break; } fh.close(); @@ -460,8 +463,8 @@ int CImageInfoNI::get_MTD_Info() memset(&mtd_info, 0, sizeof(mtd_info)); - buffer=NULL; - if (!(fh=fopen("/proc/mtd", "r"))) + buffer = NULL; + if (!(fh = fopen("/proc/mtd", "r"))) return false; #ifdef BOXMODEL_CST_HD2 @@ -484,12 +487,12 @@ int CImageInfoNI::get_MTD_Info() mtd_info.push_back(entry); if (strstr(mtd_info[i].name, sysfs.c_str())) - systemfs=i; + systemfs = i; i++; } } fclose(fh); - if(buffer) + if (buffer) free(buffer); return 0; } @@ -497,13 +500,13 @@ int CImageInfoNI::get_MTD_Info() #if 0 void CImageInfoNI::paint_MTD_Info(int posx) { - for (int i=0; i<(int)mtd_info.size(); i++) + for (int i = 0; i < (int)mtd_info.size(); i++) { - char buf[(strlen(mtd_info[i].dev)+strlen(mtd_info[i].name)+3)]; + char buf[(strlen(mtd_info[i].dev) + strlen(mtd_info[i].name) + 3)]; - sprintf((char*) buf, "%s: %s", mtd_info[i].dev, mtd_info[i].name); + sprintf((char *) buf, "%s: %s", mtd_info[i].dev, mtd_info[i].name); paintLine(posx, font_small, buf); - ypos+= sheight; + ypos += sheight; } } #endif @@ -516,12 +519,12 @@ int CImageInfoNI::Stat_Info(_stat *stat_info) ssize_t read; size_t len; - stat_info->old_usr = stat_info->usr; - stat_info->old_nice = stat_info->nice; - stat_info->old_system = stat_info->system; - stat_info->old_idle = stat_info->idle; + stat_info->old_usr = stat_info->usr; + stat_info->old_nice = stat_info->nice; + stat_info->old_system = stat_info->system; + stat_info->old_idle = stat_info->idle; - buffer=NULL; + buffer = NULL; if (!(fh = fopen("/proc/stat", "r"))) return false; @@ -529,12 +532,12 @@ int CImageInfoNI::Stat_Info(_stat *stat_info) { if ((ptr = strstr(buffer, "cpu"))) { - sscanf(ptr+3, "%lu %i %lu %lu", &stat_info->usr, &stat_info->nice, &stat_info->system, &stat_info->idle); + sscanf(ptr + 3, "%lu %i %lu %lu", &stat_info->usr, &stat_info->nice, &stat_info->system, &stat_info->idle); break; } } fclose(fh); - if(buffer) + if (buffer) free(buffer); return true; } @@ -554,14 +557,14 @@ int CImageInfoNI::CPU_Percent(_stat *cpu) long unsigned int percent = ((float) sys_diff / (float) total_diff) * 100; if (sys_diff > 1 || total_diff > 1) - return(percent); + return (percent); else - return(0); + return (0); } void CImageInfoNI::paint_Stat_Info_Box(int InfoB_x, int InfoB_y, int InfoB_w, int InfoB_h) { - frameBuffer->paintBoxRel(InfoB_x - OFFSET_INNER_MID, InfoB_y - OFFSET_INNER_MID, InfoB_w + 2*OFFSET_INNER_MID, InfoB_h + 2*OFFSET_INNER_MID, COL_INFOBAR_PLUS_0); + frameBuffer->paintBoxRel(InfoB_x - OFFSET_INNER_MID, InfoB_y - OFFSET_INNER_MID, InfoB_w + 2 * OFFSET_INNER_MID, InfoB_h + 2 * OFFSET_INNER_MID, COL_INFOBAR_PLUS_0); g_Font[font_info]->RenderString(InfoB_x, InfoB_y, InfoB_w, "CPU-Load", COL_INFOBAR_TEXT); sigBox_x = InfoB_x; @@ -569,7 +572,7 @@ void CImageInfoNI::paint_Stat_Info_Box(int InfoB_x, int InfoB_y, int InfoB_w, in sigBox_w = InfoB_w; sigBox_h = InfoB_h; - frameBuffer->paintBoxRel(sigBox_x,sigBox_y,sigBox_w,sigBox_h, COL_BLACK); + frameBuffer->paintBoxRel(sigBox_x, sigBox_y, sigBox_w, sigBox_h, COL_BLACK); } void CImageInfoNI::paint_CPU_Percent(int percent) @@ -580,32 +583,34 @@ void CImageInfoNI::paint_CPU_Percent(int percent) sigBox_pos = (++sigBox_pos_t) % sigBox_w; - frameBuffer->paintVLine(sigBox_x+sigBox_pos, sigBox_y, sigBox_y+sigBox_h, COL_WHITE); - frameBuffer->paintVLine(sigBox_x+x_now, sigBox_y, sigBox_y+sigBox_h, COL_BLACK); + frameBuffer->paintVLine(sigBox_x + sigBox_pos, sigBox_y, sigBox_y + sigBox_h, COL_WHITE); + frameBuffer->paintVLine(sigBox_x + x_now, sigBox_y, sigBox_y + sigBox_h, COL_BLACK); yd = y_cpu_pixel(percent, 100, sigBox_h); if ((old_x == 0 && old_y == 0) || sigBox_pos == 1) { - old_x = sigBox_x+x_now; - old_y = sigBox_y+sigBox_h-yd; + old_x = sigBox_x + x_now; + old_y = sigBox_y + sigBox_h - yd; } else { - frameBuffer->paintLine(old_x, old_y, sigBox_x+x_now, sigBox_y+sigBox_h-yd, COL_RED); - old_x = sigBox_x+x_now; - old_y = sigBox_y+sigBox_h-yd; + frameBuffer->paintLine(old_x, old_y, sigBox_x + x_now, sigBox_y + sigBox_h - yd, COL_RED); + old_x = sigBox_x + x_now; + old_y = sigBox_y + sigBox_h - yd; } } int CImageInfoNI::y_cpu_pixel(int value, int max_value, int max_y) { - int l; + int l; - if (!max_value) max_value = 1; + if (!max_value) + max_value = 1; - l = (max_y * value ) / max_value; - if (l > max_y) l = max_y; + l = (max_y * value) / max_value; + if (l > max_y) + l = max_y; return l; } @@ -620,18 +625,19 @@ void CImageInfoNI::get_DF_Info() memset(&image_size, 0, sizeof(image_size)); - buffer=NULL; - if (!(pipe_reader = popen ("df", "r"))) - printf("[read_df] popen error\n" ); + buffer = NULL; + if (!(pipe_reader = popen("df", "r"))) + printf("[read_df] popen error\n"); #ifdef BOXMODEL_CST_HD2 - strcpy(mtd_info[systemfs].dev, ("mtd:"+get_systemRoot()).c_str()); + strcpy(mtd_info[systemfs].dev, ("mtd:" + get_systemRoot()).c_str()); #endif - while ((read = getline(&buffer, &len, pipe_reader)) != -1) - { - if ((ptr = strstr(buffer, mtd_info[systemfs].dev))) { - sscanf(ptr+strlen(mtd_info[systemfs].dev), "%ld\t%ld\t%ld\t%i", + while ((read = getline(&buffer, &len, pipe_reader)) != -1) + { + if ((ptr = strstr(buffer, mtd_info[systemfs].dev))) + { + sscanf(ptr + strlen(mtd_info[systemfs].dev), "%ld\t%ld\t%ld\t%i", &image_size.blocks, &image_size.used, &image_size.available, @@ -639,18 +645,18 @@ void CImageInfoNI::get_DF_Info() } } pclose(pipe_reader); - if(buffer) + if (buffer) free(buffer); } void CImageInfoNI::paint_DF_Info(int posx) { - ypos += sheight/2; + ypos += sheight / 2; std::ostringstream buf; - int boxH = sheight - 2*OFFSET_INNER_MIN; - int boxW = swidth*8; - int boxX = posx + width/3 - boxW; + int boxH = sheight - 2 * OFFSET_INNER_MIN; + int boxW = swidth * 8; + int boxX = posx + width / 3 - boxW; int boxY = ypos - sheight + OFFSET_INNER_MIN; get_DF_Info(); @@ -672,26 +678,26 @@ void CImageInfoNI::paint_DF_Info(int posx) if (image_size.blocks > 1024) { if (image_size.used > 1024) - buf << "Total: " << (image_size.blocks/1024.0) << " MB Used: " << (image_size.used/1024.0) << " MB"; + buf << "Total: " << (image_size.blocks / 1024.0) << " MB, Used: " << (image_size.used / 1024.0) << " MB"; else - buf << "Total: " << (image_size.blocks/1024.0) << " MB Used: " << image_size.used << " KB"; + buf << "Total: " << (image_size.blocks / 1024.0) << " MB, Used: " << image_size.used << " kB"; } else { if (image_size.used > 1024) - buf << "Total: " << image_size.blocks << " KB Used: " << (image_size.used/1024.0) << " MB"; + buf << "Total: " << image_size.blocks << " kB, Used: " << (image_size.used / 1024.0) << " MB"; else - buf << "Total: " << image_size.blocks << " KB Used: " << image_size.used << " KB"; + buf << "Total: " << image_size.blocks << " kB, Used: " << image_size.used << " kB"; } - ypos+= sheight; + ypos += sheight; paintLine(posx, font_small, buf.str()); buf.str(""); if (image_size.available > 1024) - buf << "Free: " << (image_size.available/1024.0) << " MB"; + buf << "Free: " << (image_size.available / 1024.0) << " MB"; else - buf << "Free: " << image_size.available << " KB"; + buf << "Free: " << image_size.available << " kB"; ypos += sheight; paintLine(posx, font_small, buf.str()); @@ -707,25 +713,26 @@ int CImageInfoNI::get_MEM_Info() memset(&mem_info, 0, sizeof(mem_info)); - buffer=NULL; + buffer = NULL; if (!(fh = fopen("/proc/meminfo", "r"))) return false; while ((read = getline(&buffer, &len, fh)) != -1) { if ((ptr = strstr(buffer, "MemTotal:"))) - sscanf(ptr+10, "%i", &mem_info.total); + sscanf(ptr + 10, "%i", &mem_info.total); else if ((ptr = strstr(buffer, "MemFree:"))) - sscanf(ptr+9, "%i", &mem_info.free); + sscanf(ptr + 9, "%i", &mem_info.free); else if ((ptr = strstr(buffer, "Buffers:"))) - sscanf(ptr+9, "%i", &mem_info.buffers); - else if ((ptr = strstr(buffer, "Cached:"))) { - sscanf(ptr+8, "%i", &mem_info.cached); + sscanf(ptr + 9, "%i", &mem_info.buffers); + else if ((ptr = strstr(buffer, "Cached:"))) + { + sscanf(ptr + 8, "%i", &mem_info.cached); break; } } fclose(fh); - if(buffer) + if (buffer) free(buffer); mem_info.tfree = mem_info.free + mem_info.buffers + mem_info.cached; @@ -736,18 +743,18 @@ int CImageInfoNI::get_MEM_Info() int CImageInfoNI::get_MEM_Percent(int total, int used) { - return ((used*200 + total) / 2 / total); //this is CST style ;) + return ((used * 200 + total) / 2 / total); //this is CST style ;) } void CImageInfoNI::paint_MEM_Info(int posx, int posy) { std::ostringstream buf; - posy += sheight/2; + posy += sheight / 2; - int boxH = sheight - 2*OFFSET_INNER_MIN; - int boxW = swidth*8; - int boxX = posx + width/3 - boxW; + int boxH = sheight - 2 * OFFSET_INNER_MIN; + int boxW = swidth * 8; + int boxX = posx + width / 3 - boxW; int boxY = posy - sheight + OFFSET_INNER_MIN ; get_MEM_Info(); @@ -765,21 +772,21 @@ void CImageInfoNI::paint_MEM_Info(int posx, int posy) pb.setValues(mem_percent, 100); pb.paint(false); - posy+= sheight; + posy += sheight; buf.str(""); buf.precision(2); - buf << std::fixed << "Total: " << (mem_info.total/1024.0) << " MB Used: " << (mem_info.used/1024.0) << " MB"; + buf << std::fixed << "Total: " << (mem_info.total / 1024.0) << " MB, Used: " << (mem_info.used / 1024.0) << " MB"; frameBuffer->paintBoxRel(posx, posy - sheight, max_text_width, sheight, COL_INFOBAR_PLUS_0); g_Font[font_small]->RenderString(posx, posy, max_text_width, buf.str().c_str(), COL_INFOBAR_TEXT); - posy+= sheight; + posy += sheight; buf.str(""); - buf << "Free: " << (mem_info.tfree < 1024 ? mem_info.tfree : (mem_info.tfree/1024.0)) - << (mem_info.tfree < 1024?" KB ":" MB ") - << "(Buffers: " << (mem_info.buffers < 1024 ? mem_info.buffers : (mem_info.buffers/1024.0)) - << (mem_info.buffers < 1024?" KB, ":" MB, ") - << "Cached: " << (mem_info.cached < 1024 ? mem_info.cached : (mem_info.cached/1024.0)) - << (mem_info.cached < 1024?" KB":" MB)"); + buf << "Free: " << (mem_info.tfree < 1024 ? mem_info.tfree : (mem_info.tfree / 1024.0)) + << (mem_info.tfree < 1024 ? " kB " : " MB ") + << "(Buffers: " << (mem_info.buffers < 1024 ? mem_info.buffers : (mem_info.buffers / 1024.0)) + << (mem_info.buffers < 1024 ? " kB, " : " MB, ") + << "Cached: " << (mem_info.cached < 1024 ? mem_info.cached : (mem_info.cached / 1024.0)) + << (mem_info.cached < 1024 ? " kB" : " MB)"); frameBuffer->paintBoxRel(posx, posy - sheight, max_text_width, sheight, COL_INFOBAR_PLUS_0); g_Font[font_small]->RenderString(posx, posy, max_text_width, buf.str().c_str(), COL_INFOBAR_TEXT); @@ -787,18 +794,18 @@ void CImageInfoNI::paint_MEM_Info(int posx, int posy) void CImageInfoNI::get_NET_Info(uint64_t *read_akt, long *read_packet, long *dummy, uint64_t *write_akt, long *write_packet) { - FILE *file = NULL; + FILE *file = NULL; char *ptr; - char *line_buffer = NULL; - long *packet_ptr[3] = {read_packet, write_packet, dummy}; - uint64_t *byte_ptr[2] = {read_akt, write_akt}; + char *line_buffer = NULL; + long *packet_ptr[3] = {read_packet, write_packet, dummy}; + uint64_t *byte_ptr[2] = {read_akt, write_akt}; ssize_t read; size_t len; char interface[20]; memset(interface, '\0', sizeof(interface)); - snprintf(interface, sizeof(interface)-1, "%s", netIfName.c_str()); + snprintf(interface, sizeof(interface) - 1, "%s", netIfName.c_str()); - if ((file = fopen("/proc/net/dev","r"))==NULL) + if ((file = fopen("/proc/net/dev", "r")) == NULL) { printf("Open Proc-File Failure\n"); fflush(stdout); } @@ -806,26 +813,26 @@ void CImageInfoNI::get_NET_Info(uint64_t *read_akt, long *read_packet, long *dum { while ((read = getline(&line_buffer, &len, file)) != -1) { - if((ptr = strstr(line_buffer, interface))!=NULL) + if ((ptr = strstr(line_buffer, interface)) != NULL) { - dprintf(DEBUG_INFO, "Procline = %s",line_buffer); + dprintf(DEBUG_INFO, "Procline = %s", line_buffer); - sscanf(ptr+strlen(interface)+1,"%llu%ld%ld%ld%ld%ld%ld%ld%llu%ld", - (long long unsigned int*)byte_ptr[0], - (long*)packet_ptr[0], + sscanf(ptr + strlen(interface) + 1, "%llu%ld%ld%ld%ld%ld%ld%ld%llu%ld", + (long long unsigned int *)byte_ptr[0], + (long *)packet_ptr[0], (long *)packet_ptr[2], (long *)packet_ptr[2], (long *)packet_ptr[2], (long *)packet_ptr[2], (long *)packet_ptr[2], (long *)packet_ptr[2], - (long long unsigned int*)byte_ptr[1], - (long*)packet_ptr[1]); + (long long unsigned int *)byte_ptr[1], + (long *)packet_ptr[1]); } } - fclose (file); + fclose(file); } - if(line_buffer) + if (line_buffer) free(line_buffer); } @@ -836,21 +843,21 @@ void CImageInfoNI::paint_NET_Info(int posx, int posy) return; #endif - uint64_t read_akt =0; - uint64_t write_akt =0; - uint64_t delta_read =0; - uint64_t delta_write =0; - long read_packet =0; - long write_packet =0; - long dummy =0; - char temp_string[200] =""; + uint64_t read_akt = 0; + uint64_t write_akt = 0; + uint64_t delta_read = 0; + uint64_t delta_write = 0; + long read_packet = 0; + long write_packet = 0; + long dummy = 0; + char temp_string[200] = ""; - posy += sheight/2; - posy += 3*sheight + sheight/2; //height meminfo above that + posy += sheight / 2; + posy += 3 * sheight + sheight / 2; //height meminfo above that - int boxH = sheight - 2*OFFSET_INNER_MIN; - int boxW = swidth*8; - int boxX = posx + width/3 - boxW; + int boxH = sheight - 2 * OFFSET_INNER_MIN; + int boxW = swidth * 8; + int boxX = posx + width / 3 - boxW; int boxY = posy - sheight + OFFSET_INNER_MIN ; /* @@ -864,53 +871,53 @@ void CImageInfoNI::paint_NET_Info(int posx, int posy) * dd of=/dev/null if=/srv/netztest bs=8192 count=131072 */ - gettimeofday (&tv, NULL); + gettimeofday(&tv, NULL); get_NET_Info(&read_akt, &read_packet, &dummy, &write_akt, &write_packet); - long d_time_ms = delta_time(&tv, &last_tv); + long d_time_ms = delta_time(&tv, &last_tv); - if(read_old != 0 && read_akt > read_old) + if (read_old != 0 && read_akt > read_old) delta_read = read_akt - read_old; - if(write_old != 0 && write_akt > write_old) + if (write_old != 0 && write_akt > write_old) delta_write = write_akt - write_old; uint64_t rbit_s = (((uint64_t) delta_read * 8000ULL) + ((uint64_t) d_time_ms / 2ULL)) / (uint64_t) d_time_ms; uint64_t wbit_s = (((uint64_t) delta_write * 8000ULL) + ((uint64_t) d_time_ms / 2ULL)) / (uint64_t) d_time_ms; - if((rbit_s+wbit_s) > net_best) - net_best = rbit_s+wbit_s; + if ((rbit_s + wbit_s) > net_best) + net_best = rbit_s + wbit_s; /* * 100 MBit * 12,5 MByte (MB) - * 12800 KByte (KB) - * 102400 KBit + * 12800 kByte (kB) + * 102400 kBit * 13107200 Byte * 104857600 Bit */ - int max_bit = 104857600; + int max_bit = 104857600; #ifdef BOXMODEL_CST_HD2 if (revision == 9) /* Apollo */ - max_bit = 1073741824; + max_bit = 1073741824; #endif - int percent = ((rbit_s+wbit_s)*100/max_bit); + int percent = ((rbit_s + wbit_s) * 100 / max_bit); - dprintf(DEBUG_INFO,"read byte = %llu - %llu\n",(long long unsigned int)read_akt,(long long unsigned int)read_old); - dprintf(DEBUG_INFO,"write byte = %llu - %llu\n",(long long unsigned int)write_akt,(long long unsigned int)write_old); - dprintf(DEBUG_INFO,"read_packet = %ld\n",read_packet); - dprintf(DEBUG_INFO,"write_packet= %ld\n",write_packet); - dprintf(DEBUG_INFO,"delta time = %10ld ms\n",d_time_ms); - dprintf(DEBUG_INFO,"read = %10llu bit/s\n",(long long unsigned int)rbit_s); - dprintf(DEBUG_INFO,"write = %10llu bit/s\n",(long long unsigned int)wbit_s); - dprintf(DEBUG_INFO,"total = %10llu bit/s (%d%%) / best %llu (%.2f MB/s) = (%d%%)\n\n", - (long long unsigned int)rbit_s+wbit_s, + dprintf(DEBUG_INFO, "read byte = %llu - %llu\n", (long long unsigned int)read_akt, (long long unsigned int)read_old); + dprintf(DEBUG_INFO, "write byte = %llu - %llu\n", (long long unsigned int)write_akt, (long long unsigned int)write_old); + dprintf(DEBUG_INFO, "read_packet = %ld\n", read_packet); + dprintf(DEBUG_INFO, "write_packet= %ld\n", write_packet); + dprintf(DEBUG_INFO, "delta time = %10ld ms\n", d_time_ms); + dprintf(DEBUG_INFO, "read = %10llu bit/s\n", (long long unsigned int)rbit_s); + dprintf(DEBUG_INFO, "write = %10llu bit/s\n", (long long unsigned int)wbit_s); + dprintf(DEBUG_INFO, "total = %10llu bit/s (%d%%) / best %llu (%.2f MB/s) = (%d%%)\n\n", + (long long unsigned int)rbit_s + wbit_s, percent, (long long unsigned int)net_best, - net_best/(8.0*1024.0*1024.0), - (int)(net_best*100/max_bit) + net_best / (8.0 * 1024.0 * 1024.0), + (int)(net_best * 100 / max_bit) ); - sprintf(temp_string,"Interface %s (%d%%):", netIfName.c_str(), percent); + sprintf(temp_string, "Interface %s (%d%%):", netIfName.c_str(), percent); // progressbar ist in same line - so we not can use max_text_width frameBuffer->paintBoxRel(posx, posy - sheight, boxX - posx, sheight, COL_INFOBAR_PLUS_0); g_Font[font_small]->RenderString(posx, posy, boxX - posx, temp_string, COL_INFOBAR_TEXT); @@ -922,22 +929,22 @@ void CImageInfoNI::paint_NET_Info(int posx, int posy) pb.setValues(percent, 100); pb.paint(false); - posy+= sheight; + posy += sheight; - sprintf(temp_string,"Receive: %llu bit/s Transmit: %llu bit/s",(long long unsigned int)rbit_s,(long long unsigned int)wbit_s); + sprintf(temp_string, "Receive: %llu bit/s, Transmit: %llu bit/s", (long long unsigned int)rbit_s, (long long unsigned int)wbit_s); frameBuffer->paintBoxRel(posx, posy - sheight, max_text_width, sheight, COL_INFOBAR_PLUS_0); g_Font[font_small]->RenderString(posx, posy, max_text_width, temp_string, COL_INFOBAR_TEXT); - posy+= sheight; + posy += sheight; - sprintf(temp_string,"Maximal: %llu bit/s - %.2f MB/s (%d%%)",(long long unsigned int)net_best,net_best/(8.0*1024.0*1024.0),(int)((net_best*100)/max_bit)); + sprintf(temp_string, "Maximal: %llu bit/s - %.2f MB/s (%d%%)", (long long unsigned int)net_best, net_best / (8.0 * 1024.0 * 1024.0), (int)((net_best * 100) / max_bit)); frameBuffer->paintBoxRel(posx, posy - sheight, max_text_width, sheight, COL_INFOBAR_PLUS_0); g_Font[font_small]->RenderString(posx, posy, max_text_width, temp_string, COL_INFOBAR_TEXT); - last_tv.tv_sec = tv.tv_sec; - last_tv.tv_usec = tv.tv_usec; - read_old = read_akt; - write_old = write_akt; + last_tv.tv_sec = tv.tv_sec; + last_tv.tv_usec = tv.tv_usec; + read_old = read_akt; + write_old = write_akt; } std::string CImageInfoNI::getYWebVersion() diff --git a/src/gui/imageinfo_ni.h b/src/gui/imageinfo_ni.h index a758cf63f..8910537eb 100644 --- a/src/gui/imageinfo_ni.h +++ b/src/gui/imageinfo_ni.h @@ -35,8 +35,8 @@ class CImageInfoNI : public CMenuTarget { private: void Init(void); - CConfigFile * configfile; - CFrameBuffer *frameBuffer; + CConfigFile *configfile; + CFrameBuffer *frameBuffer; int x; int y; int ypos; @@ -44,13 +44,13 @@ class CImageInfoNI : public CMenuTarget int ycpu; int width; int height; - int hheight,iheight,sheight; + int hheight, iheight, sheight; int swidth; int max_height; int max_width; int max_text_width; - + neutrino_locale_t name; int offset; @@ -63,7 +63,8 @@ class CImageInfoNI : public CMenuTarget void paintLine(int xpos, int font, std::string text); void clearLine(int xpos, int font); - typedef struct { + typedef struct + { unsigned long usr; unsigned int nice; unsigned long system; @@ -74,14 +75,16 @@ class CImageInfoNI : public CMenuTarget unsigned long old_idle; } _stat; - struct { + struct + { unsigned long blocks; unsigned long used; unsigned long available; int percent; } image_size; - struct { + struct + { int total; int free; int buffers; @@ -90,7 +93,8 @@ class CImageInfoNI : public CMenuTarget int used; } mem_info; - struct S_MTD_INFO { + struct S_MTD_INFO + { char dev[8]; char size[9]; char erasesize[9]; @@ -104,10 +108,10 @@ class CImageInfoNI : public CMenuTarget uint64_t net_best; std::string netIfName; - pthread_t InfoThread; - static void* InfoProc(void *arg); - void StartInfoThread(); - void StopInfoThread(); + pthread_t InfoThread; + static void *InfoProc(void *arg); + void StartInfoThread(); + void StopInfoThread(); int systemfs; int revision; @@ -145,12 +149,11 @@ class CImageInfoNI : public CMenuTarget std::string getYWebVersion(); public: - CImageInfoNI(); ~CImageInfoNI(); void hide(); - int exec(CMenuTarget* parent, const std::string & actionKey); + int exec(CMenuTarget *parent, const std::string &actionKey); }; #endif