git-svn-id: svn://db.shs.com.ru/pip@46 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
135 lines
3.7 KiB
C++
135 lines
3.7 KiB
C++
#ifndef DAEMON_H
|
|
#define DAEMON_H
|
|
|
|
#include "piscreentiles.h"
|
|
#include "pipeer.h"
|
|
#include "pisystemmonitor.h"
|
|
#include "pidatatransfer.h"
|
|
#include "pifiletransfer.h"
|
|
#include "file_manager.h"
|
|
|
|
extern PISystemMonitor sys_mon;
|
|
|
|
class Daemon: public PIPeer {
|
|
PIOBJECT_SUBCLASS(Daemon, PIPeer)
|
|
public:
|
|
Daemon();
|
|
~Daemon();
|
|
|
|
struct HostInfo {
|
|
HostInfo() {
|
|
processorsCount = ID = threads = priority = -1;
|
|
physical_memsize = share_memsize = 0;
|
|
cpu_load_system = cpu_load_user = 0.;
|
|
}
|
|
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 showMainList() {showTile(list_daemons, "Select daemon");}
|
|
void showActionList() {showTile(list_actions, "Select action");}
|
|
|
|
PIStringList availableDaemons();
|
|
void connectToDaemon(const PIString & dn);
|
|
void disconnect();
|
|
|
|
PIString connectedDaemon() const;
|
|
PIString thisDaemonName() const {return selfInfo().name.mid(6);}
|
|
|
|
PIScreenTile * tile() const;
|
|
|
|
private:
|
|
enum PacketType {
|
|
RequestHostInfo = 10,
|
|
RequestChangeDir,
|
|
|
|
ReplyHostInfo = 20,
|
|
ReplyChangeDir,
|
|
|
|
DataTransfer = 30
|
|
|
|
};
|
|
|
|
class Remote: public PIThread {
|
|
public:
|
|
Remote(const PIString & n = PIString()) {dt.setName(n); ft.setName(n); dir = PIDir::current();}
|
|
void sendData(const PIByteArray & d) {_d = d; startOnce();}
|
|
PIDir dir;
|
|
PIDataTransfer dt;
|
|
PIFileTransfer ft;
|
|
PIByteArray _d;
|
|
void run() {dt.send(_d);}
|
|
};
|
|
|
|
EVENT_HANDLER2(void, tileEvent, PIScreenTile *, t, PIScreenTypes::TileEvent, e);
|
|
EVENT_HANDLER1(void, keyEvent, PIKbdListener::KeyEvent, key);
|
|
EVENT_HANDLER1(void, fmKeyEvent, PIKbdListener::KeyEvent, key);
|
|
EVENT_HANDLER2(void, timerEvent, void * , _d, int, delim);
|
|
EVENT_HANDLER1(void, dtSendRequest, PIByteArray &, data);
|
|
EVENT_HANDLER1(void, dtReceived, bool, ok);
|
|
EVENT(menuRequest);
|
|
void hideAll();
|
|
void showTile(PIScreenTile * t, const PIString & header = PIString());
|
|
void fillInfoTile(const HostInfo & hi);
|
|
void peerConnected(const PIString & name);
|
|
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();
|
|
|
|
void requestChDir(const PIString & d);
|
|
|
|
mutable PIStringList available_daemons;
|
|
PITimer timer;
|
|
PIString conn_name;
|
|
PIMap<int, PIString> dnames;
|
|
PIMap<PIString, Remote*> remotes;
|
|
PISystemMonitor sys_mon_other;
|
|
HostInfo info_my, info_other;
|
|
FileManager fm;
|
|
PIScreenTile * tile_root, * tile_fm;
|
|
TileSimple * tile_info, * tile_header;
|
|
TileList * list_daemons, * list_actions;
|
|
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
|