|
|
|
|
@@ -1,232 +1,110 @@
|
|
|
|
|
#include "pip.h"
|
|
|
|
|
#include "piintrospection_server.h"
|
|
|
|
|
#include "piintrospection_containers_p.h"
|
|
|
|
|
//#include <winsock2.h>
|
|
|
|
|
|
|
|
|
|
class CL: public PIObject {
|
|
|
|
|
PIOBJECT(CL)
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
class PIHash {
|
|
|
|
|
public:
|
|
|
|
|
EVENT_HANDLER1(void, nc, PIEthernet * , client) {
|
|
|
|
|
piCout << "client" << client;
|
|
|
|
|
inline PIHash() {
|
|
|
|
|
shift = 0;
|
|
|
|
|
r_size = 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
inline T & operator [](size_t index) {return content[index].second;}
|
|
|
|
|
inline const T & operator [](size_t index) const {return content[index].second;}
|
|
|
|
|
inline size_t size() const {return r_size;}
|
|
|
|
|
inline ssize_t size_s() const {return r_size;}
|
|
|
|
|
inline size_t capacity() const {return content.capacity();}
|
|
|
|
|
inline bool isEmpty() const {return content.isEmpty();}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
inline PIHash<T> & push_back(const T & v) {
|
|
|
|
|
uint h = piHash(v);
|
|
|
|
|
add_hash(h);
|
|
|
|
|
int i = (h >> (32 - shift));
|
|
|
|
|
if (content[i].first == 0) r_size++;
|
|
|
|
|
content[i] = HashPair(h, v);
|
|
|
|
|
//for (int i=0; i<content.size_s(); ++i) piCout << i << content[i].first << content[i].second;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
inline PIHash<T> & append(const T & v) {return push_back(v);}
|
|
|
|
|
// inline PIVector<T> & append(const PIVector<T> & other) {
|
|
|
|
|
// assert(&other != this);
|
|
|
|
|
// size_t ps = piv_size;
|
|
|
|
|
// alloc(piv_size + other.piv_size);
|
|
|
|
|
// newT(piv_data + ps, other.piv_data, other.piv_size);
|
|
|
|
|
// return *this;
|
|
|
|
|
// }
|
|
|
|
|
inline PIHash<T> & operator <<(const T & v) {return push_back(v);}
|
|
|
|
|
// inline PIVector<T> & operator <<(const PIVector<T> & other) {return append(other);}
|
|
|
|
|
private:
|
|
|
|
|
typedef PIPair<uint, T> HashPair;
|
|
|
|
|
void add_hash(uint nh) {
|
|
|
|
|
piCout << "add" << nh;
|
|
|
|
|
//for (int i=0; i<content.size_s(); ++i) piCout << i << content[i].first << content[i].second;
|
|
|
|
|
if (nh == 0) {
|
|
|
|
|
piCout << "invalid hash";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
double el = tm.elapsed_m();
|
|
|
|
|
piCout << el;
|
|
|
|
|
if (shift == 0) {
|
|
|
|
|
shift++;
|
|
|
|
|
content.resize(1 << shift, HashPair(0, T()));
|
|
|
|
|
}
|
|
|
|
|
int i = (nh >> (32 - shift));
|
|
|
|
|
while (content[i].first != nh && content[i].first != 0) {
|
|
|
|
|
shift++;
|
|
|
|
|
i = (nh >> (32 - shift));
|
|
|
|
|
content.resize(1 << shift, HashPair(0, T()));
|
|
|
|
|
rehash();
|
|
|
|
|
}
|
|
|
|
|
//for (int i=0; i<content.size_s(); ++i) piCout << i << content[i].first << content[i].second;
|
|
|
|
|
}
|
|
|
|
|
void rehash() {
|
|
|
|
|
piCout << "rehash";
|
|
|
|
|
PIVector<PIPair<uint, T> > tmpc(content.size(), HashPair(0, T()));
|
|
|
|
|
for (int i=0; i<content.size_s(); ++i) {
|
|
|
|
|
if (content[i].first == 0) continue;
|
|
|
|
|
int h = (content[i].first >> (32 - shift));
|
|
|
|
|
tmpc[h] = content[i];
|
|
|
|
|
piCout << i << "->" << h;
|
|
|
|
|
}
|
|
|
|
|
content.swap(tmpc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*piCout << "****";
|
|
|
|
|
PIPeer().dump();
|
|
|
|
|
piCout << "----";*/
|
|
|
|
|
PIVector<PIPair<uint, T> > content;
|
|
|
|
|
uint shift;
|
|
|
|
|
size_t r_size;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* 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());
|
|
|
|
|
template<typename T>
|
|
|
|
|
inline PICout operator <<(PICout s, const PIHash<T> & v) {
|
|
|
|
|
s.space();
|
|
|
|
|
s.setControl(0, true);
|
|
|
|
|
s << "{";
|
|
|
|
|
for (size_t i = 0; i < v.size(); ++i) {
|
|
|
|
|
s << v[i];
|
|
|
|
|
if (i < v.size() - 1)
|
|
|
|
|
s << ", ";
|
|
|
|
|
}
|
|
|
|
|
el = tm.elapsed_m();
|
|
|
|
|
piCout << "";
|
|
|
|
|
piCout << ret;
|
|
|
|
|
piCout << "crc" << el;
|
|
|
|
|
s << "}";
|
|
|
|
|
s.restoreControl();
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tm.reset();
|
|
|
|
|
for (int i = 0; i < 1000000; ++i) {
|
|
|
|
|
ret = HashLy(_sd.data(), _sd.size_s());
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
PIHash<PIString> v;
|
|
|
|
|
v << "x";
|
|
|
|
|
v << "bbb";
|
|
|
|
|
v << "bbc";
|
|
|
|
|
v << "aaa";
|
|
|
|
|
v << "123";
|
|
|
|
|
v << "321";
|
|
|
|
|
v << "aaa" << "bbb" << "ccc";
|
|
|
|
|
piCout << v.size() << v.capacity();
|
|
|
|
|
//piCout << (1 << 2);
|
|
|
|
|
PIHash<PIString> v2;
|
|
|
|
|
for (int i=0; i<1000; ++i) {
|
|
|
|
|
v2 << PIString::fromNumber(randomi());
|
|
|
|
|
}
|
|
|
|
|
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 ...";
|
|
|
|
|
piCout << v2.size() << v2.capacity();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|