From 42afbb11b77809d21ead5c06e8792260f458d4c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Thu, 9 Apr 2015 08:26:58 +0000 Subject: [PATCH] TimerPool fixoutManipulator git-svn-id: svn://db.shs.com.ru/pip@80 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- CMakeLists.txt | 2 +- src/io/pibasetransfer.cpp | 3 +- src/io/pibasetransfer.h | 8 ++- src/io/pifiletransfer.cpp | 12 ++-- utils/system_daemon/daemon.cpp | 111 +++++++++++++++------------------ utils/system_daemon/daemon.h | 11 ++-- 6 files changed, 69 insertions(+), 78 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b28cf09..f27f5880 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ project(pip) cmake_minimum_required(VERSION 2.6) -#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3") include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) include(CheckFunctionExists) diff --git a/src/io/pibasetransfer.cpp b/src/io/pibasetransfer.cpp index 1cae4672..cc116f3b 100644 --- a/src/io/pibasetransfer.cpp +++ b/src/io/pibasetransfer.cpp @@ -21,9 +21,8 @@ PIBaseTransfer::PIBaseTransfer(): crc(standardCRC_16()), diag(false) { PIBaseTransfer::~PIBaseTransfer() { + diag.stop(); break_ = true; - session.clear(); - replies.clear(); } diff --git a/src/io/pibasetransfer.h b/src/io/pibasetransfer.h index f1a994a1..34d4dad1 100644 --- a/src/io/pibasetransfer.h +++ b/src/io/pibasetransfer.h @@ -52,6 +52,11 @@ public: const llong * bytesCur_ptr() const {return &bytes_cur;} const PIDiagnostics &diagnostic() {return diag;} + EVENT_HANDLER1(void, received, PIByteArray, data); + EVENT_HANDLER(void, stop) {stopSend(); stopReceive();} + EVENT_HANDLER(void, pause) {setPause(true);} + EVENT_HANDLER(void, resume) {setPause(false);} + EVENT(receiveStarted) EVENT(paused) EVENT(resumed) @@ -59,9 +64,6 @@ public: EVENT(sendStarted) EVENT1(sendFinished, bool, ok) EVENT1(sendRequest, PIByteArray &, data) - EVENT_HANDLER1(void, received, PIByteArray, data); - EVENT_HANDLER(void, pause) {setPause(true);} - EVENT_HANDLER(void, resume) {setPause(false);} protected: uint packet_header_size, part_header_size; diff --git a/src/io/pifiletransfer.cpp b/src/io/pifiletransfer.cpp index 979613bd..f8c1f5b3 100644 --- a/src/io/pifiletransfer.cpp +++ b/src/io/pifiletransfer.cpp @@ -19,8 +19,7 @@ PIFileTransfer::PIFileTransfer() { PIFileTransfer::~PIFileTransfer() { - break_ = true; - files_.clear(); + stop(); work_file.close(); } @@ -85,7 +84,10 @@ bool PIFileTransfer::sendFiles(const PIVector &files) { pftheader.step = pft_Description; buildSession(PIVector() << Part(0, desc.size())); cur_file_string = ""; - if (!send_process()) return false; + if (!send_process()) { + sendFilesFinished(false); + return false; + } pftheader.step = pft_Data; PIVector pts; for (int i=0; i &files) { } buildSession(pts); bool ok = send_process(); + sendFilesFinished(ok); return ok; } @@ -290,7 +293,4 @@ void PIFileTransfer::receive_finished(bool ok) { void PIFileTransfer::send_finished(bool ok) { work_file.close(); started_ = false; - sendFilesFinished(ok); } - - diff --git a/utils/system_daemon/daemon.cpp b/utils/system_daemon/daemon.cpp index 800ae3a8..c974da95 100644 --- a/utils/system_daemon/daemon.cpp +++ b/utils/system_daemon/daemon.cpp @@ -42,8 +42,8 @@ Daemon::TileFileProgress::TileFileProgress(): PIScreenTile() { label_speed = new TileSimple(""); prog_file = new TileProgress(); prog_all = new TileProgress(); - buttons = new TileButtons(); - buttons->content << TileButtons::Button("Ok", CellFormat()); + buttons = new TileButtons("fd_buttons"); + buttons->content << TileButtons::Button("Pause", CellFormat()); buttons->content << TileButtons::Button("Cancel", CellFormat()); buttons->back_format.color_back = label_file->back_format.color_back = label_speed->back_format.color_back = Yellow; label_file->back_format.color_char = label_speed->back_format.color_char = Black; @@ -55,6 +55,7 @@ Daemon::TileFileProgress::TileFileProgress(): PIScreenTile() { addTile(prog_file); addTile(prog_all); addTile(buttons); + CONNECTU(&(::screen), tileEvent, this, tileEvent) } @@ -72,6 +73,7 @@ void Daemon::TileFileProgress::sizeHint(int & w, int & h) const { void Daemon::TileFileProgress::drawEvent(PIScreenDrawer * d) { + if (ft) { label_file->content[0].first = ft->stateString() + ft->curFile(); PIString spd; @@ -87,6 +89,41 @@ void Daemon::TileFileProgress::drawEvent(PIScreenDrawer * d) { } +void Daemon::TileFileProgress::show(PIFileTransfer * f) { + ft = f; + if (ft) { + conn_name = ft->name(); + ::screen.setDialogTile(this); + buttons->setFocus(); + } +} + + +void Daemon::TileFileProgress::close() { + ft = 0; + ::screen.setDialogTile(0); +} + + +void Daemon::TileFileProgress::tileEvent(PIScreenTile * t, TileEvent e) { + if (t->name() == "fd_buttons") { + if (e.type != TileButtons::ButtonSelected || !ft) return; + switch (e.data.toInt()) { + case 0: + if (buttons->content[0].first == "Pause") { + buttons->content[0].first = "Resume"; + ft->pause(); + } else { + buttons->content[0].first = "Pause"; + ft->resume(); + } + break; + case 1: ft->stop(); close(); break; + }; + } +} + + Daemon::Daemon(): PIPeer(pisd_prefix + PISystemInfo::instance()->hostname + "_" + PIString(rand() % 100)), fm(this) { @@ -273,8 +310,7 @@ void Daemon::fmActionRequest(bool remote_tile, FileManager::Action type, PIVaria Remote * r = remotes.value(conn_name, 0); if (!r) return; r->sendFiles(fm.localDir() + PIDir::separator, data.toStringList()); - tile_file_progress->ft = &(r->ft); - screen.setDialogTile(tile_file_progress); + tile_file_progress->show(&(r->ft)); } break; default: break; @@ -338,6 +374,8 @@ void Daemon::peerConnected(const PIString & name) { Remote * r = new Remote(name); CONNECTU(r, sendRequest, this, sendRequest) CONNECTU(r, receiveFinished, this, filesReceived) + CONNECTU(r, receiveFinished, this, closeFileDialog) + CONNECTU(r, sendFinished, this, closeFileDialog) remotes.insert(name, r); } @@ -358,6 +396,14 @@ void Daemon::filesReceived(const PIString & name, bool ok) { } +void Daemon::closeFileDialog(const PIString & name, bool ok) { + piCout << "CLOSE" << name << ok; + if (tile_file_progress->conn_name != name) return; + if (ok) + tile_file_progress->close(); +} + + void Daemon::dataReceived(const PIString & from, const PIByteArray & data) { //if (conn_name != from) return; if (data.size() < 4) return; @@ -444,63 +490,6 @@ void Daemon::makeOtherHostInfo() { } -void Daemon::updateConsole() { - switch (mode) { - case 0: tabConnect(); break; - case 1: tabFeature(); break; - case RequestHostInfo: tabInfo(); break; - } -} - - -void Daemon::tabConnectedHeader(int cols) { - /*console.addString("Connected to: " + connectedDaemon(), 1, PIConsole::BackGreen | PIConsole::Bold); - for (int i = 2; i <= cols; ++i) - console.addString(" ", i, PIConsole::Green | PIConsole::Inverse);*/ -} - - -void Daemon::tabConnect() { - /*startTab(); - console.addString("Available daemons:"); - int num = 0; - dnames.clear(); - PIStringList adl = availableDaemons(); - piForeachC (PIString & p, adl) { - dnames[num] = p; - console.addString(" " + PIString(num++) + " - " + p); - } - finishTab();*/ -} - - -void Daemon::tabFeature() { - /*startTab(); - tabConnectedHeader(); - console.addString("What do you wish to do with this daemon?"); - console.addString(" 0 - show host info"); - console.addString(" 1 - file manager"); - console.addString(" 2 - execute command"); - finishTab();*/ -} - - -void Daemon::tabInfo() { - /*startTab(2); - tabConnectedHeader(2); - console.addString("Exec command: " + info_other.execCommand); - console.addString(" Executed on " + info_other.execDateTime.toString()); - console.addString(" Hostname: " + info_other.hostname); - console.addString(" Username: " + info_other.user); - console.addString(" OS name: " + info_other.OS_name); - console.addString(" OS version: " + info_other.OS_version); - console.addString("Architecture: " + info_other.architecture); - console.addString(" CPU count: " + PIString::fromNumber(info_other.processorsCount)); - console.addVariable("of this process", &sys_mon_other, 2); - finishTab();*/ -} - - void Daemon::requestChDir(const PIString & d) { if (d.isEmpty()) return; fm.remoteSaveDir(); diff --git a/utils/system_daemon/daemon.h b/utils/system_daemon/daemon.h index 1f920cba..958794a2 100644 --- a/utils/system_daemon/daemon.h +++ b/utils/system_daemon/daemon.h @@ -86,8 +86,11 @@ private: }; class TileFileProgress: public PIScreenTile { + PIOBJECT_SUBCLASS(TileFileProgress, PIScreenTile) public: TileFileProgress(); + void show(PIFileTransfer * f); + void close(); TileSimple * label_file, * label_speed; TileProgress * prog_file, * prog_all; TileButtons * buttons; @@ -95,6 +98,8 @@ private: void resizeEvent(int w, int h); void sizeHint(int & w, int & h) const; void drawEvent(PIScreenDrawer * d); + PIString conn_name; + EVENT_HANDLER2(void, tileEvent, PIScreenTile *, t, PIScreenTypes::TileEvent, e); }; EVENT_HANDLER2(void, tileEvent, PIScreenTile *, t, PIScreenTypes::TileEvent, e); @@ -104,6 +109,7 @@ private: EVENT_HANDLER3(void, fmActionRequest, bool, remote_tile, FileManager::Action, type, PIVariant, data); EVENT_HANDLER2(void, timerEvent, void * , _d, int, delim); EVENT_HANDLER2(void, filesReceived, const PIString & , name, bool, ok); + EVENT_HANDLER2(void, closeFileDialog, const PIString & , name, bool, ok); EVENT(menuRequest); void hideAll(); void showTile(PIScreenTile * t, const PIString & header = PIString()); @@ -113,11 +119,6 @@ private: void dataReceived(const PIString & from, const PIByteArray & data); void makeMyHostInfo(); void makeOtherHostInfo(); - void updateConsole(); - void tabConnectedHeader(int cols = 1); - void tabConnect(); - void tabFeature(); - void tabInfo(); void requestChDir(const PIString & d);