/* PIP - Platform Independent Primitives Remote console viewer Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com 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 3 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, see . */ #include "picli.h" #include "pisystemmonitor.h" #include "pisysteminfo.h" #include "file_manager.h" #include "daemon.h" #include "shared.h" class _Init { public: _Init() {srand(PISystemTime::current().toMicroseconds());} }; _Init _pisd_init; PIScreen screen(false); PISystemMonitor sys_mon; FileManager file_manager; Daemon daemon_; class MainMenu: public PIObject { PIOBJECT(MainMenu) public: MainMenu() { TileSimple * tile = new TileSimple("title"); tile->content << TileSimple::Row("pisd (PI System Daemon, PIP version " + PIPVersion() + ")", CellFormat(Black, Transparent)); tile->back_format.color_back = Yellow; tile->size_policy = Fixed; screen.rootTile()->addTile(tile); PIScreenTile * center = new PIScreenTile("center"); center->back_format.color_back = Cyan; center->size_policy = Expanding; center->setMargins(2, 2, 1, 1); screen.rootTile()->addTile(center); PIScreenTile * mt = tmenu = menuTile(); mt->show(); mt->name = "main menu"; center->addTile(mt); mtiles << mt; mt = tinfo = infoTile(); mt->hide(); mt->name = "local info"; center->addTile(mt); mtiles << mt; mt = tfm = file_manager.tile(); mt->hide(); mt->name = "file manager"; center->addTile(mt); mtiles << mt; mt = tdaemon = daemon_.tile(); mt->hide(); mt->name = "daemon"; center->addTile(mt); mtiles << mt; CONNECTU(&screen, tileEvent, this, tileEvent) CONNECTU(&screen, keyPressed, this, keyEvent) CONNECTU(&file_manager, menuRequest, this, menuRequest) CONNECTU(&daemon_, menuRequest, this, menuRequest) } PIScreenTile * menuTile() { TileList * ret = new TileList(); ret->content << TileList::Row("Show local info", CellFormat()); ret->content << TileList::Row("Local file manager", CellFormat()); ret->content << TileList::Row("Connect to another daemon", CellFormat()); ret->selection_mode = TileList::NoSelection; return ret; } PIScreenTile * infoTile() { TileSimple * ret = new TileSimple(); ret->content << TileSimple::Row("Exec command: " + PISystemInfo::instance()->execCommand, CellFormat()); ret->content << TileSimple::Row(" Executed on " + PISystemInfo::instance()->execDateTime.toString(), CellFormat()); ret->content << TileSimple::Row(" Hostname: " + PISystemInfo::instance()->hostname, CellFormat()); ret->content << TileSimple::Row(" Username: " + PISystemInfo::instance()->user, CellFormat()); ret->content << TileSimple::Row(" OS name: " + PISystemInfo::instance()->OS_name, CellFormat()); ret->content << TileSimple::Row(" OS version: " + PISystemInfo::instance()->OS_version, CellFormat()); ret->content << TileSimple::Row("Architecture: " + PISystemInfo::instance()->architecture, CellFormat()); ret->content << TileSimple::Row(" CPU count: " + PIString::fromNumber(PISystemInfo::instance()->processorsCount), CellFormat()); return ret; } EVENT_HANDLER(void, menuRequest) { piForeach (PIScreenTile * t, mtiles) t->hide(); tmenu->show(); tmenu->setFocus(); } EVENT_HANDLER2(void, tileEvent, PIScreenTile *, t, PIScreenTypes::TileEvent, e) { if (t == tmenu) { if (e.type == TileList::RowPressed) { piForeach (PIScreenTile * t, mtiles) t->hide(); switch (e.data.toInt()) { case 0: tinfo->show(); break; case 1: tfm->show(); break; case 2: tdaemon->show(); break; } } return; } } EVENT_HANDLER1(void, keyEvent, PIKbdListener::KeyEvent, e) { if (e.key == PIKbdListener::Esc) menuRequest(); //piCout << "key" << e.key; } PIScreenTile * tmenu, * tinfo, * tfm, * tdaemon; PIVector mtiles; }; void tabMenu() { /*startTab(); console.addString("Select with numeric key:"); console.addString(" 0 - this screen"); console.addString(" 1 - show host info"); console.addString(" 2 - local file manager"); console.addString(" 3 - connect to another daemon"); finishTab();*/ } void tabInfo() { /*startTab(); console.addString("Exec command: " + PISystemInfo::instance()->execCommand); console.addString(" Executed on " + PISystemInfo::instance()->execDateTime.toString()); console.addString(" Hostname: " + PISystemInfo::instance()->hostname); console.addString(" Username: " + PISystemInfo::instance()->user); console.addString(" OS name: " + PISystemInfo::instance()->OS_name); console.addString(" OS version: " + PISystemInfo::instance()->OS_version); console.addString("Architecture: " + PISystemInfo::instance()->architecture); console.addString(" CPU count: " + PIString::fromNumber(PISystemInfo::instance()->processorsCount)); console.addVariable("of this process", &sys_mon, 2); finishTab();*/ } void tabConnect() { } #include int main(int argc, char * argv[]) { /*PICRC<16> crc(0xFF12FF34); PIByteArray ba(4096); for (int i = 0; i < ba.size_s(); ++i) ba[i] = i % 256; PITimeMeasurer tm; uint_cl<16> ret; for (int i = 0; i < 1000; ++i) { ret = crc.calculate(ba); }*/ /*if (argc < 2) return 0; PIFile af; if (!af.open(argv[1], PIIODevice::ReadOnly)) return 0; piCout << "open" << af.path(); PIByteArray sign, jfif, rsign, rdata; int phase = 0, pos = 0, asize = af.size(); ushort jct = 0, jcl = 0; uint ct = 0, cl = 0, cc = 0, tend = 1229278788; sign << uchar(0x89) << uchar(0x50) << uchar(0x4E) << uchar(0x47) << uchar(0x0D) << uchar(0x0A) << uchar(0x1A) << uchar(0x0A); jfif << uchar(0x4A) << uchar(0x46) << uchar(0x49) << uchar(0x46); rsign.resize(sign.size()); PIByteArray nf; PITimeMeasurer tm; int cnt = 0, j = 0; while (!af.isEnd()) { if (tm.elapsed_m() >= 500) { tm.reset(); piCout << "readed" << PIString::readableSize(af.pos()); } if (pos >= asize) break; switch (phase) { case 0: af.seek(pos); af.read(rsign.data(), rsign.size_s()); if (rsign == sign) { phase = 1; nf = rsign; } else if (rsign.resized(4) == jfif) { phase = 2; af.seek(pos - 6); nf.resize(2); af.read(nf.data(), nf.size_s()); } else pos++; break; case 1: af.read(&cl, 4); af.read(&ct, 4); rdata.resize(piLetobe(cl)); af.read(rdata.data(), rdata.size_s()); af.read(&cc, 4); nf.append(&cl, 4); nf.append(&ct, 4); nf.append(rdata); nf.append(&cc, 4); if (piLetobe(ct) == tend) { piCout << "found PNG size" << PIString::readableSize(nf.size_s()); PIFile wf("./PNG/" + PIString(cnt++) + ".png"); if (wf.open(PIIODevice::ReadWrite)) wf.write(nf.data(), nf.size()); nf.clear(); phase = 0; pos = af.pos(); } break; case 2: //jct = 0; //while (jct != ushort(0xD9FF)) { // af.read(&jct, 2); // nf.append(&jct, 2); //} //if (++j >= 30) return 0; af.read(&jct, 2); nf.append(&jct, 2); if (jct == ushort(0xD9FF)) { piCout << "found JPG size" << PIString::readableSize(nf.size_s()); PIFile wf("./PNG/" + PIString(cnt++) + ".jpg"); if (wf.open(PIIODevice::ReadWrite)) wf.write(nf.data(), nf.size()); nf.clear(); phase = 0; pos = af.pos(); break; } af.read(&jcl, 2); nf.append(&jcl, 2); if (jct == 0xDAFF) { jct = 0; int pp = af.pos(); rdata.resize(1024*1024*3); af.read(rdata.data(), rdata.size_s()); nf.append(rdata); //while (jct != ushort(0xFFD9)) { // af.read(&jct, 2); // nf.append(&jct, 2); // //piCout << Hex << jct; //} piCout << "found JPG size" << PIString::readableSize(nf.size_s()); PIFile wf("./PNG/" + PIString(cnt++) + ".jpg"); if (wf.open(PIIODevice::ReadWrite)) wf.write(nf.data(), nf.size()); nf.clear(); phase = 0; pos = pp + 1; break; } //piCout << "length" << piLetobe(jcl); rdata.resize(piLetobe(jcl) - 2); af.read(rdata.data(), rdata.size_s()); nf.append(rdata); break; }; }; return 0;*/ //piCout << Hex << uint(ret) << tm.elapsed_m(); piDebug = false; PICLI cli(argc, argv); //cli.addArgument(""); sys_mon.startOnSelf(); screen.enableExitCapture(PIKbdListener::F10); MainMenu menu; screen.start(); screen.waitForFinish(); //return 0; /*while (!PIKbdListener::exiting) { if (oldmode != mode) { file_manager.disable(); daemon_.disable(); oldmode = mode; switch (mode) { case 0: /// menu tabMenu(); break; case 1: /// host info tabInfo(); break; case 2: /// file manager file_manager.enable(); break; case 3: /// daemon daemon_.enable(); break; } } piMSleep(100); }*/ return 0; };