diff --git a/PCiNooB.cbp b/PCiNooB.cbp new file mode 100644 index 0000000..8eb1fab --- /dev/null +++ b/PCiNooB.cbp @@ -0,0 +1,47 @@ + + + + + + diff --git a/PCiNooB.depend b/PCiNooB.depend new file mode 100644 index 0000000..870e9a1 --- /dev/null +++ b/PCiNooB.depend @@ -0,0 +1,32 @@ +# depslib dependency file v1.0 +1586447065 source:/home/imshakil/Desktop/GTKApplication/PCiNooB/main.cpp + "main.h" + "SystemAnalyzer.h" + + + + + + + +1586317279 /home/imshakil/Desktop/GTKApplication/PCiNooB/main.h + + + + + + +1586445915 /home/imshakil/Desktop/GTKApplication/PCiNooB/SystemAnalyzer.h + + "uptime.h" + + +1586412187 /home/imshakil/Desktop/GTKApplication/PCiNooB/uptime.h + + + + + + + + diff --git a/PCiNooB.layout b/PCiNooB.layout new file mode 100644 index 0000000..09534b8 --- /dev/null +++ b/PCiNooB.layout @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/SystemAnalyzer.h b/SystemAnalyzer.h new file mode 100644 index 0000000..f81584e --- /dev/null +++ b/SystemAnalyzer.h @@ -0,0 +1,202 @@ +#include +#include "uptime.h" +#include + +using namespace std; + +/** Created a System Class **/ + +class SystemAnalyzer{ + +public: + + /** Get Device Information **/ + + string GetInformationFromCommand(string cmdline) { + string data; + FILE * stream; + const int max_buffer = 256; + char buffer[max_buffer]; + + stream = popen(cmdline.c_str(), "r"); + if (stream) { + while (!feof(stream)) + if (fgets(buffer, max_buffer, stream) != NULL) data.append(buffer); + pclose(stream); + } + return data; + } + + void GetDeviceInfo() + { + freopen("Device.info", "w", stdout); + + string ItemsName[] = { "BIOS Version\t\t: ", "BIOS Vendor\t\t: ", "Release Date\t\t: ", + "Motherboard Name\t: ", "Motherboard Vendor\t: ", "Motherboard Versions\t: ", + "Product\t\t\t: ", "Product Name\t\t: ", "Product Version\t\t: ", "System Vendor\t\t: "}; + + string ItemsPath[] = {"/sys/class/dmi/id/bios_version", "/sys/class/dmi/id/bios_vendor", "/sys/class/dmi/id/bios_date", + "/sys/class/dmi/id/board_name", "/sys/class/dmi/id/board_vendor", "/sys/class/dmi/id/board_version", + "/sys/class/dmi/id/product_sku", "/sys/class/dmi/id/product_name", "/sys/class/dmi/id/product_version", "/sys/class/dmi/id/sys_vendor"}; + + for(int i=0; i<10; i++) + { + ifstream ifs (ItemsPath[i], ifstream::in); + + string line; + while(getline(ifs, line)) cout<3) break; + } + + fclose(stdout); + } + + /** Get Hard Disk Information **/ + + void GetHDDInfo() + { + freopen("HardDisk.info", "w", stdout); + + string ptype[2] = {"GPT", "MBR"}; /// Hard disk partition style + string hddNames[] = {"Disk Model\t: ", "Vendor\t\t: ", "Size\t\t: ", "Version\t\t: ", "Partitioned\t: "}; /// hard disk hardware information + string hddItems[] = {"/sys/block/sda/device/model", "/sys/block/sda/device/vendor", "/sys/block/sda/size", "/sys/block/sda/device/rev", "/sys/block/sda/device/type"}; + string Size[] = {" KB", " MB", " GB", " TB"}; + + for(int i=0; i<5; i++) + { + ifstream ifs (hddItems[i], ifstream::in); + string line; + while(getline(ifs, line)) + { + if(i==2) { + int sz = stoi(line)/2; + cout<> major >> minor >> block >> name; + + int sz = stoi(block); + int cnt = 0; + while(sz>1024) + { + sz /= 1024; + cnt++; + } + if(name.length()==3) name+="0"; + + cout<5) break; + } + + vector entries1; + vector entries2; + + ReadStatsCPU(entries1); + + this_thread::sleep_for(chrono::milliseconds(100)); + + ReadStatsCPU(entries2); + + cout<<"\nControl Processing Unit Uptime\n\n"; + PrintStats(entries1, entries2); + + } + + + /** Get Graphics Processor Unit Information **/ + + void GetGPUInfo() + { + freopen("GPU.info", "w", stdout); + + string ot = GetInformationFromCommand("lspci"); /// get a list of PCI associate with the PC + cout< +#include +#include +#include +#include +#include +using namespace std; + +int minWidth = 650, minHeight = 450; /// Application Window Size + +Fl_Double_Window *window_main=(Fl_Double_Window *)0; + +Fl_Button *btnTest=(Fl_Button *)0; + +Fl_Return_Button *btnClose=(Fl_Return_Button *)0; + + +/** Method to create an object of + SystemAnalyzer Class to call + each method and store information + into text files + **/ + +void GenarateInformation() +{ + SystemAnalyzer sysinfo; + sysinfo.GetCPUInfo(); + sysinfo.GetDeviceInfo(); + sysinfo.GetGPUInfo(); + sysinfo.GetHDDInfo(); + sysinfo.GetMemInfo(); +} + +/** Custom Method to load + information using text buffer + and display in monitor + **/ + +void LoadInformation(char *File) +{ + Fl_Text_Buffer *buff = new Fl_Text_Buffer(); + Fl_Text_Display *disp = new Fl_Text_Display(20, 35, 580, 350); + disp->buffer(buff); + buff->loadfile(File); +} + +void SetWaterMark() +{ + Fl_Box *box = new Fl_Box(0, minHeight-30,100,20,"PC i NooB ~ https://github.com/imshakil/"); + box->labelcolor(FL_DARK_CYAN); +} + +/** Button callback to display new window + with Tabs & specific Device Information. + Created an object of SystemAnalyzer class + to call each method + **/ + +void bt_callback(Fl_Widget*, void* userdata) { + + if(userdata == "test") { + + GenarateInformation(); /// Stored Information in text files. + this_thread::sleep_for(chrono::microseconds(2000)); + + Fl_Window* adw = new Fl_Window (minWidth, minHeight, "PCiNooB - Hardware Information"); /// Added Window + + adw->align(FL_ALIGN_CENTER); + + Fl_Tabs *tabs = new Fl_Tabs(10,0,600,400); + tabs->selection_color(FL_DARK3); + { + Fl_Group *grp0 = new Fl_Group(20, 30, 280, 450, "Device"); + { + LoadInformation("Device.info"); /// loaded information from text file + } + grp0->end(); /// tabs1 ended here + + Fl_Group *grp1 = new Fl_Group(20,30,280,450,"CPU Information"); + { + LoadInformation("CPU.info"); /// loaded information from text file + } + grp1->end(); /// tabs2 ended here + + Fl_Group *grp2 = new Fl_Group(20,30,280,450,"HDD Information"); + { + LoadInformation("HardDisk.info"); /// loaded information from text file + } + grp2->end(); /// tabs3 ended here + + Fl_Group *grp3 = new Fl_Group(20,30,280,450,"Memory Information"); + { + LoadInformation("Memory.info"); /// loaded information from text file + } + grp3->end(); /// tabs4 ended here + + Fl_Group *grp4 = new Fl_Group(20,30,280,450,"GPU Information"); + { + LoadInformation("GPU.info"); ///loaded information from text file + } + grp4->end(); + } + tabs->end(); /// tabs ended here + + SetWaterMark(); /// my github link + adw->show(); /// Display new Window with list of tabs + } +else if (userdata == "close") + exit(0); /// close program with exit button +} + + +/** Main Function of this Application**/ + +int main(int argc, char **argv) { + + Fl_Double_Window* w; + { + Fl_Double_Window* o = window_main = new Fl_Double_Window(minWidth, minHeight, "PCiNooB - PC Configuration"); + w = o; + o->align(FL_ALIGN_CENTER); + { + Fl_Box *box = new Fl_Box(minWidth/2-130,40,260,100,"PC i NooB"); + box->box(FL_UP_BOX); + box->labelsize(36); + box->labelfont(FL_BOLD+FL_ITALIC); + box->labeltype(FL_SHADOW_LABEL); + } + { Fl_Button* o = btnTest = new Fl_Button(minWidth/2 - 80, minHeight/2-40, 160, 40, "Get PC Specification"); /// centralized button in window + o->callback((Fl_Callback*)bt_callback, (void*)("test")); + } + { Fl_Return_Button* o = btnClose = new Fl_Return_Button(minWidth/2-50, minHeight/2+20, 100, 40, "Exit"); /// centralized button in window + o->callback((Fl_Callback*)bt_callback, (void*)("close")); + } + + { + SetWaterMark(); + } + + o->end(); + } + w->show(argc, argv); + return Fl::run(); +} diff --git a/main.fld b/main.fld new file mode 100644 index 0000000..1e46e97 --- /dev/null +++ b/main.fld @@ -0,0 +1,42 @@ +# data file for the Fltk User Interface Designer (fluid) +version 1.0304 +header_name {.h} +code_name {.cpp} +decl {\#include } {private local +} + +Function {bt_callback(Fl_Widget*, void* userdata)} {open return_type {static void} +} { + code {if(userdata == "test") + std::cout << "Testing" << std::endl; +else if (userdata == "close") + exit(0);} {} + Fl_Window {} {open selected + xywh {327 156 650 450} type Double hide + } {} +} + +Function {} {open +} { + Fl_Window window_main { + label {FLTK window} open + xywh {415 203 650 450} type Double box THIN_DOWN_BOX color 26 selection_color 70 labelsize 18 labelcolor 60 align 80 visible + } { + Fl_Input input { + label {Please enter value:} + xywh {145 10 150 25} + } + Fl_Button btnTest { + label Test + user_data {"test"} + callback bt_callback + xywh {10 100 100 25} + } + Fl_Return_Button btnClose { + label Close + user_data {"close"} + callback bt_callback + xywh {195 100 100 25} + } + } +} diff --git a/main.h b/main.h new file mode 100644 index 0000000..d23c852 --- /dev/null +++ b/main.h @@ -0,0 +1,17 @@ +// generated by Fast Light User Interface Designer (fluid) version 1.0107 + +#ifndef main_h +#define main_h +#include +void bt_callback(Fl_Widget*, void* userdata); +#include +extern Fl_Double_Window *window_main; +#include +extern Fl_Input *input; +#include +extern void bt_callback(Fl_Button*, void*); +extern Fl_Button *btnTest; +#include +extern void bt_callback(Fl_Return_Button*, void*); +extern Fl_Return_Button *btnClose; +#endif diff --git a/main.o b/main.o new file mode 100644 index 0000000..fc7c81e Binary files /dev/null and b/main.o differ diff --git a/uptime.h b/uptime.h new file mode 100644 index 0000000..6dc411a --- /dev/null +++ b/uptime.h @@ -0,0 +1,123 @@ + +#include +#include +#include +#include +#include +#include +#include + +const int NUM_CPU_STATES = 10; + +enum CPUStates +{ + S_USER = 0, + S_NICE, + S_SYSTEM, + S_IDLE, + S_IOWAIT, + S_IRQ, + S_SOFTIRQ, + S_STEAL, + S_GUEST, + S_GUEST_NICE +}; + +typedef struct CPUData +{ + std::string cpu; + size_t times[NUM_CPU_STATES]; +} CPUData; + +void ReadStatsCPU(std::vector & entries); + +size_t GetIdleTime(const CPUData & e); +size_t GetActiveTime(const CPUData & e); + +void PrintStats(const std::vector & entries1, const std::vector & entries2); + +void ReadStatsCPU(std::vector & entries) +{ + std::ifstream fileStat("/proc/stat"); + + std::string line; + + const std::string STR_CPU("cpu"); + const std::size_t LEN_STR_CPU = STR_CPU.size(); + const std::string STR_TOT("tot"); + + while(std::getline(fileStat, line)) + { + // cpu stats line found + if(!line.compare(0, LEN_STR_CPU, STR_CPU)) + { + std::istringstream ss(line); + + // store entry + entries.emplace_back(CPUData()); + CPUData & entry = entries.back(); + + // read cpu label + ss >> entry.cpu; + + // remove "cpu" from the label when it's a processor number + if(entry.cpu.size() > LEN_STR_CPU) + entry.cpu.erase(0, LEN_STR_CPU); + // replace "cpu" with "tot" when it's total values + else + entry.cpu = STR_TOT; + + // read times + for(int i = 0; i < NUM_CPU_STATES; ++i) + ss >> entry.times[i]; + } + } +} + +size_t GetIdleTime(const CPUData & e) +{ + return e.times[S_IDLE] + + e.times[S_IOWAIT]; +} + +size_t GetActiveTime(const CPUData & e) +{ + return e.times[S_USER] + + e.times[S_NICE] + + e.times[S_SYSTEM] + + e.times[S_IRQ] + + e.times[S_SOFTIRQ] + + e.times[S_STEAL] + + e.times[S_GUEST] + + e.times[S_GUEST_NICE]; +} + +void PrintStats(const std::vector & entries1, const std::vector & entries2) +{ + const size_t NUM_ENTRIES = entries1.size(); + + for(size_t i = 0; i < NUM_ENTRIES; ++i) + { + const CPUData & e1 = entries1[i]; + const CPUData & e2 = entries2[i]; + + std::cout.width(3); + std::cout << e1.cpu << "] "; + + const float ACTIVE_TIME = static_cast(GetActiveTime(e2) - GetActiveTime(e1)); + const float IDLE_TIME = static_cast(GetIdleTime(e2) - GetIdleTime(e1)); + const float TOTAL_TIME = ACTIVE_TIME + IDLE_TIME; + + std::cout << "active: "; + std::cout.setf(std::ios::fixed, std::ios::floatfield); + std::cout.width(6); + std::cout.precision(2); + std::cout << (100.f * ACTIVE_TIME / TOTAL_TIME) << "%"; + + std::cout << " - idle: "; + std::cout.setf(std::ios::fixed, std::ios::floatfield); + std::cout.width(6); + std::cout.precision(2); + std::cout << (100.f * IDLE_TIME / TOTAL_TIME) << "%" << std::endl; + } +}