git-svn-id: svn://db.shs.com.ru/pip@12 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
287 lines
9.8 KiB
C++
287 lines
9.8 KiB
C++
#include "pip.h"
|
|
|
|
class Ob: public PIObject {
|
|
PIOBJECT(Ob)
|
|
public:
|
|
Ob() {
|
|
sft.setName("sft");
|
|
sft.setDirectory(sft.directory().cd("..\\"));
|
|
piCout << "Send File Transfer DIrectory" << sft.directory().absolutePath();
|
|
CONNECTU(&sft, sendRequest, this, ssend);
|
|
|
|
rft.setName("rft");
|
|
rft.setDirectory(rft.directory().cd("..\\1"));
|
|
piCout << "Receive File Transfer DIrectory" << rft.directory().absolutePath();
|
|
CONNECTU(&rft, sendRequest, this, rsend);
|
|
}
|
|
|
|
void startsend() {
|
|
PIDir dir = PIDir::current();
|
|
dir.cd("..\\");
|
|
piCout << dir.absolutePath();
|
|
PIVector<PIFile::FileInfo> des = dir.allEntries();
|
|
piCout << "all entries" << des.size();
|
|
PIFile::FileInfo sde;
|
|
piForeachC(PIFile::FileInfo de, des) {
|
|
//piCout << (de.isDir() ? "dir:" : "file") << de.name << de.size;
|
|
if (de.path == "0") sde = de;
|
|
}
|
|
//sft.setPacketSize(64096);
|
|
sft.send(sde);
|
|
}
|
|
|
|
private:
|
|
EVENT_HANDLER1(void, ssend, PIByteArray &, data) {
|
|
// piCout << "[sender]" << sft.stateString() << ". datasize =" << data.size()
|
|
// << "(" << PIString::readableSize(sft.bytesFileCur()) << "/" << PIString::readableSize(sft.bytesFileAll()) << ", "
|
|
// << PIString::readableSize(sft.bytesTotalCur()) << "/" << PIString::readableSize(sft.bytesTotalAll()) << ")";
|
|
if(rand()%100 != 90) rft.received(data);
|
|
}
|
|
|
|
EVENT_HANDLER1(void, rsend, PIByteArray &, data) {
|
|
// piCout << "[receiver]" << rft.stateString() << ". datasize =" << data.size()
|
|
// << "(" << PIString::readableSize(rft.bytesFileCur()) << "/" << PIString::readableSize(rft.bytesFileAll()) << ", "
|
|
// << PIString::readableSize(rft.bytesTotalCur()) << "/" << PIString::readableSize(rft.bytesTotalAll()) << ")";
|
|
if(rand()%100 != 90) sft.received(data);
|
|
}
|
|
|
|
PIFileTransfer sft;
|
|
PIFileTransfer rft;
|
|
};
|
|
|
|
|
|
class UDPFileTransfer: public PITimer {
|
|
PIOBJECT_SUBCLASS(UDPFileTransfer, PITimer)
|
|
public:
|
|
UDPFileTransfer(const PIString &src_ip_port, const PIString &dst_ip_port) {
|
|
eth.setReadAddress(src_ip_port);
|
|
eth.setSendAddress(dst_ip_port);
|
|
//ft.setPacketSize(65000);
|
|
CONNECTU(&ft, sendRequest, this, ftsend);
|
|
CONNECTU(&ft, startSend, this, ftevent);
|
|
CONNECTU(&ft, finishSend, this, ftevent);
|
|
CONNECTU(&ft, startReceive, this, ftevent);
|
|
CONNECTU(&ft, finishReceive, this, ftevent);
|
|
CONNECTU(ð, threadedReadEvent, this, received);
|
|
start(50);
|
|
eth.open();
|
|
eth.startThreadedRead();
|
|
}
|
|
|
|
void startSend(const PIString &file) {
|
|
ft.send(file);
|
|
}
|
|
|
|
PIFileTransfer ft;
|
|
|
|
private:
|
|
PIEthernet eth;
|
|
|
|
void tick(void *, int) {
|
|
if (ft.isSending() || ft.isReceiving()) ftevent();
|
|
}
|
|
|
|
EVENT_HANDLER(void, ftevent) {
|
|
piCout << ft.stateString()
|
|
<< "(" << PIString::readableSize(ft.bytesFileCur()) << "/" << PIString::readableSize(ft.bytesFileAll()) << ", "
|
|
<< PIString::readableSize(ft.bytesCur()) << "/" << PIString::readableSize(ft.bytesAll()) << ")";
|
|
}
|
|
|
|
EVENT_HANDLER1(void, ftsend, PIByteArray &, data) {
|
|
eth.send(data);
|
|
}
|
|
|
|
EVENT_HANDLER2(void, received, uchar * , readed, int, size) {
|
|
PIByteArray ba(readed, size);
|
|
ft.received(ba);
|
|
}
|
|
};
|
|
|
|
|
|
#include "ccm_kbd.h"
|
|
void key_event(PIKbdListener::KeyEvent e, void*) {
|
|
PICodeInfo::EnumInfo * ei = PICodeInfo::enumsInfo->value("PIKbdListener::SpecialKey");
|
|
if (!ei) return;
|
|
piCout << PICoutManipulators::NewLine << "modifiers" << e.modifiers;
|
|
piForeachC (PICodeInfo::EnumeratorInfo & i, ei->members)
|
|
if (i.value == e.key) {
|
|
piCout << "key" << i.name;
|
|
return;
|
|
}
|
|
piCout << "key" << e.key;
|
|
}
|
|
class Catcher: public PIObject {
|
|
PIOBJECT(Catcher)
|
|
public:
|
|
EVENT_HANDLER2(void, event, PIScreenTile *, t, PIScreenTypes::TileEvent, e) {
|
|
piCout << "event from" << t->name << "type" << e.type << e.data;
|
|
if (e.data == 2)
|
|
delete t->parentTile();
|
|
}
|
|
EVENT_HANDLER1(void, eventKey, PIKbdListener::KeyEvent, e) {
|
|
piCout << "key" << e.key;
|
|
}
|
|
};
|
|
|
|
using namespace PIScreenTypes;
|
|
|
|
int main (int argc, char * argv[]) {
|
|
/*PILibrary lib(argv[1]);
|
|
piCout << lib.isLoaded();
|
|
piCout << lib.resolve(argv[2]);
|
|
lib.unload();
|
|
piCout << lib.load(argv[1]);
|
|
piCout << lib.resolve(argv[2]);
|
|
return 0;*/
|
|
/*if (!(argc == 3 || argc == 4)) {
|
|
piCout << "UDPFileTransfer";
|
|
piCout << "USE: piptest [src_ip_port] [dst_ip_port] {filename}";
|
|
return 0;
|
|
}
|
|
PIKbdListener kbd;
|
|
kbd.enableExitCapture();
|
|
PIString src = argv[1];
|
|
PIString dst = argv[2];
|
|
UDPFileTransfer f(src, dst);
|
|
piCout << "work directory" << f.ft.directory().absolutePath() << ", listen on" << src << ",send to" << dst;
|
|
if (argc == 4) {
|
|
PIString file = argv[3];
|
|
piCout << "send file" << file;
|
|
f.startSend(file);
|
|
return 0;
|
|
} else {
|
|
piCout << "wait for receiving";
|
|
}*/
|
|
Catcher catcher;
|
|
PIScreen screen(false, key_event);
|
|
CONNECTU(&screen, tileEvent, &catcher, event)
|
|
CONNECTU(&screen, keyPressed, &catcher, eventKey)
|
|
screen.enableExitCapture(PIKbdListener::F10);
|
|
//screen.start();
|
|
float cx = 0, cy = 0, vx = 1., vy = 0.3, t = 0.;
|
|
PITimeMeasurer tm;
|
|
Color col = Red;
|
|
screen.rootTile()->back_symbol = '0';
|
|
|
|
PIScreenTile * tile = new TileSimple();
|
|
screen.rootTile()->addTile(tile);
|
|
((TileSimple*)tile)->content << TileSimple::Row("SADHFJKL", CellFormat(Red, Default));
|
|
tile->back_symbol = '1';
|
|
tile->size_policy = Fixed;
|
|
tile->minimumHeight = 3;
|
|
|
|
tile = new PIScreenTile("center");
|
|
screen.rootTile()->addTile(tile);
|
|
tile->direction = Horizontal;
|
|
tile->back_symbol = '*';
|
|
tile->marginLeft = 1;
|
|
tile->marginTop = 2;
|
|
tile->marginRight = 3;
|
|
tile->marginBottom = 4;
|
|
tile->spacing = 2;
|
|
|
|
PIScreenTile * tile2 = new PIScreenTile();
|
|
tile->addTile(tile2);
|
|
tile2->back_symbol = '4';
|
|
tile2->back_format.flags = Bold;
|
|
|
|
tile2 = new TileSimple();
|
|
tile->addTile(tile2);
|
|
((TileSimple*)tile2)->alignment = Right;
|
|
((TileSimple*)tile2)->content << TileSimple::Row("red", CellFormat(Red, Default));
|
|
((TileSimple*)tile2)->content << TileSimple::Row("┏━━┯━━┓", CellFormat(Green, Red));
|
|
((TileSimple*)tile2)->content << TileSimple::Row("┃ │ ┃", CellFormat(Green, Red));
|
|
((TileSimple*)tile2)->content << TileSimple::Row("┠──┴──┨", CellFormat(Green, Red));
|
|
((TileSimple*)tile2)->content << TileSimple::Row("┃╱╲ ╱╲┃", CellFormat(Green, Red));
|
|
((TileSimple*)tile2)->content << TileSimple::Row("┃╲╱ ╲╱┃", CellFormat(Green, Red));
|
|
((TileSimple*)tile2)->content << TileSimple::Row("┗━━━━━┛", CellFormat(Green, Red));
|
|
|
|
tile2 = new TileList("list0");
|
|
tile->addTile(tile2);
|
|
((TileList*)tile2)->alignment = Right;
|
|
for (int i = 0; i < 30; ++i)
|
|
((TileList*)tile2)->content << TileList::Row("item " + PIString(i), CellFormat(Red, Magenta));
|
|
((TileList*)tile2)->selection_mode = TileList::SingleSelection;
|
|
|
|
tile2 = new TileList("list1");
|
|
tile->addTile(tile2);
|
|
((TileList*)tile2)->alignment = Center;
|
|
for (int i = 0; i < 50; ++i)
|
|
((TileList*)tile2)->content << TileList::Row("item " + PIString(i), CellFormat(Magenta, Magenta, (i % 3 ? Bold : 0) | (i % 2 ? Underline : 0)));
|
|
((TileList*)tile2)->selection_mode = TileList::MultiSelection;
|
|
|
|
tile = new PIScreenTile();
|
|
screen.rootTile()->addTile(tile);
|
|
tile->back_symbol = '3';
|
|
tile->maximumHeight = 4;
|
|
//tile->size_policy = Expanding;
|
|
|
|
tile = new PIScreenTile();
|
|
screen.rootTile()->addTile(tile);
|
|
tile->back_symbol = '8';
|
|
tile->back_format.color_back = Yellow;
|
|
tile->maximumHeight = 5;
|
|
|
|
|
|
tile = new PIScreenTile();
|
|
|
|
tile2 = new TileSimple();
|
|
tile2->back_format.color_back = Transparent;
|
|
((TileSimple*)tile2)->content << TileSimple::Row("label", CellFormat(Magenta, Magenta, Bold));
|
|
((TileSimple*)tile2)->alignment = PIScreenTypes::Center;
|
|
tile2->size_policy = PIScreenTypes::Preferred;
|
|
tile->addTile(tile2);
|
|
|
|
tile2 = new TileButtons("butt0");
|
|
tile2->back_format.color_back = Transparent;
|
|
tile->addTile(tile2);
|
|
((TileButtons*)tile2)->content << TileButtons::Button("first", CellFormat(Green, Transparent));
|
|
((TileButtons*)tile2)->content << TileButtons::Button("sec", CellFormat(Green, Red));
|
|
((TileButtons*)tile2)->content << TileButtons::Button("3", CellFormat(Green, Transparent));
|
|
((TileButtons*)tile2)->direction = PIScreenTypes::Horizontal;
|
|
//((TileButtons*)tile)->alignment = Center;
|
|
|
|
tile2 = new TileButtons("butt1");
|
|
tile2->back_format.color_back = Transparent;
|
|
tile->addTile(tile2);
|
|
((TileButtons*)tile2)->content << TileButtons::Button("fF", CellFormat(Green, Transparent));
|
|
((TileButtons*)tile2)->content << TileButtons::Button("sec2", CellFormat(Green, Red));
|
|
((TileButtons*)tile2)->content << TileButtons::Button("333", CellFormat(Green, Transparent));
|
|
((TileButtons*)tile2)->direction = PIScreenTypes::Horizontal;
|
|
//((TileButtons*)tile)->alignment = Center;
|
|
|
|
((TileButtons*)tile)->back_format.color_back = Yellow;
|
|
tile->setMargins(2, 2, 1, 1);
|
|
tile->spacing = 1;
|
|
screen.setDialogTile(tile);
|
|
|
|
//screen.rootTile()->hide();
|
|
while (!PIKbdListener::exiting) {
|
|
cx += vx;
|
|
cy += vy;
|
|
t += 0.05;
|
|
if (cx < 0) {cx = 0.; vx *= -1;}
|
|
if (cx >= screen.windowWidth()) {cx = screen.windowWidth() - 1; vx *= -1;}
|
|
if (cy < 0) {cy = 0.; vy *= -1;}
|
|
if (cy >= screen.windowHeight()) {cy = screen.windowHeight() - 1; vy *= -1;}
|
|
if (tm.elapsed_m() > 500) {
|
|
tm.reset();
|
|
if (col == Red) col = Green;
|
|
else col = Red;
|
|
//screen.tileByName("list0")->visible = !screen.tileByName("list0")->visible;
|
|
}
|
|
/*screen.lock();
|
|
screen.clear();
|
|
screen.drawer()->drawRect(0, 0, 20, 10, ' ', Default, col);
|
|
screen.drawer()->drawLine(21, 0, 21, 10, '|', Default, col);
|
|
screen.drawer()->drawPixel(21, 5, '#', Magenta, col);
|
|
screen.drawer()->drawPixel(21, 4, '#', Magenta, col, Bold);
|
|
screen.drawer()->drawText(50 + cos(t)*50, 20 + sin(t)*20, "Hello PIScreen!", Magenta);
|
|
//screen.drawer()->drawPixel(cx, cy, 'W', Default, Blue);
|
|
screen.unlock();*/
|
|
piMSleep(25);
|
|
}
|
|
return 0;
|
|
}
|
|
|