PIFile: applyFileInfo
PIPeer: fixed pisd work progress ... git-svn-id: svn://db.shs.com.ru/pip@20 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
18
main.cpp
18
main.cpp
@@ -126,13 +126,17 @@ public:
|
|||||||
using namespace PIScreenTypes;
|
using namespace PIScreenTypes;
|
||||||
|
|
||||||
int main (int argc, char * argv[]) {
|
int main (int argc, char * argv[]) {
|
||||||
/*PILibrary lib(argv[1]);
|
PIFile::FileInfo fi = PIFile::fileInfo(argv[1]);
|
||||||
piCout << lib.isLoaded();
|
piCout << fi;
|
||||||
piCout << lib.resolve(argv[2]);
|
fi.perm_user = fi.perm_group = fi.perm_other = 7;
|
||||||
lib.unload();
|
fi.id_user = 1000;
|
||||||
piCout << lib.load(argv[1]);
|
fi.time_access.day--;
|
||||||
piCout << lib.resolve(argv[2]);
|
fi.time_modification.hours++;
|
||||||
return 0;*/
|
fi.flags |= PIFile::FileInfo::Hidden;
|
||||||
|
piCout << PIFile::applyFileInfo(fi);
|
||||||
|
fi = PIFile::fileInfo(argv[1]);
|
||||||
|
piCout << fi;
|
||||||
|
return 0;
|
||||||
/*if (!(argc == 3 || argc == 4)) {
|
/*if (!(argc == 3 || argc == 4)) {
|
||||||
piCout << "UDPFileTransfer";
|
piCout << "UDPFileTransfer";
|
||||||
piCout << "USE: piptest [src_ip_port] [dst_ip_port] {filename}";
|
piCout << "USE: piptest [src_ip_port] [dst_ip_port] {filename}";
|
||||||
|
|||||||
@@ -227,6 +227,7 @@ void PIScreen::SystemConsole::print() {
|
|||||||
}
|
}
|
||||||
for (int i = 0; i < height; ++i)
|
for (int i = 0; i < height; ++i)
|
||||||
pcells[i] = cells[i];
|
pcells[i] = cells[i];
|
||||||
|
printf("\e[0m");
|
||||||
fflush(0);
|
fflush(0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -295,8 +295,8 @@ PIString PIDateTime::toString(const PIString & format) const {
|
|||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
PIDateTime::PIDateTime(FILETIME t) {
|
PIDateTime::PIDateTime(FILETIME t) {
|
||||||
FILETIME lt;
|
FILETIME lt;
|
||||||
FileTimeToLocalFileTime(&t, <);
|
|
||||||
SYSTEMTIME st;
|
SYSTEMTIME st;
|
||||||
|
FileTimeToLocalFileTime(&t, <);
|
||||||
FileTimeToSystemTime(<, &st);
|
FileTimeToSystemTime(<, &st);
|
||||||
year = st.wYear;
|
year = st.wYear;
|
||||||
month = st.wMonth;
|
month = st.wMonth;
|
||||||
@@ -306,6 +306,22 @@ PIString PIDateTime::toString(const PIString & format) const {
|
|||||||
seconds = st.wSecond;
|
seconds = st.wSecond;
|
||||||
milliseconds = st.wMilliseconds;
|
milliseconds = st.wMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FILETIME PIDateTime::toFILETIME() const {
|
||||||
|
FILETIME lt, ret;
|
||||||
|
SYSTEMTIME st;
|
||||||
|
st.wYear = year;
|
||||||
|
st.wMonth = month;
|
||||||
|
st.wDay = day;
|
||||||
|
st.wHour = hours;
|
||||||
|
st.wMinute = minutes;
|
||||||
|
st.wSecond = seconds;
|
||||||
|
st.wMilliseconds = milliseconds;
|
||||||
|
SystemTimeToFileTime(&st, <);
|
||||||
|
LocalFileTimeToFileTime(<, &ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -224,6 +224,7 @@ struct PIP_EXPORT PIDateTime {
|
|||||||
PIDateTime(const PIDate & date, const PITime & time) {year = date.year; month = date.month; day = date.day; hours = time.hours; minutes = time.minutes; seconds = time.seconds; milliseconds = time.milliseconds;}
|
PIDateTime(const PIDate & date, const PITime & time) {year = date.year; month = date.month; day = date.day; hours = time.hours; minutes = time.minutes; seconds = time.seconds; milliseconds = time.milliseconds;}
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
PIDateTime(FILETIME t);
|
PIDateTime(FILETIME t);
|
||||||
|
FILETIME toFILETIME() const;
|
||||||
#endif
|
#endif
|
||||||
int year;
|
int year;
|
||||||
int month;
|
int month;
|
||||||
|
|||||||
@@ -218,7 +218,12 @@ PIVector<PIFile::FileInfo> PIDir::entries() {
|
|||||||
# else
|
# else
|
||||||
const_cast<char*>(p.data()), 0
|
const_cast<char*>(p.data()), 0
|
||||||
# endif
|
# endif
|
||||||
, 0, versionsort);
|
, 0,
|
||||||
|
# ifdef MAC_OS
|
||||||
|
alphasort);
|
||||||
|
# else
|
||||||
|
versionsort);
|
||||||
|
# endif
|
||||||
for (int i = 0; i < cnt; ++i) {
|
for (int i = 0; i < cnt; ++i) {
|
||||||
l << PIFile::fileInfo(dp + PIString(list[i]->d_name));
|
l << PIFile::fileInfo(dp + PIString(list[i]->d_name));
|
||||||
delete list[i];
|
delete list[i];
|
||||||
|
|||||||
@@ -34,7 +34,9 @@
|
|||||||
# define S_IFSOCK 0x20
|
# define S_IFSOCK 0x20
|
||||||
#else
|
#else
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
|
# include <sys/time.h>
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
|
# include <utime.h>
|
||||||
#endif
|
#endif
|
||||||
#define S_IFHDN 0x40
|
#define S_IFHDN 0x40
|
||||||
#ifdef QNX
|
#ifdef QNX
|
||||||
@@ -289,6 +291,20 @@ PIFile::FileInfo PIFile::fileInfo(const PIString & path) {
|
|||||||
ret.size = filesize.QuadPart;
|
ret.size = filesize.QuadPart;
|
||||||
ret.time_access = PIDateTime(fi.ftLastAccessTime);
|
ret.time_access = PIDateTime(fi.ftLastAccessTime);
|
||||||
ret.time_modification = PIDateTime(fi.ftLastWriteTime);
|
ret.time_modification = PIDateTime(fi.ftLastWriteTime);
|
||||||
|
/*PIByteArray sec;
|
||||||
|
DWORD sec_n(0);
|
||||||
|
//SECURITY_DESCRIPTOR sec;
|
||||||
|
GetFileSecurity(path.data(), DACL_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION, (SECURITY_DESCRIPTOR*)sec.data(), 0, &sec_n);
|
||||||
|
sec.resize(sec_n);
|
||||||
|
GetFileSecurity(path.data(), DACL_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION, (SECURITY_DESCRIPTOR*)sec.data(), sec.size(), &sec_n);
|
||||||
|
errorClear();
|
||||||
|
SID sid; BOOL def;
|
||||||
|
GetSecurityDescriptorGroup((PSECURITY_DESCRIPTOR)sec.data(), &sid, &def);
|
||||||
|
char * s(0);
|
||||||
|
ConvertSidToStringSid((PSID)&sid, s);
|
||||||
|
piCout << s;
|
||||||
|
LocalFree(s);
|
||||||
|
//ret.id_user = ;*/
|
||||||
}
|
}
|
||||||
CloseHandle(hFile);
|
CloseHandle(hFile);
|
||||||
#else
|
#else
|
||||||
@@ -325,3 +341,65 @@ PIFile::FileInfo PIFile::fileInfo(const PIString & path) {
|
|||||||
if (n == "..") ret.flags = FileInfo::Dir | FileInfo::DotDot;
|
if (n == "..") ret.flags = FileInfo::Dir | FileInfo::DotDot;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PIFile::applyFileInfo(const PIString & path, const PIFile::FileInfo & info) {
|
||||||
|
if (path.isEmpty()) return false;
|
||||||
|
PIString fp(path);
|
||||||
|
if (fp.endsWith(PIDir::separator)) fp.pop_back();
|
||||||
|
#ifdef WINDOWS
|
||||||
|
DWORD attr = GetFileAttributes((LPCTSTR)(path.data()));
|
||||||
|
if (attr == 0xFFFFFFFF) return false;
|
||||||
|
attr &= ~(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY);
|
||||||
|
if (info.isHidden()) attr |= FILE_ATTRIBUTE_HIDDEN;
|
||||||
|
if (!info.perm_user.write) attr |= FILE_ATTRIBUTE_READONLY;
|
||||||
|
if (SetFileAttributes((LPCTSTR)(fp.data()), attr) == 0) {
|
||||||
|
piCout << "[PIFile] applyFileInfo: \"SetFileAttributes\" error:" << errorString();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
HANDLE hFile = 0;
|
||||||
|
if ((attr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) {
|
||||||
|
hFile = CreateFile(path.data(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
|
||||||
|
} else {
|
||||||
|
hFile = CreateFile(path.data(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
|
||||||
|
}
|
||||||
|
if (!hFile) return false;
|
||||||
|
FILETIME atime = info.time_access.toFILETIME(), mtime = info.time_modification.toFILETIME();
|
||||||
|
if (SetFileTime(hFile, 0, &atime, &mtime) == 0) {
|
||||||
|
piCout << "[PIFile] applyFileInfo: \"SetFileTime\" error:" << errorString();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
CloseHandle(hFile);
|
||||||
|
#else
|
||||||
|
int mode(0);
|
||||||
|
if (info.perm_user.read) mode |= S_IRUSR;
|
||||||
|
if (info.perm_user.write) mode |= S_IWUSR;
|
||||||
|
if (info.perm_user.exec) mode |= S_IXUSR;
|
||||||
|
if (info.perm_group.read) mode |= S_IRGRP;
|
||||||
|
if (info.perm_group.write) mode |= S_IWGRP;
|
||||||
|
if (info.perm_group.exec) mode |= S_IXGRP;
|
||||||
|
if (info.perm_other.read) mode |= S_IROTH;
|
||||||
|
if (info.perm_other.write) mode |= S_IWOTH;
|
||||||
|
if (info.perm_other.exec) mode |= S_IXOTH;
|
||||||
|
if (chmod(fp.data(), mode) != 0) {
|
||||||
|
piCout << "[PIFile] applyFileInfo: \"chmod\" error:" << errorString();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (chown(fp.data(), info.id_user, info.id_group) != 0) {
|
||||||
|
piCout << "[PIFile] applyFileInfo: \"chown\" error:" << errorString();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
struct timeval tm[2];
|
||||||
|
PISystemTime st = info.time_access.toSystemTime();
|
||||||
|
tm[0].tv_sec = st.seconds;
|
||||||
|
tm[0].tv_usec = st.nanoseconds / 1000;
|
||||||
|
st = info.time_modification.toSystemTime();
|
||||||
|
tm[1].tv_sec = st.seconds;
|
||||||
|
tm[1].tv_usec = st.nanoseconds / 1000;
|
||||||
|
if (utimes(fp.data(), tm) != 0) {
|
||||||
|
piCout << "[PIFile] applyFileInfo: \"utimes\" error:" << errorString();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ public:
|
|||||||
Permissions(uchar r = 0): raw(r) {}
|
Permissions(uchar r = 0): raw(r) {}
|
||||||
Permissions(bool r, bool w, bool e): raw(0) {read = w; write = w; exec = e;}
|
Permissions(bool r, bool w, bool e): raw(0) {read = w; write = w; exec = e;}
|
||||||
PIString toString() const {return PIString(read ? "r" : "-") + PIString(write ? "w" : "-") + PIString(exec ? "x" : "-");}
|
PIString toString() const {return PIString(read ? "r" : "-") + PIString(write ? "w" : "-") + PIString(exec ? "x" : "-");}
|
||||||
|
operator int() const {return raw;}
|
||||||
|
Permissions & operator =(int v) {raw = v; return *this;}
|
||||||
union {
|
union {
|
||||||
uchar raw;
|
uchar raw;
|
||||||
struct {
|
struct {
|
||||||
@@ -259,6 +261,12 @@ public:
|
|||||||
//! Returns FileInfo of file or dir with path "path"
|
//! Returns FileInfo of file or dir with path "path"
|
||||||
static FileInfo fileInfo(const PIString & path);
|
static FileInfo fileInfo(const PIString & path);
|
||||||
|
|
||||||
|
//! Apply "info" parameters to file or dir with path "path"
|
||||||
|
static bool applyFileInfo(const PIString & path, const FileInfo & info);
|
||||||
|
|
||||||
|
//! Apply "info" parameters to file or dir with path "info".path
|
||||||
|
static bool applyFileInfo(const FileInfo & info) {return applyFileInfo(info.path, info);}
|
||||||
|
|
||||||
//! \handlers
|
//! \handlers
|
||||||
//! \{
|
//! \{
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,18 @@ int PIPeer::PeerInfo::ping() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIString PIPeer::PeerInfo::fastestAddress() const {
|
||||||
|
double mp = -1.;
|
||||||
|
PIString ret;
|
||||||
|
piForeachC (Address & a, addresses)
|
||||||
|
if (a.ping > 0.) {
|
||||||
|
mp = piMaxd(mp, a.ping);
|
||||||
|
ret = a.address;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PIPeer::PIPeer(const PIString & name_): PIObject() {
|
PIPeer::PIPeer(const PIString & name_): PIObject() {
|
||||||
setName(name_);
|
setName(name_);
|
||||||
self_info.name = name_;
|
self_info.name = name_;
|
||||||
@@ -202,12 +214,13 @@ PIPeer::PeerInfo * PIPeer::quickestPeer(const PIString & to) {
|
|||||||
PeerInfo * dp = 0;
|
PeerInfo * dp = 0;
|
||||||
int mping = 0x7FFFFFFF;
|
int mping = 0x7FFFFFFF;
|
||||||
for (int i = 0; i < tp.size_s(); ++i) {
|
for (int i = 0; i < tp.size_s(); ++i) {
|
||||||
if (mping > tp[i]->ping()) {
|
int p = tp[i]->ping();
|
||||||
mping = tp[i]->ping();
|
if (mping > p && p > 0) {
|
||||||
|
mping = p;
|
||||||
dp = tp[i];
|
dp = tp[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//piCout << "*** search quickest peer: found" << dp->name;
|
//piCout << "*** search quickest peer: found" << (dp ? dp->name : "0");
|
||||||
return dp;
|
return dp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +235,7 @@ bool PIPeer::send(const PIString & to, const void * data, int size) {
|
|||||||
ba << int(4) << self_info.name << to << int(0) << size;
|
ba << int(4) << self_info.name << to << int(0) << size;
|
||||||
PIByteArray fmsg(data, size), cmsg;
|
PIByteArray fmsg(data, size), cmsg;
|
||||||
int msg_count = (size - 1) / _PIPEER_MSG_SIZE + 1;
|
int msg_count = (size - 1) / _PIPEER_MSG_SIZE + 1;
|
||||||
//piCout << "[PIPeer] send" << size << "bytes in" << msg_count << "packets ...";
|
piCout << "[PIPeer] send" << size << "bytes in" << msg_count << "packets ...";
|
||||||
for (int i = 0; i < msg_count; ++i) {
|
for (int i = 0; i < msg_count; ++i) {
|
||||||
int csize = (i == msg_count - 1) ? ((size - 1) % _PIPEER_MSG_SIZE + 1) : _PIPEER_MSG_SIZE;
|
int csize = (i == msg_count - 1) ? ((size - 1) % _PIPEER_MSG_SIZE + 1) : _PIPEER_MSG_SIZE;
|
||||||
cmsg = ba;
|
cmsg = ba;
|
||||||
@@ -230,7 +243,7 @@ bool PIPeer::send(const PIString & to, const void * data, int size) {
|
|||||||
cmsg.append(fmsg.data(i * _PIPEER_MSG_SIZE), csize);
|
cmsg.append(fmsg.data(i * _PIPEER_MSG_SIZE), csize);
|
||||||
if (!sendToNeighbour(dp, cmsg)) return false;
|
if (!sendToNeighbour(dp, cmsg)) return false;
|
||||||
}
|
}
|
||||||
//piCout << "[PIPeer] send" << size << "bytes ok";
|
piCout << "[PIPeer] send" << size << "bytes ok";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,6 +255,7 @@ bool PIPeer::dataRead(uchar * readed, int size) {
|
|||||||
PIString from, to;
|
PIString from, to;
|
||||||
ba >> type;
|
ba >> type;
|
||||||
PIMutexLocker locker(eth_mutex);
|
PIMutexLocker locker(eth_mutex);
|
||||||
|
PIMutexLocker plocker(peers_mutex);
|
||||||
//piCout << "[PIPeer \"" + name_ + "\"] Received packet" << type;
|
//piCout << "[PIPeer \"" + name_ + "\"] Received packet" << type;
|
||||||
if (type == 5) { // ping
|
if (type == 5) { // ping
|
||||||
PIString addr;
|
PIString addr;
|
||||||
@@ -259,7 +273,7 @@ bool PIPeer::dataRead(uchar * readed, int size) {
|
|||||||
a.wait_ping = false;
|
a.wait_ping = false;
|
||||||
if (a.ping < 0) a.ping = ptime.toMilliseconds();
|
if (a.ping < 0) a.ping = ptime.toMilliseconds();
|
||||||
else a.ping = 0.6 * a.ping + 0.4 * ptime.toMilliseconds();
|
else a.ping = 0.6 * a.ping + 0.4 * ptime.toMilliseconds();
|
||||||
piCout << "*** ping echo" << p.name << a.address << a.ping;
|
//piCout << "*** ping echo" << p.name << a.address << a.ping;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -348,7 +362,7 @@ bool PIPeer::mbcastRead(uchar * data, int size) {
|
|||||||
case 1: // new peer
|
case 1: // new peer
|
||||||
//piCout << "new peer packet ...";
|
//piCout << "new peer packet ...";
|
||||||
peers_mutex.lock();
|
peers_mutex.lock();
|
||||||
if (hasPeer(pi.name)) {
|
if (!hasPeer(pi.name)) {
|
||||||
ba >> pi;
|
ba >> pi;
|
||||||
pi.sync = 0;
|
pi.sync = 0;
|
||||||
if (pi.dist == 0) {
|
if (pi.dist == 0) {
|
||||||
@@ -397,8 +411,9 @@ bool PIPeer::mbcastRead(uchar * data, int size) {
|
|||||||
if (rpeer.name == self_info.name) continue;
|
if (rpeer.name == self_info.name) continue;
|
||||||
bool exist = false;
|
bool exist = false;
|
||||||
piForeach (PeerInfo & peer, peers) {
|
piForeach (PeerInfo & peer, peers) {
|
||||||
if (peer.name == rpeer.name) exist = true;
|
if (peer.name == rpeer.name) {
|
||||||
if (exist && isPeerRecent(peer, rpeer)) {
|
exist = true;
|
||||||
|
if (isPeerRecent(peer, rpeer)) {
|
||||||
//piCout << "synced " << peer.name;
|
//piCout << "synced " << peer.name;
|
||||||
for (int z = 0; z < rpeer.addresses.size_s(); ++z) {
|
for (int z = 0; z < rpeer.addresses.size_s(); ++z) {
|
||||||
PeerInfo::Address & ra(rpeer.addresses[z]);
|
PeerInfo::Address & ra(rpeer.addresses[z]);
|
||||||
@@ -412,12 +427,14 @@ bool PIPeer::mbcastRead(uchar * data, int size) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
peer.was_update = true;
|
||||||
peer.addresses = rpeer.addresses;
|
peer.addresses = rpeer.addresses;
|
||||||
peer.cnt = rpeer.cnt;
|
peer.cnt = rpeer.cnt;
|
||||||
peer.time = rpeer.time;
|
peer.time = rpeer.time;
|
||||||
peer.addNeighbours(rpeer.neighbours);
|
peer.addNeighbours(rpeer.neighbours);
|
||||||
rpeer.neighbours = peer.neighbours;
|
rpeer.neighbours = peer.neighbours;
|
||||||
if (peer.name == pi.name) peer.sync = 0;
|
if (peer.name == pi.name) peer.sync = 0;
|
||||||
|
}
|
||||||
piBreak;
|
piBreak;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -430,8 +447,6 @@ bool PIPeer::mbcastRead(uchar * data, int size) {
|
|||||||
}
|
}
|
||||||
//piCout << "***";
|
//piCout << "***";
|
||||||
//piCout << self_info.name << self_info.neighbours;
|
//piCout << self_info.name << self_info.neighbours;
|
||||||
if (ch)
|
|
||||||
findNearestAddresses();
|
|
||||||
piForeach (PeerInfo & i, peers) {
|
piForeach (PeerInfo & i, peers) {
|
||||||
if (i.dist == 0) {
|
if (i.dist == 0) {
|
||||||
self_info.addNeighbour(i.name);
|
self_info.addNeighbour(i.name);
|
||||||
@@ -439,6 +454,8 @@ bool PIPeer::mbcastRead(uchar * data, int size) {
|
|||||||
}
|
}
|
||||||
//piCout << i.name << i.neighbours;
|
//piCout << i.name << i.neighbours;
|
||||||
}
|
}
|
||||||
|
if (ch)
|
||||||
|
findNearestAddresses();
|
||||||
peers_mutex.unlock();
|
peers_mutex.unlock();
|
||||||
//piCoutObj << "after sync " << peers.size_s() << " peers";
|
//piCoutObj << "after sync " << peers.size_s() << " peers";
|
||||||
break;
|
break;
|
||||||
@@ -449,9 +466,10 @@ bool PIPeer::mbcastRead(uchar * data, int size) {
|
|||||||
|
|
||||||
bool PIPeer::sendToNeighbour(PIPeer::PeerInfo * peer, const PIByteArray & ba) {
|
bool PIPeer::sendToNeighbour(PIPeer::PeerInfo * peer, const PIByteArray & ba) {
|
||||||
//if (peer->_neth == 0) return false;
|
//if (peer->_neth == 0) return false;
|
||||||
piCout << "[PIPeer] sendToNeighbour" << peer->name << peer->_naddress << ba.size_s() << "bytes ...";
|
PIString addr = peer->fastestAddress();
|
||||||
|
piCout << "[PIPeer] sendToNeighbour" << peer->name << addr << ba.size_s() << "bytes ...";
|
||||||
//bool ok = peer->_neth->send(peer->_naddress, ba.data(), ba.size_s());
|
//bool ok = peer->_neth->send(peer->_naddress, ba.data(), ba.size_s());
|
||||||
bool ok = eth_send.send(peer->_naddress, ba);
|
bool ok = eth_send.send(addr, ba);
|
||||||
//piCout << "[PIPeer] sendToNeighbour" << (ok ? "ok" : "fail");
|
//piCout << "[PIPeer] sendToNeighbour" << (ok ? "ok" : "fail");
|
||||||
if (ok) diag_d.sended(ba.size_s());
|
if (ok) diag_d.sended(ba.size_s());
|
||||||
return ok;
|
return ok;
|
||||||
@@ -504,7 +522,7 @@ void PIPeer::pingNeighbours() {
|
|||||||
ba << int(5) << self_info.name;
|
ba << int(5) << self_info.name;
|
||||||
//piCout << "pingNeighbours" << peers.size();
|
//piCout << "pingNeighbours" << peers.size();
|
||||||
piForeach (PeerInfo & p, peers) {
|
piForeach (PeerInfo & p, peers) {
|
||||||
//piCout << " ping neighbour" << p.name;
|
piCout << " ping neighbour" << p.name << p.ping();
|
||||||
if (!p.isNeighbour()) continue;
|
if (!p.isNeighbour()) continue;
|
||||||
piForeach (PeerInfo::Address & a, p.addresses) {
|
piForeach (PeerInfo::Address & a, p.addresses) {
|
||||||
//piCout << " address" << a.address << a.wait_ping;
|
//piCout << " address" << a.address << a.wait_ping;
|
||||||
@@ -528,7 +546,7 @@ void PIPeer::syncPeers() {
|
|||||||
peers_mutex.lock();
|
peers_mutex.lock();
|
||||||
for (uint i = 0; i < peers.size(); ++i) {
|
for (uint i = 0; i < peers.size(); ++i) {
|
||||||
PeerInfo & cp(peers[i]);
|
PeerInfo & cp(peers[i]);
|
||||||
if (cp.sync > 3 && cp.dist == 0) {
|
if (cp.sync > 3) {
|
||||||
pn = cp.name;
|
pn = cp.name;
|
||||||
//piCoutObj << "sync: remove " << pn;
|
//piCoutObj << "sync: remove " << pn;
|
||||||
addToRemoved(cp);
|
addToRemoved(cp);
|
||||||
@@ -543,7 +561,11 @@ void PIPeer::syncPeers() {
|
|||||||
change = true;
|
change = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (cp.was_update)
|
||||||
|
cp.sync = 0;
|
||||||
|
else
|
||||||
cp.sync++;
|
cp.sync++;
|
||||||
|
cp.was_update = false;
|
||||||
}
|
}
|
||||||
pingNeighbours();
|
pingNeighbours();
|
||||||
if (change) findNearestAddresses();
|
if (change) findNearestAddresses();
|
||||||
@@ -600,7 +622,7 @@ void PIPeer::findNearestAddresses() {
|
|||||||
piForeach (PIEthernet * e, eths_traffic)
|
piForeach (PIEthernet * e, eths_traffic)
|
||||||
if (e->readAddress() == ma) {
|
if (e->readAddress() == ma) {
|
||||||
i._neth = e;
|
i._neth = e;
|
||||||
break;
|
piBreak;
|
||||||
}
|
}
|
||||||
//piCout << i.name << i._naddress;
|
//piCout << i.name << i._naddress;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public:
|
|||||||
friend PIByteArray & operator <<(PIByteArray & s, const PIPeer::PeerInfo & v);
|
friend PIByteArray & operator <<(PIByteArray & s, const PIPeer::PeerInfo & v);
|
||||||
friend PIByteArray & operator >>(PIByteArray & s, PIPeer::PeerInfo & v);
|
friend PIByteArray & operator >>(PIByteArray & s, PIPeer::PeerInfo & v);
|
||||||
public:
|
public:
|
||||||
PeerInfo() {dist = sync = cnt = 0; _neth = 0; _first = 0;}
|
PeerInfo() {dist = sync = cnt = 0; _neth = 0; _first = 0; was_update = false;}
|
||||||
|
|
||||||
struct Address {
|
struct Address {
|
||||||
Address(const PIString & a = PIString(), const PIString & m = "255.255.255.0");
|
Address(const PIString & a = PIString(), const PIString & m = "255.255.255.0");
|
||||||
@@ -70,6 +70,7 @@ public:
|
|||||||
|
|
||||||
bool isNeighbour() const {return dist == 0;}
|
bool isNeighbour() const {return dist == 0;}
|
||||||
int ping() const;
|
int ping() const;
|
||||||
|
PIString fastestAddress() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void addNeighbour(const PIString & n) {if (!neighbours.contains(n)) neighbours << n;}
|
void addNeighbour(const PIString & n) {if (!neighbours.contains(n)) neighbours << n;}
|
||||||
@@ -79,6 +80,7 @@ public:
|
|||||||
PIString nearest_address;
|
PIString nearest_address;
|
||||||
PIStringList neighbours;
|
PIStringList neighbours;
|
||||||
int sync, cnt;
|
int sync, cnt;
|
||||||
|
bool was_update;
|
||||||
PISystemTime time;
|
PISystemTime time;
|
||||||
PIString _naddress;
|
PIString _naddress;
|
||||||
PIEthernet * _neth;
|
PIEthernet * _neth;
|
||||||
|
|||||||
@@ -2,89 +2,121 @@
|
|||||||
#include "shared.h"
|
#include "shared.h"
|
||||||
#include "pisysteminfo.h"
|
#include "pisysteminfo.h"
|
||||||
|
|
||||||
|
extern PIScreen screen;
|
||||||
|
|
||||||
Daemon::Daemon(): PIPeer("_pisd_" + PISystemInfo::instance()->hostname + "_" + PIString(rand() % 100)) {
|
Daemon::Daemon(): PIPeer("_pisd_" + PISystemInfo::instance()->hostname + "_" + PIString(rand() % 100)) {
|
||||||
setName("Daemon");
|
setName("Daemon");
|
||||||
timer.setName("__S__Daemon_timer");
|
timer.setName("__S__Daemon_timer");
|
||||||
enabled = false;
|
|
||||||
mode = offset = cur = height = 0;
|
mode = offset = cur = height = 0;
|
||||||
//CONNECTU(&console, keyPressed, this, keyEvent)
|
CONNECTU(&screen, keyPressed, this, keyEvent)
|
||||||
CONNECTU(&timer, tickEvent, this, timerEvent)
|
CONNECTU(&timer, tickEvent, this, timerEvent)
|
||||||
timer.addDelimiter(5);
|
timer.addDelimiter(5);
|
||||||
timer.start(200);
|
timer.start(200);
|
||||||
|
|
||||||
|
//CONNECTU(&console, keyPressed, this, keyEvent)
|
||||||
|
//dir.setDir("/home/peri4/Documents");
|
||||||
|
//TileSimple * tl;
|
||||||
|
|
||||||
|
tile_root = new PIScreenTile();
|
||||||
|
tile_root->direction = Vertical;
|
||||||
|
|
||||||
|
tile_header = new TileSimple("daemon header");
|
||||||
|
tile_header->size_policy = Fixed;
|
||||||
|
|
||||||
|
list_daemons = new TileList("daemons list");
|
||||||
|
list_daemons->hide();
|
||||||
|
|
||||||
|
list_actions = new TileList("actions list");
|
||||||
|
list_actions->hide();
|
||||||
|
list_actions->content << TileList::Row("Information", CellFormat());
|
||||||
|
list_actions->content << TileList::Row("File manager", CellFormat());
|
||||||
|
list_actions->content << TileList::Row("Shell", CellFormat());
|
||||||
|
|
||||||
|
tile_info = new TileSimple("daemon info");
|
||||||
|
tile_info->hide();
|
||||||
|
|
||||||
|
tile_root->addTile(tile_header);
|
||||||
|
tile_root->addTile(list_daemons);
|
||||||
|
tile_root->addTile(list_actions);
|
||||||
|
tile_root->addTile(tile_info);
|
||||||
|
|
||||||
|
CONNECTU(&screen, tileEvent, this, tileEvent)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIScreenTile * Daemon::tile() const {
|
PIScreenTile * Daemon::tile() const {
|
||||||
return new PIScreenTile();
|
return tile_root;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Daemon::hideAll() {
|
||||||
|
list_actions->hide();
|
||||||
|
tile_info->hide();
|
||||||
|
list_daemons->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Daemon::showTile(PIScreenTile * t, const PIString & header) {
|
||||||
|
hideAll();
|
||||||
|
t->show();
|
||||||
|
t->setFocus();
|
||||||
|
tile_header->content.resize(1);
|
||||||
|
tile_header->content[0].first = header;
|
||||||
|
tile_header->content[0].second.flags = Bold;
|
||||||
|
if (!conn_name.isEmpty())
|
||||||
|
tile_header->content[0].first.insert(0, "Daemon \"" + connectedDaemon() + "\": ");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Daemon::fillInfoTile(const Daemon::HostInfo & hi) {
|
||||||
|
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());
|
||||||
|
tile_info->content << TileSimple::Row(" Hostname: " + hi.hostname, CellFormat());
|
||||||
|
tile_info->content << TileSimple::Row(" Username: " + hi.user, CellFormat());
|
||||||
|
tile_info->content << TileSimple::Row(" OS name: " + hi.OS_name, CellFormat());
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Daemon::tileEvent(PIScreenTile * t, TileEvent e) {
|
||||||
|
if (t == list_daemons) {
|
||||||
|
if (e.type == TileList::RowPressed) {
|
||||||
|
connectToDaemon(list_daemons->content[e.data.toInt()].first);
|
||||||
|
showActionList();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (t == list_actions) {
|
||||||
|
if (e.type == TileList::RowPressed) {
|
||||||
|
switch (e.data.toInt()) {
|
||||||
|
case 0: mode = 2; showTile(tile_info, "Information"); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Daemon::keyEvent(PIKbdListener::KeyEvent key) {
|
void Daemon::keyEvent(PIKbdListener::KeyEvent key) {
|
||||||
if (!enabled) return;
|
if (!tile_root->visible) return;
|
||||||
int num = key.key - '0';
|
|
||||||
switch (mode) {
|
|
||||||
case 0:
|
|
||||||
if (num >= 0 && num <= 9) {
|
|
||||||
connectToDaemon(dnames.value(key.key - '0'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
if (num >= 0 && num <= 9) {
|
|
||||||
mode = num + 10;
|
|
||||||
updateConsole();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
switch (key.key) {
|
switch (key.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:
|
case PIKbdListener::Esc:
|
||||||
//selected.clear();
|
|
||||||
//updateConsole();
|
|
||||||
if (mode == 0)
|
if (mode == 0)
|
||||||
menuRequest();
|
menuRequest();
|
||||||
else {
|
else {
|
||||||
if (mode > 1) {
|
if (mode > 1) {
|
||||||
mode = 1;
|
mode = 1;
|
||||||
updateConsole();
|
screen.lock();
|
||||||
|
tile_info->content.clear();
|
||||||
|
screen.unlock();
|
||||||
|
showActionList();
|
||||||
} else
|
} else
|
||||||
disconnect();
|
disconnect();
|
||||||
}
|
}
|
||||||
@@ -95,16 +127,17 @@ void Daemon::keyEvent(PIKbdListener::KeyEvent key) {
|
|||||||
|
|
||||||
|
|
||||||
void Daemon::timerEvent(void * _d, int delim) {
|
void Daemon::timerEvent(void * _d, int delim) {
|
||||||
if (!enabled) return;
|
screen.lock();
|
||||||
if (delim == 1) {
|
list_daemons->content.clear();
|
||||||
if (mode == 0)
|
availableDaemons();
|
||||||
updateConsole();
|
piForeachC (PIString & i, available_daemons)
|
||||||
|
list_daemons->content << TileList::Row(i, CellFormat());
|
||||||
}
|
screen.unlock();
|
||||||
if (delim == 5) {
|
if (delim == 5 && mode == 2) {
|
||||||
if (conn_name.isEmpty()) return;
|
if (conn_name.isEmpty()) return;
|
||||||
PIByteArray ba; ba << int(RequestHostInfo);
|
PIByteArray ba; ba << int(RequestHostInfo);
|
||||||
send(conn_name, ba);
|
send(conn_name, ba);
|
||||||
|
//std::cout << "send " << std::hex << ba;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,14 +156,13 @@ void Daemon::connectToDaemon(const PIString & dn) {
|
|||||||
if (dn.isEmpty()) return;
|
if (dn.isEmpty()) return;
|
||||||
conn_name = "_pisd_" + dn;
|
conn_name = "_pisd_" + dn;
|
||||||
mode = 1;
|
mode = 1;
|
||||||
updateConsole();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Daemon::disconnect() {
|
void Daemon::disconnect() {
|
||||||
conn_name.clear();
|
conn_name.clear();
|
||||||
mode = 0;
|
mode = 0;
|
||||||
updateConsole();
|
showMainList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -139,10 +171,16 @@ PIString Daemon::connectedDaemon() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Daemon::peerConnected(const PIString & name) {
|
||||||
|
/*piCout << "connected" << name;
|
||||||
|
mode = 2;
|
||||||
|
conn_name = name;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Daemon::peerDisconnected(const PIString & name) {
|
void Daemon::peerDisconnected(const PIString & name) {
|
||||||
if (name == conn_name) {
|
if (name == conn_name) {
|
||||||
conn_name.clear();
|
disconnect();
|
||||||
mode = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +190,7 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
|||||||
if (data.size() < 4) return;
|
if (data.size() < 4) return;
|
||||||
PIByteArray ba(data), rba;
|
PIByteArray ba(data), rba;
|
||||||
int type; ba >> type;
|
int type; ba >> type;
|
||||||
//piCout << "rec from" << from << type;
|
//std::cout << "rec from " << from << type;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case RequestHostInfo:
|
case RequestHostInfo:
|
||||||
makeMyHostInfo();
|
makeMyHostInfo();
|
||||||
@@ -161,6 +199,7 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
|||||||
case ReplyHostInfo:
|
case ReplyHostInfo:
|
||||||
ba >> info_other;
|
ba >> info_other;
|
||||||
makeOtherHostInfo();
|
makeOtherHostInfo();
|
||||||
|
fillInfoTile(info_other);
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
if (!rba.isEmpty()) send(from, rba);
|
if (!rba.isEmpty()) send(from, rba);
|
||||||
@@ -200,7 +239,6 @@ void Daemon::makeOtherHostInfo() {
|
|||||||
|
|
||||||
|
|
||||||
void Daemon::updateConsole() {
|
void Daemon::updateConsole() {
|
||||||
if (!enabled) return;
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 0: tabConnect(); break;
|
case 0: tabConnect(); break;
|
||||||
case 1: tabFeature(); break;
|
case 1: tabFeature(); break;
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ public:
|
|||||||
Daemon();
|
Daemon();
|
||||||
|
|
||||||
struct HostInfo {
|
struct HostInfo {
|
||||||
|
HostInfo() {
|
||||||
|
processorsCount = ID = threads = priority = -1;
|
||||||
|
physical_memsize = share_memsize = 0;
|
||||||
|
cpu_load_system = cpu_load_user = 0.;
|
||||||
|
}
|
||||||
PIString execCommand;
|
PIString execCommand;
|
||||||
PIString hostname;
|
PIString hostname;
|
||||||
PIString user;
|
PIString user;
|
||||||
@@ -31,14 +36,15 @@ public:
|
|||||||
float cpu_load_user;
|
float cpu_load_user;
|
||||||
};
|
};
|
||||||
|
|
||||||
void enable() {enabled = true;}
|
void showMainList() {showTile(list_daemons, "Select daemon");}
|
||||||
void disable() {enabled = false;}
|
void showActionList() {showTile(list_actions, "Select action");}
|
||||||
|
|
||||||
PIStringList availableDaemons() const;
|
PIStringList availableDaemons() const;
|
||||||
void connectToDaemon(const PIString & dn);
|
void connectToDaemon(const PIString & dn);
|
||||||
void disconnect();
|
void disconnect();
|
||||||
|
|
||||||
PIString connectedDaemon() const;
|
PIString connectedDaemon() const;
|
||||||
|
PIString thisDaemonName() const {return selfInfo().name.mid(6);}
|
||||||
|
|
||||||
PIScreenTile * tile() const;
|
PIScreenTile * tile() const;
|
||||||
|
|
||||||
@@ -50,9 +56,14 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EVENT_HANDLER2(void, tileEvent, PIScreenTile *, t, PIScreenTypes::TileEvent, e);
|
||||||
EVENT_HANDLER1(void, keyEvent, PIKbdListener::KeyEvent, key);
|
EVENT_HANDLER1(void, keyEvent, PIKbdListener::KeyEvent, key);
|
||||||
EVENT_HANDLER2(void, timerEvent, void * , _d, int, delim);
|
EVENT_HANDLER2(void, timerEvent, void * , _d, int, delim);
|
||||||
EVENT(menuRequest);
|
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 peerDisconnected(const PIString & name);
|
||||||
void dataReceived(const PIString & from, const PIByteArray & data);
|
void dataReceived(const PIString & from, const PIByteArray & data);
|
||||||
void makeMyHostInfo();
|
void makeMyHostInfo();
|
||||||
@@ -69,7 +80,9 @@ private:
|
|||||||
PIMap<int, PIString> dnames;
|
PIMap<int, PIString> dnames;
|
||||||
PISystemMonitor sys_mon_other;
|
PISystemMonitor sys_mon_other;
|
||||||
HostInfo info_my, info_other;
|
HostInfo info_my, info_other;
|
||||||
bool enabled;
|
PIScreenTile * tile_root;
|
||||||
|
TileSimple * tile_info, * tile_header;
|
||||||
|
TileList * list_daemons, * list_actions;
|
||||||
int mode, offset, cur, height;
|
int mode, offset, cur, height;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "file_manager.h"
|
#include "file_manager.h"
|
||||||
#include "shared.h"
|
#include "shared.h"
|
||||||
|
|
||||||
|
extern PIScreen screen;
|
||||||
|
|
||||||
FileManager::TileDir::TileDir(): TileList() {
|
FileManager::TileDir::TileDir(): TileList() {
|
||||||
label_path = 0;
|
label_path = 0;
|
||||||
@@ -132,8 +132,8 @@ void FileManager::TileDir::resizeEvent(int w, int h) {
|
|||||||
|
|
||||||
FileManager::FileManager() {
|
FileManager::FileManager() {
|
||||||
setName("FileManager");
|
setName("FileManager");
|
||||||
enabled = del_commit = false;
|
del_commit = false;
|
||||||
//CONNECTU(&console, keyPressed, this, keyEvent)
|
CONNECTU(&screen, keyPressed, this, keyEvent)
|
||||||
//dir.setDir("/home/peri4/Documents");
|
//dir.setDir("/home/peri4/Documents");
|
||||||
TileSimple * tl;
|
TileSimple * tl;
|
||||||
|
|
||||||
@@ -183,6 +183,13 @@ PIScreenTile * FileManager::tile() const {
|
|||||||
|
|
||||||
|
|
||||||
void FileManager::keyEvent(PIKbdListener::KeyEvent key) {
|
void FileManager::keyEvent(PIKbdListener::KeyEvent key) {
|
||||||
|
if (!tile_root->visible) return;
|
||||||
|
switch (key.key) {
|
||||||
|
case PIKbdListener::Esc:
|
||||||
|
menuRequest();
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
/*if (!enabled) return;
|
/*if (!enabled) return;
|
||||||
if (key.key == 'D') {
|
if (key.key == 'D') {
|
||||||
if (cur >= files.size_s() || cur < 0) return;
|
if (cur >= files.size_s() || cur < 0) return;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ private:
|
|||||||
EVENT(menuRequest);
|
EVENT(menuRequest);
|
||||||
void updateConsole();
|
void updateConsole();
|
||||||
|
|
||||||
bool enabled, del_commit;
|
bool del_commit;
|
||||||
TileDir * panels[2];
|
TileDir * panels[2];
|
||||||
PIScreenTile * tile_root;
|
PIScreenTile * tile_root;
|
||||||
PIStringList selected;
|
PIStringList selected;
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ public:
|
|||||||
cur_peer = -1;
|
cur_peer = -1;
|
||||||
TileSimple * tile = new TileSimple("title");
|
TileSimple * tile = new TileSimple("title");
|
||||||
tile->content << TileSimple::Row("pisd (PI System Daemon, PIP version " + PIPVersion() + ")", CellFormat(Black, Transparent));
|
tile->content << TileSimple::Row("pisd (PI System Daemon, PIP version " + PIPVersion() + ")", CellFormat(Black, Transparent));
|
||||||
|
tile->content << TileSimple::Row("This daemon: \"" + daemon_.thisDaemonName() + "\"", CellFormat(Black, Transparent));
|
||||||
tile->back_format.color_back = Yellow;
|
tile->back_format.color_back = Yellow;
|
||||||
tile->size_policy = Fixed;
|
tile->size_policy = Fixed;
|
||||||
screen.rootTile()->addTile(tile);
|
screen.rootTile()->addTile(tile);
|
||||||
@@ -149,9 +150,10 @@ public:
|
|||||||
piForeachC(PeerPair &p , daemon_._peerMap()) {
|
piForeachC(PeerPair &p , daemon_._peerMap()) {
|
||||||
PIString s = p.first + " | ";
|
PIString s = p.first + " | ";
|
||||||
piForeachC(PIPeer::PeerInfo * pp, p.second) s += "->" + pp->name;
|
piForeachC(PIPeer::PeerInfo * pp, p.second) s += "->" + pp->name;
|
||||||
|
peermap << s;
|
||||||
}
|
}
|
||||||
piForeachC(PIString &s , peermap)
|
piForeachC(PIString &s , peermap)
|
||||||
peers_tl->content << TileList::Row(s, CellFormat());
|
peermap_tl->content << TileList::Row(s, CellFormat());
|
||||||
screen.unlock();
|
screen.unlock();
|
||||||
}
|
}
|
||||||
void tick(void* data_, int delimiter) {
|
void tick(void* data_, int delimiter) {
|
||||||
@@ -171,8 +173,8 @@ public:
|
|||||||
switch (e.data.toInt()) {
|
switch (e.data.toInt()) {
|
||||||
case 0: tinfo->show(); break;
|
case 0: tinfo->show(); break;
|
||||||
case 1: tfm->show(); break;
|
case 1: tfm->show(); break;
|
||||||
case 2: tdaemon->show(); break;
|
case 2: daemon_.showMainList(); tdaemon->show(); break;
|
||||||
case 3: tpeer->show(); break;
|
case 3: tpeer->show(); peers_tl->setFocus(); break;
|
||||||
case 4: PIKbdListener::exiting = true; break;
|
case 4: PIKbdListener::exiting = true; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -187,6 +189,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
EVENT_HANDLER1(void, keyEvent, PIKbdListener::KeyEvent, e) {
|
EVENT_HANDLER1(void, keyEvent, PIKbdListener::KeyEvent, e) {
|
||||||
|
if (tpeer->visible || tinfo->visible)
|
||||||
if (e.key == PIKbdListener::Esc) menuRequest();
|
if (e.key == PIKbdListener::Esc) menuRequest();
|
||||||
//piCout << "key" << e.key;
|
//piCout << "key" << e.key;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user