Files
pip/utils/system_daemon/main.cpp
Бычков Андрей 3beb3cf8bf add Exit to pisd
git-svn-id: svn://db.shs.com.ru/pip@16 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
2015-03-12 08:47:07 +00:00

190 lines
6.2 KiB
C++
Executable File

/*
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 <http://www.gnu.org/licenses/>.
*/
#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->content << TileList::Row("Exit", 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;
case 3: PIKbdListener::exiting = true; 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<PIScreenTile * > 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() {
}
int main(int argc, char * argv[]) {
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;
};