git-svn-id: svn://db.shs.com.ru/pip@4 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2015-02-28 18:35:47 +00:00
parent 8e451c891d
commit 13336674eb
154 changed files with 44021 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
file(GLOB CPPS "*.cpp")
file(GLOB HDRS "*.h")
add_executable(pisd ${CPPS} ${HDRS})
target_link_libraries(pisd pip)
if (DEFINED LIB)
install(TARGETS pisd DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
endif ()

View File

@@ -0,0 +1,265 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "MinGW Makefiles" Generator, CMake Version 2.8
# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canonical targets will work.
.SUFFIXES:
# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =
.SUFFIXES: .hpux_make_needs_suffix_list
# Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
SHELL = cmd.exe
# The CMake executable.
CMAKE_COMMAND = "C:\Program Files (x86)\CMake 2.8\bin\cmake.exe"
# The command to remove a file.
RM = "C:\Program Files (x86)\CMake 2.8\bin\cmake.exe" -E remove -f
# Escaping for special characters.
EQUALS = =
# The program to use to edit the cache.
CMAKE_EDIT_COMMAND = "C:\Program Files (x86)\CMake 2.8\bin\cmake-gui.exe"
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = C:\libs
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = C:\libs
#=============================================================================
# Targets provided globally by CMake.
# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
"C:\Program Files (x86)\CMake 2.8\bin\cmake-gui.exe" -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache
# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast
# Special rule for the target install
install: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
"C:\Program Files (x86)\CMake 2.8\bin\cmake.exe" -P cmake_install.cmake
.PHONY : install
# Special rule for the target install
install/fast: preinstall/fast
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
"C:\Program Files (x86)\CMake 2.8\bin\cmake.exe" -P cmake_install.cmake
.PHONY : install/fast
# Special rule for the target install/local
install/local: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..."
"C:\Program Files (x86)\CMake 2.8\bin\cmake.exe" -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
.PHONY : install/local
# Special rule for the target install/local
install/local/fast: install/local
.PHONY : install/local/fast
# Special rule for the target install/strip
install/strip: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
"C:\Program Files (x86)\CMake 2.8\bin\cmake.exe" -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
.PHONY : install/strip
# Special rule for the target install/strip
install/strip/fast: install/strip
.PHONY : install/strip/fast
# Special rule for the target list_install_components
list_install_components:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\""
.PHONY : list_install_components
# Special rule for the target list_install_components
list_install_components/fast: list_install_components
.PHONY : list_install_components/fast
# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
"C:\Program Files (x86)\CMake 2.8\bin\cmake.exe" -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# The main all target
all: cmake_check_build_system
cd /d C:\libs && $(CMAKE_COMMAND) -E cmake_progress_start C:\libs\CMakeFiles C:\libs\pip\utils\system_daemon\CMakeFiles\progress.marks
cd /d C:\libs && $(MAKE) -f CMakeFiles\Makefile2 pip/utils/system_daemon/all
$(CMAKE_COMMAND) -E cmake_progress_start C:\libs\CMakeFiles 0
.PHONY : all
# The main clean target
clean:
cd /d C:\libs && $(MAKE) -f CMakeFiles\Makefile2 pip/utils/system_daemon/clean
.PHONY : clean
# The main clean target
clean/fast: clean
.PHONY : clean/fast
# Prepare targets for installation.
preinstall: all
cd /d C:\libs && $(MAKE) -f CMakeFiles\Makefile2 pip/utils/system_daemon/preinstall
.PHONY : preinstall
# Prepare targets for installation.
preinstall/fast:
cd /d C:\libs && $(MAKE) -f CMakeFiles\Makefile2 pip/utils/system_daemon/preinstall
.PHONY : preinstall/fast
# clear depends
depend:
cd /d C:\libs && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles\Makefile.cmake 1
.PHONY : depend
# Convenience name for target.
pip/utils/system_daemon/CMakeFiles/pisd.dir/rule:
cd /d C:\libs && $(MAKE) -f CMakeFiles\Makefile2 pip/utils/system_daemon/CMakeFiles/pisd.dir/rule
.PHONY : pip/utils/system_daemon/CMakeFiles/pisd.dir/rule
# Convenience name for target.
pisd: pip/utils/system_daemon/CMakeFiles/pisd.dir/rule
.PHONY : pisd
# fast build rule for target.
pisd/fast:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/build
.PHONY : pisd/fast
daemon.obj: daemon.cpp.obj
.PHONY : daemon.obj
# target to build an object file
daemon.cpp.obj:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/daemon.cpp.obj
.PHONY : daemon.cpp.obj
daemon.i: daemon.cpp.i
.PHONY : daemon.i
# target to preprocess a source file
daemon.cpp.i:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/daemon.cpp.i
.PHONY : daemon.cpp.i
daemon.s: daemon.cpp.s
.PHONY : daemon.s
# target to generate assembly for a file
daemon.cpp.s:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/daemon.cpp.s
.PHONY : daemon.cpp.s
file_manager.obj: file_manager.cpp.obj
.PHONY : file_manager.obj
# target to build an object file
file_manager.cpp.obj:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/file_manager.cpp.obj
.PHONY : file_manager.cpp.obj
file_manager.i: file_manager.cpp.i
.PHONY : file_manager.i
# target to preprocess a source file
file_manager.cpp.i:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/file_manager.cpp.i
.PHONY : file_manager.cpp.i
file_manager.s: file_manager.cpp.s
.PHONY : file_manager.s
# target to generate assembly for a file
file_manager.cpp.s:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/file_manager.cpp.s
.PHONY : file_manager.cpp.s
main.obj: main.cpp.obj
.PHONY : main.obj
# target to build an object file
main.cpp.obj:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/main.cpp.obj
.PHONY : main.cpp.obj
main.i: main.cpp.i
.PHONY : main.i
# target to preprocess a source file
main.cpp.i:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/main.cpp.i
.PHONY : main.cpp.i
main.s: main.cpp.s
.PHONY : main.s
# target to generate assembly for a file
main.cpp.s:
cd /d C:\libs && $(MAKE) -f pip\utils\system_daemon\CMakeFiles\pisd.dir\build.make pip/utils/system_daemon/CMakeFiles/pisd.dir/main.cpp.s
.PHONY : main.cpp.s
# Help Target
help:
@echo The following are some of the valid targets for this Makefile:
@echo ... all (the default if no target is provided)
@echo ... clean
@echo ... depend
@echo ... edit_cache
@echo ... install
@echo ... install/local
@echo ... install/strip
@echo ... list_install_components
@echo ... pisd
@echo ... rebuild_cache
@echo ... daemon.obj
@echo ... daemon.i
@echo ... daemon.s
@echo ... file_manager.obj
@echo ... file_manager.i
@echo ... file_manager.s
@echo ... main.obj
@echo ... main.i
@echo ... main.s
.PHONY : help
#=============================================================================
# Special targets to cleanup operation of make.
# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
cd /d C:\libs && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles\Makefile.cmake 0
.PHONY : cmake_check_build_system

View File

@@ -0,0 +1,47 @@
# Install script for directory: C:/libs/pip/utils/system_daemon
# Set the install prefix
IF(NOT DEFINED CMAKE_INSTALL_PREFIX)
SET(CMAKE_INSTALL_PREFIX "C:/mingw/x32")
ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)
STRING(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
# Set the install configuration name.
IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
IF(BUILD_TYPE)
STRING(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
ELSE(BUILD_TYPE)
SET(CMAKE_INSTALL_CONFIG_NAME "Release")
ENDIF(BUILD_TYPE)
MESSAGE(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
# Set the component getting installed.
IF(NOT CMAKE_INSTALL_COMPONENT)
IF(COMPONENT)
MESSAGE(STATUS "Install component: \"${COMPONENT}\"")
SET(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
ELSE(COMPONENT)
SET(CMAKE_INSTALL_COMPONENT)
ENDIF(COMPONENT)
ENDIF(NOT CMAKE_INSTALL_COMPONENT)
IF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")
list(APPEND CMAKE_ABSOLUTE_DESTINATION_FILES
"C:/mingw/x32/bin/pisd.exe")
IF (CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)
message(WARNING "ABSOLUTE path INSTALL DESTINATION : ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
ENDIF (CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)
IF (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)
message(FATAL_ERROR "ABSOLUTE path INSTALL DESTINATION forbidden (by caller): ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
ENDIF (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)
FILE(INSTALL DESTINATION "C:/mingw/x32/bin" TYPE EXECUTABLE FILES "C:/libs/pip/utils/system_daemon/pisd.exe")
IF(EXISTS "$ENV{DESTDIR}/C:/mingw/x32/bin/pisd.exe" AND
NOT IS_SYMLINK "$ENV{DESTDIR}/C:/mingw/x32/bin/pisd.exe")
IF(CMAKE_INSTALL_DO_STRIP)
EXECUTE_PROCESS(COMMAND "C:/mingw/x32/bin/strip.exe" "$ENV{DESTDIR}/C:/mingw/x32/bin/pisd.exe")
ENDIF(CMAKE_INSTALL_DO_STRIP)
ENDIF()
ENDIF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")

View File

@@ -0,0 +1,252 @@
#include "daemon.h"
#include "shared.h"
#include "pisysteminfo.h"
Daemon::Daemon(): PIPeer("_pisd_" + PISystemInfo::instance()->hostname + "_" + PIString(rand() % 100)) {
setName("Daemon");
timer.setName("__S__Daemon_timer");
enabled = false;
mode = offset = cur = height = 0;
CONNECTU(&console, keyPressed, this, keyEvent)
CONNECTU(&timer, tickEvent, this, timerEvent)
timer.addDelimiter(5);
timer.start(200);
}
void Daemon::keyEvent(char key) {
if (!enabled) return;
int num = key - '0';
switch (mode) {
case 0:
if (num >= 0 && num <= 9) {
connectToDaemon(dnames.value(key - '0'));
return;
}
break;
case 1:
if (num >= 0 && num <= 9) {
mode = num + 10;
updateConsole();
return;
}
break;
}
switch (key) {
case PIKbdListener::UpArrow:
/*cur--;
if (cur < 0) cur = 0;
if (cur - offset < 2) offset--;
if (offset < 0) offset = 0;*/
updateConsole();
break;
case PIKbdListener::Space:
/*if (cur < 0 || cur >= files.size_s()) return;
if (selected.contains(files[cur].name)) selected.removeOne(files[cur].name);
else selected << files[cur].name;*/
case PIKbdListener::DownArrow:
/*cur++;
if (cur >= files.size_s()) cur = files.size_s() - 1;
if (cur - offset >= height - 2) offset++;
if (offset >= files.size_s() - height) offset = files.size_s() - height;*/
updateConsole();
break;
case PIKbdListener::Home:
//cur = offset = 0;
updateConsole();
break;
case PIKbdListener::End:
//cur = files.size_s() - 1;
//offset = files.size_s() - height;
updateConsole();
break;
case PIKbdListener::Return:
//if (cur < files.size_s() && cur >= 0) {
//}
break;
case 'A':
updateConsole();
break;
case 'R':
updateConsole();
break;
case PIKbdListener::Esc:
//selected.clear();
//updateConsole();
if (mode == 0)
menuRequest();
else {
if (mode > 1) {
mode = 1;
updateConsole();
} else
disconnect();
}
break;
default: break;
}
}
void Daemon::timerEvent(void * _d, int delim) {
if (!enabled) return;
if (delim == 1) {
if (mode == 0)
updateConsole();
}
if (delim == 5) {
if (conn_name.isEmpty()) return;
PIByteArray ba; ba << int(RequestHostInfo);
send(conn_name, ba);
}
}
PIStringList Daemon::availableDaemons() const {
available_daemons.clear();
piForeachC (PIPeer::PeerInfo & p, allPeers()) {
if (!p.name.startsWith("_pisd_")) continue;
available_daemons << p.name.mid(6);
}
return available_daemons;
}
void Daemon::connectToDaemon(const PIString & dn) {
if (dn.isEmpty()) return;
conn_name = "_pisd_" + dn;
mode = 1;
updateConsole();
}
void Daemon::disconnect() {
conn_name.clear();
mode = 0;
updateConsole();
}
PIString Daemon::connectedDaemon() const {
return conn_name.mid(6);
}
void Daemon::peerDisconnected(const PIString & name) {
if (name == conn_name) {
conn_name.clear();
mode = 0;
}
}
void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
//if (conn_name != from) return;
if (data.size() < 4) return;
PIByteArray ba(data), rba;
int type; ba >> type;
//piCout << "rec from" << from << type;
switch (type) {
case RequestHostInfo:
makeMyHostInfo();
rba << int(ReplyHostInfo) << info_my;
break;
case ReplyHostInfo:
ba >> info_other;
makeOtherHostInfo();
break;
};
if (!rba.isEmpty()) send(from, rba);
}
void Daemon::makeMyHostInfo() {
info_my.execCommand = PISystemInfo::instance()->execCommand;
info_my.hostname = PISystemInfo::instance()->hostname;
info_my.user = PISystemInfo::instance()->user;
info_my.OS_name = PISystemInfo::instance()->OS_name;
info_my.OS_version = PISystemInfo::instance()->OS_version;
info_my.architecture = PISystemInfo::instance()->architecture;
info_my.execDateTime = PISystemInfo::instance()->execDateTime;
info_my.processorsCount = PISystemInfo::instance()->processorsCount;
info_my.ID = sys_mon.statistic().ID;
info_my.threads = sys_mon.statistic().threads;
info_my.priority = sys_mon.statistic().priority;
info_my.physical_memsize = sys_mon.statistic().physical_memsize;
info_my.share_memsize = sys_mon.statistic().share_memsize;
info_my.cpu_load_system = sys_mon.statistic().cpu_load_system;
info_my.cpu_load_user = sys_mon.statistic().cpu_load_user;
}
void Daemon::makeOtherHostInfo() {
PISystemMonitor::ProcessStats & ps(const_cast<PISystemMonitor::ProcessStats & >(sys_mon_other.statistic()));
ps.ID = info_other.ID;
ps.threads = info_other.threads;
ps.priority = info_other.priority;
ps.physical_memsize = info_other.physical_memsize;
ps.share_memsize = info_other.share_memsize;
ps.cpu_load_system = info_other.cpu_load_system;
ps.cpu_load_user = info_other.cpu_load_user;
sys_mon_other.setStatistic(ps);
}
void Daemon::updateConsole() {
if (!enabled) return;
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();
}

View File

@@ -0,0 +1,93 @@
#ifndef DAEMON_H
#define DAEMON_H
#include "piconsole.h"
#include "pipeer.h"
extern PIConsole console;
extern PISystemMonitor sys_mon;
class Daemon: public PIPeer {
PIOBJECT(Daemon)
public:
Daemon();
struct HostInfo {
PIString execCommand;
PIString hostname;
PIString user;
PIString OS_name;
PIString OS_version;
PIString architecture;
PIDateTime execDateTime;
int processorsCount;
int ID;
int threads;
int priority;
ulong physical_memsize;
ulong share_memsize;
float cpu_load_system;
float cpu_load_user;
};
void enable() {enabled = true;}
void disable() {enabled = false;}
PIStringList availableDaemons() const;
void connectToDaemon(const PIString & dn);
void disconnect();
PIString connectedDaemon() const;
private:
enum PacketType {
RequestHostInfo = 10,
ReplyHostInfo = 20
};
EVENT_HANDLER1(void, keyEvent, char, key);
EVENT_HANDLER2(void, timerEvent, void * , _d, int, delim);
EVENT(menuRequest);
void peerDisconnected(const PIString & name);
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();
mutable PIStringList available_daemons;
PITimer timer;
PIString conn_name;
PIMap<int, PIString> dnames;
PISystemMonitor sys_mon_other;
HostInfo info_my, info_other;
bool enabled;
int mode, offset, cur, height;
};
inline PIByteArray & operator <<(PIByteArray & b, const Daemon::HostInfo & v) {
b << v.execCommand << v.hostname << v.user << v.OS_name
<< v.OS_version << v.architecture << v.execDateTime
<< v.processorsCount << v.ID << v.threads << v.priority
<< v.physical_memsize << v.share_memsize
<< v.cpu_load_system << v.cpu_load_user;
return b;
}
inline PIByteArray & operator >>(PIByteArray & b, Daemon::HostInfo & v) {
b >> v.execCommand >> v.hostname >> v.user >> v.OS_name
>> v.OS_version >> v.architecture >> v.execDateTime
>> v.processorsCount >> v.ID >> v.threads >> v.priority
>> v.physical_memsize >> v.share_memsize
>> v.cpu_load_system >> v.cpu_load_user;
return b;
}
#endif // DAEMON_H

View File

@@ -0,0 +1,182 @@
#include "file_manager.h"
#include "shared.h"
FileManager::FileManager() {
setName("FileManager");
offset = cur = height = 0;
enabled = del_commit = false;
CONNECTU(&console, keyPressed, this, keyEvent)
dir = PIDir::current();
//dir.setDir("/home/peri4/Documents");
dir.setDir("/home/peri4");
updateDir();
}
void FileManager::keyEvent(char key) {
if (!enabled) return;
if (key == 'D') {
if (cur >= files.size_s() || cur < 0) return;
if (del_commit) {
piForeachC (PIString & f, selected) {
PIFile::remove(dir.absolutePath() + PIDir::separator + f);
//piCout << "remove" << (dir.absolutePath() + PIDir::separator + f);
}
selected.clear();
updateDir();
console.clearCustomStatus();
del_commit = false;
} else {
if (selected.isEmpty()) selected << files[cur].path;
console.addCustomStatus("Delete " + PIString(selected.size_s()) + " file, are you sure? D as yes");
del_commit = true;
}
updateConsole();
return;
}
console.clearCustomStatus();
del_commit = false;
PIStringList nsel;
switch (key) {
case PIKbdListener::UpArrow:
cur--;
if (cur < 0) cur = 0;
if (cur - offset < 3) offset--;
if (offset < 0) offset = 0;
updateConsole();
break;
case PIKbdListener::Space:
if (cur < 0 || cur >= files.size_s()) return;
if (selected.contains(files[cur].path)) selected.removeOne(files[cur].path);
else selected << files[cur].path;
case PIKbdListener::DownArrow:
cur++;
if (cur >= files.size_s()) cur = files.size_s() - 1;
if (cur - offset >= height - 3) offset++;
if (offset >= files.size_s() - height) offset = files.size_s() - height;
updateConsole();
//piCout << offset << files.size_s() << height;
break;
case PIKbdListener::Home:
cur = offset = 0;
updateConsole();
break;
case PIKbdListener::End:
cur = files.size_s() - 1;
offset = files.size_s() - height;
updateConsole();
//piCout << offset << files.size_s() << height;
break;
case PIKbdListener::Return:
if (cur < files.size_s() && cur >= 0) {
piCout << files[cur];
if (files[cur].isDir()) {
prev_pos[dir.path()] = cur;
prev_off[dir.path()] = offset;
dir.cd(files[cur].name());
cur = prev_pos.value(dir.path(), 0);
offset = prev_off.value(dir.path(), 0);
selected.clear();
updateDir();
updateConsole();
}
}
break;
case 'A':
selected.clear();
piForeach (PIFile::FileInfo & e, files)
selected << e.path;
updateConsole();
break;
case 'R':
updateDir();
piForeach (PIFile::FileInfo & e, files)
if (selected.contains(e.path))
nsel << e.path;
selected = nsel;
updateConsole();
break;
case PIKbdListener::Esc:
//selected.clear();
//updateConsole();
menuRequest();
break;
default: break;
}
}
void FileManager::updateConsole() {
if (!enabled) return;
startTab(2);
console.addString("File manager", 1, PIConsole::Yellow | PIConsole::Inverse);
console.addString("Path: " + dir.absolutePath(), 1, PIConsole::Green | PIConsole::Inverse | PIConsole::Bold);
console.addString("Name", 1, PIConsole::Green | PIConsole::Inverse | PIConsole::Bold);
console.addString(" ", 2, PIConsole::Yellow | PIConsole::Inverse);
console.addString(" ", 2, PIConsole::Green | PIConsole::Inverse);
console.addString(" ", 2, PIConsole::Green | PIConsole::Inverse);
buildNames();
console.addString("A - select all, D - remove, R - refresh, Esc - exit", 1, PIConsole::Green | PIConsole::Inverse | PIConsole::Bold);
finishTab();
}
void FileManager::buildNames() {
if (!enabled) return;
height = console.windowHeight() - 10;
int is = piClampi(offset, 0, piMaxi(0, files.size_s() - 1)), ie = piClampi(offset + height, 0, files.size_s());
console.addString((is > 0) ? (PIString(" /\\ ").repeat(console.windowWidth() / 8)) : " ", 1, PIConsole::Green | PIConsole::Bold);
console.addString(" ", 2);
PIChar t;
PIConsole::FormatFlags f = 0;
PIString scol;
piCout << cur;
for (int i = is; i < ie; ++i) {
if (files[i].isDir()) {
t = '/';
f = PIConsole::Bold;
scol = " dir";
} else {
if (files[i].perm_user.exec || files[i].perm_group.exec || files[i].perm_other.exec) {
f = PIConsole::Green | PIConsole::Bold;
t = '*';
} else {
t = ' ';
f = 0;
}
scol = PIString::readableSize(files[i].size);
}
if (files[i].isSymbolicLink() && (t != '*')) t = '~';
scol = scol.expandRightTo(9, ' ') + "| " + files[i].time_modification.toString("dd.MM hh:mm:ss") + " | "
+ files[i].perm_user.toString() + " " + files[i].perm_group.toString() + " " + files[i].perm_other.toString();
if (i == cur) f |= PIConsole::BackBlue;
if (selected.contains(files[i].path)) f |= PIConsole::Yellow | PIConsole::Bold;
console.addString(t + files[i].name(), 1, f);
console.addString(scol, 2, f);
}
console.addString((ie < files.size_s()) ? (PIString(" \\/ ").repeat(console.windowWidth() / 8)) : " ", 1, PIConsole::Green | PIConsole::Bold);
console.addString(" ", 2);
}
void FileManager::updateDir() {
if (!enabled) return;
files.clear();
PIVector<PIFile::FileInfo> el = dir.entries(), fl, dl;
for (int i = 0; i < el.size_s(); ++i) {
if (el[i].path == ".") continue;
if (el[i].path == "..") {
dl.push_front(el[i]);
continue;
}
if (el[i].isDir()) dl << el[i];
else fl << el[i];
}
files << dl << fl;
if (cur >= files.size_s()) cur = files.size_s() - 1;
if (offset >= files.size_s() - height) offset = files.size_s() - height;
if (cur < 0) cur = 0;
if (offset < 0) offset = 0;
}

View File

@@ -0,0 +1,33 @@
#ifndef FILE_MANAGER_H
#define FILE_MANAGER_H
#include "piconsole.h"
#include "pidir.h"
extern PIConsole console;
class FileManager: public PIObject {
PIOBJECT(FileManager)
public:
FileManager();
void enable() {enabled = true; updateDir(); updateConsole();}
void disable() {enabled = false;}
private:
EVENT_HANDLER1(void, keyEvent, char, key);
EVENT(menuRequest);
void updateConsole();
void updateDir();
void buildNames();
int offset, cur, height;
bool enabled, del_commit;
PIDir dir;
PIVector<PIFile::FileInfo> files;
PIMap<PIString, int> prev_pos, prev_off;
PIStringList selected;
};
#endif // FILE_MANAGER_H

244
utils/system_daemon/main.cpp Executable file
View File

@@ -0,0 +1,244 @@
/*
PIP - Platform Independent Primitives
Remote console viewer
Copyright (C) 2014 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"
void key_event(char key, void * );
class _Init {
public:
_Init() {srand(PISystemTime::current().toMicroseconds());}
};
_Init _pisd_init;
PIConsole console(false, key_event);
PISystemMonitor sys_mon;
FileManager file_manager;
Daemon daemon_;
int mode = 0, oldmode = -1;
class MenuOperator: public PIObject {
PIOBJECT(MenuOperator)
public:
MenuOperator() {
CONNECTU(&file_manager, menuRequest, this, menuRequest)
CONNECTU(&daemon_, menuRequest, this, menuRequest)
}
EVENT_HANDLER(void, menuRequest) {mode = 0;}
};
MenuOperator menu_operator;
void key_event(char key, void * ) {
if (key == PIKbdListener::Esc) {
;//mode = 0;
} else {
if (mode != 3) {
if (key < '0' || key > '9') return;
mode = key - '0';
}
}
}
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.addString(" ", 2, PIConsole::Yellow | PIConsole::Inverse);
console.addVariable("of this process", &sys_mon, 2);
finishTab();
}
void tabConnect() {
}
#include <picrc.h>
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();
PICLI cli(argc, argv);
//cli.addArgument("");
sys_mon.startOnSelf();
console.enableExitCapture();
console.setDefaultAlignment(PIConsole::Right);
console.start();
//WAIT_FOR_EXIT
//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;
};

Binary file not shown.

View File

@@ -0,0 +1,22 @@
#include "piconsole.h"
extern PIConsole console;
inline void header(int cols = 1) {
console.addString("PIP System Daemon (PIP " + PIPVersion() + ")", 1, PIConsole::Yellow | PIConsole::Inverse);
for (int i = 2; i <= cols; ++i)
console.addString(" ", i, PIConsole::Yellow | PIConsole::Inverse);
}
inline void startTab(int cols = 1) {
console.pause(true);
console.clearTab(0);
console.lock();
header(cols);
}
inline void finishTab() {
console.unlock();
console.pause(false);
console.update();
}