233 lines
5.1 KiB
C++
233 lines
5.1 KiB
C++
#include "pip.h"
|
|
#include "piintrospection_server.h"
|
|
#include "piintrospection_containers_p.h"
|
|
//#include <winsock2.h>
|
|
|
|
class CL: public PIObject {
|
|
PIOBJECT(CL)
|
|
public:
|
|
EVENT_HANDLER1(void, nc, PIEthernet * , client) {
|
|
piCout << "client" << client;
|
|
}
|
|
};
|
|
|
|
PIKbdListener kbd(0, 0, false);
|
|
#include <typeinfo>
|
|
#define PIIS_TYPENAME(t) typeid(t).name()
|
|
|
|
template<typename T> class Name
|
|
{
|
|
public:
|
|
static const char * name() {return PIIS_TYPENAME(T);}
|
|
};
|
|
|
|
PISystemMonitor sys_mon;
|
|
|
|
|
|
|
|
class TestRec: public PIObject {
|
|
PIOBJECT(TestRec)
|
|
public:
|
|
EVENT_HANDLER(void, reinitSpec) {/*piCout << "reinitSpec";*/int a = 10; (void*)&a;}
|
|
|
|
EVENT_HANDLER(void, coeffsChanged) {piCout << "coeffsChanged";}
|
|
EVENT_HANDLER(void, guiAboutSend) {piCout << "guiAboutSend";}
|
|
EVENT_HANDLER(void, guiAfterSend) {piCout << "guiAfterSend";}
|
|
EVENT_HANDLER(void, guiReceived) {piCout << "guiReceived";}
|
|
|
|
EVENT_HANDLER(void, playerReceived) {/*piCout << "playerReceived";*/int a = 10; (void*)&a;}
|
|
|
|
EVENT_HANDLER(void, playerValuesReceived) {piCout << "playerValuesReceived";}
|
|
EVENT_HANDLER(void, calculate) {piCout << "calculate";}
|
|
EVENT_HANDLER(void, autostart) {piCout << "autostart";}
|
|
|
|
EVENT_HANDLER(void, syncOff) {/*piCout << "syncOff";*/int a = 10; (void*)&a;}
|
|
|
|
EVENT_HANDLER(void, del) {piCout << "DEL";}
|
|
};
|
|
|
|
class TestSnd: public PIObject {
|
|
PIOBJECT(TestSnd)
|
|
public:
|
|
EVENT(reinitSpec)
|
|
EVENT(coeffsChanged)
|
|
EVENT(guiAboutSend)
|
|
EVENT(guiAfterSend)
|
|
EVENT(guiReceived)
|
|
EVENT(playerReceived)
|
|
EVENT(playerValuesReceived)
|
|
EVENT(calculate)
|
|
EVENT(autostart)
|
|
EVENT(syncOff);
|
|
};
|
|
|
|
class CA: public PIObject {
|
|
PIOBJECT(CA)
|
|
EVENT(evA)
|
|
};
|
|
|
|
class CB: public CA {
|
|
PIOBJECT_SUBCLASS(CB, CA)
|
|
EVENT(evB)
|
|
};
|
|
|
|
class CC: public CB {
|
|
PIOBJECT_SUBCLASS(CC, CB)
|
|
EVENT(evC)
|
|
};
|
|
|
|
#define CONN(sn) CONNECTU(snd, sn, rec, sn)
|
|
uint HashLy(const void* d, int l) {
|
|
uint hash = 0u;
|
|
for(int i = 0; i < l; ++i)
|
|
hash = (hash * 1664525u) + ((uchar*)d)[i] + 1013904223u;
|
|
return hash;
|
|
}
|
|
int main(int argc, char * argv[]) {
|
|
//sys_mon.startOnSelf();
|
|
|
|
PITimeMeasurer tm;
|
|
|
|
TestRec * rec = 0;
|
|
TestSnd * snd = 0;
|
|
|
|
for (int i = 0; i < 1; ++i) {
|
|
if (rec) delete rec;
|
|
if (snd) delete snd;
|
|
rec = new TestRec();
|
|
snd = new TestSnd();
|
|
}
|
|
|
|
CONNECTU(snd, deleted, rec, del)
|
|
CONN(reinitSpec)
|
|
CONN(coeffsChanged)
|
|
CONN(guiAboutSend)
|
|
CONN(guiAfterSend)
|
|
CONN(guiReceived)
|
|
CONN(playerReceived)
|
|
CONN(playerValuesReceived)
|
|
CONN(calculate)
|
|
CONN(autostart)
|
|
CONN(syncOff);
|
|
|
|
// 0.6 us on call
|
|
for (int j = 0; j < 10; ++j) {
|
|
tm.reset();
|
|
for (int i = 0; i < 10000; ++i) {
|
|
snd->reinitSpec();
|
|
snd->playerReceived();
|
|
snd->syncOff();
|
|
}
|
|
double el = tm.elapsed_m();
|
|
piCout << el;
|
|
}
|
|
|
|
/*piCout << "****";
|
|
PIPeer().dump();
|
|
piCout << "----";*/
|
|
|
|
/* PIString _s = "012345678901234567890123456789";
|
|
CRC_32 crc = standardCRC_32();
|
|
PIByteArray _sd = _s.toByteArray();
|
|
double el;
|
|
uint ret;
|
|
|
|
tm.reset();
|
|
for (int i = 0; i < 1000000; ++i) {
|
|
ret = crc.calculate(_sd.data(), _sd.size_s());
|
|
}
|
|
el = tm.elapsed_m();
|
|
piCout << "";
|
|
piCout << ret;
|
|
piCout << "crc" << el;
|
|
|
|
tm.reset();
|
|
for (int i = 0; i < 1000000; ++i) {
|
|
ret = HashLy(_sd.data(), _sd.size_s());
|
|
}
|
|
el = tm.elapsed_m();
|
|
piCout << "";
|
|
piCout << ret;
|
|
piCout << " ly" << el;
|
|
|
|
tm.reset();
|
|
for (int i = 0; i < 1000000; ++i) {
|
|
ret = murmur3_32((const uchar*)_sd.data(), _sd.size_s());
|
|
}
|
|
el = tm.elapsed_m();
|
|
piCout << "";
|
|
piCout << ret;
|
|
piCout << "mur" << el;
|
|
*/
|
|
delete snd;
|
|
delete rec;
|
|
|
|
return 0;
|
|
|
|
PIString s;
|
|
s = "gafaffaf";
|
|
piCout << s;
|
|
piCout << s;
|
|
s = "dd";
|
|
piCout << s;
|
|
return 0;
|
|
|
|
PIINTROSPECTION_START;
|
|
//uint id = standardCRC_32().calculate("6PIChar");
|
|
//PIIntrospectionContainers * ci = PIINTROSPECTION_CONTAINERS->p;
|
|
FOREVER {
|
|
piMSleep(100);
|
|
//piCout << ci->data[id].count << ci->data[id].bytes_allocated << ci->data[id].bytes_used;
|
|
}
|
|
return 0;
|
|
|
|
PICLI cli(argc, argv);
|
|
cli.setDebug(false);
|
|
cli.addArgument("send");
|
|
//PISystemInfo::machineID();
|
|
kbd.enableExitCapture();
|
|
kbd.start();
|
|
|
|
if (cli.hasArgument("send")) {
|
|
/*piCout << "send mode";
|
|
PIEthernet eth;
|
|
eth.setSendAddress(cli.rawArguments().back() + ":15123");
|
|
eth.open();
|
|
while (!kbd.exiting) {
|
|
eth.send(PIByteArray("test string", 12));
|
|
piMSleep(500);
|
|
}*/
|
|
PIEthernet eth(PIEthernet::TCP_Server);
|
|
eth.listen(cli.rawArguments().back() + ":15123", true);
|
|
//eth.open();
|
|
CL cl;
|
|
CONNECTU(ð, newConnection, &cl, nc);
|
|
|
|
WAIT_FOR_EXIT;
|
|
piCout << "exiting ...";
|
|
|
|
} else {
|
|
piCout << "recv mode";
|
|
PIEthernet eth(PIEthernet::TCP_Client);
|
|
//eth.setReadAddress(cli.rawArguments().back() + ":15123");
|
|
eth.startThreadedRead();
|
|
int s = eth.socket();
|
|
piCout << s;
|
|
piCout << "connect ...";
|
|
eth.connect(cli.rawArguments().back() + /*":13361"*/":15123");
|
|
piCout << "connect done" << eth.isConnected();
|
|
//fcntl(fd, F_SETFL, O_NONBLOCK);
|
|
|
|
WAIT_FOR_EXIT;
|
|
piCout << "exiting ...";
|
|
|
|
}
|
|
/*PIThread t;
|
|
t.start(10);
|
|
//WAIT_FOR_EXIT;
|
|
piSleep(20.);
|
|
t.stop(true);*/
|
|
piCout << "exit main ...";
|
|
return 0;
|
|
}
|