git-svn-id: svn://db.shs.com.ru/pip@239 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
PIp System Daemon
|
||||
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
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
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "picli.h"
|
||||
#include "pisystemmonitor.h"
|
||||
#include "pisysteminfo.h"
|
||||
#include "piprocess.h"
|
||||
#include "file_manager.h"
|
||||
#include "daemon.h"
|
||||
#include "shared.h"
|
||||
@@ -30,28 +31,27 @@ public:
|
||||
};
|
||||
_Init _pisd_init;
|
||||
|
||||
PIScreen screen(false);
|
||||
PISystemMonitor sys_mon;
|
||||
Daemon daemon_;
|
||||
PIScreen * screen = 0;
|
||||
//FileManager file_manager;
|
||||
|
||||
|
||||
class MainMenu: public PITimer {
|
||||
PIOBJECT_SUBCLASS(MainMenu, PITimer)
|
||||
public:
|
||||
MainMenu() {
|
||||
MainMenu(Daemon & d): daemon_(d) {
|
||||
cur_peer = -1;
|
||||
title = new TileSimple("title");
|
||||
updateTitle(title);
|
||||
title->back_format.color_back = Yellow;
|
||||
title->size_policy = Fixed;
|
||||
screen.rootTile()->addTile(title);
|
||||
screen->rootTile()->addTile(title);
|
||||
|
||||
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);
|
||||
screen->rootTile()->addTile(center);
|
||||
|
||||
PIScreenTile * mt = tmenu = menuTile();
|
||||
mt->show(); mt->name() = "main menu";
|
||||
@@ -79,10 +79,10 @@ public:
|
||||
|
||||
TilePICout * outt = new TilePICout();
|
||||
outt->size_policy = PIScreenTypes::Expanding;
|
||||
screen.rootTile()->addTile(outt);
|
||||
screen->rootTile()->addTile(outt);
|
||||
|
||||
CONNECTU(&screen, tileEvent, this, tileEvent)
|
||||
CONNECTU(&screen, keyPressed, this, keyEvent)
|
||||
CONNECTU(screen, tileEvent, this, tileEvent)
|
||||
CONNECTU(screen, keyPressed, this, keyEvent)
|
||||
CONNECTU(&daemon_.fm, menuRequest, this, menuRequest)
|
||||
CONNECTU(&daemon_, menuRequest, this, menuRequest)
|
||||
start(10);
|
||||
@@ -168,7 +168,7 @@ public:
|
||||
}
|
||||
void updatePeerInfo() {
|
||||
bool pm = daemon_.lockedPeers();
|
||||
screen.lock();
|
||||
screen->lock();
|
||||
daemon_.lock();
|
||||
peers_tl->content.clear();
|
||||
addrs_tl->content.clear();
|
||||
@@ -206,7 +206,7 @@ public:
|
||||
updatePeerDiag(peerdiagdata_tl, daemon_.diagnosticData());
|
||||
updatePeerDiag(peerdiagservice_tl, daemon_.diagnosticService());
|
||||
daemon_.unlock();
|
||||
screen.unlock();
|
||||
screen->unlock();
|
||||
}
|
||||
void tick(void* data_, int delimiter) {
|
||||
updatePeerInfo();
|
||||
@@ -249,11 +249,12 @@ public:
|
||||
PIKbdListener::exiting = true;
|
||||
return;
|
||||
}
|
||||
if (screen.dialogTile()) return;
|
||||
if (screen->dialogTile()) return;
|
||||
if (tpeer->visible || tinfo->visible || tpeerdiag->visible)
|
||||
if (e.key == PIKbdListener::Esc) menuRequest();
|
||||
//piCout << "key" << e.key;
|
||||
}
|
||||
Daemon & daemon_;
|
||||
PIScreenTile * tmenu, * tinfo, * tfm, * tdaemon, * tpeer, * tpeerdiag;
|
||||
TileList * peers_tl, * addrs_tl, * peermap_tl;
|
||||
TileSimple * title;
|
||||
@@ -264,15 +265,52 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
void usage() {
|
||||
piCout << PICoutManipulators::Bold << "PIP System Daemon";
|
||||
piCout << PICoutManipulators::Cyan << "Version" << PICoutManipulators::Bold << PIPVersion() << PICoutManipulators::NewLine;
|
||||
piCout << PICoutManipulators::Green << PICoutManipulators::Bold << "Usage:" << PICoutManipulators::Default
|
||||
<< "\"pisd [-hdf] [-n <name>]\"" << PICoutManipulators::NewLine;
|
||||
piCout << PICoutManipulators::Green << PICoutManipulators::Bold << "Details:";
|
||||
piCout << "-h --help " << PICoutManipulators::Green << "- display this message and exit";
|
||||
piCout << "-d --daemon " << PICoutManipulators::Green << "- start as daemon";
|
||||
piCout << "-f --force " << PICoutManipulators::Green << "- don`t check for another running instance";
|
||||
piCout << "-n --name <name> " << PICoutManipulators::Green << "- set daemon name";
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
//piDebug = false;
|
||||
PICLI cli(argc, argv);
|
||||
cli.addArgument("help");
|
||||
cli.addArgument("daemon");
|
||||
cli.addArgument("force");
|
||||
cli.addArgument("name", true);
|
||||
if (cli.hasArgument("help")) {
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
PIString name = cli.argumentValue("name");
|
||||
if (cli.hasArgument("daemon")) {
|
||||
PIStringList args;
|
||||
if (cli.hasArgument("force"))
|
||||
args << "-f";
|
||||
if (!name.isEmpty())
|
||||
args << "-n" << name;
|
||||
PIProcess::execIndependent(PISystemInfo::instance()->execCommand, args);
|
||||
return 0;
|
||||
}
|
||||
PIINTROSPECTION_START
|
||||
//cli.addArgument("");
|
||||
screen = new PIScreen(false);
|
||||
Daemon daemon_;
|
||||
sys_mon.startOnSelf();
|
||||
screen.enableExitCapture(PIKbdListener::F10);
|
||||
MainMenu menu;
|
||||
screen.start();
|
||||
screen.waitForFinish();
|
||||
screen->enableExitCapture(PIKbdListener::F10);
|
||||
if (!name.isEmpty())
|
||||
daemon_.changeName(pisd_prefix + name);
|
||||
MainMenu menu(daemon_);
|
||||
screen->start();
|
||||
screen->waitForFinish();
|
||||
delete screen;
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user