git-svn-id: svn://db.shs.com.ru/pip@239 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include "picrypt.h"
|
||||
|
||||
const char self_name[] = "__self__";
|
||||
extern PIScreen screen;
|
||||
extern PIScreen * screen;
|
||||
//bool Daemon::inited__ = false;
|
||||
|
||||
Daemon::Remote::Remote(const PIString & n): PIThread() {
|
||||
@@ -105,20 +105,20 @@ Daemon::TileFileProgress::TileFileProgress(): PIScreenTile() {
|
||||
addTile(prog_file);
|
||||
addTile(prog_all);
|
||||
addTile(buttons);
|
||||
CONNECTU(&(::screen), tileEvent, this, tileEvent)
|
||||
CONNECTU((::screen), tileEvent, this, tileEvent)
|
||||
}
|
||||
|
||||
|
||||
void Daemon::TileFileProgress::resizeEvent(int w, int h) {
|
||||
PIScreenTile::resizeEvent(w, h);
|
||||
w = ::screen.windowWidth() / 1.4;
|
||||
w = ::screen->windowWidth() / 1.4;
|
||||
minimumWidth = maximumWidth = w;
|
||||
}
|
||||
|
||||
|
||||
void Daemon::TileFileProgress::sizeHint(int & w, int & h) const {
|
||||
PIScreenTile::sizeHint(w, h);
|
||||
w = ::screen.windowWidth() / 1.4;
|
||||
w = ::screen->windowWidth() / 1.4;
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ void Daemon::TileFileProgress::show(PIFileTransfer * f) {
|
||||
ft = f;
|
||||
if (ft) {
|
||||
conn_name = ft->name();
|
||||
::screen.setDialogTile(this);
|
||||
::screen->setDialogTile(this);
|
||||
label_file->content[0].first = "Preparing ...";
|
||||
prog_file->value = prog_all->value = 0;
|
||||
buttons->cur = 0;
|
||||
@@ -177,7 +177,7 @@ void Daemon::TileFileProgress::show(PIFileTransfer * f) {
|
||||
void Daemon::TileFileProgress::close(bool ok) {
|
||||
buttons->content[0].first = "Pause";
|
||||
ft = 0;
|
||||
::screen.setDialogTile(0);
|
||||
::screen->setDialogTile(0);
|
||||
if (!ok) {
|
||||
piCout << "Achtung! Alarm!! Error!!!";
|
||||
showInfo("Error while files transfer...");
|
||||
@@ -210,7 +210,7 @@ Daemon::Daemon(): inited__(false), PIPeer(pisd_prefix + PISystemInfo::instance()
|
||||
// setName("Daemon");
|
||||
dtimer.setName("__S__Daemon_timer");
|
||||
mode = offset = cur = height = 0;
|
||||
CONNECTU(&screen, keyPressed, this, keyEvent)
|
||||
CONNECTU(screen, keyPressed, this, keyEvent)
|
||||
CONNECTU(&dtimer, tickEvent, this, timerEvent)
|
||||
CONNECTU(&fm, tileKey, this, fmKeyEvent)
|
||||
CONNECTU(&fm, actionRequest, this, fmActionRequest)
|
||||
@@ -259,7 +259,7 @@ Daemon::Daemon(): inited__(false), PIPeer(pisd_prefix + PISystemInfo::instance()
|
||||
tile_root->addTile(tile_info);
|
||||
tile_root->addTile(tile_fm);
|
||||
|
||||
CONNECTU(&screen, tileEvent, this, tileEvent)
|
||||
CONNECTU(screen, tileEvent, this, tileEvent)
|
||||
reinit();
|
||||
inited__ = true;
|
||||
}
|
||||
@@ -317,7 +317,7 @@ void Daemon::showTile(PIScreenTile * t, const PIString & header) {
|
||||
|
||||
|
||||
void Daemon::fillInfoTile(const Daemon::HostInfo & hi) {
|
||||
screen.lock();
|
||||
screen->lock();
|
||||
tile_info->content.clear();
|
||||
tile_info->content << TileSimple::Row("Exec command: " + hi.execCommand, CellFormat());
|
||||
tile_info->content << TileSimple::Row(" Executed on " + hi.execDateTime.toString(), CellFormat());
|
||||
@@ -327,7 +327,7 @@ void Daemon::fillInfoTile(const Daemon::HostInfo & hi) {
|
||||
tile_info->content << TileSimple::Row(" OS version: " + hi.OS_version, CellFormat());
|
||||
tile_info->content << TileSimple::Row("Architecture: " + hi.architecture, CellFormat());
|
||||
tile_info->content << TileSimple::Row(" CPU count: " + PIString::fromNumber(hi.processorsCount), CellFormat());
|
||||
screen.unlock();
|
||||
screen->unlock();
|
||||
}
|
||||
|
||||
|
||||
@@ -360,7 +360,7 @@ void Daemon::tileEvent(PIScreenTile * t, TileEvent e) {
|
||||
|
||||
void Daemon::keyEvent(PIKbdListener::KeyEvent key) {
|
||||
if (!tile_root->visible) return;
|
||||
if (screen.dialogTile()) return;
|
||||
if (screen->dialogTile()) return;
|
||||
switch (key.key) {
|
||||
case PIKbdListener::Esc:
|
||||
if (mode == 0)
|
||||
@@ -368,9 +368,9 @@ void Daemon::keyEvent(PIKbdListener::KeyEvent key) {
|
||||
else {
|
||||
if (mode > 1) {
|
||||
mode = 1;
|
||||
screen.lock();
|
||||
screen->lock();
|
||||
tile_info->content.clear();
|
||||
screen.unlock();
|
||||
screen->unlock();
|
||||
showActionList();
|
||||
} else
|
||||
disconnect();
|
||||
@@ -472,12 +472,12 @@ void Daemon::fmActionRequest(bool remote_tile, FileManager::Action type, PIVaria
|
||||
|
||||
|
||||
void Daemon::timerEvent(void * _d, int delim) {
|
||||
screen.lock();
|
||||
screen->lock();
|
||||
list_daemons->content.clear();
|
||||
availableDaemons();
|
||||
piForeachC (PIString & i, available_daemons)
|
||||
list_daemons->content << TileList::Row(i, CellFormat());
|
||||
screen.unlock();
|
||||
screen->unlock();
|
||||
if (delim == 5 && mode == 2) {
|
||||
if (conn_name.isEmpty()) return;
|
||||
PIByteArray ba; ba << int(RequestHostInfo);
|
||||
|
||||
@@ -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